diff --git a/package.json b/package.json index d6d3f374..7965a5cf 100644 --- a/package.json +++ b/package.json @@ -102,9 +102,11 @@ "@noble/curves": "^1.9.6", "@solana/wallet-adapter-base": "^0.9.27", "@solana/web3.js": "^1.98.4", + "@tronweb3/tronwallet-abstract-adapter": "^1.1.9", "bech32": "^2.0.0", "bitcoinjs-lib": "^7.0.0-rc.0", "bs58": "^6.0.0", + "tronweb": "^6.0.4", "viem": "^2.33.3" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9dade95..3238a93d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,6 +32,9 @@ importers: '@solana/web3.js': specifier: ^1.98.4 version: 1.98.4(bufferutil@4.0.9)(typescript@5.9.2)(utf-8-validate@5.0.10) + '@tronweb3/tronwallet-abstract-adapter': + specifier: ^1.1.9 + version: 1.1.9(bufferutil@4.0.9)(utf-8-validate@5.0.10) bech32: specifier: ^2.0.0 version: 2.0.0 @@ -41,6 +44,9 @@ importers: bs58: specifier: ^6.0.0 version: 6.0.0 + tronweb: + specifier: ^6.0.4 + version: 6.0.4(bufferutil@4.0.9)(utf-8-validate@5.0.10) viem: specifier: ^2.33.3 version: 2.33.3(bufferutil@4.0.9)(typescript@5.9.2)(utf-8-validate@5.0.10) @@ -113,6 +119,9 @@ packages: graphql: ^15.5.0 || ^16.0.0 || ^17.0.0 typescript: ^5.0.0 + '@adraffy/ens-normalize@1.10.1': + resolution: {integrity: sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==} + '@adraffy/ens-normalize@1.11.0': resolution: {integrity: sha512-/3DDPKHqqIqxUULp8yP4zODUY1i+2xvVWsv8A79xGWdCAG+8sb0hRh0Rk2QyOJUnnbyPUAZYcpBuRe3nS2OIUg==} @@ -137,6 +146,10 @@ packages: engines: {node: '>=6.0.0'} hasBin: true + '@babel/runtime@7.26.10': + resolution: {integrity: sha512-2WJMeRQPHKSPemqk/awGrAiuFfzBmOIPXKizAsVhWH9YJqLZ0H+HS4c8loHGgW6utJ3E/ejXQUsiGaQy2NZ9Fw==} + engines: {node: '>=6.9.0'} + '@babel/runtime@7.28.2': resolution: {integrity: sha512-KHp2IflsnGywDjBWDkR9iEqiWSpc8GIi0lgTT3mOElT0PP1tG26P4tmFI2YvAdzgq9RGyoHZQEIEdZy6Ec5xCA==} engines: {node: '>=6.9.0'} @@ -562,6 +575,12 @@ packages: resolution: {integrity: sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw==} engines: {node: ^14.21.3 || >=16} + '@noble/curves@1.2.0': + resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} + + '@noble/curves@1.4.2': + resolution: {integrity: sha512-TavHr8qycMChk8UwMld0ZDRvatedkzWfH8IiaeGCfymOP5i0hSCozz9vHOL0nkwk7HRMlFnAiKpS2jrUmSybcw==} + '@noble/curves@1.9.2': resolution: {integrity: sha512-HxngEd2XUcg9xi20JkwlLCtYwfoFw4JGkuZpT+WlsPD4gB/cxkvTD8fSsoAnphGZhFdZYKeQIPCuFlWPm1uE0g==} engines: {node: ^14.21.3 || >=16} @@ -570,6 +589,14 @@ packages: resolution: {integrity: sha512-GIKz/j99FRthB8icyJQA51E8Uk5hXmdyThjgQXRKiv9h0zeRlzSCLIzFw6K1LotZ3XuB7yzlf76qk7uBmTdFqA==} engines: {node: ^14.21.3 || >=16} + '@noble/hashes@1.3.2': + resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} + engines: {node: '>= 16'} + + '@noble/hashes@1.4.0': + resolution: {integrity: sha512-V1JJ1WTRUqHHrOSh597hURcMqVKVGL/ea3kv0gSnEdsEZ0/+VyPghM1lMNGc00z7CIQorSvbKpuJkxvuHbvdbg==} + engines: {node: '>= 16'} + '@noble/hashes@1.8.0': resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==} engines: {node: ^14.21.3 || >=16} @@ -699,12 +726,21 @@ packages: cpu: [x64] os: [win32] + '@scure/base@1.1.9': + resolution: {integrity: sha512-8YKhl8GHiNI/pU2VMaofa2Tor7PJRAjwQLBBuilkJ9L5+13yVbC7JO/wS7piioAvPSwR3JKM1IJ/u4xQzbcXKg==} + '@scure/base@1.2.6': resolution: {integrity: sha512-g/nm5FgUa//MCj1gV09zTJTaM6KBAHqLN907YVQqf7zC49+DcO4B1so4ZX07Ef10Twr6nuqYEH9GEggFXA4Fmg==} + '@scure/bip32@1.4.0': + resolution: {integrity: sha512-sVUpc0Vq3tXCkDGYVWGIZTRfnvu8LoTDaev7vbwh0omSvVORONr960MQWdKqJDCReIEmTj3PAr73O3aoxz7OPg==} + '@scure/bip32@1.7.0': resolution: {integrity: sha512-E4FFX/N3f4B80AKWp5dP6ow+flD1LQZo/w8UnLGYZO674jS6YnYeepycOOksv+vLPSpgN35wgKgy+ybfTb2SMw==} + '@scure/bip39@1.3.0': + resolution: {integrity: sha512-disdg7gHuTDZtY+ZdkmLpPCk7fxZSu3gBiEGuoC1XYxv9cGx3Z6cpTggCgW6odSOOIXCiDjuGejW+aJKCY/pIQ==} + '@scure/bip39@1.6.0': resolution: {integrity: sha512-+lF0BbLiJNwVlev4eKelw1WWLaiKXw7sSl8T6FvBlWkdX+94aGJ4o8XjUdlyhTCjd8c+B3KT3JfS8P0bLRNU6A==} @@ -747,6 +783,10 @@ packages: '@swc/helpers@0.5.17': resolution: {integrity: sha512-5IKx/Y13RsYd+sauPb2x+U/xZikHjolzfuDgTAl/Tdf3Q8rslRvC19NKDLgAJQ6wsqADk10ntlv08nPFw/gO/A==} + '@tronweb3/tronwallet-abstract-adapter@1.1.9': + resolution: {integrity: sha512-2wev5T/Z+Yt96nv2upZeq54v8zk8aXCg0p6yx1BpfY2y25lC0jEiul+F/6o5s2uIUXe2ENdbpMiGQz8+/Jy1EQ==} + engines: {node: '>=16', pnpm: '>=7'} + '@ts-graphviz/adapter@2.0.6': resolution: {integrity: sha512-kJ10lIMSWMJkLkkCG5gt927SnGZcBuG0s0HHswGzcHTgvtUe7yk5/3zTEr0bafzsodsOq5Gi6FhQeV775nC35Q==} engines: {node: '>=18'} @@ -805,6 +845,9 @@ packages: '@types/node@12.20.55': resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} + '@types/node@22.7.5': + resolution: {integrity: sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==} + '@types/node@24.2.1': resolution: {integrity: sha512-DRh5K+ka5eJic8CjH7td8QpYEV6Zo10gfRkjHCO3weqZHWDtAaSTFtl4+VMqOJ4N5jcuhZ9/l+yy8rVgw7BQeQ==} @@ -957,6 +1000,9 @@ packages: add-stream@1.0.0: resolution: {integrity: sha512-qQLMr+8o0WC4FZGQTcJiKBVC59JylcPSrTtk6usvmIDFUOCKegapy1VHQwRbFMOFyb/inzUVqHs+eMYKDM1YeQ==} + aes-js@4.0.0-beta.5: + resolution: {integrity: sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==} + agentkeepalive@4.6.0: resolution: {integrity: sha512-kja8j7PjmncONqaTsB8fQ+wE2mSU2DJ9D4XKoJ5PFWIdRMa6SLSN1ff4mOr4jCbfRSsxR4keIiySJU0N9T5hIQ==} engines: {node: '>= 8.0.0'} @@ -1022,6 +1068,12 @@ packages: ast-v8-to-istanbul@0.3.4: resolution: {integrity: sha512-cxrAnZNLBnQwBPByK4CeDaw5sWZtMilJE/Q3iDA0aamgaIVNDF9T6K2/8DfYDZEejZ2jNnDrG9m8MY72HFd0KA==} + asynckit@0.4.0: + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + + axios@1.11.0: + resolution: {integrity: sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA==} + balanced-match@1.0.2: resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==} @@ -1037,6 +1089,9 @@ packages: bech32@2.0.0: resolution: {integrity: sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==} + bignumber.js@9.1.2: + resolution: {integrity: sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==} + bip174@3.0.0-rc.1: resolution: {integrity: sha512-+8P3BpSairVNF2Nee6Ksdc1etIjWjBOi/MH0MwKtq9YaYp+S2Hk2uvup0e8hCT4IKlS58nXJyyQVmW92zPoD4Q==} engines: {node: '>=18.0.0'} @@ -1090,6 +1145,10 @@ packages: resolution: {integrity: sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==} engines: {node: '>=8'} + call-bind-apply-helpers@1.0.2: + resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==} + engines: {node: '>= 0.4'} + callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} engines: {node: '>=6'} @@ -1169,6 +1228,10 @@ packages: colorette@2.0.20: resolution: {integrity: sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==} + combined-stream@1.0.8: + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} + engines: {node: '>= 0.8'} + commander@12.1.0: resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} engines: {node: '>=18'} @@ -1358,6 +1421,10 @@ packages: resolution: {integrity: sha512-ReEBKkIfe4ya47wlPYf/gu5ib6yUG0/Aez0JQZQz94kiWtRQvZIQbTiehsnwHvLSWJnQdhVeqYue7Id1dKr0qw==} engines: {node: '>=10'} + delayed-stream@1.0.0: + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} + engines: {node: '>=0.4.0'} + dependency-tree@11.2.0: resolution: {integrity: sha512-+C1H3mXhcvMCeu5i2Jpg9dc0N29TWTuT6vJD7mHLAfVmAbo9zW8NlkvQ1tYd3PDMab0IRQM0ccoyX68EZtx9xw==} engines: {node: '>=18'} @@ -1426,6 +1493,10 @@ packages: resolution: {integrity: sha512-sCm11ak2oY6DglEPpCB8TixLjWAxd3kJTs6UIcSasNYxXdFPV+YKlye92c8H4kKFqV5qYMIh7d+cYecEg0dIkA==} engines: {node: '>=6'} + dunder-proto@1.0.1: + resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==} + engines: {node: '>= 0.4'} + eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -1457,9 +1528,25 @@ packages: error-ex@1.3.2: resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==} + es-define-property@1.0.1: + resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==} + engines: {node: '>= 0.4'} + + es-errors@1.3.0: + resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} + engines: {node: '>= 0.4'} + es-module-lexer@1.7.0: resolution: {integrity: sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==} + es-object-atoms@1.1.1: + resolution: {integrity: sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==} + engines: {node: '>= 0.4'} + + es-set-tostringtag@2.1.0: + resolution: {integrity: sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==} + engines: {node: '>= 0.4'} + es6-promise@4.2.8: resolution: {integrity: sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==} @@ -1507,6 +1594,16 @@ packages: resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==} engines: {node: '>=0.10.0'} + ethereum-cryptography@2.2.1: + resolution: {integrity: sha512-r/W8lkHSiTLxUxW8Rf3u4HGB0xQweG2RyETjywylKZSzLWoWAijRz8WCuOtJ6wah+avllXBqZuk29HCCvhEIRg==} + + ethers@6.13.5: + resolution: {integrity: sha512-+knKNieu5EKRThQJWwqaJ10a6HE9sSehGeqWN65//wE7j47ZpFhKAnHB/JJFibwwg61I/koxaPsXbXpD/skNOQ==} + engines: {node: '>=14.0.0'} + + eventemitter3@4.0.7: + resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} + eventemitter3@5.0.1: resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} @@ -1575,10 +1672,23 @@ packages: resolution: {integrity: sha512-YyZM99iHrqLKjmt4LJDj58KI+fYyufRLBSYcqycxf//KpBk9FoewoGX0450m9nB44qrZnovzC2oeP5hUibxc/g==} engines: {node: '>=18'} + follow-redirects@1.15.11: + resolution: {integrity: sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + foreground-child@3.3.1: resolution: {integrity: sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==} engines: {node: '>=14'} + form-data@4.0.4: + resolution: {integrity: sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==} + engines: {node: '>= 6'} + fs-extra@11.3.1: resolution: {integrity: sha512-eXvGGwZ5CL17ZSwHWd3bbgk7UUpF6IFHtP57NYYakPvHOs8GDgDe5KJI36jIJzDkJ6eJjuzRA8eBQb6SkKue0g==} engines: {node: '>=14.14'} @@ -1606,6 +1716,10 @@ packages: resolution: {integrity: sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==} engines: {node: '>=18'} + get-intrinsic@1.3.0: + resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==} + engines: {node: '>= 0.4'} + get-own-enumerable-property-symbols@3.0.2: resolution: {integrity: sha512-I0UBV/XOz1XkIJHEUDMZAbzCThU/H8DxmSfmdGcKPnVhu2VfFqr34jr9777IyaTYvxjedWhqVIilEDsCdP5G6g==} @@ -1614,6 +1728,10 @@ packages: engines: {node: '>=6.9.0'} hasBin: true + get-proto@1.0.1: + resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==} + engines: {node: '>= 0.4'} + git-raw-commits@2.0.11: resolution: {integrity: sha512-VnctFhw+xfj8Va1xtfEqCUD2XDrbAPSJx+hSrE5K7fGdjZruW7XV+QOrN7LF/RJyvspRiD2I0asWsxFp0ya26A==} engines: {node: '>=10'} @@ -1657,6 +1775,13 @@ packages: engines: {node: '>=0.6.0'} hasBin: true + google-protobuf@3.21.4: + resolution: {integrity: sha512-MnG7N936zcKTco4Jd2PX2U96Kf9PxygAPKBug+74LHzmHXmceN16MmRcdgZv+DGef/S9YvQAfRsNCn4cjf9yyQ==} + + gopd@1.2.0: + resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==} + engines: {node: '>= 0.4'} + gql.tada@1.8.13: resolution: {integrity: sha512-fYoorairdPgxtE7Sf1X9/6bSN9Kt2+PN8KLg3hcF8972qFnawwUgs1OLVU8efZMHwL7EBHhhKBhrsGPlOs2lZQ==} hasBin: true @@ -1687,6 +1812,14 @@ packages: resolution: {integrity: sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==} engines: {node: '>=8'} + has-symbols@1.1.0: + resolution: {integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==} + engines: {node: '>= 0.4'} + + has-tostringtag@1.0.2: + resolution: {integrity: sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==} + engines: {node: '>= 0.4'} + hasown@2.0.2: resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} engines: {node: '>= 0.4'} @@ -2017,6 +2150,10 @@ packages: resolution: {integrity: sha512-hdN1wVrZbb29eBGiGjJbeP8JbKjq1urkHJ/LIP/NY48MZ1QVXUsQBV1G1zvYFHn1XE06cwjBsOI2K3Ulnj1YXQ==} engines: {node: '>=8'} + math-intrinsics@1.1.0: + resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==} + engines: {node: '>= 0.4'} + meow@12.1.1: resolution: {integrity: sha512-BhXM0Au22RwUneMPwSCnyhTOizdWoIEPU9sp0Aqa1PnDMR5Wv2FGXYDjuzJEIX+Eo2Rb8xuYe5jrnm5QowQFkw==} engines: {node: '>=16.10'} @@ -2033,6 +2170,14 @@ packages: resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} + mime-db@1.52.0: + resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} + engines: {node: '>= 0.6'} + + mime-types@2.1.35: + resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} + engines: {node: '>= 0.6'} + mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} engines: {node: '>=6'} @@ -2318,6 +2463,9 @@ packages: process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + proxy-from-env@1.1.0: + resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} + psl@1.15.0: resolution: {integrity: sha512-JZd3gMVBAVQkSs6HdNZo9Sdo0LNcQeMNP3CozBJb3JYC/QUYZTnKxP+f8oWRX4rHP5EurWxqAHTSwUCjlNKa1w==} @@ -2377,6 +2525,9 @@ packages: resolution: {integrity: sha512-6tDA8g98We0zd0GvVeMT9arEOnTw9qM03L9cJXaCjrip1OO764RDBLBfrB4cwzNGDj5OA5ioymC9GkizgWJDUg==} engines: {node: '>=8'} + regenerator-runtime@0.14.1: + resolution: {integrity: sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==} + require-directory@2.1.1: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} @@ -2459,6 +2610,11 @@ packages: resolution: {integrity: sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==} hasBin: true + semver@7.7.1: + resolution: {integrity: sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==} + engines: {node: '>=10'} + hasBin: true + semver@7.7.2: resolution: {integrity: sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==} engines: {node: '>=10'} @@ -2689,6 +2845,9 @@ packages: resolution: {integrity: sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==} engines: {node: '>=8'} + tronweb@6.0.4: + resolution: {integrity: sha512-+9Nc7H4FYVh2DcOnQG93WLm3UdlHSf9W+GXkfrXI77oLjTB1cptROJDKRSSxQBiOAyjjAJOOTuYDzlAkaLT85w==} + ts-api-utils@2.1.0: resolution: {integrity: sha512-CUgTZL1irw8u29bzrOD/nH85jqyc74D6SshFgujOIA7osm2Rz7dYH77agkx7H4FBNxDq7Cjf+IjaX/8zwFW+ZQ==} engines: {node: '>=18.12'} @@ -2717,6 +2876,9 @@ packages: resolution: {integrity: sha512-NoZ4roiN7LnbKn9QqE1amc9DJfzvZXxF4xDavcOWt1BPkdx+m+0gJuPM+S0vCe7zTJMYUP0R8pO2XMr+Y8oLIg==} engines: {node: '>=6'} + tslib@2.7.0: + resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==} + tslib@2.8.1: resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} @@ -2761,6 +2923,9 @@ packages: resolution: {integrity: sha512-9vqDWmoSXOoi+K14zNaf6LBV51Q8MayF0/IiQs3GlygIKUYtog603e6virExkjjFosfJUBI4LhbQK1iq8IG11A==} engines: {node: '>=14.0.0'} + undici-types@6.19.8: + resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} + undici-types@7.10.0: resolution: {integrity: sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag==} @@ -2807,6 +2972,10 @@ packages: validate-npm-package-license@3.0.4: resolution: {integrity: sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==} + validator@13.12.0: + resolution: {integrity: sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==} + engines: {node: '>= 0.10'} + varuint-bitcoin@2.0.0: resolution: {integrity: sha512-6QZbU/rHO2ZQYpWFDALCDSRsXbAs1VOEmXAxtbtjLtKuMJ/FQ8YbhfxlaiKv5nklci0M6lZtlZyxo9Q+qNnyog==} @@ -2948,6 +3117,18 @@ packages: utf-8-validate: optional: true + ws@8.17.1: + resolution: {integrity: sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==} + engines: {node: '>=10.0.0'} + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: '>=5.0.2' + peerDependenciesMeta: + bufferutil: + optional: true + utf-8-validate: + optional: true + ws@8.18.2: resolution: {integrity: sha512-DMricUmwGZUVr++AEAe2uiVM7UoO9MAVZMDu05UQOaUII0lp+zOzLLU4Xqh/JvTqklB1T4uELaaPBKyjE1r4fQ==} engines: {node: '>=10.0.0'} @@ -3050,6 +3231,8 @@ snapshots: graphql: 16.11.0 typescript: 5.9.2 + '@adraffy/ens-normalize@1.10.1': {} + '@adraffy/ens-normalize@1.11.0': {} '@ampproject/remapping@2.3.0': @@ -3071,6 +3254,10 @@ snapshots: dependencies: '@babel/types': 7.28.2 + '@babel/runtime@7.26.10': + dependencies: + regenerator-runtime: 0.14.1 + '@babel/runtime@7.28.2': {} '@babel/types@7.28.2': @@ -3485,6 +3672,14 @@ snapshots: '@noble/ciphers@1.3.0': {} + '@noble/curves@1.2.0': + dependencies: + '@noble/hashes': 1.3.2 + + '@noble/curves@1.4.2': + dependencies: + '@noble/hashes': 1.4.0 + '@noble/curves@1.9.2': dependencies: '@noble/hashes': 1.8.0 @@ -3493,6 +3688,10 @@ snapshots: dependencies: '@noble/hashes': 1.8.0 + '@noble/hashes@1.3.2': {} + + '@noble/hashes@1.4.0': {} + '@noble/hashes@1.8.0': {} '@nodelib/fs.scandir@2.1.5': @@ -3579,14 +3778,27 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.46.2': optional: true + '@scure/base@1.1.9': {} + '@scure/base@1.2.6': {} + '@scure/bip32@1.4.0': + dependencies: + '@noble/curves': 1.4.2 + '@noble/hashes': 1.4.0 + '@scure/base': 1.1.9 + '@scure/bip32@1.7.0': dependencies: '@noble/curves': 1.9.6 '@noble/hashes': 1.8.0 '@scure/base': 1.2.6 + '@scure/bip39@1.3.0': + dependencies: + '@noble/hashes': 1.4.0 + '@scure/base': 1.1.9 + '@scure/bip39@1.6.0': dependencies: '@noble/hashes': 1.8.0 @@ -3653,6 +3865,15 @@ snapshots: dependencies: tslib: 2.8.1 + '@tronweb3/tronwallet-abstract-adapter@1.1.9(bufferutil@4.0.9)(utf-8-validate@5.0.10)': + dependencies: + eventemitter3: 4.0.7 + tronweb: 6.0.4(bufferutil@4.0.9)(utf-8-validate@5.0.10) + transitivePeerDependencies: + - bufferutil + - debug + - utf-8-validate + '@ts-graphviz/adapter@2.0.6': dependencies: '@ts-graphviz/common': 2.1.5 @@ -3682,7 +3903,7 @@ snapshots: '@types/connect@3.4.38': dependencies: - '@types/node': 12.20.55 + '@types/node': 24.2.1 '@types/conventional-commits-parser@5.0.1': dependencies: @@ -3707,6 +3928,10 @@ snapshots: '@types/node@12.20.55': {} + '@types/node@22.7.5': + dependencies: + undici-types: 6.19.8 + '@types/node@24.2.1': dependencies: undici-types: 7.10.0 @@ -3721,7 +3946,7 @@ snapshots: '@types/ws@7.4.7': dependencies: - '@types/node': 12.20.55 + '@types/node': 24.2.1 '@types/ws@8.18.1': dependencies: @@ -3901,6 +4126,8 @@ snapshots: add-stream@1.0.0: {} + aes-js@4.0.0-beta.5: {} + agentkeepalive@4.6.0: dependencies: humanize-ms: 1.2.1 @@ -3956,6 +4183,16 @@ snapshots: estree-walker: 3.0.3 js-tokens: 9.0.1 + asynckit@0.4.0: {} + + axios@1.11.0: + dependencies: + follow-redirects: 1.15.11 + form-data: 4.0.4 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + balanced-match@1.0.2: {} base-x@3.0.11: @@ -3968,6 +4205,8 @@ snapshots: bech32@2.0.0: {} + bignumber.js@9.1.2: {} + bip174@3.0.0-rc.1: dependencies: uint8array-tools: 0.0.9 @@ -4044,6 +4283,11 @@ snapshots: cac@6.7.14: {} + call-bind-apply-helpers@1.0.2: + dependencies: + es-errors: 1.3.0 + function-bind: 1.1.2 + callsites@3.1.0: {} camelcase-keys@6.2.2: @@ -4122,6 +4366,10 @@ snapshots: colorette@2.0.20: {} + combined-stream@1.0.8: + dependencies: + delayed-stream: 1.0.0 + commander@12.1.0: {} commander@13.1.0: {} @@ -4330,6 +4578,8 @@ snapshots: delay@5.0.0: {} + delayed-stream@1.0.0: {} + dependency-tree@11.2.0: dependencies: commander: 12.1.0 @@ -4410,6 +4660,12 @@ snapshots: find-up: 3.0.0 minimatch: 3.1.2 + dunder-proto@1.0.1: + dependencies: + call-bind-apply-helpers: 1.0.2 + es-errors: 1.3.0 + gopd: 1.2.0 + eastasianwidth@0.2.0: {} emoji-regex@10.4.0: {} @@ -4433,8 +4689,23 @@ snapshots: dependencies: is-arrayish: 0.2.1 + es-define-property@1.0.1: {} + + es-errors@1.3.0: {} + es-module-lexer@1.7.0: {} + es-object-atoms@1.1.1: + dependencies: + es-errors: 1.3.0 + + es-set-tostringtag@2.1.0: + dependencies: + es-errors: 1.3.0 + get-intrinsic: 1.3.0 + has-tostringtag: 1.0.2 + hasown: 2.0.2 + es6-promise@4.2.8: {} es6-promisify@5.0.0: @@ -4496,6 +4767,28 @@ snapshots: esutils@2.0.3: {} + ethereum-cryptography@2.2.1: + dependencies: + '@noble/curves': 1.4.2 + '@noble/hashes': 1.4.0 + '@scure/bip32': 1.4.0 + '@scure/bip39': 1.3.0 + + ethers@6.13.5(bufferutil@4.0.9)(utf-8-validate@5.0.10): + dependencies: + '@adraffy/ens-normalize': 1.10.1 + '@noble/curves': 1.2.0 + '@noble/hashes': 1.3.2 + '@types/node': 22.7.5 + aes-js: 4.0.0-beta.5 + tslib: 2.7.0 + ws: 8.17.1(bufferutil@4.0.9)(utf-8-validate@5.0.10) + transitivePeerDependencies: + - bufferutil + - utf-8-validate + + eventemitter3@4.0.7: {} + eventemitter3@5.0.1: {} expect-type@1.2.2: {} @@ -4570,11 +4863,21 @@ snapshots: path-exists: 5.0.0 unicorn-magic: 0.1.0 + follow-redirects@1.15.11: {} + foreground-child@3.3.1: dependencies: cross-spawn: 7.0.6 signal-exit: 4.1.0 + form-data@4.0.4: + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + es-set-tostringtag: 2.1.0 + hasown: 2.0.2 + mime-types: 2.1.35 + fs-extra@11.3.1: dependencies: graceful-fs: 4.2.11 @@ -4597,6 +4900,19 @@ snapshots: get-east-asian-width@1.3.0: {} + get-intrinsic@1.3.0: + dependencies: + call-bind-apply-helpers: 1.0.2 + es-define-property: 1.0.1 + es-errors: 1.3.0 + es-object-atoms: 1.1.1 + function-bind: 1.1.2 + get-proto: 1.0.1 + gopd: 1.2.0 + has-symbols: 1.1.0 + hasown: 2.0.2 + math-intrinsics: 1.1.0 + get-own-enumerable-property-symbols@3.0.2: {} get-pkg-repo@4.2.1: @@ -4606,6 +4922,11 @@ snapshots: through2: 2.0.5 yargs: 16.2.0 + get-proto@1.0.1: + dependencies: + dunder-proto: 1.0.1 + es-object-atoms: 1.1.1 + git-raw-commits@2.0.11: dependencies: dargs: 7.0.0 @@ -4664,6 +4985,10 @@ snapshots: dependencies: minimist: 1.2.8 + google-protobuf@3.21.4: {} + + gopd@1.2.0: {} + gql.tada@1.8.13(graphql@16.11.0)(typescript@5.9.2): dependencies: '@0no-co/graphql.web': 1.2.0(graphql@16.11.0) @@ -4695,6 +5020,12 @@ snapshots: has-flag@4.0.0: {} + has-symbols@1.1.0: {} + + has-tostringtag@1.0.2: + dependencies: + has-symbols: 1.1.0 + hasown@2.0.2: dependencies: function-bind: 1.1.2 @@ -5011,6 +5342,8 @@ snapshots: map-obj@4.3.0: {} + math-intrinsics@1.1.0: {} + meow@12.1.1: {} meow@8.1.2: @@ -5034,6 +5367,12 @@ snapshots: braces: 3.0.3 picomatch: 2.3.1 + mime-db@1.52.0: {} + + mime-types@2.1.35: + dependencies: + mime-db: 1.52.0 + mimic-fn@2.1.0: {} mimic-function@5.0.1: {} @@ -5317,6 +5656,8 @@ snapshots: process-nextick-args@2.0.1: {} + proxy-from-env@1.1.0: {} + psl@1.15.0: dependencies: punycode: 2.3.1 @@ -5385,6 +5726,8 @@ snapshots: indent-string: 4.0.0 strip-indent: 3.0.0 + regenerator-runtime@0.14.1: {} + require-directory@2.1.1: {} require-from-string@2.0.2: {} @@ -5480,6 +5823,8 @@ snapshots: semver@6.3.1: {} + semver@7.7.1: {} + semver@7.7.2: {} shebang-command@2.0.0: @@ -5696,6 +6041,22 @@ snapshots: trim-newlines@3.0.1: {} + tronweb@6.0.4(bufferutil@4.0.9)(utf-8-validate@5.0.10): + dependencies: + '@babel/runtime': 7.26.10 + axios: 1.11.0 + bignumber.js: 9.1.2 + ethereum-cryptography: 2.2.1 + ethers: 6.13.5(bufferutil@4.0.9)(utf-8-validate@5.0.10) + eventemitter3: 5.0.1 + google-protobuf: 3.21.4 + semver: 7.7.1 + validator: 13.12.0 + transitivePeerDependencies: + - bufferutil + - debug + - utf-8-validate + ts-api-utils@2.1.0(typescript@5.9.2): dependencies: typescript: 5.9.2 @@ -5731,6 +6092,8 @@ snapshots: minimist: 1.2.8 strip-bom: 3.0.0 + tslib@2.7.0: {} + tslib@2.8.1: {} type-fest@0.18.1: {} @@ -5754,6 +6117,8 @@ snapshots: uint8array-tools@0.0.9: {} + undici-types@6.19.8: {} + undici-types@7.10.0: {} unicorn-magic@0.1.0: {} @@ -5789,6 +6154,8 @@ snapshots: spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 + validator@13.12.0: {} + varuint-bitcoin@2.0.0: dependencies: uint8array-tools: 0.0.8 @@ -5941,6 +6308,11 @@ snapshots: bufferutil: 4.0.9 utf-8-validate: 5.0.10 + ws@8.17.1(bufferutil@4.0.9)(utf-8-validate@5.0.10): + optionalDependencies: + bufferutil: 4.0.9 + utf-8-validate: 5.0.10 + ws@8.18.2(bufferutil@4.0.9)(utf-8-validate@5.0.10): optionalDependencies: bufferutil: 4.0.9 diff --git a/src/core/Tron/Tron.ts b/src/core/Tron/Tron.ts new file mode 100644 index 00000000..f3962ae3 --- /dev/null +++ b/src/core/Tron/Tron.ts @@ -0,0 +1,46 @@ +import type { ChainType, Token } from '@lifi/types' +import type { StepExecutor, StepExecutorOptions } from '../types.js' +import { getTronBalance } from './getTronBalance.js' +import { resolveTronAddress } from './resolveTronAddress.js' +import { TronStepExecutor } from './TronStepExecutor.js' +import type { TronProvider, TronProviderOptions } from './types.js' +import { isValidTronAddress } from './utils.js' + +export function Tron(options?: TronProviderOptions): TronProvider { + const _options: TronProviderOptions = options ?? {} + return { + get type() { + return 'TVM' as ChainType + }, + isAddress: isValidTronAddress, + resolveAddress: resolveTronAddress, + getBalance: async (walletAddress: string, tokens: Token[]) => { + const balance = await getTronBalance(walletAddress) + return tokens.map((token) => ({ + ...token, + amount: BigInt(balance), + blockNumber: 0n, + })) + }, + async getStepExecutor(options: StepExecutorOptions): Promise { + if (!_options.getWallet) { + throw new Error('getWallet is not provided.') + } + + const wallet = await _options.getWallet() + + const executor = new TronStepExecutor({ + wallet, + routeId: options.routeId, + executionOptions: { + ...options.executionOptions, + }, + }) + + return executor + }, + setOptions(options: TronProviderOptions) { + Object.assign(_options, options) + }, + } +} diff --git a/src/core/Tron/TronStepExecutor.ts b/src/core/Tron/TronStepExecutor.ts new file mode 100644 index 00000000..7ba30fed --- /dev/null +++ b/src/core/Tron/TronStepExecutor.ts @@ -0,0 +1,191 @@ +import type { Adapter } from '@tronweb3/tronwallet-abstract-adapter' +import { TronWeb } from 'tronweb' +import { config } from '../../config.js' +import { LiFiErrorCode } from '../../errors/constants.js' +import { TransactionError } from '../../errors/errors.js' +import { getStepTransaction } from '../../services/api.js' +import { BaseStepExecutor } from '../BaseStepExecutor.js' +import { checkBalance } from '../checkBalance.js' +import { stepComparison } from '../stepComparison.js' +import type { LiFiStepExtended, TransactionParameters } from '../types.js' +import { waitForDestinationChainTransaction } from '../waitForDestinationChainTransaction.js' +import type { TronStepExecutorOptions } from './types.js' +export class TronStepExecutor extends BaseStepExecutor { + private wallet: Adapter + private tronWeb: TronWeb + + constructor(options: TronStepExecutorOptions) { + super(options) + this.wallet = options.wallet + // Initialize TronWeb with default nodes + this.tronWeb = new TronWeb({ + fullNode: 'https://api.trongrid.io', + }) + } + + checkWallet = (step: LiFiStepExtended) => { + // Prevent execution of the quote by wallet different from the one which requested the quote + if (this.wallet.address !== step.action.fromAddress) { + throw new TransactionError( + LiFiErrorCode.WalletChangedDuringExecution, + 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.' + ) + } + } + + executeStep = async (step: LiFiStepExtended): Promise => { + step.execution = this.statusManager.initExecutionObject(step) + + const fromChain = await config.getChainById(step.action.fromChainId) + const toChain = await config.getChainById(step.action.toChainId) + + const isBridgeExecution = fromChain.id !== toChain.id + const currentProcessType = isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP' + + let process = this.statusManager.findOrCreateProcess({ + step, + type: currentProcessType, + chainId: fromChain.id, + }) + + if (process.status !== 'DONE') { + try { + process = this.statusManager.updateProcess( + step, + process.type, + 'STARTED' + ) + + // Check balance + await checkBalance(step.action.fromAddress!, step) + + // Create new transaction + if (!step.transactionRequest) { + // biome-ignore lint/correctness/noUnusedVariables: destructuring + const { execution, ...stepBase } = step + const updatedStep = await getStepTransaction(stepBase) + const comparedStep = await stepComparison( + this.statusManager, + step, + updatedStep, + this.allowUserInteraction, + this.executionOptions + ) + Object.assign(step, { + ...comparedStep, + execution: step.execution, + }) + } + + if (!step.transactionRequest?.data) { + throw new TransactionError( + LiFiErrorCode.TransactionUnprepared, + 'Unable to prepare transaction.' + ) + } + + process = this.statusManager.updateProcess( + step, + process.type, + 'ACTION_REQUIRED' + ) + + if (!this.allowUserInteraction) { + return step + } + + let transactionRequest: TransactionParameters = { + data: step.transactionRequest.data, + } + + if (this.executionOptions?.updateTransactionRequestHook) { + const customizedTransactionRequest: TransactionParameters = + await this.executionOptions.updateTransactionRequestHook({ + requestType: 'transaction', + ...transactionRequest, + }) + + transactionRequest = { + ...transactionRequest, + ...customizedTransactionRequest, + } + } + + const transactionRequestData = transactionRequest.data + + if (!transactionRequestData) { + throw new TransactionError( + LiFiErrorCode.TransactionUnprepared, + 'Unable to prepare transaction.' + ) + } + + this.checkWallet(step) + + // We give users 2 minutes to sign the transaction + const signedTx = await this.wallet.signTransaction( + transactionRequestData // TODO: map formats + ) + + process = this.statusManager.updateProcess( + step, + process.type, + 'PENDING' + ) + + // Broadcast the signed transaction + const result = await this.tronWeb.trx.sendRawTransaction(signedTx) + + if (!result.result) { + throw new TransactionError( + LiFiErrorCode.TransactionFailed, + `Transaction failed: ${result.message || 'Unknown error'}` + ) + } + + // Transaction has been confirmed and we can update the process + process = this.statusManager.updateProcess( + step, + process.type, + 'PENDING', + { + txHash: result.txid, + txLink: `${fromChain.metamask.blockExplorerUrls[0]}tx/${result.txid}`, + } + ) + + if (isBridgeExecution) { + process = this.statusManager.updateProcess(step, process.type, 'DONE') + } + } catch (e: any) { + const error = new TransactionError( + LiFiErrorCode.TransactionFailed, + `Transaction failed: ${e.message || 'Unknown error'}` + ) + process = this.statusManager.updateProcess( + step, + process.type, + 'FAILED', + { + error: { + message: error.message, + code: error.code, + }, + } + ) + this.statusManager.updateExecution(step, 'FAILED') + throw error + } + } + + await waitForDestinationChainTransaction( + step, + process, + fromChain, + toChain, + this.statusManager + ) + + return step + } +} diff --git a/src/core/Tron/getTronBalance.ts b/src/core/Tron/getTronBalance.ts new file mode 100644 index 00000000..a62146f2 --- /dev/null +++ b/src/core/Tron/getTronBalance.ts @@ -0,0 +1,20 @@ +import { TronWeb } from 'tronweb' + +/** + * Get the balance of a Tron address + * @param address - The Tron address to get balance for + * @returns The balance in sun (smallest unit) + */ +export async function getTronBalance(address: string): Promise { + try { + const tronWeb = new TronWeb({ + fullNode: 'https://api.trongrid.io', + }) + + // https://tronweb.network/docu/docs/API%20List/trx/getBalance/ + return await tronWeb.trx.getBalance(address) + } catch (error) { + console.error('Error getting Tron balance:', error) + return 0 + } +} diff --git a/src/core/Tron/resolveTronAddress.ts b/src/core/Tron/resolveTronAddress.ts new file mode 100644 index 00000000..37b5383f --- /dev/null +++ b/src/core/Tron/resolveTronAddress.ts @@ -0,0 +1,13 @@ +import { isValidTronAddress } from './utils.js' + +/** + * Resolve a Tron address - validates and returns the address + * @param address - The address to resolve + * @returns The resolved address + */ +export async function resolveTronAddress(address: string): Promise { + if (!isValidTronAddress(address)) { + throw new Error(`Invalid Tron address: ${address}`) + } + return address +} diff --git a/src/core/Tron/types.ts b/src/core/Tron/types.ts new file mode 100644 index 00000000..d9cba95a --- /dev/null +++ b/src/core/Tron/types.ts @@ -0,0 +1,19 @@ +import type { ChainType } from '@lifi/types' +import type { Adapter } from '@tronweb3/tronwallet-abstract-adapter' +import type { SDKProvider, StepExecutorOptions } from '../types.js' + +export interface TronProviderOptions { + getWallet?: () => Promise +} + +export interface TronProvider extends SDKProvider { + setOptions: (options: TronProviderOptions) => void +} + +export function isTron(provider: SDKProvider): provider is TronProvider { + return provider.type === ('TVM' as ChainType) +} + +export interface TronStepExecutorOptions extends StepExecutorOptions { + wallet: Adapter +} diff --git a/src/core/Tron/utils.ts b/src/core/Tron/utils.ts new file mode 100644 index 00000000..c10953c5 --- /dev/null +++ b/src/core/Tron/utils.ts @@ -0,0 +1,50 @@ +import { TronWeb } from 'tronweb' + +/** + * Check if the given address is a valid Tron address + * @param address - The address to validate + * @returns True if the address is valid, false otherwise + */ +export function isValidTronAddress(address: string): boolean { + try { + return TronWeb.isAddress(address) + } catch { + return false + } +} + +/** + * Convert a Tron address to its hex format + * @param address - The Tron address to convert + * @returns The hex format of the address + */ +export function tronAddressToHex(address: string): string { + return TronWeb.address.toHex(address) +} + +/** + * Convert a hex address to Tron address format + * @param hexAddress - The hex address to convert + * @returns The Tron address format + */ +export function hexToTronAddress(hexAddress: string): string { + return TronWeb.address.fromHex(hexAddress) +} + +/** + * Get the base58 address from a hex address + * @param hexAddress - The hex address + * @returns The base58 address + */ +export function getBase58Address(hexAddress: string): string { + return TronWeb.address.fromHex(hexAddress) +} + +/** + * Get the hex address from a base58 address + * @param base58Address - The base58 address + * @returns The hex address + */ +export function getHexAddress(base58Address: string): string { + return TronWeb.address.toHex(base58Address) +} diff --git a/src/index.ts b/src/index.ts index c61bfef7..3c6d381c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,6 +51,9 @@ export { StatusManager } from './core/StatusManager.js' export { Sui } from './core/Sui/Sui.js' export type { SuiProvider, SuiProviderOptions } from './core/Sui/types.js' export { isSui } from './core/Sui/types.js' +export { Tron } from './core/Tron/Tron.js' +export type { TronProvider, TronProviderOptions } from './core/Tron/types.js' +export { isTron } from './core/Tron/types.js' export type { AcceptExchangeRateUpdateHook, AcceptSlippageUpdateHook, diff --git a/tests/setup.ts b/tests/setup.ts index b192c791..5c256883 100644 --- a/tests/setup.ts +++ b/tests/setup.ts @@ -1,9 +1,9 @@ import { createConfig } from '../src/createConfig.js' -import { EVM, Solana, Sui, UTXO } from '../src/index.js' +import { EVM, Solana, Sui, UTXO, Tron } from '../src/index.js' export const setupTestEnvironment = () => { createConfig({ integrator: 'lifi-sdk', - providers: [EVM(), Solana(), UTXO(), Sui()], + providers: [EVM(), Solana(), UTXO(), Sui(), Tron()], }) }