Skip to content

Commit

Permalink
Revert "fix: asset uniqueIds (#1421)"
Browse files Browse the repository at this point in the history
This reverts commit b1e3f5e.
  • Loading branch information
DanielSinclair committed Mar 29, 2024
1 parent bb36850 commit 7c6c4bb
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 128 deletions.
4 changes: 2 additions & 2 deletions src/core/resources/assets/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { createQueryKey } from '~/core/react-query';
import { SupportedCurrencyKey } from '~/core/references';
import { connectedToHardhatStore } from '~/core/state/currentSettings/connectedToHardhat';
import {
AssetApiResponse,
ParsedAssetsDictByChain,
ParsedUserAsset,
ZerionAsset,
} from '~/core/types/assets';
import { ChainId } from '~/core/types/chains';
import {
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function parseUserAssets({
assets: {
quantity: string;
small_balance?: boolean;
asset: AssetApiResponse;
asset: ZerionAsset;
}[];
chainIds: ChainId[];
currency: SupportedCurrencyKey;
Expand Down
2 changes: 1 addition & 1 deletion src/core/resources/assets/customNetworkAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async function customNetworkAssetsFunction({
isNativeAsset: true,
name: chain.nativeCurrency.symbol,
symbol: chain.nativeCurrency.symbol,
uniqueId: `${AddressZero}_${chain.id}`,
uniqueId: `${ETH_ADDRESS}_${chain.id}`,
decimals: 18,
native: { price: undefined },
price: { value: 0 },
Expand Down
9 changes: 2 additions & 7 deletions src/core/types/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,10 @@ export interface ZerionAssetPrice {

export type AssetApiResponse = {
asset_code: AddressOrEth;
bridging: {
bridgeable: boolean;
networks: { [id in ChainId]?: { bridgeable: boolean } };
};
decimals: number;
icon_url: string;
name: string;
chain_id: number;
chain_id?: number;
price?: {
value: number;
changed_at: number;
Expand Down Expand Up @@ -158,8 +154,7 @@ export type ProtocolType =
| 'pickle'
| 'yearn-v3'
| 'venus'
| 'sushiswap'
| 'native';
| 'sushiswap';

export type AssetMetadata = {
circulatingSupply: number;
Expand Down
6 changes: 3 additions & 3 deletions src/core/types/refraction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetApiResponse } from '~/core/types/assets';
import { ZerionAsset } from '~/core/types/assets';
import { ChainId, ChainName } from '~/core/types/chains';
import { PaginatedTransactionsApiResponse } from '~/core/types/transactions';

Expand All @@ -23,7 +23,7 @@ export interface MessageMeta {
export interface AddressAssetsReceivedMessage {
payload?: {
assets?: {
asset: AssetApiResponse;
asset: ZerionAsset;
quantity: string;
small_balances?: boolean;
}[];
Expand All @@ -47,7 +47,7 @@ export interface TransactionsReceivedMessage {
export interface AssetPricesReceivedMessage {
payload?: {
prices?: {
[id: string]: AssetApiResponse;
[id: string]: ZerionAsset;
};
};
meta?: MessageMeta;
Expand Down
155 changes: 74 additions & 81 deletions src/core/utils/assets.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { AddressZero } from '@ethersproject/constants';
import { expect, test } from 'vitest';

import { ETH_ADDRESS } from '../references';
import { AddressOrEth, AssetApiResponse, AssetMetadata } from '../types/assets';
import { AddressOrEth, AssetMetadata, ZerionAsset } from '../types/assets';
import { ChainId, ChainName } from '../types/chains';
import { SearchAsset } from '../types/search';

Expand All @@ -15,41 +13,50 @@ import {

const ETH_FROM_ZERION = {
asset_code: 'eth',
chain_id: ChainId.mainnet,
name: 'Ethereum',
symbol: 'ETH',
decimals: 18,
price: {
value: 1499.87,
relative_change_24h: -3.4472325578401155,
changed_at: 1678390027,
},
networks: {
[ChainId.arbitrum]: {
address: AddressZero,
implementations: {
arbitrum: {
address: null,
decimals: 18,
},
aurora: {
address: null,
decimals: 18,
},
ethereum: {
address: null,
decimals: 18,
},
[ChainId.mainnet]: {
address: ETH_ADDRESS,
loopring: {
address: '0x0000000000000000000000000000000000000000',
decimals: 18,
},
[ChainId.optimism]: {
address: AddressZero,
optimism: {
address: null,
decimals: 18,
},
},
icon_url:
'https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/smartchain/0x2170ed0880ac9a755fd29b2688956bd959f933f8.png',
price: {
value: 1499.87,
relative_change_24h: -3.4472325578401155,
},
is_displayable: true,
is_verified: true,
colors: {
primary: '#808088',
fallback: '#E8EAF5',
},
network: ChainName.mainnet,
mainnet_address: 'eth',
bridging: {
bridgeable: true,
networks: [],
},
} satisfies AssetApiResponse;
} satisfies ZerionAsset;

const ETH_FROM_SEARCH: SearchAsset = {
decimals: 18,
Expand Down Expand Up @@ -137,62 +144,82 @@ const ETH_FROM_METADATA = {

const BSC_ETH_FROM_ZERION = {
asset_code: '0x2170ed0880ac9a755fd29b2688956bd959f933f8',
chain_id: ChainId.bsc,
decimals: 18,
icon_url:
'https://rainbowme-res.cloudinary.com/image/upload/v1668565116/assets/smartchain/0x2170ed0880ac9a755fd29b2688956bd959f933f8.png',
name: 'Ethereum',
network: 'bsc' as ChainName,
price: {
value: 1500.67,
relative_change_24h: -3.3290651940864646,
},
symbol: 'ETH',
colors: {
primary: '#808088',
fallback: '#E8EAF5',
},
mainnet_address: 'eth',
bridging: {
bridgeable: true,
networks: [],
},
price: {
value: 1500.67,
relative_change_24h: -3.3290651940864646,
changed_at: 1678390027,
},
} satisfies AssetApiResponse;
} satisfies ZerionAsset;

const USD_FROM_ZERION = {
asset_code: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
chain_id: ChainId.mainnet,
name: 'USD Coin',
symbol: 'USDC',
decimals: 6,
networks: {
'1': {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
implementations: {
arbitrum: {
address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',
decimals: 6,
},
'10': {
address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
aurora: {
address: '0xb12bfca5a55806aaf64e99521918a4bf0fc40802',
decimals: 6,
},
'56': {
avalanche: {
address: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
decimals: 6,
},
'binance-smart-chain': {
address: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
decimals: 18,
},
'137': {
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
ethereum: {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
decimals: 6,
},
'42161': {
address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',
fantom: {
address: '0x04068da6c83afcfa0e13ba15a6696662335d5b75',
decimals: 6,
},
'43114': {
address: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
loopring: {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
decimals: 6,
},
optimism: {
address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
decimals: 6,
},
polygon: {
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
decimals: 6,
},
xdai: {
address: '0xddafbb505ad214d7b80b1f830fccc89b60fb7a83',
decimals: 6,
},
},
icon_url:
'https://rainbowme-res.cloudinary.com/image/upload/v1668633498/assets/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png',
price: {
value: 1.0034249098613037,
relative_change_24h: 0.3604239001534948,
},
is_displayable: true,
is_verified: true,
colors: {
primary: '#2775CA',
fallback: '#9ABDE8',
Expand All @@ -201,19 +228,14 @@ const USD_FROM_ZERION = {
bridgeable: true,
networks: [],
},
price: {
value: 1.0034249098613037,
relative_change_24h: 0.3604239001534948,
changed_at: 1678390027,
},
} satisfies AssetApiResponse;
} satisfies ZerionAsset;

const OPTIMISM_USD_FROM_SEARCH = {
decimals: 6,
highLiquidity: true,
name: 'USD Coin',
symbol: 'USDC',
uniqueId: '0x7f5c764cbc14f9669b88837ca1490cca17c31607_10',
uniqueId: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48_10',
colors: {
primary: '#2775CA',
fallback: '#9ABDE8',
Expand Down Expand Up @@ -257,53 +279,26 @@ const OPTIMISM_USD_FROM_SEARCH = {

const OPTIMISM_USD_FROM_ZERION = {
asset_code: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
chain_id: ChainId.optimism,
decimals: 6,
icon_url:
'https://rainbowme-res.cloudinary.com/image/upload/v1668633498/assets/ethereum/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png',
name: 'USD Coin',
network: ChainName.optimism,
price: {
value: 1.001,
relative_change_24h: 0.06633900739942358,
},
symbol: 'USDC',
colors: {
primary: '#2775CA',
fallback: '#9ABDE8',
},
mainnet_address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
bridging: {
bridgeable: true,
networks: [],
},
networks: {
'1': {
address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
decimals: 6,
},
'10': {
address: '0x7f5c764cbc14f9669b88837ca1490cca17c31607',
decimals: 6,
},
'56': {
address: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d',
decimals: 18,
},
'137': {
address: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
decimals: 6,
},
'42161': {
address: '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8',
decimals: 6,
},
'43114': {
address: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
decimals: 6,
},
},
price: {
value: 1.001,
relative_change_24h: 0.06633900739942358,
changed_at: 1678390027,
},
} satisfies AssetApiResponse;
} satisfies ZerionAsset;

const OPTIMISM_USD_FROM_METADATA = {
colors: {
Expand Down Expand Up @@ -371,9 +366,7 @@ test('[utils/assets -> parseAsset] :: parse zerion asset', async () => {
asset: BSC_ETH_FROM_ZERION,
currency: 'EUR',
});
expect(bscEth.uniqueId).toEqual(
'0x2170ed0880ac9a755fd29b2688956bd959f933f8_56',
);
expect(bscEth.uniqueId).toEqual('eth_56');
expect(bscEth.isNativeAsset).toEqual(false);
expect(bscEth.native.price?.display[0]).toEqual('€');

Expand All @@ -391,7 +384,7 @@ test('[utils/assets -> parseAsset] :: parse zerion asset', async () => {
currency: 'USD',
});
expect(optimismUSD.uniqueId).toEqual(
`${OPTIMISM_USD_FROM_ZERION.asset_code}_${ChainId.optimism}`,
`${OPTIMISM_USD_FROM_ZERION.mainnet_address}_${ChainId.optimism}`,
);
expect(optimismUSD.isNativeAsset).toEqual(false);
expect(optimismUSD.native.price?.display[0]).toEqual('$');
Expand Down

0 comments on commit 7c6c4bb

Please sign in to comment.