UNPKG

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

Version:

EVM support for the CCTPR corridor of the CCTP SDK

40 lines 1.89 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 { amountItem, Usdc } from "@stable-io/cctp-sdk-definitions"; import { paddedSlotItem } from "@stable-io/cctp-sdk-evm"; //stored in cents -> shift down by 2 decimal and read as human const absoluteUsdcTransform = { to: (value) => value / 100, from: (human) => Number(human.mul(100).floor()), }; //negative values mean a discount on relay costs (but gas dropoff is never discounted) const feeAdjustmentAbsoluteUsdcItem = { ...amountItem(2, Usdc, "human", absoluteUsdcTransform), binary: "int", }; //100 means no discount and no risk premium on execution costs const feeAdjustmentRelativePercentItem = { binary: "uint", size: 1 }; const feeAdjustmentLayout = [ { name: "absoluteUsdc", ...feeAdjustmentAbsoluteUsdcItem }, { name: "relativePercent", ...feeAdjustmentRelativePercentItem }, ]; //We reverse the order because layout arrays have the opposite indexing order of uint256s that are // used as arrays in the contract: // * layouts are indexed/serialized "left to right" i.e. MSB first, i.e. Aptos is index 0, while // Ethereum is index 9 // * uint256s are indexed "right to left" i.e. LSB first, i.e. Ethereum is stored in the least // significant bytes of the uint256 which corresponds to index 0 const reverseAdjustments = (fa) => fa.toReversed(); export const feeAdjustmentsPerSlot = 10; export const feeAdjustmentsSlotItem = { binary: "bytes", layout: paddedSlotItem({ binary: "array", length: feeAdjustmentsPerSlot, layout: feeAdjustmentLayout, }), custom: { to: reverseAdjustments, from: reverseAdjustments }, }; //# sourceMappingURL=feeAdjustments.js.map