feat(wallet)_: upgrade paraswap client to v6.2

This commit is contained in:
Dario Gabriel Lipicar 2024-07-24 13:21:11 -03:00 committed by dlipicar
parent 84928e218f
commit 0809c0b156
6 changed files with 49 additions and 39 deletions

View File

@ -197,16 +197,15 @@ func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams) (uint64
} }
func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams) (address common.Address, err error) { func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams) (address common.Address, err error) {
if params.FromChain.ChainID == walletCommon.EthereumMainnet { key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol)
address = common.HexToAddress("0x216b4b4ba9f3e719726886d34a177484278bfcae") priceRouteIns, ok := s.priceRoute.Load(key)
} else if params.FromChain.ChainID == walletCommon.ArbitrumMainnet { if !ok {
address = common.HexToAddress("0x216b4b4ba9f3e719726886d34a177484278bfcae") err = ErrPriceRouteNotFound
} else if params.FromChain.ChainID == walletCommon.OptimismMainnet { return
address = common.HexToAddress("0x216b4b4ba9f3e719726886d34a177484278bfcae")
} else {
err = ErrContractNotFound
} }
return priceRoute := priceRouteIns.(*paraswap.Route)
return priceRoute.TokenTransferProxy, nil
} }
func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error { func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error {

View File

@ -21,14 +21,16 @@ import (
func TestParaswapWithPartnerFee(t *testing.T) { func TestParaswapWithPartnerFee(t *testing.T) {
testPriceRoute := &paraswap.Route{ testPriceRoute := &paraswap.Route{
GasCost: &bigint.BigInt{Int: big.NewInt(500)}, GasCost: &bigint.BigInt{Int: big.NewInt(500)},
SrcAmount: &bigint.BigInt{Int: big.NewInt(1000)}, SrcAmount: &bigint.BigInt{Int: big.NewInt(1000)},
SrcTokenAddress: common.HexToAddress("0x123"), SrcTokenAddress: common.HexToAddress("0x123"),
SrcTokenDecimals: 18, SrcTokenDecimals: 18,
DestAmount: &bigint.BigInt{Int: big.NewInt(2000)}, DestAmount: &bigint.BigInt{Int: big.NewInt(2000)},
DestTokenAddress: common.HexToAddress("0x465"), DestTokenAddress: common.HexToAddress("0x465"),
DestTokenDecimals: 6, DestTokenDecimals: 6,
Side: paraswap.SellSide, Side: paraswap.SellSide,
ContractAddress: common.HexToAddress("0x789"),
TokenTransferProxy: common.HexToAddress("0xabc"),
} }
processor := NewSwapParaswapProcessor(nil, nil, nil) processor := NewSwapParaswapProcessor(nil, nil, nil)
@ -72,6 +74,11 @@ func TestParaswapWithPartnerFee(t *testing.T) {
require.NotNil(t, amountOut) require.NotNil(t, amountOut)
require.Equal(t, testPriceRoute.DestAmount.Uint64(), amountOut.Uint64()) require.Equal(t, testPriceRoute.DestAmount.Uint64(), amountOut.Uint64())
} }
// Check contract address
contractAddress, err := processor.GetContractAddress(testInputParams)
require.NoError(t, err)
require.Equal(t, testPriceRoute.TokenTransferProxy, contractAddress)
} }
} }

View File

