@aurigami/sdk 1.24.0 → 1.24.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.
Files changed (46) hide show
  1. package/dist/consts/constants.d.ts +3 -1
  2. package/dist/consts/constants.js +4 -2
  3. package/dist/entities/auriEnv.d.ts +2 -1
  4. package/dist/entities/auriEnv.js +3 -3
  5. package/dist/helpers/priceFetcher.js +9 -13
  6. package/dist/interactors/misc.js +2 -2
  7. package/package.json +2 -14
  8. package/src/SDK.ts +0 -223
  9. package/src/abis/index.ts +0 -38
  10. package/src/consts/constants.ts +0 -210
  11. package/src/consts/decimals.ts +0 -31
  12. package/src/consts/deployments.ts +0 -4
  13. package/src/consts/dummy.ts +0 -51
  14. package/src/consts/index.ts +0 -5
  15. package/src/consts/symbols.ts +0 -9
  16. package/src/entities/BlockchainEntity.ts +0 -29
  17. package/src/entities/auriEnv.ts +0 -180
  18. package/src/entities/index.ts +0 -4
  19. package/src/entities/token.ts +0 -21
  20. package/src/entities/tokenAmount.ts +0 -48
  21. package/src/helpers/aurigami-api.ts +0 -42
  22. package/src/helpers/aurora-api-helpers.ts +0 -17
  23. package/src/helpers/graphql-helpers.ts +0 -8
  24. package/src/helpers/helpers.ts +0 -212
  25. package/src/helpers/historicalPriceFetcher.ts +0 -200
  26. package/src/helpers/index.ts +0 -7
  27. package/src/helpers/kyber-aggregator-api.ts +0 -37
  28. package/src/helpers/multicall.ts +0 -251
  29. package/src/helpers/notification-api.ts +0 -22
  30. package/src/helpers/one-inch-aggregator-api.ts +0 -45
  31. package/src/helpers/priceFetcher.ts +0 -388
  32. package/src/helpers/subgraphQuery.ts +0 -17
  33. package/src/helpers/transfer-event-query.ts +0 -68
  34. package/src/index.ts +0 -14
  35. package/src/interactors/Airdrop.ts +0 -72
  36. package/src/interactors/MoneyMarket.ts +0 -486
  37. package/src/interactors/Multicall.ts +0 -50
  38. package/src/interactors/Papermill.ts +0 -185
  39. package/src/interactors/PlyGame.ts +0 -172
  40. package/src/interactors/PlyTokenLock.ts +0 -46
  41. package/src/interactors/Pulp.ts +0 -41
  42. package/src/interactors/Referral.ts +0 -214
  43. package/src/interactors/Staking.ts +0 -156
  44. package/src/interactors/index.ts +0 -9
  45. package/src/interactors/misc.ts +0 -433
  46. package/src/types/index.ts +0 -252
