Skip to content

Commit

Permalink
types
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Feb 5, 2024
1 parent dfc9009 commit 30851e2
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 56 deletions.
48 changes: 24 additions & 24 deletions data/addresses.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,45 +161,45 @@
"type": "fungibleModule"
},
{
"address": "0x0000028a2eB8346cd5c0267856aB7594B7a55308",
"address": "0xf091867EC603A6628eD83D274E835539D82e9cc8",
"category": "messaging",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"chain_id": "1",
"chain_name": "eth_mainnet",
"type": "zetaToken"
},
{
"address": "0x000063A6e758D9e2f438d430108377564cf4077D",
"address": "0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a",
"category": "messaging",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"chain_id": "1",
"chain_name": "eth_mainnet",
"type": "connector"
},
{
"address": "0x00000fF8fA992424957F97688015814e707A0115",
"address": "0x0000030Ec64DF25301d8414eE5a29588C4B0dE10",
"category": "omnichain",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"chain_id": "1",
"chain_name": "eth_mainnet",
"type": "erc20Custody"
},
{
"address": "0xf091867EC603A6628eD83D274E835539D82e9cc8",
"address": "0x0000028a2eB8346cd5c0267856aB7594B7a55308",
"category": "messaging",
"chain_id": "1",
"chain_name": "eth_mainnet",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"type": "zetaToken"
},
{
"address": "0x000007Cf399229b2f5A4D043F20E90C9C98B7C6a",
"address": "0x000063A6e758D9e2f438d430108377564cf4077D",
"category": "messaging",
"chain_id": "1",
"chain_name": "eth_mainnet",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"type": "connector"
},
{
"address": "0x0000030Ec64DF25301d8414eE5a29588C4B0dE10",
"address": "0x00000fF8fA992424957F97688015814e707A0115",
"category": "omnichain",
"chain_id": "1",
"chain_name": "eth_mainnet",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"type": "erc20Custody"
},
{
Expand All @@ -217,17 +217,17 @@
"type": "tssUpdater"
},
{
"address": "0xaf28a257D292e7f0E531073f70a175b57E0261a8",
"address": "0xaeB6dDB7708467814D557e340283248be8E43124",
"category": "messaging",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"chain_id": "1",
"chain_name": "eth_mainnet",
"type": "pauser"
},
{
"address": "0xaeB6dDB7708467814D557e340283248be8E43124",
"address": "0xaf28a257D292e7f0E531073f70a175b57E0261a8",
"category": "messaging",
"chain_id": "1",
"chain_name": "eth_mainnet",
"chain_id": "56",
"chain_name": "bsc_mainnet",
"type": "pauser"
}
]
58 changes: 29 additions & 29 deletions data/addresses.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,6 @@
"address": "0x735b14BB79463307AAcBED86DAf3322B1e6226aB",
"type": "fungibleModule"
},
{
"address": "0x0000c9ec4042283e8139c74f4c64bcd1e0b9b54f",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "zetaToken"
},
{
"address": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "connector"
},
{
"address": "0x0000a7db254145767262c6a81a7ee1650684258e",
"category": "omnichain",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "erc20Custody"
},
{
"address": "0x0000c304d2934c00db1d51995b9f6996affd17c0",
"category": "messaging",
Expand Down Expand Up @@ -224,17 +203,31 @@
"type": "erc20Custody"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"address": "0x0000c9ec4042283e8139c74f4c64bcd1e0b9b54f",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "zetaToken"
},
{
"address": "0x0000ecb8cdd25a18f12daa23f6422e07fbf8b9e1",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "connector"
},
{
"address": "0x0000a7db254145767262c6a81a7ee1650684258e",
"category": "omnichain",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "tssUpdater"
"type": "erc20Custody"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"category": "omnichain",
"chain_id": "97",
"chain_name": "bsc_testnet",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "tssUpdater"
},
{
Expand All @@ -246,10 +239,10 @@
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "pauser"
"category": "omnichain",
"chain_id": "97",
"chain_name": "bsc_testnet",
"type": "tssUpdater"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
Expand All @@ -258,6 +251,13 @@
"chain_name": "goerli_testnet",
"type": "pauser"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"category": "messaging",
"chain_id": "80001",
"chain_name": "mumbai_testnet",
"type": "pauser"
},
{
"address": "0x55122f7590164Ac222504436943FAB17B62F5d7d",
"category": "messaging",
Expand Down
3 changes: 2 additions & 1 deletion lib/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import testnet from "../data/addresses.testnet.json";

Check failure on line 1 in lib/addresses.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these imports!
import mainnet from "../data/addresses.mainnet.json";
import { getChainId } from "@zetachain/networks";
import { ParamChainName, ParamSymbol, ParamType } from "./types";

export const getAddress = (type: any, network: any, symbol?: any) => {
export const getAddress = (type: ParamType, network: ParamChainName, symbol?: ParamSymbol) => {
const networks = [...testnet, ...mainnet];
let address;
if (type === "zrc20" && !symbol) {
Expand Down
1 change: 1 addition & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from "./address.tools";

Check failure on line 1 in lib/index.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these exports!
export * from "./addresses";
export * from "./types";

export { default as testnet } from "../data/addresses.testnet.json";
export { default as mainnet } from "../data/addresses.mainnet.json";
4 changes: 4 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare type ParamSymbol = "USDC.BSC" | "USDC.ETH" | "BTC.BTC" | "BNB.BSC" | "USDT.ETH" | "USDT.BSC" | "ETH.ETH" | "USDC" | "gETH" | "tMATIC" | "tBTC" | "tBNB";

Check failure on line 1 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·"USDC.BSC"·|·"USDC.ETH"·|·"BTC.BTC"·|·"BNB.BSC"·|·"USDT.ETH"·|·"USDT.BSC"·|·"ETH.ETH"·|·"USDC"·|·"gETH"·|·"tMATIC"·|·"tBTC"` with `⏎··|·"USDC.BSC"⏎··|·"USDC.ETH"⏎··|·"BTC.BTC"⏎··|·"BNB.BSC"⏎··|·"USDT.ETH"⏎··|·"USDT.BSC"⏎··|·"ETH.ETH"⏎··|·"USDC"⏎··|·"gETH"⏎··|·"tMATIC"⏎··|·"tBTC"⏎·`

Check failure on line 1 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Union type ParamSymbol members must be sorted
export declare type ParamChainName = "eth_mainnet" | "bsc_mainnet" | "btc_mainnet" | "zeta_mainnet" | "zeta_testnet" | "goerli_testnet" | "bsc_testnet" | "mumbai_testnet" | "btc_testnet";

Check failure on line 2 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·"eth_mainnet"·|·"bsc_mainnet"·|·"btc_mainnet"·|·"zeta_mainnet"·|·"zeta_testnet"·|·"goerli_testnet"·|·"bsc_testnet"·|·"mumbai_testnet"` with `⏎··|·"eth_mainnet"⏎··|·"bsc_mainnet"⏎··|·"btc_mainnet"⏎··|·"zeta_mainnet"⏎··|·"zeta_testnet"⏎··|·"goerli_testnet"⏎··|·"bsc_testnet"⏎··|·"mumbai_testnet"⏎·`

Check failure on line 2 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Union type ParamChainName members must be sorted
export declare type ParamType = "tss" | "systemContract" | "connector" | "zrc20" | "uniswapv2Factory" | "wZetaContract" | "uniswapv2Router02" | "fungibleModule" | "zetaToken" | "erc20Custody" | "tssUpdater" | "pauser";

Check failure on line 3 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Replace `·"tss"·|·"systemContract"·|·"connector"·|·"zrc20"·|·"uniswapv2Factory"·|·"wZetaContract"·|·"uniswapv2Router02"·|·"fungibleModule"·|·"zetaToken"·|·"erc20Custody"·|·"tssUpdater"` with `⏎··|·"tss"⏎··|·"systemContract"⏎··|·"connector"⏎··|·"zrc20"⏎··|·"uniswapv2Factory"⏎··|·"wZetaContract"⏎··|·"uniswapv2Router02"⏎··|·"fungibleModule"⏎··|·"zetaToken"⏎··|·"erc20Custody"⏎··|·"tssUpdater"⏎·`

Check failure on line 3 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Union type ParamType members must be sorted

Check failure on line 4 in lib/types.ts

View workflow job for this annotation

GitHub Actions / build

Delete `⏎`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@
},
"types": "./dist/lib/index.d.ts",
"version": "0.0.8"
}
}
6 changes: 5 additions & 1 deletion scripts/generate_addresses.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
echo "Generating protocol addresses..."

npx hardhat addresses --network zeta_testnet > ./data/addresses.testnet.json
npx hardhat addresses --network zeta_mainnet > ./data/addresses.mainnet.json
npx hardhat addresses --network zeta_mainnet > ./data/addresses.mainnet.json

echo "Generating protocol addresses types..."

npx ts-node scripts/generate_addresses_types.ts > ./lib/types.d.ts
42 changes: 42 additions & 0 deletions scripts/generate_addresses_types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import testnet from "../data/addresses.testnet.json";

Check failure on line 1 in scripts/generate_addresses_types.ts

View workflow job for this annotation

GitHub Actions / build

Run autofix to sort these imports!
import mainnet from "../data/addresses.mainnet.json";

const extractUniqueValues = (data: any[], key: string): string[] => {
const allValues = data.filter((item) => item[key] !== undefined).map((item) => item[key].toString());
return [...new Set(allValues)];
};

const generateTypesForKeys = (keys: string[]) => {
const networks = [...mainnet, ...testnet];

let typeDefs = "";

keys.forEach((key) => {
const uniqueValues = extractUniqueValues(networks, key);
if (uniqueValues.length > 0) {
const isNumeric = uniqueValues.every((value) => !isNaN(Number(value)));
const formattedValues = isNumeric ? uniqueValues.join(" | ") : `"${uniqueValues.join('" | "')}"`;

typeDefs += `export type Param${toCamelCase(key, true)} = ${formattedValues};\n`;
}
});

console.log(typeDefs);
};

// Modify this function to handle underscores and capitalize each word
const toCamelCase = (string: string, capitalizeFirst: boolean = false) => {
return string
.split("_")
.map((word, index) => {
if (index === 0) {
return capitalizeFirst ? word.charAt(0).toUpperCase() + word.slice(1) : word;
}
return word.charAt(0).toUpperCase() + word.slice(1);
})
.join("");
};

const keysToGenerate = ["symbol", "chain_name", "type"];

generateTypesForKeys(keysToGenerate);

0 comments on commit 30851e2

Please sign in to comment.