Skip to content
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

SDKv2 migration: Route adapter #2090

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bf41f70
sdkv2 route unit tests wip
artursapek Apr 30, 2024
7569267
fix mistake
artursapek May 8, 2024
74f6d86
ugh
artursapek May 8, 2024
1681f85
injective
artursapek May 9, 2024
a6952e2
version lock deps to fix SDK clashes
artursapek May 9, 2024
3ab418a
move mappings
artursapek May 9, 2024
7c4e829
circular dep?
artursapek May 9, 2024
0a86905
ugh
artursapek May 9, 2024
dcd830c
moar tests
artursapek May 9, 2024
9dbf38f
provide better rpc for solana
artursapek May 9, 2024
a740d1d
compare isSupportedChain
artursapek May 9, 2024
076d494
add exception for cosmos token bridge check
artursapek May 10, 2024
c339f32
supported src, dest token
artursapek May 10, 2024
49dfbe2
disable RPC-heavy tests for now
artursapek May 10, 2024
bc76117
clean up logs
artursapek May 10, 2024
541607b
get rid of unused methods
artursapek May 10, 2024
3474f6e
working quotes sorta
artursapek May 14, 2024
5a86a39
example of local sdk working (in case i break it)
artursapek May 14, 2024
30b66e3
script for using local copy of sdk
artursapek May 14, 2024
f3c14a1
repro
artursapek May 14, 2024
eae567b
script for installing local copy of sdk
artursapek May 15, 2024
591e0e4
it works \o/
artursapek May 15, 2024
2bbc9bd
remove unnecessary overrides
artursapek May 15, 2024
9f08734
remove old copy
artursapek May 15, 2024
8e2a493
move route mapping to its own file
artursapek May 15, 2024
6139fee
moar route mapping
artursapek May 15, 2024
50eb5ca
fix mapping
artursapek May 15, 2024
bc22911
muahahaa
artursapek May 16, 2024
603dbf2
revert part of 541607b
artursapek May 16, 2024
3f5c32b
fix mistake
artursapek May 16, 2024
6eac195
bamp
artursapek May 16, 2024
1cc43ae
test
artursapek May 16, 2024
431d69d
test2
artursapek May 16, 2024
83d3bec
move localStorage call
artursapek May 16, 2024
201f925
move wormhole deps to top level package
artursapek May 20, 2024
8523ab2
sigh
artursapek May 20, 2024
5c6d330
package lock
artursapek May 20, 2024
49289aa
i can do this all day mof
artursapek May 20, 2024
d1bb664
move RPC-hungry tests to idle file for now
artursapek May 20, 2024
f0c62f0
rename fn
artursapek May 23, 2024
a48fc9e
remove redundant check
artursapek May 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
- run: npm ci
- run: npm run build -w sdk
- run: npm test -w wormhole-connect
env:
REACT_APP_SOLANA_RPC: ${{ vars.REACT_APP_SOLANA_RPC }}

