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

Fix TBRv3 library issues #104

Merged
merged 35 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d78c63e
Update all @wormhole-foundation/sdk versions to the latest one and ad…
Alex99y Dec 18, 2024
f7a157a
evm: fixes sdk deserialization logic
scnale Dec 19, 2024
3825f94
misc: updates yarn pnp
scnale Dec 19, 2024
2452e25
Fixed layout testnet issue & mint issue
Alex99y Dec 20, 2024
de5325b
evm: removes redundant deserialized key check
scnale Dec 20, 2024
e266e45
Add whitelist token address filter
Alex99y Jan 3, 2025
a9be8cb
Fixing unwrapIntent param for evm
Alex99y Jan 6, 2025
825b498
Update all @wormhole-foundation/sdk versions to the latest one and ad…
Alex99y Dec 18, 2024
fab59ac
evm: fixes sdk deserialization logic
scnale Dec 19, 2024
0b01590
misc: updates yarn pnp
scnale Dec 19, 2024
601586b
Fixed layout testnet issue & mint issue
Alex99y Dec 20, 2024
992ed99
evm: removes redundant deserialized key check
scnale Dec 20, 2024
876bf4b
Add whitelist token address filter
Alex99y Jan 3, 2025
5857b79
Fixing unwrapIntent param for evm
Alex99y Jan 6, 2025
7a94091
Merge branch 'fix/TBRv3' of github.com:XLabs/arbitrary-token-transfer…
Alex99y Jan 8, 2025
715ad8b
Merge branch 'main' into fix/TBRv3
Alex99y Jan 8, 2025
a10709d
Fix Solana gasDropOffIssue
Alex99y Jan 10, 2025
8d17070
Fix Solana tests compilation issues
Alex99y Jan 10, 2025
d0ae704
Fix @solana/web3.js version
Alex99y Jan 10, 2025
c6d5542
Update @solana/web3.js to the latest version
Alex99y Jan 10, 2025
0a11ecd
Fix Transfers SOL to another chain test
Alex99y Jan 13, 2025
8fae0ea
Fix Sends a foreign token back to its original chain test
Alex99y Jan 13, 2025
6802424
Modify wormhole peerDependency rules
Alex99y Jan 13, 2025
10fca2d
Update yarn.lock file
Alex99y Jan 13, 2025
1682022
misc: several libraries update
scnale Jan 8, 2025
68dcb11
connect: removes obsolete imports
scnale Jan 16, 2025
9def226
Merge branch 'main' into fix/TBRv3
Alex99y Jan 20, 2025
13af2bc
Reduce @solana/web3.js version to 1.95.3 and remove unneeded code
Alex99y Jan 20, 2025
a33532f
Return @solana/web3.js version to ^1.98.0 and fix anchor type issues
Alex99y Jan 20, 2025
b2e862d
ci: updates node version
scnale Jan 20, 2025
90c4abd
misc: updates yarn to v4.6.0
scnale Jan 20, 2025
e27493a
misc: fixes yarn lockfile
scnale Jan 20, 2025
23c1904
Move gasdropoff calculation
Alex99y Jan 20, 2025
67f4575
Fix solana Transfers SOL to another chain test
Alex99y Jan 20, 2025
d3e78bf
misc: format fix
scnale Jan 22, 2025
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: 1 addition & 1 deletion .github/workflows/ci_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.17.0"
node-version: "20.18.1"
registry-url: "https://npm.pkg.github.com"
cache: "yarn"
cache-dependency-path: |
Expand Down
881 changes: 411 additions & 470 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
925 changes: 0 additions & 925 deletions .yarn/releases/yarn-4.4.1.cjs

This file was deleted.

934 changes: 934 additions & 0 deletions .yarn/releases/yarn-4.6.0.cjs

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# yarn zero install's "binary" can't describe references relative to the global cache reliably, so we disable it
enableGlobalCache: false

yarnPath: .yarn/releases/yarn-4.4.1.cjs
npmPublishRegistry: "https://npm.pkg.github.com"

npmPublishRegistry: 'https://npm.pkg.github.com'
npmScopes:
xlabs:
npmRegistryServer: 'https://npm.pkg.github.com'
npmRegistryServer: "https://npm.pkg.github.com"
xlabs-xyz:
npmPublishRegistry: 'https://registry.npmjs.org'
npmRegistryServer: 'https://registry.npmjs.org'
npmPublishRegistry: "https://registry.npmjs.org"
npmRegistryServer: "https://registry.npmjs.org"

