Skip to content

Commit

Permalink
feat: add warp route guide
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongsu-hong committed Feb 27, 2024
1 parent 58ba3da commit b68ca6d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
38 changes: 33 additions & 5 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,7 @@ docker compose down
# if you want to use private key as signing account. then you can set `--pk` option
# if you want to use mnemonic as signing account. then you can set `--mn` option
# or if you want to use custom rpc endpoint. then you can set `--endpoint` option
yarn cw-hpl-exp deploy-test-recipient \
--pk 'YOUR_PRIVATE_KEY'
--mn 'YOUR_MNEMONIC_PHRASE'
--endpoint 'https://rpc.sepolia.org'
yarn cw-hpl-exp deploy-test-recipient --pk 'YOUR_PRIVATE_KEY'
```

## 6. Run Messaging Test
Expand All @@ -199,7 +196,38 @@ cast send \
yarn cw-hpl contract test-dispatch -n osmo-test-5 11155111 $SEPOLIA_TEST_RECIPIENT_ADDRESS hello
```

## 7. Done 🎉
## 7. Warp Route

```bash
# deploy warp route on sepolia
yarn cw-hpl-exp warp deploy --pk 'YOUR_PRIVATE_KEY'

# then output will like this
{ "hypErc20Osmo": "0x..." }

# deploy warp route on osmo-test-5
yarn cw-hpl warp deploy create ./warp/uosmo.json -n osmo-test-5

# regiter osmo-test-5 warp route to sepolia warp route
yarn cw-hpl-exp warp link $hypErc20Osmo 1037 $OSMOSIS_WARP_ROUTE_ADDRESS --pk 'YOUR_PRIVATE_KEY'

# also register sepolia warp route to osmo-test-5 warp route
yarn cw-hpl warp link \
--asset-type native \
--asset-id uosmo \
--target-domain 11155111 \
--warp-address $hypErc20Osmo \
-n osmo-test-5

# test transfer
yarn cw-hpl warp transfer \
--asset-type native \
--asset-id uosmo \
--target-domain 11155111 \
-n osmo-test-5
```
## 8. Done 🎉
This is it! You have successfully deployed Hyperlane between Osmosis Testnet and Sepolia Testnet.
Expand Down
7 changes: 7 additions & 0 deletions example/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fromBech32 } from "@cosmjs/encoding";
import {
PublicClient,
Transport,
Expand All @@ -20,6 +21,12 @@ export const logTx = (title: string, tx: string) =>
`tx hash: "${tx.green}". Waiting for confirmation...`
);

export const extractByte32AddrFromBech32 = (addr: string): string => {
const { data } = fromBech32(addr);
const hexed = Buffer.from(data).toString("hex");
return hexed.length === 64 ? hexed : addPad(hexed);
};

export const expectNextContractAddr = async (
query: PublicClient<Transport, Chain>,
account: Account
Expand Down
19 changes: 10 additions & 9 deletions example/src/warp.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { Hex, encodeFunctionData, isAddress, isHex } from "viem";
import { Command } from "commander";
import { Hex, isAddress } from "viem";

import { HypERC20 } from "../abi/HypERC20";
import { ProxyAdmin } from "../abi/ProxyAdmin";
import { TransparentUpgradeableProxy } from "../abi/TransparentUpgradeableProxy";

import { HYP_MAILBOX } from "./constants";
import { CONTAINER, Dependencies } from "./ioc";
import { addPad, expectNextContractAddr, logTx } from "./utils";
import { Command } from "commander";
import {
expectNextContractAddr,
extractByte32AddrFromBech32,
logTx,
} from "./utils";

const warpCmd = new Command("warp");

warpCmd.command("deploy-route").action(deployWarpRoute);
warpCmd.command("deploy").action(deployWarpRoute);
warpCmd
.command("link-route")
.command("link")
.argument("<warp>", "address of warp route")
.argument("<domain>", "destination domain to set")
.argument("<route>", "destination address to set")
Expand Down Expand Up @@ -66,13 +68,12 @@ async function linkWarpRoute(warp: string, domain: string, route: string) {
} = CONTAINER.get(Dependencies);

if (!isAddress(warp)) throw new Error("Invalid warp address");
if (!isHex(route)) throw new Error("Invalid route address");

const tx = await exec.writeContract({
abi: HypERC20.abi,
address: warp,
functionName: "enrollRemoteRouter",
args: [parseInt(domain), `0x${addPad(route)}`],
args: [parseInt(domain), `0x${extractByte32AddrFromBech32(route)}`],
});
logTx(`Linking warp route with external chain ${domain}`, tx);
await query.waitForTransactionReceipt({ hash: tx });
Expand Down

0 comments on commit b68ca6d

Please sign in to comment.