@ondo-gm/1inch
Version:
1inch Fusion swap integration for Ondo SDK
145 lines (141 loc) • 5.06 kB
text/typescript
import * as _1inch_fusion_sdk from '@1inch/fusion-sdk';
import { PreparedOrder, Web3Like, OrderInfo } from '@1inch/fusion-sdk';
export { OrderInfo, OrderStatus, OrderStatusResponse } from '@1inch/fusion-sdk';
import { TypedDataDomain, TypedDataField, Signer } from 'ethers';
/**
* Configuration for creating a 1inch Fusion order
*/
interface FusionOrderConfig {
/** Address of the token being sold (maker asset) */
fromTokenAddress: string;
/** Address of the token being bought (taker asset) */
toTokenAddress: string;
/** Amount of fromToken to sell (in wei/smallest unit) */
amount: string;
/** Wallet address creating the order */
walletAddress: string;
/** Optional receiver address (defaults to maker address) */
receiverAddress?: string;
/** Preset type to use for the order */
preset?: 'fast' | 'medium' | 'slow' | 'custom';
/** Custom preset configuration (only used if preset is 'custom') */
customPreset?: {
auctionDuration: number;
auctionStartAmount: string;
auctionEndAmount: string;
points?: Array<{
delay: number;
coefficient: number;
}>;
};
/** Enable price estimation */
enableEstimate?: boolean;
/** Fee in basis points (100 = 1%) */
fee?: number;
/** Enable surplus fee */
surplus?: boolean;
}
interface TypedDataSigner {
_signTypedData(domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, value: Record<string, unknown>): Promise<string>;
}
/**
* Signer interface for signing orders (compatible with ethers v5/v6)
*/
interface OrderSigner extends TypedDataSigner {
getAddress(): Promise<string>;
}
/**
* Result of creating a fusion order
*/
interface CreateFusionOrderResult {
/** The order structure */
order: PreparedOrder;
/** Quote information used to create the order */
quoteId: string;
/** Settlement contract address */
settlementAddress: string;
/** Extension data */
extension: string;
/** Order hash */
orderHash: string;
}
/**
* Result of signing a fusion order
*/
interface SignFusionOrderResult {
/** The signed order ready for submission */
order: PreparedOrder;
/** The signature */
signature: string;
/** Order hash */
orderHash: string;
/** Quote ID */
quoteId: string;
}
declare function sleep(ms: number): Promise<void>;
/**
* Client for creating and signing 1inch Fusion orders using the official SDK
*/
declare class FusionClient {
private sdk;
private networkId;
private baseUrl;
private chainId;
private web3Provider;
private signer;
private approveAllowance;
constructor(chainId: number, provider: Web3Like, signer: Signer, baseUrl: string, approveAllowance: (contractAddress: string, spender: string, quantity: string, signer: Signer) => Promise<void>, authKey?: string);
getNativeSwapQuote(fromToken: string, toToken: string, amount: string): Promise<any>;
swapNativeToken(address: string, fromToken: string, toToken: string, amount: string): Promise<any>;
private isNativeToken;
/**
* Gets the wrapped token address for a given chain ID
*/
private getWrappedTokenAddress;
/**
* Creates a fusion order based on the provided configuration
*/
createFusionOrder(config: FusionOrderConfig): Promise<CreateFusionOrderResult>;
/**
* Signs a fusion order using EIP-712
*/
signFusionOrder(orderResult: CreateFusionOrderResult): Promise<SignFusionOrderResult>;
/**
* Submits a signed fusion order to the 1inch relayer
*/
submitFusionOrder(signedOrderResult: SignFusionOrderResult): Promise<OrderInfo>;
/**
* Creates, signs, and submits a fusion order in one call
*/
createAndSubmitFusionOrder(config: FusionOrderConfig): Promise<OrderInfo>;
getOrderStatus(info: OrderInfo): Promise<_1inch_fusion_sdk.OrderStatusResponse>;
getTokens(tokens: Array<string>): Promise<any>;
getBalance(walletAddress: string): Promise<Record<string, Record<string, string>> | null>;
/**
* Gets a quote from the 1inch quoter API
*/
getQuote(config: FusionOrderConfig): Promise<any>;
/**
* Maps chain ID to NetworkEnum
*/
private getNetworkEnum;
/**
* Maps preset string to PresetEnum
*/
private mapPresetToEnum;
}
/**
* Configuration for creating a 1inch Fusion client
*/
interface FusionClientConfig {
chainId: number;
/** Custom API URLs (optional, will use defaults if not provided) */
apiUrl: string;
signer: Signer;
approveAllowance: (contractAddress: string, spender: string, quantity: string, signer: Signer) => Promise<void>;
}
/**
* Creates a new 1inch Fusion order client
*/
declare function createFusionClient(config: FusionClientConfig): FusionClient;
export { type CreateFusionOrderResult, FusionClient, type FusionClientConfig, type FusionOrderConfig, type OrderSigner, type SignFusionOrderResult, type TypedDataSigner, createFusionClient, sleep };