Skip to content

Commit

Permalink
fix estimation; bump cosmjs versions
Browse files Browse the repository at this point in the history
  • Loading branch information
nnoln committed Sep 24, 2024
1 parent d697a86 commit 2aabd74
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 25 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@
"release:dry": "release-it --dry-run"
},
"dependencies": {
"@cosmjs/encoding": "^0.31.0",
"@cosmjs/stargate": "^0.31.3",
"@cosmjs/encoding": "^0.32.4",
"@cosmjs/stargate": "^0.32.4",
"@cosmjs/cosmwasm-stargate": "^0.32.2",
"@ethersproject/abstract-signer": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"axios": "^1.5.0",
"cosmjs-types": "^0.8.0",
"cosmjs-types": "^0.9.0",
"ethers": "6.8.1",
"ethers-multicall-provider": "^5.0.0",
"lodash": "^4.17.21",
Expand Down
12 changes: 7 additions & 5 deletions src/handlers/cosmos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { MsgDepositForBurn } from "./cctpProto";
import { TokensChains } from "../../utils/TokensChains";
import Long from "long";

export class CosmosHandler {
async validateBalance({
Expand Down Expand Up @@ -83,6 +84,7 @@ export class CosmosHandler {
}

case IBC_TRANSFER_TYPE:
cosmosMsg.value.timeoutTimestamp = Long.fromValue(cosmosMsg.value.timeoutTimestamp).toNumber()
msgs.push(cosmosMsg);

break;
Expand All @@ -100,18 +102,18 @@ export class CosmosHandler {
throw new Error(`Cosmos message ${cosmosMsg.typeUrl} not supported`);
}

// simulate tx to estimate gas cost
const estimatedGas = await signer.simulate(signerAddress, msgs, "");
const gasMultiplier = Number(route.transactionRequest?.maxFeePerGas) || 1.3;
const gasPrice = route.transactionRequest?.gasPrice as string;

let memo = "";
if (data.route.transactionRequest?.requestId) {
memo = JSON.stringify({
squidRequestId: data.route.transactionRequest?.requestId,
});
}

// simulate tx to estimate gas cost
const estimatedGas = await signer.simulate(signerAddress, msgs, memo);
const gasMultiplier = Number(route.transactionRequest?.maxFeePerGas) || 1.5;
const gasPrice = route.transactionRequest?.gasPrice as string;

return signer.sign(
signerAddress,
msgs,
Expand Down
169 changes: 152 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,32 @@
"@cosmjs/math" "^0.31.3"
"@cosmjs/utils" "^0.31.3"

"@cosmjs/amino@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/amino/-/amino-0.32.4.tgz#3908946c0394e6d431694c8992c5147079a1c860"
integrity sha512-zKYOt6hPy8obIFtLie/xtygCkH9ZROiQ12UHfKsOkWaZfPQUvVbtgmu6R4Kn1tFLI/SRkw7eqhaogmW/3NYu/Q==
dependencies:
"@cosmjs/crypto" "^0.32.4"
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/utils" "^0.32.4"

"@cosmjs/cosmwasm-stargate@^0.32.2":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/cosmwasm-stargate/-/cosmwasm-stargate-0.32.4.tgz#2ee93f2cc0b1c146ac369b2bf8ef9ee2e159fd50"
integrity sha512-Fuo9BGEiB+POJ5WeRyBGuhyKR1ordvxZGLPuPosFJOH9U0gKMgcjwKMCgAlWFkMlHaTB+tNdA8AifWiHrI7VgA==
dependencies:
"@cosmjs/amino" "^0.32.4"
"@cosmjs/crypto" "^0.32.4"
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/proto-signing" "^0.32.4"
"@cosmjs/stargate" "^0.32.4"
"@cosmjs/tendermint-rpc" "^0.32.4"
"@cosmjs/utils" "^0.32.4"
cosmjs-types "^0.9.0"
pako "^2.0.2"

"@cosmjs/crypto@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/crypto/-/crypto-0.31.3.tgz#c752cb6d682fdc735dcb45a2519f89c56ba16c26"
Expand All @@ -1083,7 +1109,20 @@
elliptic "^6.5.4"
libsodium-wrappers-sumo "^0.7.11"

"@cosmjs/encoding@^0.31.0", "@cosmjs/encoding@^0.31.0-alpha.1", "@cosmjs/encoding@^0.31.3":
"@cosmjs/crypto@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/crypto/-/crypto-0.32.4.tgz#5d29633b661eaf092ddb3e7ea6299cfd6f4507a2"
integrity sha512-zicjGU051LF1V9v7bp8p7ovq+VyC91xlaHdsFOTo2oVry3KQikp8L/81RkXmUIT8FxMwdx1T7DmFwVQikcSDIw==
dependencies:
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/utils" "^0.32.4"
"@noble/hashes" "^1"
bn.js "^5.2.0"
elliptic "^6.5.4"
libsodium-wrappers-sumo "^0.7.11"

"@cosmjs/encoding@^0.31.0-alpha.1", "@cosmjs/encoding@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.31.3.tgz#2519d9c9ae48368424971f253775c4580b54c5aa"
integrity sha512-6IRtG0fiVYwyP7n+8e54uTx2pLYijO48V3t9TLiROERm5aUAIzIlz6Wp0NYaI5he9nh1lcEGJ1lkquVKFw3sUg==
Expand All @@ -1092,6 +1131,15 @@
bech32 "^1.1.4"
readonly-date "^1.0.0"

"@cosmjs/encoding@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/encoding/-/encoding-0.32.4.tgz#646e0e809f7f4f1414d8fa991fb0ffe6c633aede"
integrity sha512-tjvaEy6ZGxJchiizzTn7HVRiyTg1i4CObRRaTRPknm5EalE13SV+TCHq38gIDfyUeden4fCuaBVEdBR5+ti7Hw==
dependencies:
base64-js "^1.3.0"
bech32 "^1.1.4"
readonly-date "^1.0.0"

"@cosmjs/json-rpc@^0.30.1":
version "0.30.1"
resolved "https://registry.yarnpkg.com/@cosmjs/json-rpc/-/json-rpc-0.30.1.tgz#16f21305fc167598c8a23a45549b85106b2372bc"
Expand All @@ -1108,14 +1156,29 @@
"@cosmjs/stream" "^0.31.3"
xstream "^11.14.0"

"@cosmjs/json-rpc@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/json-rpc/-/json-rpc-0.32.4.tgz#be91eb89ea78bd5dc02d0a9fa184dd6790790f0b"
integrity sha512-/jt4mBl7nYzfJ2J/VJ+r19c92mUKF0Lt0JxM3MXEJl7wlwW5haHAWtzRujHkyYMXOwIR+gBqT2S0vntXVBRyhQ==
dependencies:
"@cosmjs/stream" "^0.32.4"
xstream "^11.14.0"

"@cosmjs/math@^0.31.0-alpha.1", "@cosmjs/math@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.31.3.tgz#767f7263d12ba1b9ed2f01f68d857597839fd957"
integrity sha512-kZ2C6glA5HDb9hLz1WrftAjqdTBb3fWQsRR+Us2HsjAYdeE6M3VdXMsYCP5M3yiihal1WDwAY2U7HmfJw7Uh4A==
dependencies:
bn.js "^5.2.0"

"@cosmjs/proto-signing@^0.31.0-alpha.1", "@cosmjs/proto-signing@^0.31.3":
"@cosmjs/math@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/math/-/math-0.32.4.tgz#87ac9eadc06696e30a30bdb562a495974bfd0a1a"
integrity sha512-++dqq2TJkoB8zsPVYCvrt88oJWsy1vMOuSOKcdlnXuOA/ASheTJuYy4+oZlTQ3Fr8eALDLGGPhJI02W2HyAQaw==
dependencies:
bn.js "^5.2.0"

"@cosmjs/proto-signing@^0.31.0-alpha.1":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/proto-signing/-/proto-signing-0.31.3.tgz#20440b7b96fb2cd924256a10e656fd8d4481cdcd"
integrity sha512-24+10/cGl6lLS4VCrGTCJeDRPQTn1K5JfknzXzDIHOx8THR31JxA7/HV5eWGHqWgAbudA7ccdSvEK08lEHHtLA==
Expand All @@ -1128,6 +1191,18 @@
cosmjs-types "^0.8.0"
long "^4.0.0"

"@cosmjs/proto-signing@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/proto-signing/-/proto-signing-0.32.4.tgz#5a06e087c6d677439c8c9b25b5223d5e72c4cd93"
integrity sha512-QdyQDbezvdRI4xxSlyM1rSVBO2st5sqtbEIl3IX03uJ7YiZIQHyv6vaHVf1V4mapusCqguiHJzm4N4gsFdLBbQ==
dependencies:
"@cosmjs/amino" "^0.32.4"
"@cosmjs/crypto" "^0.32.4"
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/utils" "^0.32.4"
cosmjs-types "^0.9.0"

"@cosmjs/socket@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/socket/-/socket-0.31.3.tgz#52086380f4de2fc3514b90b0484b4b1c4c50e39e"
Expand All @@ -1138,6 +1213,16 @@
ws "^7"
xstream "^11.14.0"

"@cosmjs/socket@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/socket/-/socket-0.32.4.tgz#86ab6adf3a442314774c0810b7a7cfcddf4f2082"
integrity sha512-davcyYziBhkzfXQTu1l5NrpDYv0K9GekZCC9apBRvL1dvMc9F/ygM7iemHjUA+z8tJkxKxrt/YPjJ6XNHzLrkw==
dependencies:
"@cosmjs/stream" "^0.32.4"
isomorphic-ws "^4.0.1"
ws "^7"
xstream "^11.14.0"

"@cosmjs/stargate@0.31.0-alpha.1":
version "0.31.0-alpha.1"
resolved "https://registry.yarnpkg.com/@cosmjs/stargate/-/stargate-0.31.0-alpha.1.tgz#85b9d41cd5e73c3b8db73115aa1c9cd6eb5914fd"
Expand All @@ -1156,22 +1241,20 @@
protobufjs "~6.11.3"
xstream "^11.14.0"

"@cosmjs/stargate@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/stargate/-/stargate-0.31.3.tgz#a2b38e398097a00f897dbd8f02d4d347d8fed818"
integrity sha512-53NxnzmB9FfXpG4KjOUAYAvWLYKdEmZKsutcat/u2BrDXNZ7BN8jim/ENcpwXfs9/Og0K24lEIdvA4gsq3JDQw==
"@cosmjs/stargate@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/stargate/-/stargate-0.32.4.tgz#bd0e4d3bf613b629addbf5f875d3d3b50f640af1"
integrity sha512-usj08LxBSsPRq9sbpCeVdyLx2guEcOHfJS9mHGCLCXpdAPEIEQEtWLDpEUc0LEhWOx6+k/ChXTc5NpFkdrtGUQ==
dependencies:
"@confio/ics23" "^0.6.8"
"@cosmjs/amino" "^0.31.3"
"@cosmjs/encoding" "^0.31.3"
"@cosmjs/math" "^0.31.3"
"@cosmjs/proto-signing" "^0.31.3"
"@cosmjs/stream" "^0.31.3"
"@cosmjs/tendermint-rpc" "^0.31.3"
"@cosmjs/utils" "^0.31.3"
cosmjs-types "^0.8.0"
long "^4.0.0"
protobufjs "~6.11.3"
"@cosmjs/amino" "^0.32.4"
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/proto-signing" "^0.32.4"
"@cosmjs/stream" "^0.32.4"
"@cosmjs/tendermint-rpc" "^0.32.4"
"@cosmjs/utils" "^0.32.4"
cosmjs-types "^0.9.0"
xstream "^11.14.0"

"@cosmjs/stream@^0.30.1":
Expand All @@ -1188,7 +1271,14 @@
dependencies:
xstream "^11.14.0"

"@cosmjs/tendermint-rpc@^0.31.0-alpha.1", "@cosmjs/tendermint-rpc@^0.31.3":
"@cosmjs/stream@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/stream/-/stream-0.32.4.tgz#83e1f2285807467c56d9ea0e1113f79d9fa63802"
integrity sha512-Gih++NYHEiP+oyD4jNEUxU9antoC0pFSg+33Hpp0JlHwH0wXhtD3OOKnzSfDB7OIoEbrzLJUpEjOgpCp5Z+W3A==
dependencies:
xstream "^11.14.0"

"@cosmjs/tendermint-rpc@^0.31.0-alpha.1":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.31.3.tgz#d1a2bc5b3c98743631c9b55888589d352403c9b3"
integrity sha512-s3TiWkPCW4QceTQjpYqn4xttUJH36mTPqplMl+qyocdqk5+X5mergzExU/pHZRWQ4pbby8bnR7kMvG4OC1aZ8g==
Expand All @@ -1204,11 +1294,32 @@
readonly-date "^1.0.0"
xstream "^11.14.0"

"@cosmjs/tendermint-rpc@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/tendermint-rpc/-/tendermint-rpc-0.32.4.tgz#b36f9ec657498e42c97e21bb7368798ef6279752"
integrity sha512-MWvUUno+4bCb/LmlMIErLypXxy7ckUuzEmpufYYYd9wgbdCXaTaO08SZzyFM5PI8UJ/0S2AmUrgWhldlbxO8mw==
dependencies:
"@cosmjs/crypto" "^0.32.4"
"@cosmjs/encoding" "^0.32.4"
"@cosmjs/json-rpc" "^0.32.4"
"@cosmjs/math" "^0.32.4"
"@cosmjs/socket" "^0.32.4"
"@cosmjs/stream" "^0.32.4"
"@cosmjs/utils" "^0.32.4"
axios "^1.6.0"
readonly-date "^1.0.0"
xstream "^11.14.0"

"@cosmjs/utils@^0.31.0-alpha.1", "@cosmjs/utils@^0.31.3":
version "0.31.3"
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.31.3.tgz#f97bbfda35ad69e80cd5c7fe0a270cbda16db1ed"
integrity sha512-VBhAgzrrYdIe0O5IbKRqwszbQa7ZyQLx9nEQuHQ3HUplQW7P44COG/ye2n6AzCudtqxmwdX7nyX8ta1J07GoqA==

"@cosmjs/utils@^0.32.4":
version "0.32.4"
resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.32.4.tgz#a9a717c9fd7b1984d9cefdd0ef6c6f254060c671"
integrity sha512-D1Yc+Zy8oL/hkUkFUL/bwxvuDBzRGpc4cF7/SkdhxX4iHpSLgdOuTt1mhCh9+kl6NQREy9t7SYZ6xeW5gFe60w==

"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
Expand Down Expand Up @@ -2677,6 +2788,15 @@ axios@^1.5.0:
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axios@^1.6.0:
version "1.7.7"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.7.tgz#2f554296f9892a72ac8d8e4c5b79c14a91d0a47f"
integrity sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==
dependencies:
follow-redirects "^1.15.6"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

babel-jest@^28.1.3:
version "28.1.3"
resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-28.1.3.tgz#c1187258197c099072156a0a121c11ee1e3917d5"
Expand Down Expand Up @@ -3327,6 +3447,11 @@ cosmjs-types@^0.8.0:
long "^4.0.0"
protobufjs "~6.11.2"

cosmjs-types@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/cosmjs-types/-/cosmjs-types-0.9.0.tgz#c3bc482d28c7dfa25d1445093fdb2d9da1f6cfcc"
integrity sha512-MN/yUe6mkJwHnCFfsNPeCfXVhyxHYW6c/xDUzrSbBycYzw++XvWDMJArXp2pLdgD6FQ8DW79vkPjeNKVrXaHeQ==

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
Expand Down Expand Up @@ -4207,6 +4332,11 @@ follow-redirects@^1.14.0, follow-redirects@^1.15.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.3.tgz#fe2f3ef2690afce7e82ed0b44db08165b207123a"
integrity sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==

follow-redirects@^1.15.6:
version "1.15.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1"
integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==

for-each@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.3.tgz#69b447e88a0a5d32c3e7084f3f1710034b21376e"
Expand Down Expand Up @@ -6238,6 +6368,11 @@ package-json@^8.1.0:
registry-url "^6.0.0"
semver "^7.3.7"

pako@^2.0.2:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==

parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
Expand Down

0 comments on commit 2aabd74

Please sign in to comment.