check-sdn-list:
runs-on: ubuntu-latest
Expand Down
27,580 changes: 17,870 additions & 9,710 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,27 @@
},
"lint-staged": {
"**/*": "prettier --workspaces --if-present --write --ignore-unknown"
},
"overrides": {
"@injectivelabs/sdk-ts@1.10.72": {
"@injectivelabs/token-metadata": "1.10.42"
},
"@ledgerhq/hw-transport@6.27.1": {
"@ledgerhq/errors": "6.10.2",
"@ledgerhq/logs": "6.12.0",
"@ledgerhq/devices": "6.27.1"
},
"@ledgerhq/hw-transport-webhhid@6.27.1": {
"@ledgerhq/errors": "6.10.2",
"@ledgerhq/logs": "6.12.0",
"@ledgerhq/devices": "6.27.1"
},
"@wormhole-foundation/sdk-definitions-ntt": {
artursapek marked this conversation as resolved.
Show resolved Hide resolved
"@wormhole-foundation/sdk-definitions": "^0.7.0-beta.1",
"@wormhole-foundation/sdk-base": "^0.7.0-beta.1"
},
"@wormhole-foundation/wormhole-connect": {
"aptos": "1.5.0"
artursapek marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
20 changes: 20 additions & 0 deletions sdk/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"env": {
"node": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"comma-dangle": ["error", "always-multiline"],
"semi": ["error", "always"],
"@typescript-eslint/explicit-module-boundary-types": ["error"],
"@typescript-eslint/no-non-null-assertion": ["error"],
"@typescript-eslint/no-explicit-any": ["error", { "ignoreRestArgs": true }]
}
}
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"ethers": "^5.7.2",
"typedoc": "^0.24.8",
"typedoc": "^0.25.0",
"typescript": "^5.3.3"
},
"scripts": {
Expand Down
15 changes: 11 additions & 4 deletions wormhole-connect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@
"@cosmjs/tendermint-rpc": "^0.31.3",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@injectivelabs/sdk-ts": "1.10.72",
"@injectivelabs/token-metadata": "1.10.42",
"@ledgerhq/devices": "6.27.1",
"@ledgerhq/errors": "6.10.2",
"@ledgerhq/hw-transport": "6.27.1",
"@ledgerhq/hw-transport-webhid": "6.27.1",
"@ledgerhq/logs": "6.12.0",
"@manahippo/aptos-wallet-adapter": "^1.0.8",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.4",
"@mysten/sui.js": "^0.32.2",
"@reduxjs/toolkit": "^1.9.1",
"@solana/wallet-adapter-wallets": "^0.19.25",
"@solana/web3.js": "^1.73.0",
"@wormhole-foundation/sdk": "^0.5.3-beta.6",
"@wormhole-foundation/sdk-definitions": "^0.6.5",
"@wormhole-foundation/sdk-definitions-ntt": "^0.0.1-beta.4",
"@wormhole-foundation/sdk": "^0.7.0-beta.3",
"@wormhole-foundation/sdk-definitions": "^0.7.0-beta.3",
"@wormhole-foundation/sdk-definitions-ntt": "^0.0.1-beta.5",
"@xlabs-libs/wallet-aggregator-aptos": "^0.0.1-alpha.14",
"@xlabs-libs/wallet-aggregator-core": "^0.0.1-alpha.18",
"@xlabs-libs/wallet-aggregator-cosmos": "^0.0.1-alpha.14",
Expand Down Expand Up @@ -66,7 +73,7 @@
"lint:ci": "scripts/lint_ci.sh",
"prettier": "prettier --write ./src",
"analyze": "NODE_ENV=production NODE_OPTIONS=--max-old-space-size=6144 vite-bundle-visualizer",
"test": "vitest run",
"test": "vitest run tests/ci",
"test:dev": "vitest",
"checksdn": "npx tsx scripts/ofac/checkSdnListForUpdates.ts",
"preview": "vite preview"
Expand Down
57 changes: 43 additions & 14 deletions wormhole-connect/src/config/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Network as NetworkConnect,
TokenConfig as TokenConfigV1,
TokensConfig as TokensConfigV1,
ChainsConfig as ChainsConfigV1,
} from 'config/types';

