From 1f7790d292fe722892d37730968bde6c59b6d6b8 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Fri, 3 Jan 2025 14:21:10 +0100 Subject: [PATCH 1/2] refactor: improve waiting for destination chain --- examples/node/package.json | 8 +- examples/node/pnpm-lock.yaml | 167 +++++++++++------- package.json | 7 +- pnpm-lock.yaml | 39 ++-- src/core/EVM/EVMStepExecutor.ts | 88 ++------- src/core/Solana/SolanaStepExecutor.ts | 72 +------- src/core/UTXO/UTXOStepExecutor.ts | 78 ++------ .../waitForDestinationChainTransaction.ts | 79 +++++++++ ...saction.ts => waitForTransactionStatus.ts} | 2 +- tsconfig.build.json | 10 +- 10 files changed, 258 insertions(+), 292 deletions(-) create mode 100644 src/core/waitForDestinationChainTransaction.ts rename src/core/{waitForReceivingTransaction.ts => waitForTransactionStatus.ts} (97%) diff --git a/examples/node/package.json b/examples/node/package.json index 90ca07a6..0430ba74 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -7,12 +7,12 @@ "author": "LI.FI ", "license": "MIT", "dependencies": { - "@lifi/data-types": "^5.19.0", - "@lifi/sdk": "^3.4.4", + "@lifi/data-types": "^5.19.1", + "@lifi/sdk": "^3.5.0", "@wagmi/connectors": "^5.7.3", "@wagmi/core": "^2.16.3", "dotenv": "^16.4.7", - "viem": "^2.22.1" + "viem": "^2.22.2" }, "scripts": { "example:swap": "tsx examples/swap.ts", @@ -24,7 +24,7 @@ "example:yearn": "tsx examples/yearnDeposit.ts" }, "devDependencies": { - "@types/node": "^22.10.3", + "@types/node": "^22.10.5", "tsx": "^4.19.2", "typescript": "^5.7.2" } diff --git a/examples/node/pnpm-lock.yaml b/examples/node/pnpm-lock.yaml index ac54c7ae..837d7143 100644 --- a/examples/node/pnpm-lock.yaml +++ b/examples/node/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: '9.0' settings: - autoInstallPeers: false + autoInstallPeers: true excludeLinksFromLockfile: false importers: @@ -9,27 +9,27 @@ importers: .: dependencies: '@lifi/data-types': - specifier: ^5.19.0 - version: 5.19.0 + specifier: ^5.19.1 + version: 5.19.1 '@lifi/sdk': - specifier: ^3.4.4 - version: 3.4.4(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) + specifier: ^3.5.0 + version: 3.5.0(@solana/wallet-adapter-base@0.9.23(@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)))(@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10))(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) '@wagmi/connectors': specifier: ^5.7.3 - version: 5.7.3(@wagmi/core@2.16.3(typescript@5.7.2)(use-sync-external-store@1.2.0)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)))(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) + version: 5.7.3(@wagmi/core@2.16.3(react@18.3.1)(typescript@5.7.2)(use-sync-external-store@1.2.0(react@18.3.1))(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)))(bufferutil@4.0.9)(react@18.3.1)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) '@wagmi/core': specifier: ^2.16.3 - version: 2.16.3(typescript@5.7.2)(use-sync-external-store@1.2.0)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) + version: 2.16.3(react@18.3.1)(typescript@5.7.2)(use-sync-external-store@1.2.0(react@18.3.1))(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) dotenv: specifier: ^16.4.7 version: 16.4.7 viem: - specifier: ^2.22.1 - version: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + specifier: ^2.22.2 + version: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) devDependencies: '@types/node': - specifier: ^22.10.3 - version: 22.10.3 + specifier: ^22.10.5 + version: 22.10.5 tsx: specifier: ^4.19.2 version: 4.19.2 @@ -46,8 +46,10 @@ packages: resolution: {integrity: sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==} engines: {node: '>=6.9.0'} - '@bigmi/core@0.0.7': - resolution: {integrity: sha512-X9YdZRSBcIJkbiklqQZ/5zHeltzskuc9UBnDqQ1ea4Xbh7X/oP60nE46blSfQJwf3YdV1nm78Yi//tPsTVGNFQ==} + '@bigmi/core@0.1.0': + resolution: {integrity: sha512-sTCuWsGnCQ8haZjdEmcSA6PPQKNSwpAO36fPqYJauZPTAvd9ChnuwawMD7HlIkj0+KVdCfDRgKYUdCESqnq+bg==} + peerDependencies: + bs58: ^6.0.0 '@coinbase/wallet-sdk@3.9.3': resolution: {integrity: sha512-N/A2DRIf0Y3PHc1XAMvbBUu4zisna6qAdqABMZwBMNEfWrXpAwx16pZGkYCLGE+Rvv1edbcB2LYDRnACNcmCiw==} @@ -221,12 +223,14 @@ packages: resolution: {integrity: sha512-zQ0IqbdX8FZ9aw11vP+dZkKDkS+kgIvQPHnSAXzP9pLu+Rfu3D3XEeLbicvoXJTYnhZiPmsZUxgdzXwNKxRPbA==} engines: {node: '>=14'} - '@lifi/data-types@5.19.0': - resolution: {integrity: sha512-00bSvQXENsAjTuSfZbVmPxeiBSN7dFMVssNoCLTZV0nOvgJuxjWL8vLMGEasg+zC5wxEBvO43EEkdHQoMI0BHg==} + '@lifi/data-types@5.19.1': + resolution: {integrity: sha512-zR71jEaOBzXtVDULWZFRA+kY9HlEHQxwbzs1fHoH6x+taLSiu3lCESUpsgFHkl1+vxN4ZfthomAjUpt92KJdqQ==} - '@lifi/sdk@3.4.4': - resolution: {integrity: sha512-npXE0PqDlaDbN0RV4oPiwrdnjqOWjm8l6a6NSVsaR9QZ5+bnEoQUIoSFDnAWnkiCPK9lJPbx9sSO28ImAdAXOQ==} + '@lifi/sdk@3.5.0': + resolution: {integrity: sha512-1YWzyPEzFL2Fd5vklt2cXjxu6z66LIlI9PQkkpLqv2wABZRUP+rrqqCQJ1KfZMlJM5OMDr01gL5gycdBwO0cUQ==} peerDependencies: + '@solana/wallet-adapter-base': ^0.9.0 + '@solana/web3.js': ^1.98.0 viem: ^2.21.0 '@lifi/types@16.5.0': @@ -343,6 +347,10 @@ packages: resolution: {integrity: sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==} engines: {node: ^14.21.3 || >=16} + '@noble/curves@1.8.0': + resolution: {integrity: sha512-j84kjAbzEnQHaSIhRPUmB3/eVXu2k3dKPl2LOrR8fSOIL+89U+7lV117EWHtq/GHM3ReGHM46iRBdZfpc4HRUQ==} + engines: {node: ^14.21.3 || >=16} + '@noble/hashes@1.4.0': resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} engines: {node: '>= 16'} @@ -355,6 +363,10 @@ packages: resolution: {integrity: sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==} engines: {node: ^14.21.3 || >=16} + '@noble/hashes@1.7.0': + resolution: {integrity: sha512-HXydb0DgzTpDPwbVeDGCG1gIu7X6+AuU6Zl6av/E/KG8LMsvPntvq+w17CHRpKBmN6Ybdrt1eP3k4cj8DJa78w==} + engines: {node: ^14.21.3 || >=16} + '@paulmillr/qr@0.2.1': resolution: {integrity: sha512-IHnV6A+zxU7XwmKFinmYjUcwlyK9+xkG3/s9KcQhI9BjQKycrJ1JRO+FbNYPwZiPKW3je/DR0k7w8/gLa5eaxQ==} @@ -475,8 +487,8 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} - '@types/node@22.10.3': - resolution: {integrity: sha512-DifAyw4BkrufCILvD3ucnuN8eydUfc/C1GlyrnI+LK6543w5/L3VeVgf05o3B4fqSXP1dKYLOZsKfutpxPzZrw==} + '@types/node@22.10.5': + resolution: {integrity: sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==} '@types/trusted-types@2.0.7': resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==} @@ -1073,6 +1085,9 @@ packages: engines: {node: '>=8'} hasBin: true + js-tokens@4.0.0: + resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} + json-rpc-engine@6.1.0: resolution: {integrity: sha512-NEdLrtrq1jUZyfjkr9OCz9EzCNhnRyWtt1PAnvnhwy6e8XETS0Dtc+ZNCO2gvuAoKsIn2+vCSowXTYE4CkgnAQ==} engines: {node: '>=10.0.0'} @@ -1110,6 +1125,10 @@ packages: lodash.isequal@4.5.0: resolution: {integrity: sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==} + loose-envify@1.4.0: + resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} + hasBin: true + lru-cache@10.4.3: resolution: {integrity: sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==} @@ -1277,6 +1296,10 @@ packages: radix3@1.1.2: resolution: {integrity: sha512-b484I/7b8rDEdSDKckSSBA8knMpcdsXudlE/LNL639wFoHKwLbEkQFZHWEYwDC0wa0FKUcCY+GAF73Z7wxNVFA==} + react@18.3.1: + resolution: {integrity: sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==} + engines: {node: '>=0.10.0'} + readable-stream@2.3.8: resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==} @@ -1542,8 +1565,8 @@ packages: varuint-bitcoin@2.0.0: resolution: {integrity: sha512-6QZbU/rHO2ZQYpWFDALCDSRsXbAs1VOEmXAxtbtjLtKuMJ/FQ8YbhfxlaiKv5nklci0M6lZtlZyxo9Q+qNnyog==} - viem@2.22.1: - resolution: {integrity: sha512-Dlul3ps87ErRSlAVuLQXQjquk0ECy/BCKATEErwHkVd0KQZvj80T5BUU0cDABo4axNF3+78Q060y6VFiT0+SqQ==} + viem@2.22.2: + resolution: {integrity: sha512-HNATy2rwkQcC1JRYBJJujJTtVtDkWlQEB7GvAtn4GBXdbBROnjs8pGXwJAWhb/crErVk5yJ/Fh50yGtA9VZh8A==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -1657,13 +1680,13 @@ snapshots: dependencies: regenerator-runtime: 0.14.1 - '@bigmi/core@0.0.7(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)': + '@bigmi/core@0.1.0(bs58@6.0.0)(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)': dependencies: - '@noble/hashes': 1.6.1 + '@noble/hashes': 1.7.0 bech32: 2.0.0 bitcoinjs-lib: 7.0.0-rc.0(typescript@5.7.2) bs58: 6.0.0 - viem: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + viem: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - typescript @@ -1787,25 +1810,24 @@ snapshots: ethereum-cryptography: 2.2.1 micro-ftch: 0.3.1 - '@lifi/data-types@5.19.0': + '@lifi/data-types@5.19.1': dependencies: '@lifi/types': 16.5.0 - '@lifi/sdk@3.4.4(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': + '@lifi/sdk@3.5.0(@solana/wallet-adapter-base@0.9.23(@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)))(@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10))(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': dependencies: - '@bigmi/core': 0.0.7(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + '@bigmi/core': 0.1.0(bs58@6.0.0)(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) '@lifi/types': 16.5.0 - '@noble/curves': 1.7.0 - '@noble/hashes': 1.6.1 + '@noble/curves': 1.8.0 + '@noble/hashes': 1.7.0 '@solana/wallet-adapter-base': 0.9.23(@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)) '@solana/web3.js': 1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10) bech32: 2.0.0 bitcoinjs-lib: 7.0.0-rc.0(typescript@5.7.2) bs58: 6.0.0 - viem: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + viem: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - - encoding - typescript - utf-8-validate - zod @@ -2029,12 +2051,18 @@ snapshots: dependencies: '@noble/hashes': 1.6.0 + '@noble/curves@1.8.0': + dependencies: + '@noble/hashes': 1.7.0 + '@noble/hashes@1.4.0': {} '@noble/hashes@1.6.0': {} '@noble/hashes@1.6.1': {} + '@noble/hashes@1.7.0': {} + '@paulmillr/qr@0.2.1': {} '@safe-global/safe-apps-provider@0.18.5(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)': @@ -2050,7 +2078,7 @@ snapshots: '@safe-global/safe-apps-sdk@9.1.0(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)': dependencies: '@safe-global/safe-gateway-typescript-sdk': 3.22.4 - viem: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + viem: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - typescript @@ -2107,8 +2135,8 @@ snapshots: '@solana/web3.js@1.98.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.26.0 - '@noble/curves': 1.7.0 - '@noble/hashes': 1.6.1 + '@noble/curves': 1.8.0 + '@noble/hashes': 1.7.0 '@solana/buffer-layout': 4.0.1 agentkeepalive: 4.6.0 bigint-buffer: 1.1.5 @@ -2212,7 +2240,7 @@ snapshots: '@types/connect@3.4.38': dependencies: - '@types/node': 22.10.3 + '@types/node': 22.10.5 '@types/debug@4.1.12': dependencies: @@ -2222,7 +2250,7 @@ snapshots: '@types/node@12.20.55': {} - '@types/node@22.10.3': + '@types/node@22.10.5': dependencies: undici-types: 6.20.0 @@ -2232,22 +2260,22 @@ snapshots: '@types/ws@7.4.7': dependencies: - '@types/node': 22.10.3 + '@types/node': 22.10.5 '@types/ws@8.5.13': dependencies: - '@types/node': 22.10.3 + '@types/node': 22.10.5 - '@wagmi/connectors@5.7.3(@wagmi/core@2.16.3(typescript@5.7.2)(use-sync-external-store@1.2.0)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)))(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': + '@wagmi/connectors@5.7.3(@wagmi/core@2.16.3(react@18.3.1)(typescript@5.7.2)(use-sync-external-store@1.2.0(react@18.3.1))(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)))(bufferutil@4.0.9)(react@18.3.1)(typescript@5.7.2)(utf-8-validate@5.0.10)(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': dependencies: '@coinbase/wallet-sdk': 4.2.3 '@metamask/sdk': 0.31.4(bufferutil@4.0.9)(utf-8-validate@5.0.10) '@safe-global/safe-apps-provider': 0.18.5(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) '@safe-global/safe-apps-sdk': 9.1.0(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) - '@wagmi/core': 2.16.3(typescript@5.7.2)(use-sync-external-store@1.2.0)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) - '@walletconnect/ethereum-provider': 2.17.0(bufferutil@4.0.9)(utf-8-validate@5.0.10) + '@wagmi/core': 2.16.3(react@18.3.1)(typescript@5.7.2)(use-sync-external-store@1.2.0(react@18.3.1))(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10)) + '@walletconnect/ethereum-provider': 2.17.0(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@5.0.10) cbw-sdk: '@coinbase/wallet-sdk@3.9.3' - viem: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + viem: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) optionalDependencies: typescript: 5.7.2 transitivePeerDependencies: @@ -2277,12 +2305,12 @@ snapshots: - utf-8-validate - zod - '@wagmi/core@2.16.3(typescript@5.7.2)(use-sync-external-store@1.2.0)(viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': + '@wagmi/core@2.16.3(react@18.3.1)(typescript@5.7.2)(use-sync-external-store@1.2.0(react@18.3.1))(viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10))': dependencies: eventemitter3: 5.0.1 mipd: 0.0.7(typescript@5.7.2) - viem: 2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) - zustand: 5.0.0(use-sync-external-store@1.2.0) + viem: 2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10) + zustand: 5.0.0(react@18.3.1)(use-sync-external-store@1.2.0(react@18.3.1)) optionalDependencies: typescript: 5.7.2 transitivePeerDependencies: @@ -2341,13 +2369,13 @@ snapshots: dependencies: tslib: 1.14.1 - '@walletconnect/ethereum-provider@2.17.0(bufferutil@4.0.9)(utf-8-validate@5.0.10)': + '@walletconnect/ethereum-provider@2.17.0(bufferutil@4.0.9)(react@18.3.1)(utf-8-validate@5.0.10)': dependencies: '@walletconnect/jsonrpc-http-connection': 1.0.8 '@walletconnect/jsonrpc-provider': 1.0.14 '@walletconnect/jsonrpc-types': 1.0.4 '@walletconnect/jsonrpc-utils': 1.0.8 - '@walletconnect/modal': 2.7.0 + '@walletconnect/modal': 2.7.0(react@18.3.1) '@walletconnect/sign-client': 2.17.0(bufferutil@4.0.9)(utf-8-validate@5.0.10) '@walletconnect/types': 2.17.0 '@walletconnect/universal-provider': 2.17.0(bufferutil@4.0.9)(utf-8-validate@5.0.10) @@ -2454,16 +2482,16 @@ snapshots: '@walletconnect/safe-json': 1.0.2 pino: 7.11.0 - '@walletconnect/modal-core@2.7.0': + '@walletconnect/modal-core@2.7.0(react@18.3.1)': dependencies: - valtio: 1.11.2 + valtio: 1.11.2(react@18.3.1) transitivePeerDependencies: - '@types/react' - react - '@walletconnect/modal-ui@2.7.0': + '@walletconnect/modal-ui@2.7.0(react@18.3.1)': dependencies: - '@walletconnect/modal-core': 2.7.0 + '@walletconnect/modal-core': 2.7.0(react@18.3.1) lit: 2.8.0 motion: 10.16.2 qrcode: 1.5.3 @@ -2471,10 +2499,10 @@ snapshots: - '@types/react' - react - '@walletconnect/modal@2.7.0': + '@walletconnect/modal@2.7.0(react@18.3.1)': dependencies: - '@walletconnect/modal-core': 2.7.0 - '@walletconnect/modal-ui': 2.7.0 + '@walletconnect/modal-core': 2.7.0(react@18.3.1) + '@walletconnect/modal-ui': 2.7.0(react@18.3.1) transitivePeerDependencies: - '@types/react' - react @@ -2703,7 +2731,7 @@ snapshots: bitcoinjs-lib@7.0.0-rc.0(typescript@5.7.2): dependencies: - '@noble/hashes': 1.6.1 + '@noble/hashes': 1.7.0 bech32: 2.0.0 bip174: 3.0.0-rc.1 bs58check: 4.0.0 @@ -2741,7 +2769,7 @@ snapshots: bs58check@4.0.0: dependencies: - '@noble/hashes': 1.6.1 + '@noble/hashes': 1.7.0 bs58: 6.0.0 buffer@6.0.3: @@ -3166,6 +3194,8 @@ snapshots: - bufferutil - utf-8-validate + js-tokens@4.0.0: {} + json-rpc-engine@6.1.0: dependencies: '@metamask/safe-event-emitter': 2.0.0 @@ -3207,6 +3237,10 @@ snapshots: lodash.isequal@4.5.0: {} + loose-envify@1.4.0: + dependencies: + js-tokens: 4.0.0 + lru-cache@10.4.3: {} math-intrinsics@1.1.0: {} @@ -3360,6 +3394,10 @@ snapshots: radix3@1.1.2: {} + react@18.3.1: + dependencies: + loose-envify: 1.4.0 + readable-stream@2.3.8: dependencies: core-util-is: 1.0.3 @@ -3541,7 +3579,9 @@ snapshots: optionalDependencies: idb-keyval: 6.2.1 - use-sync-external-store@1.2.0: {} + use-sync-external-store@1.2.0(react@18.3.1): + dependencies: + react: 18.3.1 utf-8-validate@5.0.10: dependencies: @@ -3565,16 +3605,18 @@ snapshots: optionalDependencies: typescript: 5.7.2 - valtio@1.11.2: + valtio@1.11.2(react@18.3.1): dependencies: proxy-compare: 2.5.1 - use-sync-external-store: 1.2.0 + use-sync-external-store: 1.2.0(react@18.3.1) + optionalDependencies: + react: 18.3.1 varuint-bitcoin@2.0.0: dependencies: uint8array-tools: 0.0.8 - viem@2.22.1(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10): + viem@2.22.2(bufferutil@4.0.9)(typescript@5.7.2)(utf-8-validate@5.0.10): dependencies: '@noble/curves': 1.7.0 '@noble/hashes': 1.6.1 @@ -3665,6 +3707,7 @@ snapshots: y18n: 4.0.3 yargs-parser: 18.1.3 - zustand@5.0.0(use-sync-external-store@1.2.0): + zustand@5.0.0(react@18.3.1)(use-sync-external-store@1.2.0(react@18.3.1)): optionalDependencies: - use-sync-external-store: 1.2.0 + react: 18.3.1 + use-sync-external-store: 1.2.0(react@18.3.1) diff --git a/package.json b/package.json index c2606107..45e163c8 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./src/_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./src/_cjs/package.json", "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./src/_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./src/_esm/package.json", "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./src/_types --emitDeclarationOnly --declaration --declarationMap", - "clean": "rm -rf dist tsconfig.tsbuildinfo tsconfig.build.tsbuildinfo src/tsconfig.build.tsbuildinfo src/_esm src/_cjs src/_types", + "clean": "rm -rf dist src/_esm src/_cjs src/_types", "coverage": "vitest run --coverage", "postinstall": "husky", "prepack": "pinst --disable", @@ -94,14 +94,13 @@ "dependencies": { "@bigmi/core": "^0.1.0", "@lifi/types": "^16.5.0", - "@noble/curves": "^1.7.0", - "@noble/hashes": "^1.6.1", + "@noble/curves": "^1.8.0", "@solana/wallet-adapter-base": "^0.9.23", "@solana/web3.js": "^1.98.0", "bech32": "^2.0.0", "bitcoinjs-lib": "^7.0.0-rc.0", "bs58": "^6.0.0", - "viem": "^2.22.1" + "viem": "^2.22.2" }, "devDependencies": { "@biomejs/biome": "^1.9.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 708efd2f..bbff14a6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,11 +15,8 @@ importers: specifier: ^16.5.0 version: 16.5.0 '@noble/curves': - specifier: ^1.7.0 - version: 1.7.0 - '@noble/hashes': - specifier: ^1.6.1 - version: 1.6.1 + specifier: ^1.8.0 + version: 1.8.0 '@solana/wallet-adapter-base': specifier: ^0.9.23 version: 0.9.23(@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)) @@ -36,8 +33,8 @@ importers: specifier: ^6.0.0 version: 6.0.0 viem: - specifier: ^2.22.1 - version: 2.22.1(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10) + specifier: ^2.22.2 + version: 2.22.2(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10) devDependencies: '@biomejs/biome': specifier: ^1.9.4 @@ -479,6 +476,10 @@ packages: resolution: {integrity: sha512-UTMhXK9SeDhFJVrHeUJ5uZlI6ajXg10O6Ddocf9S6GjbSBVZsJo88HzKwXznNfGpMTRDyJkqMjNDPYgf0qFWnw==} engines: {node: ^14.21.3 || >=16} + '@noble/curves@1.8.0': + resolution: {integrity: sha512-j84kjAbzEnQHaSIhRPUmB3/eVXu2k3dKPl2LOrR8fSOIL+89U+7lV117EWHtq/GHM3ReGHM46iRBdZfpc4HRUQ==} + engines: {node: ^14.21.3 || >=16} + '@noble/hashes@1.6.0': resolution: {integrity: sha512-YUULf0Uk4/mAA89w+k3+yUYh6NrEvxZa5T6SY3wlMvE2chHkxFUUIDI8/XW1QSC357iA5pSnqt7XEhvFOqmDyQ==} engines: {node: ^14.21.3 || >=16} @@ -487,6 +488,10 @@ packages: resolution: {integrity: sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==} engines: {node: ^14.21.3 || >=16} + '@noble/hashes@1.7.0': + resolution: {integrity: sha512-HXydb0DgzTpDPwbVeDGCG1gIu7X6+AuU6Zl6av/E/KG8LMsvPntvq+w17CHRpKBmN6Ybdrt1eP3k4cj8DJa78w==} + engines: {node: ^14.21.3 || >=16} + '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} engines: {node: '>= 8'} @@ -2717,8 +2722,8 @@ packages: varuint-bitcoin@2.0.0: resolution: {integrity: sha512-6QZbU/rHO2ZQYpWFDALCDSRsXbAs1VOEmXAxtbtjLtKuMJ/FQ8YbhfxlaiKv5nklci0M6lZtlZyxo9Q+qNnyog==} - viem@2.22.1: - resolution: {integrity: sha512-Dlul3ps87ErRSlAVuLQXQjquk0ECy/BCKATEErwHkVd0KQZvj80T5BUU0cDABo4axNF3+78Q060y6VFiT0+SqQ==} + viem@2.22.2: + resolution: {integrity: sha512-HNATy2rwkQcC1JRYBJJujJTtVtDkWlQEB7GvAtn4GBXdbBROnjs8pGXwJAWhb/crErVk5yJ/Fh50yGtA9VZh8A==} peerDependencies: typescript: '>=5.0.4' peerDependenciesMeta: @@ -2954,7 +2959,7 @@ snapshots: bech32: 2.0.0 bitcoinjs-lib: 7.0.0-rc.0(typescript@5.7.2) bs58: 6.0.0 - viem: 2.22.1(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10) + viem: 2.22.2(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10) transitivePeerDependencies: - bufferutil - typescript @@ -3273,10 +3278,16 @@ snapshots: dependencies: '@noble/hashes': 1.6.0 + '@noble/curves@1.8.0': + dependencies: + '@noble/hashes': 1.7.0 + '@noble/hashes@1.6.0': {} '@noble/hashes@1.6.1': {} + '@noble/hashes@1.7.0': {} + '@nodelib/fs.scandir@2.1.5': dependencies: '@nodelib/fs.stat': 2.0.5 @@ -3388,7 +3399,7 @@ snapshots: '@solana/web3.js@1.98.0(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: '@babel/runtime': 7.26.0 - '@noble/curves': 1.7.0 + '@noble/curves': 1.8.0 '@noble/hashes': 1.6.1 '@solana/buffer-layout': 4.0.1 agentkeepalive: 4.5.0 @@ -4914,7 +4925,7 @@ snapshots: ox@0.6.0(typescript@5.7.2): dependencies: '@adraffy/ens-normalize': 1.11.0 - '@noble/curves': 1.7.0 + '@noble/curves': 1.8.0 '@noble/hashes': 1.6.1 '@scure/bip32': 1.6.0 '@scure/bip39': 1.5.0 @@ -5539,7 +5550,7 @@ snapshots: dependencies: uint8array-tools: 0.0.8 - viem@2.22.1(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10): + viem@2.22.2(bufferutil@4.0.8)(typescript@5.7.2)(utf-8-validate@5.0.10): dependencies: '@noble/curves': 1.7.0 '@noble/hashes': 1.6.1 @@ -5627,7 +5638,7 @@ snapshots: webauthn-p256@0.0.10: dependencies: - '@noble/curves': 1.7.0 + '@noble/curves': 1.8.0 '@noble/hashes': 1.6.1 webidl-conversions@3.0.1: {} diff --git a/src/core/EVM/EVMStepExecutor.ts b/src/core/EVM/EVMStepExecutor.ts index 3b77bd83..28d65827 100644 --- a/src/core/EVM/EVMStepExecutor.ts +++ b/src/core/EVM/EVMStepExecutor.ts @@ -1,8 +1,4 @@ -import type { - ExtendedTransactionInfo, - FullStatusData, - Process, -} from '@lifi/types' +import type { Process } from '@lifi/types' import type { Client, GetAddressesReturnType, @@ -15,18 +11,16 @@ import { config } from '../../config.js' import { LiFiErrorCode } from '../../errors/constants.js' import { TransactionError, ValidationError } from '../../errors/errors.js' import { getStepTransaction } from '../../services/api.js' -import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js' import { isZeroAddress } from '../../utils/isZeroAddress.js' import { BaseStepExecutor } from '../BaseStepExecutor.js' import { checkBalance } from '../checkBalance.js' -import { getSubstatusMessage } from '../processMessages.js' import { stepComparison } from '../stepComparison.js' import type { LiFiStepExtended, StepExecutorOptions, TransactionParameters, } from '../types.js' -import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js' +import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js' import { checkAllowance } from './checkAllowance.js' import { updateMultisigRouteProcess } from './multisig.js' import { parseEVMErrors } from './parseEVMErrors.js' @@ -109,16 +103,16 @@ export class EVMStepExecutor extends BaseStepExecutor { executeStep = async (step: LiFiStepExtended): Promise => { step.execution = this.statusManager.initExecutionObject(step) - // Find if it's bridging and the step is waiting for a transaction on the receiving chain - const recievingChainProcess = step.execution?.process.find( + // Find if it's bridging and the step is waiting for a transaction on the destination chain + const destinationChainProcess = step.execution?.process.find( (process) => process.type === 'RECEIVING_CHAIN' ) // Make sure that the chain is still correct - // If the step is waiting for a transaction on the receiving chain, we do not switch the chain + // If the step is waiting for a transaction on the destination chain, we do not switch the chain // All changes are already done from the source chain // Return the step - if (recievingChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION') { + if (destinationChainProcess?.substatus !== 'WAIT_DESTINATION_TRANSACTION') { const updatedClient = await this.checkClient(step) if (!updatedClient) { return step @@ -138,7 +132,7 @@ export class EVMStepExecutor extends BaseStepExecutor { const isBridgeExecution = fromChain.id !== toChain.id const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP' - // STEP 1: Check allowance + // Check allowance const existingProcess = step.execution.process.find( (p) => p.type === currentProcessType ) @@ -171,7 +165,6 @@ export class EVMStepExecutor extends BaseStepExecutor { } } - // STEP 2: Get transaction let process = this.statusManager.findOrCreateProcess({ step, type: currentProcessType, @@ -245,7 +238,6 @@ export class EVMStepExecutor extends BaseStepExecutor { ) } - // STEP 3: Send the transaction // Make sure that the chain is still correct const updatedClient = await this.checkClient(step, process) if (!updatedClient) { @@ -335,7 +327,6 @@ export class EVMStepExecutor extends BaseStepExecutor { } as SendTransactionParameters) } - // STEP 4: Wait for the transaction if (isMultisigClient) { process = this.statusManager.updateProcess( step, @@ -423,8 +414,7 @@ export class EVMStepExecutor extends BaseStepExecutor { } } - // STEP 5: Wait for the receiving chain - const processTxHash = process.txHash + // Wait for the transaction status on the destination chain if (isBridgeExecution) { process = this.statusManager.findOrCreateProcess({ step, @@ -433,63 +423,13 @@ export class EVMStepExecutor extends BaseStepExecutor { chainId: toChain.id, }) } - let statusResponse: FullStatusData - - try { - if (!processTxHash) { - throw new Error('Transaction hash is undefined.') - } - statusResponse = (await waitForReceivingTransaction( - processTxHash, - this.statusManager, - process.type, - step - )) as FullStatusData - - const statusReceiving = - statusResponse.receiving as ExtendedTransactionInfo - - process = this.statusManager.updateProcess(step, process.type, 'DONE', { - substatus: statusResponse.substatus, - substatusMessage: - statusResponse.substatusMessage || - getSubstatusMessage(statusResponse.status, statusResponse.substatus), - txHash: statusReceiving?.txHash, - txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`, - }) - this.statusManager.updateExecution(step, 'DONE', { - fromAmount: statusResponse.sending.amount, - toAmount: statusReceiving?.amount, - toToken: statusReceiving?.token, - gasCosts: [ - { - amount: statusResponse.sending.gasAmount, - amountUSD: statusResponse.sending.gasAmountUSD, - token: statusResponse.sending.gasToken, - estimate: statusResponse.sending.gasUsed, - limit: statusResponse.sending.gasUsed, - price: statusResponse.sending.gasPrice, - type: 'SEND', - }, - ], - }) - } catch (e: unknown) { - const htmlMessage = await getTransactionFailedMessage( - step, - process.txLink - ) - - process = this.statusManager.updateProcess(step, process.type, 'FAILED', { - error: { - code: LiFiErrorCode.TransactionFailed, - message: 'Failed while waiting for receiving chain.', - htmlMessage, - }, - }) - this.statusManager.updateExecution(step, 'FAILED') - throw await parseEVMErrors(e as Error, step, process) - } + await waitForDestinationChainTransaction( + step, + process, + this.statusManager, + toChain + ) // DONE return step diff --git a/src/core/Solana/SolanaStepExecutor.ts b/src/core/Solana/SolanaStepExecutor.ts index d06c8a76..fb98b705 100644 --- a/src/core/Solana/SolanaStepExecutor.ts +++ b/src/core/Solana/SolanaStepExecutor.ts @@ -1,4 +1,4 @@ -import type { ExtendedTransactionInfo, FullStatusData } from '@lifi/types' +import type {} from '@lifi/types' import type { SignerWalletAdapter } from '@solana/wallet-adapter-base' import { VersionedTransaction } from '@solana/web3.js' import { withTimeout } from 'viem' @@ -7,17 +7,15 @@ import { LiFiErrorCode } from '../../errors/constants.js' import { TransactionError } from '../../errors/errors.js' import { getStepTransaction } from '../../services/api.js' import { base64ToUint8Array } from '../../utils/base64ToUint8Array.js' -import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js' import { BaseStepExecutor } from '../BaseStepExecutor.js' import { checkBalance } from '../checkBalance.js' -import { getSubstatusMessage } from '../processMessages.js' import { stepComparison } from '../stepComparison.js' import type { LiFiStepExtended, StepExecutorOptions, TransactionParameters, } from '../types.js' -import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js' +import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js' import { callSolanaWithRetry } from './connection.js' import { parseSolanaErrors } from './parseSolanaErrors.js' import { sendAndConfirmTransaction } from './sendAndConfirmTransaction.js' @@ -53,7 +51,6 @@ export class SolanaStepExecutor extends BaseStepExecutor { const isBridgeExecution = fromChain.id !== toChain.id const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP' - // STEP 2: Get transaction let process = this.statusManager.findOrCreateProcess({ step, type: currentProcessType, @@ -220,8 +217,7 @@ export class SolanaStepExecutor extends BaseStepExecutor { } } - // STEP 5: Wait for the receiving chain - const processTxHash = process.txHash + // Wait for the transaction status on the destination chain if (isBridgeExecution) { process = this.statusManager.findOrCreateProcess({ step, @@ -230,63 +226,13 @@ export class SolanaStepExecutor extends BaseStepExecutor { chainId: toChain.id, }) } - let statusResponse: FullStatusData - try { - if (!processTxHash) { - throw new Error('Transaction hash is undefined.') - } - statusResponse = (await waitForReceivingTransaction( - processTxHash, - this.statusManager, - process.type, - step - )) as FullStatusData - - const statusReceiving = - statusResponse.receiving as ExtendedTransactionInfo - - process = this.statusManager.updateProcess(step, process.type, 'DONE', { - substatus: statusResponse.substatus, - substatusMessage: - statusResponse.substatusMessage || - getSubstatusMessage(statusResponse.status, statusResponse.substatus), - txHash: statusReceiving?.txHash, - txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`, - }) - - this.statusManager.updateExecution(step, 'DONE', { - fromAmount: statusResponse.sending.amount, - toAmount: statusReceiving?.amount, - toToken: statusReceiving?.token, - gasCosts: [ - { - amount: statusResponse.sending.gasAmount, - amountUSD: statusResponse.sending.gasAmountUSD, - token: statusResponse.sending.gasToken, - estimate: statusResponse.sending.gasUsed, - limit: statusResponse.sending.gasUsed, - price: statusResponse.sending.gasPrice, - type: 'SEND', - }, - ], - }) - } catch (e: unknown) { - const htmlMessage = await getTransactionFailedMessage( - step, - process.txLink - ) - process = this.statusManager.updateProcess(step, process.type, 'FAILED', { - error: { - code: LiFiErrorCode.TransactionFailed, - message: 'Failed while waiting for receiving chain.', - htmlMessage, - }, - }) - this.statusManager.updateExecution(step, 'FAILED') - console.warn(e) - throw e - } + await waitForDestinationChainTransaction( + step, + process, + this.statusManager, + toChain + ) // DONE return step diff --git a/src/core/UTXO/UTXOStepExecutor.ts b/src/core/UTXO/UTXOStepExecutor.ts index 86f62405..b7f4253a 100644 --- a/src/core/UTXO/UTXOStepExecutor.ts +++ b/src/core/UTXO/UTXOStepExecutor.ts @@ -1,27 +1,21 @@ import { signPsbt, waitForTransaction } from '@bigmi/core' import type { ReplacementReason } from '@bigmi/core' -import { - ChainId, - type ExtendedTransactionInfo, - type FullStatusData, -} from '@lifi/types' +import { ChainId } from '@lifi/types' import { Psbt, address, networks } from 'bitcoinjs-lib' import { type Client, withTimeout } from 'viem' import { config } from '../../config.js' import { LiFiErrorCode } from '../../errors/constants.js' import { TransactionError } from '../../errors/errors.js' import { getStepTransaction } from '../../services/api.js' -import { getTransactionFailedMessage } from '../../utils/getTransactionMessage.js' import { BaseStepExecutor } from '../BaseStepExecutor.js' import { checkBalance } from '../checkBalance.js' -import { getSubstatusMessage } from '../processMessages.js' import { stepComparison } from '../stepComparison.js' import type { LiFiStepExtended, StepExecutorOptions, TransactionParameters, } from '../types.js' -import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js' +import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js' import { getUTXOPublicClient } from './getUTXOPublicClient.js' import { parseUTXOErrors } from './parseUTXOErrors.js' @@ -57,7 +51,6 @@ export class UTXOStepExecutor extends BaseStepExecutor { const isBridgeExecution = fromChain.id !== toChain.id const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP' - // STEP 2: Get transaction let process = this.statusManager.findOrCreateProcess({ step, type: currentProcessType, @@ -270,8 +263,7 @@ export class UTXOStepExecutor extends BaseStepExecutor { } } - // STEP 5: Wait for the receiving chain - const processTxHash = process.txHash + // Wait for the transaction status on the destination chain if (isBridgeExecution) { process = this.statusManager.findOrCreateProcess({ step, @@ -280,64 +272,14 @@ export class UTXOStepExecutor extends BaseStepExecutor { chainId: toChain.id, }) } - let statusResponse: FullStatusData - try { - if (!processTxHash) { - throw new Error('Transaction hash is undefined.') - } - statusResponse = (await waitForReceivingTransaction( - processTxHash, - this.statusManager, - process.type, - step, - 10_000 - )) as FullStatusData - - const statusReceiving = - statusResponse.receiving as ExtendedTransactionInfo - - process = this.statusManager.updateProcess(step, process.type, 'DONE', { - substatus: statusResponse.substatus, - substatusMessage: - statusResponse.substatusMessage || - getSubstatusMessage(statusResponse.status, statusResponse.substatus), - txHash: statusReceiving?.txHash, - txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`, - }) - - this.statusManager.updateExecution(step, 'DONE', { - fromAmount: statusResponse.sending.amount, - toAmount: statusReceiving?.amount, - toToken: statusReceiving?.token, - gasCosts: [ - { - amount: statusResponse.sending.gasAmount, - amountUSD: statusResponse.sending.gasAmountUSD, - token: statusResponse.sending.gasToken, - estimate: statusResponse.sending.gasUsed, - limit: statusResponse.sending.gasUsed, - price: statusResponse.sending.gasPrice, - type: 'SEND', - }, - ], - }) - } catch (e: unknown) { - const htmlMessage = await getTransactionFailedMessage( - step, - process.txLink - ) - process = this.statusManager.updateProcess(step, process.type, 'FAILED', { - error: { - code: LiFiErrorCode.TransactionFailed, - message: 'Failed while waiting for receiving chain.', - htmlMessage, - }, - }) - this.statusManager.updateExecution(step, 'FAILED') - console.warn(e) - throw e - } + await waitForDestinationChainTransaction( + step, + process, + this.statusManager, + toChain, + 10_000 + ) // DONE return step diff --git a/src/core/waitForDestinationChainTransaction.ts b/src/core/waitForDestinationChainTransaction.ts new file mode 100644 index 00000000..a445a17a --- /dev/null +++ b/src/core/waitForDestinationChainTransaction.ts @@ -0,0 +1,79 @@ +import type { + ExtendedChain, + ExtendedTransactionInfo, + FullStatusData, + Process, +} from '@lifi/types' +import { LiFiErrorCode } from '../errors/constants.js' +import { getTransactionFailedMessage } from '../utils/getTransactionMessage.js' +import type { StatusManager } from './StatusManager.js' +import type { LiFiStepExtended } from './types.js' +import { waitForTransactionStatus } from './waitForTransactionStatus.js' + +export async function waitForDestinationChainTransaction( + step: LiFiStepExtended, + process: Process, + statusManager: StatusManager, + toChain: ExtendedChain, + pollingInterval?: number +): Promise { + if (!process.txHash) { + throw new Error('Transaction hash is undefined.') + } + + try { + const statusResponse = (await waitForTransactionStatus( + process.txHash, + statusManager, + process.type, + step, + pollingInterval + )) as FullStatusData + + const statusReceiving = statusResponse.receiving as ExtendedTransactionInfo + + // Update process status + statusManager.updateProcess(step, process.type, 'DONE', { + substatus: statusResponse.substatus, + substatusMessage: statusResponse.substatusMessage, + txHash: statusReceiving?.txHash, + txLink: `${toChain.metamask.blockExplorerUrls[0]}tx/${statusReceiving?.txHash}`, + }) + + // Update execution status + statusManager.updateExecution(step, 'DONE', { + ...(statusResponse.sending.amount && { + fromAmount: statusResponse.sending.amount, + }), + ...(statusReceiving?.amount && { toAmount: statusReceiving.amount }), + ...(statusReceiving?.token && { toToken: statusReceiving.token }), + gasCosts: [ + { + amount: statusResponse.sending.gasAmount, + amountUSD: statusResponse.sending.gasAmountUSD, + token: statusResponse.sending.gasToken, + estimate: statusResponse.sending.gasUsed, + limit: statusResponse.sending.gasUsed, + price: statusResponse.sending.gasPrice, + type: 'SEND', + }, + ], + }) + + return step + } catch (e: unknown) { + const htmlMessage = await getTransactionFailedMessage(step, process.txLink) + + statusManager.updateProcess(step, process.type, 'FAILED', { + error: { + code: LiFiErrorCode.TransactionFailed, + message: + 'Failed while waiting for status of destination chain transaction.', + htmlMessage, + }, + }) + + statusManager.updateExecution(step, 'FAILED') + throw e + } +} diff --git a/src/core/waitForReceivingTransaction.ts b/src/core/waitForTransactionStatus.ts similarity index 97% rename from src/core/waitForReceivingTransaction.ts rename to src/core/waitForTransactionStatus.ts index 83b87a03..a3c4eac6 100644 --- a/src/core/waitForReceivingTransaction.ts +++ b/src/core/waitForTransactionStatus.ts @@ -12,7 +12,7 @@ import { getSubstatusMessage } from './processMessages.js' const TRANSACTION_HASH_OBSERVERS: Record> = {} -export async function waitForReceivingTransaction( +export async function waitForTransactionStatus( txHash: string, statusManager: StatusManager, processType: ProcessType, diff --git a/tsconfig.build.json b/tsconfig.build.json index 322f5a0e..8f739efb 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,10 +2,16 @@ // This file is used to compile the for cjs and esm (see package.json build scripts). It should exclude all test files. "extends": "./tsconfig.base.json", "include": ["src"], - "exclude": ["tests", "./src/**/*.spec.ts", "./src/**/*.mock.ts", "./src/**/*.handlers.ts"], + "exclude": [ + "tests", + "./src/**/*.spec.ts", + "./src/**/*.mock.ts", + "./src/**/*.handlers.ts" + ], "compilerOptions": { + "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.build.tsbuildinfo", "moduleResolution": "node", "sourceMap": true, - "rootDir": "./src", + "rootDir": "./src" } } From 0d94041e4c171d5ebc1d2a7a4691be8f129922a3 Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Fri, 3 Jan 2025 14:52:10 +0100 Subject: [PATCH 2/2] chore(release): 3.5.1-beta.0 --- package.json | 2 +- src/version.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 45e163c8..4fdb44f2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lifi/sdk", - "version": "3.5.0", + "version": "3.5.1-beta.0", "description": "LI.FI Any-to-Any Cross-Chain-Swap SDK", "keywords": [ "bridge", diff --git a/src/version.ts b/src/version.ts index 25e6c864..dcbe239b 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ export const name = '@lifi/sdk' -export const version = '3.5.0' +export const version = '3.5.1-beta.0'