supportedArchitectures:
cpu:
- current
- x64
- arm64
os:
- current
- darwin
- linux
libc:
- current
- glibc
- musl
os:
- current
- darwin
- linux

yarnPath: .yarn/releases/yarn-4.6.0.cjs
10 changes: 7 additions & 3 deletions connect/definitions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,21 @@
"author": "",
"license": "Apache 2",
"dependencies": {
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"ethers": "^6.13.3"
"ethers": "^6.13.5"
},
"devDependencies": {
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"prettier": "^3.3.3",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"src/index.ts"
Expand Down
13 changes: 9 additions & 4 deletions connect/platforms/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,25 @@
"author": "",
"license": "Apache 2",
"dependencies": {
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"@wormhole-foundation/sdk-evm": "^1.1.1",
"@xlabs-xyz/arbitrary-token-transfers-definitions": "workspace:*",
"@xlabs-xyz/evm-arbitrary-token-transfers": "workspace:*",
"ethers": "^6.13.3"
"ethers": "^6.13.5"
},
"devDependencies": {
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"@wormhole-foundation/sdk-evm": "^1.4.5",
"prettier": "^3.3.3",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-evm": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"src/index.ts"
Expand Down
4 changes: 1 addition & 3 deletions connect/platforms/evm/src/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
ChainsConfig,
Contracts,
isNative,
resolveWrappedToken,
toNative,
VAA,
} from '@wormhole-foundation/sdk-definitions';
import '@wormhole-foundation/sdk-evm';
Expand Down Expand Up @@ -132,7 +130,7 @@ export class AutomaticTokenBridgeV3EVM<N extends Network, C extends EvmChains>
address: params.recipient.address.toUniversalAddress(),
chain: recipientChain,
},
unwrapIntent: true, // TODO: receive as option/param? would require UI work
unwrapIntent: params.unwrapIntent,
},
feeEstimation: {
fee,
Expand Down
15 changes: 10 additions & 5 deletions connect/platforms/solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@
"license": "Apache 2",
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@solana/spl-token": "0.3.9",
"@solana/web3.js": "^1.95.3",
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"@wormhole-foundation/sdk-solana": "^1.1.1",
"@solana/spl-token": "0.4.9",
"@solana/web3.js": "^1.98.0",
"@xlabs-xyz/arbitrary-token-transfers-definitions": "workspace:*",
"@xlabs-xyz/solana-arbitrary-token-transfers": "workspace:*"
},
"devDependencies": {
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"@wormhole-foundation/sdk-solana": "^1.4.5",
"prettier": "^3.3.3",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-solana": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"src/index.ts"
Expand Down
10 changes: 2 additions & 8 deletions connect/platforms/solana/src/automatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export class AutomaticTokenBridgeV3Solana<N extends Network, C extends SolanaCha
gasDropoffAmount,
maxFeeLamports: BigInt(params.fee.toString() || 0),
unwrapIntent: params.unwrapIntent,
mintAddress: mint,
}),
);

Expand Down Expand Up @@ -262,14 +263,7 @@ export class AutomaticTokenBridgeV3Solana<N extends Network, C extends SolanaCha
}

async baseRelayingParams(chain: SupportedChains): Promise<BaseRelayingParams> {
const config = await this.client.account.chainConfig(chain).fetch();

return {
maxGasDropoff: config.maxGasDropoffMicroToken,
baseFee: config.relayerFeeMicroUsd,
paused: config.pausedOutboundTransfers,
canonicalPeer: new UniversalAddress(new Uint8Array(config.canonicalPeer)),
};
return this.client.baseRelayingParams(chain);
}

