Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- added: Xgram support

## 2.42.3 (2026-03-10)

- fixed: Map `mayachain` pluginId to MAYA chain correctly and remove non-existent `cacao` pluginId
Expand Down
4 changes: 3 additions & 1 deletion scripts/allSynchronizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { makeSideShiftSynchronizer } from './synchronizers/sideshift/sideshiftSy
import { makeSwapKitSynchronizer } from './synchronizers/swapkit/swapkitSynchronizer'
import { makeSwapuzSynchronizer } from './synchronizers/swapuz/swapuzSynchronizer'
import { makeThorchainSynchronizer } from './synchronizers/thorchain/thorchainSynchronizer'
import { makeXgramSynchronizer } from './synchronizers/xgram/xgramSynchronizer'
import { SwapSynchronizer } from './types'

export const synchronizers: SwapSynchronizer[] = [
Expand All @@ -33,5 +34,6 @@ export const synchronizers: SwapSynchronizer[] = [
makeSideShiftSynchronizer(config),
makeSwapKitSynchronizer(config),
makeSwapuzSynchronizer(config),
makeThorchainSynchronizer(config)
makeThorchainSynchronizer(config),
makeXgramSynchronizer(config)
]
3 changes: 2 additions & 1 deletion scripts/mapctlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const asMapctlConfig = asObject({
LETSEXCHANGE_API_KEY: asOptional(asString, ''),
RANGO_API_KEY: asOptional(asString, ''),
SWAPUZ_API_KEY: asOptional(asString, ''),
SWAPKIT_API_KEY: asOptional(asString, '')
SWAPKIT_API_KEY: asOptional(asString, ''),
XGRAM_API_KEY: asOptional(asString, '')
})

export type MapctlConfig = ReturnType<typeof asMapctlConfig>
Expand Down
92 changes: 92 additions & 0 deletions scripts/mappings/xgramMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { EdgeCurrencyPluginId } from '../../src/util/edgeCurrencyPluginIds'

export const xgram = new Map<string, EdgeCurrencyPluginId | null>()
// WARNING: Not included by the synchronizer synchronization
xgram.set('ada', 'cardano')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ALGO', 'algorand')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ARBITRUM', 'arbitrum')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ATOM', 'cosmoshub')

// WARNING: Not included by the synchronizer synchronization
xgram.set('AVAXC', 'avalanche')

// WARNING: Not included by the synchronizer synchronization
xgram.set('BITCOINCASH', 'bitcoincash')

// WARNING: Not included by the synchronizer synchronization
xgram.set('BSC', 'binancesmartchain')

// WARNING: Not included by the synchronizer synchronization
xgram.set('BSV', 'bitcoinsv')

// WARNING: Not included by the synchronizer synchronization
xgram.set('BTC', 'bitcoin')

// WARNING: Not included by the synchronizer synchronization
xgram.set('CELO', 'celo')

// WARNING: Not included by the synchronizer synchronization
xgram.set('DGB', 'digibyte')

// WARNING: Not included by the synchronizer synchronization
xgram.set('DOGECOIN', 'dogecoin')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ETH', 'ethereum')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ETHEREUM CLASSIC', 'ethereumclassic')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ETHEREUMPOW', 'ethereumpow')

// WARNING: Not included by the synchronizer synchronization
xgram.set('FIL', 'filecoin')

// WARNING: Not included by the synchronizer synchronization
xgram.set('FIO', 'fio')

// WARNING: Not included by the synchronizer synchronization
xgram.set('HBAR', 'hedera')

// WARNING: Not included by the synchronizer synchronization
xgram.set('OPTIMISM', 'optimism')

// WARNING: Not included by the synchronizer synchronization
xgram.set('OSMO', 'osmosis')

// WARNING: Not included by the synchronizer synchronization
xgram.set('POL', 'polygon')

// WARNING: Not included by the synchronizer synchronization
xgram.set('QTUM', 'qtum')

// WARNING: Not included by the synchronizer synchronization
xgram.set('RVN', 'ravencoin')

// WARNING: Not included by the synchronizer synchronization
xgram.set('SOL', 'solana')

