Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,340 changes: 1,340 additions & 0 deletions codegen/openapi/fusionplus_orders-openapi.json

Large diffs are not rendered by default.

783 changes: 783 additions & 0 deletions codegen/openapi/fusionplus_quoter-openapi.json

Large diffs are not rendered by default.

225 changes: 225 additions & 0 deletions codegen/openapi/fusionplus_relayer-openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{
"openapi": "3.0.0",
"paths": {
"/v1.0/submit": {
"post": {
"operationId": "RelayerController_submit",
"summary": "Submit a cross chain order that resolvers will be able to fill",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SignedOrderInput"
}
}
}
},
"responses": {
"201": {
"description": "The order has been successfully saved"
}
},
"tags": [
"Relayer"
]
}
},
"/v1.0/submit/many": {
"post": {
"operationId": "RelayerController_submitMany",
"summary": "Submit many cross chain orders that resolvers will be able to fill",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "string"
},
"x-go-type-skip-optional-pointer": true
}
}
}
},
"responses": {
"201": {
"description": "The orders has been successfully saved"
}
},
"tags": [
"Relayer"
]
}
},
"/v1.0/submit/secret": {
"post": {
"operationId": "RelayerController_submitSecrets",
"summary": "Submit a secret for order fill after SrcEscrow and DstEscrow deployed and DstChain finality lock passed",
"parameters": [],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SecretInput"
}
}
}
},
"responses": {
"201": {
"description": "The secret has been successfully saved"
}
},
"tags": [
"Relayer"
]
}
}
},
"info": {
"title": "1inch Fusion+ Relayer API",
"description": "Relayer API accepts orders and distribute them across resolvers",
"version": "1.0",
"contact": {}
},
"tags": [],
"servers": [
{
"url": "/relayer"
}
],
"components": {
"schemas": {
"OrderInput": {
"type": "object",
"properties": {
"salt": {
"type": "string",
"example": "42",
"x-go-type-skip-optional-pointer": true
},
"makerAsset": {
"type": "string",
"description": "Source chain address of the maker asset",
"example": "0x0000000000000000000000000000000000000001",
"x-go-type-skip-optional-pointer": true
},
"takerAsset": {
"type": "string",
"description": "Destination chain address of the taker asset",
"example": "0x0000000000000000000000000000000000000001",
"x-go-type-skip-optional-pointer": true
},
"maker": {
"type": "string",
"description": "Source chain address of the maker (wallet or contract address)",
"example": "0x0000000000000000000000000000000000000001",
"x-go-type-skip-optional-pointer": true
},
"receiver": {
"type": "string",
"description": "Destination chain address of the wallet or contract who will receive filled amount ",
"default": "0x0000000000000000000000000000000000000001",
"x-go-type-skip-optional-pointer": true
},
"makingAmount": {
"type": "string",
"description": "Order maker's token amount",
"example": "100000000000000000000",
"x-go-type-skip-optional-pointer": true
},
"takingAmount": {
"type": "string",
"description": "Order taker's token amount",
"example": "100000000000000000000",
"x-go-type-skip-optional-pointer": true
},
"makerTraits": {
"type": "string",
"description": "Includes some flags like: allow multiple fills, is partial fill allowed or not, price improvement, nonce, deadline etc. See <a href=\"https://github.com/1inch/limit-order-sdk/blob/master/src/limit-order/maker-traits.ts\" target=\"_blank\">maker-traits.ts</a>",
"default": "0",
"x-go-type-skip-optional-pointer": true
}
},
"required": [
"salt",
"makerAsset",
"takerAsset",
"maker",
"receiver",
"makingAmount",
"takingAmount",
"makerTraits"
]
},
"SignedOrderInput": {
"type": "object",
"properties": {
"order": {
"$ref": "#/components/schemas/OrderInput"
},
"srcChainId": {
"type": "number",
"description": "Source chain id",
"example": 1,
"x-go-type-skip-optional-pointer": true
},
"signature": {
"type": "string",
"description": "Signature of the cross chain order typed data (using signTypedData v4)",
"x-go-type-skip-optional-pointer": true
},
"extension": {
"type": "string",
"description": "An interaction call data. ABI encoded a set of makerAssetSuffix, takerAssetSuffix, makingAmountGetter, takingAmountGetter, predicate, permit, preInteraction, postInteraction.Lowest 160 bits of the order salt must be equal to the lowest 160 bits of the extension hash. See <a href=\"https://github.com/1inch/cross-chain-sdk/blob/master/src/cross-chain-order/escrow-extension.ts\" target=\"_blank\">escrow-extension.ts</a>>",
"example": "0x",
"x-go-type-skip-optional-pointer": true
},
"quoteId": {
"type": "string",
"description": "Quote id of the quote with presets",
"x-go-type-skip-optional-pointer": true
},
"secretHashes": {
"description": "Secret Hashes, required for order with multiple fills allowed. keccak256(secret(idx))",
"type": "array",
"items": {
"type": "string"
},
"x-go-type-skip-optional-pointer": true
}
},
"required": [
"order",
"srcChainId",
"signature",
"extension",
"quoteId"
]
},
"SecretInput": {
"type": "object",
"properties": {
"secret": {
"type": "string",
"description": "A secret for the fill hashlock",
"x-go-type-skip-optional-pointer": true
},
"orderHash": {
"type": "string",
"x-go-type-skip-optional-pointer": true
}
},
"required": [
"secret",
"orderHash"
]
}
}
}
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/1inch/1inch-sdk-go
go 1.21.1

