Skip to content

Commit

Permalink
wip: change uppercase solana network id
Browse files Browse the repository at this point in the history
  • Loading branch information
NickKelly1 committed Aug 15, 2024
1 parent 8028cec commit ffbe73d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/swap/src/providers/changelly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
Expand All @@ -66,16 +67,25 @@ class Changelly extends ProviderClass {
async init(): Promise<void> {
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<string, SupportedNetworkName> = {};
// 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 &&
Expand All @@ -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]] = {};
Expand Down
1 change: 1 addition & 0 deletions packages/swap/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export enum NetworkNames {
Sanko = "sanko",
Degen = "degen",
Ham = "ham",
Solana = "SOLANA",
}

export enum CoingeckoPlatform {
Expand Down

1 comment on commit ffbe73d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.