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 all commits
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
30 changes: 30 additions & 0 deletions scripts/tbr-config-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# tbr-config-generator

## Dune Query Ids

- Ethereum: 4126080
- Polygon: 4128580
- BNB Chain: 4128575
- Avalanche: 4137843
- Fantom: 4137974
- Celo: 4137984
- Arbitrum: 4138031
- Optimism: 4140347
- Base: 4140404

## Config Generation

```bash
npm exec tbr-configs -- --queries Ethereum:4126080,Polygon:4128580,Bsc:4128575,Avalanche:4137843,Fantom:4137974,Celo:4137984,Arbitrum:4138031,Optimism:4140347,Base:4140404
```

## Environment options

```bash
NETWORK = Mainnet|Testnet
DUNE_API_KEY = <API-Key>
DUNE_QUERY_EXECUTE = true|false
DUNE_QUERY_OFFSET = result offset, default 0
DUNE_QUERY_LIMIT = result limit, default 30
[CHAIN]_RPC = Chain rpc specific
```
71 changes: 71 additions & 0 deletions scripts/tbr-config-generator/bin/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env tsx
import { EvmChains } from "@wormhole-foundation/sdk-evm";
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'
},
queries: {
type: 'string'
},
},
allowPositionals: true
});

function printHelp() {
console.log(`
Usage: index.mts [options]
Options:
-h, --help Print this help message
--queries The queries to run with the format [Chain Name]:[Query Id]
`);
}

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

function parseInput(input: string) {
const query = input.split(":");
const queryIdStr = query.pop()!;
const chain = query.pop()! as EvmChains;
return {
queryIdStr,
chain
}
}

async function executeCreateConfigFromDuneQuery() {
const { default: createConfig } = await import("../src/config/createConfig");
const output = positionals.pop() || "output.json";
const inputs = values.queries?.split(',') || [];
const result = [];
for (const input of inputs) {
const { queryIdStr, chain } = parseInput(input);
const chainConfig = await createConfig(queryIdStr, chain);
result.push(chainConfig);
writeFileSync(
output,
JSON.stringify(result, (_, value) => typeof value === 'bigint' ? value.toString() : value, 2),
'utf-8'
);
}
writeFileSync(
output,
JSON.stringify(result, (_, value) => typeof value === 'bigint' ? value.toString() : value, 2),
'utf-8'
);
}

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