Skip to content

Commit

Permalink
loading currencies from assethub
Browse files Browse the repository at this point in the history
  • Loading branch information
mrq1911 committed Apr 28, 2024
1 parent 04a8e4f commit 501cda6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 94 deletions.
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from 'dotenv';
dotenv.config();

export const rpc = process.env.RPC_URL || 'wss://localhost:9988';
export const ahRpc = process.env.AH_RPC_URL || 'wss://polkadot-asset-hub-rpc.polkadot.io';
export const token = process.env.DISCORD_TOKEN;
export const channel = process.env.DISCORD_CHANNEL;
export const sha = process.env.COMMIT_SHA || 'dev';
Expand Down
104 changes: 10 additions & 94 deletions src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,101 +3,9 @@ import dijkstrajs from "dijkstrajs";
import {usdCurrencyId, whaleAmount} from "./config.js";
import {fromAccount} from "./utils/evm.js";
import {emojify} from "./utils/emojify.js";
import {metadata} from "./utils/assethub.js";

let currencies = {
'1000019': {
name: 'DED',
assetType: 'External',
existentialDeposit: '1',
symbol: 'DED',
decimals: '10'
},
'1000021': {
name: 'PINK',
assetType: 'External',
existentialDeposit: '1',
symbol: 'PINK',
decimals: '10'
},
'1000023': {
name: 'IceCreamToken',
assetType: 'External',
existentialDeposit: '1',
symbol: 'ICE',
decimals: '20'
},
'1000026': {
name: 'Efinity Token',
assetType: 'External',
existentialDeposit: '1',
symbol: 'EFI',
decimals: '18'
},
'1000027': {
name: 'web3.online',
assetType: 'External',
existentialDeposit: '1',
symbol: 'web3',
decimals: '18'
},
'1000028': {
name: 'Polkadot Index',
assetType: 'External',
existentialDeposit: '1',
symbol: 'PINT',
decimals: '12'
},
'1000029': {
name: 'Danger Coin',
assetType: 'External',
existentialDeposit: '1',
symbol: 'DANGER',
decimals: '8'
},
'1000034': {
name: 'STINK',
assetType: 'External',
existentialDeposit: '1',
symbol: 'STINK',
decimals: '10'
},
'1000035': {
name: 'BEER',
assetType: 'External',
existentialDeposit: '1',
symbol: 'BEER',
decimals: '6'
},
'1000036': {
name: 'BEEFY',
assetType: 'External',
existentialDeposit: '1',
symbol: 'BEEFY',
decimals: '2'
},
'1000038': {
name: 'DOTA',
assetType: 'External',
existentialDeposit: '1',
symbol: 'DOTA',
decimals: '4'
},
'1000085': {
name: 'WUD',
assetType: 'External',
existentialDeposit: '1',
symbol: 'WUD',
decimals: '10'
},
'1000091': {
name: 'BDNT',
assetType: 'External',
existentialDeposit: '1',
symbol: 'BDNT',
decimals: '10'
}
};

let currencies = {};
const prices = {};

export const isWhale = amount => amount >= whaleAmount;
Expand All @@ -121,6 +29,14 @@ async function loadCurrency(id) {
const [parent, maturity] = bond.toHuman();
currency = {...currency, parent, maturity};
}
if (currency.assetType === 'External') {
const location = (await api().query.assetRegistry.assetLocations(id)).toJSON();
const ahId = location?.interior?.x3[2]?.generalIndex;
if (ahId) {
const meta = await metadata(ahId);
currency = {...currency, ...meta?.toHuman()};
}
}
currencies = {...currencies, [id]: currency};
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/utils/assethub.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {ApiPromise, WsProvider} from "@polkadot/api";
import {ahRpc} from "../config.js";

let _api;

async function api() {
if (!_api && ahRpc) {
const provider = new WsProvider(ahRpc);
_api = await ApiPromise.create({provider});
}
return _api;
}

export async function metadata(id) {
return (await api())?.query.assets.metadata(id);
}

0 comments on commit 501cda6

Please sign in to comment.