diff --git a/golang/client/client.go b/golang/client/client.go index bc83af94..a3ea2b47 100644 --- a/golang/client/client.go +++ b/golang/client/client.go @@ -172,13 +172,13 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt err = json.Unmarshal(data, &messageMap) if err != nil { // Fallback to raw string if unmarshalling fails - return nil, fmt.Errorf("failed to unmarshal response body: %s", string(data)) + return nil, fmt.Errorf("failed to unmarshal response body - response code: %d - raw response body: %s", resp.StatusCode, string(data)) } // Marshal the message with indentation formattedMessage, err := json.MarshalIndent(messageMap, "", " ") if err != nil { - return nil, fmt.Errorf("failed to marshal formatted message: %v - Original error: %s", err, string(data)) + return nil, fmt.Errorf("failed to marshal formatted message: %v - original error: %s", err, string(data)) } return nil, fmt.Errorf("%s", formattedMessage) diff --git a/golang/client/onchain/onchain.go b/golang/client/onchain/onchain.go index 05dd304a..24990dae 100644 --- a/golang/client/onchain/onchain.go +++ b/golang/client/onchain/onchain.go @@ -8,9 +8,6 @@ import ( "strings" "time" - "github.com/1inch/1inch-sdk/golang/helpers" - "github.com/1inch/1inch-sdk/golang/helpers/consts/amounts" - "github.com/1inch/1inch-sdk/golang/helpers/consts/chains" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" @@ -18,7 +15,10 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethclient" - "github.com/1inch/1inch-sdk/golang/helpers/consts/contracts" + "github.com/1inch/1inch-sdk/golang/helpers" + "github.com/1inch/1inch-sdk/golang/helpers/consts/abis" + "github.com/1inch/1inch-sdk/golang/helpers/consts/amounts" + "github.com/1inch/1inch-sdk/golang/helpers/consts/chains" ) const gasLimit = uint64(21000000) // TODO make sure this value more dynamic @@ -143,7 +143,7 @@ func GetLegacyTx(client *ethclient.Client, nonce uint64, to string, value *big.I // ReadContractName reads the 'name' public variable from a contract. func ReadContractName(client *ethclient.Client, contractAddress common.Address) (string, error) { - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) // Make a generic version of this ABI + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) // Make a generic version of this ABI if err != nil { return "", err } @@ -172,7 +172,7 @@ func ReadContractName(client *ethclient.Client, contractAddress common.Address) // ReadContractSymbol reads the 'symbol' public variable from a contract. func ReadContractSymbol(client *ethclient.Client, contractAddress common.Address) (string, error) { - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) // Make a generic version of this ABI + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) // Make a generic version of this ABI if err != nil { return "", err } @@ -201,7 +201,7 @@ func ReadContractSymbol(client *ethclient.Client, contractAddress common.Address // ReadContractDecimals reads the 'decimals' public variable from a contract. func ReadContractDecimals(client *ethclient.Client, contractAddress common.Address) (uint8, error) { - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) // Make a generic version of this ABI + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) // Make a generic version of this ABI if err != nil { return 0, err } @@ -230,7 +230,7 @@ func ReadContractDecimals(client *ethclient.Client, contractAddress common.Addre // ReadContractNonce reads the 'nonces' public variable from a contract. func ReadContractNonce(client *ethclient.Client, publicAddress common.Address, contractAddress common.Address) (int64, error) { - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) // Make a generic version of this ABI + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) // Make a generic version of this ABI if err != nil { return -1, err } @@ -263,7 +263,7 @@ func ReadContractNonce(client *ethclient.Client, publicAddress common.Address, c // ReadContractAllowance reads the allowance a given contract has for a wallet. func ReadContractAllowance(client *ethclient.Client, erc20Address common.Address, publicAddress common.Address, spenderAddress common.Address) (*big.Int, error) { - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) // Make a generic version of this ABI + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) // Make a generic version of this ABI if err != nil { return nil, err } @@ -297,7 +297,7 @@ func ReadContractAllowance(client *ethclient.Client, erc20Address common.Address func GetTypeHash(client *ethclient.Client, addressAsString string) (string, error) { // Pack the call to get the PERMIT_TYPEHASH constant // Parse the ABI - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) if err != nil { return "", fmt.Errorf("failed to parse contract ABI: %v", err) } @@ -338,7 +338,7 @@ func GetTypeHash(client *ethclient.Client, addressAsString string) (string, erro func ApproveTokenForRouter(client *ethclient.Client, nonceCache map[string]uint64, config Erc20ApprovalConfig) error { // Parse the USDC contract ABI to get the 'Approve' function signature - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) if err != nil { return fmt.Errorf("failed to parse USDC ABI: %v", err) } @@ -365,9 +365,114 @@ func ApproveTokenForRouter(client *ethclient.Client, nonceCache map[string]uint6 return nil } +func GetTimestampBelowCalldata(expiration int64) ([]byte, error) { + + expiration = time.Now().UnixMilli() + + parsedABI, err := abi.JSON(strings.NewReader(abis.SeriesNonceManager)) + if err != nil { + return nil, fmt.Errorf("failed to parse ABI: %v", err) + } + + // Pack the transaction data with the method signature and parameters + data, err := parsedABI.Pack("timestampBelow", big.NewInt(expiration)) + if err != nil { + return nil, fmt.Errorf("failed to pack data: %v", err) + } + + return data, nil +} + +func GetTimeSeriesManagerNonce(client *ethclient.Client, seriesNonceManager string, publicAddress string) (*big.Int, error) { + + function := "nonce" + + parsedABI, err := abi.JSON(strings.NewReader(abis.SeriesNonceManager)) + if err != nil { + return nil, fmt.Errorf("failed to parse ABI: %v", err) + } + + // Pack the transaction data with the method signature and parameters + data, err := parsedABI.Pack(function, big.NewInt(0), common.HexToAddress(publicAddress)) + if err != nil { + return nil, fmt.Errorf("failed to pack data: %v", err) + } + + address := common.HexToAddress(seriesNonceManager) + + // Create the call message + msg := ethereum.CallMsg{ + To: &address, + Data: data, + } + + // Query the blockchain + result, err := client.CallContract(context.Background(), msg, nil) + if err != nil { + return nil, fmt.Errorf("failed to retrieve the PERMIT_TYPEHASH: %v", err) + } + + // Unpack the result + var nonce *big.Int + err = parsedABI.UnpackIntoInterface(&nonce, function, result) + if err != nil { + return nil, err + } + + return nonce, nil +} + +func GetTimestampBelowAndNonceEqualsCalldata(expiration int64, nonce *big.Int, publicAddress string) ([]byte, error) { + var ( + timeInt = new(big.Int).SetUint64(uint64(expiration)) + nonceInt = new(big.Int).SetUint64(nonce.Uint64()) + seriesInt = new(big.Int).SetUint64(uint64(0)) // Limit orders have a static series of 0 + accountInt = new(big.Int) + ) + + accountInt.SetString(publicAddress[2:], 16) + + timeInt.Lsh(timeInt, 216) + nonceInt.Lsh(nonceInt, 176) + seriesInt.Lsh(seriesInt, 160) + + result := new(big.Int) + result.Or(result, timeInt) + result.Or(result, nonceInt) + result.Or(result, seriesInt) + result.Or(result, accountInt) + + parsedABI, err := abi.JSON(strings.NewReader(abis.SeriesNonceManager)) + if err != nil { + return nil, fmt.Errorf("failed to parse ABI: %v", err) + } + + data, err := parsedABI.Pack("timestampBelowAndNonceEquals", result) + if err != nil { + return nil, fmt.Errorf("failed to pack data: %v", err) + } + + return data, nil +} + +func GetPredicateCalldata(seriesNonceManager string, getTimestampBelowAndNonceEqualsCalldata []byte) ([]byte, error) { + parsedABI, err := abi.JSON(strings.NewReader(abis.AggregationRouterV5)) + if err != nil { + return nil, fmt.Errorf("failed to parse ABI: %v", err) + } + + // Pack the transaction data with the method signature and parameters + data, err := parsedABI.Pack("arbitraryStaticCall", common.HexToAddress(seriesNonceManager), getTimestampBelowAndNonceEqualsCalldata) + if err != nil { + return nil, fmt.Errorf("failed to pack data: %v", err) + } + + return data, nil +} + func RevokeApprovalForRouter(client *ethclient.Client, nonceCache map[string]uint64, config Erc20RevokeConfig) error { // Parse the USDC contract ABI to get the 'Approve' function signature - parsedABI, err := abi.JSON(strings.NewReader(contracts.Erc20Abi)) + parsedABI, err := abi.JSON(strings.NewReader(abis.Erc20)) if err != nil { return fmt.Errorf("failed to parse ABI: %v", err) } diff --git a/golang/client/orderbook.go b/golang/client/orderbook.go index 1d1d27b1..4fc3d31f 100644 --- a/golang/client/orderbook.go +++ b/golang/client/orderbook.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "net/http" + "time" "github.com/ethereum/go-ethereum/common" @@ -27,6 +28,11 @@ func (s *OrderbookService) CreateOrder(ctx context.Context, params orderbook.Cre return nil, nil, err } + // Orders only last one minute if not specified in the request + if params.ExpireAfter == 0 { + params.ExpireAfter = time.Now().Add(time.Minute).Unix() + } + // To post an order that is open to anyone, the taker address must be the zero address if params.Taker == "" { params.Taker = addresses.Zero @@ -77,7 +83,17 @@ func (s *OrderbookService) CreateOrder(ctx context.Context, params orderbook.Cre } } - order, err := orderbook.CreateLimitOrder(params) + seriesNonceManager, err := contracts.GetSeriesNonceManagerFromChainId(params.ChainId) + if err != nil { + return nil, nil, fmt.Errorf("failed to get series nonce manager address: %v", err) + } + + interactions, err := orderbook.GetInteractions(ethClient, seriesNonceManager, params.ExpireAfter, params.Maker) + if err != nil { + return nil, nil, fmt.Errorf("failed to get interactions: %v", err) + } + + order, err := orderbook.CreateLimitOrderMessage(params, interactions) if err != nil { return nil, nil, err } diff --git a/golang/client/orderbook/contracts.go b/golang/client/orderbook/contracts.go deleted file mode 100644 index 47d4f2cb..00000000 --- a/golang/client/orderbook/contracts.go +++ /dev/null @@ -1,6 +0,0 @@ -package orderbook - -const ( - nonceManagerAddress = `0x303389f541ff2d620e42832f180a08e767b28e10` - nonceManagerAbi = `[{"inputs":[],"name":"AdvanceNonceFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"maker","type":"address"},{"indexed":false,"internalType":"uint256","name":"series","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newNonce","type":"uint256"}],"name":"NonceIncreased","type":"event"},{"inputs":[{"internalType":"uint256","name":"series","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"advanceNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"series","type":"uint8"}],"name":"increaseNonce","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"series","type":"uint256"},{"internalType":"address","name":"makerAddress","type":"address"},{"internalType":"uint256","name":"makerNonce","type":"uint256"}],"name":"nonceEquals","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"time","type":"uint256"}],"name":"timestampBelow","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"timeNonceSeriesAccount","type":"uint256"}],"name":"timestampBelowAndNonceEquals","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]` -) diff --git a/golang/client/orderbook/limitorder.go b/golang/client/orderbook/limitorder.go index 003d06ed..3444fba0 100644 --- a/golang/client/orderbook/limitorder.go +++ b/golang/client/orderbook/limitorder.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io" + "math/big" "os" "strings" "time" @@ -23,7 +24,9 @@ type Client struct { EthClient *ethclient.Client } -func CreateLimitOrder(orderRequest CreateOrderParams) (*Order, error) { +func CreateLimitOrderMessage(orderRequest CreateOrderParams, interactions []string) (*Order, error) { + + offsets := getOffsets(interactions) orderData := OrderData{ MakerAsset: orderRequest.MakerAsset, @@ -34,8 +37,8 @@ func CreateLimitOrder(orderRequest CreateOrderParams) (*Order, error) { Maker: orderRequest.Maker, AllowedSender: "0x0000000000000000000000000000000000000000", // TODO use this Receiver: orderRequest.Taker, - Offsets: "0", // TODO use this - Interactions: "0x", // TODO use this + Offsets: fmt.Sprintf("%v", offsets), + Interactions: interactions[4], // The 5th entry in this slice is the predicate and is the only field needed } aggregationRouter, err := contracts.Get1inchRouterFromChainId(orderRequest.ChainId) @@ -134,6 +137,60 @@ func CreateLimitOrder(orderRequest CreateOrderParams) (*Order, error) { }, err } +func GetInteractions(client *ethclient.Client, seriesNonceManager string, expiration int64, maker string) ([]string, error) { + + currentNonce, err := onchain.GetTimeSeriesManagerNonce(client, seriesNonceManager, maker) + if err != nil { + return nil, err + } + + timeBelowAndNonceEqualsCalldata, err := onchain.GetTimestampBelowAndNonceEqualsCalldata(expiration, currentNonce, maker) + + if err != nil { + return nil, fmt.Errorf("failed to get predicate calldata: %v", err) + } + + predicate, err := onchain.GetPredicateCalldata(seriesNonceManager, timeBelowAndNonceEqualsCalldata) + if err != nil { + return nil, fmt.Errorf("failed to get predicate calldata: %v", err) + } + + makerAssetData := `0x` + takerAssetData := `0x` + getMakingAmount := `0x` + getTakingAmount := `0x` + permit := `0x` + preInteraction := `0x` + postInteraction := `0x` + + return []string{makerAssetData, takerAssetData, getMakingAmount, getTakingAmount, fmt.Sprintf("0x%x", predicate), permit, preInteraction, postInteraction}, nil +} + +func getOffsets(interactions []string) *big.Int { + var lengthMap []int + for _, interaction := range interactions { + if interaction[:2] == "0x" { + lengthMap = append(lengthMap, len(interaction)/2-1) + } else { + lengthMap = append(lengthMap, len(interaction)/2) + } + } + + cumulativeSum := 0 + bytesAccumulator := big.NewInt(0) + var index uint64 + + for _, length := range lengthMap { + cumulativeSum += length + shiftVal := big.NewInt(int64(cumulativeSum)) + shiftVal.Lsh(shiftVal, uint(32*index)) // Shift left + bytesAccumulator.Add(bytesAccumulator, shiftVal) // Add to accumulator + index++ + } + + return bytesAccumulator +} + func ConfirmLimitOrderWithUser(order *Order, ethClient *ethclient.Client) (bool, error) { stdOut := helpers.StdOutPrinter{} return confirmLimitOrderWithUser(order, ethClient, os.Stdin, stdOut) diff --git a/golang/client/orderbook/limitorder_test.go b/golang/client/orderbook/limitorder_test.go index 8ed56198..b31a5ce8 100644 --- a/golang/client/orderbook/limitorder_test.go +++ b/golang/client/orderbook/limitorder_test.go @@ -130,6 +130,7 @@ func TestCreateLimitOrder(t *testing.T) { tests := []struct { name string orderRequest CreateOrderParams + interactions []string // TODO Revisit this to make it more encapsulated mockBigInt func(string) (*big.Int, error) expectedOrder *Order expectError bool @@ -145,14 +146,12 @@ func TestCreateLimitOrder(t *testing.T) { MakingAmount: "1000000", TakingAmount: "1000000000", Maker: "0x2c9b2DBdbA8A9c969Ac24153f5C1c23CB0e63914", - //AllowedSender: "0x0000000000000000000000000000000000000000", - Taker: "0x0000000000000000000000000000000000000000", - //Offsets: "0", - //Interactions: "0x", + Taker: "0x0000000000000000000000000000000000000000", }, + interactions: []string{"0x", "0x", "0x", "0x", "0xbf15fcd8000000000000000000000000a5eb255ef45dfb48b5d133d08833def69871691d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242cc2878d0071150dff0000000000000050c5df26654b5efbdd0c54a062dfa6012933defe00000000000000000000000000000000000000000000000000000000", "0x", "0x", "0x"}, expectedOrder: &Order{ - OrderHash: "0xaba6be89f39d5c6fce46648caaa974a0bc31a842b157b29a99f05d4c2fa7b781", - Signature: "0xfc1e704bcd719c076396f2e4795501aec5f50607ef8ec123d0f9306f9420b8543bcee9e934a86c8ecf1a57723463108568743b4c8da03f699a1127a46112e8371c", + OrderHash: "0xdc9344cfa6d3b4da5a2ad3283e02826d3f569b4472443390d3e1cfe86cacd13f", + Signature: "0x317ed3e021851542deeafb4897ef091b010317772b7299477121d0f46cdd32cf1403429b13d2337b459c7a982ac71144ceaad88dd08d5b7c7b8abbe1618070ab1b", Data: OrderData{ MakerAsset: "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063", TakerAsset: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619", @@ -162,8 +161,8 @@ func TestCreateLimitOrder(t *testing.T) { Maker: "0x2c9b2DBdbA8A9c969Ac24153f5C1c23CB0e63914", AllowedSender: "0x0000000000000000000000000000000000000000", Receiver: "0x0000000000000000000000000000000000000000", - Offsets: "0", - Interactions: "0x", + Offsets: "4421431254442149611168492388118363282642987198110904030635476664713216", + Interactions: "0xbf15fcd8000000000000000000000000a5eb255ef45dfb48b5d133d08833def69871691d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242cc2878d0071150dff0000000000000050c5df26654b5efbdd0c54a062dfa6012933defe00000000000000000000000000000000000000000000000000000000", }, }, expectError: false, @@ -178,11 +177,9 @@ func TestCreateLimitOrder(t *testing.T) { MakingAmount: "1000000", TakingAmount: "1000000000", Maker: "0x2c9b2DBdbA8A9c969Ac24153f5C1c23CB0e63914", - //AllowedSender: "0x0000000000000000000000000000000000000000", - Taker: "0x0000000000000000000000000000000000000000", - //Offsets: "0", - //Interactions: "0x", + Taker: "0x0000000000000000000000000000000000000000", }, + interactions: []string{"0x", "0x", "0x", "0x", "0xbf15fcd8000000000000000000000000a5eb255ef45dfb48b5d133d08833def69871691d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242cc2878d0071150dff0000000000000050c5df26654b5efbdd0c54a062dfa6012933defe00000000000000000000000000000000000000000000000000000000", "0x", "0x", "0x"}, expectError: true, expectedError: "error hashing typed data", }, @@ -196,11 +193,9 @@ func TestCreateLimitOrder(t *testing.T) { MakingAmount: "1000000", TakingAmount: "1000000000", Maker: "0x2c9b2DBdbA8A9c969Ac24153f5C1c23CB0e63914", - //AllowedSender: "0x0000000000000000000000000000000000000000", - Taker: "0x0000000000000000000000000000000000000000", - //Offsets: "0", - //Interactions: "0x", + Taker: "0x0000000000000000000000000000000000000000", }, + interactions: []string{"0x", "0x", "0x", "0x", "0xbf15fcd8000000000000000000000000a5eb255ef45dfb48b5d133d08833def69871691d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242cc2878d0071150dff0000000000000050c5df26654b5efbdd0c54a062dfa6012933defe00000000000000000000000000000000000000000000000000000000", "0x", "0x", "0x"}, expectError: true, expectedError: "error hashing typed data", }, @@ -214,11 +209,9 @@ func TestCreateLimitOrder(t *testing.T) { MakingAmount: "1000000", TakingAmount: "1000000000", Maker: "0x2c9b2DBdbA8A9c969Ac24153f5C1c23CB0e63914", - //AllowedSender: "0x0000000000000000000000000000000000000000", - Taker: "0x0000000000000000000000000000000000000000", - //Offsets: "0", - //Interactions: "0x", + Taker: "0x0000000000000000000000000000000000000000", }, + interactions: []string{"0x", "0x", "0x", "0x", "0xbf15fcd8000000000000000000000000a5eb255ef45dfb48b5d133d08833def69871691d000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000242cc2878d0071150dff0000000000000050c5df26654b5efbdd0c54a062dfa6012933defe00000000000000000000000000000000000000000000000000000000", "0x", "0x", "0x"}, expectError: true, expectedError: "error converting private key to ECDSA", }, @@ -233,7 +226,7 @@ func TestCreateLimitOrder(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - result, err := CreateLimitOrder(tc.orderRequest) + result, err := CreateLimitOrderMessage(tc.orderRequest, tc.interactions) if tc.expectError { assert.Error(t, err) diff --git a/golang/client/orderbook/orderbook_types.go b/golang/client/orderbook/orderbook_types.go index b90c3fbd..ff6d5ad4 100644 --- a/golang/client/orderbook/orderbook_types.go +++ b/golang/client/orderbook/orderbook_types.go @@ -8,6 +8,7 @@ import ( type CreateOrderParams struct { ChainId int PrivateKey string + ExpireAfter int64 Maker string MakerAsset string TakerAsset string @@ -22,6 +23,7 @@ func (params *CreateOrderParams) Validate() error { validationErrors = validate.Parameter(params.ChainId, "chainId", validate.CheckChainIdRequired, validationErrors) validationErrors = validate.Parameter(params.PrivateKey, "privateKey", validate.CheckPrivateKeyRequired, validationErrors) validationErrors = validate.Parameter(params.Maker, "maker", validate.CheckEthereumAddressRequired, validationErrors) + validationErrors = validate.Parameter(params.ExpireAfter, "expireAfter", validate.CheckExpireAfter, validationErrors) validationErrors = validate.Parameter(params.MakerAsset, "makerAsset", validate.CheckEthereumAddressRequired, validationErrors) validationErrors = validate.Parameter(params.TakerAsset, "takerAsset", validate.CheckEthereumAddressRequired, validationErrors) validationErrors = validate.Parameter(params.TakingAmount, "takingAmount", validate.CheckBigIntRequired, validationErrors) diff --git a/golang/client/orderbook/supplemented_types.go b/golang/client/orderbook/supplemented_types.go index c4225f31..dacc4773 100644 --- a/golang/client/orderbook/supplemented_types.go +++ b/golang/client/orderbook/supplemented_types.go @@ -3,7 +3,7 @@ package orderbook import "time" type CreateOrderResponse struct { - Success bool + Success bool `json:"success"` } type OrderResponse struct { diff --git a/golang/client/orderbook_e2e_test.go b/golang/client/orderbook_e2e_test.go index 9c1d29e0..a353bd33 100644 --- a/golang/client/orderbook_e2e_test.go +++ b/golang/client/orderbook_e2e_test.go @@ -1,6 +1,3 @@ -//go:build ignoretest -// +build ignoretest - package client import ( diff --git a/golang/client/orderbook_integration_test.go b/golang/client/orderbook_integration_test.go index 09977b58..e154c69c 100644 --- a/golang/client/orderbook_integration_test.go +++ b/golang/client/orderbook_integration_test.go @@ -1,6 +1,3 @@ -//go:build ignoretest -// +build ignoretest - package client import ( diff --git a/golang/client/swap_actions.go b/golang/client/swap_actions.go index 51e32ce9..0e9696c1 100644 --- a/golang/client/swap_actions.go +++ b/golang/client/swap_actions.go @@ -367,7 +367,7 @@ func getNativeTokenDetails(chainId int) *swap.TokenInfo { tokenSymbol = "AVAX" case chains.Base: tokenSymbol = "ETH" - case chains.BSC: + case chains.Bsc: tokenSymbol = "BNB" case chains.Ethereum: tokenSymbol = "ETH" diff --git a/golang/client/validate/validate.go b/golang/client/validate/validate.go index b091d1b6..8ae2cce8 100644 --- a/golang/client/validate/validate.go +++ b/golang/client/validate/validate.go @@ -5,6 +5,7 @@ import ( "math/big" "regexp" "strings" + "time" "github.com/1inch/1inch-sdk/golang/helpers" "github.com/1inch/1inch-sdk/golang/helpers/consts/chains" @@ -335,6 +336,8 @@ func CheckFee(parameter interface{}, variableName string) error { return nil } +// TODO The enforced naming pattern for the variable name string literal doesn't work for generic types like "Float32NonNegativeWhole" + func CheckFloat32NonNegativeWhole(parameter interface{}, variableName string) error { value, ok := parameter.(float32) if !ok { @@ -405,3 +408,18 @@ func CheckPermitHash(parameter interface{}, variableName string) error { } return nil } + +func CheckExpireAfter(parameter interface{}, variableName string) error { + value, ok := parameter.(int64) + if !ok { + return fmt.Errorf("for parameter '%v' to be validated as '%v', it must be a string", variableName, "ExpireAfter") + } + if value == 0 { + return nil + } + + if value < time.Now().Unix() { + return NewParameterValidationError(variableName, "must be a future timestamp") + } + return nil +} diff --git a/golang/client/validate/validate_test.go b/golang/client/validate/validate_test.go index e90e7429..f2561001 100644 --- a/golang/client/validate/validate_test.go +++ b/golang/client/validate/validate_test.go @@ -913,3 +913,36 @@ func TestCheckPermitHash(t *testing.T) { }) } } + +func TestExpireAfter(t *testing.T) { + testcases := []struct { + description string + value int64 + expectError bool + }{ + { + description: "Valid timestamp - empty", + value: 0, + }, + { + description: "Valid timestamp - year 2030", + value: 1897205247, + }, + { + description: "Invalid timestamp - past", + value: 1707791247, + expectError: true, + }, + } + + for _, tc := range testcases { + t.Run(tc.description, func(t *testing.T) { + err := CheckExpireAfter(tc.value, "testValue") + if tc.expectError { + require.Error(t, err, fmt.Sprintf("%s should have caused an error", tc.description)) + } else { + require.NoError(t, err, fmt.Sprintf("%s should not have caused an error", tc.description)) + } + }) + } +} diff --git a/golang/helpers/consts/abis/abis.go b/golang/helpers/consts/abis/abis.go new file mode 100644 index 00000000..f93d8219 --- /dev/null +++ b/golang/helpers/consts/abis/abis.go @@ -0,0 +1,12 @@ +package abis + +import _ "embed" + +//go:embed erc20.abi.json +var Erc20 string + +//go:embed seriesNonceManager.abi.json +var SeriesNonceManager string + +//go:embed aggregationRouterV5.abi.json +var AggregationRouterV5 string diff --git a/golang/helpers/consts/abis/aggregationRouterV5.abi.json b/golang/helpers/consts/abis/aggregationRouterV5.abi.json new file mode 100644 index 00000000..d3f0b23d --- /dev/null +++ b/golang/helpers/consts/abis/aggregationRouterV5.abi.json @@ -0,0 +1,2188 @@ +[ + { + "inputs": [ + { + "internalType": "contract IWETH", + "name": "weth", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "AccessDenied", + "type": "error" + }, + { + "inputs": [], + "name": "AdvanceNonceFailed", + "type": "error" + }, + { + "inputs": [], + "name": "AlreadyFilled", + "type": "error" + }, + { + "inputs": [], + "name": "ArbitraryStaticCallFailed", + "type": "error" + }, + { + "inputs": [], + "name": "BadPool", + "type": "error" + }, + { + "inputs": [], + "name": "BadSignature", + "type": "error" + }, + { + "inputs": [], + "name": "ETHTransferFailed", + "type": "error" + }, + { + "inputs": [], + "name": "ETHTransferFailed", + "type": "error" + }, + { + "inputs": [], + "name": "EmptyPools", + "type": "error" + }, + { + "inputs": [], + "name": "EthDepositRejected", + "type": "error" + }, + { + "inputs": [], + "name": "GetAmountCallFailed", + "type": "error" + }, + { + "inputs": [], + "name": "IncorrectDataLength", + "type": "error" + }, + { + "inputs": [], + "name": "InsufficientBalance", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidMsgValue", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidMsgValue", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidatedOrder", + "type": "error" + }, + { + "inputs": [], + "name": "MakingAmountExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "MakingAmountTooLow", + "type": "error" + }, + { + "inputs": [], + "name": "OnlyOneAmountShouldBeZero", + "type": "error" + }, + { + "inputs": [], + "name": "OrderExpired", + "type": "error" + }, + { + "inputs": [], + "name": "PermitLengthTooLow", + "type": "error" + }, + { + "inputs": [], + "name": "PredicateIsNotTrue", + "type": "error" + }, + { + "inputs": [], + "name": "PrivateOrder", + "type": "error" + }, + { + "inputs": [], + "name": "RFQBadSignature", + "type": "error" + }, + { + "inputs": [], + "name": "RFQPrivateOrder", + "type": "error" + }, + { + "inputs": [], + "name": "RFQSwapWithZeroAmount", + "type": "error" + }, + { + "inputs": [], + "name": "RFQZeroTargetIsForbidden", + "type": "error" + }, + { + "inputs": [], + "name": "ReentrancyDetected", + "type": "error" + }, + { + "inputs": [], + "name": "RemainingAmountIsZero", + "type": "error" + }, + { + "inputs": [], + "name": "ReservesCallFailed", + "type": "error" + }, + { + "inputs": [], + "name": "ReturnAmountIsNotEnough", + "type": "error" + }, + { + "inputs": [], + "name": "SafePermitBadLength", + "type": "error" + }, + { + "inputs": [], + "name": "SafeTransferFailed", + "type": "error" + }, + { + "inputs": [], + "name": "SafeTransferFromFailed", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bool", + "name": "success", + "type": "bool" + }, + { + "internalType": "bytes", + "name": "res", + "type": "bytes" + } + ], + "name": "SimulationResults", + "type": "error" + }, + { + "inputs": [], + "name": "SwapAmountTooLarge", + "type": "error" + }, + { + "inputs": [], + "name": "SwapWithZeroAmount", + "type": "error" + }, + { + "inputs": [], + "name": "TakingAmountExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "TakingAmountIncreased", + "type": "error" + }, + { + "inputs": [], + "name": "TakingAmountTooHigh", + "type": "error" + }, + { + "inputs": [], + "name": "TransferFromMakerToTakerFailed", + "type": "error" + }, + { + "inputs": [], + "name": "TransferFromTakerToMakerFailed", + "type": "error" + }, + { + "inputs": [], + "name": "UnknownOrder", + "type": "error" + }, + { + "inputs": [], + "name": "WrongAmount", + "type": "error" + }, + { + "inputs": [], + "name": "WrongGetter", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroAddress", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroMinReturn", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroReturnAmount", + "type": "error" + }, + { + "inputs": [], + "name": "ZeroTargetIsForbidden", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newNonce", + "type": "uint256" + } + ], + "name": "NonceIncreased", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "remainingRaw", + "type": "uint256" + } + ], + "name": "OrderCanceled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "remaining", + "type": "uint256" + } + ], + "name": "OrderFilled", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + } + ], + "name": "OrderFilledRFQ", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "amount", + "type": "uint8" + } + ], + "name": "advanceNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "and", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "arbitraryStaticCall", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order", + "type": "tuple" + } + ], + "name": "cancelOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "orderRemaining", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "orderInfo", + "type": "uint256" + } + ], + "name": "cancelOrderRFQ", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "orderInfo", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "additionalMask", + "type": "uint256" + } + ], + "name": "cancelOrderRFQ", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order", + "type": "tuple" + } + ], + "name": "checkPredicate", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IClipperExchangeInterface", + "name": "clipperExchange", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "dstToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "inputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "outputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "goodUntil", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "vs", + "type": "bytes32" + } + ], + "name": "clipperSwap", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IClipperExchangeInterface", + "name": "clipperExchange", + "type": "address" + }, + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "dstToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "inputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "outputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "goodUntil", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "vs", + "type": "bytes32" + } + ], + "name": "clipperSwapTo", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IClipperExchangeInterface", + "name": "clipperExchange", + "type": "address" + }, + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "dstToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "inputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "outputAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "goodUntil", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "vs", + "type": "bytes32" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + } + ], + "name": "clipperSwapToWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "destroy", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "eq", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "interaction", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "skipPermitAndThresholdAmount", + "type": "uint256" + } + ], + "name": "fillOrder", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + } + ], + "name": "fillOrderRFQ", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "vs", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + } + ], + "name": "fillOrderRFQCompact", + "outputs": [ + { + "internalType": "uint256", + "name": "filledMakingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "filledTakingAmount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "fillOrderRFQTo", + "outputs": [ + { + "internalType": "uint256", + "name": "filledMakingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "filledTakingAmount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "info", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + } + ], + "internalType": "struct OrderRFQLib.OrderRFQ", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "flagsAndAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + } + ], + "name": "fillOrderRFQToWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order_", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "interaction", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "skipPermitAndThresholdAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "fillOrderTo", + "outputs": [ + { + "internalType": "uint256", + "name": "actualMakingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "actualTakingAmount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "interaction", + "type": "bytes" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "skipPermitAndThresholdAmount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + } + ], + "name": "fillOrderToWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "gt", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "salt", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "takerAsset", + "type": "address" + }, + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "address", + "name": "allowedSender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "takingAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "interactions", + "type": "bytes" + } + ], + "internalType": "struct OrderLib.Order", + "name": "order", + "type": "tuple" + } + ], + "name": "hashOrder", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "increaseNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "internalType": "uint256", + "name": "slot", + "type": "uint256" + } + ], + "name": "invalidatorForOrderRFQ", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "lt", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonce", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "makerAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makerNonce", + "type": "uint256" + } + ], + "name": "nonceEquals", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "offsets", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "or", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "name": "remaining", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "orderHash", + "type": "bytes32" + } + ], + "name": "remainingRaw", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32[]", + "name": "orderHashes", + "type": "bytes32[]" + } + ], + "name": "remainingsRaw", + "outputs": [ + { + "internalType": "uint256[]", + "name": "", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "token", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "rescueFunds", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "simulate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IAggregationExecutor", + "name": "executor", + "type": "address" + }, + { + "components": [ + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "dstToken", + "type": "address" + }, + { + "internalType": "address payable", + "name": "srcReceiver", + "type": "address" + }, + { + "internalType": "address payable", + "name": "dstReceiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturnAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "flags", + "type": "uint256" + } + ], + "internalType": "struct GenericRouter.SwapDescription", + "name": "desc", + "type": "tuple" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "spentAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "timestampBelow", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "timeNonceAccount", + "type": "uint256" + } + ], + "name": "timestampBelowAndNonceEquals", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + } + ], + "name": "uniswapV3Swap", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "int256", + "name": "amount0Delta", + "type": "int256" + }, + { + "internalType": "int256", + "name": "amount1Delta", + "type": "int256" + }, + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "name": "uniswapV3SwapCallback", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + } + ], + "name": "uniswapV3SwapTo", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + } + ], + "name": "uniswapV3SwapToWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + } + ], + "name": "unoswap", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + } + ], + "name": "unoswapTo", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address payable", + "name": "recipient", + "type": "address" + }, + { + "internalType": "contract IERC20", + "name": "srcToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "minReturn", + "type": "uint256" + }, + { + "internalType": "uint256[]", + "name": "pools", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "permit", + "type": "bytes" + } + ], + "name": "unoswapToWithPermit", + "outputs": [ + { + "internalType": "uint256", + "name": "returnAmount", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "stateMutability": "payable", + "type": "receive" + } +] diff --git a/golang/helpers/consts/abis/erc20.abi.json b/golang/helpers/consts/abis/erc20.abi.json new file mode 100644 index 00000000..e15a5415 --- /dev/null +++ b/golang/helpers/consts/abis/erc20.abi.json @@ -0,0 +1,180 @@ +[ + { + "constant": true, + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "bytes", + "name": "signature", + "type": "bytes" + } + ], + "name": "permit", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "decrement", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/golang/helpers/consts/abis/seriesNonceManager.abi.json b/golang/helpers/consts/abis/seriesNonceManager.abi.json new file mode 100644 index 00000000..726e339b --- /dev/null +++ b/golang/helpers/consts/abis/seriesNonceManager.abi.json @@ -0,0 +1,154 @@ +[ + { + "inputs": [], + "name": "AdvanceNonceFailed", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "maker", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "series", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "newNonce", + "type": "uint256" + } + ], + "name": "NonceIncreased", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "series", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "advanceNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint8", + "name": "series", + "type": "uint8" + } + ], + "name": "increaseNonce", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonce", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "series", + "type": "uint256" + }, + { + "internalType": "address", + "name": "makerAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "makerNonce", + "type": "uint256" + } + ], + "name": "nonceEquals", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "time", + "type": "uint256" + } + ], + "name": "timestampBelow", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "timeNonceSeriesAccount", + "type": "uint256" + } + ], + "name": "timestampBelowAndNonceEquals", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/golang/helpers/consts/chains/chains.go b/golang/helpers/consts/chains/chains.go index e013d960..b63fa3f4 100644 --- a/golang/helpers/consts/chains/chains.go +++ b/golang/helpers/consts/chains/chains.go @@ -5,7 +5,7 @@ const ( Aurora = 1313161554 Avalanche = 43114 Base = 8453 - BSC = 56 + Bsc = 56 Ethereum = 1 Fantom = 250 Gnosis = 100 @@ -17,4 +17,4 @@ const ( // TODO Can I move this somewhere else to avoid conflicting with autocomplete? -var ValidChainIds = []int{Arbitrum, Aurora, Avalanche, Base, BSC, Ethereum, Fantom, Gnosis, Klayton, Optimism, Polygon, ZkSyncEra} +var ValidChainIds = []int{Arbitrum, Aurora, Avalanche, Base, Bsc, Ethereum, Fantom, Gnosis, Klayton, Optimism, Polygon, ZkSyncEra} diff --git a/golang/helpers/consts/contracts/abis.go b/golang/helpers/consts/contracts/abis.go deleted file mode 100644 index 7d872a9f..00000000 --- a/golang/helpers/consts/contracts/abis.go +++ /dev/null @@ -1,192 +0,0 @@ -package contracts - -const Erc20Abi = `[ - { - "constant":true, - "inputs":[ - - ], - "name":"PERMIT_TYPEHASH", - "outputs":[ - { - "internalType":"bytes32", - "name":"", - "type":"bytes32" - } - ], - "payable":false, - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"owner", - "type":"address" - }, - { - "internalType":"address", - "name":"spender", - "type":"address" - }, - { - "internalType":"uint256", - "name":"value", - "type":"uint256" - }, - { - "internalType":"uint256", - "name":"deadline", - "type":"uint256" - }, - { - "internalType":"bytes", - "name":"signature", - "type":"bytes" - } - ], - "name":"permit", - "outputs":[ - - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"spender", - "type":"address" - }, - { - "internalType":"uint256", - "name":"value", - "type":"uint256" - } - ], - "name":"approve", - "outputs":[ - { - "internalType":"bool", - "name":"", - "type":"bool" - } - ], - "stateMutability":"nonpayable", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"owner", - "type":"address" - } - ], - "name":"nonces", - "outputs":[ - { - "internalType":"uint256", - "name":"", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"decimals", - "outputs":[ - { - "internalType":"uint8", - "name":"", - "type":"uint8" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"name", - "outputs":[ - { - "internalType":"string", - "name":"", - "type":"string" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - - ], - "name":"symbol", - "outputs":[ - { - "internalType":"string", - "name":"", - "type":"string" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"owner", - "type":"address" - }, - { - "internalType":"address", - "name":"spender", - "type":"address" - } - ], - "name":"allowance", - "outputs":[ - { - "internalType":"uint256", - "name":"", - "type":"uint256" - } - ], - "stateMutability":"view", - "type":"function" - }, - { - "inputs":[ - { - "internalType":"address", - "name":"spender", - "type":"address" - }, - { - "internalType":"uint256", - "name":"decrement", - "type":"uint256" - } - ], - "name":"decreaseAllowance", - "outputs":[ - { - "internalType":"bool", - "name":"", - "type":"bool" - } - ], - "stateMutability":"nonpayable", - "type":"function" - } -]` diff --git a/golang/helpers/consts/contracts/contracts.go b/golang/helpers/consts/contracts/contracts.go index d957f9b3..330110d1 100644 --- a/golang/helpers/consts/contracts/contracts.go +++ b/golang/helpers/consts/contracts/contracts.go @@ -12,6 +12,10 @@ const AggregationV5RouterZkSyncEra = "0x6e2B76966cbD9cF4cC2Fa0D76d24d5241E0ABC2F const AggregationRouterV5Name = "1inch Aggregation Router" const AggregationRouterV5VersionNumber = "5" +const SeriesNonceManager = "0x303389f541ff2d620e42832f180a08e767b28e10" +const SeriesNonceManagerPolygon = "0xa5eb255EF45dFb48B5d133d08833DEF69871691D" +const SeriesNonceManagerBsc = "0x58ce0e6ef670c9a05622f4188faa03a9e12ee2e4" + func Get1inchRouterFromChainId(chainId int) (string, error) { if helpers.Contains(chainId, chains.ValidChainIds) { if chainId == chains.ZkSyncEra { @@ -23,3 +27,18 @@ func Get1inchRouterFromChainId(chainId int) (string, error) { return "", fmt.Errorf("unrecognized chain id: %d", chainId) } } + +// TODO add nonce manager contracts for all supported chains + +func GetSeriesNonceManagerFromChainId(chainId int) (string, error) { + switch chainId { + case chains.Ethereum: + return SeriesNonceManager, nil + case chains.Polygon: + return SeriesNonceManagerPolygon, nil + case chains.Bsc: + return SeriesNonceManagerBsc, nil + default: + return "", fmt.Errorf("unrecognized chain id: %d", chainId) + } +} diff --git a/golang/helpers/consts/web3providers/web3providers.go b/golang/helpers/consts/web3providers/web3providers.go index 2dc3afa0..a57b2055 100644 --- a/golang/helpers/consts/web3providers/web3providers.go +++ b/golang/helpers/consts/web3providers/web3providers.go @@ -3,3 +3,4 @@ package web3providers const Arbitrum = "https://arb1.arbitrum.io/rpc" const Ethereum = "https://eth-mainnet.public.blastapi.io" const Polygon = "https://polygon.llamarpc.com" +const Bsc = "https://bsc-dataseed1.binance.org"