UNPKG

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

Version:

EVM support for the CCTPR corridor of the CCTP SDK

85 lines 3.82 kB
// Copyright (c) 2025 Stable Technologies Inc // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. import { boolItem } from "binary-layout"; import { universalAddressItem, signatureItem, enumSwitchVariants, byteSwitchLayout, } from "@stable-io/cctp-sdk-definitions"; import { wordSize, permitItem, evmAddressItem } from "@stable-io/cctp-sdk-evm"; import { zip } from "@stable-io/map-utils"; import { usdcItem, evmGasTokenItem, supportedDomainItem, gasDropoffItem, corridors, timestampItem, } from "./common.js"; const maxFastFeeUsdcItem = { name: "maxFastFeeUsdc", ...usdcItem }; const corridorVariants = zip([corridors, [[], [maxFastFeeUsdcItem], [maxFastFeeUsdcItem]]]); const corridorVariantItem = byteSwitchLayout("type", enumSwitchVariants(corridorVariants)); const offChainVariant = (feePaymentVariant) => [ "offChain", [ { name: "expirationTime", ...timestampItem }, { name: "feePaymentVariant", ...feePaymentVariant }, { name: "quoterSignature", ...signatureItem }, ], ]; const onChainUsdcVariant = [ "onChainUsdc", [ { name: "maxRelayFeeUsdc", ...usdcItem }, { name: "takeRelayFeeFromInput", ...boolItem() }, ], ]; const userFeePaymentVariants = [ ["usdc", [{ name: "relayFeeUsdc", ...usdcItem }]], ["gasToken", [{ name: "relayFeeGasToken", ...evmGasTokenItem }]], ]; const userFeePaymentVariantItem = byteSwitchLayout("payIn", enumSwitchVariants(userFeePaymentVariants)); const userQuoteVariants = [ offChainVariant(userFeePaymentVariantItem), onChainUsdcVariant, ["onChainGas", []], ]; const userQuoteVariantItem = byteSwitchLayout("type", enumSwitchVariants(userQuoteVariants)); const transferCommonLayout = (network, quoteVariantItem) => [ { name: "inputAmountUsdc", ...usdcItem }, { name: "destinationDomain", ...supportedDomainItem(network) }, { name: "mintRecipient", ...universalAddressItem }, { name: "gasDropoff", ...gasDropoffItem }, { name: "corridorVariant", ...corridorVariantItem }, { name: "quoteVariant", ...quoteVariantItem }, ]; const payInUsdcItem = { binary: "uint", size: 1, custom: { to: "usdc", from: 1 } }; const usdcFeePaymentItem = { binary: "bytes", layout: [ { name: "payIn", ...payInUsdcItem }, { name: "relayFeeUsdc", ...usdcItem }, ], }; const gaslessQuoteVariants = [ offChainVariant(usdcFeePaymentItem), onChainUsdcVariant, ]; const gaslessQuoteVariantItem = byteSwitchLayout("type", enumSwitchVariants(gaslessQuoteVariants)); const permit2NonceItem = { binary: "bytes", size: wordSize }; const permit2DataItem = { binary: "bytes", layout: [ { name: "owner", ...evmAddressItem }, { name: "amount", ...usdcItem }, { name: "nonce", ...permit2NonceItem }, { name: "deadline", ...timestampItem }, { name: "signature", ...signatureItem }, ], }; const userTransferCommonLayout = (network) => transferCommonLayout(network, userQuoteVariantItem); const transferWithPermitLayout = (network) => [ { name: "permit", ...permitItem }, ...userTransferCommonLayout(network), ]; const transferGaslessLayout = (network) => [ { name: "permit2Data", ...permit2DataItem }, { name: "gaslessFeeUsdc", ...usdcItem }, ...transferCommonLayout(network, gaslessQuoteVariantItem), ]; const transferVariants = (network) => [ [[0x01, "Permit"], transferWithPermitLayout(network)], [[0x02, "Preapproval"], userTransferCommonLayout(network)], [[0x03, "Gasless"], transferGaslessLayout(network)], ]; export const transferLayout = (network) => byteSwitchLayout("approvalType", transferVariants(network)); //# sourceMappingURL=transfer.js.map