@aurigami/sdk 1.12.9 → 1.13.0
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/PlyGame.d.ts +0 -1
- package/dist/interactors/misc.d.ts +2 -0
- package/dist/sdk.cjs.development.js +809 -425
- 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 +807 -426
- 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/PlyGame.ts +1 -10
- package/src/interactors/misc.ts +82 -32
- package/src/types/index.ts +6 -0
package/src/interactors/misc.ts
CHANGED
|
@@ -25,9 +25,7 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
25
25
|
const marketCount = consts.networkAddresses.auTokens.length;
|
|
26
26
|
var userMarketDetails: types.UserMarketDetails[] = [],
|
|
27
27
|
assetsIn: string[];
|
|
28
|
-
var promises = [];
|
|
29
28
|
var totalBorrowLimit = new BigNumber(0);
|
|
30
|
-
var pricePromises = [];
|
|
31
29
|
for (const auToken of consts.networkAddresses.auTokens) {
|
|
32
30
|
const userMarketDetail: types.UserMarketDetails = {} as types.UserMarketDetails;
|
|
33
31
|
userMarketDetails.push(userMarketDetail);
|
|
@@ -37,37 +35,21 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
37
35
|
auToken.address,
|
|
38
36
|
auToken.underlying
|
|
39
37
|
);
|
|
40
|
-
|
|
41
|
-
moneyMarket.getUserDepositBalance(userAddress)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
moneyMarket.getCollateralRatio().then((res: BigNumber) => {
|
|
52
|
-
userMarketDetail.collateralRatio = res.toNumber();
|
|
53
|
-
})
|
|
54
|
-
);
|
|
55
|
-
pricePromises.push(
|
|
56
|
-
fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider).then((res) => {
|
|
57
|
-
userMarketDetail.underlyingPrice = res.toString();
|
|
58
|
-
return res;
|
|
59
|
-
})
|
|
60
|
-
);
|
|
38
|
+
const [depositBalance, borrowBalance, collateralRatio, underlyingPrice] = await Promise.all([
|
|
39
|
+
moneyMarket.getUserDepositBalance(userAddress),
|
|
40
|
+
moneyMarket.getUserBorrowBalance(userAddress),
|
|
41
|
+
moneyMarket.getCollateralRatio(),
|
|
42
|
+
fetchPrice(moneyMarket.underlying.address, this._networkConnection.provider),
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
userMarketDetail.depositBalance = depositBalance;
|
|
46
|
+
userMarketDetail.borrowBalance = borrowBalance;
|
|
47
|
+
userMarketDetail.collateralRatio = collateralRatio.toNumber();
|
|
48
|
+
userMarketDetail.underlyingPrice = underlyingPrice.toString();
|
|
61
49
|
}
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
this.env.comptroller.getAssetsIn(userAddress).then((res: string[]) => {
|
|
65
|
-
assetsIn = res;
|
|
66
|
-
})
|
|
67
|
-
);
|
|
51
|
+
assetsIn = await this.env.comptroller.getAssetsIn(userAddress);
|
|
68
52
|
|
|
69
|
-
await Promise.all(promises);
|
|
70
|
-
var underlyingPrices = await Promise.all(pricePromises);
|
|
71
53
|
var depositValues = [];
|
|
72
54
|
for (var i = 0; i < marketCount; i++) {
|
|
73
55
|
const auToken = consts.networkAddresses.auTokens[i];
|
|
@@ -79,7 +61,12 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
79
61
|
} else {
|
|
80
62
|
userMarketDetails[i].isCollateral = false;
|
|
81
63
|
}
|
|
82
|
-
depositValues.push(
|
|
64
|
+
depositValues.push(
|
|
65
|
+
calcValuation(
|
|
66
|
+
userMarketDetails[i].depositBalance,
|
|
67
|
+
new BigNumber(userMarketDetails[i].underlyingPrice)
|
|
68
|
+
)
|
|
69
|
+
);
|
|
83
70
|
}
|
|
84
71
|
|
|
85
72
|
totalBorrowLimit = depositValues.reduce((p: BigNumber, v: BigNumber, index: number) => {
|
|
@@ -123,7 +110,7 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
123
110
|
: new BigNumber(0);
|
|
124
111
|
const maxWithdrawCap: BigNumber = borrowLimitMargin
|
|
125
112
|
.div(userMarketDetails[i].collateralRatio)
|
|
126
|
-
.div(
|
|
113
|
+
.div(userMarketDetails[i].underlyingPrice);
|
|
127
114
|
userMarketDetails[i].maxWithdrawableAmount =
|
|
128
115
|
userMarketDetails[i].isCollateral &&
|
|
129
116
|
maxWithdrawCap.lt(userMarketDetails[i].depositBalance.formattedAmount())
|
|
@@ -320,4 +307,67 @@ export class MiscRead extends BlockchainEntityRead {
|
|
|
320
307
|
}
|
|
321
308
|
return res;
|
|
322
309
|
}
|
|
310
|
+
|
|
311
|
+
public async getNetApyWithoutIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
312
|
+
let sum = new BigNumber(0);
|
|
313
|
+
let totalSuppliedValue = new BigNumber(0);
|
|
314
|
+
let totalBorrowedValue = new BigNumber(0);
|
|
315
|
+
let netApy = new BigNumber(0);
|
|
316
|
+
|
|
317
|
+
const apys = await Promise.all(
|
|
318
|
+
consts.networkAddresses.auTokens.map((auToken) => {
|
|
319
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
320
|
+
this._networkConnection,
|
|
321
|
+
auToken.address,
|
|
322
|
+
auToken.underlying
|
|
323
|
+
);
|
|
324
|
+
const apyWithoutIncentive = moneyMarket.getApyWithoutIncentive(userAddress);
|
|
325
|
+
return apyWithoutIncentive;
|
|
326
|
+
})
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
for (const apy of apys) {
|
|
330
|
+
sum = sum.plus(apy.sum);
|
|
331
|
+
totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
|
|
332
|
+
totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (sum.gt(0)) {
|
|
336
|
+
netApy = sum.div(totalSuppliedValue);
|
|
337
|
+
} else if (sum.lt(0)) {
|
|
338
|
+
netApy = sum.div(totalBorrowedValue);
|
|
339
|
+
}
|
|
340
|
+
return netApy;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
public async getNetApyWithIncentive(userAddress: types.Address): Promise<BigNumber> {
|
|
344
|
+
let sum = new BigNumber(0);
|
|
345
|
+
let totalSuppliedValue = new BigNumber(0);
|
|
346
|
+
let totalBorrowedValue = new BigNumber(0);
|
|
347
|
+
let netApy = new BigNumber(0);
|
|
348
|
+
const apys = await Promise.all(
|
|
349
|
+
consts.networkAddresses.auTokens.map((auToken) => {
|
|
350
|
+
const moneyMarket: MoneyMarketRead = new MoneyMarketRead(
|
|
351
|
+
this._networkConnection,
|
|
352
|
+
auToken.address,
|
|
353
|
+
auToken.underlying
|
|
354
|
+
);
|
|
355
|
+
const apyWithIncentive = moneyMarket.getApyWithIncentive(userAddress);
|
|
356
|
+
return apyWithIncentive;
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
for (const apy of apys) {
|
|
361
|
+
sum = sum.plus(apy.sum);
|
|
362
|
+
totalSuppliedValue = totalSuppliedValue.plus(apy.suppliedValue);
|
|
363
|
+
totalBorrowedValue = totalBorrowedValue.plus(apy.borrowedValue);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (sum.gt(0)) {
|
|
367
|
+
netApy = sum.div(totalSuppliedValue);
|
|
368
|
+
} else if (sum.lt(0)) {
|
|
369
|
+
netApy = sum.div(totalBorrowedValue);
|
|
370
|
+
}
|
|
371
|
+
return netApy;
|
|
372
|
+
}
|
|
323
373
|
}
|
package/src/types/index.ts
CHANGED
|
@@ -183,3 +183,9 @@ export type PlyGameLeaderboardItem = {
|
|
|
183
183
|
export type PlyBetMadeEvent = TypedEvent<
|
|
184
184
|
[string, BN, number] & { player: string; amount: BN; outcome: number }
|
|
185
185
|
>;
|
|
186
|
+
|
|
187
|
+
export type Apy = {
|
|
188
|
+
sum: BigNumber;
|
|
189
|
+
suppliedValue: BigNumber;
|
|
190
|
+
borrowedValue: BigNumber;
|
|
191
|
+
};
|