Skip to content

Commit

Permalink
TS: remove old sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jan 28, 2024
1 parent d3fcaaf commit a59ea08
Show file tree
Hide file tree
Showing 8 changed files with 3,984 additions and 11,434 deletions.
15,116 changes: 3,836 additions & 11,280 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@
"main": "ts-node ./ts-scripts/main.ts",
"deploy": "npm run build; ts-node ./ts-scripts/main.ts deploy",
"build": "npm install; forge build; npm run typechain",
"typechain": "typechain --target ethers-v5 --out-dir ./ts-scripts/ethers-contracts ./out/**/*.json",
"typechain": "typechain --target ethers-v6 --out-dir ./ts-scripts/ethers-contracts ./out/**/*.json",
"test": "jest --config ./ts-scripts/jest.config.js",
"status": "ts-node ./ts-scripts/main.ts --getStatus",
"clean": "rm -rf ts-scripts/ethers-contracts/; rm -rf out/;"
},
"dependencies": {
"@certusone/wormhole-sdk": "^0.10.5",
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
"@typechain/ethers-v5": "^11.0.0",
"ethers": "^5",
"@typechain/ethers-v6": "^0.4.0",
"ethers": "^6",
"ts-node": "^10.9.1",
"typechain": "^8.2.0"
"typechain": "^8.2.0",
"@wormhole-foundation/connect-sdk": "^0.4.0-beta.2",
"@wormhole-foundation/connect-sdk-evm": "^0.4.0-beta.2",
"@wormhole-foundation/connect-sdk-evm-core": "^0.4.0-beta.2",
"@wormhole-foundation/connect-sdk-evm-cctp": "^0.4.0-beta.2"
},
"devDependencies": {
"@types/jest": "^29.5.2",
Expand All @@ -29,4 +31,4 @@
"ts-jest": "^29.1.0",
"typescript": "^5.1.3"
}
}
}
5 changes: 3 additions & 2 deletions test/extensions/HelloWormholeRefunds.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ contract HelloWormholeRefundsTest is WormholeRelayerBasicTest {
vm.deal(refundAddress, 0);

vm.selectFork(sourceFork);

helloSource.sendCrossChainGreeting{value: cost}(targetChain, address(helloTarget), "Hello Wormhole!", targetChain, refundAddress);

performDelivery();
Expand All @@ -48,10 +47,12 @@ contract HelloWormholeRefundsTest is WormholeRelayerBasicTest {

vm.recordLogs();

vm.selectFork(targetFork);
address payable refundAddress = payable(0x1234567890123456789012345678901234567890);
vm.deal(refundAddress, 0);

helloSource.sendCrossChainGreeting{value: cost}(targetChain, address(helloTarget), "Hello Wormhole!", sourceChain, refundAddress);
vm.selectFork(sourceFork);
helloSource.sendCrossChainGreeting{value: cost}(targetChain, address(helloTarget), "Hello Wormhole!", targetChain, refundAddress);

performDelivery();

Expand Down
29 changes: 15 additions & 14 deletions ts-scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import { HelloWormhole__factory } from "./ethers-contracts"
import { HelloWormhole__factory } from "./ethers-contracts";
import {
loadConfig,
getWallet,
storeDeployedAddresses,
getChain,
loadDeployedAddresses,
} from "./utils"
} from "./utils";

export async function deploy() {
const config = loadConfig()
const config = loadConfig();

const deployed = loadDeployedAddresses()
for (const chainId of config.chains.map(c => c.chainId)) {
const chain = getChain(chainId)
const signer = getWallet(chainId)
const deployed = loadDeployedAddresses();
for (const chainId of config.chains.map((c) => c.chainId)) {
const chain = getChain(chainId);
const signer = getWallet(chainId);

const helloWormhole = await new HelloWormhole__factory(signer).deploy(
chain.wormholeRelayer
)
await helloWormhole.deployed()
);
await helloWormhole.waitForDeployment();
const address = await helloWormhole.getAddress();

deployed.helloWormhole[chainId] = address;

deployed.helloWormhole[chainId] = helloWormhole.address

console.log(
`HelloWormhole deployed to ${helloWormhole.address} on ${chain.description} (chain ${chainId})`
)
`HelloWormhole deployed to ${address} on ${chain.description} (chain ${chainId})`
);
}

storeDeployedAddresses(deployed)
storeDeployedAddresses(deployed);
}
35 changes: 13 additions & 22 deletions ts-scripts/getStatus.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
import {
loadConfig,
getWallet,
storeDeployedAddresses,
getChain,
loadDeployedAddresses,
} from "./utils";
import { relayer, ChainName } from "@certusone/wormhole-sdk";
import { Chain, Wormhole, api } from "@wormhole-foundation/connect-sdk";
import { EvmPlatform } from "@wormhole-foundation/connect-sdk-evm";

export async function getStatus(
sourceChain: ChainName,
transactionHash: string
sourceChain: Chain,
txid: string
): Promise<{ status: string; info: string }> {
const info = await relayer.getWormholeRelayerInfo(
sourceChain,
transactionHash,
{ environment: "TESTNET" }
);
const status =
info.targetChainStatus.events[0]?.status || DeliveryStatus.PendingDelivery;
return { status, info: info.stringified || "Info not obtained" };
}
const wh = new Wormhole("Testnet", [EvmPlatform]);
const ctx = wh.getChain(sourceChain);
const [msgid] = await ctx.parseTransaction(txid);

export const DeliveryStatus = relayer.DeliveryStatus;
const info = await wh.getTransactionStatus(msgid!);
const status = info?.globalTx?.originTx.status || "Pending";
return { status, info: JSON.stringify(info) || "Info not obtained" };
}

