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