diff --git a/chains/mainnet/juno.js b/chains/mainnet/juno.js index cd9f14d2..3f04a1ec 100644 --- a/chains/mainnet/juno.js +++ b/chains/mainnet/juno.js @@ -22,6 +22,26 @@ module.exports = { 'noble-1': 'channel-224', 'stargaze-1': 'channel-20', }, + // NEW ICS CHANNELS + ics20Channels: { + 'phoenix-1': [ + { + contract: + 'juno1v4887y83d6g28puzvt8cl0f3cdhd3y6y9mpysnsp3k8krdm7l6jqgm0rkn', + channel: 'channel-154', + otherChannel: 'channel-33', + }, + ], + 'osmosis-1': [ + { + contract: + 'juno1v4887y83d6g28puzvt8cl0f3cdhd3y6y9mpysnsp3k8krdm7l6jqgm0rkn', + channel: 'channel-47', + otherChannel: 'channel-169', + }, + ], + }, + // LEGACY ICS CHANNELS (to be removed soon) icsChannels: { 'phoenix-1': { contract: diff --git a/chains/mainnet/terra.js b/chains/mainnet/terra.js index 78f5517e..7163799e 100644 --- a/chains/mainnet/terra.js +++ b/chains/mainnet/terra.js @@ -34,6 +34,74 @@ module.exports = { 'celestia': 'channel-300', 'stargaze-1': 'channel-324', }, + // NEW ICS CHANNELS + ics20Channels: { + 'carbon-1': [ + { + contract: + 'terra1e0mrzy8077druuu42vs0hu7ugguade0cj65dgtauyaw4gsl4kv0qtdf2au', + channel: 'channel-41', + otherChannel: 'channel-16', + }, + ], + 'juno-1': [ + { + contract: + 'terra1e0mrzy8077druuu42vs0hu7ugguade0cj65dgtauyaw4gsl4kv0qtdf2au', + channel: 'channel-32', + otherChannel: 'channel-153', + }, + ], + 'kaiyo-1': [ + { + contract: + 'terra1e0mrzy8077druuu42vs0hu7ugguade0cj65dgtauyaw4gsl4kv0qtdf2au', + channel: 'channel-28', + otherChannel: 'channel-36', + }, + ], + 'migaloo-1': [ + { + contract: + 'terra1e0mrzy8077druuu42vs0hu7ugguade0cj65dgtauyaw4gsl4kv0qtdf2au', + channel: 'channel-87', + otherChannel: 'channel-2', + }, + ], + 'osmosis-1': [ + { + contract: + 'terra1e0mrzy8077druuu42vs0hu7ugguade0cj65dgtauyaw4gsl4kv0qtdf2au', + channel: 'channel-26', + otherChannel: 'channel-341', + }, + ], + 'pacific-1': [ + { + contract: 'terra1jhfjnm39y3nn9l4520mdn4k5mw23nz0674c4gsvyrcr90z9tqcvst22fce', + channel: 'channel-171', + otherChannel: 'channel-8', + tokens: ['terra1nsuqsk6kh58ulczatwev87ttq2z6r3pusulg9r24mfj2fvtzd4uq3exn26'], + } + ], + 'neutron-1': [ + { + contract: 'terra1jhfjnm39y3nn9l4520mdn4k5mw23nz0674c4gsvyrcr90z9tqcvst22fce', + channel: 'channel-167', + otherChannel: 'channel-5', + tokens: ['terra1nsuqsk6kh58ulczatwev87ttq2z6r3pusulg9r24mfj2fvtzd4uq3exn26'], + } + ], + 'injective-1': [ + { + contract: 'terra1jhfjnm39y3nn9l4520mdn4k5mw23nz0674c4gsvyrcr90z9tqcvst22fce', + channel: 'channel-91', + otherChannel: 'channel-104', + tokens: ['terra1nsuqsk6kh58ulczatwev87ttq2z6r3pusulg9r24mfj2fvtzd4uq3exn26'], + } + ] + }, + // LEGACY ICS CHANNELS (to be removed soon) icsChannels: { 'carbon-1': { contract: @@ -66,7 +134,6 @@ module.exports = { otherChannel: 'channel-341', }, }, - // doesn't require IBC channels since it's already on all the other chains explorer: { address: 'https://terrasco.pe/mainnet/address/{}', diff --git a/index.js b/index.js index 9c92f16e..869ff818 100644 --- a/index.js +++ b/index.js @@ -105,9 +105,11 @@ const fs = require('fs').promises Object.keys(channels).forEach((otherChainID) => { const channel = chains[network][otherChainID]?.channels?.[chainID] if (!channel) { - console.error( - `${otherChainID} doesn't have an IBC channel configured with ${chainID}.` - ) + // throw error only if the other chain exists + !!chains[network][otherChainID] && + console.error( + `${otherChainID} doesn't have an IBC channel configured with ${chainID}.` + ) return } @@ -121,22 +123,32 @@ const fs = require('fs').promises chainID: otherChainID, } }) - } else if (isICS && chains[network][chainID]?.icsChannels) { - const channels = chains[network][chainID].icsChannels + } else if (isICS && chains[network][chainID]?.ics20Channels) { + const channels = chains[network][chainID].ics20Channels const denom = `cw20:${coinData.token}` - Object.entries(channels).forEach( - ([otherChainID, { channel, otherChannel }]) => { - const ibcDenom = calculateIBCDenom(otherChannel, denom) + Object.entries(channels).forEach(([otherChainID, icsChannels]) => { + const icsChannel = + // specific ICS channel for that token + icsChannels.find( + ({ tokens }) => !!tokens && tokens.includes(coinData.token) + ) || + // generic ICS channel for that chain + icsChannels.find(({ tokens }) => !tokens) - ibcDenomMapOut[network][`${otherChainID}:${ibcDenom}`] = { - token: tokenId, - chainID: otherChainID, - // to send it back on the original chain - icsChannel: channel, - } + // no valid ICS channel found for this token + if (!icsChannel) return + + const { channel, otherChannel } = icsChannel + const ibcDenom = calculateIBCDenom(otherChannel, denom) + + ibcDenomMapOut[network][`${otherChainID}:${ibcDenom}`] = { + token: tokenId, + chainID: otherChainID, + // to send it back on the original chain + icsChannel: channel, } - ) + }) } })