UNPKG

@stable-io/cctp-sdk-cctpr-evm

Version:

EVM support for the CCTPR corridor of the CCTP SDK

629 lines 26.6 kB
import type { RoArray, Simplify } from "@stable-io/map-utils"; import type { DomainsOf, GasTokenOf, Usdc, UniversalAddress, EvmGasToken, Domain, Network, Percentage } from "@stable-io/cctp-sdk-definitions"; import { v2 } from "@stable-io/cctp-sdk-definitions"; import type { EvmClient, ContractTx, Permit, CallData, Permit2TypedData } from "@stable-io/cctp-sdk-evm"; import { EvmAddress } from "@stable-io/cctp-sdk-evm"; import type { SupportedDomain } from "@stable-io/cctp-sdk-cctpr-definitions"; import type { GovernanceCommand, QuoteRelay, OffChainQuote, ExtraChainIds, FeeAdjustment, FeeAdjustmentType } from "./layouts/index.js"; import { Rational } from "@stable-io/amount"; export * as layouts from "./layouts/index.js"; export { extraDomains } from "./layouts/common.js"; export type SupportedEvmDomain<N extends Network> = SupportedDomain<N> & DomainsOf<"Evm">; export declare const offChainQuoteData: <N extends Network>(network: N) => (params: OffChainQuote<N>) => Uint8Array<ArrayBufferLike>; export declare const execSelector: CallData; export declare const parseTransferTxCalldata: <N extends Network>(network: N) => (calldata: CallData) => { readonly gasDropoff: import("@stable-io/amount").Amount<{ readonly name: "GasToken"; readonly units: readonly [{ readonly symbol: "GasToken"; readonly scale: 1n; }, { readonly symbol: "mGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "\u00B5GasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "nGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "aGasToken"; readonly scale: bigint | Rational; }]; readonly human: "GasToken"; }>; readonly destinationDomain: import("@stable-io/utils").ApplyAliases<import("@stable-io/cctp-sdk-definitions").DomainAliases, { Mainnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Solana", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; Testnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; }[N extends bigint ? `bigint(${N})` : N extends boolean ? `boolean(${N})` : N][number]>; readonly approvalType: "Permit"; readonly permit: { readonly value: bigint; readonly deadline: bigint; readonly signature: Uint8Array<ArrayBufferLike>; }; readonly inputAmountUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly mintRecipient: UniversalAddress; readonly corridorVariant: { readonly type: "v1"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "v2Direct"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "avaxHop"; }; readonly quoteVariant: { readonly type: "offChain"; readonly expirationTime: Date; readonly feePaymentVariant: { readonly relayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly payIn: "usdc"; } | { readonly relayFeeGasToken: import("@stable-io/amount").Amount<{ readonly name: "EvmGasToken"; readonly units: readonly [{ readonly symbol: "EvmGasToken"; readonly scale: 1n; }, { readonly symbol: "nEvmGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "aEvmGasToken"; readonly scale: bigint | Rational; }]; readonly human: "EvmGasToken"; readonly atomic: "aEvmGasToken"; }>; readonly payIn: "gasToken"; }; readonly quoterSignature: Uint8Array<ArrayBufferLike>; } | { readonly type: "onChainUsdc"; readonly maxRelayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly takeRelayFeeFromInput: boolean; } | { readonly type: "onChainGas"; }; } | { readonly gasDropoff: import("@stable-io/amount").Amount<{ readonly name: "GasToken"; readonly units: readonly [{ readonly symbol: "GasToken"; readonly scale: 1n; }, { readonly symbol: "mGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "\u00B5GasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "nGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "aGasToken"; readonly scale: bigint | Rational; }]; readonly human: "GasToken"; }>; readonly destinationDomain: import("@stable-io/utils").ApplyAliases<import("@stable-io/cctp-sdk-definitions").DomainAliases, { Mainnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Solana", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; Testnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; }[N extends bigint ? `bigint(${N})` : N extends boolean ? `boolean(${N})` : N][number]>; readonly approvalType: "Preapproval"; readonly inputAmountUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly mintRecipient: UniversalAddress; readonly corridorVariant: { readonly type: "v1"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "v2Direct"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "avaxHop"; }; readonly quoteVariant: { readonly type: "offChain"; readonly expirationTime: Date; readonly feePaymentVariant: { readonly relayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly payIn: "usdc"; } | { readonly relayFeeGasToken: import("@stable-io/amount").Amount<{ readonly name: "EvmGasToken"; readonly units: readonly [{ readonly symbol: "EvmGasToken"; readonly scale: 1n; }, { readonly symbol: "nEvmGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "aEvmGasToken"; readonly scale: bigint | Rational; }]; readonly human: "EvmGasToken"; readonly atomic: "aEvmGasToken"; }>; readonly payIn: "gasToken"; }; readonly quoterSignature: Uint8Array<ArrayBufferLike>; } | { readonly type: "onChainUsdc"; readonly maxRelayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly takeRelayFeeFromInput: boolean; } | { readonly type: "onChainGas"; }; } | { readonly gasDropoff: import("@stable-io/amount").Amount<{ readonly name: "GasToken"; readonly units: readonly [{ readonly symbol: "GasToken"; readonly scale: 1n; }, { readonly symbol: "mGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "\u00B5GasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "nGasToken"; readonly scale: bigint | Rational; }, { readonly symbol: "aGasToken"; readonly scale: bigint | Rational; }]; readonly human: "GasToken"; }>; readonly destinationDomain: import("@stable-io/utils").ApplyAliases<import("@stable-io/cctp-sdk-definitions").DomainAliases, { Mainnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Solana", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; Testnet: ["Ethereum", "Avalanche", "Optimism", "Arbitrum", "Base", "Polygon", "Unichain", "Linea", "Codex", "Sonic", "Worldchain"]; }[N extends bigint ? `bigint(${N})` : N extends boolean ? `boolean(${N})` : N][number]>; readonly approvalType: "Gasless"; readonly inputAmountUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly mintRecipient: UniversalAddress; readonly corridorVariant: { readonly type: "v1"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "v2Direct"; } | { readonly maxFastFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly type: "avaxHop"; }; readonly quoteVariant: { readonly type: "offChain"; readonly expirationTime: Date; readonly feePaymentVariant: { readonly payIn: "usdc"; readonly relayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; }; readonly quoterSignature: Uint8Array<ArrayBufferLike>; } | { readonly type: "onChainUsdc"; readonly maxRelayFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly takeRelayFeeFromInput: boolean; }; readonly permit2Data: { readonly owner: EvmAddress; readonly amount: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly nonce: Uint8Array<ArrayBufferLike>; readonly deadline: Date; readonly signature: Uint8Array<ArrayBufferLike>; }; readonly gaslessFeeUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; }; export declare const parseGovernanceTxCalldata: <N extends Network>(network: N) => (calldata: CallData) => readonly ({ readonly feeType: "v1" | "v2Direct" | "avaxHop" | "gasDropoff"; readonly mappingIndex: number; readonly adjustments: { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[]; readonly command: "updateFeeAdjustments"; } | { readonly amount: bigint; readonly tokenAddress: EvmAddress; readonly command: "sweepTokens"; } | { readonly address: EvmAddress; readonly command: "updateFeeRecipient"; } | { readonly address: EvmAddress; readonly command: "updateFeeAdjuster"; } | { readonly address: EvmAddress; readonly command: "updateOffChainQuoter"; } | { readonly address: EvmAddress; readonly command: "proposeOwnershipTransfer"; } | { readonly command: "acceptOwnershipTransfer"; } | { readonly command: "cancelOwnershipTransfer"; } | { readonly domain: "Codex" | "Sonic" | "Worldchain"; readonly chainId: number; readonly command: "setChainIdForDomain"; })[]; type QtOnChain = { readonly type: "onChain"; }; type QtOffChain = { readonly type: "offChain"; }; type ExtraFields<QT> = QT extends QtOnChain ? unknown : Readonly<{ expirationTime: Date; quoterSignature: Uint8Array; }>; type RelayFieldName<T, U> = Readonly<T extends QtOnChain ? { maxRelayFee: U; } : { relayFee: U; }>; type QuoteTypeImpl<WEF extends boolean, //with extra fields GT = never> = Simplify<QtOnChain | QtOffChain extends infer QT ? QT extends any ? (QT & (WEF extends true ? ExtraFields<QT> : unknown)) extends infer Q ? Q & RelayFieldName<Q, Usdc | GT> : never : never : never>; export type Quote<SD extends DomainsOf<"Evm">> = QuoteTypeImpl<true, GasTokenOf<SD, DomainsOf<"Evm">>>; export type UsdcQuote = QuoteTypeImpl<true>; export type UsdcQuoteBase = QuoteTypeImpl<false>; type ErasedQuoteBase = QuoteTypeImpl<false, GasTokenOf<DomainsOf<"Evm">>>; export declare function quoteIsInUsdc(quote: ErasedQuoteBase): quote is UsdcQuote; export type CorridorParams<N extends Network, SD extends SupportedEvmDomain<N>, DD extends SupportedDomain<N>> = Simplify<Readonly<{ type: "v1"; } | (SD extends Exclude<v2.SupportedDomain<N>, "Avalanche"> ? (DD extends v2.SupportedDomain<N> ? "v2Direct" : "avaxHop") extends infer T extends "v2Direct" | "avaxHop" ? { type: T; fastFeeRate: Percentage; } : never : never)>>; export declare class CctpRBase<N extends Network, SD extends SupportedEvmDomain<N>> { readonly client: EvmClient<N, SD>; readonly address: EvmAddress; constructor(client: EvmClient<N, SD>); protected execTx(value: EvmGasToken, commandData: CallData): ContractTx; } export type InOrOut = { amount: Usdc; type: "in" | "out"; }; export declare class CctpR<N extends Network, SD extends SupportedEvmDomain<N>> extends CctpRBase<N, SD> { quoteOnChainRelay(queries: RoArray<QuoteRelay<N>>): Promise<RoArray<Usdc | GasTokenOf<SD>>>; checkCostAndCalcRequiredAllowance(inOrOut: InOrOut, quote: Quote<SD>, corridor: CorridorParams<N, SD, SupportedDomain<N>>, gaslessFee?: Usdc): Usdc; transferWithRelay<DD extends SupportedDomain<N>>(destination: DD, inOrOut: InOrOut, //meaningless distinction, if relay fee is paid in gas and corridor is v1 mintRecipient: UniversalAddress, gasDropoff: GasTokenOf<DD, SupportedDomain<N>>, corridor: CorridorParams<N, SD, DD>, quote: Quote<SD>, permit?: Permit): ContractTx; composeGaslessTransferMessage<DD extends SupportedDomain<N>>(destination: DD, cctprAddress: EvmAddress, //FIXME eliminate and use this.address instead inOrOut: InOrOut, mintRecipient: UniversalAddress, gasDropoff: GasTokenOf<DD, SupportedDomain<N>>, corridor: CorridorParams<N, SD, DD>, quote: UsdcQuoteBase, nonce: Uint8Array, //TODO better type deadline: Date, gaslessFee: Usdc): Permit2TypedData; transferGasless<DD extends SupportedDomain<N>>(destination: DD, inOrOut: InOrOut, mintRecipient: UniversalAddress, gasDropoff: GasTokenOf<DD, SupportedDomain<N>>, corridor: CorridorParams<N, SD, DD>, quote: UsdcQuote, nonce: Uint8Array, //TODO better type deadline: Date, gaslessFee: Usdc, user: EvmAddress, permit2Signature: Uint8Array): ContractTx; private checkCorridorDestinationCoherence; private static toCorridorVariant; private calcGaslessAmounts; private calcBurnAmount; private static calcFastFee; private static ceilToMicroUsdc; } export type FeeAdjustments = Record<Domain, FeeAdjustment>; export declare class CctpRGovernance<N extends Network, S extends DomainsOf<"Evm">> extends CctpRBase<N, S> { static adjustmentSlots: number; static feeAdjustmentsAtIndex(feeAdjustments: Partial<FeeAdjustments>, mappingIndex: number): { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[]; static feeAdjustmentsArray(feeAdjustments: Record<FeeAdjustmentType, Partial<FeeAdjustments>>): [{ readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[], { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[], { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[], { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: number; }[]][]; static extraChainsArray<N extends Network>(network: N): number[][]; static constructorCalldata<N extends Network>(network: N, domain: DomainsOf<"Evm">, owner: EvmAddress, feeAdjuster: EvmAddress, feeRecipient: EvmAddress, offChainQuoter: EvmAddress, priceOracle: EvmAddress, feeAdjustments: Record<FeeAdjustmentType, Partial<FeeAdjustments>>): Uint8Array; static avaxRouterConstructorCalldata(network: Network): Uint8Array; static gasDropoffConstructorCalldata(network: Network, domain: DomainsOf<"Evm">): Uint8Array; private static readonly mappings; static readonly roles: readonly ["feeRecipient", "offChainQuoter", "owner", "pendingOwner", "feeAdjuster"]; static readonly relayAtCostFeeAdjustment: { readonly absoluteUsdc: import("@stable-io/amount").Amount<{ readonly name: "Usdc"; readonly units: readonly [{ readonly symbol: "USDC"; readonly scale: 1; }, { readonly symbol: "\u00B5USDC"; readonly scale: bigint | Rational; }]; readonly human: "USDC"; readonly atomic: "\u00B5USDC"; readonly stringify: (val: Rational) => string; }>; readonly relativePercent: 100; }; execGovernance(commands: RoArray<GovernanceCommand<N>>): ContractTx; getRole(role: typeof CctpRGovernance.roles[number]): Promise<EvmAddress>; getRegisteredChainId(): Promise<ExtraChainIds<N>>; getFeeAdjustments(type: FeeAdjustmentType): Promise<FeeAdjustments>; private getStorageAt; private static slotOfKeyInMapping; } //# sourceMappingURL=index.d.ts.map