Skip to content

Commit f3532be

Browse files
authored
Fix testnet IBC connection lookup and improve fallback robustness (#3296)
* allow testnet IBC channels to be verified * Allow IBC transfer method
1 parent 7404aea commit f3532be

File tree

1 file changed

+73
-21
lines changed

1 file changed

+73
-21
lines changed

.github/workflows/utility/generate_assetlist_functions.mjs

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,38 @@ chain_reg.setup();
88
import * as zone from "./assetlist_functions.mjs";
99
import { getAssetsPricing } from "./getPools.mjs";
1010
import { getAllRelatedAssets } from "./getRelatedAssets.mjs";
11+
import * as fs from 'fs';
12+
import * as path from 'path';
1113

1214
//-- Global Constants --
1315

1416
//This address corresponds to the native assset on all evm chains (e.g., wei on ethereum)
1517
const zero_address = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
1618

19+
//-- Helper Functions --
20+
21+
// Get IBC file property with zone-aware path selection
22+
// Determines _IBC directory based on the destination chain (osmosistestnet = testnet, osmosis = mainnet)
23+
function getIBCFilePropertyForZone(chainName1, chainName2, property) {
24+
// chainName2 is the zone chain (osmosistestnet or osmosis) which tells us which _IBC to use
25+
const isTestnetZone = chainName2 === "osmosistestnet";
26+
const ibcDirectory = isTestnetZone
27+
? path.join(chain_reg.chainRegistryRoot, "testnets", "_IBC")
28+
: path.join(chain_reg.chainRegistryRoot, "_IBC");
29+
30+
// Build the IBC file path
31+
const sortedChains = [chainName1, chainName2].sort();
32+
const fileName = `${sortedChains[0]}-${sortedChains[1]}.json`;
33+
const filePath = path.join(ibcDirectory, fileName);
34+
35+
// Check if file exists and return the property
36+
if (fs.existsSync(filePath)) {
37+
return chain_reg.readJsonFile(filePath)[property];
38+
}
39+
40+
return undefined;
41+
}
42+
1743
//This defines with types of traces are considered essentially the same asset
1844
const originTraceTypes = [
1945
"ibc",
@@ -180,7 +206,7 @@ export function getAssetTrace(asset_data) {
180206

181207

182208
//--Find IBC Connection--
183-
const channels = chain_reg.getIBCFileProperty(
209+
const channels = getIBCFilePropertyForZone(
184210
asset_data.source_asset.chain_name,
185211
asset_data.chainName,
186212
"channels"
@@ -329,11 +355,33 @@ export async function setLocalAsset(asset_data) {
329355
return;
330356
}
331357

332-
// Only add trace if it was successfully retrieved
358+
// Add trace if it was successfully retrieved, or create minimal trace from fallback
333359
if (trace?.chain?.path) {
334360
traces.push(trace);
335361
} else {
336362
console.log(`Warning: Using path from zone_asset for ${asset_data.zone_asset.chain_name}:${asset_data.zone_asset.base_denom} (IBC connection not found in registry)`);
363+
364+
// Create minimal trace from zone_asset to prevent downstream errors
365+
// Path format: "transfer/channel-123/denom"
366+
const segments = pathToUse.split("/");
367+
const type = (asset_data.source_asset.base_denom.slice(0, 5) === "cw20:") ? "ibc-cw20" : "ibc";
368+
369+
// Extract channel ID from path (e.g., "channel-123" from segments[1])
370+
const channelId = segments[1];
371+
372+
const minimalTrace = {
373+
type: type,
374+
counterparty: {
375+
chain_name: asset_data.source_asset.chain_name,
376+
base_denom: asset_data.source_asset.base_denom,
377+
channel_id: channelId // Will be set in setTransferMethods if needed
378+
},
379+
chain: {
380+
channel_id: channelId,
381+
path: pathToUse
382+
}
383+
};
384+
traces.push(minimalTrace);
337385
}
338386

339387
try {
@@ -1528,27 +1576,31 @@ export function setTransferMethods(asset_data) {
15281576
if (asset_data.source_asset.chain_name !== asset_data.chainName) {
15291577
const traces = getAssetProperty(asset_data.local_asset, "traces");
15301578
const trace = traces?.[traces.length - 1];
1531-
const ibcTransferMethod = {
1532-
name: "Osmosis IBC Transfer",
1533-
type: "ibc",
1534-
counterparty: {
1535-
chainName: trace.counterparty.chain_name,
1536-
chainId: chain_reg.getFileProperty(
1537-
trace.counterparty.chain_name,
1538-
"chain",
1539-
"chain_id"
1540-
),
1541-
sourceDenom: trace.counterparty.base_denom,
1542-
port: trace.counterparty.port ?? "transfer",
1543-
channelId: trace.counterparty.channel_id
1544-
},
1545-
chain: {
1546-
port: trace.chain.port ?? "transfer",
1547-
channelId: trace.chain.channel_id,
1548-
path: trace.chain.path
1579+
1580+
// Only add IBC transfer method if we have a valid trace with required fields
1581+
if (trace?.counterparty?.chain_name && trace?.chain?.channel_id) {
1582+
const ibcTransferMethod = {
1583+
name: "Osmosis IBC Transfer",
1584+
type: "ibc",
1585+
counterparty: {
1586+
chainName: trace.counterparty.chain_name,
1587+
chainId: chain_reg.getFileProperty(
1588+
trace.counterparty.chain_name,
1589+
"chain",
1590+
"chain_id"
1591+
),
1592+
sourceDenom: trace.counterparty.base_denom,
1593+
port: trace.counterparty.port ?? "transfer",
1594+
channelId: trace.counterparty.channel_id
1595+
},
1596+
chain: {
1597+
port: trace.chain.port ?? "transfer",
1598+
channelId: trace.chain.channel_id,
1599+
path: trace.chain.path
1600+
}
15491601
}
1602+
transferMethods.push(ibcTransferMethod);
15501603
}
1551-
transferMethods.push(ibcTransferMethod);
15521604
}
15531605

15541606
asset_data.frontend.transferMethods = transferMethods;

0 commit comments

Comments
 (0)