@aurigami/sdk 0.4.2 → 0.4.4
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 +4 -3
- package/dist/constants.d.ts +1 -1
- package/dist/priceFetcher.d.ts +2 -1
- package/dist/sdk.cjs.development.js +64 -35
- 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 +67 -38
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/MoneyMarket.ts +3 -5
- package/src/SDK.ts +40 -11
- package/src/constants.ts +1 -1
- package/src/priceFetcher.ts +7 -5
- package/src/types.ts +8 -0
package/dist/SDK.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import { LockingDetails, PlyAuroraPoolDetails, NetworkConnection, UserDetails, UserMarketDetails, CurrencyAmount, HypotheticalStats } from './types';
|
|
2
|
+
import { LockingDetails, PlyAuroraPoolDetails, NetworkConnection, UserDetails, UserMarketDetails, CurrencyAmount, HypotheticalStats, MarketAction } from './types';
|
|
3
3
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
4
4
|
import { Contract } from 'ethers';
|
|
5
5
|
import { AuriFairLaunch, Comptroller, TokenLock } from '@aurigami/contracts/typechain';
|
|
@@ -16,11 +16,12 @@ export declare class SdkRead extends BlockchainEntityRead {
|
|
|
16
16
|
getPlyAuroraPoolDetails(): Promise<PlyAuroraPoolDetails>;
|
|
17
17
|
getTokenPrice(token: Token): Promise<CurrencyAmount>;
|
|
18
18
|
stakeBalanceOf(user: string): Promise<TokenAmount>;
|
|
19
|
-
calcHypotheticalStats(
|
|
19
|
+
calcHypotheticalStats({ userMarketDetail, currentBorrowLimit, currentBorrowValuation, action, tokenAmount }: {
|
|
20
20
|
userMarketDetail: UserMarketDetails;
|
|
21
21
|
currentBorrowLimit: CurrencyAmount;
|
|
22
22
|
currentBorrowValuation: CurrencyAmount;
|
|
23
|
-
|
|
23
|
+
action: MarketAction;
|
|
24
|
+
tokenAmount?: TokenAmount;
|
|
24
25
|
}): HypotheticalStats;
|
|
25
26
|
}
|
|
26
27
|
export declare class SdkReadWrite extends SdkRead {
|
package/dist/constants.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
|
|
|
2
2
|
export declare const dummyAddress: string;
|
|
3
3
|
export declare const ETHAddress: string;
|
|
4
4
|
export declare const AURORA_CHAINID = 1313161554;
|
|
5
|
-
export declare const DECIMAL_PRECISION =
|
|
5
|
+
export declare const DECIMAL_PRECISION = 10;
|
|
6
6
|
export declare type NetworkAddresses = {
|
|
7
7
|
auTokens: {
|
|
8
8
|
address: string;
|
package/dist/priceFetcher.d.ts
CHANGED
|
@@ -18,4 +18,5 @@ export declare function fetchUnderlyingTokensPrices(provider: providers.Provider
|
|
|
18
18
|
underlyingPrice: BigNumber;
|
|
19
19
|
}[]>;
|
|
20
20
|
export declare function fetchPrice(address: Address, provider: providers.Provider): Promise<BigNumber>;
|
|
21
|
-
export declare function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider
|
|
21
|
+
export declare function fetchValuation(tokenAmount: TokenAmount, provider: providers.Provider): Promise<BigNumber>;
|
|
22
|
+
export declare function calcValuation(tokenAmount: TokenAmount, price: BigNumber): BigNumber;
|
|
@@ -897,10 +897,24 @@ var BlockchainEntity = /*#__PURE__*/function () {
|
|
|
897
897
|
return BlockchainEntity;
|
|
898
898
|
}();
|
|
899
899
|
|
|
900
|
+
(function (ComptrollerRewardType) {
|
|
901
|
+
ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
|
|
902
|
+
ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
|
|
903
|
+
})(exports.ComptrollerRewardType || (exports.ComptrollerRewardType = {}));
|
|
904
|
+
|
|
905
|
+
(function (MarketAction) {
|
|
906
|
+
MarketAction[MarketAction["Deposit"] = 0] = "Deposit";
|
|
907
|
+
MarketAction[MarketAction["Borrow"] = 1] = "Borrow";
|
|
908
|
+
MarketAction[MarketAction["Withdraw"] = 2] = "Withdraw";
|
|
909
|
+
MarketAction[MarketAction["Repay"] = 3] = "Repay";
|
|
910
|
+
MarketAction[MarketAction["EnableCollateral"] = 4] = "EnableCollateral";
|
|
911
|
+
MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
|
|
912
|
+
})(exports.MarketAction || (exports.MarketAction = {}));
|
|
913
|
+
|
|
900
914
|
var dummyAddress = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
901
915
|
var ETHAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
902
916
|
var AURORA_CHAINID = 1313161554;
|
|
903
|
-
var DECIMAL_PRECISION =
|
|
917
|
+
var DECIMAL_PRECISION = 10;
|
|
904
918
|
var networkAddresses = {
|
|
905
919
|
auTokens: [{
|
|
906
920
|
address: /*#__PURE__*/'0x2dEf6eb801757655AD227110d65C80DB595bBc60'.toLowerCase(),
|
|
@@ -1013,11 +1027,6 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
|
|
|
1013
1027
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
1014
1028
|
}
|
|
1015
1029
|
|
|
1016
|
-
(function (ComptrollerRewardType) {
|
|
1017
|
-
ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
|
|
1018
|
-
ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
|
|
1019
|
-
})(exports.ComptrollerRewardType || (exports.ComptrollerRewardType = {}));
|
|
1020
|
-
|
|
1021
1030
|
var Token = function Token(address, decimals) {
|
|
1022
1031
|
this.address = address.toLowerCase();
|
|
1023
1032
|
this.decimals = decimals;
|
|
@@ -2271,31 +2280,25 @@ function _fetchPrice() {
|
|
|
2271
2280
|
return _fetchPrice.apply(this, arguments);
|
|
2272
2281
|
}
|
|
2273
2282
|
|
|
2274
|
-
function fetchValuation(_x13, _x14
|
|
2283
|
+
function fetchValuation(_x13, _x14) {
|
|
2275
2284
|
return _fetchValuation.apply(this, arguments);
|
|
2276
2285
|
}
|
|
2277
2286
|
|
|
2278
2287
|
function _fetchValuation() {
|
|
2279
|
-
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider
|
|
2288
|
+
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider) {
|
|
2289
|
+
var price;
|
|
2280
2290
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
2281
2291
|
while (1) {
|
|
2282
2292
|
switch (_context8.prev = _context8.next) {
|
|
2283
2293
|
case 0:
|
|
2284
|
-
|
|
2285
|
-
_context8.next = 4;
|
|
2286
|
-
break;
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
_context8.next = 3;
|
|
2294
|
+
_context8.next = 2;
|
|
2290
2295
|
return fetchPrice(tokenAmount.token.address, provider);
|
|
2291
2296
|
|
|
2292
|
-
case
|
|
2297
|
+
case 2:
|
|
2293
2298
|
price = _context8.sent;
|
|
2299
|
+
return _context8.abrupt("return", calcValuation(tokenAmount, price));
|
|
2294
2300
|
|
|
2295
2301
|
case 4:
|
|
2296
|
-
return _context8.abrupt("return", new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price));
|
|
2297
|
-
|
|
2298
|
-
case 5:
|
|
2299
2302
|
case "end":
|
|
2300
2303
|
return _context8.stop();
|
|
2301
2304
|
}
|
|
@@ -2305,6 +2308,10 @@ function _fetchValuation() {
|
|
|
2305
2308
|
return _fetchValuation.apply(this, arguments);
|
|
2306
2309
|
}
|
|
2307
2310
|
|
|
2311
|
+
function calcValuation(tokenAmount, price) {
|
|
2312
|
+
return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2308
2315
|
var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
2309
2316
|
_inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
|
|
2310
2317
|
|
|
@@ -2626,7 +2633,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2626
2633
|
case 11:
|
|
2627
2634
|
_context9.t0 = calcLMRewardApr;
|
|
2628
2635
|
_context9.next = 14;
|
|
2629
|
-
return
|
|
2636
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardBorrowSpeed.toString()), plyPrice);
|
|
2630
2637
|
|
|
2631
2638
|
case 14:
|
|
2632
2639
|
_context9.t1 = _context9.sent;
|
|
@@ -2635,7 +2642,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2635
2642
|
borrowPlyApy = (0, _context9.t0)(_context9.t1, _context9.t2, _context9.t3);
|
|
2636
2643
|
_context9.t4 = calcLMRewardApr;
|
|
2637
2644
|
_context9.next = 21;
|
|
2638
|
-
return
|
|
2645
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardSupplySpeed.toString()), plyPrice);
|
|
2639
2646
|
|
|
2640
2647
|
case 21:
|
|
2641
2648
|
_context9.t5 = _context9.sent;
|
|
@@ -2987,7 +2994,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2987
2994
|
var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
|
|
2988
2995
|
var _this2 = this;
|
|
2989
2996
|
|
|
2990
|
-
var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices,
|
|
2997
|
+
var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices, depositValues, _loop, i, accountLiquidity, rewardBalancesMetadata, lockedAmount, values, borrowedvaluation, bufferedBorrowLimit, minimumBorrowLimitAllowed, borrowableAmount, auToken, moneyMarket, maxWithdrawCap;
|
|
2991
2998
|
|
|
2992
2999
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2993
3000
|
while (1) {
|
|
@@ -3036,7 +3043,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3036
3043
|
|
|
3037
3044
|
case 12:
|
|
3038
3045
|
underlyingPrices = _context2.sent;
|
|
3039
|
-
|
|
3046
|
+
depositValues = [];
|
|
3040
3047
|
|
|
3041
3048
|
_loop = function _loop() {
|
|
3042
3049
|
var auToken = networkAddresses.auTokens[i];
|
|
@@ -3049,18 +3056,13 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3049
3056
|
userMarketDetails[i].isCollateral = false;
|
|
3050
3057
|
}
|
|
3051
3058
|
|
|
3052
|
-
|
|
3059
|
+
depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
|
|
3053
3060
|
};
|
|
3054
3061
|
|
|
3055
3062
|
for (i = 0; i < marketCount; i++) {
|
|
3056
3063
|
_loop();
|
|
3057
3064
|
}
|
|
3058
3065
|
|
|
3059
|
-
_context2.next = 18;
|
|
3060
|
-
return Promise.all(depositValuationPromises);
|
|
3061
|
-
|
|
3062
|
-
case 18:
|
|
3063
|
-
depositValues = _context2.sent;
|
|
3064
3066
|
totalBorrowLimit = depositValues.reduce(function (p, v, index) {
|
|
3065
3067
|
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
3066
3068
|
return p;
|
|
@@ -3069,10 +3071,10 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3069
3071
|
promises.push(this._comptroller.getAccountLiquidity(userAddress));
|
|
3070
3072
|
promises.push(this._auriLens.callStatic.getRewardBalancesMetadata(this._comptroller.address, this._auriFairLaunch.address, userAddress, [AurPlyPid]));
|
|
3071
3073
|
promises.push(this._tokenLock.lockedAmounts(userAddress));
|
|
3072
|
-
_context2.next =
|
|
3074
|
+
_context2.next = 23;
|
|
3073
3075
|
return Promise.all(promises);
|
|
3074
3076
|
|
|
3075
|
-
case
|
|
3077
|
+
case 23:
|
|
3076
3078
|
values = _context2.sent;
|
|
3077
3079
|
accountLiquidity = values[0];
|
|
3078
3080
|
rewardBalancesMetadata = values[1];
|
|
@@ -3113,7 +3115,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3113
3115
|
}
|
|
3114
3116
|
});
|
|
3115
3117
|
|
|
3116
|
-
case
|
|
3118
|
+
case 34:
|
|
3117
3119
|
case "end":
|
|
3118
3120
|
return _context2.stop();
|
|
3119
3121
|
}
|
|
@@ -3236,15 +3238,41 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3236
3238
|
return stakeBalanceOf;
|
|
3237
3239
|
}();
|
|
3238
3240
|
|
|
3239
|
-
_proto.calcHypotheticalStats = function calcHypotheticalStats(
|
|
3240
|
-
var
|
|
3241
|
-
|
|
3241
|
+
_proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
|
|
3242
|
+
var userMarketDetail = _ref.userMarketDetail,
|
|
3243
|
+
currentBorrowLimit = _ref.currentBorrowLimit,
|
|
3244
|
+
currentBorrowValuation = _ref.currentBorrowValuation,
|
|
3245
|
+
action = _ref.action,
|
|
3246
|
+
tokenAmount = _ref.tokenAmount;
|
|
3247
|
+
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
3248
|
+
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
3249
|
+
|
|
3250
|
+
switch (action) {
|
|
3251
|
+
case exports.MarketAction.EnableCollateral:
|
|
3252
|
+
case exports.MarketAction.DisableCollateral:
|
|
3253
|
+
var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
|
|
3254
|
+
newBorrowLimit = action == exports.MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
|
|
3255
|
+
break;
|
|
3256
|
+
|
|
3257
|
+
case exports.MarketAction.Deposit:
|
|
3258
|
+
case exports.MarketAction.Withdraw:
|
|
3259
|
+
deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
|
|
3260
|
+
newBorrowLimit = action == exports.MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
|
|
3261
|
+
break;
|
|
3262
|
+
|
|
3263
|
+
case exports.MarketAction.Borrow:
|
|
3264
|
+
case exports.MarketAction.Repay:
|
|
3265
|
+
var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
|
|
3266
|
+
newBorrowValuation = action == exports.MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
|
|
3267
|
+
break;
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3242
3270
|
return {
|
|
3243
3271
|
newBorrowLimit: {
|
|
3244
3272
|
amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
3245
3273
|
currency: "USD"
|
|
3246
3274
|
},
|
|
3247
|
-
newBorrowUtilization:
|
|
3275
|
+
newBorrowUtilization: newBorrowValuation.div(newBorrowLimit).toNumber()
|
|
3248
3276
|
};
|
|
3249
3277
|
};
|
|
3250
3278
|
|
|
@@ -3390,6 +3418,7 @@ exports.SdkReadWrite = SdkReadWrite;
|
|
|
3390
3418
|
exports.Token = Token;
|
|
3391
3419
|
exports.TokenAmount = TokenAmount;
|
|
3392
3420
|
exports.calcLMRewardApr = calcLMRewardApr;
|
|
3421
|
+
exports.calcValuation = calcValuation;
|
|
3393
3422
|
exports.decimalFactor = decimalFactor;
|
|
3394
3423
|
exports.dummyAddress = dummyAddress;
|
|
3395
3424
|
exports.dummyMarketAddress = dummyMarketAddress;
|