-
Notifications
You must be signed in to change notification settings - Fork 48
Swap - Xgram Support #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Swap - Xgram Support #441
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.