// WARNING: Not included by the synchronizer synchronization
xgram.set('SUI', 'sui')

// WARNING: Not included by the synchronizer synchronization
xgram.set('TRX', 'tron')

// WARNING: Not included by the synchronizer synchronization
xgram.set('WAX', 'wax')

// WARNING: Not included by the synchronizer synchronization
xgram.set('XMR', 'monero')

// WARNING: Not included by the synchronizer synchronization
xgram.set('XRP', 'ripple')

// WARNING: Not included by the synchronizer synchronization
xgram.set('ZEC', 'zcash')
82 changes: 82 additions & 0 deletions scripts/synchronizers/xgram/xgramSynchronizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { asMaybe } from 'cleaners'
import fetch from 'node-fetch'

import { MapctlConfig } from '../../mapctlConfig'
import { FetchChainCodeResult, SwapSynchronizer } from '../../types'
import { getMappingFilePath, loadMappingFile } from '../../util/loadMappingFile'
import { asXgramCurrency } from './xgramTypes'

const NAME = 'xgram'
export const makeXgramSynchronizer = (
config: MapctlConfig
): SwapSynchronizer => {
const apiKey = config.XGRAM_API_KEY
if (apiKey == null || apiKey === '') {
throw new Error('Missing XGRAM_API_KEY in environment variables')
}

return {
name: NAME,
get map() {
return loadMappingFile(NAME)
},
mappingFilePath: getMappingFilePath(NAME),
fetchChainCodes: async (): Promise<FetchChainCodeResult[]> => {
const response = await fetch(
'https://xgram.io/api/v1/list-currency-options',
{
headers: {
'x-api-key': apiKey
}
}
)

if (!response.ok) {
throw new Error(
`Failed to fetch Xgram currencies: ${response.statusText}`
)
}

const data = await response.json()
if (typeof data !== 'object' || data == null) {
throw new Error('Xgram API returned unexpected response format')
}

// Note: The `network` field from list-currency-options does not map
// cleanly to the v2 quote endpoint's accepted fromNetwork/toNetwork
// values. We still collect it here for visibility in sync output, but
// the checked-in Xgram mappings remain hand-maintained.
const networkMap = new Map<string, { count: number }>()
for (const [, value] of Object.entries(data)) {
const currency = asMaybe(asXgramCurrency)(value)
if (currency == null) continue
if (currency.network === '' || !currency.available) continue

const existing = networkMap.get(currency.network)
if (existing != null) {
existing.count++
} else {
networkMap.set(currency.network, { count: 1 })
}
}

const results = Array.from(networkMap.entries()).map(
([network, info]) => ({
chainCode: network,
metadata: {
'Display Name': network,
'Currency Count': String(info.count)
}
})
)

if (results.length === 0) {
throw new Error(
'Xgram API returned currencies but no valid networks were extracted.'
)
}

return results
}
}
}
11 changes: 11 additions & 0 deletions scripts/synchronizers/xgram/xgramTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { asBoolean, asNumber, asObject, asString } from 'cleaners'

