@eco-foundation/routes-sdk
Version:
Eco Routes SDK
129 lines (121 loc) • 4.91 kB
text/typescript
import { Hex } from 'viem';
import { IntentType, EcoChainIds } from '@eco-foundation/routes-ts';
declare const chainIds: readonly [1, 10, 130, 137, 8453, 42161, 42220, 57073];
type RoutesSupportedChainId = typeof chainIds[number];
declare const stables: readonly ["USDC", "USDbC", "USDCe", "USDT", "oUSDT", "USDT0"];
type RoutesSupportedStable = typeof stables[number];
declare const stableAddresses: Record<RoutesSupportedChainId, Partial<Record<RoutesSupportedStable, Hex | undefined>>>;
type SolverQuote = {
quoteData: QuoteData;
};
type QuoteData = {
tokens: {
token: Hex;
amount: string;
}[];
expiryTime: string;
estimatedFulfillTimeSec: number;
};
type CreateSimpleIntentParams = {
creator: Hex;
originChainID: RoutesSupportedChainId;
destinationChainID: RoutesSupportedChainId;
receivingToken: Hex;
spendingToken: Hex;
spendingTokenLimit: bigint;
amount: bigint;
prover?: "HyperProver" | "StorageProver";
recipient?: Hex;
expiryTime?: Date;
};
type CreateIntentParams = {
creator: Hex;
originChainID: RoutesSupportedChainId;
destinationChainID: RoutesSupportedChainId;
calls: IntentCall[];
callTokens: IntentToken[];
tokens: IntentToken[];
prover: "HyperProver" | "StorageProver" | Hex;
expiryTime?: Date;
};
type ApplyQuoteToIntentParams = {
intent: IntentType;
quote: SolverQuote;
};
type IntentCall = {
target: Hex;
data: Hex;
value: bigint;
};
type IntentToken = {
token: Hex;
amount: bigint;
};
declare class RoutesService {
private isPreprod;
constructor({ isPreprod }?: {
isPreprod?: boolean;
});
/**
* Creates a simple intent.
*
* @param {CreateSimpleIntentParams} params - The parameters for creating the simple intent.
*
* @returns {IntentType} The created intent.
*
* @throws {Error} If the creator address is invalid, the origin and destination chain are the same, the amount is invalid, or the expiry time is in the past. Or if there is no prover for the specified configuration.
*/
createSimpleIntent({ creator, originChainID, destinationChainID, receivingToken, spendingToken, spendingTokenLimit, amount, recipient, prover, expiryTime }: CreateSimpleIntentParams): IntentType;
/**
* Creates an intent.
*
* @param {CreateRouteParams} params - The parameters for creating the intent.
*
* @returns {IntentType} The created intent.
*
* @throws {Error} If the creator address is invalid, the origin and destination chain are the same, the calls or tokens are invalid, or the expiry time is in the past.
*/
createIntent({ creator, originChainID, destinationChainID, calls, callTokens, tokens, prover, expiryTime }: CreateIntentParams): IntentType;
/**
* Applies a quote to an intent, modifying the reward tokens.
*
* @param {ApplyQuoteToIntentParams} params - The parameters for applying the quote to the intent.
*
* @returns {IntentType} The intent with the quote applied.
*
* @throws {Error} If the quote is invalid.
*/
applyQuoteToIntent({ intent, quote }: ApplyQuoteToIntentParams): IntentType;
/**
* Returns the EcoChainId for a given chainId, appending "-pre" if the environment is pre-production.
*
* @param chainId - The chain ID to be converted to an EcoChainId.
* @returns The EcoChainId, with "-pre" appended if the environment is pre-production.
*/
getEcoChainId(chainId: RoutesSupportedChainId): EcoChainIds;
private getProverContract;
static getStableAddress(chainID: RoutesSupportedChainId, stable: RoutesSupportedStable): Hex;
static getStableFromAddress(chainID: RoutesSupportedChainId, address: Hex): RoutesSupportedStable | undefined;
}
declare class OpenQuotingClient {
private readonly MAX_RETRIES;
private dAppID;
private axiosInstance;
constructor({ dAppID, customBaseUrl }: {
dAppID: string;
customBaseUrl?: string;
});
/**
* Requests quotes for a given intent.
*
* @param intent - The intent for which quotes are being requested.
* @returns A promise that resolves to an `OpenQuotingClient_ApiResponse_Quotes` object containing the quotes.
* @throws An error if multiple requests fail.
*
* @remarks
* This method sends a POST request to the `/api/v1/quotes` endpoint with the provided intent information.
*/
requestQuotesForIntent(intent: IntentType): Promise<SolverQuote[]>;
}
declare function selectCheapestQuote(quotes: SolverQuote[]): SolverQuote;
export { type ApplyQuoteToIntentParams, type CreateIntentParams, type CreateSimpleIntentParams, OpenQuotingClient, type QuoteData, RoutesService, type RoutesSupportedChainId, type RoutesSupportedStable, type SolverQuote, chainIds, selectCheapestQuote, stableAddresses, stables };