Skip to content

Commit

Permalink
fix: apply code review
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Mar 7, 2024
1 parent 2fb59ad commit 17d16fc
Show file tree
Hide file tree
Showing 7 changed files with 7,698 additions and 3,964 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@cosmjs/proto-signing": "^0.32.2",
"@cosmjs/stargate": "^0.32.2",
"@cosmjs/tendermint-rpc": "^0.32.2",
"@hyperlane-xyz/sdk": "^3.7.0",
"@hyperlane-xyz/utils": "^3.7.0",
"axios": "^1.6.7",
"colors": "^1.4.0",
"commander": "^11.1.0",
Expand Down
110 changes: 43 additions & 67 deletions script/shared/agent.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,19 @@
import path from "path";
import fs from "fs";
import { AgentConfig } from "@hyperlane-xyz/sdk";
import { ProtocolType } from "@hyperlane-xyz/utils";

import { Config } from "./config";
import { defaultContextPath } from "./constants";
import { Context, ContextHook } from "./context";
import { extractByte32AddrFromBech32 } from "./utils";
import { extractByte32AddrFromBech32 as fromBech32 } from "./utils";
import { getContractInfo } from "./wasm";

export type HplAgentConfig = {
name: string;
domainId: string;
chainId: string;
protocol: "cosmos";
rpcUrls: { http: string }[];
grpcUrl: string;
canonicalAsset: string; // usually same as gas token
bech32Prefix: string; // hrp
gasPrice: {
amount: string;
denom: string;
};
contractAddressBytes: 32;
index: {
from: number;
chunk: number;
};
blocks: {
reorgPeriod: 0; // instant finality ⭐️
};

mailbox: string; // hexed
interchainGasPaymaster: string; // hexed
validatorAnnounce: string; // hexed
merkleTreeHook: string; // hexed
testRecipient: string; // hexed
};

export async function fromContext(
network: Config["networks"][number],
context: Context
): Promise<HplAgentConfig> {
const toHex = (v: string) => `0x${extractByte32AddrFromBech32(v)}`;

const { hooks, core, test } = context.deployments;
): Promise<AgentConfig> {
const { hooks, core } = context.deployments;

const mailboxAddr = core?.mailbox?.address!;
const mailboxContractInfo = await getContractInfo(network, mailboxAddr);
Expand All @@ -57,39 +28,44 @@ export async function fromContext(
findHook(hooks?.required!, "hpl_hook_merkle");
if (!merkleTreeHook) throw new Error("no merkle tree hook on this context");

const agent: HplAgentConfig = {
name: network.id.split("-").join(""),
domainId: network.domain.toString(),
chainId: network.id,
protocol: "cosmos",

rpcUrls: [{ http: network.endpoint.rpc }],
grpcUrl: network.endpoint.grpc,
canonicalAsset: network.gas.denom,
bech32Prefix: network.hrp,

gasPrice: {
amount: network.gas.price,
denom: network.gas.denom,
},
contractAddressBytes: 32,

index: {
from:
// sub 1 block to make sure we don't miss any block
parseInt(mailboxContractInfo.contract_info.created.block_height) - 1,
chunk: 10_000,
},
blocks: {
reorgPeriod: 0,
const agent: AgentConfig = {
chains: {
[network.id.split("-").join("")]: {
name: network.id.split("-").join(""),
domainId: network.domain,
chainId: network.id,
protocol: ProtocolType.Cosmos,

rpcUrls: [{ http: network.endpoint.rpc }],
grpcUrls: [{ http: network.endpoint.grpc }],
canonicalAsset: network.gas.denom,
bech32Prefix: network.hrp,

gasPrice: {
amount: network.gas.price,
denom: network.gas.denom,
},
contractAddressBytes: 32,

index: {
from:
// sub 1 block to make sure we don't miss any block
parseInt(mailboxContractInfo.contract_info.created.block_height) -
1,
chunk: 10_000,
},
blocks: {
confirmations: 0,
reorgPeriod: 0,
},

// contract addresses
mailbox: fromBech32(core?.mailbox?.address!),
validatorAnnounce: fromBech32(core?.validator_announce?.address!),
interchainGasPaymaster: fromBech32(igp.address),
merkleTreeHook: fromBech32(merkleTreeHook.address),
},
},

// contract addresses
mailbox: toHex(core?.mailbox?.address!),
validatorAnnounce: toHex(core?.validator_announce?.address!),
interchainGasPaymaster: toHex(igp.address),
merkleTreeHook: toHex(merkleTreeHook.address),
testRecipient: toHex(test?.msg_receiver?.address!),
};

return agent;
Expand All @@ -101,7 +77,7 @@ export async function saveAgentConfig(
{ contextPath }: { contextPath: string } = {
contextPath: defaultContextPath,
}
): Promise<HplAgentConfig> {
): Promise<AgentConfig> {
const agentConfig = await fromContext(network, context);
const fileName = path.join(contextPath, `${network.id}.config.json`);
fs.writeFileSync(fileName, JSON.stringify(agentConfig, null, 2));
Expand Down
7 changes: 7 additions & 0 deletions script/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ export const contractNames = [
"hpl_warp_cw20",
"hpl_warp_native",
];

export const REMOTE_REPO_NAME = "many-things/cw-hyperlane";
export const REMOTE_MIN_VERSION = "v0.0.6-rc8";

export const RELEASE_API_URL = `https://api.github.com/repos/${REMOTE_REPO_NAME}/releases`;
export const RELEASE_ARTIFACT_URL = (tag: string) =>
`https://github.com/${REMOTE_REPO_NAME}/releases/download/${tag}/cw-hyperlane-${tag}.zip`;
15 changes: 6 additions & 9 deletions script/shared/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import path from "path";
import decompress from "decompress";

import { downloadFile } from "./utils";

const RELEASE_API_URL =
"https://api.github.com/repos/many-things/cw-hyperlane/releases";

const RELEASE_ARTIFACT_URL = (tag: string) =>
`https://github.com/many-things/cw-hyperlane/releases/download/${tag}/cw-hyperlane-${tag}.zip`;

export const MIN_RELEASE_VERSION = "v0.0.6-rc8";
import {
RELEASE_API_URL,
RELEASE_ARTIFACT_URL,
REMOTE_MIN_VERSION,
} from "./constants";

interface ReleaseApiResp {
tag_name: string;
Expand All @@ -23,7 +20,7 @@ export const getReleases = async (): Promise<Record<string, string>> => {
return Object.fromEntries(
releases
.map((v) => v.tag_name)
.filter((v) => v >= MIN_RELEASE_VERSION)
.filter((v) => v >= REMOTE_MIN_VERSION)
.map((v) => [v, RELEASE_ARTIFACT_URL(v)])
);
};
Expand Down
2 changes: 1 addition & 1 deletion script/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const withLink = (text: string, url: string) =>
export const extractByte32AddrFromBech32 = (addr: string): string => {
const { data } = fromBech32(addr);
const hexed = Buffer.from(data).toString("hex");
return hexed.length === 64 ? hexed : addPad(hexed);
return `0x${hexed.length === 64 ? hexed : addPad(hexed)}`;
};

export const downloadFile = async (url: string, dest: string) => {
Expand Down
Loading

0 comments on commit 17d16fc

Please sign in to comment.