Skip to content

Commit

Permalink
Bug Fixes (#467)
Browse files Browse the repository at this point in the history
* Fix platform generic issue

* update fetchAttestation to also check if the transfer has been completed

* allow calling fetch attestation even if its > attested

* bamp

---------

Co-authored-by: Artur Sapek <art@wormholelabs.xyz>
  • Loading branch information
barnjamin and artursapek authored Apr 15, 2024
1 parent 80a0949 commit 65ba31b
Show file tree
Hide file tree
Showing 32 changed files with 139 additions and 117 deletions.
6 changes: 3 additions & 3 deletions connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-connect",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -75,8 +75,8 @@
},
"dependencies": {
"axios": "^1.4.0",
"@wormhole-foundation/sdk-base": "0.5.3-beta.3",
"@wormhole-foundation/sdk-definitions": "0.5.3-beta.3"
"@wormhole-foundation/sdk-base": "0.5.3-beta.4",
"@wormhole-foundation/sdk-definitions": "0.5.3-beta.4"
},
"type": "module"
}
11 changes: 10 additions & 1 deletion connect/src/protocols/cctpTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class CircleTransfer<N extends Network = Network>
2) Once available, pull the VAA and parse it
3) return seq
*/
if (this._state < TransferState.SourceInitiated || this._state > TransferState.Attested)
if (this._state < TransferState.SourceInitiated)
throw new Error("Invalid state transition in `fetchAttestation`");

const ids: AttestationId[] = this.transfer.automatic
Expand All @@ -374,6 +374,15 @@ export class CircleTransfer<N extends Network = Network>

this._state = TransferState.Attested;

if (this.attestations && this.attestations.length > 0) {
for (const _attestation of this.attestations) {
const { attestation } = _attestation;
if (!CircleBridge.isCircleAttestation(attestation)) continue;
const completed = await CircleTransfer.isTransferComplete(this.toChain, attestation!);
if (completed) this._state = TransferState.DestinationFinalized;
}
}

return ids;
}

Expand Down
11 changes: 11 additions & 0 deletions connect/src/protocols/tokenTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,17 @@ export class TokenTransfer<N extends Network = Network>
);
}
this._state = TransferState.Attested;

if (this.attestations.length > 0) {
// Check if the transfer has been completed
const { attestation } = this.attestations[0]!;
const completed = await TokenTransfer.isTransferComplete(
this.toChain,
attestation as TokenTransferVAA,
);
if (completed) this._state = TransferState.DestinationFinalized;
}

return this.attestations.map((vaa) => vaa.id);
}

Expand Down
2 changes: 1 addition & 1 deletion core/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-base",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down
4 changes: 2 additions & 2 deletions core/definitions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-definitions",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -66,7 +66,7 @@
"dependencies": {
"@noble/hashes": "^1.3.1",
"@noble/curves": "^1.4.0",
"@wormhole-foundation/sdk-base": "0.5.3-beta.3"
"@wormhole-foundation/sdk-base": "0.5.3-beta.4"
},
"type": "module"
}
4 changes: 2 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/connect-sdk-examples",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -51,6 +51,6 @@
"tsx": "^4.7.0"
},
"dependencies": {
"@wormhole-foundation/sdk": "0.5.3-beta.3"
"@wormhole-foundation/sdk": "0.5.3-beta.4"
}
}
28 changes: 15 additions & 13 deletions examples/src/cctp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Network,
Signer,
TransactionId,
TransferState,
Wormhole,
amount,
wormhole,
Expand Down Expand Up @@ -46,24 +47,24 @@ AutoRelayer takes a 0.1usdc fee when xfering to any chain beside goerli, which i
// The amount specified here is denominated in the token being transferred (USDC here)
const nativeGas = automatic ? amount.units(amount.parse("0.0", 6)) : 0n;

await cctpTransfer(wh, source, destination, {
amount: amt,
automatic,
nativeGas,
});
//await cctpTransfer(wh, source, destination, {
// amount: amt,
// automatic,
// nativeGas,
//});

// Note: you can pick up a partial transfer from the origin chain name and txid
// once created, you can call `fetchAttestations` and `completeTransfer` assuming its a manual transfer.
// This is especially helpful for chains with longer time to finality where you don't want
// to have to wait for the attestation to be generated.
// await completeTransfer(
// wh,
// {
// chain: sendChain.chain,
// txid: "0xfe374b6e3ea032c05eb244e5c310047bc779f5cc389a2a0e3fccbf07fb2ae8a2",
// },
// destination.signer,
// );
await completeTransfer(
wh,
{
chain: sendChain.chain,
txid: "0x6b431a9172f6c672976294b3a3d6cd79f46a7d6247440c0934af4bfc2b5ad957",
},
destination.signer,
);
})();

