-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added product fee to the quote #348
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,20 +41,24 @@ KEY_DIR=geth_keystore | |
ACCOUNT_NUM=0 | ||
PWD_FILE=pwd.txt | ||
CHAIN_ID=33 | ||
|
||
KEY_SECRET=FlyoverTestEnv/LPS-LOCAL-KEY | ||
PASSWORD_SECRET=FlyoverTestEnv/LPS-LOCAL-PASSWORD | ||
BTC_WALLET_PASSWORD=FlyoverTestEnv/LPS-LOCAL-BTC-WALLET-PASSWORD | ||
BTC_ENCRYPTED_WALLET=true | ||
|
||
AWS_ACCESS_KEY_ID= | ||
AWS_SECRET_ACCESS_KEY= | ||
AWS_REGION= | ||
[email protected] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont use mailgun anymore |
||
MAILGUN_DOMAIN=b30c8b203ade9013f16fbd24232f7580-102c75d8-2e73f63d | ||
|
||
AWS_ACCESS_KEY_ID=AKIARRR3WWCRU722UAHK | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please dont push this to the repo !! |
||
AWS_SECRET_ACCESS_KEY=DvQLL+krYY3AWY5U+7RsYQ05fBr9/Qpk+1wuM+Ce | ||
AWS_REGION=us-east-1 | ||
|
||
ENCRYPT_APP_KEY=FlyoverTestEnv/ENCRYPT-KEY | ||
# From previous .env | ||
LIQUIDITY_PROVIDER_RSK_ADDR=0x9D93929A9099be4355fC2389FbF253982F9dF47c | ||
PEGIN_LIQUIDITY_PROVIDER_RSK_ADDR= | ||
PEGOUT_LIQUIDITY_PROVIDER_RSK_ADDR= | ||
LIQUIDITY_PROVIDER_RSK_ADDR=0x9d93929a9099be4355fc2389fbf253982f9df47c | ||
PEGIN_LIQUIDITY_PROVIDER_RSK_ADDR=0x9d93929a9099be4355fc2389fbf253982f9df47c | ||
PEGOUT_LIQUIDITY_PROVIDER_RSK_ADDR=0x9d93929a9099be4355fc2389fbf253982f9df47c | ||
|
||
BTCD_RPC_USER=test | ||
BTCD_RPC_PASS=test | ||
|
@@ -85,5 +89,5 @@ QUOTE_CACHE_START_BLOCK=0 | |
CAPTCHA_SECRET_KEY= | ||
CAPTCHA_SITE_KEY= | ||
CAPTCHA_THRESHOLD=0.8 | ||
DISABLE_CAPTCHA=false | ||
DISABLE_CAPTCHA=true | ||
PROVIDER_TYPE=both |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,7 @@ const GetCollateralError = "Unable to get collateral" | |
const ErrorAddingProvider = "Error Adding New provider: %v" | ||
const ErrorRetrivingProviderAddress = "Error Retrieving Provider Address from MongoDB" | ||
const ErrorNotLiquidity = "Not enough liquidity" | ||
const ErrorRetrievingDaoFeePercentage = "Error retrieving dao fee percentage" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to stop doing this pattern of error msg and switch to sentinel errors (not to you or this PR, just adding to my tech debt list) |
||
|
||
type LiquidityProviderList struct { | ||
Endpoint string `env:"RSK_ENDPOINT"` | ||
|
@@ -830,14 +831,12 @@ func (s *Server) getQuoteHandler(w http.ResponseWriter, r *http.Request) { | |
|
||
var gas uint64 | ||
gas, err = s.rsk.EstimateGas(qr.CallEoaOrContractAddress, big.NewInt(int64(qr.ValueToTransfer)), []byte(qr.CallContractArguments)) | ||
|
||
if err != nil { | ||
log.Error(ErrorEstimatingGas, err.Error()) | ||
customError := NewServerError(ErrorEstimatingGas, make(Details), true) | ||
ResponseError(w, customError, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
price, err := s.rsk.GasPrice() | ||
if err != nil { | ||
log.Error(ErrorEstimatingGas, err.Error()) | ||
|
@@ -864,9 +863,20 @@ func (s *Server) getQuoteHandler(w http.ResponseWriter, r *http.Request) { | |
} | ||
minLockTxValueInWei := types.SatoshiToWei(minLockTxValueInSatoshi.Uint64()) | ||
|
||
daoFeePercentage, err := s.rsk.GetDaoFeePercentage() | ||
|
||
if err != nil { | ||
log.Error(ErrorRetrievingDaoFeePercentage, err.Error()) | ||
customError := NewServerError(ErrorRetrievingDaoFeePercentage, make(map[string]interface{}), true) | ||
ResponseError(w, customError, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
daoFeeAmount := qr.ValueToTransfer * daoFeePercentage / 100 | ||
Luisfc68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
getQuoteFailed := false | ||
amountBelowMinLockTxValue := false | ||
q := parseReqToQuote(qr, s.rsk.GetLBCAddress(), fedAddress, gas) | ||
q := parseReqToQuote(qr, s.rsk.GetLBCAddress(), fedAddress, gas, daoFeeAmount) | ||
pq, err := s.provider.GetQuote(q, gas, types.NewBigWei(price)) | ||
if err != nil { | ||
log.Error("error getting quote: ", err) | ||
|
@@ -879,7 +889,6 @@ func (s *Server) getQuoteHandler(w http.ResponseWriter, r *http.Request) { | |
} | ||
|
||
hash, err := s.storeQuote(pq) | ||
|
||
if err != nil { | ||
log.Error(err) | ||
errmsg := ErrorStoringProviderQuote + ": " + err.Error() | ||
|
@@ -989,7 +998,19 @@ func (s *Server) getPegoutQuoteHandler(w http.ResponseWriter, r *http.Request) { | |
|
||
getQuoteFailed := false | ||
amountBelowMinLockTxValue := false | ||
q := parseReqToPegOutQuote(qr, s.rsk.GetLBCAddress()) | ||
|
||
daoFeePercentage, err := s.rsk.GetDaoFeePercentage() | ||
|
||
if err != nil { | ||
log.Error(ErrorRetrievingDaoFeePercentage, err.Error()) | ||
customError := NewServerError(ErrorRetrievingDaoFeePercentage, make(map[string]interface{}), true) | ||
ResponseError(w, customError, http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
daoFeeAmount := qr.ValueToTransfer * daoFeePercentage / 100 | ||
Luisfc68 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
q := parseReqToPegOutQuote(qr, s.rsk.GetLBCAddress(), daoFeeAmount) | ||
rskBlockNumber, err := s.rsk.GetRskHeight() | ||
if err != nil { | ||
log.Error("Error getting last block", err.Error()) | ||
|
@@ -1195,26 +1216,28 @@ func (s *Server) acceptQuoteHandler(w http.ResponseWriter, r *http.Request) { | |
returnQuoteSignFunc(w, signature, depositAddress) | ||
} | ||
|
||
func parseReqToQuote(qr QuoteRequest, lbcAddr string, fedAddr string, limitGas uint64) *pegin.Quote { | ||
func parseReqToQuote(qr QuoteRequest, lbcAddr string, fedAddr string, limitGas uint64, daoFeeAmount uint64) *pegin.Quote { | ||
return &pegin.Quote{ | ||
LBCAddr: lbcAddr, | ||
FedBTCAddr: fedAddr, | ||
BTCRefundAddr: qr.BitcoinRefundAddress, | ||
RSKRefundAddr: qr.RskRefundAddress, | ||
ContractAddr: qr.CallEoaOrContractAddress, | ||
Data: qr.CallContractArguments, | ||
Value: types.NewWei(int64(qr.ValueToTransfer)), | ||
GasLimit: uint32(limitGas), | ||
LBCAddr: lbcAddr, | ||
FedBTCAddr: fedAddr, | ||
BTCRefundAddr: qr.BitcoinRefundAddress, | ||
RSKRefundAddr: qr.RskRefundAddress, | ||
ContractAddr: qr.CallEoaOrContractAddress, | ||
Data: qr.CallContractArguments, | ||
Value: types.NewWei(int64(qr.ValueToTransfer)), | ||
GasLimit: uint32(limitGas), | ||
ProductFeeAmount: daoFeeAmount, | ||
} | ||
} | ||
|
||
func parseReqToPegOutQuote(qr QuotePegOutRequest, lbcAddr string) *pegout.Quote { | ||
func parseReqToPegOutQuote(qr QuotePegOutRequest, lbcAddr string, productFeeAmount uint64) *pegout.Quote { | ||
return &pegout.Quote{ | ||
LBCAddr: lbcAddr, | ||
BtcRefundAddr: qr.BitcoinRefundAddress, | ||
RSKRefundAddr: qr.RskRefundAddress, | ||
DepositAddr: qr.To, | ||
Value: types.NewWei(int64(qr.ValueToTransfer)), | ||
LBCAddr: lbcAddr, | ||
BtcRefundAddr: qr.BitcoinRefundAddress, | ||
RSKRefundAddr: qr.RskRefundAddress, | ||
DepositAddr: qr.To, | ||
Value: types.NewWei(int64(qr.ValueToTransfer)), | ||
ProductFeeAmount: productFeeAmount, | ||
} | ||
} | ||
|
||
|
@@ -1260,6 +1283,7 @@ func getPegOutProviderByAddress(liquidityProviders []pegout.LiquidityProvider, a | |
} | ||
|
||
func (s *Server) storeQuote(q *pegin.Quote) (string, error) { | ||
log.Debug(q.ProductFeeAmount) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls delete this or add more context to the message |
||
h, err := s.rsk.HashQuote(q) | ||
if err != nil { | ||
return "", err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you parse using wei here and above you parse using big int directly?