@aurigami/sdk 0.3.5 → 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 +10 -3
- package/dist/constants.d.ts +1 -7
- package/dist/priceFetcher.d.ts +2 -1
- package/dist/sdk.cjs.development.js +101 -65
- 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 +89 -48
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +13 -0
- package/package.json +2 -1
- package/src/MoneyMarket.ts +3 -5
- package/src/SDK.ts +60 -11
- package/src/constants.ts +2 -20
- package/src/dummy.ts +2 -1
- package/src/priceFetcher.ts +8 -7
- package/src/types.ts +16 -2
package/dist/SDK.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BlockchainEntity, BlockchainEntityRead } from './BlockchainEntity';
|
|
2
|
-
import { LockingDetails, PlyAuroraPoolDetails, NetworkConnection, UserDetails, CurrencyAmount } from './types';
|
|
2
|
+
import { LockingDetails, PlyAuroraPoolDetails, NetworkConnection, UserDetails, UserMarketDetails, CurrencyAmount, HypotheticalStats, MarketAction } from './types';
|
|
3
3
|
import { TransactionResponse } from '@ethersproject/abstract-provider';
|
|
4
|
-
import { Contract
|
|
4
|
+
import { Contract } from 'ethers';
|
|
5
5
|
import { AuriFairLaunch, Comptroller, TokenLock } from '@aurigami/contracts/typechain';
|
|
6
6
|
import { TokenAmount } from './tokenAmount';
|
|
7
7
|
import { Token } from './token';
|
|
@@ -16,6 +16,13 @@ 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({ userMarketDetail, currentBorrowLimit, currentBorrowValuation, action, tokenAmount }: {
|
|
20
|
+
userMarketDetail: UserMarketDetails;
|
|
21
|
+
currentBorrowLimit: CurrencyAmount;
|
|
22
|
+
currentBorrowValuation: CurrencyAmount;
|
|
23
|
+
action: MarketAction;
|
|
24
|
+
tokenAmount?: TokenAmount;
|
|
25
|
+
}): HypotheticalStats;
|
|
19
26
|
}
|
|
20
27
|
export declare class SdkReadWrite extends SdkRead {
|
|
21
28
|
claim(): Promise<TransactionResponse>;
|
|
@@ -25,5 +32,5 @@ export declare class SdkReadWrite extends SdkRead {
|
|
|
25
32
|
export declare class SDK extends BlockchainEntity {
|
|
26
33
|
constructor();
|
|
27
34
|
read(networkConnection: NetworkConnection): SdkRead;
|
|
28
|
-
|
|
35
|
+
readWrite(networkConnection: NetworkConnection): SdkReadWrite;
|
|
29
36
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
|
-
import { Signer } from 'ethers';
|
|
3
|
-
export declare const AVAX_DEFAULT_PROVIDER_URL = "https://api.avax.network/ext/bc/C/rpc";
|
|
4
|
-
export declare const AVAX_DEFAULT_PROVIDER: any;
|
|
5
|
-
export declare const AURORA_DEFAULT_PROVIDER_URL = "https://mainnet.aurora.dev";
|
|
6
|
-
export declare const AURORA_DEFAULT_PROVIDER: any;
|
|
7
2
|
export declare const dummyAddress: string;
|
|
8
3
|
export declare const ETHAddress: string;
|
|
9
|
-
export declare const AURORA_DEFAULT_SIGNER: Signer;
|
|
10
4
|
export declare const AURORA_CHAINID = 1313161554;
|
|
11
|
-
export declare const DECIMAL_PRECISION =
|
|
5
|
+
export declare const DECIMAL_PRECISION = 10;
|
|
12
6
|
export declare type NetworkAddresses = {
|
|
13
7
|
auTokens: {
|
|
14
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;
|
|
@@ -6,11 +6,12 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var abstractSigner = require('@ethersproject/abstract-signer');
|
|
8
8
|
var BigNumber = _interopDefault(require('bignumber.js'));
|
|
9
|
-
var ethers
|
|
9
|
+
var ethers = require('ethers');
|
|
10
10
|
var AuErc20ABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuErc20.sol/AuErc20.json'));
|
|
11
11
|
var AuETHABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuETH.sol/AuETH.json'));
|
|
12
12
|
var ComptrollerABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/Comptroller.sol/Comptroller.json'));
|
|
13
13
|
var AuriLensABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuriLens.sol/AuriLens.json'));
|
|
14
|
+
var axios = _interopDefault(require('axios'));
|
|
14
15
|
var TokenLockABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/TokenLock.sol/TokenLock.json'));
|
|
15
16
|
var AuriFairLaunchABI = _interopDefault(require('@aurigami/contracts/artifacts/contracts/AuriFairLaunch.sol/AuriFairLaunch.json'));
|
|
16
17
|
|
|
@@ -896,18 +897,24 @@ var BlockchainEntity = /*#__PURE__*/function () {
|
|
|
896
897
|
return BlockchainEntity;
|
|
897
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 = {}));
|
|
900
913
|
|
|
901
|
-
var AVAX_DEFAULT_PROVIDER_URL = 'https://api.avax.network/ext/bc/C/rpc';
|
|
902
|
-
var AVAX_DEFAULT_PROVIDER = /*#__PURE__*/new ethers.providers.JsonRpcProvider(AVAX_DEFAULT_PROVIDER_URL);
|
|
903
|
-
var AURORA_DEFAULT_PROVIDER_URL = "https://mainnet.aurora.dev";
|
|
904
|
-
var AURORA_DEFAULT_PROVIDER = /*#__PURE__*/new ethers.providers.JsonRpcProvider(AURORA_DEFAULT_PROVIDER_URL);
|
|
905
914
|
var dummyAddress = "0xDEADbeEfEEeEEEeEEEeEEeeeeeEeEEeeeeEEEEeE";
|
|
906
915
|
var ETHAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
907
|
-
var dummyPrivateKey = '1111111111111111111111111111111111111111111111111111111111111111';
|
|
908
|
-
var AURORA_DEFAULT_SIGNER = /*#__PURE__*/new ethers.Wallet(dummyPrivateKey, AURORA_DEFAULT_PROVIDER);
|
|
909
916
|
var AURORA_CHAINID = 1313161554;
|
|
910
|
-
var DECIMAL_PRECISION =
|
|
917
|
+
var DECIMAL_PRECISION = 10;
|
|
911
918
|
var networkAddresses = {
|
|
912
919
|
auTokens: [{
|
|
913
920
|
address: /*#__PURE__*/'0x2dEf6eb801757655AD227110d65C80DB595bBc60'.toLowerCase(),
|
|
@@ -977,7 +984,7 @@ function formatObject(object) {
|
|
|
977
984
|
return JSON.stringify(object, null, ' ');
|
|
978
985
|
}
|
|
979
986
|
function decimalFactor(decimal) {
|
|
980
|
-
return ethers
|
|
987
|
+
return ethers.BigNumber.from(10).pow(decimal).toString();
|
|
981
988
|
}
|
|
982
989
|
var isSameAddress = function isSameAddress(address1, address2) {
|
|
983
990
|
return address1.toLowerCase() == address2.toLowerCase();
|
|
@@ -1004,7 +1011,7 @@ var getCurrentTimestamp = /*#__PURE__*/function () {
|
|
|
1004
1011
|
}();
|
|
1005
1012
|
function validateAndParseAddress(address) {
|
|
1006
1013
|
try {
|
|
1007
|
-
return ethers
|
|
1014
|
+
return ethers.utils.getAddress(address);
|
|
1008
1015
|
} catch (error) {
|
|
1009
1016
|
throw new Error("Invalid address: " + address);
|
|
1010
1017
|
}
|
|
@@ -1020,11 +1027,6 @@ function calcLMRewardApr(rewardsValue, totalStakeValue, frequencyPerYear) {
|
|
|
1020
1027
|
return rewardsValue.multipliedBy(frequencyPerYear).dividedBy(totalStakeValue);
|
|
1021
1028
|
}
|
|
1022
1029
|
|
|
1023
|
-
(function (ComptrollerRewardType) {
|
|
1024
|
-
ComptrollerRewardType[ComptrollerRewardType["PLY"] = 0] = "PLY";
|
|
1025
|
-
ComptrollerRewardType[ComptrollerRewardType["AURORA"] = 1] = "AURORA";
|
|
1026
|
-
})(exports.ComptrollerRewardType || (exports.ComptrollerRewardType = {}));
|
|
1027
|
-
|
|
1028
1030
|
var Token = function Token(address, decimals) {
|
|
1029
1031
|
this.address = address.toLowerCase();
|
|
1030
1032
|
this.decimals = decimals;
|
|
@@ -2009,8 +2011,6 @@ var IUniswapV2PairABI = {
|
|
|
2009
2011
|
deployedLinkReferences: deployedLinkReferences
|
|
2010
2012
|
};
|
|
2011
2013
|
|
|
2012
|
-
var axios = /*#__PURE__*/require('axios');
|
|
2013
|
-
|
|
2014
2014
|
function fetchPriceFromCoingeckoAPI(_x) {
|
|
2015
2015
|
return _fetchPriceFromCoingeckoAPI.apply(this, arguments);
|
|
2016
2016
|
}
|
|
@@ -2083,7 +2083,7 @@ function _fetchLPPositions() {
|
|
|
2083
2083
|
switch (_context3.prev = _context3.next) {
|
|
2084
2084
|
case 0:
|
|
2085
2085
|
promises = [];
|
|
2086
|
-
LPContract = new ethers
|
|
2086
|
+
LPContract = new ethers.Contract(LPAddress, IUniswapV2PairABI.abi, provider);
|
|
2087
2087
|
promises.push(LPContract.token0());
|
|
2088
2088
|
promises.push(LPContract.toekn1());
|
|
2089
2089
|
promises.push(LPContract.getReserves());
|
|
@@ -2179,7 +2179,7 @@ function _fetchPriceFromOracle() {
|
|
|
2179
2179
|
while (1) {
|
|
2180
2180
|
switch (_context5.prev = _context5.next) {
|
|
2181
2181
|
case 0:
|
|
2182
|
-
oracleContract = new ethers
|
|
2182
|
+
oracleContract = new ethers.Contract(networkAddresses.misc.oracle, OracleABI.abi, provider);
|
|
2183
2183
|
_context5.next = 3;
|
|
2184
2184
|
return oracleContract.getUnderlyingPrice(auTokenAddress);
|
|
2185
2185
|
|
|
@@ -2208,7 +2208,7 @@ function _fetchUnderlyingTokensPrices() {
|
|
|
2208
2208
|
while (1) {
|
|
2209
2209
|
switch (_context6.prev = _context6.next) {
|
|
2210
2210
|
case 0:
|
|
2211
|
-
auriLens = new ethers
|
|
2211
|
+
auriLens = new ethers.Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, provider);
|
|
2212
2212
|
auTokenAddresses = networkAddresses.auTokens.map(function (auToken) {
|
|
2213
2213
|
return auToken.address;
|
|
2214
2214
|
});
|
|
@@ -2280,31 +2280,25 @@ function _fetchPrice() {
|
|
|
2280
2280
|
return _fetchPrice.apply(this, arguments);
|
|
2281
2281
|
}
|
|
2282
2282
|
|
|
2283
|
-
function fetchValuation(_x13, _x14
|
|
2283
|
+
function fetchValuation(_x13, _x14) {
|
|
2284
2284
|
return _fetchValuation.apply(this, arguments);
|
|
2285
2285
|
}
|
|
2286
2286
|
|
|
2287
2287
|
function _fetchValuation() {
|
|
2288
|
-
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider
|
|
2288
|
+
_fetchValuation = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(tokenAmount, provider) {
|
|
2289
|
+
var price;
|
|
2289
2290
|
return runtime_1.wrap(function _callee8$(_context8) {
|
|
2290
2291
|
while (1) {
|
|
2291
2292
|
switch (_context8.prev = _context8.next) {
|
|
2292
2293
|
case 0:
|
|
2293
|
-
|
|
2294
|
-
_context8.next = 4;
|
|
2295
|
-
break;
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
_context8.next = 3;
|
|
2294
|
+
_context8.next = 2;
|
|
2299
2295
|
return fetchPrice(tokenAmount.token.address, provider);
|
|
2300
2296
|
|
|
2301
|
-
case
|
|
2297
|
+
case 2:
|
|
2302
2298
|
price = _context8.sent;
|
|
2299
|
+
return _context8.abrupt("return", calcValuation(tokenAmount, price));
|
|
2303
2300
|
|
|
2304
2301
|
case 4:
|
|
2305
|
-
return _context8.abrupt("return", new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price));
|
|
2306
|
-
|
|
2307
|
-
case 5:
|
|
2308
2302
|
case "end":
|
|
2309
2303
|
return _context8.stop();
|
|
2310
2304
|
}
|
|
@@ -2314,6 +2308,10 @@ function _fetchValuation() {
|
|
|
2314
2308
|
return _fetchValuation.apply(this, arguments);
|
|
2315
2309
|
}
|
|
2316
2310
|
|
|
2311
|
+
function calcValuation(tokenAmount, price) {
|
|
2312
|
+
return new BigNumber(tokenAmount.formattedAmount()).multipliedBy(price);
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2317
2315
|
var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
2318
2316
|
_inheritsLoose(MoneyMarketRead, _BlockchainEntityRead);
|
|
2319
2317
|
|
|
@@ -2323,14 +2321,14 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2323
2321
|
_this = _BlockchainEntityRead.call(this, networkConnection) || this;
|
|
2324
2322
|
|
|
2325
2323
|
if (isSameAddress(underlyingAsset, ETHAddress)) {
|
|
2326
|
-
_this.auToken = new ethers
|
|
2324
|
+
_this.auToken = new ethers.Contract(auToken, AuETHABI.abi, networkConnection.provider);
|
|
2327
2325
|
} else {
|
|
2328
|
-
_this.auToken = new ethers
|
|
2326
|
+
_this.auToken = new ethers.Contract(auToken, AuErc20ABI.abi, networkConnection.provider);
|
|
2329
2327
|
}
|
|
2330
2328
|
|
|
2331
2329
|
_this.underlying = new Token(underlyingAsset, getDecimal(underlyingAsset));
|
|
2332
|
-
_this._comptroller = new ethers
|
|
2333
|
-
_this._auriLens = new ethers
|
|
2330
|
+
_this._comptroller = new ethers.Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider);
|
|
2331
|
+
_this._auriLens = new ethers.Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider);
|
|
2334
2332
|
return _this;
|
|
2335
2333
|
}
|
|
2336
2334
|
|
|
@@ -2415,7 +2413,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2415
2413
|
return Promise.all(promises);
|
|
2416
2414
|
|
|
2417
2415
|
case 5:
|
|
2418
|
-
return _context3.abrupt("return", new TokenAmount(this.underlying, ethers
|
|
2416
|
+
return _context3.abrupt("return", new TokenAmount(this.underlying, ethers.BigNumber.from(totalCash.rawAmount()).add(totalBorrow.rawAmount()).toString()));
|
|
2419
2417
|
|
|
2420
2418
|
case 6:
|
|
2421
2419
|
case "end":
|
|
@@ -2635,7 +2633,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2635
2633
|
case 11:
|
|
2636
2634
|
_context9.t0 = calcLMRewardApr;
|
|
2637
2635
|
_context9.next = 14;
|
|
2638
|
-
return
|
|
2636
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardBorrowSpeed.toString()), plyPrice);
|
|
2639
2637
|
|
|
2640
2638
|
case 14:
|
|
2641
2639
|
_context9.t1 = _context9.sent;
|
|
@@ -2644,7 +2642,7 @@ var MoneyMarketRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2644
2642
|
borrowPlyApy = (0, _context9.t0)(_context9.t1, _context9.t2, _context9.t3);
|
|
2645
2643
|
_context9.t4 = calcLMRewardApr;
|
|
2646
2644
|
_context9.next = 21;
|
|
2647
|
-
return
|
|
2645
|
+
return calcValuation(new TokenAmount(PLYToken, rewardSpeeds.plyRewardSupplySpeed.toString()), plyPrice);
|
|
2648
2646
|
|
|
2649
2647
|
case 21:
|
|
2650
2648
|
_context9.t5 = _context9.sent;
|
|
@@ -2934,10 +2932,10 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2934
2932
|
var _this;
|
|
2935
2933
|
|
|
2936
2934
|
_this = _BlockchainEntityRead.call(this, networkConnection) || this;
|
|
2937
|
-
_this._comptroller = new ethers
|
|
2938
|
-
_this._tokenLock = new ethers
|
|
2939
|
-
_this._auriFairLaunch = new ethers
|
|
2940
|
-
_this._auriLens = new ethers
|
|
2935
|
+
_this._comptroller = new ethers.Contract(networkAddresses.misc.COMPTROLLER, ComptrollerABI.abi, networkConnection.provider);
|
|
2936
|
+
_this._tokenLock = new ethers.Contract(networkAddresses.misc.TOKENLOCK, TokenLockABI.abi, networkConnection.provider);
|
|
2937
|
+
_this._auriFairLaunch = new ethers.Contract(networkAddresses.misc.AURIFAIRLAUNCH, AuriFairLaunchABI.abi, networkConnection.provider);
|
|
2938
|
+
_this._auriLens = new ethers.Contract(networkAddresses.misc.AURILENS, AuriLensABI.abi, networkConnection.provider);
|
|
2941
2939
|
return _this;
|
|
2942
2940
|
}
|
|
2943
2941
|
|
|
@@ -2955,7 +2953,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2955
2953
|
|
|
2956
2954
|
case 2:
|
|
2957
2955
|
currentTime = _context.sent;
|
|
2958
|
-
currentWeek = ethers
|
|
2956
|
+
currentWeek = ethers.BigNumber.from(currentTime - REWARDCLAIMSTART).div(7 * ONE_DAY).toNumber();
|
|
2959
2957
|
denominator = 10000;
|
|
2960
2958
|
promises = [];
|
|
2961
2959
|
promises.push(this._tokenLock.percentageLock(currentWeek));
|
|
@@ -2996,7 +2994,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
2996
2994
|
var _getUserDetails = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(userAddress) {
|
|
2997
2995
|
var _this2 = this;
|
|
2998
2996
|
|
|
2999
|
-
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;
|
|
3000
2998
|
|
|
3001
2999
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
3002
3000
|
while (1) {
|
|
@@ -3023,7 +3021,10 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3023
3021
|
promises.push(moneyMarket.getCollateralRatio().then(function (res) {
|
|
3024
3022
|
userMarketDetail.collateralRatio = res.toNumber();
|
|
3025
3023
|
}));
|
|
3026
|
-
pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider))
|
|
3024
|
+
pricePromises.push(fetchPrice(moneyMarket.underlying.address, _this2._networkConnection.provider).then(function (res) {
|
|
3025
|
+
userMarketDetail.underlyingPrice = res.toString();
|
|
3026
|
+
return res;
|
|
3027
|
+
}));
|
|
3027
3028
|
};
|
|
3028
3029
|
|
|
3029
3030
|
for (_iterator = _createForOfIteratorHelperLoose(networkAddresses.auTokens); !(_step = _iterator()).done;) {
|
|
@@ -3042,7 +3043,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3042
3043
|
|
|
3043
3044
|
case 12:
|
|
3044
3045
|
underlyingPrices = _context2.sent;
|
|
3045
|
-
|
|
3046
|
+
depositValues = [];
|
|
3046
3047
|
|
|
3047
3048
|
_loop = function _loop() {
|
|
3048
3049
|
var auToken = networkAddresses.auTokens[i];
|
|
@@ -3055,18 +3056,13 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3055
3056
|
userMarketDetails[i].isCollateral = false;
|
|
3056
3057
|
}
|
|
3057
3058
|
|
|
3058
|
-
|
|
3059
|
+
depositValues.push(calcValuation(userMarketDetails[i].depositBalance, underlyingPrices[i]));
|
|
3059
3060
|
};
|
|
3060
3061
|
|
|
3061
3062
|
for (i = 0; i < marketCount; i++) {
|
|
3062
3063
|
_loop();
|
|
3063
3064
|
}
|
|
3064
3065
|
|
|
3065
|
-
_context2.next = 18;
|
|
3066
|
-
return Promise.all(depositValuationPromises);
|
|
3067
|
-
|
|
3068
|
-
case 18:
|
|
3069
|
-
depositValues = _context2.sent;
|
|
3070
3066
|
totalBorrowLimit = depositValues.reduce(function (p, v, index) {
|
|
3071
3067
|
if (userMarketDetails[index].isCollateral) return p.plus(v.multipliedBy(userMarketDetails[index].collateralRatio));
|
|
3072
3068
|
return p;
|
|
@@ -3075,15 +3071,20 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3075
3071
|
promises.push(this._comptroller.getAccountLiquidity(userAddress));
|
|
3076
3072
|
promises.push(this._auriLens.callStatic.getRewardBalancesMetadata(this._comptroller.address, this._auriFairLaunch.address, userAddress, [AurPlyPid]));
|
|
3077
3073
|
promises.push(this._tokenLock.lockedAmounts(userAddress));
|
|
3078
|
-
_context2.next =
|
|
3074
|
+
_context2.next = 23;
|
|
3079
3075
|
return Promise.all(promises);
|
|
3080
3076
|
|
|
3081
|
-
case
|
|
3077
|
+
case 23:
|
|
3082
3078
|
values = _context2.sent;
|
|
3083
3079
|
accountLiquidity = values[0];
|
|
3084
3080
|
rewardBalancesMetadata = values[1];
|
|
3085
3081
|
lockedAmount = values[2];
|
|
3086
3082
|
borrowedvaluation = totalBorrowLimit.minus(new BigNumber(accountLiquidity[1].toString()).div(decimalFactor(18)));
|
|
3083
|
+
|
|
3084
|
+
if (borrowedvaluation.lt("0.00001")) {
|
|
3085
|
+
borrowedvaluation = new BigNumber(0);
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3087
3088
|
bufferedBorrowLimit = totalBorrowLimit.multipliedBy(BORROW_LIMIT_BUFFER);
|
|
3088
3089
|
minimumBorrowLimitAllowed = borrowedvaluation.div(BORROW_LIMIT_BUFFER);
|
|
3089
3090
|
|
|
@@ -3114,7 +3115,7 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3114
3115
|
}
|
|
3115
3116
|
});
|
|
3116
3117
|
|
|
3117
|
-
case
|
|
3118
|
+
case 34:
|
|
3118
3119
|
case "end":
|
|
3119
3120
|
return _context2.stop();
|
|
3120
3121
|
}
|
|
@@ -3237,6 +3238,44 @@ var SdkRead = /*#__PURE__*/function (_BlockchainEntityRead) {
|
|
|
3237
3238
|
return stakeBalanceOf;
|
|
3238
3239
|
}();
|
|
3239
3240
|
|
|
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
|
+
|
|
3270
|
+
return {
|
|
3271
|
+
newBorrowLimit: {
|
|
3272
|
+
amount: newBorrowLimit.toFixed(DECIMAL_PRECISION),
|
|
3273
|
+
currency: "USD"
|
|
3274
|
+
},
|
|
3275
|
+
newBorrowUtilization: newBorrowValuation.div(newBorrowLimit).toNumber()
|
|
3276
|
+
};
|
|
3277
|
+
};
|
|
3278
|
+
|
|
3240
3279
|
return SdkRead;
|
|
3241
3280
|
}(BlockchainEntityRead);
|
|
3242
3281
|
var SdkReadWrite = /*#__PURE__*/function (_SdkRead) {
|
|
@@ -3332,8 +3371,8 @@ var SDK = /*#__PURE__*/function (_BlockchainEntity) {
|
|
|
3332
3371
|
return new SdkRead(networkConnection);
|
|
3333
3372
|
};
|
|
3334
3373
|
|
|
3335
|
-
|
|
3336
|
-
return new
|
|
3374
|
+
_proto3.readWrite = function readWrite(networkConnection) {
|
|
3375
|
+
return new SdkReadWrite(networkConnection);
|
|
3337
3376
|
};
|
|
3338
3377
|
|
|
3339
3378
|
return SDK;
|
|
@@ -3353,16 +3392,12 @@ var dummyUserMarketDetails = {
|
|
|
3353
3392
|
borrowBalance: dummyZeroTokenAmount,
|
|
3354
3393
|
isCollateral: true,
|
|
3355
3394
|
maxWithdrawableAmount: dummyTokenAmount,
|
|
3356
|
-
collateralRatio: 0.5
|
|
3395
|
+
collateralRatio: 0.5,
|
|
3396
|
+
underlyingPrice: "1"
|
|
3357
3397
|
};
|
|
3358
3398
|
|
|
3359
3399
|
exports.AURORA_CHAINID = AURORA_CHAINID;
|
|
3360
|
-
exports.AURORA_DEFAULT_PROVIDER = AURORA_DEFAULT_PROVIDER;
|
|
3361
|
-
exports.AURORA_DEFAULT_PROVIDER_URL = AURORA_DEFAULT_PROVIDER_URL;
|
|
3362
|
-
exports.AURORA_DEFAULT_SIGNER = AURORA_DEFAULT_SIGNER;
|
|
3363
3400
|
exports.AURPLYToken = AURPLYToken;
|
|
3364
|
-
exports.AVAX_DEFAULT_PROVIDER = AVAX_DEFAULT_PROVIDER;
|
|
3365
|
-
exports.AVAX_DEFAULT_PROVIDER_URL = AVAX_DEFAULT_PROVIDER_URL;
|
|
3366
3401
|
exports.AurPlyPid = AurPlyPid;
|
|
3367
3402
|
exports.BORROW_LIMIT_BUFFER = BORROW_LIMIT_BUFFER;
|
|
3368
3403
|
exports.BlockchainEntity = BlockchainEntity;
|
|
@@ -3383,6 +3418,7 @@ exports.SdkReadWrite = SdkReadWrite;
|
|
|
3383
3418
|
exports.Token = Token;
|
|
3384
3419
|
exports.TokenAmount = TokenAmount;
|
|
3385
3420
|
exports.calcLMRewardApr = calcLMRewardApr;
|
|
3421
|
+
exports.calcValuation = calcValuation;
|
|
3386
3422
|
exports.decimalFactor = decimalFactor;
|
|
3387
3423
|
exports.dummyAddress = dummyAddress;
|
|
3388
3424
|
exports.dummyMarketAddress = dummyMarketAddress;
|