@aurigami/sdk 0.1.5 → 0.2.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/dist/BlockchainEntity.d.ts +6 -7
- package/dist/MoneyMarket.d.ts +19 -8
- package/dist/SDK.d.ts +11 -6
- package/dist/constants.d.ts +18 -2
- package/dist/decimals.d.ts +1 -0
- package/dist/helpers.d.ts +9 -2
- package/dist/index.d.ts +4 -1
- package/dist/priceFetcher.d.ts +18 -0
- package/dist/sdk.cjs.development.js +1506 -1259
- 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 +1483 -1259
- package/dist/sdk.esm.js.map +1 -1
- package/dist/token.d.ts +3 -2
- package/dist/types.d.ts +19 -11
- package/package.json +9 -6
- package/src/BlockchainEntity.ts +13 -10
- package/src/MoneyMarket.ts +121 -37
- package/src/SDK.ts +158 -68
- 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 +73 -5
- package/src/decimals.ts +18 -0
- package/src/helpers.ts +30 -8
- package/src/index.ts +4 -4
- package/src/priceFetcher.ts +108 -0
- package/src/token.ts +16 -6
- package/src/types.ts +22 -12
- package/src/abis/IERC20.json +0 -1259
- package/src/abis/auToken.json +0 -1536
|
@@ -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,11 +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
|
-
'0x0000000000000000000000000000000000000001', 2
|
|
7
|
-
);
|
|
8
|
-
|
|
9
5
|
export const AVAX_DEFAULT_PROVIDER_URL =
|
|
10
6
|
'https://api.avax.network/ext/bc/C/rpc';
|
|
11
7
|
|
|
@@ -13,6 +9,78 @@ export const AVAX_DEFAULT_PROVIDER = new ethers.providers.JsonRpcProvider(
|
|
|
13
9
|
AVAX_DEFAULT_PROVIDER_URL
|
|
14
10
|
);
|
|
15
11
|
|
|
12
|
+
export const dummyAddress: string = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
13
|
+
export const ETHAddress: string = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
14
|
+
|
|
16
15
|
const dummyPrivateKey =
|
|
17
16
|
'1111111111111111111111111111111111111111111111111111111111111111';
|
|
18
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 AurPlyPid = 1;
|
|
86
|
+
|
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/helpers.ts
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
|
-
import
|
|
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
|
+
|
|
2
6
|
export function formatObject(object: Object) {
|
|
3
7
|
return JSON.stringify(object, null, ' ');
|
|
4
8
|
}
|
|
5
9
|
|
|
6
|
-
export
|
|
7
|
-
return BN.from(10)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
}
|
|
11
23
|
|
|
12
|
-
export function validateAndParseAddress(address:
|
|
24
|
+
export function validateAndParseAddress(address: Address): Address {
|
|
13
25
|
try {
|
|
14
26
|
return utils.getAddress(address);
|
|
15
27
|
} catch (error) {
|
|
16
|
-
throw new Error("Invalid address " + address);
|
|
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');
|
|
17
38
|
}
|
|
39
|
+
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
18
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 fetchPriceFromCoingecko(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 fetchBasicTokenPrice(address: Address): Promise<BigNumber> {
|
|
25
|
+
if (isSameAddress(address, networkAddresses.tokens.AURORA)) {
|
|
26
|
+
return fetchPriceFromCoingecko('aurora-near');
|
|
27
|
+
} else {
|
|
28
|
+
throw Error(`Unknown token ${address} in fetchBasicTokenPrice`);
|
|
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 fetchBasicTokenPrice(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
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
+
import { getDecimal } from "./helpers";
|
|
2
|
+
import { networkAddresses } from "./constants";
|
|
3
|
+
|
|
1
4
|
export class Token {
|
|
2
5
|
public readonly address: string;
|
|
3
|
-
public readonly decimals: number;
|
|
4
|
-
public
|
|
5
|
-
|
|
6
|
-
public constructor(address: string, decimals: number, expiry?: number) {
|
|
6
|
+
public readonly decimals: number;
|
|
7
|
+
public constructor(address: string, decimals: number) {
|
|
7
8
|
this.address = address.toLowerCase();
|
|
8
9
|
this.decimals = decimals;
|
|
9
|
-
this.expiry = expiry;
|
|
10
10
|
}
|
|
11
|
-
}
|
|
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
|
+
)
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { providers, Signer } from 'ethers';
|
|
2
|
-
import {
|
|
2
|
+
import { TokenAmount } from './tokenAmount';
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type NetworkConnection = {
|
|
5
|
+
provider: providers.Provider,
|
|
6
|
+
signer?: Signer
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type Address = string;
|
|
10
|
+
|
|
11
|
+
export type CurrencyAmount = {
|
|
12
|
+
currency: string,
|
|
13
|
+
amount: string
|
|
14
|
+
};
|
|
5
15
|
|
|
6
16
|
export type MoneyMarketDetails = {
|
|
7
17
|
auTokenAddress: string;
|
|
8
|
-
totalTokenDeposited:
|
|
9
|
-
totalTokenBorrowed:
|
|
18
|
+
totalTokenDeposited: TokenAmount;
|
|
19
|
+
totalTokenBorrowed: TokenAmount;
|
|
10
20
|
depositApy: number;
|
|
11
21
|
depositPlyApy: number;
|
|
12
22
|
borrowApy: number;
|
|
@@ -17,8 +27,8 @@ export type MoneyMarketDetails = {
|
|
|
17
27
|
export type UserDetails = {
|
|
18
28
|
markets: UserMarketDetails[];
|
|
19
29
|
borrowLimit: CurrencyAmount;
|
|
20
|
-
accruedPly:
|
|
21
|
-
lockedPly:
|
|
30
|
+
accruedPly: TokenAmount;
|
|
31
|
+
lockedPly: TokenAmount;
|
|
22
32
|
borrowableAmount: CurrencyAmount;
|
|
23
33
|
};
|
|
24
34
|
|
|
@@ -35,13 +45,13 @@ export type PlyAuroraPool = {
|
|
|
35
45
|
|
|
36
46
|
export type UserMarketDetails = {
|
|
37
47
|
market: string;
|
|
38
|
-
depositBalance:
|
|
39
|
-
borrowBalance:
|
|
48
|
+
depositBalance: TokenAmount;
|
|
49
|
+
borrowBalance: TokenAmount;
|
|
40
50
|
isCollateral: boolean;
|
|
41
|
-
maxWithdrawableAmount:
|
|
51
|
+
maxWithdrawableAmount: TokenAmount;
|
|
42
52
|
};
|
|
43
53
|
|
|
44
54
|
export type PlyAuroraPoolDetails = {
|
|
45
|
-
totalStakedLiquidity:
|
|
46
|
-
apy:
|
|
47
|
-
};
|
|
55
|
+
totalStakedLiquidity: TokenAmount;
|
|
56
|
+
apy: string;
|
|
57
|
+
};
|