From 0cf6c6c18d9cc9f62d65cccc752cb589ab81dabb Mon Sep 17 00:00:00 2001 From: harvin <648800939@qq.com> Date: Thu, 27 Jun 2024 21:18:32 +0800 Subject: [PATCH] upgrade chainRegistry --- examples/swap-tokens/config/assets.ts | 39 +-- examples/swap-tokens/hooks/usePrices.ts | 29 +- examples/swap-tokens/hooks/useSwap.tsx | 346 +++++++++++++++++------- examples/swap-tokens/package.json | 4 +- examples/swap-tokens/yarn.lock | 62 ++--- 5 files changed, 316 insertions(+), 164 deletions(-) diff --git a/examples/swap-tokens/config/assets.ts b/examples/swap-tokens/config/assets.ts index c42ac3802..ae94103d1 100644 --- a/examples/swap-tokens/config/assets.ts +++ b/examples/swap-tokens/config/assets.ts @@ -1,6 +1,6 @@ import { chains } from 'chain-registry'; import { Asset } from '@chain-registry/types'; -import { CoinDenom } from '@chain-registry/utils'; +import { CoinDenom } from '@osmonauts/math/dist/types'; import { assets, asset_list } from '@chain-registry/osmosis'; import { CoinGeckoId } from '@/hooks'; import { defaultChainName } from '@/config'; @@ -10,24 +10,29 @@ export type Assets = Asset[] & { CoinGeckoIds: CoinGeckoId[]; CoinDenomToAsset: Record; CoinGeckoIdToAsset: Record; -} +}; -export const OsmosisAssets = [ - ...assets.assets, - ...asset_list.assets -].filter(({ type_asset }) => type_asset !== 'ics20') as Assets; +export const OsmosisAssets = [...assets.assets, ...asset_list.assets].filter( + ({ type_asset }) => type_asset !== 'ics20' +) as Assets; -OsmosisAssets.WithCoinGeckoId = OsmosisAssets - .filter(({ coingecko_id }) => Boolean(coingecko_id)); +OsmosisAssets.WithCoinGeckoId = OsmosisAssets.filter(({ coingecko_id }) => + Boolean(coingecko_id) +); -OsmosisAssets.CoinGeckoIds = OsmosisAssets.WithCoinGeckoId - .map(({ coingecko_id }) => coingecko_id) as CoinGeckoId[]; +OsmosisAssets.CoinGeckoIds = OsmosisAssets.WithCoinGeckoId.map( + ({ coingecko_id }) => coingecko_id +) as CoinGeckoId[]; -OsmosisAssets.CoinGeckoIdToAsset = OsmosisAssets.WithCoinGeckoId - .reduce((cache, asset) => ({ ...cache, [asset.coingecko_id!]: asset }), {}) +OsmosisAssets.CoinGeckoIdToAsset = OsmosisAssets.WithCoinGeckoId.reduce( + (cache, asset) => ({ ...cache, [asset.coingecko_id!]: asset }), + {} +); -OsmosisAssets.CoinDenomToAsset = OsmosisAssets - .reduce((cache, asset) => ({ ...cache, [asset.base]: asset }), {}); +OsmosisAssets.CoinDenomToAsset = OsmosisAssets.reduce( + (cache, asset) => ({ ...cache, [asset.base]: asset }), + {} +); function getChainByDenom(denom: CoinDenom) { let chainName = ''; @@ -39,10 +44,10 @@ function getChainByDenom(denom: CoinDenom) { } return chainName ? chains.find(({ chain_name }) => chain_name === chainName) - : null + : null; } export const Osmosis = { getChainByDenom, - Assets: OsmosisAssets -} \ No newline at end of file + Assets: OsmosisAssets, +}; diff --git a/examples/swap-tokens/hooks/usePrices.ts b/examples/swap-tokens/hooks/usePrices.ts index 87a7ad0d6..037ae6575 100644 --- a/examples/swap-tokens/hooks/usePrices.ts +++ b/examples/swap-tokens/hooks/usePrices.ts @@ -1,6 +1,6 @@ -import { useQuery, UseQueryResult } from "@tanstack/react-query"; -import { PriceHash } from '@chain-registry/utils'; -import { Osmosis } from "@/config"; +import { useQuery, UseQueryResult } from '@tanstack/react-query'; +import { PriceHash } from '@osmonauts/math/dist/types'; +import { Osmosis } from '@/config'; export type CoinGeckoId = string; export type CoinGeckoPrice = { usd: number }; @@ -18,26 +18,33 @@ export type CoinGeckoResponse = Record; // } // } -async function fetchPrices(coinGeckoIds: CoinGeckoId[]): Promise { +async function fetchPrices( + coinGeckoIds: CoinGeckoId[] +): Promise { const url = `https://api.coingecko.com/api/v3/simple/price?ids=${coinGeckoIds.join()}&vs_currencies=usd`; return await fetch(url).then((res) => res.json()); } function toPriceHash(prices: CoinGeckoResponse = {}): PriceHash { - return Object.entries(prices).reduce((result, [id, price]) => ({ - ...result, - [Osmosis.Assets.CoinGeckoIdToAsset[id]!.base]: price.usd, - }), {}); + return Object.entries(prices).reduce( + (result, [id, price]) => ({ + ...result, + [Osmosis.Assets.CoinGeckoIdToAsset[id]!.base]: price.usd, + }), + {} + ); } export function usePrices() { const query = useQuery({ queryKey: ['prices'], queryFn: () => fetchPrices(Osmosis.Assets.CoinGeckoIds), - staleTime: Infinity + staleTime: Infinity, }); - return { query, ...toPriceHash(query.data) } as PriceHash & { query: UseQueryResult }; + return { query, ...toPriceHash(query.data) } as PriceHash & { + query: UseQueryResult; + }; } // Waht prices: PriceHash looks like: @@ -47,4 +54,4 @@ export function usePrices() { // ... // "uion": 75.55, // "uosmo": 0.228555 -// } \ No newline at end of file +// } diff --git a/examples/swap-tokens/hooks/useSwap.tsx b/examples/swap-tokens/hooks/useSwap.tsx index c9a5b233c..a98d4c2e2 100644 --- a/examples/swap-tokens/hooks/useSwap.tsx +++ b/examples/swap-tokens/hooks/useSwap.tsx @@ -1,27 +1,42 @@ -import BigNumber from "bignumber.js"; +import BigNumber from 'bignumber.js'; import { coin } from '@cosmjs/amino'; -import { Coin } from "@cosmjs/stargate"; -import { FEES, osmosis } from "osmo-query"; -import { useEffect, useState } from "react"; -import { useChain } from "@cosmos-kit/react"; +import { Coin } from '@cosmjs/stargate'; +import { FEES, osmosis } from 'osmo-query'; +import { useEffect, useState } from 'react'; +import { useChain } from '@cosmos-kit/react'; import { Text } from '@interchain-ui/react'; import { toast } from '@interchain-ui/react'; -import { Asset } from "@chain-registry/types"; -import { getExponentByDenom } from "@chain-registry/utils"; -import { CoinDenom, PrettyPair } from "@osmonauts/math/dist/types"; -import { SwapAmountInRoute } from "osmo-query/dist/codegen/osmosis/poolmanager/v1beta1/swap_route"; -import { convertBaseUnitsToDisplayUnits, convertBaseUnitsToDollarValue, PriceHash } from "@chain-registry/utils"; -import { makePoolPairs, getRoutesForTrade, calcPriceImpactGivenIn, calcPriceImpactGivenOut, calcAmountWithSlippage } from "@osmonauts/math"; -import { Token, Slippages, TokenList, SwapInfoProps } from "@/components/swap"; -import { Pools, usePools, usePrices, useBalances, useTx } from "@/hooks"; -import { defaultChainName, Osmosis } from "@/config"; -import { getLogo, integer } from "@/utils"; +import { Asset } from '@chain-registry/types'; + +import { + CoinDenom, + PrettyPair, + PriceHash, + Exponent, +} from '@osmonauts/math/dist/types'; +import { SwapAmountInRoute } from 'osmo-query/dist/codegen/osmosis/poolmanager/v1beta1/swap_route'; +import { + getExponentByDenom, + convertBaseUnitToDisplayUnit, + convertBaseUnitToDollarValue, +} from '@chain-registry/utils'; +import { + makePoolPairs, + getRoutesForTrade, + calcPriceImpactGivenIn, + calcPriceImpactGivenOut, + calcAmountWithSlippage, +} from '@osmonauts/math'; +import { Token, Slippages, TokenList, SwapInfoProps } from '@/components/swap'; +import { Pools, usePools, usePrices, useBalances, useTx } from '@/hooks'; +import { defaultChainName, Osmosis } from '@/config'; +import { getLogo, integer } from '@/utils'; export type Swap = { - to: Token - from: Token - slippage: number -} + to: Token; + from: Token; + slippage: number; +}; export function useSwap() { const { tx } = useTx(defaultChainName); @@ -35,7 +50,7 @@ export function useSwap() { // The selected From token. // from.amount is the balance of the From token in display units (atom, osmo ...) - const [amount, setAmount] = useState("0"); + const [amount, setAmount] = useState('0'); // amount is the amount of From token to swap (user input) const [slippage, setSlippage] = useState(Slippages[0]); @@ -45,7 +60,7 @@ export function useSwap() { const prices = usePrices(); const pools = usePools(prices); - const pairs = makePoolPairs(Osmosis.Assets, pools.freefloat.priced, prices); // see pairs data structure at file bottom + const pairs = makePoolPairs(Osmosis.Assets, pools.freefloat.priced, prices); // see pairs data structure at file bottom const denoms = denomsInPairs(pairs); const tokens = newTokens(denoms, prices, balances.hash, from, to); @@ -57,20 +72,26 @@ export function useSwap() { const info = newSwapInfo(swap, pools, routes); const steps = newSwapSteps(swap, pools, routes); - const isLoading = pools.query.isLoading || prices.query.isLoading || balances.query.isLoading; + const isLoading = + pools.query.isLoading || prices.query.isLoading || balances.query.isLoading; const isZeroAmount = new BigNumber(amount).lte(0); const isRoutesEmpty = routes.length === 0; const isInsufficientBalance = new BigNumber(amount).gt(from?.amount || '0'); - const isSwapDisabled = isLoading || isSwapping || isZeroAmount || isRoutesEmpty || isInsufficientBalance; + const isSwapDisabled = + isLoading || + isSwapping || + isZeroAmount || + isRoutesEmpty || + isInsufficientBalance; useEffect(() => { isWalletConnected ? null : setAmount('0'); - }, [isWalletConnected]) + }, [isWalletConnected]); useEffect(() => { if (tokens.length < 2) return; - setFrom((prev) => prev ? tokens.hash[prev.denom] : tokens[0]); - setTo((prev) => prev ? tokens.hash[prev.denom] : tokens[1]); + setFrom((prev) => (prev ? tokens.hash[prev.denom] : tokens[0])); + setTo((prev) => (prev ? tokens.hash[prev.denom] : tokens[1])); }, [pools.query.data, prices.query.data, balances.query.data]); function onFlip() { @@ -87,22 +108,34 @@ export function useSwap() { const num = new BigNumber(amount); const max = from?.amount || '0'; - const val = Number(amount) >= 0 && num.gte(0) ? num.gt(max) ? max : amount : '0'; + const val = + Number(amount) >= 0 && num.gte(0) ? (num.gt(max) ? max : amount) : '0'; setAmount(val); } async function onSwap() { - if (!address || isLoading || isZeroAmount || isInsufficientBalance || isRoutesEmpty) return; + if ( + !address || + isLoading || + isZeroAmount || + isInsufficientBalance || + isRoutesEmpty + ) + return; setIsSwapping(true); const msg = newSwapMessage(swap, address, routes); const fee = FEES.osmosis.swapExactAmountIn(); const res = await tx([msg], { fee }); - setIsSwapping(false) + setIsSwapping(false); if (res.error) { // will be simple as toast.error(res.errorMsg) when interchain-ui fixs the text overflow issue - const error = {res.errorMsg} + const error = ( + + {res.errorMsg} + + ); toast.error(error); console.log(res.response); console.log(res.error.message); @@ -114,12 +147,32 @@ export function useSwap() { } return { - to, setTo, from, setFrom, swap, info, - pools, prices, tokens, balances, routes, steps, - amount, slippage, setSlippage, onFlip, onSwap, onAmountChange, - isLoading, isSwapping, isZeroAmount, isRoutesEmpty, - isSwapDisabled, isWalletConnected, isInsufficientBalance - } + to, + setTo, + from, + setFrom, + swap, + info, + pools, + prices, + tokens, + balances, + routes, + steps, + amount, + slippage, + setSlippage, + onFlip, + onSwap, + onAmountChange, + isLoading, + isSwapping, + isZeroAmount, + isRoutesEmpty, + isSwapDisabled, + isWalletConnected, + isInsufficientBalance, + }; } export function newSwap( @@ -132,20 +185,29 @@ export function newSwap( const swap: Swap = { to: { denom: '', symbol: '', amount: '0', value: '0', $value: '$0' }, from: { denom: '', symbol: '', amount: '0', value: '0', $value: '$0' }, - slippage + slippage, }; if (from && to && prices[from.denom] && prices[to.denom]) { swap.from.denom = from.denom; swap.from.symbol = from.symbol; swap.from.amount = amount; - swap.from.value = new BigNumber(amount).multipliedBy(prices[from.denom]).toString(); - swap.from.$value = `\$${new BigNumber(swap.from.value).decimalPlaces(2).toString()}`; + swap.from.value = new BigNumber(amount) + .multipliedBy(prices[from.denom]) + .toString(); + swap.from.$value = `\$${new BigNumber(swap.from.value) + .decimalPlaces(2) + .toString()}`; swap.to.denom = to.denom; swap.to.symbol = to.symbol; - swap.to.amount = new BigNumber(swap.from.value).div(prices[to.denom]).decimalPlaces(6).toString(); + swap.to.amount = new BigNumber(swap.from.value) + .div(prices[to.denom]) + .decimalPlaces(6) + .toString(); swap.to.value = swap.from.value; - swap.to.$value = `\$${new BigNumber(swap.to.value).decimalPlaces(2).toString()}`; + swap.to.$value = `\$${new BigNumber(swap.to.value) + .decimalPlaces(2) + .toString()}`; } return swap; @@ -158,27 +220,51 @@ export function newTokens( from?: Token, to?: Token ) { - const tokens = denoms.map((denom) => { - const asset = Osmosis.Assets.CoinDenomToAsset[denom]; - const logo = getLogo(asset); - const balance = balances[asset.base]; - const value = balance ? convertBaseUnitsToDollarValue(Osmosis.Assets, prices, asset.symbol, balance.amount) : '0'; - return { - logo, - asset, - denom, - value, - price: prices[asset.base], - chain: Osmosis.getChainByDenom(denom), - symbol: asset.symbol, - amount: balance ? convertBaseUnitsToDisplayUnits(Osmosis.Assets, asset.symbol, balance.amount) : '0', - $value: balance ? `\$${new BigNumber(value).decimalPlaces(2).toString()}` : '$0', - balance: balances[asset.base], - } as Token - }).sort((a, b) => (new BigNumber(a.value!).lt(b.value!) ? 1 : -1)) as TokenList - - tokens.rest = tokens.filter((token) => token.denom !== from?.denom && token.denom !== to?.denom); - tokens.hash = tokens.reduce((acc, token) => ({ ...acc, [token.denom]: token }), {}) as Record; + const tokens = denoms + .map((denom) => { + const asset = Osmosis.Assets.CoinDenomToAsset[denom]; + const logo = getLogo(asset); + const balance = balances[asset.base]; + const value = balance + ? convertBaseUnitToDollarValue( + [{ assets: Osmosis.Assets, chain_name: 'osmosis' }], + prices, + asset.symbol, + balance.amount + ) + : '0'; + return { + logo, + asset, + denom, + value, + price: prices[asset.base], + chain: Osmosis.getChainByDenom(denom), + symbol: asset.symbol, + amount: balance + ? convertBaseUnitToDisplayUnit( + [{ assets: Osmosis.Assets, chain_name: 'osmosis' }], + asset.symbol, + balance.amount + ) + : '0', + $value: balance + ? `\$${new BigNumber(value).decimalPlaces(2).toString()}` + : '$0', + balance: balances[asset.base], + } as Token; + }) + .sort((a, b) => + new BigNumber(a.value!).lt(b.value!) ? 1 : -1 + ) as TokenList; + + tokens.rest = tokens.filter( + (token) => token.denom !== from?.denom && token.denom !== to?.denom + ); + tokens.hash = tokens.reduce( + (acc, token) => ({ ...acc, [token.denom]: token }), + {} + ) as Record; return tokens; } @@ -187,8 +273,14 @@ export function newCoin(token: Token) { return { denom: token.denom, amount: new BigNumber(token.amount || '0') - .shiftedBy(getExponentByDenom(Osmosis.Assets, token.denom)).toString() - } + .shiftedBy( + getExponentByDenom( + [{ assets: Osmosis.Assets, chain_name: 'osmosis' }], + token.denom + ) as Exponent + ) + .toString(), + }; } export function newRoutes(swap: Swap, pairs: PrettyPair[]) { @@ -196,12 +288,14 @@ export function newRoutes(swap: Swap, pairs: PrettyPair[]) { const trade = { sell: newCoin(swap.from), buy: newCoin(swap.to), - } + }; return getRoutesForTrade(Osmosis.Assets, { trade, pairs }); } export function denomsInPairs(pairs: PrettyPair[]) { - return Array.from(new Set(pairs.map((pair) => ([pair.baseAddress, pair.quoteAddress])).flat())); + return Array.from( + new Set(pairs.map((pair) => [pair.baseAddress, pair.quoteAddress]).flat()) + ); } export function calcPriceImpact( @@ -209,26 +303,43 @@ export function calcPriceImpact( pools: Pools, routes: SwapAmountInRoute[] = [] ) { - if (new BigNumber(swap.from.amount || '0').isEqualTo(0) || routes.length === 0) return '0'; + if ( + new BigNumber(swap.from.amount || '0').isEqualTo(0) || + routes.length === 0 + ) + return '0'; const to = newCoin(swap.to); const from = newCoin(swap.from); if (routes.length === 1) { - return calcPriceImpactGivenIn(from, to.denom, pools.map.get(routes[0].poolId)!) + return calcPriceImpactGivenIn( + from, + to.denom, + pools.map.get(routes[0].poolId)! + ); } const toRoute = routes.find((route) => route.tokenOutDenom === to.denom)!; const fromRoute = routes.find((route) => route.tokenOutDenom !== to.denom)!; return new BigNumber( - calcPriceImpactGivenIn(from, fromRoute.tokenOutDenom, pools.map.get(fromRoute.poolId)!) - ).plus( - calcPriceImpactGivenOut(to, fromRoute.tokenOutDenom, pools.map.get(toRoute.poolId)!) - ).toString() + calcPriceImpactGivenIn( + from, + fromRoute.tokenOutDenom, + pools.map.get(fromRoute.poolId)! + ) + ) + .plus( + calcPriceImpactGivenOut( + to, + fromRoute.tokenOutDenom, + pools.map.get(toRoute.poolId)! + ) + ) + .toString(); } -export function calcSwapFee(pools: Pools, routes: SwapAmountInRoute[] = [] -) { +export function calcSwapFee(pools: Pools, routes: SwapAmountInRoute[] = []) { if (routes.length === 0) return '0'; return routes.reduce((total, route) => { const pool = pools.map.get(route.poolId)!; @@ -249,63 +360,88 @@ export function newSwapInfo( const priceImpactPercent = priceImpact.decimalPlaces(5).shiftedBy(2); const priceImpactPercentString = priceImpactPercent.toString() + '%'; const swapFee = calcSwapFee(pools, routes); - const swapFeeValue = new BigNumber(swap.from.value || '0').multipliedBy(swapFee).decimalPlaces(2, BigNumber.ROUND_DOWN); - const swapFeePercent = new BigNumber(swapFee).shiftedBy(2) + const swapFeeValue = new BigNumber(swap.from.value || '0') + .multipliedBy(swapFee) + .decimalPlaces(2, BigNumber.ROUND_DOWN); + const swapFeePercent = new BigNumber(swapFee).shiftedBy(2); const swapFeePercentString = swapFeePercent.toString() + '%'; const info = { priceImpact: { number: priceImpact, percent: { number: priceImpactPercent, string: priceImpactPercentString }, - display: priceImpactPercent.gte(0.001) ? priceImpactPercentString : '< 0.001%', + display: priceImpactPercent.gte(0.001) + ? priceImpactPercentString + : '< 0.001%', }, swapFee: { value: swapFeeValue, $value: `\$${swapFeeValue.decimalPlaces(2).toString()}`, number: new BigNumber(swapFee), - percent: { number: swapFeePercent, string: swapFeePercentString } + percent: { number: swapFeePercent, string: swapFeePercentString }, }, expectedOutput: new BigNumber(swap.to.amount!).decimalPlaces(6).toString(), minimumReceived: new BigNumber( - convertBaseUnitsToDisplayUnits( - Osmosis.Assets, swap.to.symbol, calcAmountWithSlippage(to.amount, swap.slippage) - )).decimalPlaces(6).toString(), - display: {} as SwapInfoProps - } + convertBaseUnitToDisplayUnit( + [{ assets: Osmosis.Assets, chain_name: 'osmosis' }], + swap.to.symbol, + calcAmountWithSlippage(to.amount, swap.slippage) + ) + ) + .decimalPlaces(6) + .toString(), + display: {} as SwapInfoProps, + }; // Pad expectedOutput and minimumReceived to the same length - const maxLength = Math.max(info.expectedOutput.length, info.minimumReceived.length); + const maxLength = Math.max( + info.expectedOutput.length, + info.minimumReceived.length + ); info.expectedOutput = info.expectedOutput.padEnd(maxLength, '0'); info.minimumReceived = info.minimumReceived.padEnd(maxLength, '0'); info.display = { priceImpact: info.priceImpact.display, swapFee: { - value: `≈ ${swapFeeValue.gt(0.01) ? info.swapFee.$value : '< \$0.01'}`, - percent: swapFeePercentString + value: `≈ ${swapFeeValue.gt(0.01) ? info.swapFee.$value : '< $0.01'}`, + percent: swapFeePercentString, }, expectedOutput: `≈ ${info.expectedOutput!} ${swap.to.symbol}`, - minimumReceived: `${info.minimumReceived} ${swap.to.symbol}` - } + minimumReceived: `${info.minimumReceived} ${swap.to.symbol}`, + }; return info; } -export function newSwapSteps(swap: Swap, pools: Pools, routes: SwapAmountInRoute[] = []) { +export function newSwapSteps( + swap: Swap, + pools: Pools, + routes: SwapAmountInRoute[] = [] +) { return routes.map((route) => newSwapStep(swap, route, pools)); } -export function newSwapStep(swap: Swap, route: SwapAmountInRoute, pools: Pools) { - const token = (asset: Asset) => - ({ logo: getLogo(asset), denom: asset.base, symbol: asset.symbol }) +export function newSwapStep( + swap: Swap, + route: SwapAmountInRoute, + pools: Pools +) { + const token = (asset: Asset) => ({ + logo: getLogo(asset), + denom: asset.base, + symbol: asset.symbol, + }); const pool = pools.map.get(route.poolId)!; let base, quote; if (route.tokenOutDenom === swap.to.denom) { - base = Osmosis.Assets.CoinDenomToAsset[ - pool.poolAssets.find(({ token }) => token.denom !== swap.to.denom)!.token.denom - ]; + base = + Osmosis.Assets.CoinDenomToAsset[ + pool.poolAssets.find(({ token }) => token.denom !== swap.to.denom)! + .token.denom + ]; quote = Osmosis.Assets.CoinDenomToAsset[swap.to.denom]; } else { base = Osmosis.Assets.CoinDenomToAsset[swap.from.denom]; @@ -313,19 +449,27 @@ export function newSwapStep(swap: Swap, route: SwapAmountInRoute, pools: Pools) } return { poolId: route.poolId.toString(), - swapFee: new BigNumber(pool.poolParams.swapFee).shiftedBy(2).toString() + '%', + swapFee: + new BigNumber(pool.poolParams.swapFee).shiftedBy(2).toString() + '%', base: token(base), quote: token(quote), - } + }; } -function newSwapMessage(swap: Swap, sender: string, routes: SwapAmountInRoute[]) { - const { swapExactAmountIn } = osmosis.gamm.v1beta1.MessageComposer.withTypeUrl; +function newSwapMessage( + swap: Swap, + sender: string, + routes: SwapAmountInRoute[] +) { + const { swapExactAmountIn } = + osmosis.gamm.v1beta1.MessageComposer.withTypeUrl; return swapExactAmountIn({ sender, routes, tokenIn: coin(integer(newCoin(swap.from).amount), swap.from.denom), - tokenOutMinAmount: integer(calcAmountWithSlippage(newCoin(swap.to).amount, swap.slippage)), + tokenOutMinAmount: integer( + calcAmountWithSlippage(newCoin(swap.to).amount, swap.slippage) + ), }); } @@ -641,4 +785,4 @@ function newSwapMessage(swap: Swap, sender: string, routes: SwapAmountInRoute[]) // "quoteSymbol": "NLS", // "quoteAddress": "ibc/D9AFCECDD361D38302AA66EB3BAC23B95234832C51D12489DC451FA2B7C72782" // } -// ] \ No newline at end of file +// ] diff --git a/examples/swap-tokens/package.json b/examples/swap-tokens/package.json index 78309798f..5a4a5deaf 100644 --- a/examples/swap-tokens/package.json +++ b/examples/swap-tokens/package.json @@ -20,7 +20,7 @@ "dependencies": { "@chain-registry/osmosis": "1.20.0", "@chain-registry/types": "0.16.0", - "@chain-registry/utils": "1.13.2", + "@chain-registry/utils": "^1.46.8", "@cosmjs/amino": "0.32.3", "@cosmjs/cosmwasm-stargate": "0.32.3", "@cosmjs/stargate": "0.32.3", @@ -33,7 +33,7 @@ "@osmonauts/math": "1.7.0", "@tanstack/react-query": "4.32.0", "bignumber.js": "9.1.1", - "chain-registry": "1.20.0", + "chain-registry": "^1.63.11", "cosmos-kit": "2.18.0", "next": "^13", "osmo-query": "16.5.1", diff --git a/examples/swap-tokens/yarn.lock b/examples/swap-tokens/yarn.lock index 28dcb7a41..fabb68311 100644 --- a/examples/swap-tokens/yarn.lock +++ b/examples/swap-tokens/yarn.lock @@ -163,15 +163,6 @@ __metadata: languageName: node linkType: hard -"@chain-registry/types@npm:^0.17.0": - version: 0.17.1 - resolution: "@chain-registry/types@npm:0.17.1" - dependencies: - "@babel/runtime": "npm:^7.21.0" - checksum: 10c0/00400f2994c838dbf0a4a6aa01af397d72badbeee82e13095e1ae1e5853a9405f802f0e5629f3aab0cfaa7ec9eae78eb0976001d5a24a7f33d138e2b02edb547 - languageName: node - linkType: hard - "@chain-registry/types@npm:^0.18.15": version: 0.18.15 resolution: "@chain-registry/types@npm:0.18.15" @@ -195,6 +186,13 @@ __metadata: languageName: node linkType: hard +"@chain-registry/types@npm:^0.45.8": + version: 0.45.8 + resolution: "@chain-registry/types@npm:0.45.8" + checksum: 10c0/ff37142bf800214cdbd3ff64740d94fedd44a272d164a35431554d95b47df31e6d9b038071b32cf20187c15c5f371eb2d8e37b531b24678809ae0576c105fc3b + languageName: node + linkType: hard + "@chain-registry/utils@npm:1.13.1": version: 1.13.1 resolution: "@chain-registry/utils@npm:1.13.1" @@ -207,18 +205,6 @@ __metadata: languageName: node linkType: hard -"@chain-registry/utils@npm:1.13.2": - version: 1.13.2 - resolution: "@chain-registry/utils@npm:1.13.2" - dependencies: - "@babel/runtime": "npm:^7.21.0" - "@chain-registry/types": "npm:^0.16.0" - bignumber.js: "npm:9.1.1" - sha.js: "npm:^2.4.11" - checksum: 10c0/782831ff1eefd0d18e2ca5f627a34cc2a0e9cd4b68b17555fe8a2651808b1277fc0a641f2639da4441dc17f69ace4aa66e0869ea854f894e8e806aa2d2a6aa50 - languageName: node - linkType: hard - "@chain-registry/utils@npm:^1.46.1, @chain-registry/utils@npm:^1.46.4": version: 1.46.4 resolution: "@chain-registry/utils@npm:1.46.4" @@ -241,6 +227,17 @@ __metadata: languageName: node linkType: hard +"@chain-registry/utils@npm:^1.46.8": + version: 1.46.8 + resolution: "@chain-registry/utils@npm:1.46.8" + dependencies: + "@chain-registry/types": "npm:^0.45.8" + bignumber.js: "npm:9.1.2" + sha.js: "npm:^2.4.11" + checksum: 10c0/6fc0b5f21102460076b4c03ef9c09e22a746643a24f73d3b205f02dbc114e0056964ce6713ad03d7c158b7e085e7fc16e9a511d30a937c35f953e0739903ece9 + languageName: node + linkType: hard + "@chakra-ui/accordion@npm:2.3.1": version: 2.3.1 resolution: "@chakra-ui/accordion@npm:2.3.1" @@ -2036,7 +2033,7 @@ __metadata: dependencies: "@chain-registry/osmosis": "npm:1.20.0" "@chain-registry/types": "npm:0.16.0" - "@chain-registry/utils": "npm:1.13.2" + "@chain-registry/utils": "npm:^1.46.8" "@cosmjs/amino": "npm:0.32.3" "@cosmjs/cosmwasm-stargate": "npm:0.32.3" "@cosmjs/stargate": "npm:0.32.3" @@ -2053,7 +2050,7 @@ __metadata: "@types/react": "npm:18.2.0" "@types/react-dom": "npm:18.2.0" bignumber.js: "npm:9.1.1" - chain-registry: "npm:1.20.0" + chain-registry: "npm:^1.63.11" cosmos-kit: "npm:2.18.0" eslint: "npm:8.28.0" eslint-config-next: "npm:13.0.5" @@ -7202,16 +7199,6 @@ __metadata: languageName: node linkType: hard -"chain-registry@npm:1.20.0": - version: 1.20.0 - resolution: "chain-registry@npm:1.20.0" - dependencies: - "@babel/runtime": "npm:^7.21.0" - "@chain-registry/types": "npm:^0.17.0" - checksum: 10c0/f2d4b23bc2b8607fc4de05fa34949eaa183a563afb07f718c039c2be151fa6fbd86e9a3c998dc6ca1b7ab9440bfbc1e1218aff51f0e681f9915788269e95a9da - languageName: node - linkType: hard - "chain-registry@npm:^1.5.0": version: 1.33.20 resolution: "chain-registry@npm:1.33.20" @@ -7222,6 +7209,15 @@ __metadata: languageName: node linkType: hard +"chain-registry@npm:^1.63.11": + version: 1.63.11 + resolution: "chain-registry@npm:1.63.11" + dependencies: + "@chain-registry/types": "npm:^0.45.8" + checksum: 10c0/76146812c380db735885db1656266f1d5da188d5ddf048bcedee5bef91bf0e7f9937c42af2d31ec40233adb613e9718566e294dd056447780362b11e036bc6f3 + languageName: node + linkType: hard + "chakra-react-select@npm:^4.4.2": version: 4.7.6 resolution: "chakra-react-select@npm:4.7.6"