@aurigami/sdk 1.23.1 → 1.24.1

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