Skip to content

Commit

Permalink
devop: switch solana asset handler to helius
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Dec 17, 2024
1 parent eec3ed6 commit 1181518
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class API implements ProviderAPIInterface {
name: 'Unknown',
symbol: 'UNKNWN',
decimals: 18,
icon: undefined,
};
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export default (
(obj, cur) => ({ ...obj, [cur.contract]: cur }),
{},
);

const marketData = new MarketData();

const marketInfo = supportedNetworks[networkName].cgPlatform
Expand Down Expand Up @@ -336,7 +335,10 @@ export default (
balancef: formatFloatingPointValue(userBalance).value,
balanceUSD: 0,
balanceUSDf: formatFiatValue('0').value,
icon: tokenInfo[unknownTokens[idx]]?.logoURI || network.icon,
icon:
tokenInfo[unknownTokens[idx]]?.logoURI ||
tInfo.icon ||
network.icon,
name: tInfo.name,
symbol: tInfo.symbol,
value: '0',
Expand All @@ -350,7 +352,6 @@ export default (
});
});
}

return assets;
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const getBalances = (network: BaseNetwork, address: string) => {
(acc.account.data as any).parsed.info.tokenAmount.amount,
);
if (balance === '0x0') return;
if ((acc.account.data as any).parsed.info.tokenAmount.decimals === 0)
// skip tokens with 0 decimals because it is an NFT
return;
const contract = (acc.account.data as any).parsed.info.mint;
if (!balanceObj[contract]) balanceObj[contract] = toBN(0);
balanceObj[contract] = balanceObj[contract].add(toBN(balance));
Expand Down
1 change: 1 addition & 0 deletions packages/extension/src/providers/ethereum/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface ERC20TokenInfo {
name: string;
symbol: string;
decimals: number;
icon?: string;
}
export interface JsonRpcRequest {
id: string;
Expand Down
59 changes: 30 additions & 29 deletions packages/extension/src/providers/solana/libs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class API implements ProviderAPIInterface {
return getSolAddress(pubkey);
}

async init(): Promise<void> { }
async init(): Promise<void> {}

/**
* Returns null if the transaction hasn't been received by the node
Expand All @@ -33,7 +33,7 @@ class API implements ProviderAPIInterface {
const tx = await this.web3.getTransaction(hash, {
maxSupportedTransactionVersion: 0,
commitment: 'confirmed',
})
});

if (!tx) {
// Transaction hasn't been picked up by the node
Expand Down Expand Up @@ -66,39 +66,41 @@ class API implements ProviderAPIInterface {
}

getTokenInfo = async (contractAddress: string): Promise<SPLTokenInfo> => {
interface TokenDetails {
address: string;
decimals: number;
name: string;
symbol: string;
logoURI: string;
extensions?: { coingeckoId: string };
}
const allTokensResponse = await cacheFetch(
const tokenResponse: {
result?: {
token_info: {
symbol: string;
decimals: number;
};
content: {
files: { uri: string }[];
metadata: {
name: string;
symbol: string;
};
};
};
} = await cacheFetch(
{
url: 'https://raw.githubusercontent.com/solflare-wallet/token-list/refs/heads/master/solana-tokenlist.json',
postProcess: (data: any) => {
const allTokens = data.tokens as TokenDetails[];
const tObj: Record<string, TokenDetails> = {};
allTokens.forEach(t => {
tObj[t.address] = t;
});
return tObj;
url: this.node,
post: {
jsonrpc: '2.0',
id: 1,
method: 'getAsset',
params: {
id: contractAddress,
},
},
},
6 * 60 * 60 * 1000,
);
const allTokens = allTokensResponse as Record<string, TokenDetails>;
let decimals = 9;
if (allTokens[contractAddress]) {
if (tokenResponse.result) {
return {
name: allTokens[contractAddress].name,
symbol: allTokens[contractAddress].symbol,
decimals: allTokens[contractAddress].decimals,
icon: allTokens[contractAddress].logoURI,
cgId: allTokens[contractAddress].extensions?.coingeckoId
? allTokens[contractAddress].extensions?.coingeckoId
: undefined,
name: tokenResponse.result.content.metadata.name,
symbol: tokenResponse.result.content.metadata.symbol,
decimals: tokenResponse.result.token_info.decimals,
icon: `https://img.mewapi.io/?image=${tokenResponse.result.content.files[0].uri}`,
};
} else {
await this.web3
Expand All @@ -115,7 +117,6 @@ class API implements ProviderAPIInterface {
symbol: 'UNKNWN',
decimals,
icon: undefined,
cgId: undefined,
};
};
}
Expand Down
4 changes: 1 addition & 3 deletions packages/extension/src/providers/solana/types/sol-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import SolanaAPI from '@/providers/bitcoin/libs/api';
import { ERC20TokenInfo } from '@/providers/ethereum/types';

export interface SPLTokenInfo extends ERC20TokenInfo {
icon: string | undefined;
cgId: string | undefined;
cgId?: string;
}

export interface SolTokenOptions extends BaseTokenOptions {
contract: string;
}
Expand Down

0 comments on commit 1181518

Please sign in to comment.