require (
github.com/FantasyJony/openzeppelin-merkle-tree-go v1.1.3
github.com/ethereum/go-ethereum v1.14.8
github.com/google/go-querystring v1.1.0
github.com/oapi-codegen/runtime v1.1.1
Expand All @@ -27,7 +28,11 @@ require (
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ=
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/FantasyJony/openzeppelin-merkle-tree-go v1.1.3 h1:KzMvCFet0baw6uJnxTE/His8YeRgaxlASd4/ISuTvzI=
github.com/FantasyJony/openzeppelin-merkle-tree-go v1.1.3/go.mod h1:OiwyYqbtMkQH+VzA4b8lI+qHnExJy0fIdz+59/8nFes=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
Expand Down Expand Up @@ -81,6 +83,7 @@ github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
Expand All @@ -100,6 +103,8 @@ github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
Expand All @@ -126,6 +131,11 @@ github.com/mitchellh/pointerstructure v1.2.0/go.mod h1:BRAsLI5zgXmw97Lf6s25bs8oh
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
Expand Down
14 changes: 14 additions & 0 deletions internal/bigint/bigint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package bigint

import (
"fmt"
"math/big"
)

func FromString(s string) (*big.Int, error) {
bigInt, ok := new(big.Int).SetString(s, 10) // base 10 for decimal
if !ok {
return nil, fmt.Errorf("failed to convert string (%v) to big.Int", s)
}
return bigInt, nil
}
74 changes: 74 additions & 0 deletions internal/bigint/bigint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package bigint

import (
"math/big"
"testing"

"github.com/stretchr/testify/require"
)

var largeString, _ = big.NewInt(0).SetString("9999999999999999999999999999", 10)

func TestFromString(t *testing.T) {
tests := []struct {
name string
input string
want *big.Int
wantErr bool
}{
{
name: "Valid decimal (10)",
input: "10",
want: big.NewInt(10),
wantErr: false,
},
{
name: "Zero value",
input: "0",
want: big.NewInt(0),
wantErr: false,
},
{
name: "Negative value (-100)",
input: "-100",
want: big.NewInt(-100),
wantErr: false,
},
{
name: "Large number",
input: "9999999999999999999999999999",
want: largeString,
wantErr: false,
},
{
name: "Invalid string",
input: "hello",
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
got, err := FromString(tt.input)
if tt.wantErr {
// We expect an error
require.Error(t, err, "Expected an error but got none")
return
}

// We do NOT expect an error
require.NoError(t, err, "Did not expect an error but got one: %v", err)

// Verify the returned *big.Int matches our expectation
// (a nil `tt.want` is unusual when wantErr=false, so ensure it's not nil)
require.NotNil(t, got, "Expected non-nil big.Int but got nil")

// Compare numerical values
if got.Cmp(tt.want) != 0 {
t.Errorf("FromString(%q) = %v, want %v", tt.input, got, tt.want)
}
})
}
}
Loading
Loading