diff --git a/.gitignore b/.gitignore index 44ef32bd..2089eaaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ .vscode/ /tmp +/bin \ No newline at end of file diff --git a/aggregation/aggregation.go b/aggregation/aggregation.go index f3e82d33..af3b3b7a 100644 --- a/aggregation/aggregation.go +++ b/aggregation/aggregation.go @@ -1,9 +1,6 @@ package aggregation import ( - "context" - - "github.com/1inch/1inch-sdk-go/aggregation/models" "github.com/1inch/1inch-sdk-go/common" "github.com/1inch/1inch-sdk-go/internal/http_executor" @@ -79,4 +76,4 @@ func NewDefaultWalletConfiguration(nodeUrl string, privateKey string, chainId ui return &WalletConfiguration{ Wallet: w, }, nil -} \ No newline at end of file +} diff --git a/aggregation/web3.go b/aggregation/web3.go index 780dcfd5..0a986652 100644 --- a/aggregation/web3.go +++ b/aggregation/web3.go @@ -36,3 +36,27 @@ func (c Client) BuildSwapTransaction(d *models.SwapResponse, nonce uint64, gasTi GasFeeCap: gasFeeCap, }), nil } + +func (c Client) BuildSwapTransactionLegacy(d *models.SwapResponse, nonce uint64, gasPrice *big.Int) (*types.Transaction, error) { + to := gethCommon.HexToAddress(d.Tx.To) + + value := new(big.Int) + value, ok := value.SetString(d.Tx.Value, 10) + if !ok { + return nil, errors.New("failed to convert d.Tx.Value to big.Int") + } + + data, err := hex.DecodeString(d.Tx.Data[2:]) + if err != nil { + return nil, err + } + + return types.NewTx(&types.LegacyTx{ + Nonce: nonce, + GasPrice: gasPrice, + Gas: uint64(d.Tx.Gas), + To: &to, + Value: value, + Data: data, + }), nil +}