export const asXgramCurrency = asObject({
coinName: asString,
contract: asString,
minFrom: asNumber,
maxFrom: asNumber,
tagname: asString,
network: asString,
available: asBoolean
})
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { makeLetsExchangePlugin } from './swap/central/letsexchange'
import { makeNexchangePlugin } from './swap/central/nexchange'
import { makeSideshiftPlugin } from './swap/central/sideshift'
import { makeSwapuzPlugin } from './swap/central/swapuz'
import { makeXgramPlugin } from './swap/central/xgram'
import { make0xGaslessPlugin } from './swap/defi/0x/0xGasless'
import { makeBridgelessPlugin } from './swap/defi/bridgeless'
import { makeCosmosIbcPlugin } from './swap/defi/cosmosIbc'
Expand Down Expand Up @@ -50,6 +51,7 @@ const plugins = {
transfer: makeTransferPlugin,
unizen: makeUnizenPlugin,
velodrome: makeVelodromePlugin,
xgram: makeXgramPlugin,
xrpdex,
fantomsonicupgrade: makeFantomSonicUpgradePlugin,
'0xgasless': make0xGaslessPlugin
Expand Down
101 changes: 101 additions & 0 deletions src/mappings/xgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* ⚠️ AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY ⚠️
*
* This file is automatically generated from scripts/mappings/xgramMappings.ts
* To regenerate this file, run: yarn mapctl update-mappings
*
* To edit mappings:
* 1. Edit scripts/mappings/xgramMappings.ts
* 2. Run: yarn mapctl update-mappings
*
* This file maps EdgeCurrencyPluginId -> synchronizer network identifier (or null)
*/

import { EdgeCurrencyPluginId } from '../util/edgeCurrencyPluginIds'

export const xgram = new Map<EdgeCurrencyPluginId, string | null>()
xgram.set('abstract', null)
xgram.set('algorand', 'ALGO')
xgram.set('amoy', null)
xgram.set('arbitrum', 'ARBITRUM')
xgram.set('avalanche', 'AVAXC')
xgram.set('axelar', null)
xgram.set('badcoin', null)
xgram.set('base', null)
xgram.set('binance', null)
xgram.set('binancesmartchain', 'BSC')
xgram.set('bitcoin', 'BTC')
xgram.set('bitcoincash', 'BITCOINCASH')
xgram.set('bitcoincashtestnet', null)
xgram.set('bitcoingold', null)
xgram.set('bitcoingoldtestnet', null)
xgram.set('bitcoinsv', 'BSV')
xgram.set('bitcointestnet', null)
xgram.set('bitcointestnet4', null)
xgram.set('bobevm', null)
xgram.set('botanix', null)
xgram.set('calibration', null)
xgram.set('cardano', 'ada')
xgram.set('cardanotestnet', null)
xgram.set('celo', 'CELO')
xgram.set('coreum', null)
xgram.set('cosmoshub', 'ATOM')
xgram.set('dash', null)
xgram.set('digibyte', 'DGB')
xgram.set('dogecoin', 'DOGECOIN')
xgram.set('eboost', null)
xgram.set('ecash', null)
xgram.set('eos', null)
xgram.set('ethDev', null)
xgram.set('ethereum', 'ETH')
xgram.set('ethereumclassic', 'ETHEREUM CLASSIC')
xgram.set('ethereumpow', 'ETHEREUMPOW')
xgram.set('fantom', null)
xgram.set('feathercoin', null)
xgram.set('filecoin', 'FIL')
xgram.set('filecoinfevm', null)
xgram.set('filecoinfevmcalibration', null)
xgram.set('fio', 'FIO')
xgram.set('groestlcoin', null)
xgram.set('hedera', 'HBAR')
xgram.set('holesky', null)
xgram.set('hyperevm', null)
xgram.set('liberland', null)
xgram.set('liberlandtestnet', null)
xgram.set('litecoin', null)
xgram.set('mayachain', null)
xgram.set('monad', null)
xgram.set('monero', 'XMR')
xgram.set('nym', null)
xgram.set('opbnb', null)
xgram.set('optimism', 'OPTIMISM')
xgram.set('osmosis', 'OSMO')
xgram.set('piratechain', null)
xgram.set('pivx', null)
xgram.set('polkadot', null)
xgram.set('polygon', 'POL')
xgram.set('pulsechain', null)
xgram.set('qtum', 'QTUM')
xgram.set('ravencoin', 'RVN')
xgram.set('ripple', 'XRP')
xgram.set('rsk', null)
xgram.set('sepolia', null)
xgram.set('smartcash', null)
xgram.set('solana', 'SOL')
xgram.set('sonic', null)
xgram.set('stellar', null)
xgram.set('sui', 'SUI')
xgram.set('suitestnet', null)
xgram.set('telos', null)
xgram.set('tezos', null)
xgram.set('thorchainrune', null)
xgram.set('thorchainrunestagenet', null)
xgram.set('ton', null)
xgram.set('tron', 'TRX')
xgram.set('ufo', null)
xgram.set('vertcoin', null)
xgram.set('wax', 'WAX')
xgram.set('zano', null)
xgram.set('zcash', 'ZEC')
xgram.set('zcoin', null)
xgram.set('zksync', null)
Loading
Loading