@shapeshiftoss/utils 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/.tsbuildinfo +1 -0
- package/dist/cjs/assertUnreachable.d.ts +1 -0
- package/dist/cjs/assertUnreachable.js +7 -0
- package/dist/cjs/assetData/assetData.test.d.ts +1 -0
- package/dist/cjs/assetData/assetData.test.js +136 -0
- package/dist/cjs/assetData/baseAssets.d.ts +24 -0
- package/dist/cjs/assetData/baseAssets.js +365 -0
- package/dist/cjs/assetData/constants.d.ts +1 -0
- package/dist/cjs/assetData/constants.js +13 -0
- package/dist/cjs/assetData/decodeAssetData.d.ts +7 -0
- package/dist/cjs/assetData/decodeAssetData.js +106 -0
- package/dist/cjs/assetData/decodeRelatedAssetIndex.d.ts +3 -0
- package/dist/cjs/assetData/decodeRelatedAssetIndex.js +14 -0
- package/dist/cjs/assetData/encodeAssetData.d.ts +4 -0
- package/dist/cjs/assetData/encodeAssetData.js +72 -0
- package/dist/cjs/assetData/encodeRelatedAssetIndex.d.ts +3 -0
- package/dist/cjs/assetData/encodeRelatedAssetIndex.js +20 -0
- package/dist/cjs/assetData/getBaseAsset.d.ts +3 -0
- package/dist/cjs/assetData/getBaseAsset.js +54 -0
- package/dist/cjs/assetData/index.d.ts +7 -0
- package/dist/cjs/assetData/index.js +23 -0
- package/dist/cjs/assetData/relatedAssetIndex.test.d.ts +1 -0
- package/dist/cjs/assetData/relatedAssetIndex.test.js +32 -0
- package/dist/cjs/assetData/types.d.ts +28 -0
- package/dist/cjs/assetData/types.js +2 -0
- package/dist/cjs/baseUnits/baseUnits.d.ts +5 -0
- package/dist/cjs/baseUnits/baseUnits.js +32 -0
- package/dist/cjs/baseUnits/baseUnits.test.d.ts +1 -0
- package/dist/cjs/baseUnits/baseUnits.test.js +32 -0
- package/dist/cjs/basisPoints.d.ts +23 -0
- package/dist/cjs/basisPoints.js +48 -0
- package/dist/cjs/bignumber/bignumber.d.ts +11 -0
- package/dist/cjs/bignumber/bignumber.js +27 -0
- package/dist/cjs/bignumber/bignumber.test.d.ts +1 -0
- package/dist/cjs/bignumber/bignumber.test.js +52 -0
- package/dist/cjs/chainIdToFeeAsset.d.ts +3 -0
- package/dist/cjs/chainIdToFeeAsset.js +9 -0
- package/dist/cjs/chainIdToFeeAssetId.d.ts +2 -0
- package/dist/cjs/chainIdToFeeAssetId.js +54 -0
- package/dist/cjs/createThrottle.d.ts +9 -0
- package/dist/cjs/createThrottle.js +36 -0
- package/dist/cjs/getAssetNamespaceFromChainId.d.ts +3 -0
- package/dist/cjs/getAssetNamespaceFromChainId.js +37 -0
- package/dist/cjs/getChainShortName.d.ts +2 -0
- package/dist/cjs/getChainShortName.js +53 -0
- package/dist/cjs/getNativeFeeAssetReference.d.ts +2 -0
- package/dist/cjs/getNativeFeeAssetReference.js +83 -0
- package/dist/cjs/historyTimeframe.d.ts +6 -0
- package/dist/cjs/historyTimeframe.js +36 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +60 -0
- package/dist/cjs/makeAsset/makeAsset.d.ts +10 -0
- package/dist/cjs/makeAsset/makeAsset.js +45 -0
- package/dist/cjs/makeAsset/makeAsset.test.d.ts +1 -0
- package/dist/cjs/makeAsset/makeAsset.test.js +47 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/promises.d.ts +4 -0
- package/dist/cjs/promises.js +9 -0
- package/dist/cjs/sha256.d.ts +1 -0
- package/dist/cjs/sha256.js +9 -0
- package/dist/cjs/timeout.d.ts +7 -0
- package/dist/cjs/timeout.js +34 -0
- package/dist/cjs/treasury.d.ts +16 -0
- package/dist/cjs/treasury.js +34 -0
- package/dist/cjs/unfreeze.d.ts +4 -0
- package/dist/cjs/unfreeze.js +10 -0
- package/dist/cjs/utxo.d.ts +2 -0
- package/dist/cjs/utxo.js +6 -0
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/assertUnreachable.d.ts +1 -0
- package/dist/esm/assertUnreachable.js +3 -0
- package/dist/esm/assetData/assetData.test.d.ts +1 -0
- package/dist/esm/assetData/assetData.test.js +134 -0
- package/dist/esm/assetData/baseAssets.d.ts +24 -0
- package/dist/esm/assetData/baseAssets.js +339 -0
- package/dist/esm/assetData/constants.d.ts +1 -0
- package/dist/esm/assetData/constants.js +10 -0
- package/dist/esm/assetData/decodeAssetData.d.ts +7 -0
- package/dist/esm/assetData/decodeAssetData.js +102 -0
- package/dist/esm/assetData/decodeRelatedAssetIndex.d.ts +3 -0
- package/dist/esm/assetData/decodeRelatedAssetIndex.js +10 -0
- package/dist/esm/assetData/encodeAssetData.d.ts +4 -0
- package/dist/esm/assetData/encodeAssetData.js +68 -0
- package/dist/esm/assetData/encodeRelatedAssetIndex.d.ts +3 -0
- package/dist/esm/assetData/encodeRelatedAssetIndex.js +16 -0
- package/dist/esm/assetData/getBaseAsset.d.ts +3 -0
- package/dist/esm/assetData/getBaseAsset.js +50 -0
- package/dist/esm/assetData/index.d.ts +7 -0
- package/dist/esm/assetData/index.js +7 -0
- package/dist/esm/assetData/relatedAssetIndex.test.d.ts +1 -0
- package/dist/esm/assetData/relatedAssetIndex.test.js +30 -0
- package/dist/esm/assetData/types.d.ts +28 -0
- package/dist/esm/assetData/types.js +1 -0
- package/dist/esm/baseUnits/baseUnits.d.ts +5 -0
- package/dist/esm/baseUnits/baseUnits.js +23 -0
- package/dist/esm/baseUnits/baseUnits.test.d.ts +1 -0
- package/dist/esm/baseUnits/baseUnits.test.js +30 -0
- package/dist/esm/basisPoints.d.ts +23 -0
- package/dist/esm/basisPoints.js +39 -0
- package/dist/esm/bignumber/bignumber.d.ts +11 -0
- package/dist/esm/bignumber/bignumber.js +16 -0
- package/dist/esm/bignumber/bignumber.test.d.ts +1 -0
- package/dist/esm/bignumber/bignumber.test.js +50 -0
- package/dist/esm/chainIdToFeeAsset.d.ts +3 -0
- package/dist/esm/chainIdToFeeAsset.js +5 -0
- package/dist/esm/chainIdToFeeAssetId.d.ts +2 -0
- package/dist/esm/chainIdToFeeAssetId.js +50 -0
- package/dist/esm/createThrottle.d.ts +9 -0
- package/dist/esm/createThrottle.js +32 -0
- package/dist/esm/getAssetNamespaceFromChainId.d.ts +3 -0
- package/dist/esm/getAssetNamespaceFromChainId.js +33 -0
- package/dist/esm/getChainShortName.d.ts +2 -0
- package/dist/esm/getChainShortName.js +49 -0
- package/dist/esm/getNativeFeeAssetReference.d.ts +2 -0
- package/dist/esm/getNativeFeeAssetReference.js +79 -0
- package/dist/esm/historyTimeframe.d.ts +6 -0
- package/dist/esm/historyTimeframe.js +29 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +39 -0
- package/dist/esm/makeAsset/makeAsset.d.ts +10 -0
- package/dist/esm/makeAsset/makeAsset.js +41 -0
- package/dist/esm/makeAsset/makeAsset.test.d.ts +1 -0
- package/dist/esm/makeAsset/makeAsset.test.js +45 -0
- package/dist/esm/promises.d.ts +4 -0
- package/dist/esm/promises.js +3 -0
- package/dist/esm/sha256.d.ts +1 -0
- package/dist/esm/sha256.js +2 -0
- package/dist/esm/timeout.d.ts +7 -0
- package/dist/esm/timeout.js +28 -0
- package/dist/esm/treasury.d.ts +16 -0
- package/dist/esm/treasury.js +30 -0
- package/dist/esm/unfreeze.d.ts +4 -0
- package/dist/esm/unfreeze.js +6 -0
- package/dist/esm/utxo.d.ts +2 -0
- package/dist/esm/utxo.js +2 -0
- package/package.json +3 -3
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { decodeAssetData } from './decodeAssetData.js';
|
|
3
|
+
import { encodeAssetData } from './encodeAssetData.js';
|
|
4
|
+
const mockGeneratedAssetData = {
|
|
5
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0': {
|
|
6
|
+
assetId: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
7
|
+
chainId: 'bip122:000000000019d6689c085ae165831e93',
|
|
8
|
+
symbol: 'BTC',
|
|
9
|
+
name: 'Bitcoin',
|
|
10
|
+
networkName: 'Bitcoin',
|
|
11
|
+
precision: 8,
|
|
12
|
+
color: '#FF9800',
|
|
13
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/bitcoin/info/logo.png',
|
|
14
|
+
explorer: 'https://live.blockcypher.com',
|
|
15
|
+
explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
|
|
16
|
+
explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
|
|
17
|
+
relatedAssetKey: null,
|
|
18
|
+
isPrimary: true,
|
|
19
|
+
isChainSpecific: true,
|
|
20
|
+
},
|
|
21
|
+
'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c': {
|
|
22
|
+
assetId: 'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
|
|
23
|
+
chainId: 'eip155:1',
|
|
24
|
+
name: 'Inception Restaked ETH on Ethereum',
|
|
25
|
+
precision: 18,
|
|
26
|
+
color: '#D6D1E4',
|
|
27
|
+
icon: 'https://assets.coingecko.com/coins/images/34127/large/inETH.png?1715036464',
|
|
28
|
+
symbol: 'INETH',
|
|
29
|
+
explorer: 'https://etherscan.io',
|
|
30
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
31
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
32
|
+
relatedAssetKey: 'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
|
|
33
|
+
isPrimary: true,
|
|
34
|
+
isChainSpecific: false,
|
|
35
|
+
},
|
|
36
|
+
'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd': {
|
|
37
|
+
assetId: 'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd',
|
|
38
|
+
chainId: 'eip155:1',
|
|
39
|
+
name: 'EveryCoin',
|
|
40
|
+
precision: 12,
|
|
41
|
+
color: '#0483CB',
|
|
42
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xEEd3aE7b0F8b5B9BB8C035A9941382B1822671CD/logo.png',
|
|
43
|
+
symbol: 'EVY',
|
|
44
|
+
explorer: 'https://etherscan.io',
|
|
45
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
46
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
47
|
+
relatedAssetKey: null,
|
|
48
|
+
isPrimary: true,
|
|
49
|
+
isChainSpecific: true,
|
|
50
|
+
},
|
|
51
|
+
'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d': {
|
|
52
|
+
explorer: 'https://etherscan.io',
|
|
53
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
54
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
55
|
+
color: '#FFFFFF',
|
|
56
|
+
icon: undefined,
|
|
57
|
+
icons: [
|
|
58
|
+
'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0xD9A442856C234a39a81a089C06451EBAa4306a72/logo.png',
|
|
59
|
+
'https://rawcdn.githack.com/trustwallet/assets/master/blockchains/ethereum/assets/0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0/logo.png',
|
|
60
|
+
],
|
|
61
|
+
name: 'Curve PUFETH/WSTETH Pool',
|
|
62
|
+
precision: 18,
|
|
63
|
+
symbol: 'pufETHwstE',
|
|
64
|
+
chainId: 'eip155:1',
|
|
65
|
+
assetId: 'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d',
|
|
66
|
+
relatedAssetKey: null,
|
|
67
|
+
isPool: true,
|
|
68
|
+
isPrimary: true,
|
|
69
|
+
isChainSpecific: true,
|
|
70
|
+
},
|
|
71
|
+
'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf': {
|
|
72
|
+
assetId: 'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf',
|
|
73
|
+
chainId: 'eip155:1',
|
|
74
|
+
name: 'The QWAN',
|
|
75
|
+
precision: 18,
|
|
76
|
+
color: '#18B6BE',
|
|
77
|
+
icon: 'https://assets.coingecko.com/coins/images/30613/large/qwan.jpg?1696529482',
|
|
78
|
+
symbol: 'QWAN',
|
|
79
|
+
explorer: 'https://etherscan.io',
|
|
80
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
81
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
82
|
+
relatedAssetKey: null,
|
|
83
|
+
isPrimary: true,
|
|
84
|
+
isChainSpecific: true,
|
|
85
|
+
},
|
|
86
|
+
'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33': {
|
|
87
|
+
assetId: 'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33',
|
|
88
|
+
chainId: 'eip155:1',
|
|
89
|
+
name: 'Big Tom',
|
|
90
|
+
precision: 9,
|
|
91
|
+
color: '#27DD08',
|
|
92
|
+
icon: 'https://assets.coingecko.com/coins/images/38555/large/huyah_%281%29.jpg?1717999187',
|
|
93
|
+
symbol: 'TOM',
|
|
94
|
+
explorer: 'https://etherscan.io',
|
|
95
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
96
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
97
|
+
relatedAssetKey: null,
|
|
98
|
+
isPrimary: true,
|
|
99
|
+
isChainSpecific: true,
|
|
100
|
+
},
|
|
101
|
+
'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f': {
|
|
102
|
+
assetId: 'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f',
|
|
103
|
+
chainId: 'eip155:1',
|
|
104
|
+
name: 'Forgotten Playland',
|
|
105
|
+
precision: 18,
|
|
106
|
+
color: '#35355D',
|
|
107
|
+
icon: 'https://assets.coingecko.com/coins/images/35339/large/200.png?1708515043',
|
|
108
|
+
symbol: 'FP',
|
|
109
|
+
explorer: 'https://etherscan.io',
|
|
110
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
111
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
112
|
+
relatedAssetKey: null,
|
|
113
|
+
isPrimary: true,
|
|
114
|
+
isChainSpecific: true,
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
// Order of these is deliberately shuffled to test sorting is preserved
|
|
118
|
+
const mockSortedAssetIds = [
|
|
119
|
+
'eip155:1/erc20:0xeeecd285f60e802ecb6d8d8d37790c887f9a4b33',
|
|
120
|
+
'eip155:1/erc20:0xeeee2a2e650697d2a8e8bc990c2f3d04203be06f',
|
|
121
|
+
'eip155:1/erc20:0xeed3ae7b0f8b5b9bb8c035a9941382b1822671cd',
|
|
122
|
+
'eip155:1/erc20:0xf073bac22dab7faf4a3dd6c6189a70d54110525c',
|
|
123
|
+
'eip155:1/erc20:0xeee0fe52299f2de8e2ed5111cd521ab67dcf0faf',
|
|
124
|
+
'eip155:1/erc20:0xeeda34a377dd0ca676b9511ee1324974fa8d980d',
|
|
125
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0', // BTC
|
|
126
|
+
];
|
|
127
|
+
describe('assetData', () => {
|
|
128
|
+
it('can encode and decode asset data as a complete round trip', () => {
|
|
129
|
+
const encodedAssetData = encodeAssetData(mockSortedAssetIds, mockGeneratedAssetData);
|
|
130
|
+
const { assetData, sortedAssetIds } = decodeAssetData(encodedAssetData);
|
|
131
|
+
expect(assetData).toEqual(mockGeneratedAssetData);
|
|
132
|
+
expect(sortedAssetIds).toEqual(mockSortedAssetIds);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
2
|
+
export declare const ethereum: Readonly<Asset>;
|
|
3
|
+
export declare const bitcoin: Readonly<Asset>;
|
|
4
|
+
export declare const bitcoincash: Readonly<Asset>;
|
|
5
|
+
export declare const dogecoin: Readonly<Asset>;
|
|
6
|
+
export declare const litecoin: Readonly<Asset>;
|
|
7
|
+
export declare const atom: Readonly<Asset>;
|
|
8
|
+
export declare const avax: Readonly<Asset>;
|
|
9
|
+
export declare const thorchain: Readonly<Asset>;
|
|
10
|
+
export declare const tcy: Readonly<Asset>;
|
|
11
|
+
export declare const ruji: Readonly<Asset>;
|
|
12
|
+
export declare const maya: Readonly<Asset>;
|
|
13
|
+
export declare const mayachain: Readonly<Asset>;
|
|
14
|
+
export declare const optimism: Readonly<Asset>;
|
|
15
|
+
export declare const bnbsmartchain: Readonly<Asset>;
|
|
16
|
+
export declare const polygon: Readonly<Asset>;
|
|
17
|
+
export declare const gnosis: Readonly<Asset>;
|
|
18
|
+
export declare const arbitrum: Readonly<Asset>;
|
|
19
|
+
export declare const arbitrumNova: Readonly<Asset>;
|
|
20
|
+
export declare const base: Readonly<Asset>;
|
|
21
|
+
export declare const monad: Readonly<Asset>;
|
|
22
|
+
export declare const solana: Readonly<Asset>;
|
|
23
|
+
export declare const tron: Readonly<Asset>;
|
|
24
|
+
export declare const sui: Readonly<Asset>;
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import * as caip from '@shapeshiftoss/caip';
|
|
2
|
+
const mayaTokenAssetId = 'cosmos:mayachain-mainnet-v1/slip44:maya';
|
|
3
|
+
export const ethereum = Object.freeze({
|
|
4
|
+
assetId: caip.ethAssetId,
|
|
5
|
+
chainId: caip.ethChainId,
|
|
6
|
+
symbol: 'ETH',
|
|
7
|
+
name: 'Ethereum',
|
|
8
|
+
networkName: 'Ethereum',
|
|
9
|
+
precision: 18,
|
|
10
|
+
color: '#5C6BC0',
|
|
11
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
|
|
12
|
+
explorer: 'https://etherscan.io',
|
|
13
|
+
explorerAddressLink: 'https://etherscan.io/address/',
|
|
14
|
+
explorerTxLink: 'https://etherscan.io/tx/',
|
|
15
|
+
relatedAssetKey: 'eip155:1/slip44:60',
|
|
16
|
+
});
|
|
17
|
+
export const bitcoin = Object.freeze({
|
|
18
|
+
assetId: caip.btcAssetId,
|
|
19
|
+
chainId: caip.btcChainId,
|
|
20
|
+
symbol: 'BTC',
|
|
21
|
+
name: 'Bitcoin',
|
|
22
|
+
networkName: 'Bitcoin',
|
|
23
|
+
precision: 8,
|
|
24
|
+
color: '#FF9800',
|
|
25
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/bitcoin/info/logo.png',
|
|
26
|
+
explorer: 'https://live.blockcypher.com',
|
|
27
|
+
explorerAddressLink: 'https://live.blockcypher.com/btc/address/',
|
|
28
|
+
explorerTxLink: 'https://live.blockcypher.com/btc/tx/',
|
|
29
|
+
relatedAssetKey: null,
|
|
30
|
+
});
|
|
31
|
+
export const bitcoincash = Object.freeze({
|
|
32
|
+
assetId: caip.bchAssetId,
|
|
33
|
+
chainId: caip.bchChainId,
|
|
34
|
+
symbol: 'BCH',
|
|
35
|
+
name: 'Bitcoin Cash',
|
|
36
|
+
networkName: 'Bitcoin Cash',
|
|
37
|
+
precision: 8,
|
|
38
|
+
color: '#8BC34A',
|
|
39
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/bitcoincash/info/logo.png',
|
|
40
|
+
explorer: 'https://blockchair.com',
|
|
41
|
+
explorerAddressLink: 'https://blockchair.com/bitcoin-cash/address/',
|
|
42
|
+
explorerTxLink: 'https://blockchair.com/bitcoin-cash/transaction/',
|
|
43
|
+
relatedAssetKey: null,
|
|
44
|
+
});
|
|
45
|
+
export const dogecoin = Object.freeze({
|
|
46
|
+
assetId: caip.dogeAssetId,
|
|
47
|
+
chainId: caip.dogeChainId,
|
|
48
|
+
symbol: 'DOGE',
|
|
49
|
+
name: 'Dogecoin',
|
|
50
|
+
networkName: 'Dogecoin',
|
|
51
|
+
precision: 8,
|
|
52
|
+
color: '#FFC107',
|
|
53
|
+
icon: 'https://assets.coingecko.com/coins/images/5/large/dogecoin.png?1696501409',
|
|
54
|
+
explorer: 'https://live.blockcypher.com',
|
|
55
|
+
explorerAddressLink: 'https://live.blockcypher.com/doge/address/',
|
|
56
|
+
explorerTxLink: 'https://live.blockcypher.com/doge/tx/',
|
|
57
|
+
relatedAssetKey: null,
|
|
58
|
+
});
|
|
59
|
+
export const litecoin = Object.freeze({
|
|
60
|
+
assetId: caip.ltcAssetId,
|
|
61
|
+
chainId: caip.ltcChainId,
|
|
62
|
+
symbol: 'LTC',
|
|
63
|
+
name: 'Litecoin',
|
|
64
|
+
networkName: 'Litecoin',
|
|
65
|
+
precision: 8,
|
|
66
|
+
color: '#B8B8B8',
|
|
67
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/litecoin/info/logo.png',
|
|
68
|
+
explorer: 'https://live.blockcypher.com',
|
|
69
|
+
explorerAddressLink: 'https://live.blockcypher.com/ltc/address/',
|
|
70
|
+
explorerTxLink: 'https://live.blockcypher.com/ltc/tx/',
|
|
71
|
+
relatedAssetKey: null,
|
|
72
|
+
});
|
|
73
|
+
export const atom = Object.freeze({
|
|
74
|
+
assetId: caip.cosmosAssetId,
|
|
75
|
+
chainId: caip.cosmosChainId,
|
|
76
|
+
symbol: 'ATOM',
|
|
77
|
+
name: 'Cosmos',
|
|
78
|
+
networkName: 'Cosmos',
|
|
79
|
+
precision: 6,
|
|
80
|
+
color: '#303F9F',
|
|
81
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/cosmos/info/logo.png',
|
|
82
|
+
explorer: 'https://www.mintscan.io/cosmos',
|
|
83
|
+
explorerAddressLink: 'https://www.mintscan.io/cosmos/account/',
|
|
84
|
+
explorerTxLink: 'https://www.mintscan.io/cosmos/txs/',
|
|
85
|
+
relatedAssetKey: null,
|
|
86
|
+
});
|
|
87
|
+
export const avax = Object.freeze({
|
|
88
|
+
assetId: caip.avalancheAssetId,
|
|
89
|
+
chainId: caip.avalancheChainId,
|
|
90
|
+
name: 'Avalanche',
|
|
91
|
+
networkName: 'Avalanche C-Chain',
|
|
92
|
+
symbol: 'AVAX',
|
|
93
|
+
precision: 18,
|
|
94
|
+
color: '#FFFFFF',
|
|
95
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/avalanchec/info/logo.png',
|
|
96
|
+
explorer: 'https://snowtrace.dev',
|
|
97
|
+
explorerAddressLink: 'https://snowtrace.dev/address/',
|
|
98
|
+
explorerTxLink: 'https://snowtrace.dev/tx/',
|
|
99
|
+
relatedAssetKey: null,
|
|
100
|
+
});
|
|
101
|
+
export const thorchain = Object.freeze({
|
|
102
|
+
assetId: caip.thorchainAssetId,
|
|
103
|
+
chainId: caip.thorchainChainId,
|
|
104
|
+
name: 'THORChain',
|
|
105
|
+
networkName: 'THORChain',
|
|
106
|
+
symbol: 'RUNE',
|
|
107
|
+
precision: 8,
|
|
108
|
+
color: '#33FF99',
|
|
109
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/thorchain/info/logo.png',
|
|
110
|
+
explorer: 'https://viewblock.io/thorchain',
|
|
111
|
+
explorerAddressLink: 'https://viewblock.io/thorchain/address/',
|
|
112
|
+
explorerTxLink: 'https://viewblock.io/thorchain/tx/',
|
|
113
|
+
relatedAssetKey: null,
|
|
114
|
+
});
|
|
115
|
+
export const tcy = Object.freeze({
|
|
116
|
+
assetId: caip.tcyAssetId,
|
|
117
|
+
chainId: caip.thorchainChainId,
|
|
118
|
+
name: 'TCY',
|
|
119
|
+
networkName: 'THORChain',
|
|
120
|
+
symbol: 'TCY',
|
|
121
|
+
precision: 8,
|
|
122
|
+
color: '#33FF99',
|
|
123
|
+
icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/tcy-icon.png',
|
|
124
|
+
explorer: 'https://viewblock.io/thorchain',
|
|
125
|
+
explorerAddressLink: 'https://viewblock.io/thorchain/address/',
|
|
126
|
+
explorerTxLink: 'https://viewblock.io/thorchain/tx/',
|
|
127
|
+
relatedAssetKey: null,
|
|
128
|
+
});
|
|
129
|
+
export const ruji = Object.freeze({
|
|
130
|
+
assetId: caip.rujiAssetId,
|
|
131
|
+
chainId: caip.thorchainChainId,
|
|
132
|
+
name: 'Rujira',
|
|
133
|
+
networkName: 'THORChain',
|
|
134
|
+
symbol: 'RUJI',
|
|
135
|
+
precision: 8,
|
|
136
|
+
color: '#D800D8',
|
|
137
|
+
icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/ruji-icon.png',
|
|
138
|
+
explorer: 'https://viewblock.io/thorchain',
|
|
139
|
+
explorerAddressLink: 'https://viewblock.io/thorchain/address/',
|
|
140
|
+
explorerTxLink: 'https://viewblock.io/thorchain/tx/',
|
|
141
|
+
relatedAssetKey: null,
|
|
142
|
+
});
|
|
143
|
+
export const maya = Object.freeze({
|
|
144
|
+
assetId: mayaTokenAssetId,
|
|
145
|
+
chainId: caip.mayachainChainId,
|
|
146
|
+
name: 'MAYA',
|
|
147
|
+
networkName: 'MAYAChain',
|
|
148
|
+
symbol: 'MAYA',
|
|
149
|
+
precision: 4,
|
|
150
|
+
color: '#00FFA0',
|
|
151
|
+
icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/maya.png',
|
|
152
|
+
explorer: 'https://mayascan.org',
|
|
153
|
+
explorerAddressLink: 'https://mayascan.org/address/',
|
|
154
|
+
explorerTxLink: 'https://mayascan.org/tx/',
|
|
155
|
+
relatedAssetKey: null,
|
|
156
|
+
});
|
|
157
|
+
export const mayachain = Object.freeze({
|
|
158
|
+
assetId: caip.mayachainAssetId,
|
|
159
|
+
chainId: caip.mayachainChainId,
|
|
160
|
+
name: 'MAYAChain',
|
|
161
|
+
networkName: 'MAYAChain',
|
|
162
|
+
symbol: 'CACAO',
|
|
163
|
+
precision: 10,
|
|
164
|
+
color: '#63FDD9',
|
|
165
|
+
icon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/cacao.png',
|
|
166
|
+
networkIcon: 'https://raw.githubusercontent.com/shapeshift/web/develop/src/assets/mayachain.png',
|
|
167
|
+
explorer: 'https://mayascan.org',
|
|
168
|
+
explorerAddressLink: 'https://mayascan.org/address/',
|
|
169
|
+
explorerTxLink: 'https://mayascan.org/tx/',
|
|
170
|
+
relatedAssetKey: null,
|
|
171
|
+
});
|
|
172
|
+
export const optimism = Object.freeze({
|
|
173
|
+
assetId: caip.optimismAssetId,
|
|
174
|
+
chainId: caip.optimismChainId,
|
|
175
|
+
name: 'Ethereum',
|
|
176
|
+
networkName: 'Optimism',
|
|
177
|
+
symbol: 'ETH',
|
|
178
|
+
precision: 18,
|
|
179
|
+
color: '#5C6BC0',
|
|
180
|
+
networkColor: '#FC0424',
|
|
181
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
|
|
182
|
+
networkIcon: 'https://assets.coingecko.com/coins/images/25244/large/Optimism.png?1660904599',
|
|
183
|
+
explorer: 'https://optimistic.etherscan.io',
|
|
184
|
+
explorerAddressLink: 'https://optimistic.etherscan.io/address/',
|
|
185
|
+
explorerTxLink: 'https://optimistic.etherscan.io/tx/',
|
|
186
|
+
relatedAssetKey: 'eip155:1/slip44:60',
|
|
187
|
+
});
|
|
188
|
+
export const bnbsmartchain = Object.freeze({
|
|
189
|
+
assetId: caip.bscAssetId,
|
|
190
|
+
chainId: caip.bscChainId,
|
|
191
|
+
name: 'BNB',
|
|
192
|
+
networkName: 'BNB Smart Chain',
|
|
193
|
+
symbol: 'BNB',
|
|
194
|
+
precision: 18,
|
|
195
|
+
color: '#F0B90B',
|
|
196
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/binance/info/logo.png',
|
|
197
|
+
explorer: 'https://bscscan.com',
|
|
198
|
+
explorerAddressLink: 'https://bscscan.com/address/',
|
|
199
|
+
explorerTxLink: 'https://bscscan.com/tx/',
|
|
200
|
+
relatedAssetKey: null,
|
|
201
|
+
});
|
|
202
|
+
export const polygon = Object.freeze({
|
|
203
|
+
assetId: caip.polygonAssetId,
|
|
204
|
+
chainId: caip.polygonChainId,
|
|
205
|
+
name: 'Polygon Ecosystem Token',
|
|
206
|
+
networkName: 'Polygon',
|
|
207
|
+
symbol: 'POL',
|
|
208
|
+
precision: 18,
|
|
209
|
+
color: '#8f00ff',
|
|
210
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/polygon/info/logo.png',
|
|
211
|
+
explorer: 'https://polygonscan.com/',
|
|
212
|
+
explorerAddressLink: 'https://polygonscan.com/address/',
|
|
213
|
+
explorerTxLink: 'https://polygonscan.com/tx/',
|
|
214
|
+
relatedAssetKey: null,
|
|
215
|
+
});
|
|
216
|
+
export const gnosis = Object.freeze({
|
|
217
|
+
assetId: caip.gnosisAssetId,
|
|
218
|
+
chainId: caip.gnosisChainId,
|
|
219
|
+
name: 'xDAI',
|
|
220
|
+
networkName: 'Gnosis',
|
|
221
|
+
symbol: 'xDAI',
|
|
222
|
+
precision: 18,
|
|
223
|
+
color: '#33765c',
|
|
224
|
+
icon: 'https://assets.coingecko.com/coins/images/11062/large/Identity-Primary-DarkBG.png?1638372986',
|
|
225
|
+
networkIcon: 'https://assets.coingecko.com/asset_platforms/images/11062/large/Aatar_green_white.png?1643204471',
|
|
226
|
+
explorer: 'https://gnosis.blockscout.com/',
|
|
227
|
+
explorerAddressLink: 'https://gnosis.blockscout.com/address/',
|
|
228
|
+
explorerTxLink: 'https://gnosis.blockscout.com/tx/',
|
|
229
|
+
relatedAssetKey: null,
|
|
230
|
+
});
|
|
231
|
+
export const arbitrum = Object.freeze({
|
|
232
|
+
assetId: caip.arbitrumAssetId,
|
|
233
|
+
chainId: caip.arbitrumChainId,
|
|
234
|
+
name: 'Ethereum',
|
|
235
|
+
networkName: 'Arbitrum One',
|
|
236
|
+
symbol: 'ETH',
|
|
237
|
+
precision: 18,
|
|
238
|
+
color: '#5C6BC0',
|
|
239
|
+
networkColor: '#213147',
|
|
240
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
|
|
241
|
+
networkIcon: 'https://raw.githubusercontent.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/arbitrum/info/logo.png',
|
|
242
|
+
explorer: 'https://arbiscan.io',
|
|
243
|
+
explorerAddressLink: 'https://arbiscan.io/address/',
|
|
244
|
+
explorerTxLink: 'https://arbiscan.io/tx/',
|
|
245
|
+
relatedAssetKey: 'eip155:1/slip44:60',
|
|
246
|
+
});
|
|
247
|
+
export const arbitrumNova = Object.freeze({
|
|
248
|
+
assetId: caip.arbitrumNovaAssetId,
|
|
249
|
+
chainId: caip.arbitrumNovaChainId,
|
|
250
|
+
name: 'Ethereum',
|
|
251
|
+
networkName: 'Arbitrum Nova',
|
|
252
|
+
symbol: 'ETH',
|
|
253
|
+
precision: 18,
|
|
254
|
+
color: '#5C6BC0',
|
|
255
|
+
networkColor: '#E67408',
|
|
256
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
|
|
257
|
+
networkIcon: 'https://assets.coingecko.com/asset_platforms/images/93/large/AN_logomark.png?1695026131',
|
|
258
|
+
explorer: 'https://nova.arbiscan.io',
|
|
259
|
+
explorerAddressLink: 'https://nova.arbiscan.io/address/',
|
|
260
|
+
explorerTxLink: 'https://nova.arbiscan.io/tx/',
|
|
261
|
+
relatedAssetKey: 'eip155:1/slip44:60',
|
|
262
|
+
});
|
|
263
|
+
export const base = Object.freeze({
|
|
264
|
+
assetId: caip.baseAssetId,
|
|
265
|
+
chainId: caip.baseChainId,
|
|
266
|
+
name: 'Ethereum',
|
|
267
|
+
networkName: 'Base',
|
|
268
|
+
symbol: 'ETH',
|
|
269
|
+
precision: 18,
|
|
270
|
+
color: '#5C6BC0',
|
|
271
|
+
networkColor: '#0052FF',
|
|
272
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
|
|
273
|
+
networkIcon: 'https://rawcdn.githack.com/base-org/brand-kit/8984fe6e08be3058fd7cf5cd0b201f8b92b5a70e/logo/symbol/Base_Symbol_Blue.png',
|
|
274
|
+
explorer: 'https://basescan.org',
|
|
275
|
+
explorerAddressLink: 'https://basescan.org/address/',
|
|
276
|
+
explorerTxLink: 'https://basescan.org/tx/',
|
|
277
|
+
relatedAssetKey: 'eip155:1/slip44:60',
|
|
278
|
+
});
|
|
279
|
+
export const monad = Object.freeze({
|
|
280
|
+
assetId: caip.monadAssetId,
|
|
281
|
+
chainId: caip.monadChainId,
|
|
282
|
+
name: 'Monad',
|
|
283
|
+
networkName: 'Monad',
|
|
284
|
+
symbol: 'MON',
|
|
285
|
+
precision: 18,
|
|
286
|
+
color: '#3B82F6',
|
|
287
|
+
networkColor: '#3B82F6',
|
|
288
|
+
icon: 'https://assets.coingecko.com/coins/images/38927/standard/monad.png?1764042736',
|
|
289
|
+
networkIcon: 'https://assets.coingecko.com/coins/images/38927/standard/monad.png?1764042736',
|
|
290
|
+
explorer: 'https://monadvision.com',
|
|
291
|
+
explorerAddressLink: 'https://monadvision.com/address/',
|
|
292
|
+
explorerTxLink: 'https://monadvision.com/tx/',
|
|
293
|
+
relatedAssetKey: null,
|
|
294
|
+
});
|
|
295
|
+
export const solana = Object.freeze({
|
|
296
|
+
assetId: caip.solAssetId,
|
|
297
|
+
chainId: caip.solanaChainId,
|
|
298
|
+
name: 'Solana',
|
|
299
|
+
networkName: 'Solana',
|
|
300
|
+
symbol: 'SOL',
|
|
301
|
+
precision: 9,
|
|
302
|
+
color: '#9971d8',
|
|
303
|
+
networkColor: '#9971d8',
|
|
304
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/426526def2f327476e868ecb902c515ab17518af/blockchains/solana/info/logo.png',
|
|
305
|
+
explorer: 'https://explorer.solana.com',
|
|
306
|
+
explorerAddressLink: 'https://explorer.solana.com/address/',
|
|
307
|
+
explorerTxLink: 'https://explorer.solana.com/tx/',
|
|
308
|
+
relatedAssetKey: null,
|
|
309
|
+
});
|
|
310
|
+
export const tron = Object.freeze({
|
|
311
|
+
assetId: caip.tronAssetId,
|
|
312
|
+
chainId: caip.tronChainId,
|
|
313
|
+
name: 'Tron',
|
|
314
|
+
networkName: 'Tron',
|
|
315
|
+
symbol: 'TRX',
|
|
316
|
+
precision: 6,
|
|
317
|
+
color: '#FF0013',
|
|
318
|
+
networkColor: '#FF0013',
|
|
319
|
+
icon: 'https://rawcdn.githack.com/trustwallet/assets/b7a5f12d893fcf58e0eb1dd64478f076857b720b/blockchains/tron/info/logo.png',
|
|
320
|
+
explorer: 'https://tronscan.org',
|
|
321
|
+
explorerAddressLink: 'https://tronscan.org/#/address/',
|
|
322
|
+
explorerTxLink: 'https://tronscan.org/#/transaction/',
|
|
323
|
+
relatedAssetKey: null,
|
|
324
|
+
});
|
|
325
|
+
export const sui = Object.freeze({
|
|
326
|
+
assetId: caip.suiAssetId,
|
|
327
|
+
chainId: caip.suiChainId,
|
|
328
|
+
name: 'Sui',
|
|
329
|
+
networkName: 'Sui',
|
|
330
|
+
symbol: 'SUI',
|
|
331
|
+
precision: 9,
|
|
332
|
+
color: '#6fbcf0',
|
|
333
|
+
networkColor: '#6fbcf0',
|
|
334
|
+
icon: 'https://assets.coingecko.com/coins/images/26375/large/sui_asset.jpeg?1727791290',
|
|
335
|
+
explorer: 'https://suiscan.xyz/mainnet',
|
|
336
|
+
explorerAddressLink: 'https://suiscan.xyz/mainnet/account/',
|
|
337
|
+
explorerTxLink: 'https://suiscan.xyz/mainnet/tx/',
|
|
338
|
+
relatedAssetKey: null,
|
|
339
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FIELDS: readonly ["assetIdx", "name", "precision", "color", "icon", "symbol", "relatedAssetKey", "isPool"];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { Asset } from '@shapeshiftoss/types';
|
|
3
|
+
import type { EncodedAssetData } from './types.js';
|
|
4
|
+
export declare const decodeAssetData: (encodedAssetData: EncodedAssetData, shouldAddNetworkName?: boolean) => {
|
|
5
|
+
assetData: Record<AssetId, Asset>;
|
|
6
|
+
sortedAssetIds: AssetId[];
|
|
7
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { fromAssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import { pick } from 'lodash';
|
|
3
|
+
import { assertUnreachable } from '../assertUnreachable.js';
|
|
4
|
+
import { FIELDS } from './constants.js';
|
|
5
|
+
import { getBaseAsset } from './getBaseAsset.js';
|
|
6
|
+
const decodeAssetId = (encodedAssetId, assetIdPrefixes) => {
|
|
7
|
+
// Performance sensitive. `lastIndexOf` + `substring` faster than `split`
|
|
8
|
+
const colonIndex = encodedAssetId.lastIndexOf(':');
|
|
9
|
+
const prefixIdx = Number(encodedAssetId.substring(0, colonIndex));
|
|
10
|
+
const assetReference = encodedAssetId.substring(colonIndex + 1);
|
|
11
|
+
// Performance sensitive. String concatenation faster than template literal
|
|
12
|
+
return assetIdPrefixes[prefixIdx] + ':' + assetReference;
|
|
13
|
+
};
|
|
14
|
+
export const decodeAssetData = (encodedAssetData, shouldAddNetworkName = false) => {
|
|
15
|
+
const { assetIdPrefixes, encodedAssetIds, encodedAssets } = encodedAssetData;
|
|
16
|
+
const sortedAssetIds = encodedAssetIds.map(encodedAssetId => decodeAssetId(encodedAssetId, assetIdPrefixes));
|
|
17
|
+
const assetData = encodedAssets.reduce((acc, encodedAsset, idx) => {
|
|
18
|
+
const assetId = sortedAssetIds[idx];
|
|
19
|
+
const { chainId } = fromAssetId(assetId);
|
|
20
|
+
const baseAsset = getBaseAsset(chainId);
|
|
21
|
+
// Initialize with default values for the chain
|
|
22
|
+
const asset = Object.assign({
|
|
23
|
+
assetId,
|
|
24
|
+
chainId,
|
|
25
|
+
symbol: '',
|
|
26
|
+
name: '',
|
|
27
|
+
precision: 0,
|
|
28
|
+
color: '',
|
|
29
|
+
icon: undefined,
|
|
30
|
+
explorer: '',
|
|
31
|
+
explorerAddressLink: '',
|
|
32
|
+
explorerTxLink: '',
|
|
33
|
+
relatedAssetKey: null,
|
|
34
|
+
}, pick(baseAsset, ['explorer', 'explorerAddressLink', 'explorerTxLink']));
|
|
35
|
+
if (assetId === baseAsset?.assetId) {
|
|
36
|
+
asset.networkName = baseAsset.networkName;
|
|
37
|
+
asset.networkIcon = baseAsset.networkIcon;
|
|
38
|
+
asset.networkColor = baseAsset.networkColor;
|
|
39
|
+
}
|
|
40
|
+
// Apply each field's decoded value to the asset
|
|
41
|
+
FIELDS.forEach((field, fieldIdx) => {
|
|
42
|
+
const value = encodedAsset[fieldIdx];
|
|
43
|
+
switch (field) {
|
|
44
|
+
case 'icon': {
|
|
45
|
+
const iconOrIcons = value;
|
|
46
|
+
if (iconOrIcons.length === 1) {
|
|
47
|
+
asset.icon = iconOrIcons[0];
|
|
48
|
+
}
|
|
49
|
+
else if (iconOrIcons.length > 1) {
|
|
50
|
+
asset.icons = iconOrIcons;
|
|
51
|
+
}
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'relatedAssetKey': {
|
|
55
|
+
const assetIdx = value;
|
|
56
|
+
const relatedAssetId = assetIdx === null ? null : sortedAssetIds[assetIdx];
|
|
57
|
+
// if (relatedAssetId === undefined) throw Error()
|
|
58
|
+
if (relatedAssetId &&
|
|
59
|
+
relatedAssetId !== asset.assetId &&
|
|
60
|
+
baseAsset.networkName &&
|
|
61
|
+
shouldAddNetworkName) {
|
|
62
|
+
asset.name = `${asset.name} on ${baseAsset.networkName}`;
|
|
63
|
+
}
|
|
64
|
+
asset.relatedAssetKey = relatedAssetId;
|
|
65
|
+
asset.isPrimary = relatedAssetId === null || relatedAssetId === asset.assetId;
|
|
66
|
+
asset.isChainSpecific = relatedAssetId === null;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'name':
|
|
70
|
+
asset.name = value;
|
|
71
|
+
break;
|
|
72
|
+
case 'precision':
|
|
73
|
+
asset.precision = value;
|
|
74
|
+
break;
|
|
75
|
+
case 'color':
|
|
76
|
+
asset.color = value;
|
|
77
|
+
break;
|
|
78
|
+
case 'symbol':
|
|
79
|
+
asset.symbol = value;
|
|
80
|
+
break;
|
|
81
|
+
case 'isPool': {
|
|
82
|
+
const isPool = value;
|
|
83
|
+
if (isPool) {
|
|
84
|
+
asset.isPool = true;
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'assetIdx':
|
|
89
|
+
// Skip assetIdx as we already have assetId
|
|
90
|
+
break;
|
|
91
|
+
default:
|
|
92
|
+
assertUnreachable(field);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
acc[assetId] = asset;
|
|
96
|
+
return acc;
|
|
97
|
+
}, {});
|
|
98
|
+
return {
|
|
99
|
+
assetData,
|
|
100
|
+
sortedAssetIds,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const decodeRelatedAssetIndex = (encodedRelatedAssetIndex, sortedAssetIds) => {
|
|
2
|
+
const result = {};
|
|
3
|
+
for (let assetIdx = 0; assetIdx < sortedAssetIds.length; assetIdx++) {
|
|
4
|
+
const assetId = sortedAssetIds[assetIdx];
|
|
5
|
+
if (!encodedRelatedAssetIndex[assetIdx])
|
|
6
|
+
continue;
|
|
7
|
+
result[assetId] = encodedRelatedAssetIndex[assetIdx].map(innerAssetIdx => sortedAssetIds[innerAssetIdx]);
|
|
8
|
+
}
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AssetId } from '@shapeshiftoss/caip';
|
|
2
|
+
import type { AssetsById } from '@shapeshiftoss/types';
|
|
3
|
+
import type { EncodedAssetData } from './types.js';
|
|
4
|
+
export declare const encodeAssetData: (sortedAssetIds: AssetId[], assetsById: AssetsById) => EncodedAssetData;
|