@defisaver/tokens 1.5.43 → 1.5.45-dev
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/.editorconfig +9 -9
- package/.env.example +4 -4
- package/README.md +23 -23
- package/esm/aaveV2Markets.d.ts +2 -2
- package/esm/aaveV2Markets.js +8 -8
- package/esm/assets.d.ts +3 -3
- package/esm/assets.js +1095 -1091
- package/esm/ilks.d.ts +3 -3
- package/esm/ilks.js +465 -465
- package/esm/index.d.ts +70 -70
- package/esm/index.js +157 -157
- package/esm/reflexerCollTypes.d.ts +2 -2
- package/esm/reflexerCollTypes.js +11 -11
- package/esm/types.d.ts +73 -73
- package/esm/types.js +1 -1
- package/esm/utils.d.ts +11 -11
- package/esm/utils.js +22 -22
- package/package.json +47 -47
- package/src/TokenIcons/GuniDaiUsdc1Icon.js +66 -66
- package/src/TokenIcons/GuniDaiUsdc2Icon.js +69 -69
- package/src/aaveV2Markets.ts +10 -10
- package/src/assets.ts +3062 -3049
- package/src/ilks.ts +468 -468
- package/src/index.ts +176 -176
- package/src/reflexerCollTypes.ts +13 -13
- package/src/types.ts +87 -87
- package/src/utils.ts +22 -22
- package/tsconfig.json +74 -74
- package/umd/index.js +56 -44
- package/webpack.umd.js +43 -43
- package/.env +0 -8
package/esm/index.d.ts
CHANGED
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import { assets } from './assets';
|
|
2
|
-
export { assets };
|
|
3
|
-
import { ilks } from './ilks';
|
|
4
|
-
export { ilks };
|
|
5
|
-
import { reflexerCollTypes } from './reflexerCollTypes';
|
|
6
|
-
export { reflexerCollTypes };
|
|
7
|
-
import { aaveV2Markets } from './aaveV2Markets';
|
|
8
|
-
export { aaveV2Markets };
|
|
9
|
-
import type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping } from './types';
|
|
10
|
-
export type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping };
|
|
11
|
-
import { stringToBytes, bytesToString, compare } from './utils';
|
|
12
|
-
export declare const set: (key: string, value: any) => void;
|
|
13
|
-
export declare const utils: {
|
|
14
|
-
stringToBytes: typeof stringToBytes;
|
|
15
|
-
bytesToString: typeof bytesToString;
|
|
16
|
-
compare: typeof compare;
|
|
17
|
-
};
|
|
18
|
-
export declare const MAXUINT: string;
|
|
19
|
-
/**
|
|
20
|
-
* Returns asset info.
|
|
21
|
-
* Warning: will not throw if asset not found. Instead, will return a placeholder object.
|
|
22
|
-
*
|
|
23
|
-
* @param symbol {string}
|
|
24
|
-
* @param chainId {number}
|
|
25
|
-
* @return {AssetData}
|
|
26
|
-
*/
|
|
27
|
-
export declare const getAssetInfo: (symbol?: string, chainId?: number | undefined) => AssetData;
|
|
28
|
-
/**
|
|
29
|
-
* Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
|
|
30
|
-
* Warning: will not throw if ilk not found. Instead, will return a placeholder object.
|
|
31
|
-
*
|
|
32
|
-
* @param ilk {string} Ilk encoded as string or as hex
|
|
33
|
-
* @returns {ExtendedIlkData}
|
|
34
|
-
*/
|
|
35
|
-
export declare const getIlkInfo: (ilk?: string) => ExtendedIlkData;
|
|
36
|
-
export declare const getAssetInfoByAddress: (address?: string, chainId?: number | undefined) => AssetData;
|
|
37
|
-
export declare const ilkToAsset: (ilk?: string) => string;
|
|
38
|
-
/** @private **/
|
|
39
|
-
export declare const compoundAsset: (underlyingAsset: string) => string;
|
|
40
|
-
/** @private **/
|
|
41
|
-
export declare const aaveAsset: (underlyingAsset: string) => string;
|
|
42
|
-
/**
|
|
43
|
-
* @param join {string} Maker or Reflexer ilk join
|
|
44
|
-
* @param fromIlks {IlkData[]}
|
|
45
|
-
* @returns {string} Token symbol
|
|
46
|
-
*/
|
|
47
|
-
export declare const tokenFromJoin: (join: string, fromIlks?: IlkData[]) => string;
|
|
48
|
-
/**
|
|
49
|
-
* @param join {string} Maker ilk join
|
|
50
|
-
* @returns {string} Token symbol
|
|
51
|
-
*/
|
|
52
|
-
export declare const tokenFromMakerJoin: (join: string) => string;
|
|
53
|
-
/**
|
|
54
|
-
* @param join {string} Reflexer ilk join
|
|
55
|
-
* @returns {string} Token symbol
|
|
56
|
-
*/
|
|
57
|
-
export declare const tokenFromReflexerJoin: (join: string) => string;
|
|
58
|
-
export declare const getAaveV2MarketInfo: (name?: string) => (AaveMarketData | void);
|
|
59
|
-
/**
|
|
60
|
-
* @param amount {Number|String|Object} Amount in wei
|
|
61
|
-
* @param asset {String} Asset symbol (or `MCD-${symbol}` for maker asset - always 18dec)
|
|
62
|
-
* @return {String}
|
|
63
|
-
*/
|
|
64
|
-
export declare const assetAmountInEth: (amount: number | string | object, asset?: string) => string;
|
|
65
|
-
/**
|
|
66
|
-
* @param amount {Number|String|Object} Amount in eth
|
|
67
|
-
* @param asset {String} Asset symbol
|
|
68
|
-
* @return {String}
|
|
69
|
-
*/
|
|
70
|
-
export declare const assetAmountInWei: (amount: number | string | object, asset: string) => string;
|
|
1
|
+
import { assets } from './assets';
|
|
2
|
+
export { assets };
|
|
3
|
+
import { ilks } from './ilks';
|
|
4
|
+
export { ilks };
|
|
5
|
+
import { reflexerCollTypes } from './reflexerCollTypes';
|
|
6
|
+
export { reflexerCollTypes };
|
|
7
|
+
import { aaveV2Markets } from './aaveV2Markets';
|
|
8
|
+
export { aaveV2Markets };
|
|
9
|
+
import type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping } from './types';
|
|
10
|
+
export type { AaveMarketData, AssetDataBase, AssetData, ExtendedIlkData, IlkData, AddressMapping };
|
|
11
|
+
import { stringToBytes, bytesToString, compare } from './utils';
|
|
12
|
+
export declare const set: (key: string, value: any) => void;
|
|
13
|
+
export declare const utils: {
|
|
14
|
+
stringToBytes: typeof stringToBytes;
|
|
15
|
+
bytesToString: typeof bytesToString;
|
|
16
|
+
compare: typeof compare;
|
|
17
|
+
};
|
|
18
|
+
export declare const MAXUINT: string;
|
|
19
|
+
/**
|
|
20
|
+
* Returns asset info.
|
|
21
|
+
* Warning: will not throw if asset not found. Instead, will return a placeholder object.
|
|
22
|
+
*
|
|
23
|
+
* @param symbol {string}
|
|
24
|
+
* @param chainId {number}
|
|
25
|
+
* @return {AssetData}
|
|
26
|
+
*/
|
|
27
|
+
export declare const getAssetInfo: (symbol?: string, chainId?: number | undefined) => AssetData;
|
|
28
|
+
/**
|
|
29
|
+
* Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
|
|
30
|
+
* Warning: will not throw if ilk not found. Instead, will return a placeholder object.
|
|
31
|
+
*
|
|
32
|
+
* @param ilk {string} Ilk encoded as string or as hex
|
|
33
|
+
* @returns {ExtendedIlkData}
|
|
34
|
+
*/
|
|
35
|
+
export declare const getIlkInfo: (ilk?: string) => ExtendedIlkData;
|
|
36
|
+
export declare const getAssetInfoByAddress: (address?: string, chainId?: number | undefined) => AssetData;
|
|
37
|
+
export declare const ilkToAsset: (ilk?: string) => string;
|
|
38
|
+
/** @private **/
|
|
39
|
+
export declare const compoundAsset: (underlyingAsset: string) => string;
|
|
40
|
+
/** @private **/
|
|
41
|
+
export declare const aaveAsset: (underlyingAsset: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* @param join {string} Maker or Reflexer ilk join
|
|
44
|
+
* @param fromIlks {IlkData[]}
|
|
45
|
+
* @returns {string} Token symbol
|
|
46
|
+
*/
|
|
47
|
+
export declare const tokenFromJoin: (join: string, fromIlks?: IlkData[]) => string;
|
|
48
|
+
/**
|
|
49
|
+
* @param join {string} Maker ilk join
|
|
50
|
+
* @returns {string} Token symbol
|
|
51
|
+
*/
|
|
52
|
+
export declare const tokenFromMakerJoin: (join: string) => string;
|
|
53
|
+
/**
|
|
54
|
+
* @param join {string} Reflexer ilk join
|
|
55
|
+
* @returns {string} Token symbol
|
|
56
|
+
*/
|
|
57
|
+
export declare const tokenFromReflexerJoin: (join: string) => string;
|
|
58
|
+
export declare const getAaveV2MarketInfo: (name?: string) => (AaveMarketData | void);
|
|
59
|
+
/**
|
|
60
|
+
* @param amount {Number|String|Object} Amount in wei
|
|
61
|
+
* @param asset {String} Asset symbol (or `MCD-${symbol}` for maker asset - always 18dec)
|
|
62
|
+
* @return {String}
|
|
63
|
+
*/
|
|
64
|
+
export declare const assetAmountInEth: (amount: number | string | object, asset?: string) => string;
|
|
65
|
+
/**
|
|
66
|
+
* @param amount {Number|String|Object} Amount in eth
|
|
67
|
+
* @param asset {String} Asset symbol
|
|
68
|
+
* @return {String}
|
|
69
|
+
*/
|
|
70
|
+
export declare const assetAmountInWei: (amount: number | string | object, asset: string) => string;
|
package/esm/index.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { assetProto, assets } from './assets';
|
|
3
|
-
export { assets };
|
|
4
|
-
import { ilks } from './ilks';
|
|
5
|
-
export { ilks };
|
|
6
|
-
import { reflexerCollTypes } from './reflexerCollTypes';
|
|
7
|
-
export { reflexerCollTypes };
|
|
8
|
-
import { aaveV2Markets } from './aaveV2Markets';
|
|
9
|
-
export { aaveV2Markets };
|
|
10
|
-
import { stringToBytes, bytesToString, compare } from './utils';
|
|
11
|
-
const config = {
|
|
12
|
-
iconFunc: undefined,
|
|
13
|
-
network: 1,
|
|
14
|
-
};
|
|
15
|
-
export const set = (key, value) => {
|
|
16
|
-
config[key] = value;
|
|
17
|
-
};
|
|
18
|
-
export const utils = { stringToBytes, bytesToString, compare };
|
|
19
|
-
export const MAXUINT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
20
|
-
Dec.set({
|
|
21
|
-
rounding: Dec.ROUND_DOWN,
|
|
22
|
-
toExpPos: 9e15,
|
|
23
|
-
toExpNeg: -9e15,
|
|
24
|
-
precision: 50,
|
|
25
|
-
});
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param symbol {string}
|
|
29
|
-
* @return symbol {string}
|
|
30
|
-
*/
|
|
31
|
-
const handleWBTCLegacy = (symbol = '') => (symbol === 'WBTC Legacy' ? 'WBTC' : symbol);
|
|
32
|
-
const _addChainSpecificData = (assetDataBase, chainId) => {
|
|
33
|
-
const assetData = Object.assign(Object.assign({}, assetDataBase), { address: assetDataBase.addresses[chainId || config.network] || '' });
|
|
34
|
-
if (config.iconFunc)
|
|
35
|
-
assetData.icon = config.iconFunc(Object.assign({}, assetData));
|
|
36
|
-
return assetData;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Returns asset info.
|
|
40
|
-
* Warning: will not throw if asset not found. Instead, will return a placeholder object.
|
|
41
|
-
*
|
|
42
|
-
* @param symbol {string}
|
|
43
|
-
* @param chainId {number}
|
|
44
|
-
* @return {AssetData}
|
|
45
|
-
*/
|
|
46
|
-
export const getAssetInfo = (symbol = '', chainId) => {
|
|
47
|
-
let assetData = assets.find(t => compare(t.symbol, handleWBTCLegacy(symbol)));
|
|
48
|
-
if (!assetData)
|
|
49
|
-
assetData = Object.assign({}, assetProto);
|
|
50
|
-
return _addChainSpecificData(assetData, chainId);
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
|
|
54
|
-
* Warning: will not throw if ilk not found. Instead, will return a placeholder object.
|
|
55
|
-
*
|
|
56
|
-
* @param ilk {string} Ilk encoded as string or as hex
|
|
57
|
-
* @returns {ExtendedIlkData}
|
|
58
|
-
*/
|
|
59
|
-
export const getIlkInfo = (ilk = '') => {
|
|
60
|
-
const _ilk = (ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk).toUpperCase();
|
|
61
|
-
const ilkData = ilks.find(i => i.ilkLabel === _ilk) || reflexerCollTypes.find(i => i.ilkLabel === _ilk);
|
|
62
|
-
if (!ilkData) {
|
|
63
|
-
console.error(`Ilk "${ilk}" not found`);
|
|
64
|
-
return {
|
|
65
|
-
ilkLabel: _ilk,
|
|
66
|
-
ilkBytes: stringToBytes(_ilk),
|
|
67
|
-
asset: ilkToAsset(ilk),
|
|
68
|
-
pip: '',
|
|
69
|
-
join: '',
|
|
70
|
-
isLP: false,
|
|
71
|
-
isCrop: false,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const assetData = getAssetInfo(ilkData.asset);
|
|
75
|
-
return Object.assign(Object.assign({}, ilkData), { assetData });
|
|
76
|
-
};
|
|
77
|
-
export const getAssetInfoByAddress = (address = '', chainId) => {
|
|
78
|
-
const assetDataBase = assets.find(t => { var _a; return ((_a = t.addresses[chainId || config.network]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase(); });
|
|
79
|
-
return _addChainSpecificData(assetDataBase || Object.assign({}, assetProto), chainId);
|
|
80
|
-
};
|
|
81
|
-
export const ilkToAsset = (ilk = '') => {
|
|
82
|
-
var _a;
|
|
83
|
-
let ilkLabel = ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk;
|
|
84
|
-
let asset = ilkLabel.replace(/-.*/, '');
|
|
85
|
-
if (ilkLabel.startsWith('PSM'))
|
|
86
|
-
asset = ((_a = ilkLabel.match(/^[A-Z]*-(.*)-[A-Z]*/)) === null || _a === void 0 ? void 0 : _a[1]) || asset;
|
|
87
|
-
if (asset === 'KNC')
|
|
88
|
-
return 'KNCL';
|
|
89
|
-
if (asset === 'PAXUSD' || asset === 'PAX')
|
|
90
|
-
return 'USDP';
|
|
91
|
-
if (asset === 'WSTETH')
|
|
92
|
-
return 'wstETH';
|
|
93
|
-
if (asset === 'CRVV1ETHSTETH')
|
|
94
|
-
return 'steCRV';
|
|
95
|
-
if (asset === 'RETH')
|
|
96
|
-
return 'rETH';
|
|
97
|
-
return asset;
|
|
98
|
-
};
|
|
99
|
-
/** @private **/
|
|
100
|
-
export const compoundAsset = (underlyingAsset) => `c${underlyingAsset.toUpperCase()}`;
|
|
101
|
-
/** @private **/
|
|
102
|
-
export const aaveAsset = (underlyingAsset) => `a${underlyingAsset.toUpperCase()}`;
|
|
103
|
-
/**
|
|
104
|
-
* @param join {string} Maker or Reflexer ilk join
|
|
105
|
-
* @param fromIlks {IlkData[]}
|
|
106
|
-
* @returns {string} Token symbol
|
|
107
|
-
*/
|
|
108
|
-
export const tokenFromJoin = (join, fromIlks = ilks) => {
|
|
109
|
-
for (const ilkInfo of fromIlks) {
|
|
110
|
-
if (compare(ilkInfo.join, join))
|
|
111
|
-
return ilkInfo.asset;
|
|
112
|
-
}
|
|
113
|
-
if (compare('0x448a5065aebb8e423f0896e6c5d525c040f59af3', join))
|
|
114
|
-
return 'ETH'; // SCD ETH
|
|
115
|
-
return '';
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* @param join {string} Maker ilk join
|
|
119
|
-
* @returns {string} Token symbol
|
|
120
|
-
*/
|
|
121
|
-
export const tokenFromMakerJoin = (join) => tokenFromJoin(join, ilks);
|
|
122
|
-
/**
|
|
123
|
-
* @param join {string} Reflexer ilk join
|
|
124
|
-
* @returns {string} Token symbol
|
|
125
|
-
*/
|
|
126
|
-
export const tokenFromReflexerJoin = (join) => tokenFromJoin(join, reflexerCollTypes);
|
|
127
|
-
export const getAaveV2MarketInfo = (name = '') => aaveV2Markets.find(i => i.name === name);
|
|
128
|
-
/**
|
|
129
|
-
* @param amount {Number|String|Object} Amount in wei
|
|
130
|
-
* @param asset {String} Asset symbol (or `MCD-${symbol}` for maker asset - always 18dec)
|
|
131
|
-
* @return {String}
|
|
132
|
-
*/
|
|
133
|
-
export const assetAmountInEth = (amount, asset = 'ETH') => {
|
|
134
|
-
if ((amount === null || amount === void 0 ? void 0 : amount.toString()) === 'Infinity')
|
|
135
|
-
return MAXUINT;
|
|
136
|
-
let decimals;
|
|
137
|
-
// USDC/WBTC have 6/8 decimals but Vat is storing it in 18 decimal precision
|
|
138
|
-
if (asset.substr(0, 4) === 'MCD-')
|
|
139
|
-
decimals = 18;
|
|
140
|
-
// Compound returns borrowing power in USD with 18 decimals
|
|
141
|
-
else if (asset === 'USD')
|
|
142
|
-
decimals = 18;
|
|
143
|
-
else
|
|
144
|
-
decimals = getAssetInfo(asset).decimals;
|
|
145
|
-
return new Dec(amount && amount.toString() || 0).div(Math.pow(10, decimals)).toDP(decimals).toString();
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* @param amount {Number|String|Object} Amount in eth
|
|
149
|
-
* @param asset {String} Asset symbol
|
|
150
|
-
* @return {String}
|
|
151
|
-
*/
|
|
152
|
-
export const assetAmountInWei = (amount, asset) => {
|
|
153
|
-
if ((amount === null || amount === void 0 ? void 0 : amount.toString()) === 'Infinity')
|
|
154
|
-
return MAXUINT;
|
|
155
|
-
const { decimals } = getAssetInfo(asset);
|
|
156
|
-
return new Dec(amount && amount.toString() || 0).mul(Math.pow(10, decimals)).floor().toString();
|
|
157
|
-
};
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { assetProto, assets } from './assets';
|
|
3
|
+
export { assets };
|
|
4
|
+
import { ilks } from './ilks';
|
|
5
|
+
export { ilks };
|
|
6
|
+
import { reflexerCollTypes } from './reflexerCollTypes';
|
|
7
|
+
export { reflexerCollTypes };
|
|
8
|
+
import { aaveV2Markets } from './aaveV2Markets';
|
|
9
|
+
export { aaveV2Markets };
|
|
10
|
+
import { stringToBytes, bytesToString, compare } from './utils';
|
|
11
|
+
const config = {
|
|
12
|
+
iconFunc: undefined,
|
|
13
|
+
network: 1,
|
|
14
|
+
};
|
|
15
|
+
export const set = (key, value) => {
|
|
16
|
+
config[key] = value;
|
|
17
|
+
};
|
|
18
|
+
export const utils = { stringToBytes, bytesToString, compare };
|
|
19
|
+
export const MAXUINT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
20
|
+
Dec.set({
|
|
21
|
+
rounding: Dec.ROUND_DOWN,
|
|
22
|
+
toExpPos: 9e15,
|
|
23
|
+
toExpNeg: -9e15,
|
|
24
|
+
precision: 50,
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param symbol {string}
|
|
29
|
+
* @return symbol {string}
|
|
30
|
+
*/
|
|
31
|
+
const handleWBTCLegacy = (symbol = '') => (symbol === 'WBTC Legacy' ? 'WBTC' : symbol);
|
|
32
|
+
const _addChainSpecificData = (assetDataBase, chainId) => {
|
|
33
|
+
const assetData = Object.assign(Object.assign({}, assetDataBase), { address: assetDataBase.addresses[chainId || config.network] || '' });
|
|
34
|
+
if (config.iconFunc)
|
|
35
|
+
assetData.icon = config.iconFunc(Object.assign({}, assetData));
|
|
36
|
+
return assetData;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Returns asset info.
|
|
40
|
+
* Warning: will not throw if asset not found. Instead, will return a placeholder object.
|
|
41
|
+
*
|
|
42
|
+
* @param symbol {string}
|
|
43
|
+
* @param chainId {number}
|
|
44
|
+
* @return {AssetData}
|
|
45
|
+
*/
|
|
46
|
+
export const getAssetInfo = (symbol = '', chainId) => {
|
|
47
|
+
let assetData = assets.find(t => compare(t.symbol, handleWBTCLegacy(symbol)));
|
|
48
|
+
if (!assetData)
|
|
49
|
+
assetData = Object.assign({}, assetProto);
|
|
50
|
+
return _addChainSpecificData(assetData, chainId);
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Returns Maker or Reflexer ilk info, and asset info as `assetData` attribute.
|
|
54
|
+
* Warning: will not throw if ilk not found. Instead, will return a placeholder object.
|
|
55
|
+
*
|
|
56
|
+
* @param ilk {string} Ilk encoded as string or as hex
|
|
57
|
+
* @returns {ExtendedIlkData}
|
|
58
|
+
*/
|
|
59
|
+
export const getIlkInfo = (ilk = '') => {
|
|
60
|
+
const _ilk = (ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk).toUpperCase();
|
|
61
|
+
const ilkData = ilks.find(i => i.ilkLabel === _ilk) || reflexerCollTypes.find(i => i.ilkLabel === _ilk);
|
|
62
|
+
if (!ilkData) {
|
|
63
|
+
console.error(`Ilk "${ilk}" not found`);
|
|
64
|
+
return {
|
|
65
|
+
ilkLabel: _ilk,
|
|
66
|
+
ilkBytes: stringToBytes(_ilk),
|
|
67
|
+
asset: ilkToAsset(ilk),
|
|
68
|
+
pip: '',
|
|
69
|
+
join: '',
|
|
70
|
+
isLP: false,
|
|
71
|
+
isCrop: false,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const assetData = getAssetInfo(ilkData.asset);
|
|
75
|
+
return Object.assign(Object.assign({}, ilkData), { assetData });
|
|
76
|
+
};
|
|
77
|
+
export const getAssetInfoByAddress = (address = '', chainId) => {
|
|
78
|
+
const assetDataBase = assets.find(t => { var _a; return ((_a = t.addresses[chainId || config.network]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === address.toLowerCase(); });
|
|
79
|
+
return _addChainSpecificData(assetDataBase || Object.assign({}, assetProto), chainId);
|
|
80
|
+
};
|
|
81
|
+
export const ilkToAsset = (ilk = '') => {
|
|
82
|
+
var _a;
|
|
83
|
+
let ilkLabel = ilk.substr(0, 2) === '0x' ? bytesToString(ilk) : ilk;
|
|
84
|
+
let asset = ilkLabel.replace(/-.*/, '');
|
|
85
|
+
if (ilkLabel.startsWith('PSM'))
|
|
86
|
+
asset = ((_a = ilkLabel.match(/^[A-Z]*-(.*)-[A-Z]*/)) === null || _a === void 0 ? void 0 : _a[1]) || asset;
|
|
87
|
+
if (asset === 'KNC')
|
|
88
|
+
return 'KNCL';
|
|
89
|
+
if (asset === 'PAXUSD' || asset === 'PAX')
|
|
90
|
+
return 'USDP';
|
|
91
|
+
if (asset === 'WSTETH')
|
|
92
|
+
return 'wstETH';
|
|
93
|
+
if (asset === 'CRVV1ETHSTETH')
|
|
94
|
+
return 'steCRV';
|
|
95
|
+
if (asset === 'RETH')
|
|
96
|
+
return 'rETH';
|
|
97
|
+
return asset;
|
|
98
|
+
};
|
|
99
|
+
/** @private **/
|
|
100
|
+
export const compoundAsset = (underlyingAsset) => `c${underlyingAsset.toUpperCase()}`;
|
|
101
|
+
/** @private **/
|
|
102
|
+
export const aaveAsset = (underlyingAsset) => `a${underlyingAsset.toUpperCase()}`;
|
|
103
|
+
/**
|
|
104
|
+
* @param join {string} Maker or Reflexer ilk join
|
|
105
|
+
* @param fromIlks {IlkData[]}
|
|
106
|
+
* @returns {string} Token symbol
|
|
107
|
+
*/
|
|
108
|
+
export const tokenFromJoin = (join, fromIlks = ilks) => {
|
|
109
|
+
for (const ilkInfo of fromIlks) {
|
|
110
|
+
if (compare(ilkInfo.join, join))
|
|
111
|
+
return ilkInfo.asset;
|
|
112
|
+
}
|
|
113
|
+
if (compare('0x448a5065aebb8e423f0896e6c5d525c040f59af3', join))
|
|
114
|
+
return 'ETH'; // SCD ETH
|
|
115
|
+
return '';
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* @param join {string} Maker ilk join
|
|
119
|
+
* @returns {string} Token symbol
|
|
120
|
+
*/
|
|
121
|
+
export const tokenFromMakerJoin = (join) => tokenFromJoin(join, ilks);
|
|
122
|
+
/**
|
|
123
|
+
* @param join {string} Reflexer ilk join
|
|
124
|
+
* @returns {string} Token symbol
|
|
125
|
+
*/
|
|
126
|
+
export const tokenFromReflexerJoin = (join) => tokenFromJoin(join, reflexerCollTypes);
|
|
127
|
+
export const getAaveV2MarketInfo = (name = '') => aaveV2Markets.find(i => i.name === name);
|
|
128
|
+
/**
|
|
129
|
+
* @param amount {Number|String|Object} Amount in wei
|
|
130
|
+
* @param asset {String} Asset symbol (or `MCD-${symbol}` for maker asset - always 18dec)
|
|
131
|
+
* @return {String}
|
|
132
|
+
*/
|
|
133
|
+
export const assetAmountInEth = (amount, asset = 'ETH') => {
|
|
134
|
+
if ((amount === null || amount === void 0 ? void 0 : amount.toString()) === 'Infinity')
|
|
135
|
+
return MAXUINT;
|
|
136
|
+
let decimals;
|
|
137
|
+
// USDC/WBTC have 6/8 decimals but Vat is storing it in 18 decimal precision
|
|
138
|
+
if (asset.substr(0, 4) === 'MCD-')
|
|
139
|
+
decimals = 18;
|
|
140
|
+
// Compound returns borrowing power in USD with 18 decimals
|
|
141
|
+
else if (asset === 'USD')
|
|
142
|
+
decimals = 18;
|
|
143
|
+
else
|
|
144
|
+
decimals = getAssetInfo(asset).decimals;
|
|
145
|
+
return new Dec(amount && amount.toString() || 0).div(Math.pow(10, decimals)).toDP(decimals).toString();
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* @param amount {Number|String|Object} Amount in eth
|
|
149
|
+
* @param asset {String} Asset symbol
|
|
150
|
+
* @return {String}
|
|
151
|
+
*/
|
|
152
|
+
export const assetAmountInWei = (amount, asset) => {
|
|
153
|
+
if ((amount === null || amount === void 0 ? void 0 : amount.toString()) === 'Infinity')
|
|
154
|
+
return MAXUINT;
|
|
155
|
+
const { decimals } = getAssetInfo(asset);
|
|
156
|
+
return new Dec(amount && amount.toString() || 0).mul(Math.pow(10, decimals)).floor().toString();
|
|
157
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IlkData } from './types';
|
|
2
|
-
export declare const reflexerCollTypes: IlkData[];
|
|
1
|
+
import { IlkData } from './types';
|
|
2
|
+
export declare const reflexerCollTypes: IlkData[];
|
package/esm/reflexerCollTypes.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export const reflexerCollTypes = [
|
|
2
|
-
{
|
|
3
|
-
"asset": "ETH",
|
|
4
|
-
"ilkLabel": "ETH-A",
|
|
5
|
-
"ilkBytes": "0x4554482d41000000000000000000000000000000000000000000000000000000",
|
|
6
|
-
"join": '0x2D3cD7b81c93f188F3CB8aD87c8Acc73d6226e3A',
|
|
7
|
-
"pip": '0xE6F5377DE93A361cd5531bdFbDf0f4b522E16B2B',
|
|
8
|
-
"isLP": false,
|
|
9
|
-
"isCrop": false
|
|
10
|
-
},
|
|
11
|
-
];
|
|
1
|
+
export const reflexerCollTypes = [
|
|
2
|
+
{
|
|
3
|
+
"asset": "ETH",
|
|
4
|
+
"ilkLabel": "ETH-A",
|
|
5
|
+
"ilkBytes": "0x4554482d41000000000000000000000000000000000000000000000000000000",
|
|
6
|
+
"join": '0x2D3cD7b81c93f188F3CB8aD87c8Acc73d6226e3A',
|
|
7
|
+
"pip": '0xE6F5377DE93A361cd5531bdFbDf0f4b522E16B2B',
|
|
8
|
+
"isLP": false,
|
|
9
|
+
"isCrop": false
|
|
10
|
+
},
|
|
11
|
+
];
|
package/esm/types.d.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
declare type Config = {
|
|
2
|
-
network: number;
|
|
3
|
-
iconFunc: ((props: object) => () => string) | undefined;
|
|
4
|
-
};
|
|
5
|
-
declare type AddressMapping = {
|
|
6
|
-
[key: number]: string;
|
|
7
|
-
};
|
|
8
|
-
declare type BoolMapping = {
|
|
9
|
-
[key: number]: boolean;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Chain-agnostic asset info type
|
|
13
|
-
*/
|
|
14
|
-
declare type AssetDataBase = {
|
|
15
|
-
symbol: string;
|
|
16
|
-
name: string;
|
|
17
|
-
addresses: AddressMapping;
|
|
18
|
-
feedAvailability: BoolMapping;
|
|
19
|
-
decimals: number;
|
|
20
|
-
icon: Function;
|
|
21
|
-
underlyingAsset: string;
|
|
22
|
-
exchange: boolean;
|
|
23
|
-
compoundCollateral: boolean;
|
|
24
|
-
aaveCollateral: boolean;
|
|
25
|
-
yearnCollateral: boolean;
|
|
26
|
-
isStable: boolean;
|
|
27
|
-
nativeChainId: number;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* Chain-specific asset info type
|
|
31
|
-
*/
|
|
32
|
-
declare type AssetData = {
|
|
33
|
-
symbol: string;
|
|
34
|
-
name: string;
|
|
35
|
-
address: string;
|
|
36
|
-
addresses: AddressMapping;
|
|
37
|
-
feedAvailability: BoolMapping;
|
|
38
|
-
decimals: number;
|
|
39
|
-
icon: Function;
|
|
40
|
-
underlyingAsset: string;
|
|
41
|
-
exchange: boolean;
|
|
42
|
-
compoundCollateral: boolean;
|
|
43
|
-
aaveCollateral: boolean;
|
|
44
|
-
yearnCollateral: boolean;
|
|
45
|
-
isStable: boolean;
|
|
46
|
-
nativeChainId: number;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Maker ilk info type
|
|
50
|
-
*/
|
|
51
|
-
declare type IlkData = {
|
|
52
|
-
ilkLabel: (string);
|
|
53
|
-
pip: (string);
|
|
54
|
-
join: (string);
|
|
55
|
-
asset: (string);
|
|
56
|
-
flip?: (string);
|
|
57
|
-
clip?: (string);
|
|
58
|
-
clipCalc?: (string);
|
|
59
|
-
ilkBytes: (string);
|
|
60
|
-
isLP: (boolean);
|
|
61
|
-
isCrop: (boolean);
|
|
62
|
-
assetAddress?: (string);
|
|
63
|
-
};
|
|
64
|
-
declare type AaveMarketData = {
|
|
65
|
-
name: (string);
|
|
66
|
-
lendingPool: (string);
|
|
67
|
-
lendingPoolAddressProvider: (string);
|
|
68
|
-
dataProvider: (string);
|
|
69
|
-
};
|
|
70
|
-
declare type ExtendedIlkData = IlkData | {
|
|
71
|
-
assetData: AssetData;
|
|
72
|
-
};
|
|
73
|
-
export { AddressMapping, AssetDataBase, AssetData, IlkData, ExtendedIlkData, AaveMarketData, Config, };
|
|
1
|
+
declare type Config = {
|
|
2
|
+
network: number;
|
|
3
|
+
iconFunc: ((props: object) => () => string) | undefined;
|
|
4
|
+
};
|
|
5
|
+
declare type AddressMapping = {
|
|
6
|
+
[key: number]: string;
|
|
7
|
+
};
|
|
8
|
+
declare type BoolMapping = {
|
|
9
|
+
[key: number]: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Chain-agnostic asset info type
|
|
13
|
+
*/
|
|
14
|
+
declare type AssetDataBase = {
|
|
15
|
+
symbol: string;
|
|
16
|
+
name: string;
|
|
17
|
+
addresses: AddressMapping;
|
|
18
|
+
feedAvailability: BoolMapping;
|
|
19
|
+
decimals: number;
|
|
20
|
+
icon: Function;
|
|
21
|
+
underlyingAsset: string;
|
|
22
|
+
exchange: boolean;
|
|
23
|
+
compoundCollateral: boolean;
|
|
24
|
+
aaveCollateral: boolean;
|
|
25
|
+
yearnCollateral: boolean;
|
|
26
|
+
isStable: boolean;
|
|
27
|
+
nativeChainId: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Chain-specific asset info type
|
|
31
|
+
*/
|
|
32
|
+
declare type AssetData = {
|
|
33
|
+
symbol: string;
|
|
34
|
+
name: string;
|
|
35
|
+
address: string;
|
|
36
|
+
addresses: AddressMapping;
|
|
37
|
+
feedAvailability: BoolMapping;
|
|
38
|
+
decimals: number;
|
|
39
|
+
icon: Function;
|
|
40
|
+
underlyingAsset: string;
|
|
41
|
+
exchange: boolean;
|
|
42
|
+
compoundCollateral: boolean;
|
|
43
|
+
aaveCollateral: boolean;
|
|
44
|
+
yearnCollateral: boolean;
|
|
45
|
+
isStable: boolean;
|
|
46
|
+
nativeChainId: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Maker ilk info type
|
|
50
|
+
*/
|
|
51
|
+
declare type IlkData = {
|
|
52
|
+
ilkLabel: (string);
|
|
53
|
+
pip: (string);
|
|
54
|
+
join: (string);
|
|
55
|
+
asset: (string);
|
|
56
|
+
flip?: (string);
|
|
57
|
+
clip?: (string);
|
|
58
|
+
clipCalc?: (string);
|
|
59
|
+
ilkBytes: (string);
|
|
60
|
+
isLP: (boolean);
|
|
61
|
+
isCrop: (boolean);
|
|
62
|
+
assetAddress?: (string);
|
|
63
|
+
};
|
|
64
|
+
declare type AaveMarketData = {
|
|
65
|
+
name: (string);
|
|
66
|
+
lendingPool: (string);
|
|
67
|
+
lendingPoolAddressProvider: (string);
|
|
68
|
+
dataProvider: (string);
|
|
69
|
+
};
|
|
70
|
+
declare type ExtendedIlkData = IlkData | {
|
|
71
|
+
assetData: AssetData;
|
|
72
|
+
};
|
|
73
|
+
export { AddressMapping, AssetDataBase, AssetData, IlkData, ExtendedIlkData, AaveMarketData, Config, };
|
package/esm/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/esm/utils.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param hex {string}
|
|
3
|
-
* @returns {string}
|
|
4
|
-
*/
|
|
5
|
-
export declare function bytesToString(hex: string): string;
|
|
6
|
-
/**
|
|
7
|
-
* @param str {string}
|
|
8
|
-
* @return {string} input encoded to hex, padded to 32 bytes
|
|
9
|
-
*/
|
|
10
|
-
export declare function stringToBytes(str: string): string;
|
|
11
|
-
export declare function compare(a?: string, b?: string): boolean;
|
|
1
|
+
/**
|
|
2
|
+
* @param hex {string}
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export declare function bytesToString(hex: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* @param str {string}
|
|
8
|
+
* @return {string} input encoded to hex, padded to 32 bytes
|
|
9
|
+
*/
|
|
10
|
+
export declare function stringToBytes(str: string): string;
|
|
11
|
+
export declare function compare(a?: string, b?: string): boolean;
|