-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New SDK Interfaces #26
Changes from all commits
ef55202
0958ac8
c19e5d9
362f2ba
555d208
903f738
b4ddf91
fa19bc9
900e985
59b538b
677c2af
b6502b7
f296008
e8cddf6
fac3bbe
b875612
dcb8c28
0616c2d
894170a
a51f02b
cca1139
300ea53
d1497a2
38a54fb
fe3367c
e8f51a0
2f40acf
f5f3b6c
1ddbb40
df4db94
b4c5ec3
5f8dd14
94e776f
0c6e5d7
c43af3f
6d66705
a146131
58a605a
fb997bd
60bab20
bc7cbea
3fa65a8
4f0baa0
208870e
8504dd6
5e4d621
9c80a21
164f560
88eec04
6542228
1ea2781
52ea548
170bcf5
81d9139
5908250
5c451ae
0e30bbc
2ad0d59
aef64cc
3dcbb54
e89726c
8e7cd82
6dbb11c
1b0c2e8
fbb26e5
cb6c92c
4b2cf3f
fc02318
b0a0f5c
eeb03a8
c7944dc
ea823a9
258834d
b847ab3
4de21de
f90e004
0225346
dce6f53
e5a273e
6c4a4f6
9894186
0ee1959
2db4c82
f53a2ef
91a55de
42f08aa
29ac7e1
4daae7d
57c6a7b
2323c26
5d28e8a
f3862ff
c0c1dd9
018d49b
50ad2ce
1782792
a952eac
52889bb
cae121b
68efb63
b4390e3
77873ed
66b28bc
04c8460
f86196b
a1a15d7
0c1eab3
49dd3d9
290df16
707e0a2
f2b5e65
3a10dcb
0985958
b140bbb
0dd7769
a977c5d
6ce7f77
e3ea0e1
c09d22a
c344867
f1de73a
515873d
6901094
4da1910
1fd74f6
7ffcdd1
4af4ca9
e71b8b2
da467aa
163336c
5c0ea03
8f8b035
958ed66
d177b5e
b050cd9
e1618df
e5eff27
218ffcd
492dd52
ed0cdac
479aa9f
6ec142f
ed9525c
5cf30d0
c37f0a5
f7d6850
1806eb2
d03aff1
b6be55e
f9b2d61
86ed80f
a566a09
1abc878
08db30f
f964f36
ac8db38
bb0228f
77b2926
b380750
46715be
89f1f22
32683d3
66f073c
548a53f
8654113
acb2cc7
db6fd95
91641c3
6521f49
a3f975a
0f9d119
5f90654
f19c2ac
4a9524b
c064ede
cca9933
dc52c05
970625d
6553fd2
d9838fb
139b8da
c09e0e0
ef9bd13
a7c24e2
d00fa07
961c63b
d0384ef
6175ca8
a5fa7f3
252b31a
81e4624
43be810
4cf7ae6
fc31add
6be6e1a
2a152cd
25d633b
02544b6
dc90598
9e7435c
1a9d8fb
abb89fd
4e6312a
a6bc068
25334d5
c33fe76
a2d38c9
033a815
8f7607b
46b01d5
bfb7a61
0744d50
33195de
f383a43
75c7155
b607da9
ed182b5
8849160
677939d
112d650
2fc4e97
0b0c2fe
197fd35
94c3a68
dfb32e3
b77586a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Node.js CI | ||
on: [push] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18.x' | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test | ||
# - run: cd core/tokenRegistry && npx ts-node src/scripts/checkForeignAssetConfig.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
.turbo/ | ||
build/ | ||
dist/ | ||
node_modules/ | ||
.env | ||
.env | ||
tsconfig-build.tsbuildinfo | ||
tsconfig.tsbuildinfo | ||
__tests__/staging |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"tabWidth": 2, | ||
"printWidth": 100, | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"semi": true | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
Design Document for Wormhole SDK | ||
--------------------------------- | ||
|
||
# Organization | ||
|
||
Code is organized into workspaces so that each can be its own module. | ||
|
||
``` | ||
core/ | ||
base/ -- Constants | ||
definitions/ -- VAA structures and module definitions | ||
connect/ -- Primary package and interface through Wormhole | ||
|
||
platforms/ -- Platform specific logic | ||
evm/ | ||
protocols/ | ||
tokenBridge.ts | ||
cctp.ts | ||
chain.ts | ||
platform.ts | ||
... | ||
solana/ | ||
protocols/ | ||
tokenBridge.ts | ||
chain.ts | ||
platform.ts | ||
... | ||
... | ||
``` | ||
|
||
# Concepts | ||
|
||
The `Wormhole` class provides methods to interact with the Wormhole protocol by mapping chain parameters to the `Platform` and `Chain` specific implementations. | ||
|
||
A `Platform` is a blockchain runtime, often shared across a number of chains (e.g. `Evm` platform for `Ethereum`, `Bsc`, `Polygon`, etc ...). | ||
|
||
A `Chain` is a specific blockchain, potentially with overrides for slight differences in the platform implementation. | ||
|
||
A `Protocol` (fka `Module`) is a specific application on a `Chain`, it provides a set of methods that can be called to accomplish some action (e.g. `TokenBridge` allows send/receive/lookup token, etc...) | ||
|
||
A `Signer` is an interface that provides a callback to sign one or more transaction objects. These signed transactions are sent to the blockchain to invoke some action. | ||
|
||
An `Attestation` is a signed guarantee that some _thing_ happened on a remote chain, sent to the target chain to complete a transfer. | ||
|
||
|
||
# Details | ||
|
||
## Wormhole | ||
|
||
Registers Platforms | ||
|
||
Allows overriding chain specific configs (rpc, contract addresses, ...) | ||
|
||
Provides methods to get PlatformContext or ChainContext objects | ||
```ts | ||
wh.getPlatform("Evm") | ||
wh.getChain("Ethereum") | ||
``` | ||
|
||
Provides methods to create a `WormholeTransfer` for any `Protocol` | ||
```ts | ||
wh.tokenTransfer(...) | ||
wh.nftTransfer(...) | ||
wh.cctp(...) | ||
//... | ||
``` | ||
|
||
Provides methods to query an API for VAAs and token details | ||
```ts | ||
// grab a vaa with identifier | ||
wh.getVaa(...) | ||
// get the token details | ||
wh.getOriginalToken(...) | ||
wh.getWrappedToken(orig, chain) | ||
``` | ||
|
||
## Platform | ||
|
||
Base class, implements Platform specific logic | ||
|
||
Parse Addresses | ||
|
||
Parse Message out of Transaction | ||
|
||
Sign/Send/Wait | ||
|
||
## ChainContext | ||
|
||
Defined in abstract ChainContext class | ||
|
||
Note: Dispatches many calls to the Platform, filling in details like ChainName and RPC | ||
|
||
The `getRpc` method is the only platform specific thing _required_ to implement. | ||
|
||
Responsible for holding RPC connection, initialized from default or overrides | ||
```ts | ||
cc.getRPC() // for evm -> ethers.Provider, for sol -> web3.Connection | ||
``` | ||
|
||
Holds references to Contract client | ||
|
||
|
||
<!-- | ||
Not Implemented | ||
Provides methods to lookup details for contract addresses, finality, address parsers/formatters | ||
|
||
```ts | ||
cc.getTokenBridgeAddress() | ||
cc.estimateFinality(txid) | ||
``` | ||
--> | ||
|
||
|
||
## WormholeTransfer | ||
|
||
Holds a reference to ChainContexts | ||
|
||
Holds details about the transfer | ||
|
||
Provides methods to step through the transfer process | ||
|
||
## Glossary | ||
|
||
- Network | ||
Mainnet, Testnet, Devnet | ||
- Platform | ||
A chain or group of chains within the same ecosystem that share common logic (e.g. EVM, Cosmwasm, etc) | ||
- Platform Context | ||
A class which implements a standardized format and set of methods. It may include additional chain-specific methods and logic. | ||
- Protocol | ||
A cross-chain application built on top of Wormhole (the core contracts are also considered a module) | ||
- Universal Address | ||
A 32-byte address, used by the wormhole contracts | ||
- Native Address (I think this should be called "Platform Address") | ||
An address in the standard chain-specific format | ||
- Native | ||
The "home" chain (e.g. ETH is native to Ethereum) | ||
- Foreign | ||
A non-native chain (e.g. ETH is foreign to Moonbeam) | ||
- VAA (Verified Action Approval) | ||
The core messaging primitive in Wormhole, it contains information about a message and a payload encoded as bytes. Once finality is achieved and it is observed by the majority of the guardians, it is signed and can then be used to complete a transfer on the destination chain | ||
- Payload | ||
Bytes that can be passed along with any wormhole message that contain application-specific data | ||
- Finality/Finality Threshold | ||
The required number of blocks to wait until a VAA is produced | ||
|
||
# Discussion | ||
|
||
|
||
## What's the purpose of the Wormhole class? | ||
|
||
Wormhole class provides the main interface to do _everything_ | ||
|
||
- Registers Platforms to access later -- constructor | ||
- Provides access to PlatformContexts -- getContext(ChainName) | ||
- Provides "shortcuts" to start a WormholeTransfer -- tokenTransfer/nftTransfer/cctp/... | ||
- Helpers for getting VAAs? or generally querying the API? | ||
- Abstract away chain-specific logic for easy mode access to methods | ||
|
||
## What do we want from a PlatformContext and how is that different from a provider / common utilities for a given platform? | ||
|
||
Provides Platform specific logic for a set of things | ||
|
||
- Register Modules (contract/app specific functionality) | ||
- Translates Platform specific stuff to generic stuff (e.g. ethers.Provider => RPC connection) | ||
- Deals with Platform specific interaction w/ chain (approve on eth, postvaa on sol, ...) | ||
- Implements standardized method format | ||
|
||
## What's the relationship between platforms/chains/providers? | ||
|
||
- A Platform provides the logic for all chains that run on that platform | ||
- A Chain provides consts (rpc/contract addresses/chain specific overrides) | ||
- A Provider is just an RPC connection and is held by the Chain. Providers are an implementation detail. | ||
|
||
## What's a signer vs. a wallet? Should signers have a provider (my answer: no)? | ||
|
||
- A Signer is an interface to sign transactions | ||
- It _may_ be backed by a wallet but not necessarily, as long as it fulfils the interface | ||
|
||
## Can we provide some way to make other non-standard applications available to use through the WormholeTransfer? | ||
|
||
Say I have an app that defines its own protocol, can I provide something that adheres to the WormholeTransfer interface so a dev can install it and call it like the TokenTransfer? | ||
Comment on lines
+180
to
+182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I already thought about this when specifying payload layouts, but until now I didn't realize that essentially layouts for an inheritance hierarchy of sorts... I'll have to think about this more 🤔 |
||
|
||
|
||
# Outstanding Questions: | ||
|
||
What is the preferred terminology to refer to either end of a cross-chain message: from/to, source/target or origin/destination? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like we've (partially) had this discussion before, but I can't quite remember where/in what context. 🤔 |
||
|
||
What is the preferred terminology for the core Wormhole layer? (i.e. Core Contracts or Wormhole Contracts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently the protocol name is CoreBridge and primarily refers to the contract and its associated payloads. Core layer in my mind should include the entire attestation mechanism (i.e. including off-chain components like guardians etc.). Bridge is perhaps not the best name because in its raw form it really is just attestation which, if anything, is a broadcast. I was reluctant to call it WormholeCore or anything else with Wormhole in the name because we're already in a Wormhole SDK and just "Core" seemed too generic. Open to suggestions. Main primary concern is consistency. |
||
|
||
Should we namespace export base/definitions? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't export the payloads by default because they only clutter up the namespace unnecessarily. E.g. users don't care about governance payloads and so they shouldn't be added to the payload factory by default. Being a C++ dinosaur and fan-boy I think we should follow the same principles "you don't pay for things you don't use". |
||
|
||
How should we think about xchain concepts without having xchain context? | ||
|
||
e.g. | ||
// need to implement universal univeral decoder? | ||
given eth address, and without installing evm platform, how do i turn it into a solana wrapped token without knowing how to fmt the address? | ||
|
||
// neet to tweak contracts on sol to support !ATA? | ||
given an xfer from eth=>sol, and without installing sol platform, how do i determine the ATA? | ||
Comment on lines
+193
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, that one is a tricky bitch. I realized that this would be an issue a while ago but haven't put a lot of thought into it myself yet. My knee-jerk response is to split platforms into a thin layer that contains light-weight stuff (like address types) and a heavy weight part (if you actually want to do stuff on that chain). But I'm afraid that this is not an abstraction that will actually work/hold up. (If you have to do address translations via RPC lookups like on Sui, you're presumably fucked). |
||
|
||
|
||
What is the benefit of costmap vs single fat object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. primarily: easily supporting multiple "views" (e.g. inverse mappings) |
||
|
||
Why is network duped across platform/chaincontext/contracts? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point/agree re Platform Address
I guess if we want to use the word "native", we should have some coherent idea what it should represent, because right now it's quite the confusing grab-bag of different concepts (e.g. calling the gas token of a chain the native token, calling the origin token of the token bridge the native / home chain etc.)