@aurigami/sdk 1.12.9 → 1.13.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.
- package/dist/SDK.d.ts +2 -0
- package/dist/consts/constants.d.ts +1 -0
- package/dist/helpers/helpers.d.ts +2 -0
- package/dist/interactors/MoneyMarket.d.ts +8 -1
- package/dist/interactors/misc.d.ts +2 -0
- package/dist/sdk.cjs.development.js +784 -363
- 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 +782 -364
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/package.json +1 -1
- package/src/SDK.ts +10 -0
- package/src/consts/constants.ts +2 -0
- package/src/helpers/helpers.ts +30 -1
- package/src/helpers/priceFetcher.ts +11 -11
- package/src/interactors/MoneyMarket.ts +176 -167
- package/src/interactors/Papermill.ts +5 -10
- package/src/interactors/misc.ts +82 -32
- package/src/types/index.ts +6 -0
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/SDK.ts
CHANGED
|
@@ -91,6 +91,16 @@ export class SdkRead extends BlockchainEntityRead {
|
|
|
91
91
|
): Promise<types.AccountAuTokensInfo[]> {
|
|
92
92
|
return this._misc.sneakAccounts(accounts, tokenAddresses, dust);
|
|
93
93
|
}
|
|
94
|
+
|
|
95
|
+
public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
96
|
+
const miscRead = new MiscRead(this._networkConnection);
|
|
97
|
+
return miscRead.getNetApyWithoutIncentive(userAddress);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
101
|
+
const miscRead = new MiscRead(this._networkConnection);
|
|
102
|
+
return miscRead.getNetApyWithIncentive(userAddress);
|
|
103
|
+
}
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export class SdkReadWrite extends SdkRead {
|
package/src/consts/constants.ts
CHANGED
|
@@ -184,3 +184,5 @@ export const REFERRAL_CAMPAIGNS: { [k: string]: { start: number; end: number } }
|
|
|
184
184
|
['referral-1506', { start: 1654696800, end: 1655301599 }],
|
|
185
185
|
['referrer-1506', { start: 1654696800, end: 1655301599 }],
|
|
186
186
|
]);
|
|
187
|
+
|
|
188
|
+
export const CACHE_TIMEOUT = 10 * 1000; // 10 seconds
|
package/src/helpers/helpers.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Provider } from '@ethersproject/abstract-provider';
|
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { BigNumber as BN, utils } from 'ethers';
|
|
5
5
|
import { Result } from 'ethers/lib/utils';
|
|
6
|
-
import { networkAddresses } from '../consts/constants';
|
|
6
|
+
import { CACHE_TIMEOUT, networkAddresses } from '../consts/constants';
|
|
7
7
|
import { decimalRecords } from '../consts/decimals';
|
|
8
8
|
import { symbolRecords } from '../consts/symbols';
|
|
9
9
|
import { Address } from '../types';
|
|
@@ -83,6 +83,15 @@ export function calcLMRewardApr(
|
|
|
83
83
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
export function calcNetApy(
|
|
87
|
+
suppliedValue: BigNumber,
|
|
88
|
+
supplyApy: BigNumber,
|
|
89
|
+
borrowedValue: BigNumber,
|
|
90
|
+
borrowApy: BigNumber
|
|
91
|
+
) {
|
|
92
|
+
return suppliedValue.multipliedBy(supplyApy).minus(borrowedValue.multipliedBy(borrowApy));
|
|
93
|
+
}
|
|
94
|
+
|
|
86
95
|
export async function getBlockTimestamp(provider: Provider, blockNumber: number): Promise<number> {
|
|
87
96
|
const block = await provider.getBlock(blockNumber);
|
|
88
97
|
return block.timestamp;
|
|
@@ -181,3 +190,23 @@ export function sortEvents<T extends Result>(events: TypedEvent<T>[]): TypedEven
|
|
|
181
190
|
return a.blockNumber - b.blockNumber;
|
|
182
191
|
});
|
|
183
192
|
}
|
|
193
|
+
|
|
194
|
+
export function Cache(cacheTimeout: number) {
|
|
195
|
+
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
196
|
+
const originalMethod = descriptor.value;
|
|
197
|
+
let cache = new Map<string, any>();
|
|
198
|
+
descriptor.value = function (...args: any[]) {
|
|
199
|
+
let key = JSON.stringify(args);
|
|
200
|
+
if (cache.has(key)) {
|
|
201
|
+
let [timestamp, value] = cache.get(key);
|
|
202
|
+
if (Date.now() - timestamp < cacheTimeout) {
|
|
203
|
+
return value;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
let result = originalMethod.apply(this, args);
|
|
207
|
+
cache.set(key, [Date.now(), result]);
|
|
208
|
+
return result;
|
|
209
|
+
};
|
|
210
|
+
return descriptor;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
@@ -81,19 +81,19 @@ export async function fetchLPPositions(
|
|
|
81
81
|
totalSupply: BN;
|
|
82
82
|
}> {
|
|
83
83
|
const LPContract = new Contract(LPAddress, IUniswapV2PairABI.abi, provider) as IUniswapV2Pair;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
const [token0, token1, reserves, totalSupply] = await Promise.all([
|
|
85
|
+
LPContract.token0(),
|
|
86
|
+
LPContract.token1(),
|
|
87
|
+
LPContract.getReserves(),
|
|
88
|
+
LPContract.totalSupply(),
|
|
89
|
+
]);
|
|
90
90
|
|
|
91
91
|
return {
|
|
92
|
-
token0:
|
|
93
|
-
token1:
|
|
94
|
-
reserve0:
|
|
95
|
-
reserve1:
|
|
96
|
-
totalSupply:
|
|
92
|
+
token0: token0,
|
|
93
|
+
token1: token1,
|
|
94
|
+
reserve0: reserves.reserve0,
|
|
95
|
+
reserve1: reserves.reserve1,
|
|
96
|
+
totalSupply: totalSupply,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -4,7 +4,7 @@ import BigNumber from 'bignumber.js';
|
|
|
4
4
|
import { BigNumber as BN, Contract } from 'ethers';
|
|
5
5
|
import * as abis from '../abis';
|
|
6
6
|
import * as consts from '../consts';
|
|
7
|
-
import { ONE_DAY } from '../consts';
|
|
7
|
+
import { CACHE_TIMEOUT, ONE_DAY } from '../consts';
|
|
8
8
|
import {
|
|
9
9
|
AuriEnv,
|
|
10
10
|
BlockchainEntity,
|
|
@@ -15,7 +15,14 @@ import {
|
|
|
15
15
|
} from '../entities';
|
|
16
16
|
import * as helpers from '../helpers';
|
|
17
17
|
import { calcValuation, fetchPrice, fetchValuation } from '../helpers/priceFetcher';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
Address,
|
|
20
|
+
Apy,
|
|
21
|
+
ComptrollerRewardType,
|
|
22
|
+
MoneyMarketDetails,
|
|
23
|
+
NetworkConnection,
|
|
24
|
+
} from '../types';
|
|
25
|
+
import { Cache } from '../helpers/helpers';
|
|
19
26
|
|
|
20
27
|
type RewardSpeeds = {
|
|
21
28
|
plyRewardSupplySpeed: BN;
|
|
@@ -43,6 +50,17 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
43
50
|
this.underlying = new Token(underlyingAsset, helpers.getDecimal(underlyingAsset));
|
|
44
51
|
}
|
|
45
52
|
|
|
53
|
+
@Cache(CACHE_TIMEOUT)
|
|
54
|
+
public async getUnderlyingPrice(): Promise<BigNumber> {
|
|
55
|
+
return fetchPrice(this.underlying.address, this._networkConnection.provider);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Cache(CACHE_TIMEOUT)
|
|
59
|
+
public async getPlyPrice(): Promise<BigNumber> {
|
|
60
|
+
return fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@Cache(CACHE_TIMEOUT)
|
|
46
64
|
protected async getRewardSpeeds(): Promise<RewardSpeeds> {
|
|
47
65
|
var speeds = await this.env.auriLens.getRewardSpeeds(
|
|
48
66
|
this.env.comptroller.address,
|
|
@@ -50,29 +68,27 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
50
68
|
);
|
|
51
69
|
return speeds;
|
|
52
70
|
}
|
|
71
|
+
|
|
72
|
+
@Cache(CACHE_TIMEOUT)
|
|
53
73
|
public async getTotalTokenBorrowed(): Promise<TokenAmount> {
|
|
54
74
|
return new TokenAmount(this.underlying, (await this.auToken.totalBorrows()).toString());
|
|
55
75
|
}
|
|
76
|
+
|
|
77
|
+
@Cache(CACHE_TIMEOUT)
|
|
56
78
|
public async getTotalTokenDeposited(): Promise<TokenAmount> {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
totalBorrow = res;
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
promises.push(
|
|
65
|
-
this.auToken.getCash().then((res: BN) => {
|
|
66
|
-
totalCash = new TokenAmount(this.underlying, res.toString());
|
|
67
|
-
})
|
|
68
|
-
);
|
|
69
|
-
await Promise.all(promises);
|
|
79
|
+
const [totalBorrow, totalCash] = await Promise.all([
|
|
80
|
+
this.getTotalTokenBorrowed(),
|
|
81
|
+
this.auToken.getCash(),
|
|
82
|
+
]);
|
|
70
83
|
return new TokenAmount(
|
|
71
84
|
this.underlying,
|
|
72
|
-
BN.from(totalCash
|
|
85
|
+
BN.from(new TokenAmount(this.underlying, totalCash.toString()).rawAmount())
|
|
86
|
+
.add(totalBorrow.rawAmount())
|
|
87
|
+
.toString()
|
|
73
88
|
);
|
|
74
89
|
}
|
|
75
90
|
|
|
91
|
+
@Cache(CACHE_TIMEOUT)
|
|
76
92
|
public async getDepositAPY(): Promise<BigNumber> {
|
|
77
93
|
const supplyRatePerTimestamp = await this.auToken.supplyRatePerTimestamp();
|
|
78
94
|
const supplyRatePerDay = new BigNumber(supplyRatePerTimestamp.toString())
|
|
@@ -82,6 +98,7 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
82
98
|
return new BigNumber(supplyRatePerDay.plus(1)).pow(365).minus(1);
|
|
83
99
|
}
|
|
84
100
|
|
|
101
|
+
@Cache(CACHE_TIMEOUT)
|
|
85
102
|
public async getBorrowAPY(): Promise<BigNumber> {
|
|
86
103
|
const borrowRatePerTimestamp = await this.auToken.borrowRatePerTimestamp();
|
|
87
104
|
const borrowRatePerDay = new BigNumber(borrowRatePerTimestamp.toString())
|
|
@@ -90,202 +107,137 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
90
107
|
return new BigNumber(borrowRatePerDay.plus(1)).pow(365).minus(1);
|
|
91
108
|
}
|
|
92
109
|
|
|
110
|
+
@Cache(CACHE_TIMEOUT)
|
|
93
111
|
public async getCollateralRatio(): Promise<BigNumber> {
|
|
94
112
|
return this.env.comptroller.markets(this.auToken.address).then((res: any) => {
|
|
95
113
|
return new BigNumber(res.collateralFactorMantissa.toString()).div(helpers.decimalFactor(18));
|
|
96
114
|
});
|
|
97
115
|
}
|
|
98
116
|
|
|
117
|
+
@Cache(CACHE_TIMEOUT)
|
|
99
118
|
public async getBorrowPlyAPY(): Promise<BigNumber> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
107
|
-
totalBorrowed = res;
|
|
108
|
-
})
|
|
109
|
-
);
|
|
110
|
-
promises.push(
|
|
111
|
-
this.env.comptroller
|
|
112
|
-
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, false)
|
|
113
|
-
.then((res) => {
|
|
114
|
-
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
promises.push(
|
|
118
|
-
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
119
|
-
(res) => {
|
|
120
|
-
plyPrice = res;
|
|
121
|
-
}
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
promises.push(
|
|
125
|
-
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
126
|
-
underlyingPrice = res;
|
|
127
|
-
})
|
|
128
|
-
);
|
|
129
|
-
await Promise.all(promises);
|
|
119
|
+
const [totalBorrowed, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
|
|
120
|
+
this.getTotalTokenBorrowed(),
|
|
121
|
+
this.getRewardSpeeds(),
|
|
122
|
+
this.getPlyPrice(),
|
|
123
|
+
this.getUnderlyingPrice(),
|
|
124
|
+
]);
|
|
130
125
|
return helpers.calcLMRewardApr(
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
calcValuation(
|
|
127
|
+
new TokenAmount(PLYToken, rewardSpeeds.plyRewardBorrowSpeed.toString()),
|
|
128
|
+
plyPrice
|
|
129
|
+
),
|
|
130
|
+
underlyingPrice.multipliedBy(totalBorrowed.formattedAmount()),
|
|
133
131
|
consts.ONE_YEAR
|
|
134
132
|
);
|
|
135
133
|
}
|
|
136
134
|
|
|
135
|
+
@Cache(CACHE_TIMEOUT)
|
|
137
136
|
public async getDepositPlyAPY(): Promise<BigNumber> {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
this.getTotalTokenDeposited().then((res: TokenAmount) => {
|
|
145
|
-
totalDeposited = res;
|
|
146
|
-
})
|
|
147
|
-
);
|
|
148
|
-
promises.push(
|
|
149
|
-
this.env.comptroller
|
|
150
|
-
.rewardSpeeds(ComptrollerRewardType.PLY, this.auToken.address, true)
|
|
151
|
-
.then((res) => {
|
|
152
|
-
rewardSpeed = new TokenAmount(PLYToken, res.toString());
|
|
153
|
-
})
|
|
154
|
-
);
|
|
155
|
-
promises.push(
|
|
156
|
-
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
157
|
-
(res) => {
|
|
158
|
-
plyPrice = res;
|
|
159
|
-
}
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
promises.push(
|
|
163
|
-
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
164
|
-
underlyingPrice = res;
|
|
165
|
-
})
|
|
166
|
-
);
|
|
167
|
-
await Promise.all(promises);
|
|
137
|
+
const [totalDeposited, rewardSpeeds, plyPrice, underlyingPrice] = await Promise.all([
|
|
138
|
+
this.getTotalTokenDeposited(),
|
|
139
|
+
this.getRewardSpeeds(),
|
|
140
|
+
this.getPlyPrice(),
|
|
141
|
+
this.getUnderlyingPrice(),
|
|
142
|
+
]);
|
|
168
143
|
return helpers.calcLMRewardApr(
|
|
169
|
-
plyPrice!.multipliedBy(rewardSpeed!.formattedAmount()),
|
|
170
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
171
|
-
consts.ONE_YEAR
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
175
|
-
var promises = [],
|
|
176
|
-
totalDeposited: TokenAmount,
|
|
177
|
-
totalBorrowed: TokenAmount,
|
|
178
|
-
depositAPY: number,
|
|
179
|
-
borrowAPY: number,
|
|
180
|
-
collateralRatio: number;
|
|
181
|
-
promises.push(
|
|
182
|
-
this.getTotalTokenDeposited().then((res: TokenAmount) => {
|
|
183
|
-
totalDeposited = res;
|
|
184
|
-
})
|
|
185
|
-
);
|
|
186
|
-
promises.push(
|
|
187
|
-
this.getTotalTokenBorrowed().then((res: TokenAmount) => {
|
|
188
|
-
totalBorrowed = res;
|
|
189
|
-
})
|
|
190
|
-
);
|
|
191
|
-
promises.push(
|
|
192
|
-
this.getDepositAPY().then((res: BigNumber) => {
|
|
193
|
-
depositAPY = res.toNumber();
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
promises.push(
|
|
197
|
-
this.getBorrowAPY().then((res: BigNumber) => {
|
|
198
|
-
borrowAPY = res.toNumber();
|
|
199
|
-
})
|
|
200
|
-
);
|
|
201
|
-
promises.push(
|
|
202
|
-
this.getCollateralRatio().then((res: BigNumber) => {
|
|
203
|
-
collateralRatio = res.toNumber();
|
|
204
|
-
})
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
var plyPrice: BigNumber, underlyingPrice: BigNumber, rewardSpeeds: RewardSpeeds;
|
|
208
|
-
promises.push(
|
|
209
|
-
this.getRewardSpeeds().then((res) => {
|
|
210
|
-
rewardSpeeds = res;
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
promises.push(
|
|
214
|
-
fetchPrice(consts.networkAddresses.tokens.PLY, this._networkConnection.provider).then(
|
|
215
|
-
(res) => {
|
|
216
|
-
plyPrice = res;
|
|
217
|
-
}
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
promises.push(
|
|
221
|
-
fetchPrice(this.underlying.address, this._networkConnection.provider).then((res) => {
|
|
222
|
-
underlyingPrice = res;
|
|
223
|
-
})
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
await Promise.all(promises);
|
|
227
|
-
|
|
228
|
-
var borrowPlyApy = helpers.calcLMRewardApr(
|
|
229
144
|
calcValuation(
|
|
230
|
-
new TokenAmount(PLYToken, rewardSpeeds
|
|
231
|
-
plyPrice
|
|
145
|
+
new TokenAmount(PLYToken, rewardSpeeds.plyRewardSupplySpeed.toString()),
|
|
146
|
+
plyPrice
|
|
232
147
|
),
|
|
233
|
-
underlyingPrice
|
|
234
|
-
consts.ONE_YEAR
|
|
235
|
-
);
|
|
236
|
-
var depositPlyApy = helpers.calcLMRewardApr(
|
|
237
|
-
calcValuation(
|
|
238
|
-
new TokenAmount(PLYToken, rewardSpeeds!.plyRewardSupplySpeed.toString()),
|
|
239
|
-
plyPrice!
|
|
240
|
-
),
|
|
241
|
-
underlyingPrice!.multipliedBy(totalDeposited!.formattedAmount()),
|
|
148
|
+
underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
|
|
242
149
|
consts.ONE_YEAR
|
|
243
150
|
);
|
|
151
|
+
}
|
|
244
152
|
|
|
245
|
-
|
|
153
|
+
@Cache(CACHE_TIMEOUT)
|
|
154
|
+
public async getDepositNearAPY(): Promise<BigNumber> {
|
|
155
|
+
const [totalDeposited, underlyingPrice] = await Promise.all([
|
|
156
|
+
this.getTotalTokenDeposited(),
|
|
157
|
+
this.getUnderlyingPrice(),
|
|
158
|
+
]);
|
|
159
|
+
let depositNEARApy = helpers.calcLMRewardApr(
|
|
246
160
|
await fetchValuation(this.getDepositNEARRewardPerWeek(), this._networkConnection.provider),
|
|
247
|
-
underlyingPrice
|
|
161
|
+
underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
|
|
248
162
|
52
|
|
249
163
|
);
|
|
250
|
-
|
|
164
|
+
return depositNEARApy;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@Cache(CACHE_TIMEOUT)
|
|
168
|
+
public async getBorrowNearAPY(): Promise<BigNumber> {
|
|
169
|
+
const [totalBorrowed, underlyingPrice] = await Promise.all([
|
|
170
|
+
this.getTotalTokenBorrowed(),
|
|
171
|
+
this.getUnderlyingPrice(),
|
|
172
|
+
]);
|
|
173
|
+
let borrowNEARApy = helpers.calcLMRewardApr(
|
|
251
174
|
await fetchValuation(this.getBorrowNEARRewardPerWeek(), this._networkConnection.provider),
|
|
252
|
-
underlyingPrice
|
|
175
|
+
underlyingPrice.multipliedBy(totalBorrowed.formattedAmount()),
|
|
253
176
|
52
|
|
254
177
|
);
|
|
255
|
-
|
|
178
|
+
return borrowNEARApy;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@Cache(CACHE_TIMEOUT)
|
|
182
|
+
public async getDepositMetaAPY(): Promise<BigNumber> {
|
|
183
|
+
const [totalDeposited, underlyingPrice] = await Promise.all([
|
|
184
|
+
this.getTotalTokenDeposited(),
|
|
185
|
+
fetchPrice(this.underlying.address, this._networkConnection.provider),
|
|
186
|
+
]);
|
|
187
|
+
let depositMETAApy;
|
|
256
188
|
if (helpers.isSameAddress(this.underlying.address, consts.networkAddresses.tokens.stNEAR)) {
|
|
257
189
|
depositMETAApy = helpers.calcLMRewardApr(
|
|
258
190
|
await fetchValuation(
|
|
259
191
|
TokenAmount.fromAddressAndAmount(consts.networkAddresses.tokens.META, '1250000', false),
|
|
260
192
|
this._networkConnection.provider
|
|
261
193
|
),
|
|
262
|
-
underlyingPrice
|
|
194
|
+
underlyingPrice.multipliedBy(totalDeposited.formattedAmount()),
|
|
263
195
|
12
|
|
264
196
|
);
|
|
265
197
|
} else {
|
|
266
198
|
depositMETAApy = new BigNumber(0);
|
|
267
199
|
}
|
|
200
|
+
return depositMETAApy;
|
|
201
|
+
}
|
|
268
202
|
|
|
203
|
+
public async getDetails(): Promise<MoneyMarketDetails> {
|
|
204
|
+
const [totalDeposited, totalBorrowed, depositAPY, borrowAPY, collateralRatio, rewardSpeeds] =
|
|
205
|
+
await Promise.all([
|
|
206
|
+
this.getTotalTokenDeposited(),
|
|
207
|
+
this.getTotalTokenBorrowed(),
|
|
208
|
+
this.getDepositAPY(),
|
|
209
|
+
this.getBorrowAPY(),
|
|
210
|
+
this.getCollateralRatio(),
|
|
211
|
+
this.getRewardSpeeds(),
|
|
212
|
+
]);
|
|
213
|
+
const [depositPlyAPY, borrowPlyAPY, depositNearAPY, borrowNearAPY, depositMetaAPY] =
|
|
214
|
+
await Promise.all([
|
|
215
|
+
this.getDepositPlyAPY(),
|
|
216
|
+
this.getBorrowPlyAPY(),
|
|
217
|
+
this.getDepositNearAPY(),
|
|
218
|
+
this.getBorrowNearAPY(),
|
|
219
|
+
this.getDepositMetaAPY(),
|
|
220
|
+
]);
|
|
269
221
|
return {
|
|
270
222
|
auTokenAddress: this.auToken.address,
|
|
271
|
-
totalTokenDeposited: totalDeposited
|
|
272
|
-
totalTokenBorrowed: totalBorrowed
|
|
273
|
-
depositApy: depositAPY
|
|
274
|
-
depositPlyApy:
|
|
275
|
-
borrowApy: borrowAPY
|
|
276
|
-
borrowPlyApy:
|
|
277
|
-
collateralRatio: collateralRatio
|
|
223
|
+
totalTokenDeposited: totalDeposited,
|
|
224
|
+
totalTokenBorrowed: totalBorrowed,
|
|
225
|
+
depositApy: depositAPY.toNumber(),
|
|
226
|
+
depositPlyApy: depositPlyAPY.toNumber(),
|
|
227
|
+
borrowApy: borrowAPY.toNumber(),
|
|
228
|
+
borrowPlyApy: borrowPlyAPY.toNumber() * -1,
|
|
229
|
+
collateralRatio: collateralRatio.toNumber(),
|
|
278
230
|
depositPlyPerWeek: new TokenAmount(
|
|
279
231
|
PLYToken,
|
|
280
|
-
rewardSpeeds
|
|
232
|
+
rewardSpeeds.plyRewardSupplySpeed.mul(consts.ONE_DAY).mul(7).toString()
|
|
281
233
|
),
|
|
282
234
|
borrowPlyPerWeek: new TokenAmount(
|
|
283
235
|
PLYToken,
|
|
284
|
-
rewardSpeeds
|
|
236
|
+
rewardSpeeds.plyRewardBorrowSpeed.mul(consts.ONE_DAY).mul(7).toString()
|
|
285
237
|
),
|
|
286
|
-
depositNEARApy:
|
|
287
|
-
borrowNEARApy:
|
|
288
|
-
depositMETAApy:
|
|
238
|
+
depositNEARApy: depositNearAPY.toNumber(),
|
|
239
|
+
borrowNEARApy: borrowNearAPY.toNumber() * -1,
|
|
240
|
+
depositMETAApy: depositMetaAPY.toNumber(),
|
|
289
241
|
};
|
|
290
242
|
}
|
|
291
243
|
|
|
@@ -344,6 +296,63 @@ export class MoneyMarketRead extends BlockchainEntityRead {
|
|
|
344
296
|
(await this.env.comptroller.borrowCaps(this.auToken.address)).toString()
|
|
345
297
|
);
|
|
346
298
|
}
|
|
299
|
+
|
|
300
|
+
public async getApyWithoutIncentive(userAddress: Address): Promise<Apy> {
|
|
301
|
+
const [price, depositApy, borrowApy, depositBalance, borrowBalance] = await Promise.all([
|
|
302
|
+
this.getUnderlyingPrice(),
|
|
303
|
+
this.getDepositAPY(),
|
|
304
|
+
this.getBorrowAPY(),
|
|
305
|
+
this.getUserDepositBalance(userAddress),
|
|
306
|
+
this.getUserBorrowBalance(userAddress),
|
|
307
|
+
]);
|
|
308
|
+
const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
|
|
309
|
+
const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
|
|
310
|
+
const sum = helpers.calcNetApy(suppliedValue, depositApy, borrowedValue, borrowApy);
|
|
311
|
+
return {
|
|
312
|
+
sum,
|
|
313
|
+
suppliedValue,
|
|
314
|
+
borrowedValue,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
public async getApyWithIncentive(userAddress: Address): Promise<Apy> {
|
|
319
|
+
const [
|
|
320
|
+
price,
|
|
321
|
+
depositApy,
|
|
322
|
+
borrowApy,
|
|
323
|
+
depositBalance,
|
|
324
|
+
borrowBalance,
|
|
325
|
+
nearDepositApy,
|
|
326
|
+
plyDepositApy,
|
|
327
|
+
metaDepositApy,
|
|
328
|
+
nearBorrowApy,
|
|
329
|
+
plyBorrowApy,
|
|
330
|
+
] = await Promise.all([
|
|
331
|
+
this.getUnderlyingPrice(),
|
|
332
|
+
this.getDepositAPY(),
|
|
333
|
+
this.getBorrowAPY(),
|
|
334
|
+
this.getUserDepositBalance(userAddress),
|
|
335
|
+
this.getUserBorrowBalance(userAddress),
|
|
336
|
+
this.getDepositNearAPY(),
|
|
337
|
+
this.getDepositPlyAPY(),
|
|
338
|
+
this.getDepositMetaAPY(),
|
|
339
|
+
this.getBorrowNearAPY(),
|
|
340
|
+
this.getBorrowPlyAPY(),
|
|
341
|
+
]);
|
|
342
|
+
const suppliedValue = price.multipliedBy(depositBalance.formattedAmount());
|
|
343
|
+
const borrowedValue = price.multipliedBy(borrowBalance.formattedAmount());
|
|
344
|
+
const totalDepositApy = depositApy
|
|
345
|
+
.plus(nearDepositApy)
|
|
346
|
+
.plus(plyDepositApy)
|
|
347
|
+
.plus(metaDepositApy);
|
|
348
|
+
const totalBorrowApy = borrowApy.plus(nearBorrowApy).plus(plyBorrowApy);
|
|
349
|
+
const sum = helpers.calcNetApy(suppliedValue, totalDepositApy, borrowedValue, totalBorrowApy);
|
|
350
|
+
return {
|
|
351
|
+
sum,
|
|
352
|
+
suppliedValue,
|
|
353
|
+
borrowedValue,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
347
356
|
}
|
|
348
357
|
|
|
349
358
|
export class MoneyMarketReadWrite extends MoneyMarketRead {
|
|
@@ -58,17 +58,12 @@ export class PapermillRead extends BlockchainEntityRead {
|
|
|
58
58
|
*/
|
|
59
59
|
public async getLockingDetails(userAddress: Address): Promise<UserLockingDetails> {
|
|
60
60
|
const currentWeek = this.getWeek(helpers.getCurrentTimestamp());
|
|
61
|
-
var promises: any[] = [];
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
promises.push(this.getUnclaimedPlyReward(userAddress));
|
|
70
|
-
|
|
71
|
-
var values: any[] = await Promise.all(promises);
|
|
62
|
+
const values = await Promise.all([
|
|
63
|
+
this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek),
|
|
64
|
+
this.env.auriLens.getPercentLock(this.env.pulp.address, userAddress, currentWeek + 1),
|
|
65
|
+
this.getUnclaimedPlyReward(userAddress),
|
|
66
|
+
]);
|
|
72
67
|
|
|
73
68
|
let percentLockCurrentWeek = BN.from(values[0]);
|
|
74
69
|
let percentLockNextWeek = BN.from(values[1]);
|