Skip to content

Commit

Permalink
fix(wallet)_: broken swap and bridge for erc20 tokens fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
saledjenic committed Nov 8, 2024
1 parent edbcc9f commit fc6637e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions services/wallet/responses/router_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type RouterSentTransaction struct {
FromToken string `json:"fromToken"`
ToToken string `json:"toToken"`
Amount string `json:"amount"` // amount sent
AmountIn string `json:"amountIn"` // amount that is "data" of tx (important for erc20 tokens)
AmountOut string `json:"amountOut"` // amount that will be received
Hash types.Hash `json:"hash"`
ApprovalTx bool `json:"approvalTx"`
Expand All @@ -68,6 +69,7 @@ func NewRouterSentTransaction(sendArgs *wallettypes.SendTxArgs, hash types.Hash,
FromToken: sendArgs.FromTokenID,
ToToken: sendArgs.ToTokenID,
Amount: sendArgs.Value.String(),
AmountIn: sendArgs.ValueIn.String(),
AmountOut: sendArgs.ValueOut.String(),
Hash: hash,
ApprovalTx: approvalTx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, sig
return tx, createBridgeHopErrorResponse(err)
}

bonderKey := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "", (*big.Int)(sendArgs.Value))
bonderKey := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "", (*big.Int)(sendArgs.ValueIn))
bonderFeeIns, ok := h.bonderFee.Load(bonderKey)
if !ok {
return nil, ErrNoBonderFeeFound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams)
func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error {
slippageBP := uint(sendArgs.SwapTx.SlippagePercentage * 100) // convert to basis points

key := makeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo, sendArgs.SwapTx.Value.ToInt())
key := makeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo, sendArgs.SwapTx.ValueIn.ToInt())
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
return ErrPriceRouteNotFound
Expand Down Expand Up @@ -259,7 +259,7 @@ func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorT
func (s *SwapParaswapProcessor) prepareTransactionV2(sendArgs *wallettypes.SendTxArgs) error {
slippageBP := uint(sendArgs.SlippagePercentage * 100) // convert to basis points

key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.Value.ToInt())
key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.ValueIn.ToInt())
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
return ErrPriceRouteNotFound
Expand Down
1 change: 1 addition & 0 deletions services/wallet/transfer/transaction_manager_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func buildTxForPath(transactor transactions.TransactorIface, path *routes.Path,
MaxPriorityFeePerGas: path.TxPriorityFee,

// additional fields version 1
ValueIn: path.AmountIn,
ValueOut: path.AmountOut,
FromChainID: path.FromChain.ChainID,
ToChainID: path.ToChain.ChainID,
Expand Down
1 change: 1 addition & 0 deletions services/wallet/wallettypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type SendTxArgs struct {
MultiTransactionID wallet_common.MultiTransactionIDType `json:"multiTransactionID"`
Symbol string `json:"symbol"`
// additional data - version SendTxArgsVersion1
ValueIn *hexutil.Big `json:"valueIn"`
ValueOut *hexutil.Big `json:"valueOut"`
FromChainID uint64 `json:"fromChainID"`
ToChainID uint64 `json:"toChainID"`
Expand Down

0 comments on commit fc6637e

Please sign in to comment.