Skip to content

Commit

Permalink
add script to automatically generate token bridge configs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianscatularo committed Nov 4, 2024
1 parent 7312a51 commit c4f6891
Show file tree
Hide file tree
Showing 13 changed files with 8,135 additions and 0 deletions.
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

0 comments on commit c4f6891

Please sign in to comment.