import * as v2 from '@wormhole-foundation/sdk';
Expand All @@ -12,17 +11,9 @@ import * as v2 from '@wormhole-foundation/sdk';
// This is only meant to be used while we transition to SDKv2
export class SDKConverter {
wh: v1.WormholeContext;
chains: ChainsConfigV1;
tokens: TokensConfigV1;

constructor(
wh: v1.WormholeContext,
chains: ChainsConfigV1,
tokens: TokensConfigV1,
) {

constructor(wh: v1.WormholeContext) {
this.wh = wh;
this.chains = chains;
this.tokens = tokens;
}

// Chain conversion
Expand All @@ -36,6 +27,9 @@ export class SDKConverter {
}

toChainV2(chain: v1.ChainName | v1.ChainId): v2.Chain {
if (typeof chain !== 'number' && typeof chain !== 'string') {
throw new Error(JSON.stringify(chain));
}
return v2.toChain(this.wh.toChainId(chain));
}

Expand Down Expand Up @@ -81,18 +75,29 @@ export class SDKConverter {
}
}

tokenIdV2<C extends v2.Chain>(
chain: v1.ChainName | v1.ChainId,
address: string,
): v2.TokenId<C> {
const chainv2 = this.toChainV2(chain) as C;
return v2.Wormhole.tokenId(chainv2, address);
}

isTokenConfigV1(v: v1.TokenId | TokenConfigV1): v is TokenConfigV1 {
return 'key' in v;
}

// Attempts to find the Connect TokenConfig, which is comomnly used in Connect code base,
// given a v2.TokenId
findTokenConfigV1(tokenId: v2.TokenId): TokenConfigV1 | undefined {
findTokenConfigV1(
tokenId: v2.TokenId,
tokenConfigs: TokenConfigV1[],
): TokenConfigV1 | undefined {
const isNative = tokenId.address === 'native';
const chain = this.toChainNameV1(tokenId.chain);

for (const key in this.tokens) {
const token = this.tokens[key];
for (const key in tokenConfigs) {
const token = tokenConfigs[key];
if (token.nativeChain === chain) {
if (isNative && token.tokenId === undefined) {
// Connect's TokenConfig lacks a tokenId field when it's the native gas token
Expand All @@ -106,4 +111,28 @@ export class SDKConverter {
}
}
}

getTokenIdV2ForKey<C extends v2.Chain>(
key: string,
chain: v1.ChainName | v1.ChainId,
tokenConfigs: TokensConfigV1,
): v2.TokenId<C> | undefined {
const tokenConfig = tokenConfigs[key];
if (!tokenConfig) return undefined;

const chainName = this.wh.toChainName(chain);

if (tokenConfig.nativeChain === chainName) {
if (tokenConfig.tokenId) {
return this.tokenIdV2(chainName, tokenConfig.tokenId.address);
}
} else {
if (tokenConfig.foreignAssets && tokenConfig.foreignAssets[chainName]) {
return this.tokenIdV2(
chainName,
tokenConfig.foreignAssets[chainName]!.address,
);
}
}
}
}
2 changes: 1 addition & 1 deletion wormhole-connect/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function buildConfig(
validateDefaults(customConfig.bridgeDefaults, networkData.chains, tokens);
}

const sdkConverter = new SDKConverter(wh, networkData.chains, tokens);
const sdkConverter = new SDKConverter(wh);

return {
wh,
Expand Down
61 changes: 61 additions & 0 deletions wormhole-connect/src/routes/mappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Route } from 'config/types';

import { routes } from '@wormhole-foundation/sdk';
import { RouteAbstract } from './abstracts/routeAbstract';

// Legacy routes
import { BridgeRoute } from './bridge';
import { RelayRoute } from './relay';
import { CCTPRelayRoute } from './cctpRelay';
import { CCTPManualRoute } from './cctpManual';
import { TBTCRoute } from './tbtc';
import { ETHBridge } from './porticoBridge/ethBridge';
import { wstETHBridge } from './porticoBridge/wstETHBridge';
import { CosmosGatewayRoute } from './cosmosGateway';
import { NttManual, NttRelay } from './ntt';

export interface RouteImpls {
v1: RouteAbstract;
v2?: routes.RouteConstructor;
}

export function getRouteImpls(route: Route): RouteImpls {
return {
[Route.Bridge]: {
v1: new BridgeRoute(),
v2: routes.TokenBridgeRoute,
},
[Route.Relay]: {
v1: new RelayRoute(),
v2: routes.AutomaticTokenBridgeRoute,
},
[Route.CCTPManual]: {
v1: new CCTPManualRoute(),
v2: routes.CCTPRoute,
},
[Route.CCTPRelay]: {
v1: new CCTPRelayRoute(),
v2: routes.AutomaticCCTPRoute,
},
[Route.CosmosGateway]: {
v1: new CosmosGatewayRoute(),
},
[Route.TBTC]: {
v1: new TBTCRoute(),
},
[Route.ETHBridge]: {
v1: new ETHBridge(),
v2: routes.AutomaticPorticoRoute,
},
[Route.wstETHBridge]: {
v1: new wstETHBridge(),
v2: routes.AutomaticPorticoRoute,
},
[Route.NttManual]: {
v1: new NttManual(),
},
[Route.NttRelay]: {
v1: new NttRelay(),
},
}[route];
}
Loading
Loading