@ -12,7 +12,7 @@ import (
walletCommon "github.com/status-im/status-go/services/wallet/common" walletCommon "github.com/status-im/status-go/services/wallet/common"
) )
const transactionsURL = "https://apiv5.paraswap.io/transactions/%d" const transactionsURL = "https://api.paraswap.io/transactions/%d"
type Transaction struct { type Transaction struct {
From string `json:"from"` From string `json:"from"`

View File

@ -13,18 +13,20 @@ import (
"github.com/status-im/status-go/services/wallet/bigint" "github.com/status-im/status-go/services/wallet/bigint"
) )
const pricesURL = "https://apiv5.paraswap.io/prices" const pricesURL = "https://api.paraswap.io/prices"
type Route struct { type Route struct {
GasCost *bigint.BigInt `json:"gasCost"` GasCost *bigint.BigInt `json:"gasCost"`
SrcAmount *bigint.BigInt `json:"srcAmount"` SrcAmount *bigint.BigInt `json:"srcAmount"`
SrcTokenAddress common.Address `json:"srcToken"` SrcTokenAddress common.Address `json:"srcToken"`
SrcTokenDecimals uint `json:"srcDecimals"` SrcTokenDecimals uint `json:"srcDecimals"`
DestAmount *bigint.BigInt `json:"destAmount"` DestAmount *bigint.BigInt `json:"destAmount"`
DestTokenAddress common.Address `json:"destToken"` DestTokenAddress common.Address `json:"destToken"`
DestTokenDecimals uint `json:"destDecimals"` DestTokenDecimals uint `json:"destDecimals"`
RawPriceRoute json.RawMessage `json:"rawPriceRoute"` RawPriceRoute json.RawMessage `json:"rawPriceRoute"`
Side SwapSide `json:"side"` Side SwapSide `json:"side"`
ContractAddress common.Address `json:"contractAddress"`
TokenTransferProxy common.Address `json:"tokenTransferProxy"`
} }
type PriceRouteResponse struct { type PriceRouteResponse struct {
@ -48,7 +50,7 @@ func (c *ClientV5) FetchPriceRoute(ctx context.Context, srcTokenAddress common.A
params.Add("side", string(side)) params.Add("side", string(side))
params.Add("partner", c.partnerID) params.Add("partner", c.partnerID)
params.Add("excludeContractMethodsWithoutFeeModel", "true") params.Add("excludeContractMethodsWithoutFeeModel", "true")
params.Add("excludeDEXS", "AugustusRFQ") // This DEX causes issues when creating the transaction params.Add("version", "6.2")
url := pricesURL url := pricesURL
response, err := c.httpClient.DoGetRequest(ctx, url, params, nil) response, err := c.httpClient.DoGetRequest(ctx, url, params, nil)

View File

@ -101,15 +101,17 @@ func TestUnmarshallPriceRoute(t *testing.T) {
responseData := []byte(fmt.Sprintf(`{"priceRoute":%s}`, string(data))) responseData := []byte(fmt.Sprintf(`{"priceRoute":%s}`, string(data)))
route := Route{ route := Route{
GasCost: &bigint.BigInt{Int: big.NewInt(111435)}, GasCost: &bigint.BigInt{Int: big.NewInt(111435)},
SrcAmount: &bigint.BigInt{Int: big.NewInt(1000000000000000000)}, SrcAmount: &bigint.BigInt{Int: big.NewInt(1000000000000000000)},
SrcTokenAddress: common.HexToAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), SrcTokenAddress: common.HexToAddress("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
SrcTokenDecimals: 18, SrcTokenDecimals: 18,
DestAmount: &bigint.BigInt{Int: big.NewInt(1000000000000000000)}, DestAmount: &bigint.BigInt{Int: big.NewInt(1000000000000000000)},
DestTokenAddress: common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"), DestTokenAddress: common.HexToAddress("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
DestTokenDecimals: 18, DestTokenDecimals: 18,
Side: SellSide, Side: SellSide,
RawPriceRoute: data, RawPriceRoute: data,
ContractAddress: common.HexToAddress("0x485D2446711E141D2C8a94bC24BeaA5d5A110D74"),
TokenTransferProxy: common.HexToAddress("0x3e7d31751347BAacf35945074a4a4A41581B2271"),
} }
receivedRoute, err := handlePriceRouteResponse(responseData) receivedRoute, err := handlePriceRouteResponse(responseData)

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
) )
const tokensURL = "https://apiv5.paraswap.io/tokens/%d" // nolint: gosec const tokensURL = "https://api.paraswap.io/tokens/%d" // nolint: gosec
type Token struct { type Token struct {
Symbol string `json:"symbol"` Symbol string `json:"symbol"`