private mintAddress(token: TokenAddress<Chain>): PublicKey {
Expand Down
13 changes: 9 additions & 4 deletions connect/route/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,26 @@
"author": "",
"license": "Apache 2",
"dependencies": {
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-connect": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"@xlabs-xyz/arbitrary-token-transfer-evm-route": "workspace:*",
"@xlabs-xyz/arbitrary-token-transfer-solana-route": "workspace:*",
"@xlabs-xyz/arbitrary-token-transfers-definitions": "workspace:*",
"ethers": "^6.13.3"
"ethers": "^6.13.5"
},
"devDependencies": {
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-connect": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"prettier": "^3.3.3",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-connect": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"src/index.ts"
Expand Down
19 changes: 15 additions & 4 deletions connect/route/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@ import {
} from '@wormhole-foundation/sdk-connect';
import {
isNative,
TokenAddress,
toNative,
UniversalAddress,
UniversalOrNative,
} from '@wormhole-foundation/sdk-definitions';
import {
SupportedChains,
tokenBridgeRelayerV3Chains,
} from '@xlabs-xyz/arbitrary-token-transfers-definitions';
import '@xlabs-xyz/arbitrary-token-transfers-definitions';
import '@xlabs-xyz/arbitrary-token-transfer-evm-route';
import '@xlabs-xyz/arbitrary-token-transfer-solana-route';

interface TransferOptions {
nativeGas: number; // this is a percentage
Expand All @@ -48,6 +47,10 @@ interface QuotedTransferOptions extends ValidatedTransferOptions {

type Receipt = TransferReceipt<AttestationReceipt<'AutomaticTokenBridgeV3'>>;

export interface AutomaticTokenBridgeRouteV3Config {
allowedTokenAddresses?: TokenId<Chain>[];
}

export class AutomaticTokenBridgeRouteV3<N extends Network>
extends routes.AutomaticRoute<N, any, any, any>
implements routes.StaticRouteMethods<typeof AutomaticTokenBridgeRouteV3>
Expand All @@ -68,10 +71,18 @@ export class AutomaticTokenBridgeRouteV3<N extends Network>
return [...(chains || [])];
}

static config: AutomaticTokenBridgeRouteV3Config | undefined = undefined;

static async supportedSourceTokens(fromChain: ChainContext<Network>): Promise<TokenId[]> {
const allowedTokenAddresses = this.config?.allowedTokenAddresses || [];
const isWhitelistConfigAvailable = this.config && allowedTokenAddresses.length > 0;
Comment on lines +77 to +78
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's all this about? This does not exactly fit the theme of the repo name of "arbitrary-token-transfers", no?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nonergodic It is funny because I asked the same question. They want this restriction to prevent users from bridging useless tokens. By default is inactive and I believe that this feature will only be used in Portal Bridge UI.
@solanoepalacio can give you more default about this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds to me that a deny list would be more desirable in that case 🤔. But I'm not sure. I'll ask.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few notes that shed a -little- bit of light to this.
There's two limitations that prevent to fully embracing the "arbitrary token transfers" nature of this protocol:

  • At the UI level the user doesn't have the ability to just select "any" token. Connect is configured with a set of supported tokens at bootstrap. I think @adam and @Art (from foundation and whlabs respectively) are working on adding the ability to enter a token address. Probably they are doing it directly against the token bridge, but we'd need to check.
  • To fully support "arbitrary-token-transfers" with automatic relaying we are faced with the problem of needing attestations in the target chain. IOW: While the relayer can't attest a token that hasn't been transferred before to a chain, we can't offer automatic ATT to users because probably the relay will fail. (There a ton of considerations on the UX side that make this implementation trickier than one may think).

For this reason, there's a "phased" plan to get to Automatic Token Transfers. Plan is like so IIRC:

  1. Release TBRv3 with a whitelist of the 30 most used tokens in each chains (this PR)
  2. Make portal support any token that has already been attested
  3. Add automatic attestation on the relayer and make the final release of Automatic Token Transfers (with automatic relaying)

return Object.values(fromChain.config.tokenMap!).map((td) =>
Wormhole.tokenId(td.chain, td.address),
);
).filter((token) => !(isWhitelistConfigAvailable && !allowedTokenAddresses.some(
(whitelistedToken) =>
whitelistedToken.chain === token.chain &&
whitelistedToken.address.toString() === token.address.toString()
)))
}

static async supportedDestinationTokens<N extends Network>(
Expand Down
18 changes: 9 additions & 9 deletions deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
},
"dependencies": {
"@coral-xyz/anchor": "^0.30.1",
"@solana/spl-token": "^0.4.8",
"@solana/web3.js": "^1.95.3",
"@solana/spl-token": "^0.4.9",
"@solana/web3.js": "^1.98.0",
Alex99y marked this conversation as resolved.
Show resolved Hide resolved
"@typechain/ethers-v6": "^0.5.1",
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"@wormhole-foundation/sdk-evm": "^1.1.1",
"@wormhole-foundation/sdk-evm-tokenbridge": "^1.1.1",
"@wormhole-foundation/sdk-solana": "^1.1.1",
"@wormhole-foundation/sdk-solana-tokenbridge": "^1.1.1",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"@wormhole-foundation/sdk-evm": "^1.4.5",
"@wormhole-foundation/sdk-evm-tokenbridge": "^1.4.5",
"@wormhole-foundation/sdk-solana": "^1.4.5",
"@wormhole-foundation/sdk-solana-tokenbridge": "^1.4.5",
"@xlabs-xyz/evm-arbitrary-token-transfers": "workspace:*",
"@xlabs-xyz/ledger-signer": "^0.0.4",
"@xlabs-xyz/ledger-signer-ethers-v6": "^0.0.1",
"@xlabs-xyz/ledger-signer-solana": "^0.0.1",
"@xlabs-xyz/solana-arbitrary-token-transfers": "workspace:*",
"chalk": "^5.3.0",
"dotenv": "^16.4.5",
"ethers": "^6.13.4",
"ethers": "^6.13.5",
"typechain": "^8.3.2"
}
}
1 change: 1 addition & 0 deletions deployment/test/test-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ async function sendSolanaTestTransaction(
gasDropoffAmount,
maxFeeLamports,
unwrapIntent,
mintAddress: mint,
} satisfies TransferParameters;

transferIx = await tbr.transferTokens(signerKey, params);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
"connect/platforms/*",
"connect/route"
],
"packageManager": "yarn@4.4.1"
"packageManager": "yarn@4.6.0"
}
10 changes: 5 additions & 5 deletions sdk/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
CustomConversion,
deserializeLayout,
Layout,
layout,
LayoutItem,
LayoutToType,
serializeLayout,
} from '@wormhole-foundation/sdk-base';
import { layoutItems, UniversalAddress, VAA } from '@wormhole-foundation/sdk-definitions';

