Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add script to automatically generate token bridge configs #1164

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions scripts/tbr-config-generator/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
4 changes: 4 additions & 0 deletions scripts/tbr-config-generator/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.yarn/** linguist-vendored
/.yarn/releases/* binary
/.yarn/plugins/**/* binary
/.pnp.* binary linguist-generated
16 changes: 16 additions & 0 deletions scripts/tbr-config-generator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# Swap the comments on the following lines if you wish to use zero-installs
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
# Documentation here: https://yarnpkg.com/features/caching#zero-installs

#!.yarn/cache
.pnp.*

node_modules
output.json
1 change: 1 addition & 0 deletions scripts/tbr-config-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# tbr-config-generator
80 changes: 80 additions & 0 deletions scripts/tbr-config-generator/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env -S node --loader @swc-node/register/esm
import { Chain } from "@wormhole-foundation/sdk";
import { writeFileSync } from "node:fs";
import { parseArgs } from "node:util";

const args = process.argv.slice(2);

const { values, positionals } = parseArgs({
args,
options: {
help: {
type: 'boolean',
short: 'h'
},
query: {
type: 'string'
},
address: {
type: 'string'
},
sourceChain: {
type: 'string'
},
targetChains: {
type: 'string'
}
},
allowPositionals: true
});

function printHelp() {
console.log(`
Usage: index.mts [options]
Options:
-h, --help Print this help message
--queries The queries to run
--address The address to use
--source-chain The chain to use
--target-chains The chains to use
`);
}

if (values.help) {
printHelp();
process.exit(0);
}

if (values.query && (values.sourceChain || values.address)) {
console.error("Queries cannot be used with address or chain");
process.exit(1);
}

if (values.address && !values.sourceChain || values.sourceChain && !values.address) {
console.error("Both address and chain are required");
process.exit(1);
}

async function executeCreateConfigFromAddressAndChain() {
const { createConfigFromAddressAndChain } = await import("../src/createConfigFromAddressAndChain");
const wormholeSourceChain = values.sourceChain as Chain;
const wormholeTargetChains = values.targetChains!.split(",") as Array<Chain>;
const output = await createConfigFromAddressAndChain(values.address!, wormholeSourceChain, wormholeTargetChains);
writeFileSync(positionals.pop() || "output.json", JSON.stringify(output, null, 2));
}

if (values.address && values.sourceChain && values.targetChains) {
console.log(`Running queries with address ${values.address} on chain ${values.sourceChain} and target chains ${values.targetChains}`);
executeCreateConfigFromAddressAndChain();
}

async function executeCreateConfigFromDuneQuery() {
const { createConfigFromDuneQuery } = await import("../src/createConfigFromDuneQuery");
const output = await createConfigFromDuneQuery(parseInt(values.query!));
writeFileSync(positionals.pop() || "output.json", JSON.stringify(output, null, 2));
}

if (values.query) {
console.log(`Running queries ${values.query}`);
executeCreateConfigFromDuneQuery();
}
Loading
Loading