@aurigami/sdk 0.1.6 → 0.2.3
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/BlockchainEntity.d.ts +6 -7
- package/dist/MoneyMarket.d.ts +25 -12
- package/dist/SDK.d.ts +15 -9
- package/dist/constants.d.ts +19 -2
- package/dist/decimals.d.ts +1 -0
- package/dist/dummy.d.ts +6 -5
- package/dist/helpers.d.ts +9 -0
- package/dist/index.d.ts +4 -1
- package/dist/priceFetcher.d.ts +18 -0
- package/dist/sdk.cjs.development.js +2210 -312
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +2184 -310
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +7 -0
- package/dist/tokenAmount.d.ts +8 -0
- package/dist/types.d.ts +23 -11
- package/package.json +8 -7
- package/src/BlockchainEntity.ts +13 -10
- package/src/MoneyMarket.ts +178 -47
- package/src/SDK.ts +163 -72
- package/src/abis/IUniswapV2Pair.json +663 -0
- package/src/abis/Oracle.json +247 -0
- package/src/abis/dummy.json +3 -0
- package/src/constants.ts +75 -8
- package/src/decimals.ts +18 -0
- package/src/dummy.ts +30 -44
- package/src/helpers.ts +37 -0
- package/src/index.ts +4 -4
- package/src/priceFetcher.ts +108 -0
- package/src/token.ts +21 -0
- package/src/tokenAmount.ts +29 -0
- package/src/types.ts +26 -12
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
{
|
|
2
|
+
"abi": [
|
|
3
|
+
{
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"payable": false,
|
|
6
|
+
"stateMutability": "nonpayable",
|
|
7
|
+
"type": "constructor"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"anonymous": false,
|
|
11
|
+
"inputs": [
|
|
12
|
+
{
|
|
13
|
+
"indexed": false,
|
|
14
|
+
"internalType": "address",
|
|
15
|
+
"name": "feed",
|
|
16
|
+
"type": "address"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"indexed": false,
|
|
20
|
+
"internalType": "string",
|
|
21
|
+
"name": "symbol",
|
|
22
|
+
"type": "string"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"name": "FeedSet",
|
|
26
|
+
"type": "event"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"anonymous": false,
|
|
30
|
+
"inputs": [
|
|
31
|
+
{
|
|
32
|
+
"indexed": false,
|
|
33
|
+
"internalType": "address",
|
|
34
|
+
"name": "oldAdmin",
|
|
35
|
+
"type": "address"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"indexed": false,
|
|
39
|
+
"internalType": "address",
|
|
40
|
+
"name": "newAdmin",
|
|
41
|
+
"type": "address"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"name": "NewAdmin",
|
|
45
|
+
"type": "event"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"anonymous": false,
|
|
49
|
+
"inputs": [
|
|
50
|
+
{
|
|
51
|
+
"indexed": false,
|
|
52
|
+
"internalType": "address",
|
|
53
|
+
"name": "asset",
|
|
54
|
+
"type": "address"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"indexed": false,
|
|
58
|
+
"internalType": "uint256",
|
|
59
|
+
"name": "previousPriceMantissa",
|
|
60
|
+
"type": "uint256"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"indexed": false,
|
|
64
|
+
"internalType": "uint256",
|
|
65
|
+
"name": "requestedPriceMantissa",
|
|
66
|
+
"type": "uint256"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"indexed": false,
|
|
70
|
+
"internalType": "uint256",
|
|
71
|
+
"name": "newPriceMantissa",
|
|
72
|
+
"type": "uint256"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"name": "PricePosted",
|
|
76
|
+
"type": "event"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"constant": true,
|
|
80
|
+
"inputs": [],
|
|
81
|
+
"name": "admin",
|
|
82
|
+
"outputs": [
|
|
83
|
+
{
|
|
84
|
+
"internalType": "address",
|
|
85
|
+
"name": "",
|
|
86
|
+
"type": "address"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"payable": false,
|
|
90
|
+
"stateMutability": "view",
|
|
91
|
+
"type": "function"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"constant": true,
|
|
95
|
+
"inputs": [
|
|
96
|
+
{
|
|
97
|
+
"internalType": "address",
|
|
98
|
+
"name": "asset",
|
|
99
|
+
"type": "address"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"name": "assetPrices",
|
|
103
|
+
"outputs": [
|
|
104
|
+
{
|
|
105
|
+
"internalType": "uint256",
|
|
106
|
+
"name": "",
|
|
107
|
+
"type": "uint256"
|
|
108
|
+
}
|
|
109
|
+
],
|
|
110
|
+
"payable": false,
|
|
111
|
+
"stateMutability": "view",
|
|
112
|
+
"type": "function"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
"constant": true,
|
|
116
|
+
"inputs": [
|
|
117
|
+
{
|
|
118
|
+
"internalType": "string",
|
|
119
|
+
"name": "symbol",
|
|
120
|
+
"type": "string"
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
"name": "getFeed",
|
|
124
|
+
"outputs": [
|
|
125
|
+
{
|
|
126
|
+
"internalType": "contract AggregatorV2V3Interface",
|
|
127
|
+
"name": "",
|
|
128
|
+
"type": "address"
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
"payable": false,
|
|
132
|
+
"stateMutability": "view",
|
|
133
|
+
"type": "function"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"constant": true,
|
|
137
|
+
"inputs": [
|
|
138
|
+
{
|
|
139
|
+
"internalType": "contract QiToken",
|
|
140
|
+
"name": "qiToken",
|
|
141
|
+
"type": "address"
|
|
142
|
+
}
|
|
143
|
+
],
|
|
144
|
+
"name": "getUnderlyingPrice",
|
|
145
|
+
"outputs": [
|
|
146
|
+
{
|
|
147
|
+
"internalType": "uint256",
|
|
148
|
+
"name": "",
|
|
149
|
+
"type": "uint256"
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"payable": false,
|
|
153
|
+
"stateMutability": "view",
|
|
154
|
+
"type": "function"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"constant": true,
|
|
158
|
+
"inputs": [],
|
|
159
|
+
"name": "isPriceOracle",
|
|
160
|
+
"outputs": [
|
|
161
|
+
{
|
|
162
|
+
"internalType": "bool",
|
|
163
|
+
"name": "",
|
|
164
|
+
"type": "bool"
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
"payable": false,
|
|
168
|
+
"stateMutability": "view",
|
|
169
|
+
"type": "function"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"constant": false,
|
|
173
|
+
"inputs": [
|
|
174
|
+
{
|
|
175
|
+
"internalType": "address",
|
|
176
|
+
"name": "newAdmin",
|
|
177
|
+
"type": "address"
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"name": "setAdmin",
|
|
181
|
+
"outputs": [],
|
|
182
|
+
"payable": false,
|
|
183
|
+
"stateMutability": "nonpayable",
|
|
184
|
+
"type": "function"
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
"constant": false,
|
|
188
|
+
"inputs": [
|
|
189
|
+
{
|
|
190
|
+
"internalType": "address",
|
|
191
|
+
"name": "asset",
|
|
192
|
+
"type": "address"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"internalType": "uint256",
|
|
196
|
+
"name": "price",
|
|
197
|
+
"type": "uint256"
|
|
198
|
+
}
|
|
199
|
+
],
|
|
200
|
+
"name": "setDirectPrice",
|
|
201
|
+
"outputs": [],
|
|
202
|
+
"payable": false,
|
|
203
|
+
"stateMutability": "nonpayable",
|
|
204
|
+
"type": "function"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"constant": false,
|
|
208
|
+
"inputs": [
|
|
209
|
+
{
|
|
210
|
+
"internalType": "string",
|
|
211
|
+
"name": "symbol",
|
|
212
|
+
"type": "string"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"internalType": "address",
|
|
216
|
+
"name": "feed",
|
|
217
|
+
"type": "address"
|
|
218
|
+
}
|
|
219
|
+
],
|
|
220
|
+
"name": "setFeed",
|
|
221
|
+
"outputs": [],
|
|
222
|
+
"payable": false,
|
|
223
|
+
"stateMutability": "nonpayable",
|
|
224
|
+
"type": "function"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"constant": false,
|
|
228
|
+
"inputs": [
|
|
229
|
+
{
|
|
230
|
+
"internalType": "contract QiToken",
|
|
231
|
+
"name": "qiToken",
|
|
232
|
+
"type": "address"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"internalType": "uint256",
|
|
236
|
+
"name": "underlyingPriceMantissa",
|
|
237
|
+
"type": "uint256"
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"name": "setUnderlyingPrice",
|
|
241
|
+
"outputs": [],
|
|
242
|
+
"payable": false,
|
|
243
|
+
"stateMutability": "nonpayable",
|
|
244
|
+
"type": "function"
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
|
2
2
|
// import ethers from 'ethers';
|
|
3
3
|
const ethers = require('ethers');
|
|
4
4
|
import { Signer } from 'ethers';
|
|
5
|
-
export const DOLLAR = new Token({
|
|
6
|
-
chainId: 43114,
|
|
7
|
-
decimal: 2,
|
|
8
|
-
symbol: 'USDC',
|
|
9
|
-
address: '0x0000000000000000000000000000000000000001',
|
|
10
|
-
});
|
|
11
|
-
|
|
12
5
|
export const AVAX_DEFAULT_PROVIDER_URL =
|
|
13
6
|
'https://api.avax.network/ext/bc/C/rpc';
|
|
14
7
|
|
|
@@ -16,6 +9,80 @@ export const AVAX_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
|
16
9
|
AVAX_DEFAULT_PROVIDER_URL
|
|
17
10
|
);
|
|
18
11
|
|
|
12
|
+
export const dummyAddress: string = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
13
|
+
export const ETHAddress: string = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
14
|
+
|
|
19
15
|
const dummyPrivateKey =
|
|
20
16
|
'1111111111111111111111111111111111111111111111111111111111111111';
|
|
21
17
|
export const AVAX_DEFAULT_SIGNER: Signer = new ethers.Wallet(dummyPrivateKey);
|
|
18
|
+
|
|
19
|
+
export const AURORA_CHAINID = 1313161554;
|
|
20
|
+
|
|
21
|
+
export const DECIMAL_PRECISION = 6;
|
|
22
|
+
|
|
23
|
+
export type NetworkAddresses = {
|
|
24
|
+
auTokens: {
|
|
25
|
+
address: string,
|
|
26
|
+
underlying: string
|
|
27
|
+
}[],
|
|
28
|
+
misc: Record<string, string>,
|
|
29
|
+
tokens: Record<string, string>
|
|
30
|
+
}
|
|
31
|
+
export const networkAddresses: NetworkAddresses = {
|
|
32
|
+
auTokens: [
|
|
33
|
+
{
|
|
34
|
+
address: '0x7967532568bef9ec96cfad6badea4c63add5888a',
|
|
35
|
+
underlying: '0x9738319d4b8a95a9b3cfd99419dbf859904f23d8'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
address: '0x96AAD2c3fde982627d531f45D1Bebd8bE3b86f60',
|
|
39
|
+
underlying: ETHAddress
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
address: '0xccf005cfc3669d806a03f0617885648c397c456e',
|
|
43
|
+
underlying: '0x959bf9bf41062e9cac0e60cacbaa441fbc8946c6'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
address: '0x55a4c111c007f39326edf22cfd63bbbb21a35b35',
|
|
47
|
+
underlying: '0x1c67cb984abdf7f0a6bce2fd5d5e662e0b983369'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
address: '0x77b088236c071ab5bd4e0bd21240b093275adffc',
|
|
51
|
+
underlying: '0x675c7e1d48f88329c6b4cd3867db5f10a69cda18'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
address: '0xaa68274f87fd9ae940f1dec31b643486838481c1',
|
|
55
|
+
underlying: '0x7a80df8230c5aa711e2702a275ab31aeb32754bf'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
address: '0x6970167dfaa2aaa67404204102cbbd18b405eca9',
|
|
59
|
+
underlying: '0x1dc7d4990b1edb9a88f3fa7d899864b69ee2c428',
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
address: '0x9630a6c5b729194972199805075fd76707a9713a',
|
|
63
|
+
underlying: '0x6f8a1daa158e08f75711a64e5a3073e959d688a6'
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
misc: {
|
|
67
|
+
COMPTROLLER: "0xb51028d4f3fc69e3f9e3118ce067a4562c595aad",
|
|
68
|
+
oracle: "0xf1ebfaa2af93f4d82215fd7817c1835853c62fb8",
|
|
69
|
+
AURIFAIRLAUNCH: "0x7942874a9ef8059c5de259625a883dc61f03320d",
|
|
70
|
+
AURILENS: '0xa2635a23a7688cd3acdd07713c4943b2f0f9082c'
|
|
71
|
+
},
|
|
72
|
+
tokens: {
|
|
73
|
+
AURORA: "0x7a80df8230c5aa711e2702a275ab31aeb32754bf",
|
|
74
|
+
PLY: "0x6f8a1daa158e08f75711a64e5a3073e959d688a6",
|
|
75
|
+
AURPLY: dummyAddress
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export const BORROW_LIMIT_BUFFER = new BigNumber(0.95);
|
|
80
|
+
|
|
81
|
+
export const REWARDCLAIMSTART = 1673280000;
|
|
82
|
+
|
|
83
|
+
export const ONE_DAY = 86400;
|
|
84
|
+
|
|
85
|
+
export const ONE_YEAR = ONE_DAY * 365;
|
|
86
|
+
|
|
87
|
+
export const AurPlyPid = 1;
|
|
88
|
+
|
package/src/decimals.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const decimalRecords: Record<string, number> = {
|
|
2
|
+
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': 18,
|
|
3
|
+
'0x9738319d4b8a95a9b3cfd99419dbf859904f23d8': 18,
|
|
4
|
+
'0x1dc7d4990b1edb9a88f3fa7d899864b69ee2c428': 18,
|
|
5
|
+
'0x1c67cb984abdf7f0a6bce2fd5d5e662e0b983369': 18,
|
|
6
|
+
'0x675c7e1d48f88329c6b4cd3867db5f10a69cda18': 18,
|
|
7
|
+
'0xaa68274f87fd9ae940f1dec31b643486838481c1': 8,
|
|
8
|
+
'0x96AAD2c3fde982627d531f45D1Bebd8bE3b86f60': 8,
|
|
9
|
+
'0x6970167dfaa2aaa67404204102cbbd18b405eca9': 8,
|
|
10
|
+
'0x6f8a1daa158e08f75711a64e5a3073e959d688a6': 18,
|
|
11
|
+
'0xccf005cfc3669d806a03f0617885648c397c456e': 8,
|
|
12
|
+
'0x959bf9bf41062e9cac0e60cacbaa441fbc8946c6': 18,
|
|
13
|
+
'0x7a80df8230c5aa711e2702a275ab31aeb32754bf': 18,
|
|
14
|
+
'0x9630a6c5b729194972199805075fd76707a9713a': 8,
|
|
15
|
+
'0x77b088236c071ab5bd4e0bd21240b093275adffc': 8,
|
|
16
|
+
'0x7967532568bef9ec96cfad6badea4c63add5888a': 8,
|
|
17
|
+
'0x55a4c111c007f39326edf22cfd63bbbb21a35b35': 8
|
|
18
|
+
}
|
package/src/dummy.ts
CHANGED
|
@@ -1,49 +1,35 @@
|
|
|
1
|
-
import { Token
|
|
1
|
+
import { Token } from './token';
|
|
2
|
+
import { TokenAmount } from './tokenAmount';
|
|
2
3
|
import { UserMarketDetails } from './types';
|
|
3
4
|
|
|
4
|
-
export const dummyToken = new Token(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
currency: dummyToken,
|
|
33
|
-
amount: '0',
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export const dummyTokenAmount2 = new CurrencyAmount({
|
|
37
|
-
currency: dummyToken,
|
|
38
|
-
amount: '456.123',
|
|
39
|
-
isRaw: false,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
export const dummyTokenAmount3 = new CurrencyAmount({
|
|
43
|
-
currency: dummyToken,
|
|
44
|
-
amount: '1000.123',
|
|
45
|
-
isRaw: false,
|
|
46
|
-
});
|
|
5
|
+
export const dummyToken = new Token('0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', 6);
|
|
6
|
+
|
|
7
|
+
export const dummyPly = new Token('0x8729438eb15e2c8b576fcc6aecda6a148776c0f5', 18);
|
|
8
|
+
|
|
9
|
+
export const dummyPlyAurora = new Token('0xE530dC2095Ef5653205CF5ea79F8979a7028065c', 18);
|
|
10
|
+
|
|
11
|
+
export const dummyTokenAmount = new TokenAmount(
|
|
12
|
+
dummyToken,
|
|
13
|
+
'123.456',
|
|
14
|
+
false,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const dummyZeroTokenAmount = new TokenAmount(
|
|
18
|
+
dummyToken,
|
|
19
|
+
'0',
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const dummyTokenAmount2 = new TokenAmount(
|
|
23
|
+
dummyToken,
|
|
24
|
+
'456.123',
|
|
25
|
+
false,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const dummyTokenAmount3 = new TokenAmount(
|
|
29
|
+
dummyToken,
|
|
30
|
+
'1000.123',
|
|
31
|
+
false,
|
|
32
|
+
);
|
|
47
33
|
|
|
48
34
|
export const dummyMarketAddress = '0xbeb5d47a3f720ec0a390d04b4d41ed7d9688bc7f'; // qiUSDC
|
|
49
35
|
|
package/src/helpers.ts
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { BigNumber as BN, providers, utils } from "ethers";
|
|
3
|
+
import { decimalRecords } from "./decimals";
|
|
4
|
+
import { Address } from "./types";
|
|
5
|
+
|
|
1
6
|
export function formatObject(object: Object) {
|
|
2
7
|
return JSON.stringify(object, null, ' ');
|
|
3
8
|
}
|
|
9
|
+
|
|
10
|
+
export function decimalFactor(decimal: number) {
|
|
11
|
+
return BN.from(10).pow(decimal).toString();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const isSameAddress = (address1: Address, address2: Address): boolean => {
|
|
15
|
+
return address1.toLowerCase() == address2.toLowerCase()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const getCurrentTimestamp = async (provider: providers.Provider): Promise<number> => {
|
|
19
|
+
const latestBlockNumber = await provider.getBlockNumber();
|
|
20
|
+
const currentTime: number = (await provider.getBlock(latestBlockNumber)).timestamp;
|
|
21
|
+
return currentTime;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function validateAndParseAddress(address: Address): Address {
|
|
25
|
+
try {
|
|
26
|
+
return utils.getAddress(address);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error("Invalid address: " + address);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getDecimal(address: Address): number {
|
|
33
|
+
return decimalRecords[address.toLowerCase()];
|
|
34
|
+
}
|
|
35
|
+
export function calcLMRewardApr(rewardsValue: BigNumber, totalStakeValue: BigNumber, frequencyPerYear: number): BigNumber {
|
|
36
|
+
if (totalStakeValue.lte(0)) { // avoid division by zero when there is no stake
|
|
37
|
+
return new BigNumber('999999999');
|
|
38
|
+
}
|
|
39
|
+
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
40
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ export * from './BlockchainEntity';
|
|
|
5
5
|
export * from './helpers';
|
|
6
6
|
export * from './constants';
|
|
7
7
|
export * from './dummy';
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export * from './priceFetcher';
|
|
9
|
+
export * from './token';
|
|
10
|
+
export * from './tokenAmount';
|
|
11
|
+
export * from './types';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Contract, providers, BigNumber as BN } from "ethers";
|
|
3
|
+
import { networkAddresses } from "./constants";
|
|
4
|
+
import OracleABI from "./abis/Oracle.json";
|
|
5
|
+
import { isSameAddress, decimalFactor, getDecimal } from "./helpers";
|
|
6
|
+
import { PriceOracle } from "@aurigami/contracts/typechain";
|
|
7
|
+
import { TokenAmount } from "./tokenAmount";
|
|
8
|
+
import { Address } from "./types";
|
|
9
|
+
import IUniswapV2PairABI from './abis/IUniswapV2Pair.json';
|
|
10
|
+
import dummyABI from "./abis/dummy.json";
|
|
11
|
+
|
|
12
|
+
const axios = require('axios')
|
|
13
|
+
|
|
14
|
+
export async function fetchPriceFromCoingeckoAPI(id: string): Promise<BigNumber> {
|
|
15
|
+
const price = await axios.get(
|
|
16
|
+
`https://api.coingecko.com/api/v3/simple/price?ids=${id}&vs_currencies=usd`
|
|
17
|
+
).then((res: any) => {
|
|
18
|
+
return res.data
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return new BigNumber(price[id].usd)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function fetchPriceFromCoingecko(address: Address): Promise<BigNumber> {
|
|
25
|
+
if (isSameAddress(address, networkAddresses.tokens.AURORA)) {
|
|
26
|
+
return fetchPriceFromCoingeckoAPI('aurora-near');
|
|
27
|
+
} else {
|
|
28
|
+
throw Error(`Unknown token ${address} in fetchPriceFromCoingecko`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export async function fetchLPPositions(LPAddress: Address, provider: providers.Provider): Promise<{
|
|
33
|
+
token0: Address,
|
|
34
|
+
token1: Address,
|
|
35
|
+
reserve0: BN,
|
|
36
|
+
reserve1: BN,
|
|
37
|
+
totalSupply: BN
|
|
38
|
+
}> {
|
|
39
|
+
var promises = [];
|
|
40
|
+
const LPContract = new Contract(LPAddress, IUniswapV2PairABI.abi, provider);
|
|
41
|
+
promises.push(LPContract.token0());
|
|
42
|
+
promises.push(LPContract.toekn1());
|
|
43
|
+
promises.push(LPContract.getReserves());
|
|
44
|
+
promises.push(LPContract.totalSupply());
|
|
45
|
+
const values = await Promise.all(promises);
|
|
46
|
+
return {
|
|
47
|
+
token0: values[0],
|
|
48
|
+
token1: values[1],
|
|
49
|
+
reserve0: values[2]._reserve0,
|
|
50
|
+
reserve1: values[2]._reserve1,
|
|
51
|
+
totalSupply: values[3]
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function fetchLPPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
|
|
56
|
+
var LPInfo = await fetchLPPositions(address, provider);
|
|
57
|
+
try {
|
|
58
|
+
const token0Price: BigNumber = await fetchPrice(LPInfo.token0, provider);
|
|
59
|
+
const reserveUSD: BigNumber = token0Price.multipliedBy(LPInfo.reserve0.toString()).multipliedBy(2);
|
|
60
|
+
return reserveUSD.multipliedBy(decimalFactor(18)).dividedBy(new BigNumber(LPInfo.totalSupply.toString()));
|
|
61
|
+
} catch {
|
|
62
|
+
try {
|
|
63
|
+
const token1Price: BigNumber = await fetchPrice(LPInfo.token1, provider);
|
|
64
|
+
const reserveUSD: BigNumber = token1Price.multipliedBy(LPInfo.reserve1.toString()).multipliedBy(2);
|
|
65
|
+
return reserveUSD.multipliedBy(decimalFactor(18)).dividedBy(new BigNumber(LPInfo.totalSupply.toString()));
|
|
66
|
+
} catch {
|
|
67
|
+
throw Error(`Unable to fetch price for both tokens of LP ${address}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function processPriceFromOracle(rawPrice: BN, underlyingDecimal: number) {
|
|
73
|
+
return new BigNumber(rawPrice.toString()).div(decimalFactor(36 - underlyingDecimal));
|
|
74
|
+
}
|
|
75
|
+
export async function fetchPriceFromOracle(auTokenAddress: Address, underlyingDecimal: number, provider: providers.Provider): Promise<BigNumber> {
|
|
76
|
+
const oracleContract: PriceOracle = new Contract(networkAddresses.misc.oracle, OracleABI.abi, provider) as PriceOracle;
|
|
77
|
+
const rawPrice = await oracleContract.getUnderlyingPrice(auTokenAddress);
|
|
78
|
+
return processPriceFromOracle(rawPrice, underlyingDecimal)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export async function fetchUnderlyingTokensPrices(provider: providers.Provider) {
|
|
82
|
+
const auriLens: Contract = new Contract(networkAddresses.misc.AURILENS, dummyABI.abi, provider);
|
|
83
|
+
const auTokenAddresses = networkAddresses.auTokens.map((auToken) => auToken.address);
|
|
84
|
+
const underlyingDecimals = networkAddresses.auTokens.map((auToken) => getDecimal(auToken.underlying));
|
|
85
|
+
const rawPrices = await auriLens.auTokenUnderlyingPriceAll(auTokenAddresses);
|
|
86
|
+
return rawPrices.map((res: any, ind: number) => {
|
|
87
|
+
return {
|
|
88
|
+
auToken: res.auToken,
|
|
89
|
+
underlyingPrice: processPriceFromOracle(res.underlyingPrice, underlyingDecimals[ind])
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export async function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber> {
|
|
95
|
+
const matchingAuToken = networkAddresses.auTokens.find((auToken) => {
|
|
96
|
+
return isSameAddress(auToken.underlying, address)
|
|
97
|
+
});
|
|
98
|
+
if (matchingAuToken !== undefined) {
|
|
99
|
+
return fetchPriceFromOracle(matchingAuToken.address, getDecimal(address), provider);
|
|
100
|
+
} else if (isSameAddress(address, networkAddresses.misc.AUPLYLP)) {
|
|
101
|
+
return fetchLPPrice(address, provider);
|
|
102
|
+
} else {
|
|
103
|
+
return fetchPriceFromCoingecko(address);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export async function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider, price?: BigNumber): Promise<BigNumber> {
|
|
107
|
+
return new BigNumber(0)
|
|
108
|
+
}
|
package/src/token.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getDecimal } from "./helpers";
|
|
2
|
+
import { networkAddresses } from "./constants";
|
|
3
|
+
|
|
4
|
+
export class Token {
|
|
5
|
+
public readonly address: string;
|
|
6
|
+
public readonly decimals: number;
|
|
7
|
+
public constructor(address: string, decimals: number) {
|
|
8
|
+
this.address = address.toLowerCase();
|
|
9
|
+
this.decimals = decimals;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const PLYToken = new Token(
|
|
14
|
+
networkAddresses.tokens.PLY,
|
|
15
|
+
getDecimal(networkAddresses.tokens.PLY)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
export const AURPLYToken = new Token(
|
|
19
|
+
networkAddresses.tokens.AURPLY,
|
|
20
|
+
getDecimal(networkAddresses.tokens.AURPLY)
|
|
21
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Token } from "./token";
|
|
2
|
+
import BigNumber from 'bignumber.js';
|
|
3
|
+
import { decimalFactor } from "./helpers";
|
|
4
|
+
|
|
5
|
+
export class TokenAmount {
|
|
6
|
+
public readonly token: Token;
|
|
7
|
+
private rawAmnt: string;
|
|
8
|
+
|
|
9
|
+
public constructor(token: Token, amount: string, isRaw: boolean = true) {
|
|
10
|
+
if (isRaw) {
|
|
11
|
+
this.rawAmnt = amount;
|
|
12
|
+
} else {
|
|
13
|
+
this.rawAmnt = new BigNumber(amount)
|
|
14
|
+
.times(decimalFactor(token.decimals))
|
|
15
|
+
.toFixed(0);
|
|
16
|
+
}
|
|
17
|
+
this.token = token;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public formattedAmount(): string {
|
|
21
|
+
return new BigNumber(this.rawAmnt)
|
|
22
|
+
.div(decimalFactor(this.token.decimals))
|
|
23
|
+
.toString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public rawAmount(): string {
|
|
27
|
+
return this.rawAmnt;
|
|
28
|
+
}
|
|
29
|
+
}
|