-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore_: improvements of the sending route generated by the router pro…
…cess This commit simplifies the sending process of the best route suggested by the router. It also makes the sending process the same for accounts (key pairs) migrated to a keycard and those stored locally in local keystore files. Deprecated endpoints: - `CreateMultiTransaction` - `ProceedWithTransactionsSignatures` Deprecated signal: - `wallet.sign.transactions` New endpoints: - `BuildTransactionsFromRoute` - `SendRouterTransactionsWithSignatures` The flow for sending the best router suggested by the router: - call `BuildTransactionsFromRoute` - wait for the `wallet.router.sign-transactions` signal - sign received hashes using `SignMessage` call or sign on keycard - call `SendRouterTransactionsWithSignatures` with the signatures of signed hashes from the previous step - `wallet.router.transactions-sent` signal will be sent after sending transactions or an error occurs New signals: - `wallet.router.sending-transactions-started` - `wallet.router.sign-transactions` - `wallet.router.transactions-sent`
- Loading branch information
1 parent
c1ce30a
commit 89503c9
Showing
37 changed files
with
1,301 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/status-im/status-go/contracts/ierc20" | ||
) | ||
|
||
func PackApprovalInputData(amountIn *big.Int, approvalContractAddress *common.Address) ([]byte, error) { | ||
if approvalContractAddress == nil || *approvalContractAddress == ZeroAddress { | ||
return []byte{}, nil | ||
} | ||
|
||
erc20ABI, err := abi.JSON(strings.NewReader(ierc20.IERC20ABI)) | ||
if err != nil { | ||
return []byte{}, err | ||
} | ||
|
||
return erc20ABI.Pack("approve", approvalContractAddress, amountIn) | ||
} | ||
|
||
func GetTokenIdFromSymbol(symbol string) (*big.Int, error) { | ||
id, success := big.NewInt(0).SetString(symbol, 0) | ||
if !success { | ||
return nil, fmt.Errorf("failed to convert %s to big.Int", symbol) | ||
} | ||
return id, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package wallet | ||
|
||
import ( | ||
"github.com/status-im/status-go/errors" | ||
) | ||
|
||
// Abbreviation `W` for the error code stands for Wallet | ||
var ( | ||
ErrCannotResolveRouteId = &errors.ErrorResponse{Code: errors.ErrorCode("W-001"), Details: "cannot resolve route id"} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package requests | ||
|
||
type RouterBuildTransactionsParams struct { | ||
Uuid string `json:"uuid"` | ||
SlippagePercentage float32 `json:"slippagePercentage"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package requests | ||
|
||
import "github.com/status-im/status-go/services/wallet/transfer" | ||
|
||
type RouterSendTransactionsParams struct { | ||
Uuid string `json:"uuid"` | ||
Signatures map[string]transfer.SignatureDetails `json:"signatures"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package responses | ||
|
||
import ( | ||
"github.com/status-im/status-go/errors" | ||
"github.com/status-im/status-go/eth-node/types" | ||
"github.com/status-im/status-go/transactions" | ||
) | ||
|
||
type SendDetails struct { | ||
Uuid string `json:"uuid"` | ||
SendType int `json:"sendType"` | ||
FromAddress types.Address `json:"fromAddress"` | ||
ToAddress types.Address `json:"toAddress"` | ||
FromToken string `json:"fromToken"` | ||
ToToken string `json:"toToken"` | ||
FromAmount string `json:"fromAmount"` // total amount | ||
ToAmount string `json:"toAmount"` | ||
OwnerTokenBeingSent bool `json:"ownerTokenBeingSent"` | ||
ErrorResponse *errors.ErrorResponse `json:"errorResponse,omitempty"` | ||
} | ||
|
||
type SigningDetails struct { | ||
Address types.Address `json:"address"` | ||
AddressPath string `json:"addressPath"` | ||
KeyUid string `json:"keyUid"` | ||
SignOnKeycard bool `json:"signOnKeycard"` | ||
Hashes []types.Hash `json:"hashes"` | ||
} | ||
|
||
type RouterTransactionsForSigning struct { | ||
SendDetails *SendDetails `json:"sendDetails"` | ||
SigningDetails *SigningDetails `json:"signingDetails"` | ||
} | ||
|
||
type RouterSentTransaction struct { | ||
FromAddress types.Address `json:"fromAddress"` | ||
ToAddress types.Address `json:"toAddress"` | ||
FromChain uint64 `json:"fromChain"` | ||
ToChain uint64 `json:"toChain"` | ||
FromToken string `json:"fromToken"` | ||
ToToken string `json:"toToken"` | ||
Amount string `json:"amount"` // amount of the transaction | ||
Hash types.Hash `json:"hash"` | ||
ApprovalTx bool `json:"approvalTx"` | ||
} | ||
|
||
type RouterSentTransactions struct { | ||
SendDetails *SendDetails `json:"sendDetails"` | ||
SentTransactions []*RouterSentTransaction `json:"sentTransactions"` | ||
} | ||
|
||
func NewRouterSentTransaction(sendArgs *transactions.SendTxArgs, hash types.Hash, approvalTx bool) *RouterSentTransaction { | ||
addr := types.Address{} | ||
if sendArgs.To != nil { | ||
addr = *sendArgs.To | ||
} | ||
return &RouterSentTransaction{ | ||
FromAddress: sendArgs.From, | ||
ToAddress: addr, | ||
FromChain: sendArgs.FromChainID, | ||
ToChain: sendArgs.ToChainID, | ||
FromToken: sendArgs.FromTokenID, | ||
ToToken: sendArgs.ToTokenID, | ||
Amount: sendArgs.Value.String(), | ||
Hash: hash, | ||
ApprovalTx: approvalTx, | ||
} | ||
} |
Oops, something went wrong.