@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.esm.js
CHANGED
|
@@ -891,10 +891,27 @@ var BlockchainEntity = /*#__PURE__*/function () {
|
|
|
891
891
|
return BlockchainEntity;
|
|
892
892
|
}();
|
|
893
893
|
|
|
894
|
+
var ComptrollerRewardType;
|
|
895
|
+
|
|
896
|
+
(function (ComptrollerRewardType) {
|
|
897
|
+
ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
|
|
898
|
+
ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
|
|
899
|
+
})(ComptrollerRewardType || (ComptrollerRewardType = {}));
|
|
900
|
+
var MarketAction;
|
|
901
|
+
|
|
902
|
+
(function (MarketAction) {
|
|
903
|
+
MarketAction[MarketAction["Deposit"] = 0] = "Deposit";
|
|
904
|
+
MarketAction[MarketAction["Borrow"] = 1] = "Borrow";
|
|
905
|
+
MarketAction[MarketAction["Withdraw"] = 2] = "Withdraw";
|
|
906
|
+
MarketAction[MarketAction["Repay"] = 3] = "Repay";
|
|
907
|
+
MarketAction[MarketAction["EnableCollateral"] = 4] = "EnableCollateral";
|
|
908
|
+
MarketAction[MarketAction["DisableCollateral"] = 5] = "DisableCollateral";
|
|
909
|
+
})(MarketAction || (MarketAction = {}));
|
|
910
|
+
|
|
894
911
|
var dummyAddress = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
895
912
|
var ETHAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
896
913
|
var AURORA_CHAINID = 1313161554;
|
|
897
|
-
var DECIMAL_PRECISION =
|
|
914
|
+
var DECIMAL_PRECISION = 10;
|
|
898
915
|
var networkAddresses = {
|
|
899
916
|
auTokens: [{
|
|
900
917
|
address: /*#__PURE__*/'0x2dEf6eb801757655AD227110d65C80DB595bBc60'.toLowerCase(),
|
|
@@ -1007,13 +1024,6 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
|
|
|
1007
1024
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
1008
1025
|
}
|
|
1009
1026
|
|
|
1010
|
-
var ComptrollerRewardType;
|
|
1011
|
-
|
|
1012
|
-
(function (ComptrollerRewardType) {
|
|
1013
|
-
ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
|
|
1014
|
-
ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
|
|
1015
|
-
})(ComptrollerRewardType || (ComptrollerRewardType = {}));
|
|
1016
|
-
|
|
1017
1027
|
var Token = function Token(address, decimals) {
|
|
1018
1028
|
this.address = address.toLowerCase();
|
|
1019
1029
|
this.decimals = decimals;
|
|
@@ -2267,31 +2277,25 @@ function _fetchPrice() {
|
|
|
2267
2277
|
return _fetchPrice.apply(this, arguments);
|
|
2268
2278
|
}
|
|
2269
2279
|
|
|
2270
|
-
function fetchValuation(_x13, _x14
|
|
2280
|
+
function fetchValuation(_x13, _x14) {
|
|
2271
2281
|
return _fetchValuation.apply(this, arguments);
|
|
2272
2282
|
}
|
|
2273
2283
|
|
|
2274
2284
|
function _fetchValuation() {
|
|
2275
|
-
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider
|
|
2285
|
+
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider) {
|
|
2286
|
+
var price;
|
|
2276
2287
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
2277
2288
|
while (1) {
|
|
2278
2289
|
switch (_context8.prev = _context8.next) {
|
|
2279
2290
|
case 0:
|
|
2280
|
-
|
|
2281
|
-
_context8.next = 4;
|
|
2282
|
-
break;
|
|
2283
|
-
}
|
|
2284
|
-
|
|
2285
|
-
_context8.next = 3;
|
|
2291
|
+
_context8.next = 2;
|
|
2286
2292
|
return fetchPrice(tokenAmount.token.address, provider);
|
|
2287
2293
|
|
|
2288
|
-
case
|
|
2294
|
+
case 2:
|
|
2289
2295
|
price = _context8.sent;
|
|
2296
|
+
return _context8.abrupt("return", calcValuation(tokenAmount, price));
|
|
2290
2297
|
|
|
2291
2298
|
case 4:
|
|
2292
|
-
return _context8.abrupt("return", new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price));
|
|
2293
|
-
|
|
2294
|
-
case 5:
|
|
2295
2299
|
case "end":
|
|
2296
2300
|
return _context8.stop();
|
|
2297
2301
|
}
|
|
@@ -2301,6 +2305,10 @@ function _fetchValuation() {
|
|
|
2301
2305
|
return _fetchValuation.apply(this, arguments);
|
|
2302
2306
|
}
|
|
2303
2307
|
|
|
2308
|
+
function calcValuation(tokenAmount, price) {
|
|
2309
|
+
return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
|
|
2310
|
+
}
|
|
2311
|
+
|
|
2304
2312
|
var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
2305
2313
|
_inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
|
|
2306
2314
|
|
|
@@ -2622,7 +2630,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2622
2630
|
case 11:
|
|
2623
2631
|
_context9.t0 = calcLMRewardApr;
|
|
2624
2632
|
_context9.next = 14;
|
|
2625
|
-
return
|
|
2633
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardBorrowSpeed.toString()), plyPrice);
|
|
2626
2634
|
|
|
2627
2635
|
case 14:
|
|
2628
2636
|
_context9.t1 = _context9.sent;
|
|
@@ -2631,7 +2639,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2631
2639
|
borrowPlyApy = (0, _context9.t0)(_context9.t1, _context9.t2, _context9.t3);
|
|
2632
2640
|
_context9.t4 = calcLMRewardApr;
|
|
2633
2641
|
_context9.next = 21;
|
|
2634
|
-
return
|
|
2642
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardSupplySpeed.toString()), plyPrice);
|
|
2635
2643
|
|
|
2636
2644
|
case 21:
|
|
2637
2645
|
_context9.t5 = _context9.sent;
|
|
@@ -2983,7 +2991,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2983
2991
|
var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
|
|
2984
2992
|
var _this2 = this;
|
|
2985
2993
|
|
|
2986
|
-
var marketCount, userMarketDetails, assetsIn, promises, totalBorrowLimit, pricePromises, _loop2, _iterator, _step, underlyingPrices,
|
|
2994
|
+
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;
|
|
2987
2995
|
|
|
2988
2996
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
2989
2997
|
while (1) {
|
|
@@ -3032,7 +3040,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3032
3040
|
|
|
3033
3041
|
case 12:
|
|
3034
3042
|
underlyingPrices = _context2.sent;
|
|
3035
|
-
|
|
3043
|
+
depositValues = [];
|
|
3036
3044
|
|
|
3037
3045
|
_loop = function _loop() {
|
|
3038
3046
|
var auToken = networkAddresses.auTokens[i];
|
|
@@ -3045,18 +3053,13 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3045
3053
|
userMarketDetails[i].isCollateral = false;
|
|
3046
3054
|
}
|
|
3047
3055
|
|
|
3048
|
-
|
|
3056
|
+
depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
|
|
3049
3057
|
};
|
|
3050
3058
|
|
|
3051
3059
|
for (i = 0; i < marketCount; i++) {
|
|
3052
3060
|
_loop();
|
|
3053
3061
|
}
|
|
3054
3062
|
|
|
3055
|
-
_context2.next = 18;
|
|
3056
|
-
return Promise.all(depositValuationPromises);
|
|
3057
|
-
|
|
3058
|
-
case 18:
|
|
3059
|
-
depositValues = _context2.sent;
|
|
3060
3063
|
totalBorrowLimit = depositValues.reduce(function (p, v, index) {
|
|
3061
3064
|
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
3062
3065
|
return p;
|
|
@@ -3065,10 +3068,10 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3065
3068
|
promises.push(this._comptroller.getAccountLiquidity(userAddress));
|
|
3066
3069
|
promises.push(this._auriLens.callStatic.getRewardBalancesMetadata(this._comptroller.address, this._auriFairLaunch.address, userAddress, [AurPlyPid]));
|
|
3067
3070
|
promises.push(this._tokenLock.lockedAmounts(userAddress));
|
|
3068
|
-
_context2.next =
|
|
3071
|
+
_context2.next = 23;
|
|
3069
3072
|
return Promise.all(promises);
|
|
3070
3073
|
|
|
3071
|
-
case
|
|
3074
|
+
case 23:
|
|
3072
3075
|
values = _context2.sent;
|
|
3073
3076
|
accountLiquidity = values[0];
|
|
3074
3077
|
rewardBalancesMetadata = values[1];
|
|
@@ -3109,7 +3112,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3109
3112
|
}
|
|
3110
3113
|
});
|
|
3111
3114
|
|
|
3112
|
-
case
|
|
3115
|
+
case 34:
|
|
3113
3116
|
case "end":
|
|
3114
3117
|
return _context2.stop();
|
|
3115
3118
|
}
|
|
@@ -3232,15 +3235,41 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3232
3235
|
return stakeBalanceOf;
|
|
3233
3236
|
}();
|
|
3234
3237
|
|
|
3235
|
-
_proto.calcHypotheticalStats = function calcHypotheticalStats(
|
|
3236
|
-
var
|
|
3237
|
-
|
|
3238
|
+
_proto.calcHypotheticalStats = function calcHypotheticalStats(_ref) {
|
|
3239
|
+
var userMarketDetail = _ref.userMarketDetail,
|
|
3240
|
+
currentBorrowLimit = _ref.currentBorrowLimit,
|
|
3241
|
+
currentBorrowValuation = _ref.currentBorrowValuation,
|
|
3242
|
+
action = _ref.action,
|
|
3243
|
+
tokenAmount = _ref.tokenAmount;
|
|
3244
|
+
var newBorrowLimit = new BigNumber(currentBorrowLimit.amount),
|
|
3245
|
+
newBorrowValuation = new BigNumber(currentBorrowValuation.amount);
|
|
3246
|
+
|
|
3247
|
+
switch (action) {
|
|
3248
|
+
case MarketAction.EnableCollateral:
|
|
3249
|
+
case MarketAction.DisableCollateral:
|
|
3250
|
+
var deltaBorrowLimit = calcValuation(userMarketDetail.depositBalance, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
|
|
3251
|
+
newBorrowLimit = action == MarketAction.EnableCollateral ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
|
|
3252
|
+
break;
|
|
3253
|
+
|
|
3254
|
+
case MarketAction.Deposit:
|
|
3255
|
+
case MarketAction.Withdraw:
|
|
3256
|
+
deltaBorrowLimit = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice)).multipliedBy(userMarketDetail.collateralRatio).multipliedBy(BORROW_LIMIT_BUFFER);
|
|
3257
|
+
newBorrowLimit = action == MarketAction.Deposit ? newBorrowLimit.plus(deltaBorrowLimit) : newBorrowLimit.minus(deltaBorrowLimit);
|
|
3258
|
+
break;
|
|
3259
|
+
|
|
3260
|
+
case MarketAction.Borrow:
|
|
3261
|
+
case MarketAction.Repay:
|
|
3262
|
+
var deltaBorrowValuation = calcValuation(tokenAmount, new BigNumber(userMarketDetail.underlyingPrice));
|
|
3263
|
+
newBorrowValuation = action == MarketAction.Borrow ? newBorrowValuation.plus(deltaBorrowValuation) : newBorrowValuation.minus(deltaBorrowValuation);
|
|
3264
|
+
break;
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3238
3267
|
return {
|
|
3239
3268
|
newBorrowLimit: {
|
|
3240
3269
|
amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
3241
3270
|
currency: "USD"
|
|
3242
3271
|
},
|
|
3243
|
-
newBorrowUtilization:
|
|
3272
|
+
newBorrowUtilization: newBorrowValuation.div(newBorrowLimit).toNumber()
|
|
3244
3273
|
};
|
|
3245
3274
|
};
|
|
3246
3275
|
|
|
@@ -3364,5 +3393,5 @@ var dummyUserMarketDetails = {
|
|
|
3364
3393
|
underlyingPrice: "1"
|
|
3365
3394
|
};
|
|
3366
3395
|
|
|
3367
|
-
export { AURORA_CHAINID, AURPLYToken, AurPlyPid, BORROW_LIMIT_BUFFER, BlockchainEntity, BlockchainEntityRead, BlockchainEntityReadWrite, ComptrollerRewardType, DECIMAL_PRECISION, ETHAddress, MoneyMarket, MoneyMarketRead, MoneyMarketReadWrite, ONE_DAY, ONE_YEAR, PLYToken, REWARDCLAIMSTART, SDK, SdkRead, SdkReadWrite, Token, TokenAmount, calcLMRewardApr, decimalFactor, dummyAddress, dummyMarketAddress, dummyPly, dummyPlyAurora, dummyToken, dummyTokenAmount, dummyTokenAmount2, dummyTokenAmount3, dummyUserMarketDetails, dummyZeroTokenAmount, fetchLPPositions, fetchLPPrice, fetchPrice, fetchPriceFromCoingecko, fetchPriceFromCoingeckoAPI, fetchPriceFromOracle, fetchUnderlyingTokensPrices, fetchValuation, formatObject, getCurrentTimestamp, getDecimal, isSameAddress, networkAddresses, validateAndParseAddress };
|
|
3396
|
+
export { AURORA_CHAINID, AURPLYToken, AurPlyPid, BORROW_LIMIT_BUFFER, BlockchainEntity, BlockchainEntityRead, BlockchainEntityReadWrite, ComptrollerRewardType, DECIMAL_PRECISION, ETHAddress, MarketAction, MoneyMarket, MoneyMarketRead, MoneyMarketReadWrite, ONE_DAY, ONE_YEAR, PLYToken, REWARDCLAIMSTART, SDK, SdkRead, SdkReadWrite, Token, TokenAmount, calcLMRewardApr, calcValuation, decimalFactor, dummyAddress, dummyMarketAddress, dummyPly, dummyPlyAurora, dummyToken, dummyTokenAmount, dummyTokenAmount2, dummyTokenAmount3, dummyUserMarketDetails, dummyZeroTokenAmount, fetchLPPositions, fetchLPPrice, fetchPrice, fetchPriceFromCoingecko, fetchPriceFromCoingeckoAPI, fetchPriceFromOracle, fetchUnderlyingTokensPrices, fetchValuation, formatObject, getCurrentTimestamp, getDecimal, isSameAddress, networkAddresses, validateAndParseAddress };
|
|
3368
3397
|
//# sourceMappingURL=sdk.esm.js.map
|