Skip to content

Commit

Permalink
JS/SDK: Handle relayer move
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley committed Apr 1, 2024
1 parent 2b97d5b commit 5111ff9
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 35 deletions.
1 change: 1 addition & 0 deletions sdk/js/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ yarn-error.log*
# ethereum contracts
/contracts
/src/ethers-contracts
/src/ethers-relayer-contracts

# tsproto output
/src/proto
Expand Down
1 change: 1 addition & 0 deletions sdk/js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.10.14

Support for move of relayer ethereum contracts
Blast Sepolia support

## 0.10.13
Expand Down
2 changes: 1 addition & 1 deletion sdk/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"sideEffects": false,
"repository": "https://github.com/certusone/wormhole/tree/main/sdk/js",
"scripts": {
"build-contracts": "cd ../../ethereum && make forge_dependencies && npm run build && cd ../sdk/js && node scripts/copyContracts.js",
"build-contracts": "cd ../../ethereum && make forge_dependencies && npm run build && cd ../ethereum-relayer && make forge_dependencies && npm run build && cd ../sdk/js && node scripts/copyContracts.js",
"build-abis": "typechain --target=ethers-v5 --out-dir=src/ethers-contracts/abi src/abi/Wormhole.abi.json",
"build-idl": "node scripts/compileAnchorIdls.js",
"build-deps": "npm run build-abis && npm run build-contracts && npm run build-idl",
Expand Down
4 changes: 4 additions & 0 deletions sdk/js/scripts/copyContracts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const copydir = require("copy-dir");
console.log("Copying from ../../ethereum/ethers-contracts");
copydir.sync("../../ethereum/ethers-contracts", "src/ethers-contracts");
copydir.sync(
"../../ethereum-relayer/ethers-contracts",
"src/ethers-relayer-contracts"
);
40 changes: 23 additions & 17 deletions sdk/js/scripts/copyEthersTypes.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
const fs = require("fs");
["lib/esm", "lib/cjs"].forEach((buildPath) => {
fs.readdirSync("src/ethers-contracts").forEach((file) => {
if (file.endsWith(".d.ts")) {
fs.copyFileSync(
`src/ethers-contracts/${file}`,
`${buildPath}/ethers-contracts/${file}`
);
}
});

fs.readdirSync("src/ethers-contracts/abi").forEach((file) => {
if (file.endsWith(".d.ts")) {
fs.copyFileSync(
`src/ethers-contracts/abi/${file}`,
`${buildPath}/ethers-contracts/abi/${file}`
);
}
function copyTypes(srcDir) {
["lib/esm", "lib/cjs"].forEach((buildPath) => {
fs.readdirSync(srcDir).forEach((file) => {
if (file.endsWith(".d.ts")) {
fs.copyFileSync(
`src/ethers-contracts/${file}`,
`${buildPath}/ethers-contracts/${file}`
);
}
});

fs.readdirSync(srcDir).forEach((file) => {
if (file.endsWith(".d.ts")) {
fs.copyFileSync(
`src/ethers-contracts/abi/${file}`,
`${buildPath}/ethers-contracts/abi/${file}`
);
}
});
});
});
}

copyTypes("src/ethers-contracts");
copyTypes("src/ethers-relayer-contracts");
2 changes: 1 addition & 1 deletion sdk/js/src/relayer/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ChainName, Network } from "../";
import {
WormholeRelayer,
WormholeRelayer__factory,
} from "../ethers-contracts/";
} from "../ethers-relayer-contracts/";

type AddressInfo = {
wormholeRelayerAddress?: string;
Expand Down
2 changes: 1 addition & 1 deletion sdk/js/src/relayer/relayer/deliver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber, ethers, ContractReceipt } from "ethers";
import { IWormholeRelayer__factory } from "../../ethers-contracts";
import { IWormholeRelayer__factory } from "../../ethers-relayer-contracts";
import {
ChainName,
toChainName,
Expand Down
8 changes: 4 additions & 4 deletions sdk/js/src/relayer/relayer/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import {
CCTPKey,
} from "../structs";
import { InfoRequestParams } from "./info";
import { Implementation__factory } from "../../ethers-contracts/";
import {
DeliveryProvider,
DeliveryProvider__factory,
Implementation__factory,
} from "../../ethers-contracts/";
import { DeliveryEvent } from "../../ethers-contracts/WormholeRelayer";
import { VaaKeyStruct } from "../../ethers-contracts/IWormholeRelayer.sol/IWormholeRelayer";
} from "../../ethers-relayer-contracts/";
import { DeliveryEvent } from "../../ethers-relayer-contracts/WormholeRelayer";
import { VaaKeyStruct } from "../../ethers-relayer-contracts/IWormholeRelayer.sol/IWormholeRelayer";

export type DeliveryTargetInfo = {
status: DeliveryStatus | string;
Expand Down
10 changes: 5 additions & 5 deletions sdk/js/src/relayer/relayer/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
TokenTransferParsed,
} from "./deliver";
import { ERC20__factory } from "../../ethers-contracts";
import { IWormholeRelayer__factory } from "../../ethers-relayer-contracts";

export type InfoRequestParams = {
environment?: Network;
Expand Down Expand Up @@ -79,11 +80,10 @@ export async function getPriceAndRefundInfo(
const wormholeRelayerAddress =
optionalParams?.wormholeRelayerAddress ||
getWormholeRelayerAddress(sourceChain, environment);
const sourceWormholeRelayer =
ethers_contracts.IWormholeRelayer__factory.connect(
wormholeRelayerAddress,
sourceChainProvider
);
const sourceWormholeRelayer = IWormholeRelayer__factory.connect(
wormholeRelayerAddress,
sourceChainProvider
);
const deliveryProviderAddress =
optionalParams?.deliveryProviderAddress ||
(await sourceWormholeRelayer.getDefaultDeliveryProvider());
Expand Down
12 changes: 6 additions & 6 deletions sdk/js/src/relayer/relayer/send.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers, BigNumber } from "ethers";
import { ethers_contracts } from "../..";
import { VaaKeyStruct } from "../../ethers-contracts/MockRelayerIntegration";
import { VaaKeyStruct } from "../../ethers-relayer-contracts/MockRelayerIntegration";
import { IWormholeRelayer__factory } from "../../ethers-relayer-contracts";
import {
ChainId,
ChainName,
Expand Down Expand Up @@ -46,11 +47,10 @@ export async function sendToEvm(
const wormholeRelayerAddress =
sendOptionalParams?.wormholeRelayerAddress ||
getWormholeRelayerAddress(sourceChain, environment);
const sourceWormholeRelayer =
ethers_contracts.IWormholeRelayer__factory.connect(
wormholeRelayerAddress,
signer
);
const sourceWormholeRelayer = IWormholeRelayer__factory.connect(
wormholeRelayerAddress,
signer
);

const refundLocationExists =
sendOptionalParams?.refundChainId !== undefined &&
Expand Down

0 comments on commit 5111ff9

Please sign in to comment.