Skip to content

Commit a94fb9d

Browse files
committed
fix: mapping to wrong usdc token on osmosis
1 parent 2b3389c commit a94fb9d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

apps/namadillo/src/App/Swap/state/atoms.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55
import {
66
getChainRegistryByChainId,
7+
getCorrespondingIbcAsset,
78
namadaRegistryChainAssetsMapAtom,
89
} from "atoms/integrations";
910
import BigNumber from "bignumber.js";
@@ -156,12 +157,8 @@ export const swapQuoteAtom = atomWithQuery((get) => {
156157
invariant(sellAsset, "Sell asset not found");
157158
invariant(buyAsset, "Buy asset not found");
158159

159-
const fromOsmosis = osmosisAssets.find(
160-
(assets) => assets.symbol === sellAsset.symbol
161-
);
162-
const toOsmosis = osmosisAssets.find(
163-
(assets) => assets.symbol === buyAsset.symbol
164-
);
160+
const fromOsmosis = getCorrespondingIbcAsset(sellAsset, osmosisAssets);
161+
const toOsmosis = getCorrespondingIbcAsset(buyAsset, osmosisAssets);
165162

166163
invariant(fromOsmosis, "From asset is not found in Osmosis assets");
167164
invariant(toOsmosis, "To asset is not found in Osmosis assets");

apps/namadillo/src/atoms/integrations/functions.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,26 @@ export const getNamadaIbcInfo = (isHousefire: boolean): IBCInfo[] => {
263263

264264
return ibcInfo;
265265
};
266+
267+
export const getCounterpartyChainName = (asset: Asset): string | undefined => {
268+
const chainName = asset.traces?.find((trace) => trace.type === "ibc")
269+
?.counterparty.chain_name;
270+
271+
return chainName;
272+
};
273+
274+
export const getCorrespondingIbcAsset = (
275+
asset: NamadaAsset,
276+
ibcAssets: Asset[]
277+
): Asset | undefined => {
278+
const assets = ibcAssets.filter((assets) => assets.symbol === asset.symbol);
279+
280+
if (assets.length === 1) {
281+
return assets[0];
282+
} else {
283+
const chainName = getCounterpartyChainName(asset);
284+
return assets.find(
285+
(ibcAsset) => getCounterpartyChainName(ibcAsset) === chainName
286+
);
287+
}
288+
};

0 commit comments

Comments
 (0)