Skip to content

Commit

Permalink
chore: attenuatedCttpBridgeAddress -> attenuatedCttpBridgeAddresses
Browse files Browse the repository at this point in the history
- ensure `ChainPolicy` can support multiple bridge attenuation contracts
  • Loading branch information
0xpatrickdev committed Jan 10, 2025
1 parent 8bf1c49 commit 3ec61df
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 19 deletions.
20 changes: 15 additions & 5 deletions packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Generated by [AVA](https://avajs.dev).
{
chainPolicies: {
Arbitrum: {
attenuatedCttpBridgeAddress: '0xe298b93ffB5eA1FB628e0C0D55A43aeaC268e347',
attenuatedCttpBridgeAddresses: [
'0xe298b93ffB5eA1FB628e0C0D55A43aeaC268e347',
],
cctpTokenMessengerAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
confirmations: 2,
Expand All @@ -28,7 +30,9 @@ Generated by [AVA](https://avajs.dev).
},
},
Base: {
attenuatedCttpBridgeAddress: '0xB6615B2662b35fc3533F8479002e62D0523341De',
attenuatedCttpBridgeAddresses: [
'0xB6615B2662b35fc3533F8479002e62D0523341De',
],
cctpTokenMessengerAddress: '0x1682Ae6375C4E4A97e4B583BC394c861A46D8962',
chainId: 8453,
confirmations: 2,
Expand All @@ -39,7 +43,9 @@ Generated by [AVA](https://avajs.dev).
},
},
Ethereum: {
attenuatedCttpBridgeAddress: '0xBC8552339dA68EB65C8b88B414B5854E0E366cFc',
attenuatedCttpBridgeAddresses: [
'0xBC8552339dA68EB65C8b88B414B5854E0E366cFc',
],
cctpTokenMessengerAddress: '0xBd3fa81B58Ba92a82136038B25aDec7066af3155',
chainId: 1,
confirmations: 2,
Expand All @@ -50,7 +56,9 @@ Generated by [AVA](https://avajs.dev).
},
},
Optimism: {
attenuatedCttpBridgeAddress: '0x48C5417ED570928eC85D5e3AD4e7E0EeD7dB1E2A',
attenuatedCttpBridgeAddresses: [
'0x48C5417ED570928eC85D5e3AD4e7E0EeD7dB1E2A',
],
cctpTokenMessengerAddress: '0x2B4069517957735bE00ceE0fadAE88a26365528f',
chainId: 10,
confirmations: 2,
Expand All @@ -61,7 +69,9 @@ Generated by [AVA](https://avajs.dev).
},
},
Polygon: {
attenuatedCttpBridgeAddress: '0x32cb9574650AFF312c80edc4B4343Ff5500767cA',
attenuatedCttpBridgeAddresses: [
'0x32cb9574650AFF312c80edc4B4343Ff5500767cA',
],
cctpTokenMessengerAddress: '0x9daF8c91AEFAE50b9c0E69629D3F6Ca40cA3B3FE',
chainId: 137,
confirmations: 2,
Expand Down
Binary file modified packages/boot/test/fast-usdc/snapshots/fast-usdc.test.ts.snap
Binary file not shown.
6 changes: 5 additions & 1 deletion packages/fast-usdc/src/type-guards.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ harden(PoolMetricsShape);

/** @type {TypedPattern<ChainPolicy>} */
export const ChainPolicyShape = {
attenuatedCttpBridgeAddress: EvmHashShape,
attenuatedCttpBridgeAddresses: M.splitArray(
[EvmHashShape],
undefined,
M.arrayOf(EvmHashShape),
),
cctpTokenMessengerAddress: EvmHashShape,
confirmations: M.number(),
chainId: M.number(),
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-usdc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface PoolMetrics extends PoolStats {

export interface ChainPolicy {
/** `msg.sender` of DepositAndBurn to TokenMessenger must be an attenuated wrapper contract that does not contain `replaceDepositForBurn` */
attenuatedCttpBridgeAddress: EvmHash;
attenuatedCttpBridgeAddresses: EvmHash[];
/** @see {@link https://developers.circle.com/stablecoins/evm-smart-contracts} */
cctpTokenMessengerAddress: EvmHash;
/** e.g., `1` for ETH mainnet 42161 for Arbitrum One. @see {@link https://chainlist.org/} */
Expand Down
30 changes: 20 additions & 10 deletions packages/fast-usdc/src/utils/chain-policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
export const ChainPolicies = /** @type {const} */ ({
MAINNET: {
Arbitrum: {
attenuatedCttpBridgeAddress: '0xe298b93ffB5eA1FB628e0C0D55A43aeaC268e347',
attenuatedCttpBridgeAddresses: [
'0xe298b93ffB5eA1FB628e0C0D55A43aeaC268e347',
],
cctpTokenMessengerAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
// TODO confirm confirmations and rateLimits
Expand All @@ -16,7 +18,9 @@ export const ChainPolicies = /** @type {const} */ ({
},
},
Base: {
attenuatedCttpBridgeAddress: '0xB6615B2662b35fc3533F8479002e62D0523341De',
attenuatedCttpBridgeAddresses: [
'0xB6615B2662b35fc3533F8479002e62D0523341De',
],
cctpTokenMessengerAddress: '0x1682Ae6375C4E4A97e4B583BC394c861A46D8962',
chainId: 8453,
// TODO confirm confirmations and rateLimits
Expand All @@ -28,7 +32,9 @@ export const ChainPolicies = /** @type {const} */ ({
},
},
Ethereum: {
attenuatedCttpBridgeAddress: '0xBC8552339dA68EB65C8b88B414B5854E0E366cFc',
attenuatedCttpBridgeAddresses: [
'0xBC8552339dA68EB65C8b88B414B5854E0E366cFc',
],
cctpTokenMessengerAddress: '0xBd3fa81B58Ba92a82136038B25aDec7066af3155',
chainId: 1,
// TODO confirm confirmations and rateLimits
Expand All @@ -40,7 +46,9 @@ export const ChainPolicies = /** @type {const} */ ({
},
},
Optimism: {
attenuatedCttpBridgeAddress: '0x48C5417ED570928eC85D5e3AD4e7E0EeD7dB1E2A',
attenuatedCttpBridgeAddresses: [
'0x48C5417ED570928eC85D5e3AD4e7E0EeD7dB1E2A',
],
cctpTokenMessengerAddress: '0x2B4069517957735bE00ceE0fadAE88a26365528f',
chainId: 10,
// TODO confirm confirmations and rateLimits
Expand All @@ -52,7 +60,9 @@ export const ChainPolicies = /** @type {const} */ ({
},
},
Polygon: {
attenuatedCttpBridgeAddress: '0x32cb9574650AFF312c80edc4B4343Ff5500767cA',
attenuatedCttpBridgeAddresses: [
'0x32cb9574650AFF312c80edc4B4343Ff5500767cA',
],
cctpTokenMessengerAddress: '0x9daF8c91AEFAE50b9c0E69629D3F6Ca40cA3B3FE',
chainId: 137,
// TODO confirm confirmations and rateLimits
Expand All @@ -67,7 +77,7 @@ export const ChainPolicies = /** @type {const} */ ({
TESTNET: {
// Arbitrum Sepolia
Arbitrum: {
attenuatedCttpBridgeAddress: '0xTODO',
attenuatedCttpBridgeAddresses: ['0xTODO'],
cctpTokenMessengerAddress: '0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5',
chainId: 421614,
confirmations: 2,
Expand All @@ -79,7 +89,7 @@ export const ChainPolicies = /** @type {const} */ ({
},
// Base Sepolia
Base: {
attenuatedCttpBridgeAddress: '0xTODO',
attenuatedCttpBridgeAddresses: ['0xTODO'],
cctpTokenMessengerAddress: '0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5',
chainId: 84532,
confirmations: 2,
Expand All @@ -91,7 +101,7 @@ export const ChainPolicies = /** @type {const} */ ({
},
// Ethereum Sepolia
Ethereum: {
attenuatedCttpBridgeAddress: '0xTODO',
attenuatedCttpBridgeAddresses: ['0xTODO'],
cctpTokenMessengerAddress: '0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5',
chainId: 11155111,
confirmations: 2,
Expand All @@ -103,7 +113,7 @@ export const ChainPolicies = /** @type {const} */ ({
},
// OP Sepolia
Optimism: {
attenuatedCttpBridgeAddress: '0xTODO',
attenuatedCttpBridgeAddresses: ['0xTODO'],
cctpTokenMessengerAddress: '0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5',
chainId: 11155420,
confirmations: 2,
Expand All @@ -115,7 +125,7 @@ export const ChainPolicies = /** @type {const} */ ({
},
// Polygon PoS Amoy
Polygon: {
attenuatedCttpBridgeAddress: '0xTODO',
attenuatedCttpBridgeAddresses: ['0xTODO'],
cctpTokenMessengerAddress: '0x9f3B8679c73C2Fef8b59B4f3444d4e156fb70AA5',
chainId: 80002,
confirmations: 2,
Expand Down
52 changes: 50 additions & 2 deletions packages/fast-usdc/test/type-guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { test } from '@agoric/zoe/tools/prepare-test-env-ava.js';

import { M, mustMatch } from '@endo/patterns';
import { TxStatus, PendingTxStatus } from '../src/constants.js';
import { CctpTxEvidenceShape, PendingTxShape } from '../src/type-guards.js';
import type { CctpTxEvidence } from '../src/types.js';
import {
CctpTxEvidenceShape,
ChainPolicyShape,
PendingTxShape,
} from '../src/type-guards.js';
import type { CctpTxEvidence, ChainPolicy } from '../src/types.js';

import { MockCctpTxEvidences } from './fixtures.js';
import { ChainPolicies } from '../src/utils/chain-policies.js';

test('CctpTxEvidenceShape', t => {
const specimen: CctpTxEvidence = harden(
Expand Down Expand Up @@ -37,3 +42,46 @@ test('PendingTxShape', t => {
),
);
});

test('ChainPolicyShape', t => {
const policy: ChainPolicy = harden({
attenuatedCttpBridgeAddresses: [
'0xe298b93ffB5eA1FB628e0C0D55A43aeaC268e347',
],
rateLimits: {
blockWindow: 20_000_000_000n,
blockWindowSize: 10,
tx: 10_000_000_000n,
},
cctpTokenMessengerAddress: '0x19330d10D9Cc8751218eaf51E8885D058642E08A',
chainId: 42161,
confirmations: 2,
});
t.notThrows(() => mustMatch(policy, ChainPolicyShape));

const a = policy.attenuatedCttpBridgeAddresses[0];
const twoAddrs = harden({
...policy,
attenuatedCttpBridgeAddresses: [a, a],
});
t.notThrows(() => mustMatch(twoAddrs, ChainPolicyShape));

const threeAddrs = harden({
...policy,
attenuatedCttpBridgeAddresses: [a, a, a],
});
t.notThrows(() => mustMatch(threeAddrs, ChainPolicyShape));

t.notThrows(() =>
mustMatch(
harden(Object.values(ChainPolicies.MAINNET)),
M.arrayOf(ChainPolicyShape),
),
);

const noAddrs = harden({
...policy,
attenuatedCttpBridgeAddresses: [],
});
t.throws(() => mustMatch(noAddrs, ChainPolicyShape));
});

0 comments on commit 3ec61df

Please sign in to comment.