@@ -1,486 +0,0 @@
1
- import { AuETH, AuErc20, EthRepayHelper } from '@aurigami/contracts/typechain';
2
- import { TransactionResponse } from '@ethersproject/abstract-provider';
3
- import BigNumber from 'bignumber.js';
4
- import { CacheType, cache } from 'cache-decorator';
5
- import { BigNumber as BN } from 'ethers';
6
- import * as abis from '../abis';
7
- import * as consts from '../consts';
8
- import { CACHE_TIMEOUT, ONE_DAY } from '../consts';
9
- import {
10
- AuriEnv,
11
- BlockchainEntity,
12
- BlockchainEntityRead,
13
- PLYToken,
14
- Token,
15
- TokenAmount,
16
- } from '../entities';
17
- import * as helpers from '../helpers';
18
- import { createContract } from '../helpers/multicall';
19
- import { calcValuation, fetchPrice, fetchValuation } from '../helpers/priceFetcher';
20
- import { Address, Apy, MoneyMarketDetails, MulticallStatic, NetworkConnection } from '../types';
21
-
22
- type RewardSpeeds = {
23
- plyRewardSupplySpeed: BN;
24
- plyRewardBorrowSpeed: BN;
25
- auroraRewardSupplySpeed: BN;
26
- auroraRewardBorrowSpeed: BN;
27
- };
28
-
29
- export class MoneyMarketRead extends BlockchainEntityRead {
30
- public underlying: Token;
31
- public auToken: MulticallStatic<AuErc20 | AuETH>;
32
- public readonly env: AuriEnv;
33
- constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
34
- super(networkConnection);
35
- this.env = new AuriEnv(networkConnection);
36
- if (helpers.isSameAddress(underlyingAsset, consts.ETHAddress)) {
37
- this.auToken = createContract<AuETH>(auToken, abis.AuETHABI.abi, networkConnection.provider);
38
- } else {
39
- this.auToken = createContract<AuErc20>(
40
- auToken,
41
- abis.AuErc20ABI.abi,
42
- networkConnection.provider
43
- );
44
- }
45
- this.underlying = new Token(underlyingAsset, helpers.getDecimal(underlyingAsset));
46
- }
47
-
48
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
49
- public async getUnderlyingPrice(): Promise<BigNumber> {
50
- return fetchPrice(this.underlying.address, this._networkConnection.provider);
51
- }
52
-
53
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
54
- public async getPlyPrice(): Promise<BigNumber> {
55
- return fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider);
56
- }
57
-
58
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
59
- protected async getRewardSpeeds(): Promise<RewardSpeeds> {
60
- var speeds = await this.env.auriLens.callStatic.getRewardSpeeds(
61
- this.env.comptroller.address,
62
- this.auToken.address
63
- );
64
- return speeds;
65
- }
66
-
67
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
68
- public async getTotalTokenBorrowed(): Promise<TokenAmount> {
69
- return new TokenAmount(
70
- this.underlying,
71
- (await this.auToken.callStatic.totalBorrows()).toString()
72
- );
73
- }
74
-
75
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
76
- public async getTotalTokenDeposited(): Promise<TokenAmount> {
77
- const [totalBorrow, totalCash] = await Promise.all([
78
- this.getTotalTokenBorrowed(),
79
- this.auToken.callStatic.getCash(),
80
- ]);
81
- return new TokenAmount(
82
- this.underlying,
83
- BN.from(new TokenAmount(this.underlying, totalCash.toString()).rawAmount())
84
- .add(totalBorrow.rawAmount())
85
- .toString()
86
- );
87
- }
88
-
89
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
90
- public async getDepositAPY(): Promise<BigNumber> {
91
- const supplyRatePerTimestamp = await this.auToken.callStatic.supplyRatePerTimestamp();
92
- const supplyRatePerDay = new BigNumber(supplyRatePerTimestamp.toString())
93
- .multipliedBy(ONE_DAY)
94
- .div(helpers.decimalFactor(18));
95
-
96
- return new BigNumber(supplyRatePerDay.plus(1)).pow(365).minus(1);
97
- }
98
-
99
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
100
- public async getBorrowAPY(): Promise<BigNumber> {
101
- const borrowRatePerTimestamp = await this.auToken.callStatic.borrowRatePerTimestamp();
102
- const borrowRatePerDay = new BigNumber(borrowRatePerTimestamp.toString())
103
- .multipliedBy(ONE_DAY)
104
- .div(helpers.decimalFactor(18));
105
- return new BigNumber(borrowRatePerDay.plus(1)).pow(365).minus(1);
106
- }
107
-
108
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
109
- public async getCollateralRatio(): Promise<BigNumber> {
110
- return this.env.comptroller.callStatic.markets(this.auToken.address).then((res: any) => {
111
- return new BigNumber(res.collateralFactorMantissa.toString()).div(helpers.decimalFactor(18));
112
- });
113
- }
114
-
115
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
116
- public async getBorrowPlyAPY(): Promise<BigNumber> {
117
- const [totalBorrowed, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
118
- this.getTotalTokenBorrowed(),
119
- this.getRewardSpeeds(),
120
- this.getPlyPrice(),
121
- this.getUnderlyingPrice(),
122
- ]);
123
- return helpers.calcLMRewardApr(
124
- calcValuation(
125
- new TokenAmount(PLYToken, rewardSpeeds.plyRewardBorrowSpeed.toString()),
126
- plyPrice
127
- ),
128
- underlyingPrice.multipliedBy(totalBorrowed.formattedAmount()),
129
- consts.ONE_YEAR
130
- );
131
- }
132
-
133
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
134
- public async getDepositPlyAPY(): Promise<BigNumber> {
135
- const [totalDeposited, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
136
- this.getTotalTokenDeposited(),
137
- this.getRewardSpeeds(),
138
- this.getPlyPrice(),
139
- this.getUnderlyingPrice(),
140
- ]);
141
- return helpers.calcLMRewardApr(
142
- calcValuation(
143
- new TokenAmount(PLYToken, rewardSpeeds.plyRewardSupplySpeed.toString()),
144
- plyPrice
145
- ),
146
- underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
147
- consts.ONE_YEAR
148
- );
149
- }
150
-
151
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
152
- public async getDepositNearAPY(): Promise<BigNumber> {
153
- const [totalDeposited, underlyingPrice] = await Promise.all([
154
- this.getTotalTokenDeposited(),
155
- this.getUnderlyingPrice(),
156
- ]);
157
- let depositNEARApy = helpers.calcLMRewardApr(
158
- await fetchValuation(this.getDepositNEARRewardPerWeek(), this._networkConnection.provider),
159
- underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
160
- 52
161
- );
162
- return depositNEARApy;
163
- }
164
-
165
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
166
- public async getBorrowNearAPY(): Promise<BigNumber> {
167
- const [totalBorrowed, underlyingPrice] = await Promise.all([
168
- this.getTotalTokenBorrowed(),
169
- this.getUnderlyingPrice(),
170
- ]);
171
- let borrowNEARApy = helpers.calcLMRewardApr(
172
- await fetchValuation(this.getBorrowNEARRewardPerWeek(), this._networkConnection.provider),
173
- underlyingPrice.multipliedBy(totalBorrowed.formattedAmount()),
174
- 52
175
- );
176
- return borrowNEARApy;
177
- }
178
-
179
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
180
- public async getDepositMetaAPY(): Promise<BigNumber> {
181
- return new BigNumber(0);
182
- // const [totalDeposited, underlyingPrice] = await Promise.all([
183
- // this.getTotalTokenDeposited(),
184
- // fetchPrice(this.underlying.address, this._networkConnection.provider),
185
- // ]);
186
- // let depositMETAApy;
187
- // if (helpers.isSameAddress(this.underlying.address, consts.networkAddresses.tokens.stNEAR)) {
188
- // depositMETAApy = helpers.calcLMRewardApr(
189
- // await fetchValuation(
190
- // TokenAmount.fromAddressAndAmount(consts.networkAddresses.tokens.META, '250000', false),
191
- // this._networkConnection.provider
192
- // ),
193
- // underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
194
- // 12
195
- // );
196
- // } else {
197
- // depositMETAApy = new BigNumber(0);
198
- // }
199
- // return depositMETAApy;
200
- }
201
-
202
- @cache({ ttl: CACHE_TIMEOUT, type: CacheType.MEMO })
203
- public async getDepositStaderAPY(): Promise<BigNumber> {
204
- return new BigNumber(0);
205
- // const rewardStartTime = 1675346400;
206
- // const currentTime = helpers.getCurrentTimestamp();
207
- // if (currentTime < rewardStartTime) {
208
- // return new BigNumber(0);
209
- // }
210
- // const [totalDeposited, underlyingPrice] = await Promise.all([
211
- // this.getTotalTokenDeposited(),
212
- // fetchPrice(this.underlying.address, this._networkConnection.provider),
213
- // ]);
214
- // let depositStaderApy;
215
- // if (helpers.isSameAddress(this.underlying.address, consts.networkAddresses.tokens.NEARX)) {
216
- // depositStaderApy = helpers.calcLMRewardApr(
217
- // await fetchValuation(
218
- // TokenAmount.fromAddressAndAmount(consts.networkAddresses.tokens.STADER, '40', false),
219
- // this._networkConnection.provider
220
- // ),
221
- // underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
222
- // 365
223
- // );
224
- // } else {
225
- // depositStaderApy = new BigNumber(0);
226
- // }
227
- // return depositStaderApy;
228
- }
229
-
230
- public async getDetails(): Promise<MoneyMarketDetails> {
231
- const [totalDeposited, totalBorrowed, depositAPY, borrowAPY, collateralRatio, rewardSpeeds] =
232
- await Promise.all([
233
- this.getTotalTokenDeposited(),
234
- this.getTotalTokenBorrowed(),
235
- this.getDepositAPY(),
236
- this.getBorrowAPY(),
237
- this.getCollateralRatio(),
238
- this.getRewardSpeeds(),
239
- ]);
240
- const [
241
- depositPlyAPY,
242
- borrowPlyAPY,
243
- depositNearAPY,
244
- borrowNearAPY,
245
- depositMetaAPY,
246
- staderDepositApy,
247
- ] = await Promise.all([
248
- this.getDepositPlyAPY(),
249
- this.getBorrowPlyAPY(),
250
- this.getDepositNearAPY(),
251
- this.getBorrowNearAPY(),
252
- this.getDepositMetaAPY(),
253
- this.getDepositStaderAPY(),
254
- ]);
255
- return {
256
- auTokenAddress: this.auToken.address,
257
- totalTokenDeposited: totalDeposited,
258
- totalTokenBorrowed: totalBorrowed,
259
- depositApy: depositAPY.toNumber(),
260
- depositPlyApy: depositPlyAPY.toNumber(),
261
- borrowApy: borrowAPY.toNumber(),
262
- borrowPlyApy: borrowPlyAPY.toNumber() * -1,
263
- collateralRatio: collateralRatio.toNumber(),
264
- depositPlyPerWeek: new TokenAmount(
265
- PLYToken,
266
- rewardSpeeds.plyRewardSupplySpeed.mul(consts.ONE_DAY).mul(7).toString()
267
- ),
268
- borrowPlyPerWeek: new TokenAmount(
269
- PLYToken,
270
- rewardSpeeds.plyRewardBorrowSpeed.mul(consts.ONE_DAY).mul(7).toString()
271
- ),
272
- depositNEARApy: depositNearAPY.toNumber(),
273
- borrowNEARApy: borrowNearAPY.toNumber() * -1,
274
- depositMETAApy: depositMetaAPY.toNumber(),
275
- staderDepositApy: staderDepositApy.toNumber(),
276
- };
277
- }
278
-
279
- public async getUserBorrowBalance(userAddress: string): Promise<TokenAmount> {
280
- const totalBorrow: BN = await this.auToken.callStatic.borrowBalanceCurrent(userAddress);
281
- return new TokenAmount(this.underlying, totalBorrow.toString());
282
- }
283
-
284
- public async getUserDepositBalance(userAddress: string): Promise<TokenAmount> {
285
- const totalDeposit: BN = await this.auToken.callStatic.balanceOfUnderlying(userAddress);
286
- return new TokenAmount(this.underlying, totalDeposit.toString());
287
- }
288
-
289
- private getDepositNEARRewardPerWeek(): TokenAmount {
290
- const NEARToken = new Token(
291
- consts.networkAddresses.tokens.WNEAR,
292
- helpers.getDecimal(consts.networkAddresses.tokens.WNEAR)
293
- );
294
- const rewardStartTime = 1650636000;
295
- const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
296
- const currentTime = helpers.getCurrentTimestamp();
297
- if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
298
- const reward =
299
- consts.DEPOSIT_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? '0';
300
- return new TokenAmount(NEARToken, reward, false);
301
- } else {
302
- return new TokenAmount(NEARToken, '0');
303
- }
304
- }
305
-
306
- private getBorrowNEARRewardPerWeek(): TokenAmount {
307
- const NEARToken = new Token(
308
- consts.networkAddresses.tokens.WNEAR,
309
- helpers.getDecimal(consts.networkAddresses.tokens.WNEAR)
310
- );
311
- const rewardStartTime = 1650636000;
312
- const rewardStopTime = 1651845600; // May 06, 2022 2 PM GMT
313
- const currentTime = helpers.getCurrentTimestamp();
314
- if (currentTime <= rewardStopTime && currentTime > rewardStartTime) {
315
- const reward =
316
- consts.BORROW_NEAR_REWARDS_PER_WEEK[this.underlying.address.toLocaleLowerCase()] ?? '0';
317
- return new TokenAmount(NEARToken, reward, false);
318
- } else {
319
- return new TokenAmount(NEARToken, '0');
320
- }
321
- }
322
- public async mintCap(): Promise<TokenAmount> {
323
- return new TokenAmount(
324
- this.underlying,
325
- (await this.env.comptroller.callStatic.mintCaps(this.auToken.address)).toString()
326
- );
327
- }
328
- public async borrowCap(): Promise<TokenAmount> {
329
- return new TokenAmount(
330
- this.underlying,
331
- (await this.env.comptroller.callStatic.borrowCaps(this.auToken.address)).toString()
332
- );
333
- }
334
-
335
- public async getDepositBorrowValue(userAddress: Address) {
336
- const [price, depositBalance, borrowBalance] = await Promise.all([
337
- this.getUnderlyingPrice(),
338
- this.getUserDepositBalance(userAddress),
339
- this.getUserBorrowBalance(userAddress),
340
- ]);
341
- const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
342
- const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
343
- return {
344
- suppliedValue,
345
- borrowedValue,
346
- };
347
- }
348
-
349
- public async getApyWithoutIncentive(userAddress: Address): Promise<Apy> {
350
- const [price, depositApy, borrowApy, depositBalance, borrowBalance] = await Promise.all([
351
- this.getUnderlyingPrice(),
352
- this.getDepositAPY(),
353
- this.getBorrowAPY(),
354
- this.getUserDepositBalance(userAddress),
355
- this.getUserBorrowBalance(userAddress),
356
- ]);
357
- const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
358
- const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
359
- const sum = helpers.calcNetApy(suppliedValue, depositApy, borrowedValue, borrowApy);
360
- return {
361
- sum,
362
- suppliedValue,
363
- borrowedValue,
364
- };
365
- }
366
-
367
- public async getApyWithIncentive(userAddress: Address): Promise<Apy> {
368
- const [
369
- price,
370
- depositApy,
371
- borrowApy,
372
- depositBalance,
373
- borrowBalance,
374
- nearDepositApy,
375
- plyDepositApy,
376
- metaDepositApy,
377
- nearBorrowApy,
378
- plyBorrowApy,
379
- ] = await Promise.all([
380
- this.getUnderlyingPrice(),
381
- this.getDepositAPY(),
382
- this.getBorrowAPY(),
383
- this.getUserDepositBalance(userAddress),
384
- this.getUserBorrowBalance(userAddress),
385
- this.getDepositNearAPY(),
386
- this.getDepositPlyAPY(),
387
- this.getDepositMetaAPY(),
388
- this.getBorrowNearAPY(),
389
- this.getBorrowPlyAPY(),
390
- ]);
391
- // idk why i cannot put this to promise.all, txds keep getting error
392
- const staderDepositApy = await this.getDepositStaderAPY();
393
- const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
394
- const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
395
- const totalDepositApy = depositApy
396
- .plus(nearDepositApy)
397
- .plus(plyDepositApy)
398
- .plus(metaDepositApy)
399
- .plus(staderDepositApy);
400
- const totalBorrowApy = borrowApy.plus(nearBorrowApy).plus(plyBorrowApy);
401
- const sum = helpers.calcNetApy(suppliedValue, totalDepositApy, borrowedValue, totalBorrowApy);
402
- return {
403
- sum,
404
- suppliedValue,
405
- borrowedValue,
406
- };
407
- }
408
- }
409
-
410
- export class MoneyMarketReadWrite extends MoneyMarketRead {
411
- protected _EthRepayHelper: MulticallStatic<EthRepayHelper>;
412
- constructor(networkConnection: NetworkConnection, auToken: Address, underlyingAsset: Address) {
413
- super(networkConnection, auToken, underlyingAsset);
414
- this._EthRepayHelper = createContract<EthRepayHelper>(
415
- consts.networkAddresses.misc.ETHREPAYHELPER,
416
- abis.EthRepayHelperABI.abi,
417
- networkConnection.provider
418
- );
419
- }
420
-
421
- public async deposit(amount: TokenAmount): Promise<TransactionResponse> {
422
- if (helpers.isSameAddress(amount.token.address, consts.ETHAddress)) {
423
- return (this.auToken.raw as AuETH)
424
- .connect(this._networkConnection.signer!)
425
- .mint({ value: amount.rawAmount() });
426
- } else {
427
- return (this.auToken.raw as AuErc20)
428
- .connect(this._networkConnection.signer!)
429
- .mint(amount.rawAmount());
430
- }
431
- }
432
- public async borrow(amount: TokenAmount): Promise<TransactionResponse> {
433
- return this.auToken.raw.connect(this._networkConnection.signer!).borrow(amount.rawAmount());
434
- }
435
- public async withdraw(amount: TokenAmount): Promise<TransactionResponse> {
436
- if (new BigNumber(amount.rawAmount()).lt(0)) {
437
- return this.auToken.raw.connect(this._networkConnection.signer!).redeemUnderlying(consts.INF);
438
- }
439
- return this.auToken.raw
440
- .connect(this._networkConnection.signer!)
441
- .redeemUnderlying(amount.rawAmount());
442
- }
443
- public async repay(amount: TokenAmount): Promise<TransactionResponse> {
444
- if (helpers.isSameAddress(amount.token.address, consts.ETHAddress)) {
445
- return this._EthRepayHelper.raw
446
- .connect(this._networkConnection.signer!)
447
- .repayBorrow({ value: amount.rawAmount() });
448
- } else {
449
- if (new BigNumber(amount.rawAmount()).lt(0)) {
450
- return this.auToken.raw.connect(this._networkConnection.signer!).repayBorrow(consts.INF);
451
- } else {
452
- return this.auToken.raw
453
- .connect(this._networkConnection.signer!)
454
- .repayBorrow(amount.rawAmount());
455
- }
456
- }
457
- }
458
- public async enableCollateral(): Promise<TransactionResponse> {
459
- return this.env.comptroller.raw
460
- .connect(this._networkConnection.signer!)
461
- .enterMarkets([this.auToken.address]);
462
- }
463
- public async disableCollateral(): Promise<TransactionResponse> {
464
- return this.env.comptroller.raw
465
- .connect(this._networkConnection.signer!)
466
- .exitMarket(this.auToken.address);
467
- }
468
- }
469
-
470
- export class MoneyMarket extends BlockchainEntity {
471
- protected address: Address;
472
-
473
- protected underlying: Address;
474
- constructor(address: string, underlying: string) {
475
- super();
476
- this.address = helpers.validateAndParseAddress(address);
477
- this.underlying = helpers.validateAndParseAddress(underlying);
478
- }
479
- public read(networkConnection: NetworkConnection): MoneyMarketRead {
480
- return new MoneyMarketRead(networkConnection, this.address, this.underlying);
481
- }
482
-
483
- public readWrite(networkConnection: NetworkConnection): MoneyMarketReadWrite {
484
- return new MoneyMarketReadWrite(networkConnection, this.address, this.underlying);
485
- }
486
- }
@@ -1,50 +0,0 @@
1
- import { Multicall2 } from '@aurigami/contracts/typechain';
2
- import { Contract, ethers } from 'ethers';
3
- import { Result } from 'ethers/lib/utils';
4
- import * as abis from '../abis';
5
- import * as consts from '../consts';
6
- import { BlockchainEntityRead } from '../entities';
7
- import { MulticallStatic, NetworkConnection } from '../types';
8
-
9
- export class MulticallRead extends BlockchainEntityRead {
10
- public readonly multicall: Multicall2;
11
- constructor(networkConnection: NetworkConnection) {
12
- super(networkConnection);
13
- this.multicall = new Contract(
14
- consts.networkAddresses.misc.MULTICALL,
15
- abis.Multicall2ABI.abi,
16
- networkConnection.provider
17
- ) as Multicall2;
18
- }
19
-
20
- /**
21
- * Run multiple calls via multicall contract
22
- */
23
- public async aggregate(
24
- calls: {
25
- contract: MulticallStatic<Contract>;
26
- method: string;
27
- args: any[];
28
- returnTypes: string[];
29
- }[]
30
- ): Promise<Result[]> {
31
- const txns = [];
32
- // prepare transactions
33
- for (let i = 0; i < calls.length; i++) {
34
- const call = calls[i];
35
- let txn = await call.contract.raw.populateTransaction[call.method](...call.args);
36
- txns.push({ target: txn.to!, callData: txn.data! });
37
- }
38
-
39
- const response = await this.multicall.callStatic.aggregate(txns);
40
-
41
- // parse results
42
- const decodedReturn = [];
43
- for (let i = 0; i < calls.length; i++) {
44
- decodedReturn.push(
45
- ethers.utils.defaultAbiCoder.decode(calls[i].returnTypes, response.returnData[i])
46
- );
47
- }
48
- return decodedReturn;
49
- }
50
- }