Skip to content

Commit

Permalink
chore: add axl to test config + script to get ibc currencies (#861)
Browse files Browse the repository at this point in the history
Signed-off-by: Norman Meier <[email protected]>
  • Loading branch information
n0izn0iz authored Jan 10, 2024
1 parent 13d9ef4 commit db14114
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 3 deletions.
218 changes: 218 additions & 0 deletions networks.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/networks/cosmos-hub-theta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const cosmosThetaNetwork: NetworkInfo = {
icon: "icons/networks/cosmos-hub.svg",
features: [],
overrides: "cosmos-registry:cosmoshubtestnet",
registryName: "cosmoshubtestnet",
currencies: cosmosHubThetaCurrencies,
txExplorer: "https://explorer.theta-testnet.polypore.xyz/transactions/$hash",
accountExplorer:
Expand Down
1 change: 1 addition & 0 deletions packages/networks/cosmos-hub/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const cosmosNetwork: NetworkInfo = {
features: [],
currencies: cosmosHubCurrencies,
overrides: "cosmos-registry:cosmoshub",
registryName: "cosmoshub",
txExplorer: "https://www.mintscan.io/cosmos/txs/$hash",
accountExplorer: "https://www.mintscan.io/cosmos/account/$address",
contractExplorer: "https://www.mintscan.io/cosmos/account/$address",
Expand Down
1 change: 1 addition & 0 deletions packages/networks/cosmos-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const networksFromCosmosRegistry = (): CosmosNetworkInfo[] => {
: chain.pretty_name + " Testnet"
: chain.pretty_name,
chainId: chain.chain_id,
registryName: chain.chain_name,
kind: NetworkKind.Cosmos,
currencies: chainAssets
.filter((asset) => !(asset.ibc || asset.base.startsWith("ibc/"))) // TODO: remove ibc filter and correctly map ibc currencies
Expand Down
1 change: 1 addition & 0 deletions packages/networks/osmosis-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NetworkFeature, NetworkInfo, NetworkKind } from "../types";
export const osmosisTestnetNetwork: NetworkInfo = {
id: "osmosis-testnet",
kind: NetworkKind.Cosmos,
registryName: "osmosistestnet",
chainId: "osmo-test-5",
overrides: "cosmos-registry:osmosistestnet",
displayName: "Osmosis Latest Testnet",
Expand Down
1 change: 1 addition & 0 deletions packages/networks/osmosis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NetworkKind, NetworkInfo, NetworkFeature } from "../types";
export const osmosisNetwork: NetworkInfo = {
id: "osmosis",
kind: NetworkKind.Cosmos,
registryName: "osmosis",
chainId: "osmosis-1",
displayName: "Osmosis",
icon: "icons/networks/osmosis.svg",
Expand Down
11 changes: 11 additions & 0 deletions packages/networks/teritori-testnet/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ export const teritoriTestnetCurrencies: CurrencyInfo[] = [
kind: "native",
color: currencyTORIcolor,
},
{
kind: "ibc",
denom:
"ibc/2CC0B1B7A981ACC74854717F221008484603BB8360E81B262411B0D830EDE9B0",
sourceNetwork: "cosmos-registry:axelartestnet",
sourceDenom: "uaxl",
sourceChannelId: "channel-399",
sourceChannelPort: "transfer",
destinationChannelId: "channel-0",
destinationChannelPort: "transfer",
},
];
1 change: 1 addition & 0 deletions packages/networks/teritori-testnet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const teritoriTestnetNetwork: NetworkInfo = {
kind: NetworkKind.Cosmos,
chainId: "teritori-test-5",
displayName: "Teritori Testnet",
registryName: "teritoritestnet",
icon: "icons/networks/teritori.svg",
features: [
NetworkFeature.NFTMarketplace,
Expand Down
1 change: 1 addition & 0 deletions packages/networks/teritori/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const teritoriNetwork: CosmosNetworkInfo = {
NetworkFeature.NFTLaunchpad,
NetworkFeature.RiotP2E,
],
registryName: "teritori",
overrides: "cosmos-registry:teritori",
walletUrlForStaking: "https://app.teritori.com/staking",
currencies: teritoriCurrencies,
Expand Down
1 change: 1 addition & 0 deletions packages/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type CosmosNetworkInfo = NetworkInfoBase & {
restEndpoint: string;
rpcEndpoint: string;
stakeCurrency: string;
registryName: string;
gasPriceStep: {
low: number;
average: number;
Expand Down
7 changes: 7 additions & 0 deletions packages/scripts/dumpIBCInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ibc } from "chain-registry";

const main = async () => {
console.log(JSON.stringify(ibc, null, 2));
};

main();
4 changes: 1 addition & 3 deletions packages/scripts/dumpNetworks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { allNetworks } from "../networks";

const main = async () => {
for (const n of allNetworks) {
console.log(n);
}
console.log(JSON.stringify(allNetworks, null, 2));
};

main();
159 changes: 159 additions & 0 deletions packages/scripts/getIBCCurrencyInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import { IBCInfo } from "@chain-registry/types";
import { ibc } from "chain-registry";
import { program } from "commander";
import nodeReadline from "node:readline";

import {
NetworkKind,
getCosmosNetwork,
parseNetworkObjectId,
} from "../networks";
import { IBCCurrencyInfo } from "../networks/ibc";
import { getIBCDenom } from "../utils/ibc";

// find IBC currency info from chain-registry

const main = async () => {
program.argument("<src-currency-id>", "source currency id");
program.argument("<dst-network-id>", "destination network id");
program.parse();

const [srcCurrencyId, dstNetworkId] = program.args;

const [srcNetwork, srcCurrencyDenom] = parseNetworkObjectId(srcCurrencyId);
if (srcNetwork?.kind !== NetworkKind.Cosmos) {
throw new Error(
`invalid source currency id: ${srcCurrencyId}: invalid network`,
);
}
if (!srcCurrencyDenom) {
throw new Error(
`invalid source currency id: ${srcCurrencyId}: invalid denom`,
);
}
// console.log(`source network: ${srcNetwork.registryName}`);

const dstNetwork = getCosmosNetwork(dstNetworkId);
if (!dstNetwork) {
throw new Error(`invalid destination network id: ${dstNetworkId}`);
}
// console.log(`destination network: ${dstNetwork.registryName}`);

const ibcInfo = ibc
.filter(
(ibcInfo) =>
(ibcInfo.chain_1.chain_name === srcNetwork.registryName &&
ibcInfo.chain_2.chain_name === dstNetwork.registryName) ||
(ibcInfo.chain_2.chain_name === srcNetwork.registryName &&
ibcInfo.chain_1.chain_name === dstNetwork.registryName),
)
.map((ibcInfo) => {
if (
ibcInfo.chain_1.chain_name === srcNetwork.registryName &&
ibcInfo.chain_2.chain_name === dstNetwork.registryName
) {
return ibcInfo;
}
return {
chain_1: ibcInfo.chain_2,
chain_2: ibcInfo.chain_1,
channels: ibcInfo.channels.map((channel) => ({
chain_1: channel.chain_2,
chain_2: channel.chain_1,
ordering: channel.ordering,
version: channel.version,
})),
};
});
if (ibcInfo.length) {
printOutput(ibcInfo, srcNetwork.id, srcCurrencyDenom);
return;
}

console.error("No IBC channel found, please enter manually...");

const readline = nodeReadline.createInterface({
input: process.stdin,
output: process.stdout,
});
const srcChannelId = await promptForString(readline, `Source channel id: `);
const dstChannelId = await promptForString(
readline,
`Destination channel id: `,
);
readline.close();

printOutput(
[
{
chain_1: {
chain_name: srcNetwork.registryName,
client_id: "",
connection_id: "",
},
chain_2: {
chain_name: dstNetwork.registryName,
client_id: "",
connection_id: "",
},
channels: [
{
chain_1: {
channel_id: `${srcChannelId}`,
port_id: "transfer",
},
chain_2: {
channel_id: `${dstChannelId}`,
port_id: "transfer",
},
ordering: "",
version: "",
},
],
},
],
srcNetwork.id,
srcCurrencyDenom,
);
};

const printOutput = (
ibcInfo: IBCInfo[],
srcNetworkId: string,
denom: string,
) => {
const channels = ibcInfo.map((ibcInfo) => ibcInfo.channels).flat();
if (!channels.length) {
throw new Error("no IBC channel found");
}
const channel = channels[0];

const currency: IBCCurrencyInfo = {
kind: "ibc",
denom: getIBCDenom(
channel.chain_2.port_id,
channel.chain_2.channel_id,
denom,
),
sourceNetwork: srcNetworkId,
sourceDenom: denom,
sourceChannelId: channel.chain_1.channel_id,
sourceChannelPort: channel.chain_1.port_id,
destinationChannelId: channel.chain_2.channel_id,
destinationChannelPort: channel.chain_2.port_id,
};

console.log(JSON.stringify(currency, null, 2));
};

const promptForString = async (
readline: nodeReadline.Interface,
prompt: string,
) => {
const input = await new Promise<string>((resolve) =>
readline.question(prompt, resolve),
);
return input;
};

main();
11 changes: 11 additions & 0 deletions packages/utils/ibc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { sha256 } from "ethers/lib/utils";

export const getIBCDenom = (
portId: string,
channelId: string,
denom: string,
) => {
const path = `${portId}/${channelId}/${denom}`;
const h = sha256(Buffer.from(path, "utf-8")).substring(2);
return `ibc/${h.toUpperCase()}`;
};

0 comments on commit db14114

Please sign in to comment.