async function cctpTransfer<N extends Network>(
Expand Down Expand Up @@ -129,6 +130,7 @@ export async function completeTransfer(
// EXAMPLE_RECOVER_TRANSFER
// Rebuild the transfer from the source txid
const xfer = await CircleTransfer.from(wh, txid);
if (xfer.getTransferState() > TransferState.Attested) return;

const attestIds = await xfer.fetchAttestation(60 * 60 * 1000);
console.log("Got attestation: ", attestIds);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-sdk",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"license": "Apache-2.0",
"directories": {
"test": "__tests__"
Expand Down
4 changes: 2 additions & 2 deletions platforms/algorand/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-algorand",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -76,7 +76,7 @@
"test": "jest --config ./jest.config.ts"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"algosdk": "2.7.0"
},
"type": "module"
Expand Down
6 changes: 3 additions & 3 deletions platforms/algorand/protocols/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-algorand-core",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -45,8 +45,8 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-algorand": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-algorand": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
8 changes: 4 additions & 4 deletions platforms/algorand/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-algorand-tokenbridge",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -45,9 +45,9 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-algorand": "0.5.3-beta.3",
"@wormhole-foundation/sdk-algorand-core": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-algorand": "0.5.3-beta.4",
"@wormhole-foundation/sdk-algorand-core": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions platforms/aptos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-aptos",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -46,7 +46,7 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"aptos": "1.21.0"
},
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions platforms/aptos/protocols/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-aptos-core",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -45,8 +45,8 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-aptos": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-aptos": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
6 changes: 3 additions & 3 deletions platforms/aptos/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-aptos-tokenbridge",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -45,8 +45,8 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-aptos": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-aptos": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions platforms/cosmwasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-cosmwasm",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -53,7 +53,7 @@
"test": "jest --config ./jest.config.ts"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@cosmjs/cosmwasm-stargate": "^0.32.0",
"@cosmjs/proto-signing": "^0.32.0",
"@cosmjs/stargate": "^0.32.0",
Expand Down
6 changes: 3 additions & 3 deletions platforms/cosmwasm/protocols/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-cosmwasm-core",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -52,8 +52,8 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.4",
"@cosmjs/cosmwasm-stargate": "^0.32.0",
"@cosmjs/stargate": "^0.32.0"
},
Expand Down
8 changes: 4 additions & 4 deletions platforms/cosmwasm/protocols/ibc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-cosmwasm-ibc",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -56,9 +56,9 @@
"@cosmjs/cosmwasm-stargate": "^0.32.0",
"@cosmjs/stargate": "^0.32.0",
"cosmjs-types": "^0.9.0",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.3",
"@wormhole-foundation/sdk-cosmwasm-core": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.4",
"@wormhole-foundation/sdk-cosmwasm-core": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
6 changes: 3 additions & 3 deletions platforms/cosmwasm/protocols/tokenBridge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-cosmwasm-tokenbridge",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -53,8 +53,8 @@
},
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.32.0",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.3"
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-cosmwasm": "0.5.3-beta.4"
},
"type": "module",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions platforms/evm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-evm",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -57,7 +57,7 @@
"nock": "13.3.8"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"ethers": "^6.5.1"
},
"type": "module",
Expand Down
6 changes: 3 additions & 3 deletions platforms/evm/protocols/cctp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wormhole-foundation/sdk-evm-cctp",
"version": "0.5.3-beta.3",
"version": "0.5.3-beta.4",
"repository": {
"type": "git",
"url": "git+https://github.com/wormhole-foundation/connect-sdk.git"
Expand Down Expand Up @@ -53,8 +53,8 @@
"prettier": "prettier --write ./src"
},
"dependencies": {
"@wormhole-foundation/sdk-connect": "0.5.3-beta.3",
"@wormhole-foundation/sdk-evm": "0.5.3-beta.3",
"@wormhole-foundation/sdk-connect": "0.5.3-beta.4",
"@wormhole-foundation/sdk-evm": "0.5.3-beta.4",
"ethers": "^6.5.1"
},
"type": "module",
Expand Down
Loading

0 comments on commit 65ba31b

Please sign in to comment.