Skip to content

Commit

Permalink
feat: add legacy transaction builder
Browse files Browse the repository at this point in the history
  • Loading branch information
EnoRage committed Apr 4, 2024
1 parent 55f321e commit 2c9e4be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
.vscode/
/tmp
/bin
5 changes: 1 addition & 4 deletions aggregation/aggregation.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -79,4 +76,4 @@ func NewDefaultWalletConfiguration(nodeUrl string, privateKey string, chainId ui
return &WalletConfiguration{
Wallet: w,
}, nil
}
}
24 changes: 24 additions & 0 deletions aggregation/web3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 2c9e4be

Please sign in to comment.