@defisaver/tokens 1.4.1 → 1.4.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/README.md CHANGED
@@ -4,7 +4,10 @@
4
4
 
5
5
  ### Type aliases
6
6
 
7
+ - [AaveMarketData](README.md#aavemarketdata)
8
+ - [AddressMapping](README.md#addressmapping)
7
9
  - [AssetData](README.md#assetdata)
10
+ - [AssetDataBase](README.md#assetdatabase)
8
11
  - [ExtendedIlkData](README.md#extendedilkdata)
9
12
  - [IlkData](README.md#ilkdata)
10
13
 
@@ -33,11 +36,44 @@
33
36
 
34
37
  ## Type aliases
35
38
 
39
+ ### AaveMarketData
40
+
41
+ Ƭ **AaveMarketData**: `Object`
42
+
43
+ #### Type declaration
44
+
45
+ | Name | Type |
46
+ | :------ | :------ |
47
+ | `dataProvider` | `string` |
48
+ | `lendingPool` | `string` |
49
+ | `lendingPoolAddressProvider` | `string` |
50
+ | `name` | `string` |
51
+
52
+ #### Defined in
53
+
54
+ [types.ts:61](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L61)
55
+
56
+ ___
57
+
58
+ ### AddressMapping
59
+
60
+ Ƭ **AddressMapping**: `Object`
61
+
62
+ #### Index signature
63
+
64
+ ▪ [key: `number`]: `string`
65
+
66
+ #### Defined in
67
+
68
+ [types.ts:6](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L6)
69
+
70
+ ___
71
+
36
72
  ### AssetData
37
73
 
38
74
  Ƭ **AssetData**: `Object`
39
75
 
40
- Asset info type
76
+ Chain-specific asset info type
41
77
 
42
78
  #### Type declaration
43
79
 
@@ -45,7 +81,35 @@ Asset info type
45
81
  | :------ | :------ |
46
82
  | `aaveCollateral` | `boolean` |
47
83
  | `address` | `string` |
48
- | `addresses` | `AddressMapping` |
84
+ | `addresses` | [`AddressMapping`](README.md#addressmapping) |
85
+ | `compoundCollateral` | `boolean` |
86
+ | `decimals` | `number` |
87
+ | `exchange` | `boolean` |
88
+ | `icon` | `Function` |
89
+ | `isStable` | `boolean` |
90
+ | `name` | `string` |
91
+ | `symbol` | `string` |
92
+ | `underlyingAsset` | `string` |
93
+ | `yearnCollateral` | `boolean` |
94
+
95
+ #### Defined in
96
+
97
+ [types.ts:30](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L30)
98
+
99
+ ___
100
+
101
+ ### AssetDataBase
102
+
103
+ Ƭ **AssetDataBase**: `Object`
104
+
105
+ Chain-agnostic asset info type
106
+
107
+ #### Type declaration
108
+
109
+ | Name | Type |
110
+ | :------ | :------ |
111
+ | `aaveCollateral` | `boolean` |
112
+ | `addresses` | [`AddressMapping`](README.md#addressmapping) |
49
113
  | `compoundCollateral` | `boolean` |
50
114
  | `decimals` | `number` |
51
115
  | `exchange` | `boolean` |
@@ -58,7 +122,7 @@ Asset info type
58
122
 
59
123
  #### Defined in
60
124
 
61
- [types.ts:13](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/types.ts#L13)
125
+ [types.ts:13](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L13)
62
126
 
63
127
  ___
64
128
 
@@ -68,7 +132,7 @@ ___
68
132
 
69
133
  #### Defined in
70
134
 
71
- [types.ts:51](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/types.ts#L51)
135
+ [types.ts:68](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L68)
72
136
 
73
137
  ___
74
138
 
@@ -95,7 +159,7 @@ Maker ilk info type
95
159
 
96
160
  #### Defined in
97
161
 
98
- [types.ts:31](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/types.ts#L31)
162
+ [types.ts:48](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/types.ts#L48)
99
163
 
100
164
  ## Variables
101
165
 
@@ -105,27 +169,27 @@ Maker ilk info type
105
169
 
106
170
  #### Defined in
107
171
 
108
- [index.ts:27](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L27)
172
+ [index.ts:27](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L27)
109
173
 
110
174
  ___
111
175
 
112
176
  ### aaveV2Markets
113
177
 
114
- • **aaveV2Markets**: `AaveMarketData`[]
178
+ • **aaveV2Markets**: [`AaveMarketData`](README.md#aavemarketdata)[]
115
179
 
116
180
  #### Defined in
117
181
 
118
- [aaveV2Markets.ts:3](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/aaveV2Markets.ts#L3)
182
+ [aaveV2Markets.ts:3](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/aaveV2Markets.ts#L3)
119
183
 
120
184
  ___
121
185
 
122
186
  ### assets
123
187
 
124
- • **assets**: [`AssetData`](README.md#assetdata)[]
188
+ • **assets**: [`AssetDataBase`](README.md#assetdatabase)[]
125
189
 
126
190
  #### Defined in
127
191
 
128
- [assets.ts:230](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/assets.ts#L230)
192
+ [assets.ts:229](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/assets.ts#L229)
129
193
 
130
194
  ___
131
195
 
@@ -135,7 +199,7 @@ ___
135
199
 
136
200
  #### Defined in
137
201
 
138
- [ilks.ts:5](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/ilks.ts#L5)
202
+ [ilks.ts:5](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/ilks.ts#L5)
139
203
 
140
204
  ___
141
205
 
@@ -145,7 +209,7 @@ ___
145
209
 
146
210
  #### Defined in
147
211
 
148
- [reflexerCollTypes.ts:3](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/reflexerCollTypes.ts#L3)
212
+ [reflexerCollTypes.ts:3](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/reflexerCollTypes.ts#L3)
149
213
 
150
214
  ___
151
215
 
@@ -163,7 +227,7 @@ ___
163
227
 
164
228
  #### Defined in
165
229
 
166
- [index.ts:25](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L25)
230
+ [index.ts:25](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L25)
167
231
 
168
232
  ## Functions
169
233
 
@@ -184,7 +248,7 @@ ___
184
248
 
185
249
  #### Defined in
186
250
 
187
- [index.ts:142](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L142)
251
+ [index.ts:144](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L144)
188
252
 
189
253
  ___
190
254
 
@@ -205,13 +269,13 @@ ___
205
269
 
206
270
  #### Defined in
207
271
 
208
- [index.ts:163](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L163)
272
+ [index.ts:165](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L165)
209
273
 
210
274
  ___
211
275
 
212
276
  ### getAaveV2MarketInfo
213
277
 
214
- ▸ `Const` **getAaveV2MarketInfo**(`name?`): `void` \| `AaveMarketData`
278
+ ▸ `Const` **getAaveV2MarketInfo**(`name?`): `void` \| [`AaveMarketData`](README.md#aavemarketdata)
215
279
 
216
280
  #### Parameters
217
281
 
@@ -221,11 +285,11 @@ ___
221
285
 
222
286
  #### Returns
223
287
 
224
- `void` \| `AaveMarketData`
288
+ `void` \| [`AaveMarketData`](README.md#aavemarketdata)
225
289
 
226
290
  #### Defined in
227
291
 
228
- [index.ts:135](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L135)
292
+ [index.ts:137](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L137)
229
293
 
230
294
  ___
231
295
 
@@ -248,7 +312,7 @@ Warning: will not throw if asset not found. Instead, will return a placeholder o
248
312
 
249
313
  #### Defined in
250
314
 
251
- [index.ts:49](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L49)
315
+ [index.ts:58](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L58)
252
316
 
253
317
  ___
254
318
 
@@ -268,7 +332,7 @@ ___
268
332
 
269
333
  #### Defined in
270
334
 
271
- [index.ts:85](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L85)
335
+ [index.ts:92](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L92)
272
336
 
273
337
  ___
274
338
 
@@ -291,7 +355,7 @@ Warning: will not throw if ilk not found. Instead, will return a placeholder obj
291
355
 
292
356
  #### Defined in
293
357
 
294
- [index.ts:64](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L64)
358
+ [index.ts:71](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L71)
295
359
 
296
360
  ___
297
361
 
@@ -311,7 +375,7 @@ ___
311
375
 
312
376
  #### Defined in
313
377
 
314
- [index.ts:87](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L87)
378
+ [index.ts:97](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L97)
315
379
 
316
380
  ___
317
381
 
@@ -332,7 +396,7 @@ ___
332
396
 
333
397
  #### Defined in
334
398
 
335
- [index.ts:21](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L21)
399
+ [index.ts:21](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L21)
336
400
 
337
401
  ___
338
402
 
@@ -355,7 +419,7 @@ Token symbol
355
419
 
356
420
  #### Defined in
357
421
 
358
- [index.ts:115](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L115)
422
+ [index.ts:117](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L117)
359
423
 
360
424
  ___
361
425
 
@@ -377,7 +441,7 @@ Token symbol
377
441
 
378
442
  #### Defined in
379
443
 
380
- [index.ts:127](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L127)
444
+ [index.ts:129](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L129)
381
445
 
382
446
  ___
383
447
 
@@ -399,4 +463,4 @@ Token symbol
399
463
 
400
464
  #### Defined in
401
465
 
402
- [index.ts:133](https://github.com/DecenterApps/defisaver-tokens/blob/5d144eb/src/index.ts#L133)
466
+ [index.ts:135](https://github.com/DecenterApps/defisaver-tokens/blob/de5eef3/src/index.ts#L135)
package/esm/assets.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { AssetData } from './types';
2
- export declare const assetProto: AssetData;
3
- export declare const assets: AssetData[];
1
+ import { AssetDataBase } from './types';
2
+ export declare const assetProto: AssetDataBase;
3
+ export declare const assets: AssetDataBase[];
package/esm/assets.js CHANGED
@@ -209,7 +209,6 @@ const GuniDaiUsdc2Address = "0x50379f632ca68D36E50cfBC8F78fe16bd1499d1e";
209
209
  export const assetProto = {
210
210
  symbol: '?',
211
211
  name: 'Unknown',
212
- address: '0x0000000000000000000000000000000000000000',
213
212
  addresses: {},
214
213
  decimals: 18,
215
214
  icon: () => {
package/esm/index.d.ts CHANGED
@@ -6,8 +6,8 @@ import { reflexerCollTypes } from './reflexerCollTypes';
6
6
  export { reflexerCollTypes };
7
7
  import { aaveV2Markets } from './aaveV2Markets';
8
8
  export { aaveV2Markets };
9
- import type { AaveMarketData, AssetData, ExtendedIlkData, IlkData } from './types';
10
- export type { AssetData, ExtendedIlkData, IlkData };
9
+ import type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping } from './types';
10
+ export type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping };
11
11
  import { stringToBytes, bytesToString, compare } from './utils';
12
12
  export declare const set: (key: string, value: any) => void;
13
13
  export declare const utils: {
@@ -35,14 +35,6 @@ export declare const getIlkInfo: (ilk?: string) => ExtendedIlkData;
35
35
  export declare const getAssetInfoByAddress: (address?: string) => AssetData;
36
36
  export declare const ilkToAsset: (ilk?: string) => string;
37
37
  /** @private **/
38
- export declare const compoundCollateralAssets: AssetData[];
39
- /** @private **/
40
- export declare const aaveCollateralAssets: AssetData[];
41
- /** @private **/
42
- export declare const yearnCollateralAssets: AssetData[];
43
- /** @private **/
44
- export declare const exchangeAssets: AssetData[];
45
- /** @private **/
46
38
  export declare const compoundAsset: (underlyingAsset: string) => string;
47
39
  /** @private **/
48
40
  export declare const aaveAsset: (underlyingAsset: string) => string;
package/esm/index.js CHANGED
@@ -28,6 +28,12 @@ Dec.set({
28
28
  * @return symbol {string}
29
29
  */
30
30
  const handleWBTCLegacy = (symbol = '') => (symbol === 'WBTC Legacy' ? 'WBTC' : symbol);
31
+ const _addChainSpecificData = (assetDataBase) => {
32
+ const assetData = Object.assign(Object.assign({}, assetDataBase), { address: assetDataBase.addresses[config.network] || '0x0000000000000000000000000000000000000000' });
33
+ if (config.iconFunc)
34
+ assetData.icon = config.iconFunc(Object.assign({}, assetData));
35
+ return assetData;
36
+ };
31
37
  /**
32
38
  * Returns asset info.
33
39
  * Warning: will not throw if asset not found. Instead, will return a placeholder object.
@@ -39,10 +45,7 @@ export const getAssetInfo = (symbol = '') => {
39
45
  let assetData = assets.find(t => compare(t.symbol, handleWBTCLegacy(symbol)));
40
46
  if (!assetData)
41
47
  assetData = Object.assign({}, assetProto);
42
- if (config.iconFunc)
43
- assetData.icon = config.iconFunc(Object.assign(Object.assign({}, assetData), { symbol }));
44
- assetData.address = assetData.addresses[config.network] || '0x0000000000000000000000000000000000000000';
45
- return assetData;
48
+ return _addChainSpecificData(assetData);
46
49
  };
47
50
  /**
48
51
  * Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
@@ -68,7 +71,10 @@ export const getIlkInfo = (ilk = '') => {
68
71
  const assetData = getAssetInfo(ilkData.asset);
69
72
  return Object.assign(Object.assign({}, ilkData), { assetData });
70
73
  };
71
- export const getAssetInfoByAddress = (address = '') => assets.find(t => t.address.toLowerCase() === address.toLowerCase()) || Object.assign({}, assetProto);
74
+ export const getAssetInfoByAddress = (address = '') => {
75
+ const assetDataBase = assets.find(t => t.addresses[config.network].toLowerCase() === address.toLowerCase());
76
+ return _addChainSpecificData(assetDataBase || Object.assign({}, assetProto));
77
+ };
72
78
  export const ilkToAsset = (ilk = '') => {
73
79
  var _a;
74
80
  let ilkLabel = ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk;
@@ -84,14 +90,6 @@ export const ilkToAsset = (ilk = '') => {
84
90
  return asset;
85
91
  };
86
92
  /** @private **/
87
- export const compoundCollateralAssets = assets.filter(t => t.compoundCollateral);
88
- /** @private **/
89
- export const aaveCollateralAssets = assets.filter(t => t.aaveCollateral);
90
- /** @private **/
91
- export const yearnCollateralAssets = assets.filter(t => t.yearnCollateral);
92
- /** @private **/
93
- export const exchangeAssets = assets.filter(t => t.exchange);
94
- /** @private **/
95
93
  export const compoundAsset = (underlyingAsset) => `c${underlyingAsset.toUpperCase()}`;
96
94
  /** @private **/
97
95
  export const aaveAsset = (underlyingAsset) => `a${underlyingAsset.toUpperCase()}`;
@@ -137,7 +135,7 @@ export const assetAmountInEth = (amount, asset = 'ETH') => {
137
135
  decimals = 18;
138
136
  else
139
137
  decimals = getAssetInfo(asset).decimals;
140
- return new Dec(amount && amount.toString() || 0).div(Math.pow(10, decimals)).toString();
138
+ return new Dec(amount && amount.toString() || 0).div(Math.pow(10, decimals)).toDP(decimals).toString();
141
139
  };
142
140
  /**
143
141
  * @param amount {Number|String|Object} Amount in eth
package/esm/types.d.ts CHANGED
@@ -6,7 +6,23 @@ declare type AddressMapping = {
6
6
  [key: number]: string;
7
7
  };
8
8
  /**
9
- * Asset info type
9
+ * Chain-agnostic asset info type
10
+ */
11
+ declare type AssetDataBase = {
12
+ symbol: string;
13
+ name: string;
14
+ addresses: AddressMapping;
15
+ decimals: number;
16
+ icon: Function;
17
+ underlyingAsset: string;
18
+ exchange: boolean;
19
+ compoundCollateral: boolean;
20
+ aaveCollateral: boolean;
21
+ yearnCollateral: boolean;
22
+ isStable: boolean;
23
+ };
24
+ /**
25
+ * Chain-specific asset info type
10
26
  */
11
27
  declare type AssetData = {
12
28
  symbol: string;
@@ -46,4 +62,4 @@ declare type AaveMarketData = {
46
62
  declare type ExtendedIlkData = IlkData | {
47
63
  assetData: AssetData;
48
64
  };
49
- export { AssetData, IlkData, ExtendedIlkData, AaveMarketData, Config, };
65
+ export { AddressMapping, AssetDataBase, AssetData, IlkData, ExtendedIlkData, AaveMarketData, Config, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/tokens",
3
- "version": "1.4.1",
3
+ "version": "1.4.4",
4
4
  "description": "Centralized asset data & utility functions",
5
5
  "main": "umd/index.js",
6
6
  "module": "esm/index.js",
package/src/assets.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AssetData } from './types';
1
+ import { AssetDataBase } from './types';
2
2
 
3
3
  const ETHAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
4
4
  const DAIAddress = "0x6b175474e89094c44da98b954eedeac495271d0f";
@@ -209,10 +209,9 @@ const cUSDPAddress = "0x041171993284df560249B57358F931D9eB7b925D";
209
209
  const GuniDaiUsdc1Address = "0xAbDDAfB225e10B90D798bB8A886238Fb835e2053";
210
210
  const GuniDaiUsdc2Address = "0x50379f632ca68D36E50cfBC8F78fe16bd1499d1e";
211
211
 
212
- export const assetProto: AssetData = {
212
+ export const assetProto: AssetDataBase = {
213
213
  symbol: '?',
214
214
  name: 'Unknown',
215
- address: '0x0000000000000000000000000000000000000000',
216
215
  addresses: {},
217
216
  decimals: 18,
218
217
  icon: () => {
@@ -227,7 +226,7 @@ export const assetProto: AssetData = {
227
226
  isStable: false,
228
227
  };
229
228
 
230
- export const assets: AssetData[] = [
229
+ export const assets: AssetDataBase[] = [
231
230
  {
232
231
  ...assetProto,
233
232
  symbol: 'ETH',
package/src/index.ts CHANGED
@@ -8,8 +8,8 @@ export {reflexerCollTypes}
8
8
  import {aaveV2Markets} from './aaveV2Markets';
9
9
  export {aaveV2Markets}
10
10
 
11
- import type {AaveMarketData, AssetData, ExtendedIlkData, IlkData, Config} from './types';
12
- export type {AssetData, ExtendedIlkData, IlkData};
11
+ import type {AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping, Config} from './types';
12
+ export type {AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping};
13
13
 
14
14
  import {stringToBytes, bytesToString, compare} from './utils';
15
15
 
@@ -39,6 +39,15 @@ Dec.set({
39
39
  */
40
40
  const handleWBTCLegacy = (symbol:string = ''):string => (symbol === 'WBTC Legacy' ? 'WBTC' : symbol);
41
41
 
42
+ const _addChainSpecificData = (assetDataBase:AssetDataBase):AssetData => {
43
+ const assetData = {
44
+ ...assetDataBase,
45
+ address: assetDataBase.addresses[config.network] || '0x0000000000000000000000000000000000000000'
46
+ };
47
+ if (config.iconFunc) assetData.icon = config.iconFunc({ ...assetData });
48
+ return assetData;
49
+ }
50
+
42
51
  /**
43
52
  * Returns asset info.
44
53
  * Warning: will not throw if asset not found. Instead, will return a placeholder object.
@@ -49,9 +58,7 @@ const handleWBTCLegacy = (symbol:string = ''):string => (symbol === 'WBTC Legacy
49
58
  export const getAssetInfo = (symbol:string = ''):AssetData => {
50
59
  let assetData = assets.find(t => compare(t.symbol, handleWBTCLegacy(symbol)));
51
60
  if (!assetData) assetData = { ...assetProto };
52
- if (config.iconFunc) assetData.icon = config.iconFunc({ ...assetData, symbol });
53
- assetData.address = assetData.addresses[config.network] || '0x0000000000000000000000000000000000000000';
54
- return assetData;
61
+ return _addChainSpecificData(assetData);
55
62
  }
56
63
 
57
64
  /**
@@ -82,7 +89,10 @@ export const getIlkInfo = (ilk:string = ''):ExtendedIlkData => {
82
89
  }
83
90
  };
84
91
 
85
- export const getAssetInfoByAddress = (address: string = ''):AssetData => assets.find(t => t.address.toLowerCase() === address.toLowerCase()) || {...assetProto};
92
+ export const getAssetInfoByAddress = (address: string = ''):AssetData => {
93
+ const assetDataBase = assets.find(t => t.addresses[config.network].toLowerCase() === address.toLowerCase());
94
+ return _addChainSpecificData(assetDataBase || {...assetProto});
95
+ }
86
96
 
87
97
  export const ilkToAsset = (ilk: string = ''):string => {
88
98
  let ilkLabel = ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk;
@@ -94,14 +104,6 @@ export const ilkToAsset = (ilk: string = ''):string => {
94
104
  return asset;
95
105
  }
96
106
 
97
- /** @private **/
98
- export const compoundCollateralAssets:AssetData[] = assets.filter(t => t.compoundCollateral);
99
- /** @private **/
100
- export const aaveCollateralAssets:AssetData[] = assets.filter(t => t.aaveCollateral);
101
- /** @private **/
102
- export const yearnCollateralAssets:AssetData[] = assets.filter(t => t.yearnCollateral);
103
- /** @private **/
104
- export const exchangeAssets:AssetData[] = assets.filter(t => t.exchange);
105
107
  /** @private **/
106
108
  export const compoundAsset = (underlyingAsset: string):string => `c${underlyingAsset.toUpperCase()}`;
107
109
  /** @private **/
@@ -152,7 +154,7 @@ export const assetAmountInEth = (amount: number | string | object, asset: string
152
154
 
153
155
  else decimals = getAssetInfo(asset).decimals;
154
156
 
155
- return new Dec(amount && amount.toString() || 0).div(10 ** decimals).toString();
157
+ return new Dec(amount && amount.toString() || 0).div(10 ** decimals).toDP(decimals).toString();
156
158
  };
157
159
 
158
160
  /**
package/src/types.ts CHANGED
@@ -8,7 +8,24 @@ type AddressMapping = {
8
8
  }
9
9
 
10
10
  /**
11
- * Asset info type
11
+ * Chain-agnostic asset info type
12
+ */
13
+ type AssetDataBase = {
14
+ symbol: string;
15
+ name: string;
16
+ addresses: AddressMapping,
17
+ decimals: number;
18
+ icon: Function;
19
+ underlyingAsset: string;
20
+ exchange: boolean;
21
+ compoundCollateral: boolean;
22
+ aaveCollateral: boolean;
23
+ yearnCollateral: boolean;
24
+ isStable: boolean;
25
+ };
26
+
27
+ /**
28
+ * Chain-specific asset info type
12
29
  */
13
30
  type AssetData = {
14
31
  symbol: string;
@@ -51,6 +68,8 @@ type AaveMarketData = {
51
68
  type ExtendedIlkData = IlkData | { assetData: AssetData }
52
69
 
53
70
  export {
71
+ AddressMapping,
72
+ AssetDataBase,
54
73
  AssetData,
55
74
  IlkData,
56
75
  ExtendedIlkData,
package/umd/index.js CHANGED
@@ -27,10 +27,6 @@ __webpack_require__.r(__webpack_exports__);
27
27
  /* harmony export */ "getIlkInfo": () => /* binding */ getIlkInfo,
28
28
  /* harmony export */ "getAssetInfoByAddress": () => /* binding */ getAssetInfoByAddress,
29
29
  /* harmony export */ "ilkToAsset": () => /* binding */ ilkToAsset,
30
- /* harmony export */ "compoundCollateralAssets": () => /* binding */ compoundCollateralAssets,
31
- /* harmony export */ "aaveCollateralAssets": () => /* binding */ aaveCollateralAssets,
32
- /* harmony export */ "yearnCollateralAssets": () => /* binding */ yearnCollateralAssets,
33
- /* harmony export */ "exchangeAssets": () => /* binding */ exchangeAssets,
34
30
  /* harmony export */ "compoundAsset": () => /* binding */ compoundAsset,
35
31
  /* harmony export */ "aaveAsset": () => /* binding */ aaveAsset,
36
32
  /* harmony export */ "tokenFromJoin": () => /* binding */ tokenFromJoin,
@@ -91,6 +87,15 @@ var handleWBTCLegacy = function handleWBTCLegacy() {
91
87
  var symbol = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
92
88
  return symbol === 'WBTC Legacy' ? 'WBTC' : symbol;
93
89
  };
90
+
91
+ var _addChainSpecificData = assetDataBase => {
92
+ var assetData = _objectSpread(_objectSpread({}, assetDataBase), {}, {
93
+ address: assetDataBase.addresses[config.network] || '0x0000000000000000000000000000000000000000'
94
+ });
95
+
96
+ if (config.iconFunc) assetData.icon = config.iconFunc(_objectSpread({}, assetData));
97
+ return assetData;
98
+ };
94
99
  /**
95
100
  * Returns asset info.
96
101
  * Warning: will not throw if asset not found. Instead, will return a placeholder object.
@@ -104,11 +109,7 @@ var getAssetInfo = function getAssetInfo() {
104
109
  var symbol = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
105
110
  var assetData = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.find(t => (0,_utils__WEBPACK_IMPORTED_MODULE_5__.compare)(t.symbol, handleWBTCLegacy(symbol)));
106
111
  if (!assetData) assetData = _objectSpread({}, _assets__WEBPACK_IMPORTED_MODULE_1__.assetProto);
107
- if (config.iconFunc) assetData.icon = config.iconFunc(_objectSpread(_objectSpread({}, assetData), {}, {
108
- symbol
109
- }));
110
- assetData.address = assetData.addresses[config.network] || '0x0000000000000000000000000000000000000000';
111
- return assetData;
112
+ return _addChainSpecificData(assetData);
112
113
  };
113
114
  /**
114
115
  * Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
@@ -144,7 +145,8 @@ var getIlkInfo = function getIlkInfo() {
144
145
  };
145
146
  var getAssetInfoByAddress = function getAssetInfoByAddress() {
146
147
  var address = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
147
- return _assets__WEBPACK_IMPORTED_MODULE_1__.assets.find(t => t.address.toLowerCase() === address.toLowerCase()) || _objectSpread({}, _assets__WEBPACK_IMPORTED_MODULE_1__.assetProto);
148
+ var assetDataBase = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.find(t => t.addresses[config.network].toLowerCase() === address.toLowerCase());
149
+ return _addChainSpecificData(assetDataBase || _objectSpread({}, _assets__WEBPACK_IMPORTED_MODULE_1__.assetProto));
148
150
  };
149
151
  var ilkToAsset = function ilkToAsset() {
150
152
  var _ilkLabel$match;
@@ -160,18 +162,6 @@ var ilkToAsset = function ilkToAsset() {
160
162
  };
161
163
  /** @private **/
162
164
 
163
- var compoundCollateralAssets = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.filter(t => t.compoundCollateral);
164
- /** @private **/
165
-
166
- var aaveCollateralAssets = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.filter(t => t.aaveCollateral);
167
- /** @private **/
168
-
169
- var yearnCollateralAssets = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.filter(t => t.yearnCollateral);
170
- /** @private **/
171
-
172
- var exchangeAssets = _assets__WEBPACK_IMPORTED_MODULE_1__.assets.filter(t => t.exchange);
173
- /** @private **/
174
-
175
165
  var compoundAsset = underlyingAsset => "c".concat(underlyingAsset.toUpperCase());
176
166
  /** @private **/
177
167
 
@@ -222,7 +212,7 @@ var assetAmountInEth = function assetAmountInEth(amount) {
222
212
 
223
213
  if (asset.substr(0, 4) === 'MCD-') decimals = 18; // Compound returns borrowing power in USD with 18 decimals
224
214
  else if (asset === 'USD') decimals = 18;else decimals = getAssetInfo(asset).decimals;
225
- return new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(amount && amount.toString() || 0).div(10 ** decimals).toString();
215
+ return new (decimal_js__WEBPACK_IMPORTED_MODULE_0___default())(amount && amount.toString() || 0).div(10 ** decimals).toDP(decimals).toString();
226
216
  };
227
217
  /**
228
218
  * @param amount {Number|String|Object} Amount in eth
@@ -470,7 +460,6 @@ var GuniDaiUsdc2Address = "0x50379f632ca68D36E50cfBC8F78fe16bd1499d1e";
470
460
  var assetProto = {
471
461
  symbol: '?',
472
462
  name: 'Unknown',
473
- address: '0x0000000000000000000000000000000000000000',
474
463
  addresses: {},
475
464
  decimals: 18,
476
465
  icon: () => {