Skip to content

Commit

Permalink
Merge pull request #203 from terra-money/multiple-ics-channels
Browse files Browse the repository at this point in the history
Support multiple ICS channels
  • Loading branch information
terencelimzhengwei authored Jan 11, 2024
2 parents b0fc386 + 4e23385 commit 63ce8fe
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 16 deletions.
20 changes: 20 additions & 0 deletions chains/mainnet/juno.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
69 changes: 68 additions & 1 deletion chains/mainnet/terra.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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/{}',
Expand Down
42 changes: 27 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
}
)
})
}
})

Expand Down

0 comments on commit 63ce8fe

Please sign in to comment.