@wormhole-foundation/sdk-definitions 0.1.3-beta.4 → 0.1.3-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +51 -2
  2. package/dist/cjs/chain.d.ts +19 -18
  3. package/dist/cjs/chain.d.ts.map +1 -1
  4. package/dist/cjs/chain.js +46 -24
  5. package/dist/cjs/chain.js.map +1 -1
  6. package/dist/cjs/index.d.ts +1 -0
  7. package/dist/cjs/index.d.ts.map +1 -1
  8. package/dist/cjs/index.js +1 -0
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/layout-items/chain.d.ts +8 -4
  11. package/dist/cjs/layout-items/chain.d.ts.map +1 -1
  12. package/dist/cjs/layout-items/chain.js +4 -4
  13. package/dist/cjs/layout-items/chain.js.map +1 -1
  14. package/dist/cjs/payloads/bam.d.ts +187 -0
  15. package/dist/cjs/payloads/bam.d.ts.map +1 -0
  16. package/dist/cjs/payloads/bam.js +37 -0
  17. package/dist/cjs/payloads/bam.js.map +1 -0
  18. package/dist/cjs/payloads/governance.d.ts +252 -252
  19. package/dist/cjs/payloads/relayer.d.ts +10 -10
  20. package/dist/cjs/payloads/tokenBridge.d.ts +14 -14
  21. package/dist/cjs/platform.d.ts +14 -19
  22. package/dist/cjs/platform.d.ts.map +1 -1
  23. package/dist/cjs/protocols/cctp.d.ts +9 -0
  24. package/dist/cjs/protocols/cctp.d.ts.map +1 -1
  25. package/dist/cjs/protocols/cctp.js +10 -0
  26. package/dist/cjs/protocols/cctp.js.map +1 -1
  27. package/dist/cjs/protocols/core.d.ts +5 -0
  28. package/dist/cjs/protocols/core.d.ts.map +1 -1
  29. package/dist/cjs/protocols/core.js +5 -0
  30. package/dist/cjs/protocols/core.js.map +1 -1
  31. package/dist/cjs/protocols/tokenBridge.d.ts +9 -0
  32. package/dist/cjs/protocols/tokenBridge.d.ts.map +1 -1
  33. package/dist/cjs/protocols/tokenBridge.js +10 -1
  34. package/dist/cjs/protocols/tokenBridge.js.map +1 -1
  35. package/dist/cjs/rpc.d.ts +1 -9
  36. package/dist/cjs/rpc.d.ts.map +1 -1
  37. package/dist/cjs/testing/mocks/chain.d.ts +6 -5
  38. package/dist/cjs/testing/mocks/chain.d.ts.map +1 -1
  39. package/dist/cjs/testing/mocks/chain.js +9 -6
  40. package/dist/cjs/testing/mocks/chain.js.map +1 -1
  41. package/dist/cjs/testing/mocks/platform.d.ts +11 -4
  42. package/dist/cjs/testing/mocks/platform.d.ts.map +1 -1
  43. package/dist/cjs/testing/mocks/platform.js +27 -6
  44. package/dist/cjs/testing/mocks/platform.js.map +1 -1
  45. package/dist/cjs/types.d.ts +1 -1
  46. package/dist/cjs/vaa.d.ts +4 -4
  47. package/dist/esm/chain.d.ts +19 -18
  48. package/dist/esm/chain.d.ts.map +1 -1
  49. package/dist/esm/chain.js +46 -24
  50. package/dist/esm/chain.js.map +1 -1
  51. package/dist/esm/index.d.ts +1 -0
  52. package/dist/esm/index.d.ts.map +1 -1
  53. package/dist/esm/index.js +1 -0
  54. package/dist/esm/index.js.map +1 -1
  55. package/dist/esm/layout-items/chain.d.ts +8 -4
  56. package/dist/esm/layout-items/chain.d.ts.map +1 -1
  57. package/dist/esm/layout-items/chain.js +1 -1
  58. package/dist/esm/layout-items/chain.js.map +1 -1
  59. package/dist/esm/payloads/bam.d.ts +187 -0
  60. package/dist/esm/payloads/bam.d.ts.map +1 -0
  61. package/dist/esm/payloads/bam.js +34 -0
  62. package/dist/esm/payloads/bam.js.map +1 -0
  63. package/dist/esm/payloads/governance.d.ts +252 -252
  64. package/dist/esm/payloads/relayer.d.ts +10 -10
  65. package/dist/esm/payloads/tokenBridge.d.ts +14 -14
  66. package/dist/esm/platform.d.ts +14 -19
  67. package/dist/esm/platform.d.ts.map +1 -1
  68. package/dist/esm/protocols/cctp.d.ts +9 -0
  69. package/dist/esm/protocols/cctp.d.ts.map +1 -1
  70. package/dist/esm/protocols/cctp.js +7 -0
  71. package/dist/esm/protocols/cctp.js.map +1 -1
  72. package/dist/esm/protocols/core.d.ts +5 -0
  73. package/dist/esm/protocols/core.d.ts.map +1 -1
  74. package/dist/esm/protocols/core.js +3 -1
  75. package/dist/esm/protocols/core.js.map +1 -1
  76. package/dist/esm/protocols/tokenBridge.d.ts +9 -0
  77. package/dist/esm/protocols/tokenBridge.d.ts.map +1 -1
  78. package/dist/esm/protocols/tokenBridge.js +7 -0
  79. package/dist/esm/protocols/tokenBridge.js.map +1 -1
  80. package/dist/esm/rpc.d.ts +1 -9
  81. package/dist/esm/rpc.d.ts.map +1 -1
  82. package/dist/esm/testing/mocks/chain.d.ts +6 -5
  83. package/dist/esm/testing/mocks/chain.d.ts.map +1 -1
  84. package/dist/esm/testing/mocks/chain.js +9 -6
  85. package/dist/esm/testing/mocks/chain.js.map +1 -1
  86. package/dist/esm/testing/mocks/platform.d.ts +11 -4
  87. package/dist/esm/testing/mocks/platform.d.ts.map +1 -1
  88. package/dist/esm/testing/mocks/platform.js +27 -6
  89. package/dist/esm/testing/mocks/platform.js.map +1 -1
  90. package/dist/esm/types.d.ts +1 -1
  91. package/dist/esm/vaa.d.ts +4 -4
  92. package/package.json +1 -1
  93. package/src/chain.ts +76 -59
  94. package/src/index.ts +1 -0
  95. package/src/layout-items/chain.ts +1 -1
  96. package/src/payloads/bam.ts +66 -0
  97. package/src/platform.ts +29 -28
  98. package/src/protocols/cctp.ts +27 -0
  99. package/src/protocols/core.ts +13 -0
  100. package/src/protocols/tokenBridge.ts +43 -0
  101. package/src/rpc.ts +1 -15
  102. package/src/testing/mocks/chain.ts +17 -8
  103. package/src/testing/mocks/platform.ts +40 -13
  104. package/src/types.ts +1 -1
