fix_: celar bridge fixes
This commit is contained in:
parent
12dfe285d7
commit
6f2b02cfdb
|
@ -29,8 +29,13 @@ import (
|
||||||
"github.com/status-im/status-go/transactions"
|
"github.com/status-im/status-go/transactions"
|
||||||
)
|
)
|
||||||
|
|
||||||
const baseURL = "https://cbridge-prod2.celer.app"
|
const (
|
||||||
const testBaseURL = "https://cbridge-v2-test.celer.network"
|
baseURL = "https://cbridge-prod2.celer.app"
|
||||||
|
testBaseURL = "https://cbridge-v2-test.celer.network"
|
||||||
|
|
||||||
|
maxSlippage = uint32(1000)
|
||||||
|
ethSymbol = "ETH"
|
||||||
|
)
|
||||||
|
|
||||||
type CBridgeTxArgs struct {
|
type CBridgeTxArgs struct {
|
||||||
transactions.SendTxArgs
|
transactions.SendTxArgs
|
||||||
|
@ -138,11 +143,11 @@ func (s *CBridge) AvailableFor(from, to *params.Network, token *token.Token, toT
|
||||||
var fromAvailable *cbridge.Chain
|
var fromAvailable *cbridge.Chain
|
||||||
var toAvailable *cbridge.Chain
|
var toAvailable *cbridge.Chain
|
||||||
for _, chain := range transferConfig.Chains {
|
for _, chain := range transferConfig.Chains {
|
||||||
if uint64(chain.GetId()) == from.ChainID {
|
if uint64(chain.GetId()) == from.ChainID && chain.GasTokenSymbol == ethSymbol {
|
||||||
fromAvailable = chain
|
fromAvailable = chain
|
||||||
}
|
}
|
||||||
|
|
||||||
if uint64(chain.GetId()) == to.ChainID {
|
if uint64(chain.GetId()) == to.ChainID && chain.GasTokenSymbol == ethSymbol {
|
||||||
toAvailable = chain
|
toAvailable = chain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +213,7 @@ func (c *CBridge) PackTxInputData(contractType string, fromNetwork *params.Netwo
|
||||||
amountIn,
|
amountIn,
|
||||||
toNetwork.ChainID,
|
toNetwork.ChainID,
|
||||||
uint64(time.Now().UnixMilli()),
|
uint64(time.Now().UnixMilli()),
|
||||||
500,
|
maxSlippage,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return abi.Pack("send",
|
return abi.Pack("send",
|
||||||
|
@ -217,7 +222,7 @@ func (c *CBridge) PackTxInputData(contractType string, fromNetwork *params.Netwo
|
||||||
amountIn,
|
amountIn,
|
||||||
toNetwork.ChainID,
|
toNetwork.ChainID,
|
||||||
uint64(time.Now().UnixMilli()),
|
uint64(time.Now().UnixMilli()),
|
||||||
500,
|
maxSlippage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,8 +256,15 @@ func (s *CBridge) EstimateGas(fromNetwork *params.Network, toNetwork *params.Net
|
||||||
|
|
||||||
estimation, err := ethClient.EstimateGas(ctx, msg)
|
estimation, err := ethClient.EstimateGas(ctx, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if !token.IsNative() {
|
||||||
|
// TODO: this is a temporary solution until we find a better way to estimate the gas
|
||||||
|
// hardcoding the estimation for other than ETH, cause we cannot get a proper estimation without having an approval placed first
|
||||||
|
// this is an error we're facing otherwise: `execution reverted: ERC20: transfer amount exceeds allowance`
|
||||||
|
estimation = 350000
|
||||||
|
} else {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
|
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
|
||||||
return uint64(increasedEstimation), nil
|
return uint64(increasedEstimation), nil
|
||||||
}
|
}
|
||||||
|
@ -327,7 +339,7 @@ func (s *CBridge) sendOrBuild(sendArgs *TransactionBridge, signerFn bind.SignerF
|
||||||
(*big.Int)(sendArgs.CbridgeTx.Amount),
|
(*big.Int)(sendArgs.CbridgeTx.Amount),
|
||||||
sendArgs.CbridgeTx.ChainID,
|
sendArgs.CbridgeTx.ChainID,
|
||||||
uint64(time.Now().UnixMilli()),
|
uint64(time.Now().UnixMilli()),
|
||||||
500,
|
maxSlippage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +350,7 @@ func (s *CBridge) sendOrBuild(sendArgs *TransactionBridge, signerFn bind.SignerF
|
||||||
(*big.Int)(sendArgs.CbridgeTx.Amount),
|
(*big.Int)(sendArgs.CbridgeTx.Amount),
|
||||||
sendArgs.CbridgeTx.ChainID,
|
sendArgs.CbridgeTx.ChainID,
|
||||||
uint64(time.Now().UnixMilli()),
|
uint64(time.Now().UnixMilli()),
|
||||||
500,
|
maxSlippage,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue