Skip to content

Commit

Permalink
Add additional token routes (#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
DefiDebauchery authored Sep 26, 2024
1 parent 98b42b7 commit a2a6bdb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/api/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getAllTokensByChain, getTokensForChainById } from './tokens';
import {
getAllTokensByChain,
getTokenById,
getTokenNative,
getTokensForChainById,
getTokenWrappedNative,
} from './tokens';
import { isApiChain } from '../../utils/chain';
import { mapValues } from 'lodash';

Expand Down Expand Up @@ -30,3 +36,28 @@ export const getChainTokens = ctx => {
ctx.status = 404;
}
};

export const getChainToken = ctx => {
try {
const token = getTokenById(ctx.params.tokenId, ctx.params.chainId);
ctx.status = token ? 200 : 404;
ctx.body = token ?? {};
} catch (err) {
console.error(err);
ctx.status = 500;
}
};

export const getChainNatives = ctx => {
try {
const chainId = ctx.params.chainId;
const native = getTokenNative(chainId);
const wrapped = getTokenWrappedNative(chainId);

ctx.status = native || wrapped ? 200 : 404;
ctx.body = { native, wrapped };
} catch (err) {
console.error(err);
ctx.status = 500;
}
};
4 changes: 3 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const tvl = require('./api/tvl');
const multichainVaults = require('./api/vaults');
const snapshot = require('./api/snapshot');
const { boosts, chainBoosts } = require('./api/boosts');
const { getTokens, getChainTokens } = require('./api/tokens');
const { getTokens, getChainTokens, getChainNatives, getChainToken } = require('./api/tokens');
const { getConfigs, getChainConfig } = require('./api/config');
const { getTreasury, getMMBal, getAllTreasury } = require('./api/treasury');
const { validatorPerformance } = require('./api/validators/index');
Expand Down Expand Up @@ -83,6 +83,8 @@ router.get('/boosts/:chainId', chainBoosts);

router.get('/tokens', getTokens);
router.get('/tokens/:chainId', getChainTokens);
router.get('/tokens/:chainId/native', getChainNatives);
router.get('/tokens/:chainId/:tokenId', getChainToken);

router.get('/config', getConfigs);
router.get('/config/:chainId', getChainConfig);
Expand Down

0 comments on commit a2a6bdb

Please sign in to comment.