export const waitForDelivery = async (
sourceChain: ChainName,
sourceChain: Chain,
transactionHash: string
) => {
let pastStatusString = "";
Expand All @@ -42,7 +33,7 @@ export const waitForDelivery = async (
console.log(res.info);
pastStatusString = res.info;
}
if (res.status !== DeliveryStatus.PendingDelivery) break;
if (res.status !== "Pending") break;
console.log(`\nContinuing to wait for delivery\n`);
}
};
14 changes: 7 additions & 7 deletions ts-scripts/hello_wormhole.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { describe, expect, test } from "@jest/globals";
import { toChain } from "@wormhole-foundation/connect-sdk";
import { ethers } from "ethers";
import { getHelloWormhole, getWallet, getDeliveryHash, sleep } from "./utils";
import { CHAIN_ID_TO_NAME } from "@certusone/wormhole-sdk";
import { waitForDelivery } from "./getStatus";
import { getHelloWormhole } from "./utils";

const sourceChain = 6;
const targetChain = 14;

import "@wormhole-foundation/connect-sdk-evm-core";

describe("Hello Wormhole Integration Tests on Testnet", () => {
test(
"Tests the sending of a random greeting",
Expand All @@ -19,22 +21,20 @@ describe("Hello Wormhole Integration Tests on Testnet", () => {
targetChain
);
console.log(
`Cost of sending the greeting: ${ethers.utils.formatEther(
cost
)} testnet AVAX`
`Cost of sending the greeting: ${ethers.formatEther(cost)} testnet AVAX`
);

console.log(`Sending greeting: ${arbitraryGreeting}`);
const tx = await sourceHelloWormholeContract.sendCrossChainGreeting(
targetChain,
targetHelloWormholeContract.address,
await targetHelloWormholeContract.getAddress(),
arbitraryGreeting,
{ value: cost }
);
console.log(`Transaction hash: ${tx.hash}`);
const rx = await tx.wait();

await waitForDelivery(CHAIN_ID_TO_NAME[sourceChain], tx.hash);
await waitForDelivery(toChain(sourceChain), tx.hash);

console.log(`Reading greeting`);
const readGreeting = await targetHelloWormholeContract.latestGreeting();
Expand Down
75 changes: 43 additions & 32 deletions ts-scripts/main.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import * as ethers from "ethers"
import * as ethers from "ethers";
import {
checkSubcommand,
getArg,
getHelloWormhole,
loadConfig,
checkFlag
} from "./utils"
import { deploy } from "./deploy"
import { getStatus } from "./getStatus"
checkFlag,
} from "./utils";
import { deploy } from "./deploy";
import { getStatus } from "./getStatus";

import "@wormhole-foundation/connect-sdk-evm-core";

async function main() {
if (checkSubcommand("sendGreeting")) {
await sendGreeting()
return
await sendGreeting();
return;
}
if (checkSubcommand("deploy")) {
await deploy()
return
await deploy();
return;
}
if (checkSubcommand("read")) {
await read()
return
await read();
return;
}
if(checkFlag("--getStatus")) {
const status = await getStatus("avalanche", getArg(["--txHash", "--tx", "-t"]) || "");
if (checkFlag("--getStatus")) {
const status = await getStatus(
"Avalanche",
getArg(["--txHash", "--tx", "-t"]) || ""
);
console.log(status.info);
}
}
Expand All @@ -32,32 +37,38 @@ async function sendGreeting() {
// const from = Number(getArg(["--from", "-f"]))
// const to = Number(getArg(["--to", "-t"]))

const from = 6
const to = 14
const greeting = getArg(["--greeting", "-g"]) ?? "Hello, Wormhole!"
const from = 6;
const to = 14;
const greeting = getArg(["--greeting", "-g"]) ?? "Hello, Wormhole!";

const helloWormhole = getHelloWormhole(from)
const cost = await helloWormhole.quoteCrossChainGreeting(to)
console.log(`cost: ${ethers.utils.formatEther(cost)}`)
const helloWormhole = getHelloWormhole(from);
const cost = await helloWormhole.quoteCrossChainGreeting(to);
console.log(`cost: ${ethers.formatEther(cost)}`);

const tx = await helloWormhole
.sendCrossChainGreeting(to, getHelloWormhole(to).address, greeting, {value: cost});
const tx = await helloWormhole.sendCrossChainGreeting(
to,
await getHelloWormhole(to).getAddress(),
greeting,
{ value: cost }
);
await tx.wait();
console.log(`Greeting "${greeting}" sent from chain ${from} to chain ${to}\nTransaction hash ${tx.hash}\nView Transaction at https://testnet.snowtrace.io/tx/${tx.hash}`)
console.log(
`Greeting "${greeting}" sent from chain ${from} to chain ${to}\nTransaction hash ${tx.hash}\nView Transaction at https://testnet.snowtrace.io/tx/${tx.hash}`
);
}

async function read(s = "State: \n\n") {
for (const chainId of loadConfig().chains.map(c => c.chainId)) {
let i = 0
const helloWormhole = getHelloWormhole(chainId)
for (const chainId of loadConfig().chains.map((c) => c.chainId)) {
let i = 0;
const helloWormhole = getHelloWormhole(chainId);
const greeting = await helloWormhole.latestGreeting();
s += `chain ${chainId}: ${greeting}\n`
s += "\n"
s += `chain ${chainId}: ${greeting}\n`;
s += "\n";
}
console.log(s)
console.log(s);
}

main().catch(e => {
console.error(e)
process.exit(1)
})
main().catch((e) => {
console.error(e);
process.exit(1);
});
Loading

0 comments on commit a59ea08

Please sign in to comment.