From c3f42601fc1988fde5a27673472885fa81e992fa Mon Sep 17 00:00:00 2001 From: JeremyParish69 <95667791+JeremyParish69@users.noreply.github.com> Date: Tue, 4 Jun 2024 20:47:53 -0600 Subject: [PATCH 1/4] Update ibc-overrides.ts (#3299) --- packages/web/config/ibc-overrides.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/web/config/ibc-overrides.ts b/packages/web/config/ibc-overrides.ts index 41c7f191cf..af6adcbe9d 100644 --- a/packages/web/config/ibc-overrides.ts +++ b/packages/web/config/ibc-overrides.ts @@ -739,6 +739,10 @@ const MainnetIBCAdditionalData: Partial< depositUrlOverride: "https://app.picasso.network/?from=SOLANA&to=OSMOSIS", withdrawUrlOverride: "https://app.picasso.network/?from=OSMOSIS&to=SOLANA", }, + WHINE: { + depositUrlOverride: "https://app.picasso.network/?from=SOLANA&to=OSMOSIS", + withdrawUrlOverride: "https://app.picasso.network/?from=OSMOSIS&to=SOLANA", + }, }; export const IBCAdditionalData: AdditionalData = IS_TESTNET From 253d32b3188434a5e24ff13076d54675adcd16aa Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Thu, 6 Jun 2024 09:03:53 -0500 Subject: [PATCH 2/4] Gas estimation fixes (#3298) * fix invalid estimation when clearing input * fix filter spent coins by sender * feedback --- packages/tx/src/__tests__/events.spec.ts | 51 ++++++++++++++++++++++++ packages/tx/src/events.ts | 3 +- packages/tx/src/gas.ts | 12 ++++-- packages/web/hooks/use-swap.tsx | 5 ++- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/packages/tx/src/__tests__/events.spec.ts b/packages/tx/src/__tests__/events.spec.ts index 9e4bb1fb15..1fc006ca41 100644 --- a/packages/tx/src/__tests__/events.spec.ts +++ b/packages/tx/src/__tests__/events.spec.ts @@ -63,6 +63,35 @@ describe("getSumTotalSpenderCoinsSpent", () => { expect(coins).toEqual([]); }); + + it("should only total the amounts for the specified sender", () => { + const coins = getSumTotalSpenderCoinsSpent( + "osmo1gtgx92pxk6hvhc3c3g0xlkrwqq6knymu0e0caw", + mockMultipleEvents + ); + + // Expected result is the sum of the amounts for the specified sender, not for osmo13vhcd3xllpvz8tql4dzp8yszxeas8zxpzptyvjttdy7m64kuyz5sv6caqq + const expectedResult = [ + { + denom: + "factory/osmo1z0qrq605sjgcqpylfl4aa6s90x738j7m58wyatt0tdzflg2ha26q67k743/wbtc", + amount: "58573", + }, + { + denom: + "ibc/EA1D43981D5C9A1C4AAEA9C23BB1D4FA126BA9BC7020A25E0AE4AA841EA25DC5", + amount: "21083680327000100", + }, + { + denom: + "ibc/F4A070A6D78496D53127EA85C094A9EC87DFC1F36071B8CCDDBD020F933D213D", + amount: "131211643845355500", + }, + { denom: "uosmo", amount: "95799380" }, + ]; + + expect(coins).toEqual(expectedResult); + }); }); describe("matchRawCoinValue", () => { @@ -225,4 +254,26 @@ const mockMultipleEvents = [ }, ], }, + { + type: "coin_spent", + attributes: [ + { + key: "spender", + value: + "osmo13vhcd3xllpvz8tql4dzp8yszxeas8zxpzptyvjttdy7m64kuyz5sv6caqq", + index: true, + }, + { + key: "amount", + value: + "2605ibc/498A0751C798A0D9A389AA3691123DADA57DAA4FE165D5C75894505B876BA6E4", + index: true, + }, + { + key: "msg_index", + value: "0", + index: true, + }, + ], + }, ]; diff --git a/packages/tx/src/events.ts b/packages/tx/src/events.ts index 6a31b2096f..09d569e3aa 100644 --- a/packages/tx/src/events.ts +++ b/packages/tx/src/events.ts @@ -15,7 +15,8 @@ export function getSumTotalSpenderCoinsSpent( if (type !== "coin_spent") return; if (attributes.length === 0) return; const spendAttribute = attributes.find((attr) => attr.key === "spender"); - if (spendAttribute && spendAttribute.value !== spenderBech32Address) return; + if (!spendAttribute || spendAttribute.value !== spenderBech32Address) + return; // a comma separated list of coins spent const coinsSpentRawAttribute = attributes.find( diff --git a/packages/tx/src/gas.ts b/packages/tx/src/gas.ts index e45df1bebb..d6b22a9eb0 100644 --- a/packages/tx/src/gas.ts +++ b/packages/tx/src/gas.ts @@ -297,9 +297,15 @@ export async function getGasFeeAmount({ bech32Address, }), ]); - const feeBalances = balances.filter((balance) => - chainFeeDenoms.includes(balance.denom) - ); + const feeBalances: { denom: string; amount: string }[] = []; + + // iterate in order of fee denoms + for (const denom of chainFeeDenoms) { + const balance = balances.find((balance) => balance.denom === denom); + if (balance) { + feeBalances.push(balance); + } + } if (!feeBalances.length) { throw new InsufficientFeeError( diff --git a/packages/web/hooks/use-swap.tsx b/packages/web/hooks/use-swap.tsx index 2c08677612..7f60f34be1 100644 --- a/packages/web/hooks/use-swap.tsx +++ b/packages/web/hooks/use-swap.tsx @@ -201,7 +201,10 @@ export function useSwap( // includes check for quoteQueryEnabled !isQuoteLoading && Boolean(quote) && - Boolean(account?.address); + Boolean(account?.address) && + inAmountInput.debouncedInAmount !== null && + inAmountInput.balance && + inAmountInput.debouncedInAmount.toDec().lte(inAmountInput.balance.toDec()); const { data: networkFee, error: networkFeeError, From 994085f7d22819bb925cca691d6510bcc180d4e9 Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Thu, 6 Jun 2024 09:05:49 -0500 Subject: [PATCH 3/4] Swap failed events: only reject committed txs with code !== 0 (#3301) * check for tx code for rejecting promise * only reject with failed txs * make error handling more consistent * fixes --- packages/web/components/swap-tool/index.tsx | 9 ++-- packages/web/hooks/use-swap.tsx | 52 +++++++++++++-------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/packages/web/components/swap-tool/index.tsx b/packages/web/components/swap-tool/index.tsx index 44ddf41132..f752ca4ae0 100644 --- a/packages/web/components/swap-tool/index.tsx +++ b/packages/web/components/swap-tool/index.tsx @@ -222,13 +222,10 @@ export const SwapTool: FunctionComponent = observer( }); } }) - .catch((error) => { - console.error("swap failed", error); - if (error instanceof Error && error.message === "Request rejected") { - // don't log when the user rejects in wallet - return; + .catch((e) => { + if (e instanceof Error && e.message.includes("Failed to send")) { + logEvent([EventName.Swap.swapFailed, baseEvent]); } - logEvent([EventName.Swap.swapFailed, baseEvent]); }) .finally(() => { setIsSendingTx(false); diff --git a/packages/web/hooks/use-swap.tsx b/packages/web/hooks/use-swap.tsx index 7f60f34be1..d50445c57b 100644 --- a/packages/web/hooks/use-swap.tsx +++ b/packages/web/hooks/use-swap.tsx @@ -272,14 +272,18 @@ export function useSwap( () => new Promise<"multiroute" | "multihop" | "exact-in">( async (resolve, reject) => { - if (!maxSlippage) return reject("No max slippage"); - if (!inAmountInput.amount) return reject("No input amount"); - if (!account) return reject("No account"); - if (!swapAssets.fromAsset) return reject("No from asset"); - if (!swapAssets.toAsset) return reject("No to asset"); + if (!maxSlippage) + return reject(new Error("Max slippage is not defined.")); + if (!inAmountInput.amount) + return reject(new Error("Input amount is not specified.")); + if (!account) + return reject(new Error("Account information is missing.")); + if (!swapAssets.fromAsset) + return reject(new Error("From asset is not specified.")); + if (!swapAssets.toAsset) + return reject(new Error("To asset is not specified.")); let txParams: ReturnType; - try { txParams = getSwapTxParameters({ coinAmount: inAmountInput.amount.toCoin().amount, @@ -290,7 +294,9 @@ export function useSwap( }); } catch (e) { const error = e as Error; - return reject(error.message); + return reject( + new Error(`Transaction preparation failed: ${error.message}`) + ); } const { routes, tokenIn, tokenOutMinAmount } = txParams; @@ -347,7 +353,7 @@ export function useSwap( ); }); } catch (e) { - return reject("Rejected manual approval"); + return reject(new Error("Rejected manual approval")); } } @@ -376,14 +382,15 @@ export function useSwap( tokenOutMinAmount, undefined, signOptions, - () => { - resolve(pools.length === 1 ? "exact-in" : "multihop"); + ({ code }) => { + if (code) + reject( + new Error("Failed to send swap exact amount in message") + ); + else resolve(pools.length === 1 ? "exact-in" : "multihop"); } ) - .catch((reason) => { - reject(reason); - }); - return pools.length === 1 ? "exact-in" : "multihop"; + .catch(reject); } else if (routes.length > 1) { account.osmosis .sendSplitRouteSwapExactAmountInMsg( @@ -392,15 +399,20 @@ export function useSwap( tokenOutMinAmount, undefined, signOptions, - () => { - resolve("multiroute"); + ({ code }) => { + if (code) + reject( + new Error( + "Failed to send split route swap exact amount in message" + ) + ); + else resolve("multiroute"); } ) - .catch((reason) => { - reject(reason); - }); + .catch(reject); } else { - reject("No routes given"); + // should not be possible because button should be disabled + reject(new Error("No routes given")); } } ).finally(() => { From daf9beffa25a8905c3ee69e98cf6c3d6cae1e1fc Mon Sep 17 00:00:00 2001 From: yakuramori <62520712+yury-dubinin@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:37:38 +0200 Subject: [PATCH 4/4] Bump typescript to 5.4.5 (#3292) * Bump types/node and typescript * up yarn.lock --- package.json | 2 +- yarn.lock | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 4b866230ff..2b83731728 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "prettier": "^2.8.8", "ts-jest": "^29.1.2", "turbo": "^1.13.3", - "typescript": "5.4.3" + "typescript": "5.4.5" }, "packageManager": "yarn@1.22.22", "resolutions": { diff --git a/yarn.lock b/yarn.lock index 03e286395e..834a199a87 100644 --- a/yarn.lock +++ b/yarn.lock @@ -25447,12 +25447,7 @@ typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0: resolved "https://registry.npmjs.org/typeforce/-/typeforce-1.18.0.tgz" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== -typescript@5.4.3: - version "5.4.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.3.tgz#5c6fedd4c87bee01cd7a528a30145521f8e0feff" - integrity sha512-KrPd3PKaCLr78MalgiwJnA25Nm8HAmdwN3mYUYZgG/wizIo9EainNVQI9/yDavtVFRN2h3k8uf3GLHuhDMgEHg== - -"typescript@>=3 < 6", typescript@^5.4.5: +typescript@5.4.5, "typescript@>=3 < 6", typescript@^5.4.5: version "5.4.5" resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==