@@ -24,7 +24,7 @@ export type ChainConfig = {
24
24
  platform: PlatformName;
25
25
  contracts: Contracts;
26
26
  finalityThreshold: number;
27
- nativeTokenDecimals: number;
27
+ nativeTokenDecimals: bigint;
28
28
  explorer: ExplorerSettings;
29
29
  rpc: string;
30
30
  };
package/dist/esm/vaa.d.ts CHANGED
@@ -61,8 +61,8 @@ declare const baseLayout: readonly [{
61
61
  readonly size: 4;
62
62
  }, {
63
63
  readonly custom: {
64
- to: (val: number) => "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Osmosis" | "Wormchain" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Sepolia";
65
- from: (val: "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Osmosis" | "Wormchain" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Sepolia") => number;
64
+ to: (val: number) => "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Sepolia";
65
+ from: (val: "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Sepolia") => number;
66
66
  };
67
67
  readonly binary: "uint";
68
68
  readonly size: 2;
@@ -121,8 +121,8 @@ export declare const create: <PL extends keyof Wormhole.PayloadLiteralToDescript
121
121
  readonly size: 4;
122
122
  }, {
123
123
  readonly custom: {
124
- to: (val: number) => "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Osmosis" | "Wormchain" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Sepolia";
125
- from: (val: "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Osmosis" | "Wormchain" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Sepolia") => number;
124
+ to: (val: number) => "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Sepolia";
125
+ from: (val: "Solana" | "Btc" | "Algorand" | "Sui" | "Aptos" | "Near" | "Ethereum" | "Terra" | "Bsc" | "Polygon" | "Avalanche" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Sepolia") => number;
126
126
  };
127
127
  readonly binary: "uint";
128
128
  readonly size: 2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wormhole-foundation/sdk-definitions",
3
- "version": "0.1.3-beta.4",
3
+ "version": "0.1.3-beta.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
package/src/chain.ts CHANGED
@@ -1,105 +1,122 @@
1
1
  import { ChainName, PlatformName } from "@wormhole-foundation/sdk-base";
2
2
  import { Platform } from "./platform";
3
+
4
+ import {
5
+ supportsAutomaticCircleBridge,
6
+ supportsCircleBridge,
7
+ } from "./protocols/cctp";
8
+ import {
9
+ supportsAutomaticTokenBridge,
10
+ supportsTokenBridge,
11
+ } from "./protocols/tokenBridge";
3
12
  import { RpcConnection } from "./rpc";
4
13
  import { AutomaticTokenBridge, TokenBridge } from "./protocols/tokenBridge";
5
14
  import { AutomaticCircleBridge, CircleBridge } from "./protocols/cctp";
6
-
7
- // TODO: there has to be a nicer way to do this
8
- // This requires the arguments in the function definition come in the same order
9
- // [chain], [rpc], ...
10
-
11
- type _omitChain<Fn> = Fn extends (chain: ChainName, ...args: infer A) => infer R
12
- ? (...args: A) => R
13
- : Fn;
14
- type _omitRpc<P extends PlatformName, Fn> = Fn extends (
15
- rpc: RpcConnection<P>,
16
- ...args: infer A
17
- ) => infer R
18
- ? (...args: A) => R
19
- : Fn;
20
-
21
- type OmitChainRpc<
22
- P extends PlatformName,
23
- F extends keyof Platform<P>
24
- > = _omitRpc<P, _omitChain<Platform<P>[F]>>;
25
-
26
- type OmitRpc<P extends PlatformName, F extends keyof Platform<P>> = _omitRpc<
27
- P,
28
- Platform<P>[F]
29
- >;
30
-
31
- type OmitChain<
32
- P extends PlatformName,
33
- F extends keyof Platform<P>
34
- > = _omitChain<Platform<P>[F]>;
15
+ import { SignedTx, TokenId } from "./types";
16
+ import { WormholeMessageId } from "./attestation";
17
+ import { NativeAddress } from "./address";
35
18
 
36
19
  export abstract class ChainContext<P extends PlatformName> {
37
20
  // Cached Protocol clients
21
+ protected rpc?: RpcConnection<P>;
38
22
  protected tokenBridge?: TokenBridge<P>;
39
23
  protected autoTokenBridge?: AutomaticTokenBridge<P>;
40
24
  protected circleBridge?: CircleBridge<P>;
41
25
  protected autoCircleBridge?: AutomaticCircleBridge<P>;
42
26
 
43
- constructor(readonly platform: Platform<P>, readonly chain: ChainName) {}
27
+ abstract platform: Platform<P>;
44
28
 
45
- abstract getRpc(): RpcConnection<P>;
29
+ constructor(readonly chain: ChainName) {}
46
30
 
47
- // Utils for platform specific queries
48
- getDecimals: OmitChainRpc<P, "getDecimals"> = (token) => {
31
+ getRpc(): RpcConnection<P> {
32
+ this.rpc = this.rpc ? this.rpc : this.platform.getRpc(this.chain);
33
+ return this.rpc;
34
+ }
35
+
36
+ // Get the number of decimals for a token
37
+ async getDecimals(token: TokenId | "native"): Promise<bigint> {
49
38
  return this.platform.getDecimals(this.chain, this.getRpc(), token);
50
- };
39
+ }
51
40
 
52
- getBalance: OmitChainRpc<P, "getBalance"> = (walletAddr, token) => {
41
+ // Get the balance of a token for a given address
42
+ async getBalance(
43
+ walletAddr: string,
44
+ token: TokenId | "native"
45
+ ): Promise<bigint | null> {
53
46
  return this.platform.getBalance(
54
47
  this.chain,
55
48
  this.getRpc(),
56
49
  walletAddr,
57
50
  token
58
51
  );
59
- };
52
+ }
53
+
54
+ async getCurrentBlock(): Promise<number> {
55
+ return this.platform.getCurrentBlock(this.getRpc());
56
+ }
60
57
 
61
58
  // Get details about the transaction
62
- parseTransaction: OmitChainRpc<P, "parseTransaction"> = (txid) => {
59
+ async parseTransaction(txid: string): Promise<WormholeMessageId[]> {
63
60
  return this.platform.parseTransaction(this.chain, this.getRpc(), txid);
64
- };
61
+ }
65
62
 
66
63
  // Send a transaction and wait for it to be confirmed
67
- sendWait: OmitChainRpc<P, "sendWait"> = (stxns) => {
64
+ async sendWait(stxns: SignedTx): Promise<string[]> {
68
65
  return this.platform.sendWait(this.chain, this.getRpc(), stxns);
69
- };
70
-
71
- // Take a native address and convert it to a UniversalAddress
72
- parseAddress: OmitChain<P, "parseAddress"> = (address) => {
73
- return this.platform.parseAddress(this.chain, address);
74
- };
66
+ }
75
67
 
68
+ //
76
69
  // protocols
77
- getTokenBridge: OmitRpc<P, "getTokenBridge"> = async () => {
70
+ //
71
+
72
+ //
73
+ supportsTokenBridge = () => supportsTokenBridge<P>(this.platform);
74
+ async getTokenBridge(): Promise<TokenBridge<P>> {
75
+ if (!supportsTokenBridge<P>(this.platform))
76
+ throw new Error("Platform does not support TokenBridge");
77
+
78
78
  this.tokenBridge = this.tokenBridge
79
79
  ? this.tokenBridge
80
80
  : await this.platform.getTokenBridge(this.getRpc());
81
+
81
82
  return this.tokenBridge;
82
- };
83
+ }
84
+
85
+ supportsAutomaticTokenBridge = () =>
86
+ supportsAutomaticTokenBridge<P>(this.platform);
87
+ async getAutomaticTokenBridge(): Promise<AutomaticTokenBridge<P>> {
88
+ if (!supportsAutomaticTokenBridge<P>(this.platform))
89
+ throw new Error("Platform does not support AutomaticTokenBridge");
83
90
 
84
- getAutomaticTokenBridge: OmitRpc<P, "getAutomaticTokenBridge"> = async () => {
85
91
  this.autoTokenBridge = this.autoTokenBridge
86
92
  ? this.autoTokenBridge
87
93
  : await this.platform.getAutomaticTokenBridge(this.getRpc());
88
94
  return this.autoTokenBridge;
89
- };
95
+ }
96
+
97
+ //
98
+ supportsCircleBridge = () => supportsCircleBridge<P>(this.platform);
99
+ async getCircleBridge(): Promise<CircleBridge<P>> {
100
+ if (!supportsCircleBridge<P>(this.platform))
101
+ throw new Error("Platform does not support CircleBridge");
90
102
 
91
- getCircleBridge: OmitRpc<P, "getCircleBridge"> = async () => {
92
103
  this.circleBridge = this.circleBridge
93
104
  ? this.circleBridge
94
105
  : await this.platform.getCircleBridge(this.getRpc());
95
106
  return this.circleBridge;
96
- };
97
-
98
- getAutomaticCircleBridge: OmitRpc<P, "getAutomaticCircleBridge"> =
99
- async () => {
100
- this.autoCircleBridge = this.autoCircleBridge
101
- ? this.autoCircleBridge
102
- : await this.platform.getAutomaticCircleBridge(this.getRpc());
103
- return this.autoCircleBridge;
104
- };
107
+ }
108
+
109
+ //
110
+ supportsAutomaticCircleBridge = () =>
111
+ supportsAutomaticCircleBridge<P>(this.platform);
112
+
113
+ async getAutomaticCircleBridge(): Promise<AutomaticCircleBridge<P>> {
114
+ if (!supportsAutomaticCircleBridge<P>(this.platform))
115
+ throw new Error("Platform does not support AutomaticCircleBridge");
116
+
117
+ this.autoCircleBridge = this.autoCircleBridge
118
+ ? this.autoCircleBridge
119
+ : await this.platform.getAutomaticCircleBridge(this.getRpc());
120
+ return this.autoCircleBridge;
121
+ }
105
122
  }
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import "./payloads/connect";
3
3
  import "./payloads/relayer";
4
4
  import "./payloads/governance";
5
5
  import "./payloads/tokenBridge";
6
+ import "./payloads/bam";
6
7
 
7
8
  export * from "./address";
8
9
  export * from "./universalAddress";
@@ -9,7 +9,7 @@ import {
9
9
  ChainName,
10
10
  } from "@wormhole-foundation/sdk-base";
11
11
 
12
- const chainItemBase = { binary: "uint", size: 2 } as const;
12
+ export const chainItemBase = { binary: "uint", size: 2 } as const;
13
13
 
14
14
  type AllowNull<T, B extends boolean> = B extends true ? T | null : T;
15
15
 
@@ -0,0 +1,66 @@
1
+ import { Layout, UintLayoutItem, LengthPrefixedBytesLayoutItem, ShallowMapping } from "@wormhole-foundation/sdk-base";
2
+ import { chainItem, amountItem } from "../layout-items";
3
+ import { registerPayloadType } from "../vaa";
4
+
5
+ const bamAddressItem = {
6
+ binary: "bytes",
7
+ lengthSize: 2
8
+ } as const satisfies Omit<LengthPrefixedBytesLayoutItem, "name">;
9
+
10
+ const customOrEmpty = (custom: any) => custom ? { custom } : {};
11
+
12
+ const messageLayout = <
13
+ const T extends number,
14
+ const C extends Pick<LengthPrefixedBytesLayoutItem, "custom">,
15
+ >(type: T, customContents?: C) => [
16
+ { name: "magicByte", binary: "uint", size: 1, custom: 0xbb, omit: true },
17
+ { name: "version", binary: "uint", size: 1, custom: 0, omit: true },
18
+ { name: "type", binary: "uint", size: 1, custom: type, omit: true },
19
+ { name: "index", binary: "uint", size: 8 },
20
+ { name: "targetChain", ...chainItem() },
21
+ { name: "targetAddress", ...bamAddressItem },
22
+ { name: "senderAddress", ...bamAddressItem },
23
+ { name: "contents", binary: "bytes", lengthSize: 2, ...customOrEmpty(customContents) },
24
+ ] as const satisfies Layout;
25
+
26
+ const tokenMessageLayout = <
27
+ const C extends Pick<LengthPrefixedBytesLayoutItem, "custom">,
28
+ const B extends Pick<UintLayoutItem, "custom">,
29
+ const A extends Pick<UintLayoutItem, "custom">,
30
+ >(
31
+ custom?: { contents?: C, bridge?: B, assetIdentifier?: A },
32
+ ) => [
33
+ ...messageLayout(1, custom?.contents),
34
+ { name: "bridge", binary: "uint", size: 1, ...customOrEmpty(custom?.bridge) },
35
+ { name: "assetIdentifier", binary: "uint", size: 2, ...customOrEmpty(custom?.assetIdentifier) },
36
+ { name: "amount", ...amountItem },
37
+ ] as const satisfies Layout;
38
+
39
+ const extendedMessageLayout = <
40
+ const C extends Pick<LengthPrefixedBytesLayoutItem, "custom">,
41
+ const R extends Pick<LengthPrefixedBytesLayoutItem, "custom">,
42
+ >(
43
+ custom?: { contents?: C, relaySignal?: R },
44
+ ) => [
45
+ ...messageLayout(2, custom?.contents),
46
+ { name: "relaySignal", binary: "bytes", lengthSize: 2, ...customOrEmpty(custom?.relaySignal) },
47
+ ] as const satisfies Layout;
48
+
49
+ export const bamPayloads = [
50
+ [ "BamMessage", messageLayout(0) ],
51
+ [ "BamTokenMessage", tokenMessageLayout() ],
52
+ [ "BamExtendedMessage", extendedMessageLayout() ],
53
+ ] as const satisfies readonly (readonly [string, Layout])[];
54
+
55
+ // factory registration:
56
+
57
+ declare global {
58
+ namespace Wormhole {
59
+ interface PayloadLiteralToDescriptionMapping
60
+ extends ShallowMapping<typeof bamPayloads> {}
61
+ }
62
+ }
63
+
64
+ bamPayloads.forEach(([payloadLiteral, layout]) =>
65
+ registerPayloadType(payloadLiteral, layout)
66
+ );
package/src/platform.ts CHANGED
@@ -1,25 +1,20 @@
1
- import { PlatformName, ChainName } from "@wormhole-foundation/sdk-base";
1
+ import {
2
+ PlatformName,
3
+ ChainName,
4
+ Network,
5
+ } from "@wormhole-foundation/sdk-base";
2
6
  import { ChainContext } from "./chain";
3
7
  import { RpcConnection } from "./rpc";
4
8
  import { ChainsConfig, TokenId, TxHash } from "./types";
5
9
  import { WormholeMessageId } from "./attestation";
6
10
  import { SignedTx } from "./types";
7
- // protocols
8
- import { TokenBridge, AutomaticTokenBridge } from "./protocols/tokenBridge";
9
- import { CircleBridge, AutomaticCircleBridge } from "./protocols/cctp";
10
- import { WormholeCore } from "./protocols/core";
11
- import { NativeAddress } from "./address";
12
11
 
13
- export type PlatformCtr<P extends PlatformName> = {
14
- _platform: P;
15
- new (conf: ChainsConfig): Platform<P>;
16
- };
12
+ export interface PlatformUtils<P extends PlatformName> {
13
+ nativeTokenId(chain: ChainName): TokenId;
17
14
 
18
- // Force passing RPC connection so we don't create a new one with every fn call
19
- export interface Platform<P extends PlatformName> {
20
- readonly platform: P;
21
- readonly conf: ChainsConfig;
22
- getChain(chain: ChainName): ChainContext<P>;
15
+ isSupportedChain(chain: ChainName): boolean;
16
+
17
+ isNativeTokenId(chain: ChainName, tokenId: TokenId): boolean;
23
18
 
24
19
  // Utils for platform specific queries
25
20
  getDecimals(
@@ -33,7 +28,7 @@ export interface Platform<P extends PlatformName> {
33
28
  walletAddr: string,
34
29
  token: TokenId | "native"
35
30
  ): Promise<bigint | null>;
36
- getRpc(chain: ChainName): RpcConnection<P>;
31
+ getCurrentBlock(rpc: RpcConnection<P>): Promise<number>;
37
32
 
38
33
  // Platform interaction utils
39
34
  sendWait(
@@ -41,21 +36,27 @@ export interface Platform<P extends PlatformName> {
41
36
  rpc: RpcConnection<P>,
42
37
  stxns: SignedTx[]
43
38
  ): Promise<TxHash[]>;
39
+
40
+ chainFromRpc(rpc: RpcConnection<P>): Promise<[Network, ChainName]>;
41
+ }
42
+
43
+ // Force passing RPC connection so we don't create a new one with every fn call
44
+ export interface Platform<P extends PlatformName> extends PlatformUtils<P> {
45
+ readonly platform: P;
46
+ readonly conf: ChainsConfig;
47
+ readonly network: Network;
48
+
49
+ // update the config for this platform
50
+ setConfig(network: Network, _conf?: ChainsConfig): Platform<P>;
51
+
52
+ // Create a new Chain context object
53
+ getChain(chain: ChainName): ChainContext<P>;
54
+
55
+ getRpc(chain: ChainName): RpcConnection<P>;
56
+
44
57
  parseTransaction(
45
58
  chain: ChainName,
46
59
  rpc: RpcConnection<P>,
47
60
  txid: TxHash
48
61
  ): Promise<WormholeMessageId[]>;
49
- parseAddress(chain: ChainName, address: string): NativeAddress<P>;
50
-
51
- // protocol clients
52
- getWormholeCore(rpc: RpcConnection<P>): Promise<WormholeCore<P>>;
53
- getTokenBridge(rpc: RpcConnection<P>): Promise<TokenBridge<P>>;
54
- getAutomaticTokenBridge(
55
- rpc: RpcConnection<P>
56
- ): Promise<AutomaticTokenBridge<P>>;
57
- getAutomaticCircleBridge(
58
- rpc: RpcConnection<P>
59
- ): Promise<AutomaticCircleBridge<P>>;
60
- getCircleBridge(rpc: RpcConnection<P>): Promise<CircleBridge<P>>;
61
62
  }
@@ -4,9 +4,35 @@ import { CircleMessageId } from "../attestation";
4
4
  import { UnsignedTransaction } from "../unsignedTransaction";
5
5
  import { TokenId, TxHash } from "../types";
6
6
  import "../payloads/connect";
7
+ import { RpcConnection } from "../rpc";
7
8
 
8
9
  // https://github.com/circlefin/evm-cctp-contracts
9
10
 
11
+ export interface SupportsCircleBridge<P extends PlatformName> {
12
+ getCircleBridge(rpc: RpcConnection<P>): Promise<CircleBridge<P>>;
13
+ }
14
+
15
+ export function supportsCircleBridge<P extends PlatformName>(
16
+ thing: SupportsCircleBridge<P> | any
17
+ ): thing is SupportsCircleBridge<P> {
18
+ return typeof (<SupportsCircleBridge<P>>thing).getCircleBridge === "function";
19
+ }
20
+
21
+ export interface SupportsAutomaticCircleBridge<P extends PlatformName> {
22
+ getAutomaticCircleBridge(
23
+ rpc: RpcConnection<P>
24
+ ): Promise<AutomaticCircleBridge<P>>;
25
+ }
26
+
27
+ export function supportsAutomaticCircleBridge<P extends PlatformName>(
28
+ thing: SupportsAutomaticCircleBridge<P> | any
29
+ ): thing is SupportsAutomaticCircleBridge<P> {
30
+ return (
31
+ typeof (<SupportsAutomaticCircleBridge<P>>thing)
32
+ .getAutomaticCircleBridge === "function"
33
+ );
34
+ }
35
+
10
36
  export type CircleTransferDetails = {
11
37
  txid: TxHash;
12
38
  token: TokenId;
@@ -29,6 +55,7 @@ export interface AutomaticCircleBridge<P extends PlatformName> {
29
55
  amount: bigint,
30
56
  nativeGas?: bigint
31
57
  ): AsyncGenerator<UnsignedTransaction>;
58
+ // TODO: events
32
59
  }
33
60
 
34
61
  export interface CircleBridge<P extends PlatformName> {
@@ -1,10 +1,23 @@
1
1
  import { PlatformName } from "@wormhole-foundation/sdk-base";
2
2
  import { UniversalOrNative } from "../address";
3
3
  import { UnsignedTransaction } from "../unsignedTransaction";
4
+ import { RpcConnection } from "../rpc";
5
+
6
+ export interface SupportsWormholeCore<P extends PlatformName> {
7
+ getWormholeCore(rpc: RpcConnection<P>): Promise<WormholeCore<P>>;
8
+ }
9
+
10
+ export function supportsWormholeCore<P extends PlatformName>(
11
+ thing: SupportsWormholeCore<P> | any
12
+ ): thing is SupportsWormholeCore<P> {
13
+ return typeof (<SupportsWormholeCore<P>>thing).getWormholeCore === "function";
14
+ }
4
15
 
5
16
  export interface WormholeCore<P extends PlatformName> {
6
17
  publishMessage(
7
18
  sender: UniversalOrNative<P>,
8
19
  message: string | Uint8Array
9
20
  ): AsyncGenerator<UnsignedTransaction>;
21
+ // TODO: parseTransactionDetails
22
+ // TODO: events?
10
23
  }
@@ -4,10 +4,36 @@ import { TokenId } from "../types";
4
4
  import { VAA } from "../vaa";
5
5
  import { UnsignedTransaction } from "../unsignedTransaction";
6
6
  import "../payloads/tokenBridge";
7
+ import { RpcConnection } from "../rpc";
7
8
 
8
9
  export const ErrNotWrapped = (token: string) =>
9
10
  new Error(`Token ${token} is not a wrapped asset`);
10
11
 
12
+ export interface SupportsTokenBridge<P extends PlatformName> {
13
+ getTokenBridge(rpc: RpcConnection<P>): Promise<TokenBridge<P>>;
14
+ }
15
+
16
+ export function supportsTokenBridge<P extends PlatformName>(
17
+ thing: SupportsTokenBridge<P> | any
18
+ ): thing is SupportsTokenBridge<P> {
19
+ return typeof (<SupportsTokenBridge<P>>thing).getTokenBridge === "function";
20
+ }
21
+
22
+ export interface SupportsAutomaticTokenBridge<P extends PlatformName> {
23
+ getAutomaticTokenBridge(
24
+ rpc: RpcConnection<P>
25
+ ): Promise<AutomaticTokenBridge<P>>;
26
+ }
27
+
28
+ export function supportsAutomaticTokenBridge<P extends PlatformName>(
29
+ thing: SupportsAutomaticTokenBridge<P> | any
30
+ ): thing is SupportsAutomaticTokenBridge<P> {
31
+ return (
32
+ typeof (<SupportsAutomaticTokenBridge<P>>thing).getAutomaticTokenBridge ===
33
+ "function"
34
+ );
35
+ }
36
+
11
37
  export interface TokenBridge<P extends PlatformName> {
12
38
  // checks a native address to see if its a wrapped version
13
39
  isWrappedAsset(nativeAddress: UniversalOrNative<P>): Promise<boolean>;
@@ -21,6 +47,7 @@ export interface TokenBridge<P extends PlatformName> {
21
47
  // Returns the address of the native version of this asset
22
48
  getWrappedAsset(foreignToken: TokenId): Promise<NativeAddress<P>>;
23
49
 
50
+ // TODO: preview (receive amount, fees, gas estimates, estimated blocks/time)
24
51
  isTransferCompleted(
25
52
  vaa: VAA<"Transfer"> | VAA<"TransferWithPayload">
26
53
  ): Promise<boolean>;
@@ -47,6 +74,7 @@ export interface TokenBridge<P extends PlatformName> {
47
74
  vaa: VAA<"Transfer"> | VAA<"TransferWithPayload">,
48
75
  unwrapNative?: boolean //default: true
49
76
  ): AsyncGenerator<UnsignedTransaction>;
77
+ // TODO: parse transaction
50
78
  }
51
79
 
52
80
  export interface AutomaticTokenBridge<P extends PlatformName> {
@@ -67,4 +95,19 @@ export interface AutomaticTokenBridge<P extends PlatformName> {
67
95
  recipient: ChainAddress,
68
96
  token: TokenId | "native"
69
97
  ): Promise<bigint>;
98
+ // the amount of native tokens a user would receive by swapping x amount of sending tokens
99
+ // nativeTokenAmount(
100
+ // destChain: ChainName | ChainId,
101
+ // token: TokenId,
102
+ // amount: BigNumber,
103
+ // walletAddress: string,
104
+ // ): Promise<BigNumber>;
105
+
106
+ // the maximum amount of sending tokens that can be swapped for native tokens
107
+ // maxSwapAmount(
108
+ // destChain: ChainName | ChainId,
109
+ // token: TokenId,
110
+ // walletAddress: string,
111
+ // ): Promise<BigNumber>;
112
+ // TODO: events (Redeem, Swap)
70
113
  }
package/src/rpc.ts CHANGED
@@ -1,16 +1,2 @@
1
1
  import { PlatformName } from "@wormhole-foundation/sdk-base";
2
-
3
- export interface EvmRpc {
4
- broadcastTransaction(stxns: string): Promise<any>;
5
- getBalance(address: string): Promise<bigint>;
6
- }
7
- export interface SolRpc {
8
- getBalance(publicKey: any, commitmentOrConfig: any): Promise<number>;
9
- getParsedAccountInfo(publickKey: any): Promise<any>;
10
- }
11
-
12
- export type RpcConnection<P extends PlatformName> = P extends "Evm"
13
- ? EvmRpc
14
- : P extends "Solana"
15
- ? SolRpc
16
- : never;
2
+ export type RpcConnection<P extends PlatformName> = any;
@@ -1,18 +1,27 @@
1
- import { ChainName, PlatformName } from "@wormhole-foundation/sdk-base";
2
- import { RpcConnection, ChainContext, Platform } from "../..";
1
+ import {
2
+ ChainName,
3
+ Network,
4
+ PlatformName,
5
+ } from "@wormhole-foundation/sdk-base";
6
+ import { ChainContext, Platform } from "../..";
7
+ import { mockPlatformFactory } from "./platform";
3
8
 
4
9
  export function chainFactory<P extends PlatformName>(
10
+ network: Network,
5
11
  p: Platform<P>,
6
12
  chain: ChainName
7
13
  ): ChainContext<P> {
8
- return new MockChain<P>(p, chain);
14
+ return new MockChain<P>(network, p.platform, chain);
9
15
  }
10
16
 
11
17
  export class MockChain<P extends PlatformName> extends ChainContext<P> {
12
- private rpc?: RpcConnection<P>;
13
-
14
- getRpc(): RpcConnection<P> {
15
- this.rpc = this.rpc ? this.rpc : this.platform.getRpc(this.chain);
16
- return this.rpc!;
18
+ readonly platform: Platform<P>;
19
+ constructor(
20
+ network: Network,
21
+ platform: PlatformName,
22
+ readonly chain: ChainName
23
+ ) {
24
+ super(chain);
25
+ this.platform = mockPlatformFactory<P>(network, platform as P, {});
17
26
  }
18
27
  }