From ffbe73d30069fdbb17e810f31f91a7b920a73832 Mon Sep 17 00:00:00 2001 From: nickkelly1 Date: Thu, 15 Aug 2024 17:13:51 -0500 Subject: [PATCH] wip: change uppercase solana network id --- packages/swap/src/providers/changelly/index.ts | 12 ++++++++++++ packages/swap/src/types/index.ts | 1 + packages/types/src/networks.ts | 1 + 3 files changed, 14 insertions(+) diff --git a/packages/swap/src/providers/changelly/index.ts b/packages/swap/src/providers/changelly/index.ts index 7a82816b9..505dfefe3 100644 --- a/packages/swap/src/providers/changelly/index.ts +++ b/packages/swap/src/providers/changelly/index.ts @@ -49,6 +49,7 @@ class Changelly extends ProviderClass { toTokens: ProviderToTokenResponse; + /** Dynamically generated Changelly swap token data from the Enkrypt dynamic-lists repo {@link CHANGELLY_LIST} */ changellyList: ChangellyCurrency[]; contractToTicker: Record; @@ -66,16 +67,25 @@ class Changelly extends ProviderClass { async init(): Promise { if (!Changelly.isSupported(this.network)) return; this.changellyList = await fetch(CHANGELLY_LIST).then((res) => res.json()); + + /** changelly blockchain name -> enkrypt supported swap network name */ const changellyToNetwork: Record = {}; + // Generate mapping of changelly blockchain -> enkrypt blockchain Object.keys(supportedNetworks).forEach((net) => { changellyToNetwork[supportedNetworks[net].changellyName] = net as unknown as SupportedNetworkName; }); + + /** List of changelly blockchain names */ const supportedChangellyNames = Object.values(supportedNetworks).map( (s) => s.changellyName ); + this.changellyList.forEach((cur) => { + // We must support the changelly network if (!supportedChangellyNames.includes(cur.blockchain)) return; + + // Can currency can be swapped from? if ( cur.enabledFrom && cur.fixRateEnabled && @@ -84,6 +94,8 @@ class Changelly extends ProviderClass { ) { this.fromTokens[cur.token.address] = cur.token; } + + // Can currency can be swapped to? if (cur.enabledTo && cur.fixRateEnabled && cur.token) { if (!this.toTokens[changellyToNetwork[cur.blockchain]]) this.toTokens[changellyToNetwork[cur.blockchain]] = {}; diff --git a/packages/swap/src/types/index.ts b/packages/swap/src/types/index.ts index e36591cf8..53034bc08 100644 --- a/packages/swap/src/types/index.ts +++ b/packages/swap/src/types/index.ts @@ -32,6 +32,7 @@ export enum SupportedNetworkName { Blast = NetworkNames.Blast, Telos = NetworkNames.Telos, Rootstock = NetworkNames.Rootstock, + Solana = NetworkNames.Solana, } // eslint-disable-next-line no-shadow diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts index 48bd18ea7..20df855fc 100644 --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -77,6 +77,7 @@ export enum NetworkNames { Sanko = "sanko", Degen = "degen", Ham = "ham", + Solana = "SOLANA", } export enum CoingeckoPlatform {