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,17 +197,16 @@ 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 {
address = common.HexToAddress("0x216b4b4ba9f3e719726886d34a177484278bfcae")
} else {
err = ErrContractNotFound
}
return return
} }
priceRoute := priceRouteIns.(*paraswap.Route)
return priceRoute.TokenTransferProxy, nil
}
func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error { func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error {
slippageBP := uint(sendArgs.SwapTx.SlippagePercentage * 100) // convert to basis points slippageBP := uint(sendArgs.SwapTx.SlippagePercentage * 100) // convert to basis points

View File

@ -29,6 +29,8 @@ func TestParaswapWithPartnerFee(t *testing.T) {
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,7 +13,7 @@ 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"`
@ -25,6 +25,8 @@ type Route struct {
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

@ -110,6 +110,8 @@ func TestUnmarshallPriceRoute(t *testing.T) {
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"`