@aurigami/sdk 1.6.3 → 1.6.5
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/ChangeLog.md +159 -0
- package/dist/SDK.d.ts +4 -7
- package/dist/abis/index.d.ts +14 -0
- package/dist/consts/constants.d.ts +2 -2
- package/dist/consts/dummy.d.ts +1 -2
- package/dist/contracts/{airdrop-lottery.d.ts → Airdrop.d.ts} +0 -5
- package/dist/contracts/MoneyMarket.d.ts +3 -4
- package/dist/contracts/Multicall.d.ts +1 -1
- package/dist/contracts/Papermill.d.ts +2 -7
- package/dist/contracts/Staking.d.ts +2 -5
- package/dist/contracts/index.d.ts +2 -1
- package/dist/contracts/misc.d.ts +26 -0
- package/dist/entities/auriEnv.d.ts +13 -0
- package/dist/entities/index.d.ts +1 -0
- package/dist/entities/tokenAmount.d.ts +1 -1
- package/dist/helpers/priceFetcher.d.ts +1 -1
- package/dist/helpers/transfer-event-query.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/sdk.cjs.development.js +582 -104415
- 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 +585 -104420
- package/dist/sdk.esm.js.map +1 -1
- package/package.json +7 -6
- package/src/SDK.ts +23 -330
- package/src/abis/index.ts +30 -0
- package/src/consts/constants.ts +15 -16
- package/src/consts/dummy.ts +4 -14
- package/src/contracts/Airdrop.ts +80 -0
- package/src/contracts/MoneyMarket.ts +56 -160
- package/src/contracts/Multicall.ts +5 -10
- package/src/contracts/Papermill.ts +32 -113
- package/src/contracts/Referral.ts +4 -7
- package/src/contracts/Staking.ts +18 -59
- package/src/contracts/index.ts +2 -1
- package/src/contracts/misc.ts +281 -0
- package/src/entities/BlockchainEntity.ts +2 -6
- package/src/entities/auriEnv.ts +39 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/token.ts +1 -1
- package/src/entities/tokenAmount.ts +4 -12
- package/src/helpers/aurora-api-helpers.ts +3 -6
- package/src/helpers/helpers.ts +9 -18
- package/src/helpers/priceFetcher.ts +21 -62
- package/src/helpers/transfer-event-query.ts +4 -6
- package/src/index.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/abis/Faucet.json +0 -157
- package/src/abis/IUniswapV2Pair.json +0 -663
- package/src/abis/Oracle.json +0 -247
- package/src/abis/dummy.json +0 -3
- package/src/contracts/airdrop-lottery.ts +0 -320
- package/src/misc/airdrop_misc/auTokensInfo.json +0 -34
- package/src/misc/airdrop_misc/whitelist.json +0 -102629
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import AuETHABI from '@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json';
|
|
3
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
4
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
5
|
-
import EthRepayHelperABI from '@aurigami/contracts/artifacts/contracts/EthRepayHelper.sol/EthRepayHelper.json';
|
|
6
|
-
import {
|
|
7
|
-
AuErc20,
|
|
8
|
-
AuETH,
|
|
9
|
-
AuriLens,
|
|
10
|
-
Comptroller,
|
|
11
|
-
EthRepayHelper,
|
|
12
|
-
} from '@aurigami/contracts/typechain';
|
|
1
|
+
import { AuErc20, AuETH, EthRepayHelper } from '@aurigami/contracts/typechain';
|
|
13
2
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
14
3
|
import BigNumber from 'bignumber.js';
|
|
15
4
|
import { BigNumber as BN, Contract } from 'ethers';
|
|
5
|
+
import * as abis from '../abis';
|
|
16
6
|
import * as consts from '../consts';
|
|
17
7
|
import {
|
|
8
|
+
AuriEnv,
|
|
18
9
|
BlockchainEntity,
|
|
19
10
|
BlockchainEntityRead,
|
|
20
11
|
PLYToken,
|
|
@@ -22,17 +13,8 @@ import {
|
|
|
22
13
|
TokenAmount,
|
|
23
14
|
} from '../entities';
|
|
24
15
|
import * as helpers from '../helpers/';
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
fetchPrice,
|
|
28
|
-
fetchValuation,
|
|
29
|
-
} from '../helpers/priceFetcher';
|
|
30
|
-
import {
|
|
31
|
-
Address,
|
|
32
|
-
ComptrollerRewardType,
|
|
33
|
-
MoneyMarketDetails,
|
|
34
|
-
NetworkConnection,
|
|
35
|
-
} from '../types';
|
|
16
|
+
import { calcValuation, fetchPrice, fetchValuation } from '../helpers/priceFetcher';
|
|
17
|
+
import { Address, ComptrollerRewardType, MoneyMarketDetails, NetworkConnection } from '../types';
|
|
36
18
|
|
|
37
19
|
type RewardSpeeds = {
|
|
38
20
|
plyRewardSupplySpeed: BN;
|
|
@@ -44,56 +26,31 @@ type RewardSpeeds = {
|
|
|
44
26
|
export class MoneyMarketRead extends BlockchainEntityRead {
|
|
45
27
|
public underlying: Token;
|
|
46
28
|
public auToken: AuErc20 | AuETH;
|
|
47
|
-
protected
|
|
48
|
-
|
|
49
|
-
protected _auriLens: AuriLens;
|
|
50
|
-
constructor(
|
|
51
|
-
networkConnection: NetworkConnection,
|
|
52
|
-
auToken: Address,
|
|
53
|
-
underlyingAsset: Address
|
|
54
|
-
) {
|
|
29
|
+
protected env: AuriEnv;
|
|
30
|
+
constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
|
|
55
31
|
super(networkConnection);
|
|
32
|
+
this.env = new AuriEnv(networkConnection);
|
|
56
33
|
if (helpers.isSameAddress(underlyingAsset, consts.ETHAddress)) {
|
|
57
|
-
this.auToken = new Contract(
|
|
58
|
-
auToken,
|
|
59
|
-
AuETHABI.abi,
|
|
60
|
-
networkConnection.provider
|
|
61
|
-
) as AuETH;
|
|
34
|
+
this.auToken = new Contract(auToken, abis.AuETHABI.abi, networkConnection.provider) as AuETH;
|
|
62
35
|
} else {
|
|
63
36
|
this.auToken = new Contract(
|
|
64
37
|
auToken,
|
|
65
|
-
AuErc20ABI.abi,
|
|
38
|
+
abis.AuErc20ABI.abi,
|
|
66
39
|
networkConnection.provider
|
|
67
40
|
) as AuErc20;
|
|
68
41
|
}
|
|
69
|
-
this.underlying = new Token(
|
|
70
|
-
underlyingAsset,
|
|
71
|
-
helpers.getDecimal(underlyingAsset)
|
|
72
|
-
);
|
|
73
|
-
this._comptroller = new Contract(
|
|
74
|
-
consts.networkAddresses.misc.COMPTROLLER,
|
|
75
|
-
ComptrollerABI.abi,
|
|
76
|
-
networkConnection.provider
|
|
77
|
-
) as Comptroller;
|
|
78
|
-
this._auriLens = new Contract(
|
|
79
|
-
consts.networkAddresses.misc.AURILENS,
|
|
80
|
-
AuriLensABI.abi,
|
|
81
|
-
networkConnection.provider
|
|
82
|
-
) as AuriLens;
|
|
42
|
+
this.underlying = new Token(underlyingAsset, helpers.getDecimal(underlyingAsset));
|
|
83
43
|
}
|
|
84
44
|
|
|
85
45
|
protected async getRewardSpeeds(): Promise<RewardSpeeds> {
|
|
86
|
-
var speeds = await this.
|
|
87
|
-
this.
|
|
46
|
+
var speeds = await this.env.auriLens.getRewardSpeeds(
|
|
47
|
+
this.env.comptroller.address,
|
|
88
48
|
this.auToken.address
|
|
89
49
|
);
|
|
90
50
|
return speeds;
|
|
91
51
|
}
|
|
92
52
|
public async getTotalTokenBorrowed(): Promise<TokenAmount> {
|
|
93
|
-
return new TokenAmount(
|
|
94
|
-
this.underlying,
|
|
95
|
-
(await this.auToken.totalBorrows()).toString()
|
|
96
|
-
);
|
|
53
|
+
return new TokenAmount(this.underlying, (await this.auToken.totalBorrows()).toString());
|
|
97
54
|
}
|
|
98
55
|
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
99
56
|
var promises = [];
|
|
@@ -130,10 +87,8 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
130
87
|
}
|
|
131
88
|
|
|
132
89
|
public async getCollateralRatio(): Promise<BigNumber> {
|
|
133
|
-
return this.
|
|
134
|
-
return new BigNumber(res.collateralFactorMantissa.toString()).div(
|
|
135
|
-
helpers.decimalFactor(18)
|
|
136
|
-
);
|
|
90
|
+
return this.env.comptroller.markets(this.auToken.address).then((res: any) => {
|
|
91
|
+
return new BigNumber(res.collateralFactorMantissa.toString()).div(helpers.decimalFactor(18));
|
|
137
92
|
});
|
|
138
93
|
}
|
|
139
94
|
|
|
@@ -149,25 +104,21 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
149
104
|
})
|
|
150
105
|
);
|
|
151
106
|
promises.push(
|
|
152
|
-
this.
|
|
107
|
+
this.env.comptroller
|
|
153
108
|
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, false)
|
|
154
109
|
.then((res) => {
|
|
155
110
|
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
156
111
|
})
|
|
157
112
|
);
|
|
158
113
|
promises.push(
|
|
159
|
-
fetchPrice(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
})
|
|
114
|
+
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
115
|
+
(res) => {
|
|
116
|
+
plyPrice = res;
|
|
117
|
+
}
|
|
118
|
+
)
|
|
165
119
|
);
|
|
166
120
|
promises.push(
|
|
167
|
-
fetchPrice(
|
|
168
|
-
this.underlying.address,
|
|
169
|
-
this._networkConnection.provider
|
|
170
|
-
).then((res) => {
|
|
121
|
+
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
171
122
|
underlyingPrice = res;
|
|
172
123
|
})
|
|
173
124
|
);
|
|
@@ -191,25 +142,21 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
191
142
|
})
|
|
192
143
|
);
|
|
193
144
|
promises.push(
|
|
194
|
-
this.
|
|
145
|
+
this.env.comptroller
|
|
195
146
|
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, true)
|
|
196
147
|
.then((res) => {
|
|
197
148
|
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
198
149
|
})
|
|
199
150
|
);
|
|
200
151
|
promises.push(
|
|
201
|
-
fetchPrice(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
})
|
|
152
|
+
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
153
|
+
(res) => {
|
|
154
|
+
plyPrice = res;
|
|
155
|
+
}
|
|
156
|
+
)
|
|
207
157
|
);
|
|
208
158
|
promises.push(
|
|
209
|
-
fetchPrice(
|
|
210
|
-
this.underlying.address,
|
|
211
|
-
this._networkConnection.provider
|
|
212
|
-
).then((res) => {
|
|
159
|
+
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
213
160
|
underlyingPrice = res;
|
|
214
161
|
})
|
|
215
162
|
);
|
|
@@ -253,27 +200,21 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
253
200
|
})
|
|
254
201
|
);
|
|
255
202
|
|
|
256
|
-
var plyPrice: BigNumber,
|
|
257
|
-
underlyingPrice: BigNumber,
|
|
258
|
-
rewardSpeeds: RewardSpeeds;
|
|
203
|
+
var plyPrice: BigNumber, underlyingPrice: BigNumber, rewardSpeeds: RewardSpeeds;
|
|
259
204
|
promises.push(
|
|
260
205
|
this.getRewardSpeeds().then((res) => {
|
|
261
206
|
rewardSpeeds = res;
|
|
262
207
|
})
|
|
263
208
|
);
|
|
264
209
|
promises.push(
|
|
265
|
-
fetchPrice(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
})
|
|
210
|
+
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
211
|
+
(res) => {
|
|
212
|
+
plyPrice = res;
|
|
213
|
+
}
|
|
214
|
+
)
|
|
271
215
|
);
|
|
272
216
|
promises.push(
|
|
273
|
-
fetchPrice(
|
|
274
|
-
this.underlying.address,
|
|
275
|
-
this._networkConnection.provider
|
|
276
|
-
).then((res) => {
|
|
217
|
+
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
277
218
|
underlyingPrice = res;
|
|
278
219
|
})
|
|
279
220
|
);
|
|
@@ -282,10 +223,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
282
223
|
|
|
283
224
|
var borrowPlyApy = helpers.calcLMRewardApr(
|
|
284
225
|
calcValuation(
|
|
285
|
-
new TokenAmount(
|
|
286
|
-
PLYToken,
|
|
287
|
-
rewardSpeeds!.plyRewardBorrowSpeed.toString()
|
|
288
|
-
),
|
|
226
|
+
new TokenAmount(PLYToken, rewardSpeeds!.plyRewardBorrowSpeed.toString()),
|
|
289
227
|
plyPrice!
|
|
290
228
|
),
|
|
291
229
|
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
|
|
@@ -293,10 +231,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
293
231
|
);
|
|
294
232
|
var depositPlyApy = helpers.calcLMRewardApr(
|
|
295
233
|
calcValuation(
|
|
296
|
-
new TokenAmount(
|
|
297
|
-
PLYToken,
|
|
298
|
-
rewardSpeeds!.plyRewardSupplySpeed.toString()
|
|
299
|
-
),
|
|
234
|
+
new TokenAmount(PLYToken, rewardSpeeds!.plyRewardSupplySpeed.toString()),
|
|
300
235
|
plyPrice!
|
|
301
236
|
),
|
|
302
237
|
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
@@ -304,28 +239,17 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
304
239
|
);
|
|
305
240
|
|
|
306
241
|
var depositNEARApy = helpers.calcLMRewardApr(
|
|
307
|
-
await fetchValuation(
|
|
308
|
-
this.getDepositNEARRewardPerWeek(),
|
|
309
|
-
this._networkConnection.provider
|
|
310
|
-
),
|
|
242
|
+
await fetchValuation(this.getDepositNEARRewardPerWeek(), this._networkConnection.provider),
|
|
311
243
|
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
312
244
|
52
|
|
313
245
|
);
|
|
314
246
|
var borrowNEARApy = helpers.calcLMRewardApr(
|
|
315
|
-
await fetchValuation(
|
|
316
|
-
this.getBorrowNEARRewardPerWeek(),
|
|
317
|
-
this._networkConnection.provider
|
|
318
|
-
),
|
|
247
|
+
await fetchValuation(this.getBorrowNEARRewardPerWeek(), this._networkConnection.provider),
|
|
319
248
|
underlyingPrice!.multipliedBy(totalBorrowed!.formattedAmount()),
|
|
320
249
|
52
|
|
321
250
|
);
|
|
322
251
|
var depositMETAApy;
|
|
323
|
-
if (
|
|
324
|
-
helpers.isSameAddress(
|
|
325
|
-
this.underlying.address,
|
|
326
|
-
consts.networkAddresses.tokens.stNEAR
|
|
327
|
-
)
|
|
328
|
-
) {
|
|
252
|
+
if (helpers.isSameAddress(this.underlying.address, consts.networkAddresses.tokens.stNEAR)) {
|
|
329
253
|
depositMETAApy = helpers.calcLMRewardApr(
|
|
330
254
|
new BigNumber(50000),
|
|
331
255
|
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
@@ -359,18 +283,12 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
359
283
|
}
|
|
360
284
|
|
|
361
285
|
public async getUserBorrowBalance(userAddress: string): Promise<TokenAmount> {
|
|
362
|
-
const totalBorrow: BN = await this.auToken.callStatic.borrowBalanceCurrent(
|
|
363
|
-
userAddress
|
|
364
|
-
);
|
|
286
|
+
const totalBorrow: BN = await this.auToken.callStatic.borrowBalanceCurrent(userAddress);
|
|
365
287
|
return new TokenAmount(this.underlying, totalBorrow.toString());
|
|
366
288
|
}
|
|
367
289
|
|
|
368
|
-
public async getUserDepositBalance(
|
|
369
|
-
|
|
370
|
-
): Promise<TokenAmount> {
|
|
371
|
-
const totalDeposit: BN = await this.auToken.callStatic.balanceOfUnderlying(
|
|
372
|
-
userAddress
|
|
373
|
-
);
|
|
290
|
+
public async getUserDepositBalance(userAddress: string): Promise<TokenAmount> {
|
|
291
|
+
const totalDeposit: BN = await this.auToken.callStatic.balanceOfUnderlying(userAddress);
|
|
374
292
|
return new TokenAmount(this.underlying, totalDeposit.toString());
|
|
375
293
|
}
|
|
376
294
|
|
|
@@ -384,9 +302,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
384
302
|
const currentTime = helpers.getCurrentTimestamp();
|
|
385
303
|
if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
|
|
386
304
|
const reward =
|
|
387
|
-
consts.DEPOSIT_NEAR_REWARDS_PER_WEEK[
|
|
388
|
-
this.underlying.address.toLocaleLowerCase()
|
|
389
|
-
] ?? '0';
|
|
305
|
+
consts.DEPOSIT_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? '0';
|
|
390
306
|
return new TokenAmount(NEARToken, reward, false);
|
|
391
307
|
} else {
|
|
392
308
|
return new TokenAmount(NEARToken, '0');
|
|
@@ -403,9 +319,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
403
319
|
const currentTime = helpers.getCurrentTimestamp();
|
|
404
320
|
if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
|
|
405
321
|
const reward =
|
|
406
|
-
consts.BORROW_NEAR_REWARDS_PER_WEEK[
|
|
407
|
-
this.underlying.address.toLocaleLowerCase()
|
|
408
|
-
] ?? '0';
|
|
322
|
+
consts.BORROW_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? '0';
|
|
409
323
|
return new TokenAmount(NEARToken, reward, false);
|
|
410
324
|
} else {
|
|
411
325
|
return new TokenAmount(NEARToken, '0');
|
|
@@ -415,15 +329,11 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
415
329
|
|
|
416
330
|
export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
417
331
|
protected _EthRepayHelper: EthRepayHelper;
|
|
418
|
-
constructor(
|
|
419
|
-
networkConnection: NetworkConnection,
|
|
420
|
-
auToken: Address,
|
|
421
|
-
underlyingAsset: Address
|
|
422
|
-
) {
|
|
332
|
+
constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
|
|
423
333
|
super(networkConnection, auToken, underlyingAsset);
|
|
424
334
|
this._EthRepayHelper = new Contract(
|
|
425
335
|
consts.networkAddresses.misc.ETHREPAYHELPER,
|
|
426
|
-
EthRepayHelperABI.abi,
|
|
336
|
+
abis.EthRepayHelperABI.abi,
|
|
427
337
|
networkConnection.provider
|
|
428
338
|
) as EthRepayHelper;
|
|
429
339
|
}
|
|
@@ -440,15 +350,11 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
|
440
350
|
}
|
|
441
351
|
}
|
|
442
352
|
public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
|
|
443
|
-
return this.auToken
|
|
444
|
-
.connect(this._networkConnection.signer!)
|
|
445
|
-
.borrow(amount.rawAmount());
|
|
353
|
+
return this.auToken.connect(this._networkConnection.signer!).borrow(amount.rawAmount());
|
|
446
354
|
}
|
|
447
355
|
public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
|
|
448
356
|
if (new BigNumber(amount.rawAmount()).lt(0)) {
|
|
449
|
-
return this.auToken
|
|
450
|
-
.connect(this._networkConnection.signer!)
|
|
451
|
-
.redeemUnderlying(consts.INF);
|
|
357
|
+
return this.auToken.connect(this._networkConnection.signer!).redeemUnderlying(consts.INF);
|
|
452
358
|
}
|
|
453
359
|
return this.auToken
|
|
454
360
|
.connect(this._networkConnection.signer!)
|
|
@@ -461,9 +367,7 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
|
461
367
|
.repayBorrow({ value: amount.rawAmount() });
|
|
462
368
|
} else {
|
|
463
369
|
if (new BigNumber(amount.rawAmount()).lt(0)) {
|
|
464
|
-
return this.auToken
|
|
465
|
-
.connect(this._networkConnection.signer!)
|
|
466
|
-
.repayBorrow(consts.INF);
|
|
370
|
+
return this.auToken.connect(this._networkConnection.signer!).repayBorrow(consts.INF);
|
|
467
371
|
} else {
|
|
468
372
|
return this.auToken
|
|
469
373
|
.connect(this._networkConnection.signer!)
|
|
@@ -472,12 +376,12 @@ export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
|
472
376
|
}
|
|
473
377
|
}
|
|
474
378
|
public async enableCollateral(): Promise<TransactionResponse> {
|
|
475
|
-
return this.
|
|
379
|
+
return this.env.comptroller
|
|
476
380
|
.connect(this._networkConnection.signer!)
|
|
477
381
|
.enterMarkets([this.auToken.address]);
|
|
478
382
|
}
|
|
479
383
|
public async disableCollateral(): Promise<TransactionResponse> {
|
|
480
|
-
return this.
|
|
384
|
+
return this.env.comptroller
|
|
481
385
|
.connect(this._networkConnection.signer!)
|
|
482
386
|
.exitMarket(this.auToken.address);
|
|
483
387
|
}
|
|
@@ -493,18 +397,10 @@ export class MoneyMarket extends BlockchainEntity {
|
|
|
493
397
|
this.underlying = helpers.validateAndParseAddress(underlying);
|
|
494
398
|
}
|
|
495
399
|
public read(networkConnection: NetworkConnection): MoneyMarketRead {
|
|
496
|
-
return new MoneyMarketRead(
|
|
497
|
-
networkConnection,
|
|
498
|
-
this.address,
|
|
499
|
-
this.underlying
|
|
500
|
-
);
|
|
400
|
+
return new MoneyMarketRead(networkConnection, this.address, this.underlying);
|
|
501
401
|
}
|
|
502
402
|
|
|
503
403
|
public readWrite(networkConnection: NetworkConnection): MoneyMarketReadWrite {
|
|
504
|
-
return new MoneyMarketReadWrite(
|
|
505
|
-
networkConnection,
|
|
506
|
-
this.address,
|
|
507
|
-
this.underlying
|
|
508
|
-
);
|
|
404
|
+
return new MoneyMarketReadWrite(networkConnection, this.address, this.underlying);
|
|
509
405
|
}
|
|
510
406
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import Multicall2ABI from '@aurigami/contracts/artifacts/contracts/mock/Multicall2.sol/Multicall2.json';
|
|
2
1
|
import { Multicall2 } from '@aurigami/contracts/typechain';
|
|
3
2
|
import { Contract, ethers } from 'ethers';
|
|
3
|
+
import { Result } from 'ethers/lib/utils';
|
|
4
|
+
import * as abis from '../abis';
|
|
4
5
|
import * as consts from '../consts';
|
|
5
6
|
import { BlockchainEntityRead } from '../entities';
|
|
6
7
|
import { NetworkConnection } from '../types';
|
|
7
|
-
import { Result } from 'ethers/lib/utils';
|
|
8
8
|
|
|
9
9
|
export class MulticallRead extends BlockchainEntityRead {
|
|
10
10
|
protected _multicall: Multicall2;
|
|
@@ -12,7 +12,7 @@ export class MulticallRead extends BlockchainEntityRead {
|
|
|
12
12
|
super(networkConnection);
|
|
13
13
|
this._multicall = new Contract(
|
|
14
14
|
consts.networkAddresses.misc.MULTICALL,
|
|
15
|
-
Multicall2ABI.abi,
|
|
15
|
+
abis.Multicall2ABI.abi,
|
|
16
16
|
networkConnection.provider
|
|
17
17
|
) as Multicall2;
|
|
18
18
|
}
|
|
@@ -32,9 +32,7 @@ export class MulticallRead extends BlockchainEntityRead {
|
|
|
32
32
|
// prepare transactions
|
|
33
33
|
for (let i = 0; i < calls.length; i++) {
|
|
34
34
|
const call = calls[i];
|
|
35
|
-
let txn = await call.contract.populateTransaction[call.method](
|
|
36
|
-
...call.args
|
|
37
|
-
);
|
|
35
|
+
let txn = await call.contract.populateTransaction[call.method](...call.args);
|
|
38
36
|
txns.push({ target: txn.to!, callData: txn.data! });
|
|
39
37
|
}
|
|
40
38
|
|
|
@@ -44,10 +42,7 @@ export class MulticallRead extends BlockchainEntityRead {
|
|
|
44
42
|
const decodedReturn = [];
|
|
45
43
|
for (let i = 0; i < calls.length; i++) {
|
|
46
44
|
decodedReturn.push(
|
|
47
|
-
ethers.utils.defaultAbiCoder.decode(
|
|
48
|
-
calls[i].returnTypes,
|
|
49
|
-
response.returnData[i]
|
|
50
|
-
)
|
|
45
|
+
ethers.utils.defaultAbiCoder.decode(calls[i].returnTypes, response.returnData[i])
|
|
51
46
|
);
|
|
52
47
|
}
|
|
53
48
|
return decodedReturn;
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import AuriFairLaunchABI from '@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json';
|
|
2
|
-
import AuriLensABI from '@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json';
|
|
3
|
-
import ComptrollerABI from '@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json';
|
|
4
|
-
import EIP20InterfaceABI from '@aurigami/contracts/artifacts/contracts/interfaces/EIP20Interface.sol/EIP20Interface.json';
|
|
5
|
-
import PulpABI from '@aurigami/contracts/artifacts/contracts/PULP.sol/PULP.json';
|
|
6
|
-
import {
|
|
7
|
-
AuriFairLaunch,
|
|
8
|
-
AuriLens,
|
|
9
|
-
Comptroller,
|
|
10
|
-
IERC20,
|
|
11
|
-
PULP,
|
|
12
|
-
} from '@aurigami/contracts/typechain';
|
|
13
1
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
14
2
|
import BigNumber from 'bignumber.js';
|
|
15
|
-
import { BigNumber as BN
|
|
3
|
+
import { BigNumber as BN } from 'ethers';
|
|
16
4
|
import * as consts from '../consts';
|
|
17
|
-
import {
|
|
18
|
-
BlockchainEntity,
|
|
19
|
-
BlockchainEntityRead,
|
|
20
|
-
Token,
|
|
21
|
-
TokenAmount,
|
|
22
|
-
} from '../entities';
|
|
5
|
+
import { AuriEnv, BlockchainEntity, BlockchainEntityRead, Token, TokenAmount } from '../entities';
|
|
23
6
|
import * as helpers from '../helpers';
|
|
24
7
|
import { Address, NetworkConnection, UserLockingDetails } from '../types';
|
|
25
8
|
|
|
@@ -27,76 +10,41 @@ const LOCKING_DENOMINATOR = BN.from(10000);
|
|
|
27
10
|
export class PapermillRead extends BlockchainEntityRead {
|
|
28
11
|
public plyToken: Token;
|
|
29
12
|
public pulpToken: Token;
|
|
30
|
-
|
|
31
|
-
protected _ply: IERC20;
|
|
32
|
-
protected _pulp: PULP;
|
|
33
|
-
protected _comptroller: Comptroller;
|
|
34
|
-
protected _auriFairLaunch: AuriFairLaunch;
|
|
35
|
-
protected _auriLens: AuriLens;
|
|
13
|
+
protected env: AuriEnv;
|
|
36
14
|
|
|
37
15
|
constructor(networkConnection: NetworkConnection) {
|
|
38
16
|
super(networkConnection);
|
|
17
|
+
this.env = new AuriEnv(networkConnection);
|
|
39
18
|
|
|
40
19
|
let plyAddress = consts.networkAddresses.tokens.PLY;
|
|
41
20
|
let pulpAddress = consts.networkAddresses.tokens.PULP;
|
|
42
21
|
|
|
43
22
|
this.plyToken = new Token(plyAddress, helpers.getDecimal(plyAddress));
|
|
44
23
|
this.pulpToken = new Token(pulpAddress, helpers.getDecimal(pulpAddress));
|
|
45
|
-
|
|
46
|
-
this._comptroller = new Contract(
|
|
47
|
-
consts.networkAddresses.misc.COMPTROLLER,
|
|
48
|
-
ComptrollerABI.abi,
|
|
49
|
-
networkConnection.provider
|
|
50
|
-
) as Comptroller;
|
|
51
|
-
this._auriFairLaunch = new Contract(
|
|
52
|
-
consts.networkAddresses.misc.AURIFAIRLAUNCH,
|
|
53
|
-
AuriFairLaunchABI.abi,
|
|
54
|
-
networkConnection.provider
|
|
55
|
-
) as AuriFairLaunch;
|
|
56
|
-
this._auriLens = new Contract(
|
|
57
|
-
consts.networkAddresses.misc.AURILENS,
|
|
58
|
-
AuriLensABI.abi,
|
|
59
|
-
networkConnection.provider
|
|
60
|
-
) as AuriLens;
|
|
61
|
-
this._ply = new Contract(
|
|
62
|
-
plyAddress,
|
|
63
|
-
EIP20InterfaceABI.abi,
|
|
64
|
-
networkConnection.provider
|
|
65
|
-
) as IERC20;
|
|
66
|
-
this._pulp = new Contract(
|
|
67
|
-
pulpAddress,
|
|
68
|
-
PulpABI.abi,
|
|
69
|
-
networkConnection.provider
|
|
70
|
-
) as PULP;
|
|
71
24
|
}
|
|
72
25
|
|
|
73
26
|
public async getPlyBalance(userAddress: Address): Promise<TokenAmount> {
|
|
74
|
-
const plyBalance = await this.
|
|
27
|
+
const plyBalance = await this.env.ply.balanceOf(userAddress);
|
|
75
28
|
return new TokenAmount(this.plyToken, plyBalance.toString());
|
|
76
29
|
}
|
|
77
30
|
|
|
78
31
|
public async getPulpBalance(userAddress: Address): Promise<TokenAmount> {
|
|
79
|
-
const pulpBalance = await this.
|
|
32
|
+
const pulpBalance = await this.env.pulp.balanceOf(userAddress);
|
|
80
33
|
return new TokenAmount(this.pulpToken, pulpBalance.toString());
|
|
81
34
|
}
|
|
82
35
|
|
|
83
36
|
/**
|
|
84
37
|
* Get all unclaimed PLY reward of the user in all markets + all staking pools
|
|
85
38
|
*/
|
|
86
|
-
public async getUnclaimedPlyReward(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this._comptroller.address,
|
|
91
|
-
this._auriFairLaunch.address,
|
|
39
|
+
public async getUnclaimedPlyReward(userAddress: Address): Promise<TokenAmount> {
|
|
40
|
+
let rewardBalancesMetadata = await this.env.auriLens.callStatic.claimRewards(
|
|
41
|
+
this.env.comptroller.address,
|
|
42
|
+
this.env.auriFairLaunch.address,
|
|
92
43
|
consts.ALL_STAKING_POOLS,
|
|
93
44
|
{ from: userAddress }
|
|
94
45
|
);
|
|
95
46
|
|
|
96
|
-
return new TokenAmount(
|
|
97
|
-
this.plyToken,
|
|
98
|
-
rewardBalancesMetadata.plyAccrured.toString()
|
|
99
|
-
);
|
|
47
|
+
return new TokenAmount(this.plyToken, rewardBalancesMetadata.plyAccrured.toString());
|
|
100
48
|
}
|
|
101
49
|
|
|
102
50
|
private getWeek(timestamp: number): number {
|
|
@@ -108,25 +56,15 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
108
56
|
/**
|
|
109
57
|
* Get all locking details of the user in all markets + all staking pools
|
|
110
58
|
*/
|
|
111
|
-
public async getLockingDetails(
|
|
112
|
-
userAddress: Address
|
|
113
|
-
): Promise<UserLockingDetails> {
|
|
59
|
+
public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
|
|
114
60
|
const currentWeek = this.getWeek(helpers.getCurrentTimestamp());
|
|
115
61
|
var promises: any[] = [];
|
|
116
62
|
|
|
117
63
|
promises.push(
|
|
118
|
-
this.
|
|
119
|
-
this._pulp.address,
|
|
120
|
-
userAddress,
|
|
121
|
-
currentWeek
|
|
122
|
-
)
|
|
64
|
+
this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek)
|
|
123
65
|
);
|
|
124
66
|
promises.push(
|
|
125
|
-
this.
|
|
126
|
-
this._pulp.address,
|
|
127
|
-
userAddress,
|
|
128
|
-
currentWeek + 1
|
|
129
|
-
)
|
|
67
|
+
this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek + 1)
|
|
130
68
|
);
|
|
131
69
|
promises.push(this.getUnclaimedPlyReward(userAddress));
|
|
132
70
|
|
|
@@ -136,44 +74,31 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
136
74
|
let percentLockNextWeek = BN.from(values[1]);
|
|
137
75
|
let totalRewards = values[2] as TokenAmount;
|
|
138
76
|
|
|
139
|
-
let [pulpAmountCurrentWeek, plyAmountCurrentWeek] =
|
|
140
|
-
|
|
77
|
+
let [pulpAmountCurrentWeek, plyAmountCurrentWeek] = await this.env.pulp.calcLockAmount(
|
|
78
|
+
userAddress,
|
|
79
|
+
totalRewards.rawAmount()
|
|
80
|
+
);
|
|
141
81
|
|
|
142
82
|
// Predict next week lock amount = totalRewards * percentLock next week
|
|
143
83
|
// This doesn't take (the reward that user might earn in the next week) into account
|
|
144
84
|
let plyAmountNextWeek = percentLockNextWeek
|
|
145
85
|
.mul(totalRewards.rawAmount())
|
|
146
86
|
.div(LOCKING_DENOMINATOR);
|
|
147
|
-
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(
|
|
148
|
-
plyAmountNextWeek
|
|
149
|
-
);
|
|
87
|
+
let pulpAmountNextWeek = BN.from(totalRewards.rawAmount()).sub(plyAmountNextWeek);
|
|
150
88
|
|
|
151
89
|
// we need to divide these two number by 10000 and multiple by 100 to get the percentage
|
|
152
90
|
// I need to use BigNumber to do this because BN of ethers.js doesn't support floating point
|
|
153
|
-
let currentUnlockPortion = LOCKING_DENOMINATOR.sub(
|
|
154
|
-
|
|
155
|
-
).toString();
|
|
156
|
-
let nextUnlockPortion =
|
|
157
|
-
LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
|
|
91
|
+
let currentUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockCurrentWeek).toString();
|
|
92
|
+
let nextUnlockPortion = LOCKING_DENOMINATOR.sub(percentLockNextWeek).toString();
|
|
158
93
|
|
|
159
94
|
return {
|
|
160
95
|
vestingStart: consts.REWARD_CLAIM_START,
|
|
161
|
-
currentUnlockPortion: new BigNumber(currentUnlockPortion)
|
|
162
|
-
.dividedBy(100)
|
|
163
|
-
.toNumber(),
|
|
96
|
+
currentUnlockPortion: new BigNumber(currentUnlockPortion).dividedBy(100).toNumber(),
|
|
164
97
|
accruedPly: totalRewards,
|
|
165
|
-
currentPly: new TokenAmount(
|
|
166
|
-
|
|
167
|
-
plyAmountCurrentWeek.toString()
|
|
168
|
-
),
|
|
169
|
-
currentPulp: new TokenAmount(
|
|
170
|
-
this.pulpToken,
|
|
171
|
-
pulpAmountCurrentWeek.toString()
|
|
172
|
-
),
|
|
98
|
+
currentPly: new TokenAmount(this.plyToken, plyAmountCurrentWeek.toString()),
|
|
99
|
+
currentPulp: new TokenAmount(this.pulpToken, pulpAmountCurrentWeek.toString()),
|
|
173
100
|
//
|
|
174
|
-
nextUnlockPortion: new BigNumber(nextUnlockPortion)
|
|
175
|
-
.dividedBy(100)
|
|
176
|
-
.toNumber(),
|
|
101
|
+
nextUnlockPortion: new BigNumber(nextUnlockPortion).dividedBy(100).toNumber(),
|
|
177
102
|
nextPly: new TokenAmount(this.plyToken, plyAmountNextWeek.toString()),
|
|
178
103
|
nextPulp: new TokenAmount(this.pulpToken, pulpAmountNextWeek.toString()),
|
|
179
104
|
};
|
|
@@ -189,8 +114,8 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
189
114
|
userAddress: Address,
|
|
190
115
|
targetUnlockPortion: number
|
|
191
116
|
): Promise<number> {
|
|
192
|
-
let weekId = await this.
|
|
193
|
-
this.
|
|
117
|
+
let weekId = await this.env.auriLens.getWeekToUnlock(
|
|
118
|
+
this.env.pulp.address,
|
|
194
119
|
userAddress,
|
|
195
120
|
targetUnlockPortion * 100
|
|
196
121
|
);
|
|
@@ -210,12 +135,9 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
210
135
|
return consts.REWARD_CLAIM_START + consts.ONE_WEEK * nextWeek;
|
|
211
136
|
}
|
|
212
137
|
|
|
213
|
-
public async getUnlockPortionAt(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
): Promise<number> {
|
|
217
|
-
let lockPortion = await this._auriLens.getPercentLock(
|
|
218
|
-
this._pulp.address,
|
|
138
|
+
public async getUnlockPortionAt(userAddress: Address, timestamp: number): Promise<number> {
|
|
139
|
+
let lockPortion = await this.env.auriLens.getPercentLock(
|
|
140
|
+
this.env.pulp.address,
|
|
219
141
|
userAddress,
|
|
220
142
|
this.getWeek(timestamp)
|
|
221
143
|
);
|
|
@@ -237,11 +159,8 @@ export class PapermillReadWrite extends PapermillRead {
|
|
|
237
159
|
* @param amount Amount of PULP to be converted to PLY.
|
|
238
160
|
* Set to ethers.constants.MaxUint256 for max redeem.
|
|
239
161
|
*/
|
|
240
|
-
public async redeem(
|
|
241
|
-
|
|
242
|
-
amount: TokenAmount
|
|
243
|
-
): Promise<TransactionResponse> {
|
|
244
|
-
return this._pulp
|
|
162
|
+
public async redeem(recipient: Address, amount: TokenAmount): Promise<TransactionResponse> {
|
|
163
|
+
return this.env.pulp
|
|
245
164
|
.connect(this._networkConnection.signer!)
|
|
246
165
|
.redeem(recipient, amount.rawAmount());
|
|
247
166
|
}
|