Skip to content

Commit

Permalink
first push to leverage ts sdk for constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nonergodic committed Aug 29, 2024
1 parent b7a0d00 commit e3d2c8c
Show file tree
Hide file tree
Showing 10 changed files with 616 additions and 2 deletions.
1 change: 1 addition & 0 deletions gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
14 changes: 14 additions & 0 deletions gen/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
GENEREATORS = chains cctpDomains

chains_PATH = ../src/constants/Chains.sol
cctpDomains_PATH = ../src/constants/CCTPDomains.sol

.PHONY: generate $(GENEREATORS)

generate: $(GENEREATORS)

$(GENEREATORS): node_modules
npm run --silent $@ > $($@_PATH)

node_modules:
npm install
30 changes: 30 additions & 0 deletions gen/cctpDomains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { toCapsSnakeCase } from "./utils";
import * as base from "@wormhole-foundation/sdk-base";

const { circleChainId, circleNetworks, circleChainMap } = base.circle;

console.log(
`// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
// This file is auto-generated by gen/cctpDomains.ts.
`);

if (circleNetworks[0] !== "Mainnet" || circleNetworks[1] !== "Testnet")
throw new Error("circleNetworks has unexpected content");

const mainnetChains = base.column(circleChainMap[0], 0);
const testnetChains = base.column(circleChainMap[1], 0);

for (const chain of mainnetChains)
console.log(
`uint32 constant CCTP_DOMAIN_${toCapsSnakeCase(chain)} = ${circleChainId("Mainnet", chain)};`
);

console.log(`
// Additional Testnet mappings:`);
for (const chain of testnetChains)
if (!(mainnetChains as string[]).includes(chain))
console.log(
`uint32 constant CCTP_DOMAIN_${toCapsSnakeCase(chain)} = ${circleChainId("Testnet", chain)};`
);
16 changes: 16 additions & 0 deletions gen/chains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { toCapsSnakeCase } from "./utils";
import * as base from "@wormhole-foundation/sdk-base";

const { chains, chainToChainId } = base.chain;

console.log(
`// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.0;
// This file is auto-generated by gen/chains.ts.
// In the wormhole wire format, 0 indicates that a message is for any destination chain
uint16 constant CHAIN_ID_UNSET = 0;`);

for (const chain of chains)
console.log(`uint16 constant CHAIN_ID_${toCapsSnakeCase(chain)} = ${chainToChainId(chain)};`);
Loading

0 comments on commit e3d2c8c

Please sign in to comment.