Skip to content

Commit 8fc0802

Browse files
authored
Sdkv2 (#347)
1 parent 5f530e2 commit 8fc0802

File tree

247 files changed

+1328
-1195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+1328
-1195
lines changed

README.md

+26-36
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,53 @@
1-
# Connect SDK
1+
# Wormhole TS SDK
22

3-
The Connect SDK is a TypeScript SDK for interacting with the chains Wormhole supports and the [protocols](#protocols) built on top of Wormhole.
3+
The Wormhole Typescript SDK is useful for interacting with the chains Wormhole supports and the [protocols](#protocols) built on top of Wormhole.
44

55
## Warning
66

77
:warning: This package is a Work in Progress so the interface may change and there are likely bugs. Please [report](https://github.com/wormhole-foundation/connect-sdk/issues) any issues you find. :warning:
88

99
## Installation
1010

11-
Install the primary package
11+
### Basic
12+
13+
Install the (meta) package
1214

1315
```bash
14-
npm install @wormhole-foundation/connect-sdk
16+
npm install @wormhole-foundation/sdk
1517
```
1618

17-
As well as any other platforms you wish to use
19+
This package combines all the individual packages in a way that makes setup easier while still allowing for tree shaking.
1820

19-
```bash
20-
npm install @wormhole-foundation/connect-sdk-evm
21-
npm install @wormhole-foundation/connect-sdk-solana
22-
npm install @wormhole-foundation/connect-sdk-algorand
23-
```
21+
### Advanced
2422

25-
And any protocols you intend to use
23+
Alternatively, for an advanced user, install a specific set of the packages published.
2624

2725
```bash
28-
npm install @wormhole-foundation/connect-sdk-evm-tokenbridge
29-
npm install @wormhole-foundation/connect-sdk-solana-tokenbridge
30-
npm install @wormhole-foundation/connect-sdk-algorand-tokenbridge
26+
# constants
27+
npm install @wormhole-foundation/sdk-base
28+
29+
# contract interfaces, basic types, vaa payload definitions
30+
npm install @wormhole-foundation/sdk-definitions
31+
32+
# Evm specific utilities
33+
npm install @wormhole-foundation/sdk-evm
34+
35+
# Evm TokenBridge protocol client
36+
npm install @wormhole-foundation/sdk-evm-tokenbridge
3137
```
3238

3339
## Usage
3440

35-
A developer would use the connect-sdk package in conjunction with one or more of the chain context packages. Most developers don't use every single chain and may only use a couple, which allows developers to import only the dependencies they actually need.
36-
3741
Getting started is simple, just import and pass in the [Platform](#platforms) modules you wish to support as an argument to the Wormhole class.
3842

3943
```ts
40-
import { Wormhole, Signer } from "@wormhole-foundation/connect-sdk";
41-
import { EvmPlatform } from "@wormhole-foundation/connect-sdk-evm";
42-
import { SolanaPlatform } from "@wormhole-foundation/connect-sdk-solana";
43-
import { AlgorandPlatform } from "@wormhole-foundation/connect-sdk-algorand";
44-
45-
// Include the protocols you wish to use
46-
// these imports register the protocol to be used by higher level abstractions
47-
// like WormholeTransfers
48-
import "@wormhole-foundation/connect-sdk-evm-tokenbridge";
49-
import "@wormhole-foundation/connect-sdk-solana-tokenbridge";
50-
import "@wormhole-foundation/connect-sdk-algorand-tokenbridge";
44+
import { Wormhole, Signer } from "@wormhole-foundation/sdk";
45+
import { evm } from "@wormhole-foundation/sdk/evm";
46+
import { solana } from "@wormhole-foundation/sdk/solana";
47+
import { algorand } from "@wormhole-foundation/sdk/algorand";
5148

5249
const network = "Mainnet"; // Or "Testnet"
53-
const wh = new Wormhole(network, [EvmPlatform, SolanaPlatform, AlgorandPlatform]);
50+
const wh = new Wormhole(network, [evm.Platform, solana.Platform, algorand.Platform]);
5451

5552
// Get a ChainContext object for a specific chain
5653
// Useful to do things like get the rpc client, make Protocol clients,
@@ -187,11 +184,6 @@ Each Protocol, if available, will have a Platform specific implementation. These
187184
The protocol that underlies all Wormhole activity is the Core protocol. This protocol is responsible for emitting the message containing the information necessary to perform bridging including [Emitter address](https://docs.wormhole.com/wormhole/reference/glossary#emitter), the [Sequence number](https://docs.wormhole.com/wormhole/reference/glossary#sequence) for the message and the Payload of the message itself.
188185

189186
```ts
190-
// ...
191-
// register the protocol
192-
import "@wormhole-foundation/connect-sdk-solana-core";
193-
194-
// ...
195187

196188
// get chain context
197189
const chain = wh.getChain("Solana");
@@ -215,9 +207,7 @@ Every chain has a `TokenBridge` protocol client that provides a consistent inter
215207
Using the `WormholeTransfer` abstractions is the recommended way to interact with these protocols but it is possible to use them directly
216208

217209
```ts
218-
import { signSendWait } from "@wormhole-foundation/connect-sdk";
219-
220-
import "@wormhole-foundation/connect-sdk-evm-tokenbridge";
210+
import { signSendWait } from "@wormhole-foundation/sdk";
221211

222212
// ...
223213

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.6
1+
0.5.0-beta.5

__tests__/integration/index.test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import {
33
PlatformContext,
44
RpcConnection,
55
TokenBridge,
6-
testing,
76
Network,
87
Platform,
98
Wormhole,
109
Chain,
11-
} from "@wormhole-foundation/connect-sdk";
12-
import { EvmPlatform } from "@wormhole-foundation/connect-sdk-evm";
13-
import { SolanaPlatform } from "@wormhole-foundation/connect-sdk-solana";
10+
} from "@wormhole-foundation/sdk-connect";
11+
import { utils } from "@wormhole-foundation/sdk-definitions/testing";
12+
import { EvmPlatform } from "@wormhole-foundation/sdk-evm";
13+
import { SolanaPlatform } from "@wormhole-foundation/sdk-solana";
1414

1515
const allPlatformCtrs = [SolanaPlatform, EvmPlatform];
1616

@@ -26,15 +26,15 @@ describe("Wormhole Tests", () => {
2626
expect(p).toBeTruthy();
2727
});
2828

29-
let c: ChainContext<Network, Platform, Chain>;
29+
let c: ChainContext<Network, Chain>;
3030
test("returns chain", async () => {
3131
c = wh.getChain("Ethereum");
3232
expect(c).toBeTruthy();
3333
});
3434

3535
test("should parse address", () => {
3636
const chain = "Ethereum";
37-
const address = testing.utils.makeNativeAddress(chain);
37+
const address = utils.makeNativeAddress(chain);
3838

3939
const result = Wormhole.parseAddress(chain, address.toString());
4040
expect(result).toBeTruthy();
@@ -60,15 +60,15 @@ describe("Platform Tests", () => {
6060
expect(rpc).toBeTruthy();
6161
});
6262

63-
let tb: TokenBridge<"Devnet", "Evm", "Ethereum">;
63+
let tb: TokenBridge<"Devnet", "Ethereum">;
6464
test("Gets Token Bridge", async () => {
6565
tb = await p.getProtocol("TokenBridge", rpc);
6666
expect(tb).toBeTruthy();
6767
});
6868
});
6969

7070
describe("Chain Tests", () => {
71-
let c: ChainContext<"Devnet", "Evm", "Ethereum">;
71+
let c: ChainContext<"Devnet", "Ethereum">;
7272
beforeEach(() => {
7373
const wh = new Wormhole<"Devnet">("Devnet", allPlatformCtrs);
7474
c = wh.getChain("Ethereum");

__tests__/tilt/helpers/helpers.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// Signer,
77
// WormholeConfig,
88
// nativeChainAddress,
9-
// } from "@wormhole-foundation/connect-sdk";
9+
// } from "@wormhole-foundation/sdk-connect";
1010
//
11-
// import { getCosmwasmSigner } from "@wormhole-foundation/connect-sdk-cosmwasm";
12-
// import { getEvmSigner } from "@wormhole-foundation/connect-sdk-evm";
13-
// import { getSolanaSigner } from "@wormhole-foundation/connect-sdk-solana";
11+
// import { getCosmwasmSigner } from "@wormhole-foundation/sdk-cosmwasm";
12+
// import { getEvmSigner } from "@wormhole-foundation/sdk-evm";
13+
// import { getSolanaSigner } from "@wormhole-foundation/sdk-solana";
1414
//
1515
// import { ETH_PRIVATE_KEY, SOLANA_PRIVATE_KEY, TERRA_PRIVATE_KEY } from "./consts";
1616
//

__tests__/tilt/tokenbridge.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
// baseUnits,
1414
// parseAmount,
1515
// signSendWait,
16-
// } from "@wormhole-foundation/connect-sdk";
17-
// import { EvmPlatform } from "@wormhole-foundation/connect-sdk-evm";
18-
// import { SolanaPlatform } from "@wormhole-foundation/connect-sdk-solana";
19-
// import { CosmwasmPlatform } from "@wormhole-foundation/connect-sdk-cosmwasm";
16+
// } from "@wormhole-foundation/sdk-connect";
17+
// import { EvmPlatform } from "@wormhole-foundation/sdk-evm";
18+
// import { SolanaPlatform } from "@wormhole-foundation/sdk-solana";
19+
// import { CosmwasmPlatform } from "@wormhole-foundation/sdk-cosmwasm";
2020
//
2121
// import { expect, jest, describe, test } from '@jest/globals';
2222
//

connect/__tests__/index.test.ts

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import * as publicRpcMock from "./mocks/publicrpc"; // Should be first
22

33
import { describe, expect, test } from "@jest/globals";
44
import { Platform, platform } from "@wormhole-foundation/sdk-base";
5-
import {
6-
ChainContext,
7-
PlatformContext,
8-
RpcConnection,
9-
testing,
10-
} from "@wormhole-foundation/sdk-definitions";
5+
import { ChainContext, PlatformContext, RpcConnection } from "@wormhole-foundation/sdk-definitions";
6+
7+
import { mocks, utils } from "@wormhole-foundation/sdk-definitions/testing";
118
import { Wormhole, networkPlatformConfigs } from "../src";
129

1310
const network: "Testnet" = "Testnet";
1411
type TNet = typeof network;
1512
const allPlatformCtrs = platform.platforms.map((p) =>
16-
testing.mocks.mockPlatformFactory(p, networkPlatformConfigs(network, p)),
17-
);
13+
mocks.mockPlatformFactory(p, networkPlatformConfigs(network, p)),
14+
) as any;
1815

1916
describe("Wormhole Tests", () => {
2017
let wh: Wormhole<TNet>;
@@ -38,7 +35,7 @@ describe("Wormhole Tests", () => {
3835
test("returns vaa bytes", async function () {
3936
const vaa = await wh.getVaaBytes({
4037
chain: "Arbitrum",
41-
emitter: testing.utils.makeUniversalAddress("Arbitrum"),
38+
emitter: utils.makeUniversalAddress("Arbitrum"),
4239
sequence: 1n,
4340
});
4441
expect(vaa).toBeDefined();
@@ -47,7 +44,7 @@ describe("Wormhole Tests", () => {
4744
test("returns undefined when vaa bytes not found", async function () {
4845
publicRpcMock.givenSignedVaaNotFound();
4946
const vaa = await wh.getVaaBytes(
50-
{ chain: "Aptos", emitter: testing.utils.makeUniversalAddress("Aptos"), sequence: 1n },
47+
{ chain: "Aptos", emitter: utils.makeUniversalAddress("Aptos"), sequence: 1n },
5148
1,
5249
);
5350
expect(vaa).toBeNull();
@@ -57,7 +54,7 @@ describe("Wormhole Tests", () => {
5754
publicRpcMock.givenSignedVaaRequestWorksAfterRetry();
5855
const vaa = await wh.getVaaBytes({
5956
chain: "Base",
60-
emitter: testing.utils.makeUniversalAddress("Base"),
57+
emitter: utils.makeUniversalAddress("Base"),
6158
sequence: 1n,
6259
});
6360
expect(vaa).toBeDefined();

connect/__tests__/route.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { describe } from "@jest/globals";
22
import { platform } from "@wormhole-foundation/sdk-base";
3-
import { testing } from "@wormhole-foundation/sdk-definitions";
3+
import { utils, mocks } from "@wormhole-foundation/sdk-definitions/testing";
44
import { Wormhole, networkPlatformConfigs } from "../src";
55
import { RouteTransferRequest } from "../src/routes";
66

77
const network: "Testnet" = "Testnet";
88
type TNet = typeof network;
99
const allPlatformCtrs = platform.platforms.map((p) =>
10-
testing.mocks.mockPlatformFactory(p, networkPlatformConfigs(network, p)),
10+
mocks.mockPlatformFactory(p, networkPlatformConfigs(network, p)),
1111
);
1212

1313
async function createRequest(wh: Wormhole<TNet>): Promise<RouteTransferRequest<TNet>> {
1414
const fromChain = wh.getChain("Solana");
1515
const toChain = wh.getChain("Ethereum");
1616

1717
const req = {
18-
from: testing.utils.makeUniversalChainAddress("Solana"),
19-
to: testing.utils.makeUniversalChainAddress("Ethereum"),
20-
source: testing.utils.makeUniversalChainAddress("Solana"),
21-
destination: testing.utils.makeUniversalChainAddress("Ethereum"),
18+
from: utils.makeUniversalChainAddress("Solana"),
19+
to: utils.makeUniversalChainAddress("Ethereum"),
20+
source: utils.makeUniversalChainAddress("Solana"),
21+
destination: utils.makeUniversalChainAddress("Ethereum"),
2222
};
2323
return RouteTransferRequest.create(wh, req, fromChain, toChain);
2424
}

connect/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@wormhole-foundation/connect-sdk",
3-
"version": "0.4.6",
2+
"name": "@wormhole-foundation/sdk-connect",
3+
"version": "0.5.0-beta.5",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
@@ -14,8 +14,8 @@
1414
},
1515
"license": "Apache-2.0",
1616
"main": "./dist/cjs/index.js",
17+
"types": "./dist/cjs/index.d.ts",
1718
"module": "./dist/esm/index.js",
18-
"types": "./dist/esm/index.d.ts",
1919
"author": "",
2020
"description": "The core package for the Connect SDK, used in conjunction with 1 or more of the chain packages",
2121
"files": [
@@ -45,7 +45,7 @@
4545
},
4646
"dependencies": {
4747
"axios": "^1.4.0",
48-
"@wormhole-foundation/sdk-base": "0.4.6",
49-
"@wormhole-foundation/sdk-definitions": "0.4.6"
48+
"@wormhole-foundation/sdk-base": "0.5.0-beta.5",
49+
"@wormhole-foundation/sdk-definitions": "0.5.0-beta.5"
5050
}
5151
}

core/base/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wormhole-foundation/sdk-base",
3-
"version": "0.4.6",
3+
"version": "0.5.0-beta.5",
44
"repository": {
55
"type": "git",
66
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
@@ -14,8 +14,8 @@
1414
},
1515
"license": "Apache-2.0",
1616
"main": "./dist/cjs/index.js",
17+
"types": "./dist/cjs/index.d.ts",
1718
"module": "./dist/esm/index.js",
18-
"types": "./dist/esm/index.d.ts",
1919
"files": [
2020
"dist"
2121
],

core/definitions/__tests__/bamVaa.ts

-57
This file was deleted.

core/definitions/__tests__/circleMessage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { deserializeLayout, circle, encoding, contracts } from "@wormhole-foundation/sdk-base";
22
import { UniversalAddress } from "../src";
3-
import { circleMessageLayout } from "../src/payloads/circleBridge";
3+
import { circleMessageLayout } from "../src/protocols/circleBridge";
44

55
const ethAddressToUniversal = (address: string) => {
66
return new UniversalAddress("00".repeat(12) + address.slice(2));

core/definitions/__tests__/connectVAA.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import "../src/payloads/automaticCircleBridge";
1+
import "../src/protocols/circleBridge/automaticCircleBridgeLayout";
22
import { encoding } from "@wormhole-foundation/sdk-base";
33
import { deserialize, deserializePayload } from "../src/vaa";
44

0 commit comments

Comments
 (0)