Cosmos adapter updates for gas and IBC (#2894)

- Combine tx amounts in cw adapter when denoms match
- Update CosmosTokenAdapters with latest from warp ui
- Fix IBC-to-warp adapter for IGP support
- Add logos for cosmos related chains
typechain11
J M Rossy 1 year ago committed by GitHub
parent bbc024abd1
commit e4ed2c3f86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      solidity/package.json
  2. 6
      typescript/helloworld/package.json
  3. 8
      typescript/infra/package.json
  4. 1
      typescript/sdk/logos/black/cosmos.svg
  5. 1
      typescript/sdk/logos/black/cosmwasm.svg
  6. 1
      typescript/sdk/logos/black/manta.svg
  7. 1
      typescript/sdk/logos/black/neutron.svg
  8. 1
      typescript/sdk/logos/color/cosmos.svg
  9. 1
      typescript/sdk/logos/color/cosmwasm.svg
  10. 1
      typescript/sdk/logos/color/manta.svg
  11. 1
      typescript/sdk/logos/color/neutron.svg
  12. 7
      typescript/sdk/package.json
  13. 1
      typescript/sdk/src/consts/chainMetadata.ts
  14. 5
      typescript/sdk/src/index.ts
  15. 33
      typescript/sdk/src/token/adapters/CosmWasmTokenAdapter.ts
  16. 171
      typescript/sdk/src/token/adapters/CosmosTokenAdapter.ts
  17. 2
      typescript/utils/package.json
  18. 25
      yarn.lock

@ -1,10 +1,10 @@
{
"name": "@hyperlane-xyz/core",
"description": "Core solidity contracts for Hyperlane",
"version": "3.1.0-beta0",
"version": "3.1.0-beta3",
"dependencies": {
"@eth-optimism/contracts": "^0.6.0",
"@hyperlane-xyz/utils": "3.1.0-beta0",
"@hyperlane-xyz/utils": "3.1.0-beta3",
"@openzeppelin/contracts": "^4.8.0",
"@openzeppelin/contracts-upgradeable": "^4.8.0"
},

@ -1,10 +1,10 @@
{
"name": "@hyperlane-xyz/helloworld",
"description": "A basic skeleton of an Hyperlane app",
"version": "3.1.0-beta0",
"version": "3.1.0-beta3",
"dependencies": {
"@hyperlane-xyz/core": "3.1.0-beta0",
"@hyperlane-xyz/sdk": "3.1.0-beta0",
"@hyperlane-xyz/core": "3.1.0-beta3",
"@hyperlane-xyz/sdk": "3.1.0-beta3",
"@openzeppelin/contracts-upgradeable": "^4.8.0",
"ethers": "^5.7.2"
},

@ -1,7 +1,7 @@
{
"name": "@hyperlane-xyz/infra",
"description": "Infrastructure utilities for the Hyperlane Network",
"version": "1.5.1",
"version": "3.1.0-beta3",
"dependencies": {
"@arbitrum/sdk": "^3.0.0",
"@aws-sdk/client-iam": "^3.74.0",
@ -11,9 +11,9 @@
"@ethersproject/experimental": "^5.7.0",
"@ethersproject/hardware-wallets": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@hyperlane-xyz/helloworld": "3.1.0-beta0",
"@hyperlane-xyz/sdk": "3.1.0-beta0",
"@hyperlane-xyz/utils": "3.1.0-beta0",
"@hyperlane-xyz/helloworld": "3.1.0-beta3",
"@hyperlane-xyz/sdk": "3.1.0-beta3",
"@hyperlane-xyz/utils": "3.1.0-beta3",
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.2.0",

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2500 2500"><circle cx="1250" cy="1250" r="1250" style="fill:#AAAAAA"/><circle cx="1250" cy="1250" r="725.3" style="fill:#000000"/><path d="M1252.6 159.5c-135 0-244.4 489.4-244.4 1093s109.4 1093.2 244.4 1093.2 244.3-489.4 244.3-1093.1-109.4-1093.1-244.3-1093.1Zm16.8 2124.5c-15.4 20.6-30.8 5.1-30.8 5.1-62.2-72-93.2-205.7-93.2-205.7-108.7-349.8-82.8-1100.8-82.8-1100.8 51-596.3 144-737.1 175.6-768.4a19.3 19.3 0 0 1 24.7-2c45.9 32.5 84.4 168.5 84.4 168.5 113.6 421.8 103.3 817.9 103.3 817.9 10.3 344.6-57 730.4-57 730.4-51.7 293.2-124.2 355-124.2 355Z" style="fill:#CCCCCC"/><path d="M2200.7 708.6c-67.2-117-546 31.6-1070 332s-893.5 638.9-826.3 756 546-31.7 1070-332 893.4-639 826.3-756ZM366.4 1780.5c-25.8-3.3-20-24.4-20-24.4 31.6-89.7 132-183.3 132-183.3 249.4-268.3 913.8-619.6 913.8-619.6 542.5-252.4 711-241.8 753.8-230a19.3 19.3 0 0 1 14 20.6c-5.1 56-104.2 157-104.2 157-309 308.6-657.8 496.8-657.8 496.8-293.8 180.5-662 314-662 314-280 101-369.6 68.8-369.6 68.8Z" style="fill:#CCCCCC"/><path d="M2198.3 1800.4c67.7-116.8-300.9-456.8-823-759.5S374.4 587.8 306.8 704.7s301 456.8 823.3 759.5 1000.6 453.2 1068.3 336.2ZM351.6 750c-10-23.8 11.2-29.5 11.2-29.5 93.4-17.6 224.7 22.6 224.7 22.6 357.1 81.3 994 480.3 994 480.3 490.3 343 565.5 494.2 576.8 537a19.3 19.3 0 0 1-10.7 22.5c-51.1 23.4-188-11.5-188-11.5-422.1-113.1-759.7-320.5-759.7-320.5-303.3-163.6-603.2-415.3-603.2-415.3-227.9-191.8-245-285.4-245-285.4Z" style="fill:#CCCCCC"/><circle cx="1250" cy="1250" r="128.6" style="fill:#b7b9c8"/><ellipse cx="1777.3" cy="756.2" rx="74.6" ry="77.2" style="fill:#b7b9c8"/><ellipse cx="553" cy="1018.5" rx="74.6" ry="77.2" style="fill:#b7b9c8"/><ellipse cx="1098.3" cy="1965" rx="74.6" ry="77.2" style="fill:#b7b9c8"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" fill="none" viewBox="0 0 50 50"><g><path fill="#000000" fill-rule="evenodd" d="M25 50c13.807 0 25-11.193 25-25S38.807 0 25 0 0 11.193 0 25s11.193 25 25 25zM13.14 12.497c.001 4.133 2.649 7.481 5.9 9.586 3.098 2.006 6.773-.072 9.917-2.005 3.975-2.442 9.131-2.69 13.447-.198a13.027 13.027 0 014.05 3.65c.306.422 1.03.221.99-.3C46.875 16.1 42.93 9.36 36.265 5.512c-2.283-1.318-2.506-1.044-2.979-.464-.714.876-1.998 2.452-11.823.293-3.037-.667-6.457.067-7.544 2.98-.49 1.314-.779 2.748-.78 4.177zm6.972 29.038c3.58-2.067 5.155-6.034 5.353-9.902.188-3.686-3.45-5.83-6.695-7.586-4.103-2.221-6.896-6.563-6.896-11.547 0-1.898.407-3.702 1.136-5.332.213-.477-.323-1.003-.753-.707C6.365 10.517 2.5 17.306 2.5 25.001c0 2.636.348 2.692 1.087 2.811 1.116.18 3.123.505 6.166 10.093.94 2.964 3.286 5.559 6.353 5.043 1.382-.233 2.768-.699 4.006-1.413zM30.52 21.297c3.448-1.763 7.671-2.382 11.251-.316 1.238.715 2.335 1.683 3.227 2.763 1.98 2.398.906 5.727-1.19 8.024-6.783 7.428-6.06 9.329-5.658 10.386.266.7.391 1.03-1.892 2.347-6.664 3.848-14.475 3.895-20.934.82-.472-.224-.284-.952.236-1.006a13.026 13.026 0 005.185-1.682c4.316-2.492 6.68-7.082 6.552-11.745-.101-3.69-.064-7.911 3.223-9.591z" clip-rule="evenodd"></path></g><defs><linearGradient id="paint0_linear_2832_1883" x1="9.3" x2="41.3" y1="2.1" y2="47.7" gradientUnits="userSpaceOnUse"><stop stop-color="#FCECB2" style="--darkreader-inline-stopcolor: #473903;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.26" stop-color="#FF8B89" style="--darkreader-inline-stopcolor: #7a0200;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.521" stop-color="#FC8ADC" style="--darkreader-inline-stopcolor: #780357;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.755" stop-color="#7954FF" style="--darkreader-inline-stopcolor: #21009a;" data-darkreader-inline-stopcolor=""></stop><stop offset="1" stop-color="#70BCFF" style="--darkreader-inline-stopcolor: #004989;" data-darkreader-inline-stopcolor=""></stop></linearGradient></defs></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="0 0 200 200" viewBox="0 0 200 200"><path d="M46.5 171.7A89.3 89.3 0 0 1 100 10.5c40.8 0 85.3 24.4 96 61.7a100 100 0 1 0 4 27.8v-5.3h-5.5a95.6 95.6 0 0 1-3.5 0l-9.3-.6c-7.5-.7-16-2-21.9-4.3a59.8 59.8 0 0 1-20.7-14.5l-.4-.3a86 86 0 0 0-24.6-18 54.6 54.6 0 0 0-34-2.6A86 86 0 0 0 65 59.1c-4.8 2-9.4 4.4-14 6.6A615.3 615.3 0 0 0 68 70.9a53 53 0 0 1 8.7 4.4c4.8 3.2 8.9 7.1 10.5 12A75 75 0 0 0 60 97.3a112 112 0 0 0-13.7 9.5l-10 8.8s12.2 1.3 18.1 2.5c4 .7 9.3 2 14.9 4s11.3 4.5 16 7.8a26 26 0 0 1 9.8 11.4c5 12.6 0 25-9.7 31.9-9.6 6.9-24.3 8.5-38.9-1.6zm34.1 15.7c4-1.3 7.6-3.2 11-5.5a37 37 0 0 0 13.3-44.3c-2.7-7-7.9-12.3-13.6-16.3-5.8-4-12.4-7-18.5-9-4-1.5-8-2.6-11.4-3.4l4-2.4a58.5 58.5 0 0 1 28-9.1c14.8 0 25.8 4.5 36.2 9.3l3 1.4c9.3 4.4 19.1 9 30.6 9 11 0 19.7-3.1 25.6-6.4a89.5 89.5 0 0 1-108.2 76.7zm96.9-83.1a44 44 0 0 1-14.3 2.3c-9 0-16.7-3.6-26.5-8.2l-2.6-1.2A95.4 95.4 0 0 0 98 87a33.4 33.4 0 0 0-17.8-21.8l2-.5a44.2 44.2 0 0 1 27.3 1.9 76 76 0 0 1 22 16.1l.2.2a70 70 0 0 0 24.1 16.7 86.5 86.5 0 0 0 21.6 4.7z" /></svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="-6 -6 66 66" fill="none"> <path fill-rule="evenodd" clip-rule="evenodd" d="M56 0H3.96053L19.2503 18.0319C21.5854 15.9808 24.6472 14.737 27.9996 14.737C35.3246 14.737 41.2627 20.6752 41.2627 28.0002C41.2627 31.2952 40.0612 34.3096 38.0723 36.629L55.9999 52.1316L56 56V0ZM49.2762 56L35.0564 39.2322C33.0127 40.519 30.5931 41.2634 27.9996 41.2634C20.6745 41.2634 14.7364 35.3252 14.7364 28.0002C14.7364 25.4215 15.4723 23.0147 16.7456 20.9783L0 6.53947V56L49.2762 56Z" fill="black"/> </svg>

After

Width:  |  Height:  |  Size: 559 B

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2500 2500"><circle cx="1250" cy="1250" r="1250" style="fill:#2e3148;--darkreader-inline-fill:#c3beb6"/><circle cx="1250" cy="1250" r="725.3" style="fill:#1b1e36;--darkreader-inline-fill:#cecac4"/><path d="M1252.6 159.5c-135 0-244.4 489.4-244.4 1093s109.4 1093.2 244.4 1093.2 244.3-489.4 244.3-1093.1-109.4-1093.1-244.3-1093.1Zm16.8 2124.5c-15.4 20.6-30.8 5.1-30.8 5.1-62.2-72-93.2-205.7-93.2-205.7-108.7-349.8-82.8-1100.8-82.8-1100.8 51-596.3 144-737.1 175.6-768.4a19.3 19.3 0 0 1 24.7-2c45.9 32.5 84.4 168.5 84.4 168.5 113.6 421.8 103.3 817.9 103.3 817.9 10.3 344.6-57 730.4-57 730.4-51.7 293.2-124.2 355-124.2 355Z" style="fill:#6f7390;--darkreader-inline-fill:#988f81"/><path d="M2200.7 708.6c-67.2-117-546 31.6-1070 332s-893.5 638.9-826.3 756 546-31.7 1070-332 893.4-639 826.3-756ZM366.4 1780.5c-25.8-3.3-20-24.4-20-24.4 31.6-89.7 132-183.3 132-183.3 249.4-268.3 913.8-619.6 913.8-619.6 542.5-252.4 711-241.8 753.8-230a19.3 19.3 0 0 1 14 20.6c-5.1 56-104.2 157-104.2 157-309 308.6-657.8 496.8-657.8 496.8-293.8 180.5-662 314-662 314-280 101-369.6 68.8-369.6 68.8Z" style="fill:#6f7390;--darkreader-inline-fill:#988f81"/><path d="M2198.3 1800.4c67.7-116.8-300.9-456.8-823-759.5S374.4 587.8 306.8 704.7s301 456.8 823.3 759.5 1000.6 453.2 1068.3 336.2ZM351.6 750c-10-23.8 11.2-29.5 11.2-29.5 93.4-17.6 224.7 22.6 224.7 22.6 357.1 81.3 994 480.3 994 480.3 490.3 343 565.5 494.2 576.8 537a19.3 19.3 0 0 1-10.7 22.5c-51.1 23.4-188-11.5-188-11.5-422.1-113.1-759.7-320.5-759.7-320.5-303.3-163.6-603.2-415.3-603.2-415.3-227.9-191.8-245-285.4-245-285.4Z" style="fill:#6f7390;--darkreader-inline-fill:#988f81"/><circle cx="1250" cy="1250" r="128.6" style="fill:#b7b9c8;--darkreader-inline-fill:#c0bab2"/><ellipse cx="1777.3" cy="756.2" rx="74.6" ry="77.2" style="fill:#b7b9c8;--darkreader-inline-fill:#c0bab2"/><ellipse cx="553" cy="1018.5" rx="74.6" ry="77.2" style="fill:#b7b9c8;--darkreader-inline-fill:#c0bab2"/><ellipse cx="1098.3" cy="1965" rx="74.6" ry="77.2" style="fill:#b7b9c8;--darkreader-inline-fill:#c0bab2"/></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" fill="none" viewBox="0 0 50 50"><g><path fill="url(#paint0_linear_2832_1883)" fill-rule="evenodd" d="M25 50c13.807 0 25-11.193 25-25S38.807 0 25 0 0 11.193 0 25s11.193 25 25 25zM13.14 12.497c.001 4.133 2.649 7.481 5.9 9.586 3.098 2.006 6.773-.072 9.917-2.005 3.975-2.442 9.131-2.69 13.447-.198a13.027 13.027 0 014.05 3.65c.306.422 1.03.221.99-.3C46.875 16.1 42.93 9.36 36.265 5.512c-2.283-1.318-2.506-1.044-2.979-.464-.714.876-1.998 2.452-11.823.293-3.037-.667-6.457.067-7.544 2.98-.49 1.314-.779 2.748-.78 4.177zm6.972 29.038c3.58-2.067 5.155-6.034 5.353-9.902.188-3.686-3.45-5.83-6.695-7.586-4.103-2.221-6.896-6.563-6.896-11.547 0-1.898.407-3.702 1.136-5.332.213-.477-.323-1.003-.753-.707C6.365 10.517 2.5 17.306 2.5 25.001c0 2.636.348 2.692 1.087 2.811 1.116.18 3.123.505 6.166 10.093.94 2.964 3.286 5.559 6.353 5.043 1.382-.233 2.768-.699 4.006-1.413zM30.52 21.297c3.448-1.763 7.671-2.382 11.251-.316 1.238.715 2.335 1.683 3.227 2.763 1.98 2.398.906 5.727-1.19 8.024-6.783 7.428-6.06 9.329-5.658 10.386.266.7.391 1.03-1.892 2.347-6.664 3.848-14.475 3.895-20.934.82-.472-.224-.284-.952.236-1.006a13.026 13.026 0 005.185-1.682c4.316-2.492 6.68-7.082 6.552-11.745-.101-3.69-.064-7.911 3.223-9.591z" clip-rule="evenodd"></path></g><defs><linearGradient id="paint0_linear_2832_1883" x1="9.3" x2="41.3" y1="2.1" y2="47.7" gradientUnits="userSpaceOnUse"><stop stop-color="#FCECB2" style="--darkreader-inline-stopcolor: #473903;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.26" stop-color="#FF8B89" style="--darkreader-inline-stopcolor: #7a0200;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.521" stop-color="#FC8ADC" style="--darkreader-inline-stopcolor: #780357;" data-darkreader-inline-stopcolor=""></stop><stop offset="0.755" stop-color="#7954FF" style="--darkreader-inline-stopcolor: #21009a;" data-darkreader-inline-stopcolor=""></stop><stop offset="1" stop-color="#70BCFF" style="--darkreader-inline-stopcolor: #004989;" data-darkreader-inline-stopcolor=""></stop></linearGradient></defs></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="enable-background:new 0 0 200 200" viewBox="0 0 200 200"><linearGradient id="a" x1="0" x2="200.1" y1="101.8" y2="98.2" gradientUnits="userSpaceOnUse"><stop offset="0" style="stop-color:#29ccb9"/><stop offset=".5" style="stop-color:#0091ff"/><stop offset="1" style="stop-color:#ff66b7"/></linearGradient><path d="M46.5 171.7A89.3 89.3 0 0 1 100 10.5c40.8 0 85.3 24.4 96 61.7a100 100 0 1 0 4 27.8v-5.3h-5.5a95.6 95.6 0 0 1-3.5 0l-9.3-.6c-7.5-.7-16-2-21.9-4.3a59.8 59.8 0 0 1-20.7-14.5l-.4-.3a86 86 0 0 0-24.6-18 54.6 54.6 0 0 0-34-2.6A86 86 0 0 0 65 59.1c-4.8 2-9.4 4.4-14 6.6A615.3 615.3 0 0 0 68 70.9a53 53 0 0 1 8.7 4.4c4.8 3.2 8.9 7.1 10.5 12A75 75 0 0 0 60 97.3a112 112 0 0 0-13.7 9.5l-10 8.8s12.2 1.3 18.1 2.5c4 .7 9.3 2 14.9 4s11.3 4.5 16 7.8a26 26 0 0 1 9.8 11.4c5 12.6 0 25-9.7 31.9-9.6 6.9-24.3 8.5-38.9-1.6zm34.1 15.7c4-1.3 7.6-3.2 11-5.5a37 37 0 0 0 13.3-44.3c-2.7-7-7.9-12.3-13.6-16.3-5.8-4-12.4-7-18.5-9-4-1.5-8-2.6-11.4-3.4l4-2.4a58.5 58.5 0 0 1 28-9.1c14.8 0 25.8 4.5 36.2 9.3l3 1.4c9.3 4.4 19.1 9 30.6 9 11 0 19.7-3.1 25.6-6.4a89.5 89.5 0 0 1-108.2 76.7zm96.9-83.1a44 44 0 0 1-14.3 2.3c-9 0-16.7-3.6-26.5-8.2l-2.6-1.2A95.4 95.4 0 0 0 98 87a33.4 33.4 0 0 0-17.8-21.8l2-.5a44.2 44.2 0 0 1 27.3 1.9 76 76 0 0 1 22 16.1l.2.2a70 70 0 0 0 24.1 16.7 86.5 86.5 0 0 0 21.6 4.7z" style="fill-rule:evenodd;clip-rule:evenodd;fill:url(#a)"/></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" viewBox="-6 -6 66 66" fill="none"> <path fill-rule="evenodd" clip-rule="evenodd" d="M56 0H3.96053L19.2503 18.0319C21.5854 15.9808 24.6472 14.737 27.9996 14.737C35.3246 14.737 41.2627 20.6752 41.2627 28.0002C41.2627 31.2952 40.0612 34.3096 38.0723 36.629L55.9999 52.1316L56 56V0ZM49.2762 56L35.0564 39.2322C33.0127 40.519 30.5931 41.2634 27.9996 41.2634C20.6745 41.2634 14.7364 35.3252 14.7364 28.0002C14.7364 25.4215 15.4723 23.0147 16.7456 20.9783L0 6.53947V56L49.2762 56Z" fill="black"/> </svg>

After

Width:  |  Height:  |  Size: 559 B

@ -1,17 +1,18 @@
{
"name": "@hyperlane-xyz/sdk",
"description": "The official SDK for the Hyperlane Network",
"version": "3.1.0-beta0",
"version": "3.1.0-beta3",
"dependencies": {
"@cosmjs/cosmwasm-stargate": "^0.31.3",
"@cosmjs/stargate": "^0.31.3",
"@hyperlane-xyz/core": "3.1.0-beta0",
"@hyperlane-xyz/utils": "3.1.0-beta0",
"@hyperlane-xyz/core": "3.1.0-beta3",
"@hyperlane-xyz/utils": "3.1.0-beta3",
"@solana/spl-token": "^0.3.8",
"@solana/web3.js": "^1.78.0",
"@types/coingecko-api": "^1.0.10",
"@types/debug": "^4.1.7",
"@wagmi/chains": "^0.2.6",
"bignumber.js": "^9.1.1",
"coingecko-api": "^1.0.10",
"cosmjs-types": "^0.9.0",
"cross-fetch": "^3.1.5",

@ -814,6 +814,7 @@ export const neutron: ChainMetadata = {
{
name: 'Mintscan',
url: 'https://www.mintscan.io/neutron',
// TODO API not actually supported, using url to meet validation requirements
apiUrl: 'https://www.mintscan.io/neutron',
family: ExplorerFamily.Other,
},

@ -294,6 +294,11 @@ export {
CwNativeTokenAdapter,
CwTokenAdapter,
} from './token/adapters/CosmWasmTokenAdapter';
export {
CosmIbcToWarpTokenAdapter,
CosmIbcTokenAdapter,
CosmNativeTokenAdapter,
} from './token/adapters/CosmosTokenAdapter';
export {
EvmHypCollateralAdapter,
EvmHypSyntheticAdapter,

@ -1,5 +1,6 @@
import { ExecuteInstruction } from '@cosmjs/cosmwasm-stargate';
import { Coin } from '@cosmjs/stargate';
import BigNumber from 'bignumber.js';
import {
Address,
@ -370,8 +371,27 @@ export class CwHypNativeAdapter
if (!txValue) {
throw new Error('txValue is required for native tokens');
}
const collateralDenom = await this.denom();
const funds: Coin[] =
collateralDenom === this.gasDenom
? [
{
amount: new BigNumber(weiAmountOrId).plus(txValue).toFixed(0),
denom: collateralDenom,
},
]
: [
{
amount: weiAmountOrId.toString(),
denom: collateralDenom,
},
{
amount: txValue.toString(),
denom: this.gasDenom,
},
];
return this.cw20adapter.prepareRouter(
{
transfer_remote: {
@ -380,16 +400,7 @@ export class CwHypNativeAdapter
amount: weiAmountOrId.toString(),
},
},
[
{
amount: weiAmountOrId.toString(),
denom: collateralDenom,
},
{
amount: txValue.toString(),
denom: this.gasDenom,
},
],
funds,
);
}
}

@ -1,31 +1,44 @@
import { MsgTransferEncodeObject } from '@cosmjs/stargate';
import { MsgTransfer } from 'cosmjs-types/ibc/applications/transfer/v1/tx';
import Long from 'long';
import { Address } from '@hyperlane-xyz/utils';
import { Address, Domain } from '@hyperlane-xyz/utils';
import { BaseCosmosAdapter } from '../../app/MultiProtocolApp';
import { MultiProtocolProvider } from '../../providers/MultiProtocolProvider';
import { ChainName } from '../../types';
import { MinimalTokenMetadata } from '../config';
import { ITokenAdapter, TransferParams } from './ITokenAdapter';
import { CwHypCollateralAdapter } from './CosmWasmTokenAdapter';
import {
IHypTokenAdapter,
ITokenAdapter,
TransferParams,
TransferRemoteParams,
} from './ITokenAdapter';
// Interacts with IBC denom tokens
export class NativeTokenAdapter
const COSMOS_IBC_TRANSFER_TIMEOUT = 600_000; // 10 minutes
// Interacts with native tokens on a Cosmos chain (e.g TIA on Celestia)
export class CosmNativeTokenAdapter
extends BaseCosmosAdapter
implements ITokenAdapter
{
constructor(
public readonly chainName: string,
public readonly chainName: ChainName,
public readonly multiProvider: MultiProtocolProvider,
public readonly addresses: Record<string, Address>,
public readonly ibcDenom: string = 'untrn',
public readonly properties: {
ibcDenom: string;
},
) {
if (!properties.ibcDenom)
throw new Error('Missing properties for CosmNativeTokenAdapter');
super(chainName, multiProvider, addresses);
}
async getBalance(address: string): Promise<string> {
const provider = await this.getProvider();
const coin = await provider.getBalance(address, this.ibcDenom);
const coin = await provider.getBalance(address, this.properties.ibcDenom);
return coin.amount;
}
@ -38,28 +51,140 @@ export class NativeTokenAdapter
}
async populateTransferTx(
transferParams: TransferParams,
_transferParams: TransferParams,
): Promise<MsgTransferEncodeObject> {
throw new Error('TODO not yet implemented');
}
}
// Interacts with native tokens on a Cosmos chain and adds support for IBC transfers
// This implements the IHypTokenAdapter interface but it's an imperfect fit as some
// methods don't apply to IBC transfers the way they do for Warp transfers
export class CosmIbcTokenAdapter
extends CosmNativeTokenAdapter
implements IHypTokenAdapter
{
constructor(
public readonly chainName: ChainName,
public readonly multiProvider: MultiProtocolProvider,
public readonly addresses: Record<string, Address>,
public readonly properties: {
ibcDenom: string;
sourcePort: string;
sourceChannel: string;
},
) {
if (
!properties.ibcDenom ||
!properties.sourcePort ||
!properties.sourceChannel
)
throw new Error('Missing properties for CosmNativeIbcTokenAdapter');
super(chainName, multiProvider, addresses, properties);
}
getDomains(): Promise<Domain[]> {
throw new Error('Method not applicable to IBC adapters');
}
getRouterAddress(_domain: Domain): Promise<Buffer> {
throw new Error('Method not applicable to IBC adapters');
}
getAllRouters(): Promise<
Array<{
domain: Domain;
address: Buffer;
}>
> {
throw new Error('Method not applicable to IBC adapters');
}
quoteGasPayment(_destination: Domain): Promise<string> {
throw new Error('Method not applicable to IBC adapters');
}
async populateTransferRemoteTx(
transferParams: TransferRemoteParams,
memo = '',
): Promise<MsgTransferEncodeObject> {
const transfer: MsgTransfer = {
sourcePort: '',
sourceChannel: '',
if (!transferParams.fromAccountOwner)
throw new Error('fromAccountOwner is required for ibc transfers');
const value = {
sourcePort: this.properties.sourcePort,
sourceChannel: this.properties.sourceChannel,
token: {
denom: this.ibcDenom,
denom: this.properties.ibcDenom,
amount: transferParams.weiAmountOrId.toString(),
},
sender: '',
receiver: '',
timeoutHeight: {
revisionNumber: 0n,
revisionHeight: 0n,
},
timeoutTimestamp: 0n,
memo: '', // how to encode this?
sender: transferParams.fromAccountOwner,
receiver: transferParams.recipient,
// Represented as nano-seconds
timeoutTimestamp: Long.fromNumber(
new Date().getTime() + COSMOS_IBC_TRANSFER_TIMEOUT,
).multiply(1_000_000),
memo,
};
return {
typeUrl: '/ibc.applications.transfer.v1.MsgTransfer',
// @ts-ignore
value: transfer,
value,
};
}
}
// A wrapper for the CosmIbcTokenAdapter that adds support auto-initiated warp transfers
// A.k.a. 'One-Click' cosmos to evm transfers
export class CosmIbcToWarpTokenAdapter
extends CosmIbcTokenAdapter
implements IHypTokenAdapter
{
constructor(
public readonly chainName: ChainName,
public readonly multiProvider: MultiProtocolProvider,
public readonly addresses: {
intermediateRouterAddress: Address;
destinationRouterAddress: Address;
},
public readonly properties: CosmIbcTokenAdapter['properties'] & {
derivedIbcDenom: string;
intermediateChainName: ChainName;
},
) {
super(chainName, multiProvider, addresses, properties);
}
async populateTransferRemoteTx(
transferParams: TransferRemoteParams,
): Promise<MsgTransferEncodeObject> {
const cwAdapter = new CwHypCollateralAdapter(
this.properties.intermediateChainName,
this.multiProvider,
{
token: this.properties.derivedIbcDenom,
warpRouter: this.addresses.intermediateRouterAddress,
},
this.properties.derivedIbcDenom,
);
const transfer = await cwAdapter.populateTransferRemoteTx(transferParams);
const cwMemo = {
wasm: {
contract: transfer.contractAddress,
msg: transfer.msg,
funds: transfer.funds,
},
};
const memo = JSON.stringify(cwMemo);
if (transfer.funds?.length !== 1) {
// Only transfers where the interchain gas denom matches the token are currently supported
throw new Error('Expected exactly one denom for IBC to Warp transfer');
}
// Grab amount from the funds details which accounts for interchain gas
const weiAmountOrId = transfer.funds[0].amount;
return super.populateTransferRemoteTx(
{
...transferParams,
weiAmountOrId,
recipient: this.addresses.intermediateRouterAddress,
},
memo,
);
}
}

@ -1,7 +1,7 @@
{
"name": "@hyperlane-xyz/utils",
"description": "General utilities and types for the Hyperlane network",
"version": "3.1.0-beta0",
"version": "3.1.0-beta3",
"dependencies": {
"@cosmjs/encoding": "^0.31.3",
"@solana/web3.js": "^1.78.0",

@ -4097,12 +4097,12 @@ __metadata:
languageName: node
linkType: hard
"@hyperlane-xyz/core@3.1.0-beta0, @hyperlane-xyz/core@workspace:solidity":
"@hyperlane-xyz/core@3.1.0-beta3, @hyperlane-xyz/core@workspace:solidity":
version: 0.0.0-use.local
resolution: "@hyperlane-xyz/core@workspace:solidity"
dependencies:
"@eth-optimism/contracts": ^0.6.0
"@hyperlane-xyz/utils": 3.1.0-beta0
"@hyperlane-xyz/utils": 3.1.0-beta3
"@nomiclabs/hardhat-ethers": ^2.2.1
"@nomiclabs/hardhat-waffle": ^2.0.3
"@openzeppelin/contracts": ^4.8.0
@ -4125,12 +4125,12 @@ __metadata:
languageName: unknown
linkType: soft
"@hyperlane-xyz/helloworld@3.1.0-beta0, @hyperlane-xyz/helloworld@workspace:typescript/helloworld":
"@hyperlane-xyz/helloworld@3.1.0-beta3, @hyperlane-xyz/helloworld@workspace:typescript/helloworld":
version: 0.0.0-use.local
resolution: "@hyperlane-xyz/helloworld@workspace:typescript/helloworld"
dependencies:
"@hyperlane-xyz/core": 3.1.0-beta0
"@hyperlane-xyz/sdk": 3.1.0-beta0
"@hyperlane-xyz/core": 3.1.0-beta3
"@hyperlane-xyz/sdk": 3.1.0-beta3
"@nomiclabs/hardhat-ethers": ^2.2.1
"@nomiclabs/hardhat-waffle": ^2.0.3
"@openzeppelin/contracts-upgradeable": ^4.8.0
@ -4170,9 +4170,9 @@ __metadata:
"@ethersproject/experimental": ^5.7.0
"@ethersproject/hardware-wallets": ^5.7.0
"@ethersproject/providers": ^5.7.2
"@hyperlane-xyz/helloworld": 3.1.0-beta0
"@hyperlane-xyz/sdk": 3.1.0-beta0
"@hyperlane-xyz/utils": 3.1.0-beta0
"@hyperlane-xyz/helloworld": 3.1.0-beta3
"@hyperlane-xyz/sdk": 3.1.0-beta3
"@hyperlane-xyz/utils": 3.1.0-beta3
"@nomiclabs/hardhat-ethers": ^2.2.1
"@nomiclabs/hardhat-etherscan": ^3.0.3
"@nomiclabs/hardhat-waffle": ^2.0.3
@ -4216,14 +4216,14 @@ __metadata:
languageName: unknown
linkType: soft
"@hyperlane-xyz/sdk@3.1.0-beta0, @hyperlane-xyz/sdk@workspace:typescript/sdk":
"@hyperlane-xyz/sdk@3.1.0-beta3, @hyperlane-xyz/sdk@workspace:typescript/sdk":
version: 0.0.0-use.local
resolution: "@hyperlane-xyz/sdk@workspace:typescript/sdk"
dependencies:
"@cosmjs/cosmwasm-stargate": ^0.31.3
"@cosmjs/stargate": ^0.31.3
"@hyperlane-xyz/core": 3.1.0-beta0
"@hyperlane-xyz/utils": 3.1.0-beta0
"@hyperlane-xyz/core": 3.1.0-beta3
"@hyperlane-xyz/utils": 3.1.0-beta3
"@nomiclabs/hardhat-ethers": ^2.2.1
"@nomiclabs/hardhat-waffle": ^2.0.3
"@solana/spl-token": ^0.3.8
@ -4233,6 +4233,7 @@ __metadata:
"@types/node": ^16.9.1
"@types/ws": ^8.5.5
"@wagmi/chains": ^0.2.6
bignumber.js: ^9.1.1
chai: ^4.3.6
coingecko-api: ^1.0.10
cosmjs-types: ^0.9.0
@ -4253,7 +4254,7 @@ __metadata:
languageName: unknown
linkType: soft
"@hyperlane-xyz/utils@3.1.0-beta0, @hyperlane-xyz/utils@workspace:typescript/utils":
"@hyperlane-xyz/utils@3.1.0-beta3, @hyperlane-xyz/utils@workspace:typescript/utils":
version: 0.0.0-use.local
resolution: "@hyperlane-xyz/utils@workspace:typescript/utils"
dependencies:

Loading…
Cancel
Save