Expand All @@ -27,11 +27,11 @@ export function throwError(message: string): never {

/** Deserialize the inner payload aka the message: `vaa.payload.payload`. */
export function deserializeTbrV3Message(payload: Uint8Array): TbrV3Payload {
return layout.deserializeLayout(TBRv3MessageLayout, payload);
return deserializeLayout(TBRv3MessageLayout, payload);
}

export function serializeTbrV3Message(message: TbrV3Payload): Uint8Array {
return layout.serializeLayout(TBRv3MessageLayout, message);
return serializeLayout(TBRv3MessageLayout, message);
}

export function toVaaWithTbrV3Message(vaa: VaaMessage): VaaMessageWithTbrV3Payload {
Expand Down Expand Up @@ -64,7 +64,7 @@ const gasDropoffItem = {
binary: 'uint',
size: 4,
custom: decimalDownShift(6),
} as const satisfies LayoutItem;
} as const;

export const TBRv3MessageLayout = [
//we can turn this into a switch layout if we ever get a version 1
Expand Down
8 changes: 6 additions & 2 deletions sdk/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"bn.js": "^5.2.1"
},
"devDependencies": {
"@types/bn.js": "^5.1.5",
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"index.ts"
Expand Down
13 changes: 9 additions & 4 deletions sdk/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,26 @@
"author": "",
"license": "Apache 2",
"dependencies": {
"@wormhole-foundation/sdk-base": "^1.1.1",
"@wormhole-foundation/sdk-definitions": "^1.1.1",
"@wormhole-foundation/sdk-evm": "^1.1.1",
"ethers": "^6.13.4"
"ethers": "^6.13.5"
},
"devDependencies": {
"@types/chai": "^4.3.19",
"@types/mocha": "^10",
"@types/node": "20.17.5",
"@wormhole-foundation/sdk-base": "^1.4.5",
"@wormhole-foundation/sdk-definitions": "^1.4.5",
"@wormhole-foundation/sdk-evm": "^1.4.5",
"chai": "^5.1.1",
"mocha": "^10.7.3",
"tsup": "^8.3.5",
"tsx": "4.19.2",
"typescript": "5.6.3"
},
"peerDependencies": {
"@wormhole-foundation/sdk-base": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-definitions": ">= 1.3.0 < 2",
"@wormhole-foundation/sdk-evm": ">= 1.3.0 < 2"
},
"tsup": {
"entry": [
"tbrv3/index.ts"
Expand Down
Loading
Loading