Skip to content

Commit

Permalink
update to latest versions
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jan 4, 2024
1 parent 7379c4a commit 3926dc8
Show file tree
Hide file tree
Showing 19 changed files with 523 additions and 290 deletions.
38 changes: 34 additions & 4 deletions sdk/js-connect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@ npm install @wormhole-foundation/wormhole-sdk-solana-tokenbridge

A developer would use the core wormhole-sdk package in conjunction with 1 or more of the chain context packages. Most developers don't use every single chain and may only use a couple, this allows developers to import only the dependencies they actually need.

Getting started is simple, just import and pass in the [Platform](#platforms) modules you wish to support as an argument to the `Wormhole` class.
Getting started is simple, first import the [Platforms](#platforms) and [Protocols](#protocols) you plan to use.

```ts
import { Wormhole, Signer } from '@wormhole-foundation/wormhole-sdk';
import { EvmContext } from '@wormhole-foundation/wormhole-sdk-evm';
import { SolanaContext } from '@wormhole-foundation/wormhole-sdk-solana';

// include the protocols you wish to use
import "@wormhole-foundation/wormhole-sdk-evm-core"
import "@wormhole-foundation/wormhole-sdk-evm-tokenbridge"
import "@wormhole-foundation/wormhole-sdk-solana-core"
import "@wormhole-foundation/wormhole-sdk-solana-tokenbridge"
```

Then pass in the [Platform](#platforms) modules you wish to support as an argument to the `Wormhole` class.

```ts
const network = "Mainnet"; // Or "Testnet"
const wh = new Wormhole(network, [EvmContext, SolanaContext]);

Expand Down Expand Up @@ -238,7 +239,6 @@ Using the `WormholeTransfer` abstraction is the recommended way to interact with
```ts
import {signSendWait} from '@wormhole-foundation/wormhole-sdk';

import "@wormhole-foundation/wormhole-sdk-evm-core"
import "@wormhole-foundation/wormhole-sdk-evm-tokenbridge"

// ...
Expand All @@ -253,6 +253,36 @@ const txids = await signSendWait(srcChain, txGenerator, src.signer) // => TxHash

Supported protocols are defined in the [definitions module](https://github.com/wormhole-foundation/connect-sdk/tree/develop/core/definitions/src/protocols)

#### Core Bridge

The Core messaging bridge can also be used to pass arbitrary messages.

```ts
import {signSendWait} from '@wormhole-foundation/wormhole-sdk';

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

// ...

const bridge = await srcChain.getWormholeCore(); // => WormholeCore<'Evm'>
const msg = encoding.bytes.encode("lol");
const nonce = 0;
const consistencyLevel = 0;

// Publish message
const publishTxs = bridge.publishMessage(address.address, encoding.bytes.encode("lol"), nonce, consistencyLevel);
const txids = await signSendWait(chain, publishTxs, signer);

// Fetch VAA
const [whm] = await chain.parseTransaction(txids[0]!.txid);
const vaa = await wh.getVaa(whm!, "Uint8Array", 60_000);

// Verify message
const verifyTxs = coreBridge.verifyMessage(address.address, vaa!);
const verifyTxIds = await signSendWait(chain, verifyTxs, signer);
```


### Signers

In order to sign transactions, an object that fulfils the `Signer` interface is required. This is a simple interface that can be implemented by wrapping a web wallet or other signing mechanism.
Expand Down
4 changes: 4 additions & 0 deletions sdk/js-connect/core/base/__tests__/amount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { normalizeAmount } from "../src/";

describe("Amount Tests", function () {
// amt, decimals, expected
const cases: [number | string, bigint, bigint][] = [
[1, 18n, BigInt(1 + "0".repeat(18))],
[0, 18n, BigInt(0)],
Expand All @@ -12,6 +13,9 @@ describe("Amount Tests", function () {
// should we throw on negative?
[-3, 2n, BigInt(-300)],
["-3", 2n, BigInt(-300)],
[1, 0n, BigInt(1)],
["1", 0n, BigInt(1)],
["1.0", 1n, BigInt(10)],
];

const badCases: [number | string, bigint][] = [
Expand Down
3 changes: 1 addition & 2 deletions sdk/js-connect/core/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"files": [
"lib/**/*",
"src/**/*"
"lib/**/*"
],
"dependencies": {
"@scure/base": "^1.1.3"
Expand Down
52 changes: 30 additions & 22 deletions sdk/js-connect/core/base/src/constants/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,37 @@ const circleAPIs = [

// https://developers.circle.com/stablecoin/docs/cctp-technical-reference#domain-list
const circleDomains = [
["Ethereum", 0],
["Ethereum", 0],
["Avalanche", 1],
["Optimism", 2],
["Arbitrum", 3],
["Base", 6],
["Optimism", 2],
["Arbitrum", 3],
["Solana", 5],
["Base", 6],
] as const satisfies MapLevel<Chain, number>;

const usdcContracts = [[
"Mainnet", [
["Ethereum", "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
["Avalanche", "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e"],
["Arbitrum", "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"],
["Optimism", "0x179522635726710dd7d2035a81d856de4aa7836c"],
["Base", "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"],
]], [
"Testnet", [
["Avalanche", "0x5425890298aed601595a70AB815c96711a31Bc65"],
["Arbitrum", "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63"],
["Ethereum", "0x07865c6e87b9f70255377e024ace6630c1eaa37f"],
["Optimism", "0xe05606174bac4A6364B31bd0eCA4bf4dD368f8C6"],
["Base", "0xf175520c52418dfe19c8098071a252da48cd1c19"],
]],
const usdcContracts = [
[
"Mainnet",
[
["Ethereum", "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"],
["Avalanche", "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e"],
["Arbitrum", "0xaf88d065e77c8cC2239327C5EDb3A432268e5831"],
["Optimism", "0x179522635726710dd7d2035a81d856de4aa7836c"],
["Solana", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"],
["Base", "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"],
],
],
[
"Testnet",
[
["Avalanche", "0x5425890298aed601595a70AB815c96711a31Bc65"],
["Arbitrum", "0xfd064A18f3BF249cf1f87FC203E90D8f650f2d63"],
["Ethereum", "0x07865c6e87b9f70255377e024ace6630c1eaa37f"],
["Optimism", "0xe05606174bac4A6364B31bd0eCA4bf4dD368f8C6"],
["Solana", "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"],
["Base", "0xf175520c52418dfe19c8098071a252da48cd1c19"],
],
],
] as const satisfies MapLevel<Network, MapLevel<Chain, string>>;

export const [circleChains, circleChainIds] = zip(circleDomains);
Expand All @@ -46,8 +55,7 @@ export const circleAPI = constMap(circleAPIs);

export const usdcContract = constMap(usdcContracts);

export const isCircleChain = (chain: string): chain is CircleChain =>
circleChainId.has(chain);
export const isCircleChain = (chain: string): chain is CircleChain => circleChainId.has(chain);

export const isCircleChainId = (chainId: number): chainId is CircleChainId =>
circleChainIdToChain.has(chainId);
Expand Down Expand Up @@ -85,7 +93,7 @@ export const toCircleChainId = (chain: number | bigint | string): CircleChainId
throw Error(`Cannot convert to ChainId: ${chain}`);
};

export const toCircleChain = (chain: number | string | bigint): Chain => {
export const toCircleChain = (chain: number | string | bigint): CircleChain => {
switch (typeof chain) {
case "string":
if (isCircleChain(chain)) return chain;
Expand Down
7 changes: 7 additions & 0 deletions sdk/js-connect/core/base/src/constants/contracts/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,12 @@ export const circleContracts = [[
wormholeRelayer: "",
wormhole: "0x2703483B1a5a7c577e8680de9Df8Be03c6f30e3c",
}],
[
"Solana", {
tokenMessenger: 'CCTPiPYPc6AsJuwueEnWgSgucamXDZwBd53dQ11YiKX3',
messageTransmitter: 'CCTPmbSD7gX1bxKPAmg77w8oFzNFpaQiQUWD43TKaecd',
wormholeRelayer:"",
wormhole:""
}]
]],
] as const satisfies MapLevel<Network, MapLevel<Chain, CircleContracts>>;
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@ import { MapLevel } from "../../utils";
import { Network } from "../networks";
import { Chain } from "../chains";

export const tokenBridgeRelayerContracts = [[
"Mainnet", [
["Ethereum", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Bsc", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Polygon", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Avalanche", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Fantom", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Celo", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Sui", "0x57f4e0ba41a7045e29d435bc66cc4175f381eb700e6ec16d4fdfe92e5a4dff9f"],
["Solana", "3vxKRPwUTiEkeUVyoZ9MXFe1V71sRLbLqu1gRYaWmehQ"],
["Base", "0xaE8dc4a7438801Ec4edC0B035EcCCcF3807F4CC1"],
["Moonbeam", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
]], [
"Testnet", [
["Ethereum", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Bsc", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Polygon", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Avalanche", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Fantom", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Celo", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Sui", "0xb30040e5120f8cb853b691cb6d45981ae884b1d68521a9dc7c3ae881c0031923"],
["Solana", "3bPRWXqtSfUaCw3S4wdgvypQtsSzcmvDeaqSqPDkncrg"],
["Base", "0xae8dc4a7438801ec4edc0b035eccccf3807f4cc1"],
["Moonbeam", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
]],
export const tokenBridgeRelayerContracts = [
[
"Mainnet",
[
["Ethereum", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Bsc", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Polygon", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Avalanche", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Fantom", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Celo", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
["Sui", "0x57f4e0ba41a7045e29d435bc66cc4175f381eb700e6ec16d4fdfe92e5a4dff9f"],
["Solana", "3vxKRPwUTiEkeUVyoZ9MXFe1V71sRLbLqu1gRYaWmehQ"],
["Base", "0xaE8dc4a7438801Ec4edC0B035EcCCcF3807F4CC1"],
["Moonbeam", "0xcafd2f0a35a4459fa40c0517e17e6fa2939441ca"],
],
],
[
"Testnet",
[
["Ethereum", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Bsc", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Polygon", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Avalanche", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Fantom", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Celo", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Sui", "0xb30040e5120f8cb853b691cb6d45981ae884b1d68521a9dc7c3ae881c0031923"],
["Base", "0xae8dc4a7438801ec4edc0b035eccccf3807f4cc1"],
["Moonbeam", "0x9563a59c15842a6f322b10f69d1dd88b41f2e97b"],
["Solana", "3bPRWXqtSfUaCw3S4wdgvypQtsSzcmvDeaqSqPDkncrg"],
],
],
] as const satisfies MapLevel<Network, MapLevel<Chain, string>>;
37 changes: 37 additions & 0 deletions sdk/js-connect/core/base/src/constants/guardians.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { RoArray, constMap } from "../utils";
import { Network } from "./networks";

const guardianNamesAndKeys = [
[
"Mainnet",
[
["JumpCrypto", "0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5"],
["Staked", "0xfF6CB952589BDE862c25Ef4392132fb9D4A42157"],
["Figment", "0x114De8460193bdf3A2fCf81f86a09765F4762fD1"],
["ChainodeTech", "0x107A0086b32d7A0977926A205131d8731D39cbEB"],
["Inotel", "0x8C82B2fd82FaeD2711d59AF0F2499D16e726f6b2"],
["HashQuark", "0x11b39756C042441BE6D8650b69b54EbE715E2343"],
["Chainlayer", "0x54Ce5B4D348fb74B958e8966e2ec3dBd4958a7cd"],
["xLabs", "0x15e7cAF07C4e3DC8e7C469f92C8Cd88FB8005a20"],
["Forbole", "0x74a3bf913953D695260D88BC1aA25A4eeE363ef0"],
["StakingFund", "0x000aC0076727b35FBea2dAc28fEE5cCB0fEA768e"],
["MoonletWallet", "0xAF45Ced136b9D9e24903464AE889F5C8a723FC14"],
["P2PValidator", "0xf93124b7c738843CBB89E864c862c38cddCccF95"],
["01Node", "0xD2CC37A4dc036a8D232b48f62cDD4731412f4890"],
["MCF", "0xDA798F6896A3331F64b48c12D1D57Fd9cbe70811"],
["Everstake", "0x71AA1BE1D36CaFE3867910F99C09e347899C19C3"],
["ChorusOne", "0x8192b6E7387CCd768277c17DAb1b7a5027c0b3Cf"],
["Syncnode", "0x178e21ad2E77AE06711549CFBB1f9c7a9d8096e8"],
["Triton", "0x5E1487F35515d02A92753504a8D75471b9f49EdB"],
["StakingFacilities", "0x6FbEBc898F403E4773E95feB15E80C9A99c8348d"],
],
],
["Testnet", [["Testnet guardian", "0x13947Bd48b18E53fdAeEe77F3473391aC727C638"]]],
["Devnet", [["", ""]]],
] as const satisfies RoArray<readonly [Network, RoArray<readonly [string, string]>]>;

export const guardianKeys = constMap(guardianNamesAndKeys);
export const guardianNames = constMap(guardianNamesAndKeys, [[0, 2], 1]);

export const devnetGuardianPrivateKey =
"cfb12303a19cde580bb4dd771639b0d26bc68353645571a8cff516ab2ee113a0";
27 changes: 23 additions & 4 deletions sdk/js-connect/core/base/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
export { Network } from "./networks";
export { ProtocolName } from "./protocols";
export { Chain, ChainId, isChain, toChainId, toChain, chains, chainToChainId, chainIdToChain } from "./chains";
export { Platform, PlatformToChains, ChainToPlatform, PlatformAddressFormat, isPlatform, platformToChains, chainToPlatform } from "./platforms";
export {
Chain,
ChainId,
isChain,
toChainId,
toChain,
chains,
chainToChainId,
chainIdToChain,
} from "./chains";
export {
Platform,
PlatformToChains,
ChainToPlatform,
PlatformAddressFormat,
isPlatform,
platformToChains,
chainToPlatform,
platformToAddressFormat,
} from "./platforms";

export * as platform from './platforms'
export * as chain from './chains'
export * as platform from "./platforms";
export * as chain from "./chains";
export * as network from "./networks";
export * as finality from "./finality";
export * as decimals from "./decimals";
Expand All @@ -13,3 +31,4 @@ export * as rpc from "./rpc";
export * as nativeChainIds from "./nativeChainIds";
export * as circle from "./circle";
export * as contracts from "./contracts";
export * as guardians from "./guardians";
Loading

0 comments on commit 3926dc8

Please sign in to comment.