oneinch

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedChains = map[string]int{
	"ETH":  1,
	"BASE": 8453,
	"BNB":  56,
	"ARB":  42161,
	"OP":   10,
}

SupportedChains maps the chainserver chain name (ETH/BASE/BNB/etc.) to 1inch's chainId. Mirrors what configs/chain table has but kept here so the package is self-contained for tests.

Functions

func ChainID

func ChainID(chainName string) (int, bool)

ChainID converts our internal chain name (ETH/BASE/BNB) into 1inch's numeric chainId. Returns 0 + ok=false for unsupported chains so the orchestrator can degrade cleanly.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps 1inch Fusion endpoints. Same instance covers all chains; the chainId is path-segment so the underlying httpc.Request can be reused.

func NewClient

func NewClient(apiKey string) *Client

func (*Client) Configured

func (c *Client) Configured() bool

func (*Client) QuoteFusion

func (c *Client) QuoteFusion(ctx context.Context, chainID int, req *FusionQuoteReq) (*FusionQuoteRes, error)

QuoteFusion calls /fusion/quoter/v2.0/{chainId}/quote/receive. Returns the multi-preset quote; caller picks which preset (fast / medium / slow) to construct the order from.

func (*Client) Status

func (c *Client) Status(ctx context.Context, chainID int, orderHash string) (*FusionOrderStatusRes, error)

Status polls /fusion/orders/v2.0/{chainId}/order/status/{orderHash}. Frontend hits this through /trade/checkTx every few seconds until the status moves out of pending.

func (*Client) SubmitOrder

func (c *Client) SubmitOrder(ctx context.Context, chainID int, req *FusionOrderSubmitReq) (*FusionOrderSubmitRes, error)

SubmitOrder pushes a user-signed order to the resolver network. The returned orderHash is what the frontend polls via Status().

type FusionOrder

type FusionOrder struct {
	Salt         string `json:"salt"`
	Maker        string `json:"maker"`      // user EOA
	Receiver     string `json:"receiver"`   // usually maker
	MakerAsset   string `json:"makerAsset"` // fromToken
	TakerAsset   string `json:"takerAsset"` // toToken
	MakingAmount string `json:"makingAmount"`
	TakingAmount string `json:"takingAmount"`
	MakerTraits  string `json:"makerTraits"`
}

FusionOrder is the EIP-712 limit-order shape 1inch resolvers fill. Caller builds this from the QuoteRes + chosen preset before signing.

type FusionOrderStatusRes

type FusionOrderStatusRes struct {
	OrderHash string `json:"orderHash"`
	Status    string `json:"status"`
	Fills     []any  `json:"fills"`
	Error     string `json:"error,omitempty"`
}

FusionOrderStatusRes mirrors GET /fusion/orders/v2.0/{chainId}/order/status/{orderHash}. Status values per 1inch docs: pending | filled | falsePartiallyFilled | partiallyFilled | expired | cancelled | refunding | refunded.

type FusionOrderSubmitReq

type FusionOrderSubmitReq struct {
	Order     FusionOrder `json:"order"`
	Signature string      `json:"signature"`
	Extension string      `json:"extension,omitempty"`
	QuoteID   string      `json:"quoteId"`
}

FusionOrderSubmitReq carries the signed order ready for the relayer. Order is the limit-order struct, Signature is the EIP-712 hex sig, Extension is the optional Permit2 / interactions field.

type FusionOrderSubmitRes

type FusionOrderSubmitRes struct {
	OrderHash string `json:"orderHash"`
	Error     string `json:"error,omitempty"`
}

type FusionPreset

type FusionPreset struct {
	AuctionDuration    int     `json:"auctionDuration"`
	StartAuctionIn     int     `json:"startAuctionIn"`
	BankFee            string  `json:"bankFee"`
	InitialRateBump    int     `json:"initialRateBump"`
	AuctionStartAmount string  `json:"auctionStartAmount"`
	StartAmount        string  `json:"startAmount"`
	AuctionEndAmount   string  `json:"auctionEndAmount"`
	ExclusiveResolver  any     `json:"exclusiveResolver"`
	CostInDstToken     string  `json:"costInDstToken"`
	Points             []any   `json:"points"`
	AllowPartialFills  bool    `json:"allowPartialFills"`
	AllowMultipleFills bool    `json:"allowMultipleFills"`
	GasCost            GasCost `json:"gasCost"`
}

FusionPreset is one of the auction profiles 1inch returns (fast / medium / slow). Pick fast for retail UX — landed-in-30s typical, slightly worse price than slow.

type FusionPrices

type FusionPrices struct {
	UsdFrom string `json:"usd.from"`
	UsdTo   string `json:"usd.to"`
}

type FusionQuoteReq

type FusionQuoteReq struct {
	FromTokenAddress string `json:"fromTokenAddress"`
	ToTokenAddress   string `json:"toTokenAddress"`
	Amount           string `json:"amount"`
	WalletAddress    string `json:"walletAddress"`
	EnableEstimate   bool   `json:"enableEstimate"` // true returns presets + gas estimates
	Source           string `json:"source,omitempty"`
}

FusionQuoteReq mirrors POST /fusion/quoter/v2.0/{chainId}/quote/receive. Amount is in fromToken's smallest unit; WalletAddress is the user EOA that will sign the EIP-712 order.

type FusionQuoteRes

type FusionQuoteRes struct {
	QuoteID           string                  `json:"quoteId"`
	FromTokenAmount   string                  `json:"fromTokenAmount"`
	ToTokenAmount     string                  `json:"toTokenAmount"`
	Presets           map[string]FusionPreset `json:"presets"`
	RecommendedPreset string                  `json:"recommended_preset"`
	Prices            FusionPrices            `json:"prices"`
	Volume            FusionVolume            `json:"volume"`
	SettlementAddress string                  `json:"settlementAddress"`
	Whitelist         []string                `json:"whitelist"`

	Error   string `json:"error,omitempty"`
	Message string `json:"message,omitempty"`
	Success *bool  `json:"success,omitempty"`
}

FusionQuoteRes is what the quoter returns. Presets carries the fast/medium/slow auction options; pick one based on Settings.

type FusionVolume

type FusionVolume struct {
	UsdFrom string `json:"usd.from"`
	UsdTo   string `json:"usd.to"`
}

type GasCost

type GasCost struct {
	GasBumpEstimate  int    `json:"gasBumpEstimate"`
	GasPriceEstimate string `json:"gasPriceEstimate"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL