Skip to content

Commit

Permalink
feat: support token list logoUri
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Lu authored and LuPoYi committed Jun 6, 2024
1 parent edcbdcb commit 40c1d04
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-insects-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@protocolink/logics': patch
---

support token list logoUri
4 changes: 2 additions & 2 deletions src/logics/balancer-v2/logic.flash-loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export class FlashLoanLogic extends core.Logic implements core.LogicTokenListInt

const tmp: Record<string, boolean> = {};
const tokenList: FlashLoanLogicTokenList = [];
for (const { chainId, address, decimals, symbol, name } of data.tokens) {
for (const { chainId, address, decimals, symbol, name, logoURI } of data.tokens) {
if (tmp[address] || chainId !== this.chainId || !name || !symbol || !decimals) continue;
tokenList.push(new common.Token(chainId, address, decimals, symbol, name));
tokenList.push(new common.Token(chainId, address, decimals, symbol, name, logoURI));
tmp[address] = true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/logics/openocean-v2/logic.swap-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class SwapTokenLogic
const resp = await axios.get(url + '/tokenList');
const tokens = resp.data.data;
const tokenList: SwapTokenLogicTokenList = [];
for (const { address, decimals, symbol, name } of tokens) {
tokenList.push(new common.Token(this.chainId, address, decimals, symbol, name));
for (const { address, decimals, symbol, name, icon } of tokens) {
tokenList.push(new common.Token(this.chainId, address, decimals, symbol, name, icon));
}
return tokenList;
}
Expand Down
4 changes: 2 additions & 2 deletions src/logics/uniswap-v3/logic.swap-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export class SwapTokenLogic

const tmp: Record<string, boolean> = { [this.nativeToken.address]: true };
const tokenList: SwapTokenLogicTokenList = [this.nativeToken];
for (const { chainId, address, decimals, symbol, name } of data.tokens) {
for (const { chainId, address, decimals, symbol, name, logoURI } of data.tokens) {
if (tmp[address] || chainId !== this.chainId) continue;
tokenList.push(new common.Token(chainId, address, decimals, symbol, name));
tokenList.push(new common.Token(chainId, address, decimals, symbol, name, logoURI));
tmp[address] = true;
}

Expand Down
24 changes: 12 additions & 12 deletions src/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ import * as common from '@protocolink/common';
import { ethers } from 'ethers';

export async function get1InchTokens(chainId: number) {
const { data } = await axios.get<Record<string, { symbol: string; name: string; decimals: number; address: string }>>(
`https://tokens.1inch.io/v1.2/${chainId}`
);
const { data } = await axios.get<
Record<string, { symbol: string; name: string; decimals: number; address: string; logoURI: string }>
>(`https://tokens.1inch.io/v1.2/${chainId}`);

const nativeToken = common.getNativeToken(chainId);
const elasticAddress = common.ELASTIC_ADDRESS.toLowerCase();
const tokens = Object.values(data).map(({ address, decimals, symbol, name }) =>
address === elasticAddress ? nativeToken : new common.Token(chainId, address, decimals, symbol, name)
const tokens = Object.values(data).map(({ address, decimals, symbol, name, logoURI }) =>
address === elasticAddress ? nativeToken : new common.Token(chainId, address, decimals, symbol, name, logoURI)
);

return tokens;
}

export async function getMetisTokens() {
const chainId = common.ChainId.metis;
const { data } = await axios.get<{ tokens: { symbol: string; name: string; decimals: number; address: string }[] }>(
`https://tokens.coingecko.com/metis-andromeda/all.json`
);
const { data } = await axios.get<{
tokens: { symbol: string; name: string; decimals: number; address: string; logoURI: string }[];
}>(`https://tokens.coingecko.com/metis-andromeda/all.json`);

const tokens = [common.getNativeToken(chainId)];
for (const { address, decimals, symbol, name } of data.tokens) {
tokens.push(new common.Token(chainId, address, decimals, symbol, name));
for (const { address, decimals, symbol, name, logoURI } of data.tokens) {
tokens.push(new common.Token(chainId, address, decimals, symbol, name, logoURI));
}

return tokens;
Expand Down Expand Up @@ -93,7 +93,7 @@ export async function getTokenList(
const tmp: Record<string, boolean> = defaultTokenList.reduce((acc, token) => ({ [token.address]: true }), {});
const tokenList: common.Token[] = [...defaultTokenList];
for (const { tokens } of tokenLists) {
for (const { chainId, address, decimals, symbol, name } of tokens) {
for (const { chainId, address, decimals, symbol, name, logoURI } of tokens) {
const lowerCaseAddress = address.toLowerCase();

if (
Expand All @@ -105,7 +105,7 @@ export async function getTokenList(
!ethers.utils.isAddress(address)
)
continue;
tokenList.push(new common.Token(chainId, address, decimals, symbol, name));
tokenList.push(new common.Token(chainId, address, decimals, symbol, name, logoURI));
tmp[lowerCaseAddress] = true;
}
}
Expand Down

0 comments on commit 40c1d04

Please sign in to comment.