From ec042d0c91f451b362c94487e956097901ad40d8 Mon Sep 17 00:00:00 2001 From: M-Picco Date: Fri, 8 Sep 2023 18:16:33 -0300 Subject: [PATCH] Move getForeignAsset gateway logic from the CosmosGateway route to the cosmos context. Remove some sdk unneeded dependencies --- package-lock.json | 310 ++++++------------ sdk/package.json | 4 +- sdk/src/contexts/cosmos/context.ts | 159 +++++++-- sdk/src/contexts/cosmos/utils.ts | 17 + wormhole-connect/package.json | 1 + .../src/components/TokensModal.tsx | 31 +- wormhole-connect/src/utils/cosmos.ts | 18 +- .../src/utils/routes/cosmosGateway.ts | 65 +--- 8 files changed, 276 insertions(+), 329 deletions(-) diff --git a/package-lock.json b/package-lock.json index ea20d7391..67ef7b93c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -92,6 +92,7 @@ "version": "3.8.1", "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.8.1.tgz", "integrity": "sha512-JGGj/9bdoLEqzatRikDeN8etseY5qeFAY0vSAx/Pd0ePNsaflKzHx6V2NZ0NsGkInq+9IXXX3RLVDf0EotizMA==", + "optional": true, "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", "@wry/context": "^0.7.3", @@ -3918,6 +3919,7 @@ "version": "3.2.0", "resolved": "https://registry.npmjs.org/@graphql-typed-document-node/core/-/core-3.2.0.tgz", "integrity": "sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==", + "optional": true, "peerDependencies": { "graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0" } @@ -3980,6 +3982,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/exceptions/-/exceptions-1.12.1.tgz", "integrity": "sha512-aYmKgw8JzO3GoWFPrPurMOaPokmdh2/v2DW23mb3a51L40NZl5yDUaRilmzCWg+xtwmpWaWANBCgvcEpqtqxNw==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/grpc-web": "^0.0.1", "@injectivelabs/ts-types": "^1.12.1", @@ -3992,6 +3995,7 @@ "version": "0.0.1", "resolved": "https://registry.npmjs.org/@injectivelabs/grpc-web/-/grpc-web-0.0.1.tgz", "integrity": "sha512-Pu5YgaZp+OvR5UWfqbrPdHer3+gDf+b5fQoY+t2VZx1IAVHX8bzbN9EreYTvTYtFeDpYRWM8P7app2u4EX5wTw==", + "optional": true, "dependencies": { "browser-headers": "^0.4.1" }, @@ -4046,6 +4050,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/networks/-/networks-1.10.12.tgz", "integrity": "sha512-tTHyLls1Nik5QTs/S03qqG2y/ITvNwI8CJOQbMmmsr1CL2CdjJBtzRYn9Dyx2p8XgzRFf9hmlybpe20tq9O3SA==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/exceptions": "^1.10.12", "@injectivelabs/ts-types": "^1.10.12", @@ -4340,6 +4345,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/token-metadata/-/token-metadata-1.12.1.tgz", "integrity": "sha512-i5pJ3M2alxL9jM1RWgkVGwPcvkUmJCNxwfA7rZ8+PPNUwmPzckwuHy+6EYMLpuXy10ft6eskoDwd4/1CRgamFg==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/exceptions": "^1.12.1", "@injectivelabs/networks": "^1.12.1", @@ -4359,6 +4365,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/networks/-/networks-1.12.1.tgz", "integrity": "sha512-X1njEOynG6CPRfQe1k/bvPSuCGCICRu98oIgNpRh4/qx4N168hPaWx0Te3d9WXx2bgkelGrk8x/VFS4NdWrIYg==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/exceptions": "^1.12.1", "@injectivelabs/ts-types": "^1.12.1", @@ -4372,6 +4379,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/utils/-/utils-1.12.1.tgz", "integrity": "sha512-BAug0w+WipBDLv5FO3ANTSmL3dNd61T0P6bp9mW5gZ0VKs4Jc5Uybv7lE5IUOWR2+nk8I90O45qpF4DbP/BnEg==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/exceptions": "^1.12.1", "@injectivelabs/ts-types": "^1.12.1", @@ -4388,6 +4396,7 @@ "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "optional": true, "dependencies": { "follow-redirects": "^1.14.0" } @@ -4397,6 +4406,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/ts-types/-/ts-types-1.12.1.tgz", "integrity": "sha512-Bj/GtZLG8VPfANckzPHA8YWgdoq9acX6eOyqNTs9f1R+wA18SYjqoihS8zEexRfUzgxZSPaYEXCSMaawEZTIQQ==", "hasInstallScript": true, + "optional": true, "dependencies": { "link-module-alias": "^1.2.0", "shx": "^0.3.2" @@ -4407,6 +4417,7 @@ "resolved": "https://registry.npmjs.org/@injectivelabs/utils/-/utils-1.10.12.tgz", "integrity": "sha512-c8al79nxIJgV1cBAdW2TPDGldj/8gm5k0h5TIN/AJs8/AeIjpTwwVGfLY3QvPOpRsxuQ9CjBkTXrAcSL1wwkcw==", "hasInstallScript": true, + "optional": true, "dependencies": { "@injectivelabs/exceptions": "^1.10.12", "@injectivelabs/ts-types": "^1.10.12", @@ -4423,6 +4434,7 @@ "version": "0.21.4", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "optional": true, "dependencies": { "follow-redirects": "^1.14.0" } @@ -5621,6 +5633,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-4.0.1.tgz", "integrity": "sha512-tghyZKLHZjcdlDqCA3gNZmLeR0XvOE9U1qoQO9ohyAZT6Pya+H9vkBPcsyXytmYLNgVoin7CKCmweo/R43V+tQ==", + "optional": true, "dependencies": { "ethereumjs-abi": "^0.6.8", "ethereumjs-util": "^6.2.1", @@ -5636,6 +5649,7 @@ "version": "4.11.6", "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-4.11.6.tgz", "integrity": "sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg==", + "optional": true, "dependencies": { "@types/node": "*" } @@ -5643,12 +5657,14 @@ "node_modules/@metamask/eth-sig-util/node_modules/bn.js": { "version": "4.12.0", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.12.0.tgz", - "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==" + "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", + "optional": true }, "node_modules/@metamask/eth-sig-util/node_modules/ethereum-cryptography": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", + "optional": true, "dependencies": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -5671,6 +5687,7 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz", "integrity": "sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw==", + "optional": true, "dependencies": { "@types/bn.js": "^4.11.3", "bn.js": "^4.11.0", @@ -8848,52 +8865,6 @@ "pbts": "bin/pbts" } }, - "node_modules/@terra-money/terra.js": { - "version": "3.1.10", - "resolved": "https://registry.npmjs.org/@terra-money/terra.js/-/terra.js-3.1.10.tgz", - "integrity": "sha512-MqR16LjTUyVD4HnEavP1iBW0c1roCoRHH/E1x9P44pXzgtv2wsMeP+2un4Bnck4Nkv/46Xvy/BSKiY90ll3BKA==", - "dependencies": { - "@classic-terra/terra.proto": "^1.1.0", - "@terra-money/terra.proto": "^2.1.0", - "axios": "^0.27.2", - "bech32": "^2.0.0", - "bip32": "^2.0.6", - "bip39": "^3.0.3", - "bufferutil": "^4.0.3", - "decimal.js": "^10.2.1", - "jscrypto": "^1.0.1", - "readable-stream": "^3.6.0", - "secp256k1": "^4.0.2", - "tmp": "^0.2.1", - "utf-8-validate": "^5.0.5", - "ws": "^7.5.9" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/@terra-money/terra.js/node_modules/axios": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.27.2.tgz", - "integrity": "sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==", - "dependencies": { - "follow-redirects": "^1.14.9", - "form-data": "^4.0.0" - } - }, - "node_modules/@terra-money/terra.js/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/@terra-money/terra.proto": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@terra-money/terra.proto/-/terra.proto-2.1.0.tgz", @@ -9709,12 +9680,14 @@ "node_modules/@types/lodash": { "version": "4.14.197", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.197.tgz", - "integrity": "sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==" + "integrity": "sha512-BMVOiWs0uNxHVlHBgzTIqJYmj+PgCo4euloGF+5m4okL3rEYzM2EEv78mw8zWSMM57dM7kVIgJ2QDvwHSoCI5g==", + "optional": true }, "node_modules/@types/lodash.values": { "version": "4.3.7", "resolved": "https://registry.npmjs.org/@types/lodash.values/-/lodash.values-4.3.7.tgz", "integrity": "sha512-Moex9/sWxtKEa+BKiH5zvmhfcieDlcz4wRxMhO/oJ2qOKUdujoU6dQjUTxWA8jwEREpHXmiY4HCwNRpycW8JQA==", + "optional": true, "dependencies": { "@types/lodash": "*" } @@ -12067,6 +12040,7 @@ "version": "0.7.3", "resolved": "https://registry.npmjs.org/@wry/context/-/context-0.7.3.tgz", "integrity": "sha512-Nl8WTesHp89RF803Se9X3IiHjdmLBrIvPMaJkl+rKVJAYyPsz1TEUbu89943HpvujtSJgDUx9W4vZw3K1Mr3sA==", + "optional": true, "dependencies": { "tslib": "^2.3.0" }, @@ -12078,6 +12052,7 @@ "version": "0.5.6", "resolved": "https://registry.npmjs.org/@wry/equality/-/equality-0.5.6.tgz", "integrity": "sha512-D46sfMTngaYlrH+OspKf8mIJETntFnf6Hsjb0V41jAXJ7Bx2kB8Rv8RCUujuVWYttFtHkUNp7g+FwxNQAr6mXA==", + "optional": true, "dependencies": { "tslib": "^2.3.0" }, @@ -12089,6 +12064,7 @@ "version": "0.4.3", "resolved": "https://registry.npmjs.org/@wry/trie/-/trie-0.4.3.tgz", "integrity": "sha512-I6bHwH0fSf6RqQcnnXLJKhkSXG45MFral3GxPaY4uAl0LYDZM+YDVDAiU9bYwjTuysy1S0IeecWtmq1SZA3M1w==", + "optional": true, "dependencies": { "tslib": "^2.3.0" }, @@ -14629,6 +14605,7 @@ "version": "2.4.1", "resolved": "https://registry.npmjs.org/copyfiles/-/copyfiles-2.4.1.tgz", "integrity": "sha512-fereAvAvxDrQDOXybk3Qu3dPbOoKoysFMWtkY3mv5BsL8//OSZVL5DCLYqgRfY5cWirgRzlC+WSrxp6Bo3eNZg==", + "optional": true, "dependencies": { "glob": "^7.0.5", "minimatch": "^3.0.3", @@ -16025,6 +16002,7 @@ "resolved": "https://registry.npmjs.org/eccrypto/-/eccrypto-1.1.6.tgz", "integrity": "sha512-d78ivVEzu7Tn0ZphUUaL43+jVPKTMPFGtmgtz1D0LrFn7cY3K8CdrvibuLz2AAkHBLKZtR8DMbB2ukRYFk987A==", "hasInstallScript": true, + "optional": true, "dependencies": { "acorn": "7.1.1", "elliptic": "6.5.4", @@ -16039,6 +16017,7 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", "integrity": "sha512-add7dgA5ppRPxCFJoAGfMDi7PIBXq1RtGo7BhbLaxwrXPOmw8gq48Y9ozT01hUKy9byMjlR20EJhu5zlkErEkg==", + "optional": true, "bin": { "acorn": "bin/acorn" }, @@ -17314,6 +17293,7 @@ "version": "2.6.0", "resolved": "https://registry.npmjs.org/eth-crypto/-/eth-crypto-2.6.0.tgz", "integrity": "sha512-GCX4ffFYRUGgnuWR5qxcZIRQJ1KEqPFiyXU9yVy7s6dtXIMlUXZQ2h+5ID6rFaOHWbpJbjfkC6YdhwtwRYCnug==", + "optional": true, "dependencies": { "@babel/runtime": "7.20.13", "@ethereumjs/tx": "3.5.2", @@ -17331,6 +17311,7 @@ "version": "7.20.13", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.20.13.tgz", "integrity": "sha512-gt3PKXs0DBoL9xCvOIIZ2NEqAGZqHjAnmVbfQtB620V0uReIQutpel14KcneZuer7UioY8ALKZ7iocavvzTNFA==", + "optional": true, "dependencies": { "regenerator-runtime": "^0.13.11" }, @@ -17341,18 +17322,21 @@ "node_modules/eth-crypto/node_modules/node-addon-api": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-5.1.0.tgz", - "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==" + "integrity": "sha512-eh0GgfEkpnoWDq+VY8OyvYhFEzBk6jIYbRKdIlyTiAXIVJ8PyBaKb0rp7oDtoddbdoHWhq8wwr+XZ81F1rpNdA==", + "optional": true }, "node_modules/eth-crypto/node_modules/regenerator-runtime": { "version": "0.13.11", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", - "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "optional": true }, "node_modules/eth-crypto/node_modules/secp256k1": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-5.0.0.tgz", "integrity": "sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA==", "hasInstallScript": true, + "optional": true, "dependencies": { "elliptic": "^6.5.4", "node-addon-api": "^5.0.0", @@ -19387,6 +19371,7 @@ "version": "16.8.0", "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.8.0.tgz", "integrity": "sha512-0oKGaR+y3qcS5mCu1vb7KG+a89vjn06C7Ihq/dDl3jA+A8B3TKomvi3CiEcVLJQGalbu8F52LxkOym7U5sSfbg==", + "optional": true, "engines": { "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" } @@ -19395,6 +19380,7 @@ "version": "2.12.6", "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==", + "optional": true, "dependencies": { "tslib": "^2.1.0" }, @@ -19846,7 +19832,8 @@ "node_modules/http-status-codes": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/http-status-codes/-/http-status-codes-2.2.0.tgz", - "integrity": "sha512-feERVo9iWxvnejp3SEfm/+oNG517npqL2/PIA8ORjyOZjGC7TwCRQsZylciLS64i6pJ0wRYz3rkXLRwbtFa8Ng==" + "integrity": "sha512-feERVo9iWxvnejp3SEfm/+oNG517npqL2/PIA8ORjyOZjGC7TwCRQsZylciLS64i6pJ0wRYz3rkXLRwbtFa8Ng==", + "optional": true }, "node_modules/http2-wrapper": { "version": "2.2.0", @@ -20097,6 +20084,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "optional": true, "engines": { "node": ">= 0.10" } @@ -23926,6 +23914,7 @@ "version": "1.4.1", "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.4.1.tgz", "integrity": "sha512-S6cATIPVv1z0IlxdN+zUk5EPjkGCdnhN4wVSBlvoUO1tOLJootbo9CquNJmbIh4yikWHiUedhRYrNPn1arpEmQ==", + "optional": true, "engines": { "node": "*" } @@ -23996,6 +23985,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/keccak256/-/keccak256-1.0.6.tgz", "integrity": "sha512-8GLiM01PkdJVGUhR1e6M/AvWnSqYS0HaERI+K/QtStGDGlSTx2B1zTqZk4Zlqu5TxHJNTxWAdP9Y+WI50OApUw==", + "optional": true, "dependencies": { "bn.js": "^5.2.0", "buffer": "^6.0.3", @@ -24237,6 +24227,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/link-module-alias/-/link-module-alias-1.2.0.tgz", "integrity": "sha512-ahPjXepbSVKbahTB6LxR//VHm8HPfI+QQygCH+E82spBY4HR5VPJTvlhKBc9F7muVxnS6C1rRfoPOXAbWO/fyw==", + "optional": true, "dependencies": { "chalk": "^2.4.1" }, @@ -24251,6 +24242,7 @@ "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "optional": true, "dependencies": { "color-convert": "^1.9.0" }, @@ -24262,6 +24254,7 @@ "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "optional": true, "dependencies": { "ansi-styles": "^3.2.1", "escape-string-regexp": "^1.0.5", @@ -24275,6 +24268,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "optional": true, "engines": { "node": ">=0.8.0" } @@ -24443,7 +24437,8 @@ "node_modules/lodash.values": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.values/-/lodash.values-4.3.0.tgz", - "integrity": "sha512-r0RwvdCv8id9TUblb/O7rYPwVy6lerCbcawrfdo9iC/1t1wsNMJknO79WNBgwkH0hIeJ08jmvvESbFpNb4jH0Q==" + "integrity": "sha512-r0RwvdCv8id9TUblb/O7rYPwVy6lerCbcawrfdo9iC/1t1wsNMJknO79WNBgwkH0hIeJ08jmvvESbFpNb4jH0Q==", + "optional": true }, "node_modules/log-update": { "version": "5.0.1", @@ -24607,6 +24602,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/map-obj/-/map-obj-4.3.0.tgz", "integrity": "sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==", + "optional": true, "engines": { "node": ">=8" }, @@ -25350,6 +25346,7 @@ "version": "0.0.0", "resolved": "https://registry.npmjs.org/noms/-/noms-0.0.0.tgz", "integrity": "sha512-lNDU9VJaOPxUmXcLb+HQFeUgQQPtMI24Gt6hgfuMHRJgMRHMF/qZ4HJD3GDru4sSw9IQl2jPjAYnQrdIeLbwow==", + "optional": true, "dependencies": { "inherits": "^2.0.1", "readable-stream": "~1.0.31" @@ -25358,12 +25355,14 @@ "node_modules/noms/node_modules/isarray": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==" + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", + "optional": true }, "node_modules/noms/node_modules/readable-stream": { "version": "1.0.34", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", "integrity": "sha512-ok1qVCJuRkNmvebYikljxJA/UEsKwLl2nI1OmaqAu4/UE+h0wKCHok4XkL/gvi39OacXvw59RJUOFUkDib2rHg==", + "optional": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.1", @@ -25374,7 +25373,8 @@ "node_modules/noms/node_modules/string_decoder": { "version": "0.10.31", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==" + "integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==", + "optional": true }, "node_modules/normalize-path": { "version": "3.0.0", @@ -25715,6 +25715,7 @@ "version": "0.17.5", "resolved": "https://registry.npmjs.org/optimism/-/optimism-0.17.5.tgz", "integrity": "sha512-TEcp8ZwK1RczmvMnvktxHSF2tKgMWjJ71xEFGX5ApLh67VsMSTy1ZUlipJw8W+KaqgOmQ+4pqwkeivY89j+4Vw==", + "optional": true, "dependencies": { "@wry/context": "^0.7.0", "@wry/trie": "^0.4.3", @@ -29786,6 +29787,7 @@ "version": "0.6.2", "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "optional": true, "dependencies": { "resolve": "^1.1.6" }, @@ -30183,6 +30185,7 @@ "version": "0.2.6", "resolved": "https://registry.npmjs.org/response-iterator/-/response-iterator-0.2.6.tgz", "integrity": "sha512-pVzEEzrsg23Sh053rmDUvLSkGXluZio0qu8VT6ukrYuvtjVfCbDZH9d6PGXb8HZfzdNZt8feXv/jvUzlhRgLnw==", + "optional": true, "engines": { "node": ">=0.8" } @@ -30940,6 +30943,7 @@ "version": "0.8.5", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "optional": true, "dependencies": { "glob": "^7.0.0", "interpret": "^1.0.0", @@ -30968,6 +30972,7 @@ "version": "0.3.4", "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "optional": true, "dependencies": { "minimist": "^1.2.3", "shelljs": "^0.8.5" @@ -31079,6 +31084,7 @@ "version": "5.4.6", "resolved": "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-5.4.6.tgz", "integrity": "sha512-7ipeNts8YTLbx/6zIaT1mQGrHG2vK+0TjywPD79QzIDJDcvNXBLX7DXQOt6by4DFdncu8lDPc+QHKHemtDEoQg==", + "optional": true, "dependencies": { "map-obj": "^4.1.0", "snake-case": "^3.0.4", @@ -31092,6 +31098,7 @@ "version": "2.19.0", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "optional": true, "engines": { "node": ">=12.20" }, @@ -31337,7 +31344,8 @@ "node_modules/store2": { "version": "2.14.2", "resolved": "https://registry.npmjs.org/store2/-/store2-2.14.2.tgz", - "integrity": "sha512-siT1RiqlfQnGqgT/YzXVUNsom9S0H1OX+dpdGN1xkyYATo4I6sep5NmsRD/40s3IIOvlCq6akxkqG82urIZW1w==" + "integrity": "sha512-siT1RiqlfQnGqgT/YzXVUNsom9S0H1OX+dpdGN1xkyYATo4I6sep5NmsRD/40s3IIOvlCq6akxkqG82urIZW1w==", + "optional": true }, "node_modules/stream-browserify": { "version": "3.0.0", @@ -32010,6 +32018,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-4.0.0.tgz", "integrity": "sha512-b19dMThMV4HVFynSAM1++gBHAbk2Tc/osgLIBZMKsyqh34jb2e8Os7T6ZW/Bt3pJFdBTd2JwAnAAEQV7rSNvcQ==", + "optional": true, "engines": { "node": ">=0.10" } @@ -32349,6 +32358,7 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", + "optional": true, "dependencies": { "readable-stream": "~2.3.6", "xtend": "~4.0.1" @@ -32357,12 +32367,14 @@ "node_modules/through2/node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "optional": true }, "node_modules/through2/node_modules/readable-stream": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "optional": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -32376,12 +32388,14 @@ "node_modules/through2/node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "optional": true }, "node_modules/through2/node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "optional": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -32618,6 +32632,7 @@ "version": "0.10.3", "resolved": "https://registry.npmjs.org/ts-invariant/-/ts-invariant-0.10.3.tgz", "integrity": "sha512-uivwYcQaxAucv1CzRp2n/QdYPo4ILf9VXgH19zEIjFx2EJufV16P0JtJVpYHy89DItG6Kwj2oIUjrcK5au+4tQ==", + "optional": true, "dependencies": { "tslib": "^2.1.0" }, @@ -32790,7 +32805,8 @@ "node_modules/tweetnacl-util": { "version": "0.15.1", "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz", - "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==" + "integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw==", + "optional": true }, "node_modules/type": { "version": "1.2.0", @@ -33083,6 +33099,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", "integrity": "sha512-KK8xQ1mkzZeg9inewmFVDNkg3l5LUhoq9kN6iWYB/CC9YMG8HA+c1Q8HwDe6dEX7kErrEVNVBO3fWsVq5iDgtw==", + "optional": true, "engines": { "node": ">=8" } @@ -35042,12 +35059,14 @@ "node_modules/zen-observable": { "version": "0.8.15", "resolved": "https://registry.npmjs.org/zen-observable/-/zen-observable-0.8.15.tgz", - "integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==" + "integrity": "sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==", + "optional": true }, "node_modules/zen-observable-ts": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/zen-observable-ts/-/zen-observable-ts-1.2.5.tgz", "integrity": "sha512-QZWQekv6iB72Naeake9hS1KxHlotfRpe+WGNbNx5/ta+R3DNjVO2bswf63gXlWDcs+EMd7XY8HfVQyP1X6T4Zg==", + "optional": true, "dependencies": { "zen-observable": "0.8.15" } @@ -35088,15 +35107,13 @@ "@cosmjs/cosmwasm-stargate": "^0.31.0", "@cosmjs/proto-signing": "^0.31.0", "@cosmjs/stargate": "^0.31.0", - "@injectivelabs/sdk-ts": "1.0.211", + "@cosmjs/tendermint-rpc": "^0.31.0", "@mysten/sui.js": "^0.32.2", "@nomad-xyz/multi-provider": "^1.1.0", "@solana/spl-token": "^0.3.7", "@solana/web3.js": "^1.73.0", - "@terra-money/terra.js": "^3.1.7", "@typescript-eslint/eslint-plugin": "^5.48.1", "@typescript-eslint/parser": "^5.48.1", - "@xpla/xpla.js": "^0.2.3", "algosdk": "^1.15.0", "aptos": "1.5.0", "axios": "^0.27.2", @@ -35121,155 +35138,6 @@ "typescript": "^4.9.4" } }, - "sdk/node_modules/@cosmjs/amino": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/crypto": "^0.29.5", - "@cosmjs/encoding": "^0.29.5", - "@cosmjs/math": "^0.29.5", - "@cosmjs/utils": "^0.29.5" - } - }, - "sdk/node_modules/@cosmjs/crypto": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/encoding": "^0.29.5", - "@cosmjs/math": "^0.29.5", - "@cosmjs/utils": "^0.29.5", - "@noble/hashes": "^1", - "bn.js": "^5.2.0", - "elliptic": "^6.5.4", - "libsodium-wrappers": "^0.7.6" - } - }, - "sdk/node_modules/@cosmjs/encoding": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "base64-js": "^1.3.0", - "bech32": "^1.1.4", - "readonly-date": "^1.0.0" - } - }, - "sdk/node_modules/@cosmjs/encoding/node_modules/bech32": { - "version": "1.1.4", - "license": "MIT" - }, - "sdk/node_modules/@cosmjs/json-rpc": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/stream": "^0.29.5", - "xstream": "^11.14.0" - } - }, - "sdk/node_modules/@cosmjs/math": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "bn.js": "^5.2.0" - } - }, - "sdk/node_modules/@cosmjs/socket": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/stream": "^0.29.5", - "isomorphic-ws": "^4.0.1", - "ws": "^7", - "xstream": "^11.14.0" - } - }, - "sdk/node_modules/@cosmjs/stream": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "xstream": "^11.14.0" - } - }, - "sdk/node_modules/@cosmjs/tendermint-rpc": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/crypto": "^0.29.5", - "@cosmjs/encoding": "^0.29.5", - "@cosmjs/json-rpc": "^0.29.5", - "@cosmjs/math": "^0.29.5", - "@cosmjs/socket": "^0.29.5", - "@cosmjs/stream": "^0.29.5", - "@cosmjs/utils": "^0.29.5", - "axios": "^0.21.2", - "readonly-date": "^1.0.0", - "xstream": "^11.14.0" - } - }, - "sdk/node_modules/@cosmjs/tendermint-rpc/node_modules/axios": { - "version": "0.21.4", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.14.0" - } - }, - "sdk/node_modules/@cosmjs/utils": { - "version": "0.29.5", - "license": "Apache-2.0" - }, - "sdk/node_modules/@injectivelabs/sdk-ts": { - "version": "1.0.211", - "hasInstallScript": true, - "license": "MIT", - "dependencies": { - "@apollo/client": "^3.5.8", - "@cosmjs/amino": "^0.29.0", - "@cosmjs/proto-signing": "^0.29.0", - "@cosmjs/tendermint-rpc": "^0.29.0", - "@ethersproject/bytes": "^5.7.0", - "@improbable-eng/grpc-web": "^0.15.0", - "@improbable-eng/grpc-web-node-http-transport": "^0.15.0", - "@improbable-eng/grpc-web-react-native-transport": "^0.15.0", - "@injectivelabs/chain-api": "1.8.2-no-tse", - "@injectivelabs/exceptions": "^1.0.25", - "@injectivelabs/indexer-api": "1.0.31", - "@injectivelabs/networks": "^1.0.37", - "@injectivelabs/token-metadata": "^1.0.51", - "@injectivelabs/ts-types": "^1.0.14", - "@injectivelabs/utils": "^1.0.31", - "@metamask/eth-sig-util": "^4.0.1", - "@types/google-protobuf": "^3.15.5", - "axios": "^0.27.2", - "bech32": "^2.0.0", - "bip39": "^3.0.4", - "eth-crypto": "^2.3.0", - "ethereumjs-abi": "^0.6.8", - "ethereumjs-util": "^7.1.4", - "ethers": "^5.6.4", - "ethjs-util": "^0.1.6", - "google-protobuf": "^3.21.0", - "graphql": "^16.3.0", - "http-status-codes": "^2.2.0", - "jscrypto": "^1.0.3", - "keccak256": "^1.0.6", - "link-module-alias": "^1.2.0", - "secp256k1": "^4.0.3", - "shx": "^0.3.2", - "snakecase-keys": "^5.4.1" - } - }, - "sdk/node_modules/@injectivelabs/sdk-ts/node_modules/@cosmjs/proto-signing": { - "version": "0.29.5", - "license": "Apache-2.0", - "dependencies": { - "@cosmjs/amino": "^0.29.5", - "@cosmjs/crypto": "^0.29.5", - "@cosmjs/encoding": "^0.29.5", - "@cosmjs/math": "^0.29.5", - "@cosmjs/utils": "^0.29.5", - "cosmjs-types": "^0.5.2", - "long": "^4.0.0" - } - }, "sdk/node_modules/axios": { "version": "0.27.2", "license": "MIT", @@ -35385,6 +35253,7 @@ "web-vitals": "^2.1.4" }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@babel/preset-env": "^7.20.2", "jest": "^29.5.0", "react": "^18.2.0", @@ -35394,6 +35263,25 @@ "react": "^18.2.0", "react-dom": "^18.2.0" } + }, + "wormhole-connect/node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.11", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.11.tgz", + "integrity": "sha512-0QZ8qP/3RLDVBwBFoWAwCtgcDZJVwA5LUJRZU8x2YFfKNuFq161wK3cuGrALu5yiPu+vzwTAg/sMWVNeWeNyaw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead.", + "dev": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.18.6", + "@babel/helper-create-class-features-plugin": "^7.21.0", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } } } } diff --git a/sdk/package.json b/sdk/package.json index 63cdad61f..dcf0a5c6a 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -9,15 +9,13 @@ "@cosmjs/cosmwasm-stargate": "^0.31.0", "@cosmjs/proto-signing": "^0.31.0", "@cosmjs/stargate": "^0.31.0", - "@injectivelabs/sdk-ts": "1.0.211", + "@cosmjs/tendermint-rpc": "^0.31.0", "@mysten/sui.js": "^0.32.2", "@nomad-xyz/multi-provider": "^1.1.0", "@solana/spl-token": "^0.3.7", "@solana/web3.js": "^1.73.0", - "@terra-money/terra.js": "^3.1.7", "@typescript-eslint/eslint-plugin": "^5.48.1", "@typescript-eslint/parser": "^5.48.1", - "@xpla/xpla.js": "^0.2.3", "algosdk": "^1.15.0", "aptos": "1.5.0", "axios": "^0.27.2", diff --git a/sdk/src/contexts/cosmos/context.ts b/sdk/src/contexts/cosmos/context.ts index ebbec19aa..4db6636f7 100644 --- a/sdk/src/contexts/cosmos/context.ts +++ b/sdk/src/contexts/cosmos/context.ts @@ -1,4 +1,7 @@ import { + CHAIN_ID_OSMOSIS, + CHAIN_ID_SEI, + CHAIN_ID_WORMCHAIN, cosmos, parseTokenTransferPayload, parseVaa, @@ -7,15 +10,19 @@ import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'; import { EncodeObject, decodeTxRaw } from '@cosmjs/proto-signing'; import { Coin, + IbcExtension, + QueryClient, StargateClient, StdFee, calculateFee, logs as cosmosLogs, + setupIbcExtension, } from '@cosmjs/stargate'; import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'; -import { BigNumber } from 'ethers'; +import { BigNumber, utils } from 'ethers'; import { arrayify, + base58, base64, hexStripZeros, hexlify, @@ -35,8 +42,13 @@ import { import { WormholeContext } from '../../wormhole'; import { TokenBridgeAbstract } from '../abstracts/tokenBridge'; import { CosmosContracts } from './contracts'; -import { searchCosmosLogs } from './utils'; +import { isCosmWasmChain, searchCosmosLogs } from './utils'; import { ForeignAssetCache } from '../../utils'; +import { + Tendermint34Client, + Tendermint37Client, + TendermintClient, +} from '@cosmjs/tendermint-rpc'; export interface CosmosTransaction { fee: StdFee | 'auto' | number; @@ -76,6 +88,8 @@ const buildExecuteMsg = ( }), }); +const IBC_PORT = 'transfer'; + export class CosmosContext< T extends WormholeContext, > extends TokenBridgeAbstract { @@ -84,7 +98,7 @@ export class CosmosContext< readonly context: T; readonly chain: ChainName; - private static CLIENT_MAP: Record = {}; + private static CLIENT_MAP: Record = {}; private foreignAssetCache: ForeignAssetCache; constructor( @@ -192,6 +206,96 @@ export class CosmosContext< } async getForeignAsset( + tokenId: TokenId, + chain: ChainId | ChainName, + ): Promise { + return this.context.toChainId(chain) === CHAIN_ID_WORMCHAIN + ? this.getWhForeignAsset(tokenId, chain) + : this.getGatewayForeignAsset(tokenId, chain); + } + + async getGatewayForeignAsset( + tokenId: TokenId, + chain: ChainId | ChainName, + ): Promise { + // add check here in case the token is a native cosmos denom + // in such cases there's no need to look for in the wormchain network + if (tokenId.chain === chain) return tokenId.address; + const wrappedAsset = await this.getWhForeignAsset( + tokenId, + CHAIN_ID_WORMCHAIN, + ); + if (!wrappedAsset) return null; + return this.isNativeDenom(wrappedAsset, chain) + ? wrappedAsset + : this.deriveIBCDenom(this.CW20AddressToFactory(wrappedAsset), chain); + } + + private CW20AddressToFactory(address: string): string { + const encodedAddress = base58.encode(cosmos.canonicalAddress(address)); + return `factory/${this.getTranslatorAddress()}/${encodedAddress}`; + } + + getTranslatorAddress(): string { + const addr = + this.context.conf.chains['wormchain']?.contracts.ibcShimContract; + if (!addr) throw new Error('IBC Shim contract not configured'); + return addr; + } + + async deriveIBCDenom( + denom: string, + chain: ChainId | ChainName, + ): Promise { + const channel = await this.getIbcDestinationChannel(chain); + const hashData = utils.hexlify(Buffer.from(`transfer/${channel}/${denom}`)); + const hash = utils.sha256(hashData).substring(2); + return `ibc/${hash.toUpperCase()}`; + } + + async getIbcDestinationChannel(chain: ChainId | ChainName): Promise { + const sourceChannel = await this.getIbcSourceChannel(chain); + const queryClient = await this.getQueryClient(CHAIN_ID_WORMCHAIN); + const conn = await queryClient.ibc.channel.channel(IBC_PORT, sourceChannel); + + const destChannel = conn.channel?.counterparty?.channelId; + if (!destChannel) { + throw new Error(`No destination channel found on chain ${chain}`); + } + + return destChannel; + } + + async getIbcSourceChannel(chain: ChainId | ChainName): Promise { + const id = this.context.toChainId(chain); + if (!isCosmWasmChain(id)) throw new Error('Chain is not cosmos chain'); + const client = await this.getCosmWasmClient(CHAIN_ID_WORMCHAIN); + const { channel } = await client.queryContractSmart( + this.getTranslatorAddress(), + { + ibc_channel: { + chain_id: id, + }, + }, + ); + return channel; + } + + private isNativeDenom(denom: string, chain: ChainName | ChainId): boolean { + const chainId = this.context.toChainId(chain); + switch (chainId) { + case CHAIN_ID_SEI: + return denom === 'usei'; + case CHAIN_ID_WORMCHAIN: + return denom === 'uworm'; + case CHAIN_ID_OSMOSIS: + return denom === 'uosmo'; + default: + return false; + } + } + + async getWhForeignAsset( tokenId: TokenId, chain: ChainName | ChainId, ): Promise { @@ -269,16 +373,7 @@ export class CosmosContext< ): Promise { const assetAddress = await this.getForeignAsset(tokenId, chain); if (!assetAddress) return null; - - if (assetAddress === this.getNativeDenom(chain)) { - return this.getNativeBalance(walletAddress, chain); - } - - const client = await this.getCosmWasmClient(chain); - const { balance } = await client.queryContractSmart(assetAddress, { - balance: { address: walletAddress }, - }); - return BigNumber.from(balance); + return this.getNativeBalance(walletAddress, chain, assetAddress); } private getNativeDenom(chain: ChainName | ChainId): string { @@ -434,19 +529,45 @@ export class CosmosContext< }; } - private async getCosmWasmClient( + private async getQueryClient( chain: ChainId | ChainName, - ): Promise { + ): Promise { + const tmClient = await this.getTmClient(chain); + return QueryClient.withExtensions(tmClient, setupIbcExtension); + } + + private async getTmClient( + chain: ChainId | ChainName, + ): Promise { const name = this.context.toChainName(chain); if (CosmosContext.CLIENT_MAP[name]) { return CosmosContext.CLIENT_MAP[name]; } - const rpc = this.context.conf.rpcs[name]; + const rpc = this.context.conf.rpcs[this.context.toChainName(chain)]; if (!rpc) throw new Error(`${chain} RPC not configured`); - const client = await CosmWasmClient.connect(rpc); - CosmosContext.CLIENT_MAP[name] = client; - return client; + + // from cosmjs: https://github.com/cosmos/cosmjs/blob/358260bff71c9d3e7ad6644fcf64dc00325cdfb9/packages/stargate/src/stargateclient.ts#L218 + let tmClient: TendermintClient; + const tm37Client = await Tendermint37Client.connect(rpc); + const version = (await tm37Client.status()).nodeInfo.version; + if (version.startsWith('0.37.')) { + tmClient = tm37Client; + } else { + tm37Client.disconnect(); + tmClient = await Tendermint34Client.connect(rpc); + } + + CosmosContext.CLIENT_MAP[name] = tmClient; + + return tmClient; + } + + private async getCosmWasmClient( + chain: ChainId | ChainName, + ): Promise { + const tmClient = await this.getTmClient(chain); + return CosmWasmClient.create(tmClient); } getTokenBridgeAddress(chain: ChainName): string { diff --git a/sdk/src/contexts/cosmos/utils.ts b/sdk/src/contexts/cosmos/utils.ts index d971fe758..280988a16 100644 --- a/sdk/src/contexts/cosmos/utils.ts +++ b/sdk/src/contexts/cosmos/utils.ts @@ -1,4 +1,11 @@ +import { + CHAIN_ID_OSMOSIS, + CHAIN_ID_TERRA2, + CHAIN_ID_WORMCHAIN, + isCosmWasmChain as isBaseCosmWasmChain, +} from '@certusone/wormhole-sdk'; import { logs as cosmosLogs } from '@cosmjs/stargate'; +import { ChainId } from '../../types'; /** * Search for a specific piece of information emitted by the contracts during the transaction @@ -20,3 +27,13 @@ export const searchCosmosLogs = ( } return null; }; + +const COSMOS_CHAINS: ChainId[] = [ + CHAIN_ID_WORMCHAIN, + CHAIN_ID_OSMOSIS, + CHAIN_ID_TERRA2, +]; + +export function isCosmWasmChain(chainId: ChainId): boolean { + return isBaseCosmWasmChain(chainId) || COSMOS_CHAINS.includes(chainId); +} diff --git a/wormhole-connect/package.json b/wormhole-connect/package.json index e7e56bf03..4e30bfc1e 100644 --- a/wormhole-connect/package.json +++ b/wormhole-connect/package.json @@ -94,6 +94,7 @@ ] }, "devDependencies": { + "@babel/plugin-proposal-private-property-in-object": "^7.21.11", "@babel/preset-env": "^7.20.2", "jest": "^29.5.0", "react": "^18.2.0", diff --git a/wormhole-connect/src/components/TokensModal.tsx b/wormhole-connect/src/components/TokensModal.tsx index d64fb838d..208352bce 100644 --- a/wormhole-connect/src/components/TokensModal.tsx +++ b/wormhole-connect/src/components/TokensModal.tsx @@ -29,7 +29,6 @@ import Scroll from './Scroll'; import TokenIcon from '../icons/TokenIcons'; import CircularProgress from '@mui/material/CircularProgress'; import Tabs from './Tabs'; -import { CosmosGatewayRoute } from 'utils/routes'; const useStyles = makeStyles()((theme: any) => ({ tokensContainer: { @@ -271,7 +270,6 @@ function TokensModal(props: Props) { destBalances, supportedSourceTokens, supportedDestTokens, - route, } = useSelector((state: RootState) => state.transferInput); const supportedTokens = useMemo(() => { @@ -334,30 +332,9 @@ function TokensModal(props: Props) { supportedTokens.map(async (t) => { let balance: BigNumber | null = null; try { - if (t.tokenId) { - // TODO: going to do some refactoring of gateway/cosmos contexts - if (isCosmWasmChain(wh.toChainId(chain))) { - const denom = await new CosmosGatewayRoute().getForeignAsset( - t.tokenId, - chain, - ); - if (denom) { - balance = await wh.getNativeBalance( - walletAddress, - chain, - denom, - ); - } - } else { - balance = await wh.getTokenBalance( - walletAddress, - t.tokenId, - chain, - ); - } - } else { - balance = await wh.getNativeBalance(walletAddress, chain); - } + balance = t.tokenId + ? await wh.getTokenBalance(walletAddress, t.tokenId, chain) + : await wh.getNativeBalance(walletAddress, chain); } catch (e) { console.warn('Failed to fetch balance', e); } @@ -376,7 +353,7 @@ function TokensModal(props: Props) { balances, }), ); - }, [walletAddress, chain, dispatch, type, supportedTokens, route]); + }, [walletAddress, chain, dispatch, type, supportedTokens]); // fetch token balances and set in store useEffect(() => { diff --git a/wormhole-connect/src/utils/cosmos.ts b/wormhole-connect/src/utils/cosmos.ts index 6725a3de0..9f3555b97 100644 --- a/wormhole-connect/src/utils/cosmos.ts +++ b/wormhole-connect/src/utils/cosmos.ts @@ -1,19 +1,11 @@ -import { ChainName, ChainId } from '@wormhole-foundation/wormhole-connect-sdk'; import { - CHAIN_ID_OSMOSIS, - CHAIN_ID_TERRA2, - CHAIN_ID_WORMCHAIN, - isCosmWasmChain as isBaseCosmWasmChain, -} from '@certusone/wormhole-sdk'; + ChainName, + ChainId, + isCosmWasmChain as isCosmWasmChainSdk, +} from '@wormhole-foundation/wormhole-connect-sdk'; import { wh } from './sdk'; -const COSMOS_CHAINS: ChainId[] = [ - CHAIN_ID_WORMCHAIN, - CHAIN_ID_OSMOSIS, - CHAIN_ID_TERRA2, -]; - export function isCosmWasmChain(chainId: ChainId | ChainName): boolean { const id = wh.toChainId(chainId); - return isBaseCosmWasmChain(id) || COSMOS_CHAINS.includes(id); + return isCosmWasmChainSdk(id); } diff --git a/wormhole-connect/src/utils/routes/cosmosGateway.ts b/wormhole-connect/src/utils/routes/cosmosGateway.ts index 35199e6fe..399bb8254 100644 --- a/wormhole-connect/src/utils/routes/cosmosGateway.ts +++ b/wormhole-connect/src/utils/routes/cosmosGateway.ts @@ -1,10 +1,4 @@ -import { - CHAIN_ID_OSMOSIS, - CHAIN_ID_SEI, - CHAIN_ID_SOLANA, - CHAIN_ID_WORMCHAIN, - cosmos, -} from '@certusone/wormhole-sdk'; +import { CHAIN_ID_SOLANA, CHAIN_ID_WORMCHAIN } from '@certusone/wormhole-sdk'; import { CosmWasmClient, MsgExecuteContractEncodeObject, @@ -35,7 +29,7 @@ import { TendermintClient, } from '@cosmjs/tendermint-rpc'; import { BigNumber, utils } from 'ethers'; -import { arrayify, base58, hexlify } from 'ethers/lib/utils.js'; +import { arrayify, hexlify } from 'ethers/lib/utils.js'; import { toChainId, wh } from 'utils/sdk'; import { isCosmWasmChain } from 'utils/cosmos'; import { CHAINS, RPCS, ROUTES, TOKENS } from 'config'; @@ -297,6 +291,13 @@ export class CosmosGatewayRoute extends BaseRoute { ); } + getForeignAsset( + token: TokenId, + chain: ChainId | ChainName, + ): Promise { + return wh.getForeignAsset(token, chain); + } + getMinSendAmount(routeOptions: any): number { return 0; } @@ -415,25 +416,6 @@ export class CosmosGatewayRoute extends BaseRoute { ]; } - private isNativeDenom(denom: string, chain: ChainName | ChainId): boolean { - const chainId = wh.toChainId(chain); - switch (chainId) { - case CHAIN_ID_SEI: - return denom === 'usei'; - case CHAIN_ID_WORMCHAIN: - return denom === 'uworm'; - case CHAIN_ID_OSMOSIS: - return denom === 'uosmo'; - default: - return false; - } - } - - private CW20AddressToFactory(address: string): string { - const encodedAddress = base58.encode(cosmos.canonicalAddress(address)); - return `factory/${this.getTranslatorAddress()}/${encodedAddress}`; - } - getTranslatorAddress(): string { const addr = CHAINS['wormchain']?.contracts.ibcShimContract; if (!addr) throw new Error('IBC Shim contract not configured'); @@ -448,35 +430,6 @@ export class CosmosGatewayRoute extends BaseRoute { return BigNumber.from(0); } - async getForeignAsset( - tokenId: TokenId, - chain: ChainId | ChainName, - ): Promise { - // fall back to original implementation if not cosmos chain - if (!isCosmWasmChain(wh.toChainId(chain))) { - return wh.getForeignAsset(tokenId, chain); - } - - // add check here in case the token is a native cosmos denom - // in such cases there's no need to look for in the wormchain network - if (tokenId.chain === chain) return tokenId.address; - const wrappedAsset = await wh.getForeignAsset(tokenId, CHAIN_ID_WORMCHAIN); - if (!wrappedAsset) return null; - return this.isNativeDenom(wrappedAsset, chain) - ? wrappedAsset - : this.deriveIBCDenom(this.CW20AddressToFactory(wrappedAsset), chain); - } - - async deriveIBCDenom( - denom: string, - chain: ChainId | ChainName, - ): Promise { - const channel = await this.getIbcDestinationChannel(chain); - const hashData = utils.hexlify(Buffer.from(`transfer/${channel}/${denom}`)); - const hash = utils.sha256(hashData).substring(2); - return `ibc/${hash.toUpperCase()}`; - } - async getIbcDestinationChannel(chain: ChainId | ChainName): Promise { const sourceChannel = await this.getIbcSourceChannel(chain); const queryClient = await this.getQueryClient(CHAIN_ID_WORMCHAIN);