impermax-sdk 1.0.2 → 1.0.3

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.
Files changed (108) hide show
  1. package/package.json +1 -1
  2. package/lib/esm/abis/ImpermaxABI.d.ts +0 -2
  3. package/lib/esm/abis/ImpermaxABI.js +0 -3
  4. package/lib/esm/abis/contracts/ClaimAggregator.json +0 -2015
  5. package/lib/esm/abis/contracts/IBorrowable.json +0 -13207
  6. package/lib/esm/abis/contracts/IClaimable.json +0 -406
  7. package/lib/esm/abis/contracts/ICollateral.json +0 -8952
  8. package/lib/esm/abis/contracts/IERC20.json +0 -2376
  9. package/lib/esm/abis/contracts/IFactory.json +0 -3660
  10. package/lib/esm/abis/contracts/IFarmingPool.json +0 -3584
  11. package/lib/esm/abis/contracts/IMerkleDistributor.json +0 -1134
  12. package/lib/esm/abis/contracts/IRouter02.json +0 -7283
  13. package/lib/esm/abis/contracts/ISimpleUniswapOracle.json +0 -1469
  14. package/lib/esm/abis/contracts/IStakedLPToken.json +0 -7309
  15. package/lib/esm/abis/contracts/IStakingRewards.json +0 -1036
  16. package/lib/esm/abis/contracts/IUniswapV2Factory.json +0 -1690
  17. package/lib/esm/abis/contracts/IUniswapV2Pair.json +0 -6761
  18. package/lib/esm/abis/contracts/ImpermaxChef.json +0 -20945
  19. package/lib/esm/config/amms.d.ts +0 -25
  20. package/lib/esm/config/amms.js +0 -196
  21. package/lib/esm/config/contracts/claim-aggregators.d.ts +0 -2
  22. package/lib/esm/config/contracts/claim-aggregators.js +0 -18
  23. package/lib/esm/config/contracts/impermax-chef.d.ts +0 -2
  24. package/lib/esm/config/contracts/impermax-chef.js +0 -18
  25. package/lib/esm/config/contracts/imxes.d.ts +0 -2
  26. package/lib/esm/config/contracts/imxes.js +0 -18
  27. package/lib/esm/config/contracts/merkle-distributors.d.ts +0 -4
  28. package/lib/esm/config/contracts/merkle-distributors.js +0 -13
  29. package/lib/esm/config/contracts/routers.d.ts +0 -2
  30. package/lib/esm/config/contracts/routers.js +0 -38
  31. package/lib/esm/config/contracts/simple-uniswap-oracles.d.ts +0 -2
  32. package/lib/esm/config/contracts/simple-uniswap-oracles.js +0 -35
  33. package/lib/esm/config/contracts/weths.d.ts +0 -2
  34. package/lib/esm/config/contracts/weths.js +0 -19
  35. package/lib/esm/config/debank-ids.d.ts +0 -2
  36. package/lib/esm/config/debank-ids.js +0 -17
  37. package/lib/esm/config/endpoints/merkle-distributors.d.ts +0 -4
  38. package/lib/esm/config/endpoints/merkle-distributors.js +0 -13
  39. package/lib/esm/config/eth.d.ts +0 -3
  40. package/lib/esm/config/eth.js +0 -32
  41. package/lib/esm/config/factories.d.ts +0 -6
  42. package/lib/esm/config/factories.js +0 -24
  43. package/lib/esm/config/farms.d.ts +0 -59
  44. package/lib/esm/config/farms.js +0 -114
  45. package/lib/esm/config/general.d.ts +0 -3
  46. package/lib/esm/config/general.js +0 -8
  47. package/lib/esm/config/subgraphs.d.ts +0 -5
  48. package/lib/esm/config/subgraphs.js +0 -68
  49. package/lib/esm/config/types.d.ts +0 -67
  50. package/lib/esm/config/types.js +0 -54
  51. package/lib/esm/impermax-router/Account.d.ts +0 -31
  52. package/lib/esm/impermax-router/Account.js +0 -154
  53. package/lib/esm/impermax-router/AccountBorrowable.d.ts +0 -22
  54. package/lib/esm/impermax-router/AccountBorrowable.js +0 -141
  55. package/lib/esm/impermax-router/AccountCollateral.d.ts +0 -11
  56. package/lib/esm/impermax-router/AccountCollateral.js +0 -63
  57. package/lib/esm/impermax-router/AccountLendingPool.d.ts +0 -57
  58. package/lib/esm/impermax-router/AccountLendingPool.js +0 -266
  59. package/lib/esm/impermax-router/AccountPoolToken.d.ts +0 -29
  60. package/lib/esm/impermax-router/AccountPoolToken.js +0 -89
  61. package/lib/esm/impermax-router/Borrowable.d.ts +0 -27
  62. package/lib/esm/impermax-router/Borrowable.js +0 -128
  63. package/lib/esm/impermax-router/Collateral.d.ts +0 -9
  64. package/lib/esm/impermax-router/Collateral.js +0 -45
  65. package/lib/esm/impermax-router/ContractsHelper.d.ts +0 -28
  66. package/lib/esm/impermax-router/ContractsHelper.js +0 -50
  67. package/lib/esm/impermax-router/ImpermaxFactory.d.ts +0 -15
  68. package/lib/esm/impermax-router/ImpermaxFactory.js +0 -42
  69. package/lib/esm/impermax-router/Interactions.d.ts +0 -16
  70. package/lib/esm/impermax-router/Interactions.js +0 -105
  71. package/lib/esm/impermax-router/InteractionsLendingPool.d.ts +0 -43
  72. package/lib/esm/impermax-router/InteractionsLendingPool.js +0 -124
  73. package/lib/esm/impermax-router/InteractionsPoolToken.d.ts +0 -23
  74. package/lib/esm/impermax-router/InteractionsPoolToken.js +0 -194
  75. package/lib/esm/impermax-router/LendingPool.d.ts +0 -69
  76. package/lib/esm/impermax-router/LendingPool.js +0 -291
  77. package/lib/esm/impermax-router/PoolToken.d.ts +0 -36
  78. package/lib/esm/impermax-router/PoolToken.js +0 -140
  79. package/lib/esm/impermax-router/index.d.ts +0 -20
  80. package/lib/esm/impermax-router/index.js +0 -34
  81. package/lib/esm/impermax-router/interfaces.d.ts +0 -218
  82. package/lib/esm/impermax-router/interfaces.js +0 -15
  83. package/lib/esm/index.d.ts +0 -3
  84. package/lib/esm/index.js +0 -10
  85. package/lib/esm/subgraph/Account.d.ts +0 -18
  86. package/lib/esm/subgraph/Account.js +0 -111
  87. package/lib/esm/subgraph/AccountLendingPool.d.ts +0 -19
  88. package/lib/esm/subgraph/AccountLendingPool.js +0 -71
  89. package/lib/esm/subgraph/AccountPoolToken.d.ts +0 -14
  90. package/lib/esm/subgraph/AccountPoolToken.js +0 -75
  91. package/lib/esm/subgraph/LendingPool.d.ts +0 -38
  92. package/lib/esm/subgraph/LendingPool.js +0 -204
  93. package/lib/esm/subgraph/PoolToken.d.ts +0 -64
  94. package/lib/esm/subgraph/PoolToken.js +0 -462
  95. package/lib/esm/subgraph/PriceHelper.d.ts +0 -21
  96. package/lib/esm/subgraph/PriceHelper.js +0 -166
  97. package/lib/esm/subgraph/SolidexHelper.d.ts +0 -16
  98. package/lib/esm/subgraph/SolidexHelper.js +0 -58
  99. package/lib/esm/subgraph/index.d.ts +0 -73
  100. package/lib/esm/subgraph/index.js +0 -185
  101. package/lib/esm/subgraph/initializer.d.ts +0 -34
  102. package/lib/esm/subgraph/initializer.js +0 -517
  103. package/lib/esm/subgraph/query.d.ts +0 -10
  104. package/lib/esm/subgraph/query.js +0 -229
  105. package/lib/esm/utils/ether-utils.d.ts +0 -5
  106. package/lib/esm/utils/ether-utils.js +0 -26
  107. package/lib/esm/utils/index.d.ts +0 -3
  108. package/lib/esm/utils/index.js +0 -16
@@ -1,141 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const interfaces_1 = require("./interfaces");
16
- const AccountPoolToken_1 = __importDefault(require("./AccountPoolToken"));
17
- const types_1 = require("../config/types");
18
- class AccountBorrowable extends AccountPoolToken_1.default {
19
- constructor() {
20
- super(...arguments);
21
- this.borrowableCache = {};
22
- }
23
- cleanCache() {
24
- super.cleanCache();
25
- this.borrowableCache = {};
26
- }
27
- // Borrowed
28
- initializeBorrowed() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const borrowable = yield this.poolToken.getPoolToken();
31
- const balance = yield borrowable.methods.borrowBalance(this.getAccount()).call();
32
- const storedAmount = yield yield this.poolToken.normalize(balance);
33
- const accrualTimestamp = yield this.getAccrualTimestamp();
34
- const borrowRate = yield this.getBorrowRate();
35
- return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
36
- });
37
- }
38
- getBorrowed() {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- if (!this.borrowableCache.borrowed)
41
- this.borrowableCache.borrowed = this.initializeBorrowed();
42
- return this.borrowableCache.borrowed;
43
- });
44
- }
45
- getBorrowedUSD() {
46
- return __awaiter(this, void 0, void 0, function* () {
47
- const borrowed = yield this.getBorrowed();
48
- const tokenPrice = yield this.getTokenPriceAccurate();
49
- return borrowed * tokenPrice;
50
- });
51
- }
52
- // Max Borrowable
53
- getMaxBorrowable() {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const availableCash = yield this.poolToken.getTotalBalance();
56
- const { valueCollateral, valueA, valueB } = yield this.accountLendingPool.getValues(interfaces_1.NO_CHANGES);
57
- const [valueBorrowed, valueOther] = this.poolToken.poolTokenType == types_1.PoolTokenType.BorrowableA ? [valueA, valueB] : [valueB, valueA];
58
- const safetyMargin = (yield this.accountLendingPool.getSafetyMargin()) * this.getUiMargin();
59
- const liquidationPenalty = yield this.accountLendingPool.getLiquidationPenalty();
60
- const actualCollateral = valueCollateral / liquidationPenalty;
61
- const totalValueBorrowable1 = (actualCollateral * Math.sqrt(safetyMargin) - valueOther) / safetyMargin;
62
- const totalValueBorrowable2 = (actualCollateral / Math.sqrt(safetyMargin) - valueOther) * safetyMargin;
63
- const maxValueBorrowable = Math.min(totalValueBorrowable1, totalValueBorrowable2) - valueBorrowed;
64
- const price = yield this.poolToken.getMarketPriceDenomLP();
65
- return Math.max(0, Math.min(availableCash, maxValueBorrowable / price));
66
- });
67
- }
68
- // Farming Shares
69
- initializeFarmingShares() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- if (!(yield this.poolToken.hasFarming()))
72
- return 0;
73
- if (yield this.poolToken.hasImpermaxChef()) {
74
- const c = (yield this.poolToken.getImpermaxChef().methods.userInfo(yield this.poolToken.getPoolTokenAddress(), this.getAccount()).call()).shares;
75
- return c;
76
- }
77
- else {
78
- const farmingPool = yield this.poolToken.getFarmingPool();
79
- return (yield farmingPool.methods.recipients(this.getAccount()).call()).shares;
80
- }
81
- });
82
- }
83
- getFarmingShares() {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- if (!this.borrowableCache.farmingShares)
86
- this.borrowableCache.farmingShares = this.initializeFarmingShares();
87
- return this.borrowableCache.farmingShares;
88
- });
89
- }
90
- // Available Reward
91
- initializeAvailableIMXReward() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- if (!(yield this.poolToken.hasFarming()))
94
- return 0;
95
- if (yield this.poolToken.hasImpermaxChef()) {
96
- const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
97
- try {
98
- return (yield this.poolToken.getImpermaxChef().methods.pendingReward(borrowableAddress, this.getAccount()).call()) / 1e18;
99
- }
100
- catch (_a) {
101
- console.log("Warning: pending reward negative");
102
- return 0;
103
- }
104
- }
105
- else {
106
- const farmingPool = yield this.poolToken.getFarmingPool();
107
- return (yield farmingPool.methods.claim().call({ from: this.getAccount() })) / 1e18;
108
- }
109
- });
110
- }
111
- getAvailableIMXReward() {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- if (!this.borrowableCache.availableIMXReward)
114
- this.borrowableCache.availableIMXReward = this.initializeAvailableIMXReward();
115
- return this.borrowableCache.availableIMXReward;
116
- });
117
- }
118
- initializeAvailableRewarderReward() {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- if (!(yield this.poolToken.hasRewarder()))
121
- return 0;
122
- const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
123
- const rewarder = yield this.poolToken.getRewarder();
124
- try {
125
- return (yield rewarder.methods.pendingReward(borrowableAddress, this.getAccount()).call()) / 1e18;
126
- }
127
- catch (_a) {
128
- console.log("Warning: pending reward negative");
129
- return 0;
130
- }
131
- });
132
- }
133
- getAvailableRewarderReward() {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- if (!this.borrowableCache.availableRewarderReward)
136
- this.borrowableCache.availableRewarderReward = this.initializeAvailableRewarderReward();
137
- return this.borrowableCache.availableRewarderReward;
138
- });
139
- }
140
- }
141
- exports.default = AccountBorrowable;
@@ -1,11 +0,0 @@
1
- import AccountPoolToken from "./AccountPoolToken";
2
- import Collateral from "./Collateral";
3
- export default class AccountCollateral extends AccountPoolToken {
4
- poolToken: Collateral;
5
- collateralCache: {};
6
- cleanCache(): void;
7
- fixStakedLPExchangeRate(n: Promise<number>): Promise<number>;
8
- getAvailableBalanceUSD(): Promise<number>;
9
- getDepositedUSD(): Promise<number>;
10
- getMaxWithdrawable(): Promise<number>;
11
- }
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const interfaces_1 = require("./interfaces");
16
- const AccountPoolToken_1 = __importDefault(require("./AccountPoolToken"));
17
- class AccountCollateral extends AccountPoolToken_1.default {
18
- constructor() {
19
- super(...arguments);
20
- this.collateralCache = {};
21
- }
22
- cleanCache() {
23
- super.cleanCache();
24
- this.collateralCache = {};
25
- }
26
- fixStakedLPExchangeRate(n) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const stakedLPExchangeRate = yield this.poolToken.lendingPool.getStakedLPExchangeRate();
29
- return (yield n) / stakedLPExchangeRate;
30
- });
31
- }
32
- getAvailableBalanceUSD() {
33
- const _super = Object.create(null, {
34
- getAvailableBalanceUSD: { get: () => super.getAvailableBalanceUSD }
35
- });
36
- return __awaiter(this, void 0, void 0, function* () {
37
- return this.fixStakedLPExchangeRate(_super.getAvailableBalanceUSD.call(this));
38
- });
39
- }
40
- getDepositedUSD() {
41
- const _super = Object.create(null, {
42
- getDepositedUSD: { get: () => super.getDepositedUSD }
43
- });
44
- return __awaiter(this, void 0, void 0, function* () {
45
- return this.fixStakedLPExchangeRate(_super.getDepositedUSD.call(this));
46
- });
47
- }
48
- // Max Withdrawable
49
- getMaxWithdrawable() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const deposited = yield this.getDeposited();
52
- const availableCash = yield this.poolToken.getTotalBalance();
53
- const { valueCollateral, valueA, valueB } = yield this.accountLendingPool.getValues(interfaces_1.NO_CHANGES);
54
- const safetyMargin = (yield this.accountLendingPool.getSafetyMargin()) * this.getUiMargin();
55
- const liquidationPenalty = yield this.accountLendingPool.getLiquidationPenalty();
56
- const actualCollateral = valueCollateral / liquidationPenalty;
57
- const maxWithdrawable1 = (actualCollateral - (valueA + valueB * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty;
58
- const maxWithdrawable2 = (actualCollateral - (valueB + valueA * safetyMargin) / Math.sqrt(safetyMargin)) * liquidationPenalty;
59
- return Math.max(0, Math.min(deposited, availableCash, maxWithdrawable1, maxWithdrawable2) / this.getDust());
60
- });
61
- }
62
- }
63
- exports.default = AccountCollateral;
@@ -1,57 +0,0 @@
1
- import { Changes, PendingRewardUI, Values } from "./interfaces";
2
- import Account from "./Account";
3
- import AccountBorrowable from "./AccountBorrowable";
4
- import AccountCollateral from "./AccountCollateral";
5
- import LendingPool from "./LendingPool";
6
- import { PoolTokenType } from '../config/types';
7
- export default class AccountLendingPool {
8
- account: Account;
9
- lendingPool: LendingPool;
10
- accountPoolTokens: {
11
- [PoolTokenType.Collateral]: AccountCollateral;
12
- [PoolTokenType.BorrowableA]: AccountBorrowable;
13
- [PoolTokenType.BorrowableB]: AccountBorrowable;
14
- };
15
- cache: {
16
- availableReward?: Promise<PendingRewardUI[]>;
17
- oldAvailableReward?: Promise<number>;
18
- };
19
- constructor(account: Account, lendingPool: LendingPool);
20
- cleanCache(): void;
21
- pta: () => AccountBorrowable;
22
- ptb: () => AccountBorrowable;
23
- ptc: () => AccountCollateral;
24
- getSafetyMargin: () => Promise<number>;
25
- getLiquidationPenalty: () => Promise<number>;
26
- getUiMargin: () => number;
27
- getBalanceUSD(): Promise<number>;
28
- getSuppliedUSD(): Promise<number>;
29
- getDebtUSD(): Promise<number>;
30
- getEquityUSD(): Promise<number>;
31
- getLPEquityUSD(): Promise<number>;
32
- getLPEquity(): Promise<number>;
33
- getAccountAPR(): Promise<number>;
34
- getValuesFromPrice(changes: Changes, priceA: number, priceB: number): Promise<{
35
- valueCollateral: number;
36
- valueA: number;
37
- valueB: number;
38
- }>;
39
- getValues(changes: Changes): Promise<{
40
- valueCollateral: number;
41
- valueA: number;
42
- valueB: number;
43
- }>;
44
- getMarketValues(changes: Changes): Promise<{
45
- valueCollateral: number;
46
- valueA: number;
47
- valueB: number;
48
- }>;
49
- getLeverage(changes?: Changes): Promise<number>;
50
- getLiquidationPriceSwingsGivenValues(values: Values): Promise<[number, number]>;
51
- getLiquidationPricesGivenValues(values: Values): Promise<[number, number]>;
52
- getLiquidationPriceSwings(changes?: Changes): Promise<[number, number]>;
53
- getLiquidationPrices(changes?: Changes): Promise<[number, number]>;
54
- getMaxLeverage(): Promise<number>;
55
- getMaxDeleverage(slippage: number): Promise<number>;
56
- getAvailableReward(): Promise<PendingRewardUI[]>;
57
- }
@@ -1,266 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const interfaces_1 = require("./interfaces");
16
- const AccountBorrowable_1 = __importDefault(require("./AccountBorrowable"));
17
- const AccountCollateral_1 = __importDefault(require("./AccountCollateral"));
18
- const types_1 = require("../config/types");
19
- class AccountLendingPool {
20
- constructor(account, lendingPool) {
21
- this.cache = {};
22
- // Shortcuts
23
- this.pta = () => this.accountPoolTokens[types_1.PoolTokenType.BorrowableA];
24
- this.ptb = () => this.accountPoolTokens[types_1.PoolTokenType.BorrowableB];
25
- this.ptc = () => this.accountPoolTokens[types_1.PoolTokenType.Collateral];
26
- this.getSafetyMargin = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getSubgraphLendingPool()).getSafetyMargin(); });
27
- this.getLiquidationPenalty = () => __awaiter(this, void 0, void 0, function* () { return (yield this.lendingPool.getSubgraphLendingPool()).getLiquidationPenalty(); });
28
- this.getUiMargin = () => this.account.router.uiMargin;
29
- this.account = account;
30
- this.lendingPool = lendingPool;
31
- this.accountPoolTokens = {
32
- [types_1.PoolTokenType.Collateral]: new AccountCollateral_1.default(this, types_1.PoolTokenType.Collateral),
33
- [types_1.PoolTokenType.BorrowableA]: new AccountBorrowable_1.default(this, types_1.PoolTokenType.BorrowableA),
34
- [types_1.PoolTokenType.BorrowableB]: new AccountBorrowable_1.default(this, types_1.PoolTokenType.BorrowableB),
35
- };
36
- }
37
- cleanCache() {
38
- this.cache = {};
39
- this.pta().cleanCache();
40
- this.ptb().cleanCache();
41
- this.ptc().cleanCache();
42
- }
43
- // Balance
44
- getBalanceUSD() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const depositedAUSD = yield this.pta().getDepositedUSD();
47
- const depositedBUSD = yield this.ptb().getDepositedUSD();
48
- const depositedCUSD = yield this.ptc().getDepositedUSD();
49
- return depositedAUSD + depositedBUSD + depositedCUSD;
50
- });
51
- }
52
- // Supplied
53
- getSuppliedUSD() {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const depositedAUSD = yield this.pta().getDepositedUSD();
56
- const depositedBUSD = yield this.ptb().getDepositedUSD();
57
- return depositedAUSD + depositedBUSD;
58
- });
59
- }
60
- // Debt
61
- getDebtUSD() {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const borrowedAUSD = yield this.pta().getBorrowedUSD();
64
- const borrowedBUSD = yield this.ptb().getBorrowedUSD();
65
- return borrowedAUSD + borrowedBUSD;
66
- });
67
- }
68
- // Equity
69
- getEquityUSD() {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const balanceUSD = yield this.getBalanceUSD();
72
- const debtUSD = yield this.getDebtUSD();
73
- return balanceUSD - debtUSD;
74
- });
75
- }
76
- getLPEquityUSD() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const collateralUSD = yield this.ptc().getDepositedUSD();
79
- const debtUSD = yield this.getDebtUSD();
80
- return collateralUSD - debtUSD;
81
- });
82
- }
83
- getLPEquity() {
84
- return __awaiter(this, void 0, void 0, function* () {
85
- const lpEquityUSD = yield this.getLPEquityUSD();
86
- const tokenPrice = yield this.ptc().getTokenPriceAccurate();
87
- const stakedLPExchangeRate = yield this.lendingPool.getStakedLPExchangeRate();
88
- return lpEquityUSD / tokenPrice * stakedLPExchangeRate;
89
- });
90
- }
91
- // Debt
92
- getAccountAPR() {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const depositedAUSD = yield this.pta().getDepositedUSD();
95
- const depositedBUSD = yield this.ptb().getDepositedUSD();
96
- const totalSupplied = depositedAUSD + depositedBUSD;
97
- const supplyAPRA = yield this.pta().getSupplyAPR();
98
- const supplyAPRB = yield this.ptb().getSupplyAPR();
99
- return totalSupplied > 0 ? (depositedAUSD * supplyAPRA + depositedBUSD * supplyAPRB) / totalSupplied : 0;
100
- });
101
- }
102
- // Values
103
- getValuesFromPrice(changes, priceA, priceB) {
104
- return __awaiter(this, void 0, void 0, function* () {
105
- const valueCollateral = (yield this.ptc().getDeposited()) + changes.changeCollateral;
106
- const amountA = (yield this.pta().getBorrowed()) + changes.changeBorrowedA;
107
- const amountB = (yield this.ptb().getBorrowed()) + changes.changeBorrowedB;
108
- const valueA = amountA * priceA;
109
- const valueB = amountB * priceB;
110
- return {
111
- valueCollateral: valueCollateral > 0 ? valueCollateral : 0,
112
- valueA: valueA > 0 ? valueA : 0,
113
- valueB: valueB > 0 ? valueB : 0,
114
- };
115
- });
116
- }
117
- getValues(changes) {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- const [priceA, priceB] = yield this.lendingPool.getPriceDenomLP();
120
- return this.getValuesFromPrice(changes, priceA, priceB);
121
- });
122
- }
123
- getMarketValues(changes) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
126
- return this.getValuesFromPrice(changes, priceA, priceB);
127
- });
128
- }
129
- // Leverage
130
- getLeverage(changes) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- if (!changes)
133
- changes = interfaces_1.NO_CHANGES;
134
- const { valueCollateral, valueA, valueB } = yield this.getValues(changes);
135
- const valueDebt = valueA + valueB;
136
- if (valueDebt == 0)
137
- return 1;
138
- const equity = valueCollateral - valueDebt;
139
- if (equity <= 0)
140
- return Infinity;
141
- return valueDebt / equity + 1;
142
- });
143
- }
144
- // Liquidation Threshold
145
- getLiquidationPriceSwingsGivenValues(values) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- if (!values)
148
- return [Infinity, Infinity];
149
- const { valueCollateral, valueA, valueB } = values;
150
- if (valueA + valueB == 0)
151
- return [Infinity, Infinity];
152
- const safetyMargin = yield this.getSafetyMargin();
153
- const liquidationPenalty = yield this.getLiquidationPenalty();
154
- const actualCollateral = valueCollateral / liquidationPenalty;
155
- const rad = Math.sqrt(Math.pow(actualCollateral, 2) - 4 * valueA * valueB);
156
- if (!rad)
157
- return [0, 0];
158
- const t = (actualCollateral + rad) / (2 * Math.sqrt(safetyMargin));
159
- let priceSwingA = Math.pow((t / valueA), 2);
160
- let priceSwingB = Math.pow((t / valueB), 2);
161
- return [priceSwingA, priceSwingB];
162
- });
163
- }
164
- getLiquidationPricesGivenValues(values) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- const currentPrice = yield this.lendingPool.getTWAPPrice();
167
- const [priceSwingA, priceSwingB] = yield this.getLiquidationPriceSwingsGivenValues(values);
168
- return !this.account.router.priceInverted ? [currentPrice / priceSwingB, currentPrice * priceSwingA] : [currentPrice / priceSwingA, currentPrice * priceSwingB];
169
- });
170
- }
171
- getLiquidationPriceSwings(changes) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- const values = yield this.getValues(changes);
174
- return this.getLiquidationPriceSwingsGivenValues(values);
175
- });
176
- }
177
- getLiquidationPrices(changes) {
178
- return __awaiter(this, void 0, void 0, function* () {
179
- if (!changes)
180
- changes = interfaces_1.NO_CHANGES;
181
- const values = yield this.getValues(changes);
182
- return this.getLiquidationPricesGivenValues(values);
183
- });
184
- }
185
- // Max Leverage
186
- getMaxLeverage() {
187
- return __awaiter(this, void 0, void 0, function* () {
188
- const availableCashA = yield this.pta().poolToken.getTotalBalance();
189
- const availableCashB = yield this.ptb().poolToken.getTotalBalance();
190
- const [priceA, priceB] = yield this.lendingPool.getMarketPriceDenomLP();
191
- const [priceATWAP,] = yield this.lendingPool.getPriceDenomLP();
192
- const diff = priceA > priceATWAP ? priceA / priceATWAP : priceATWAP / priceA;
193
- const adjustFactor = 1 / diff;
194
- const availableCashValue1 = availableCashA * priceA;
195
- const availableCashValue2 = availableCashB * priceB;
196
- const { valueCollateral, valueA, valueB } = yield this.getValues(interfaces_1.NO_CHANGES);
197
- const safetyMargin = (yield this.getSafetyMargin()) * this.getUiMargin();
198
- const liquidationPenalty = yield this.getLiquidationPenalty();
199
- const actualCollateral = valueCollateral / liquidationPenalty;
200
- const num1 = actualCollateral * Math.sqrt(safetyMargin) - valueA * safetyMargin - valueB;
201
- const num2 = actualCollateral * Math.sqrt(safetyMargin) - valueB * safetyMargin - valueA;
202
- const den = safetyMargin + 1 - 2 * Math.sqrt(safetyMargin) / liquidationPenalty;
203
- const additionalValueBorrowablePerSide = Math.min(num1 / den, num2 / den, availableCashValue1, availableCashValue2) * adjustFactor;
204
- const valueDebt = valueA + valueB;
205
- const equity = valueCollateral - valueDebt;
206
- if (equity == 0)
207
- return 1;
208
- return (valueDebt + additionalValueBorrowablePerSide * 2) / equity + 1;
209
- });
210
- }
211
- // Max Deleverage
212
- getMaxDeleverage(slippage) {
213
- return __awaiter(this, void 0, void 0, function* () {
214
- const { valueCollateral, valueA, valueB } = yield this.getMarketValues(interfaces_1.NO_CHANGES);
215
- const minRepayPerSide = valueCollateral / 2 / Math.sqrt(slippage);
216
- if (minRepayPerSide >= valueA && minRepayPerSide >= valueB) {
217
- return this.ptc().getDeposited();
218
- }
219
- if (minRepayPerSide * 2 < valueA + valueB) {
220
- return 0;
221
- }
222
- return Math.min(valueA, valueB) * 2 * Math.sqrt(slippage);
223
- });
224
- }
225
- // Available Reward
226
- getAvailableReward() {
227
- return __awaiter(this, void 0, void 0, function* () {
228
- const result = [];
229
- const imxAmount = (yield this.pta().getAvailableIMXReward()) + (yield this.ptb().getAvailableIMXReward());
230
- if (imxAmount > 0)
231
- result.push({
232
- symbol: "IMX",
233
- amount: imxAmount
234
- });
235
- const symbols = [
236
- yield this.pta().poolToken.getRewarderTokenSymbol(),
237
- yield this.ptb().poolToken.getRewarderTokenSymbol()
238
- ];
239
- const rewarderAmounts = [
240
- yield this.pta().getAvailableRewarderReward(),
241
- yield this.ptb().getAvailableRewarderReward()
242
- ];
243
- if (symbols[0] === symbols[1]) {
244
- const rewarderAmount = rewarderAmounts[0] + rewarderAmounts[1];
245
- if (rewarderAmount === 0)
246
- return result;
247
- result.push({
248
- symbol: symbols[0],
249
- amount: rewarderAmount
250
- });
251
- }
252
- else {
253
- for (let i = 0; i < 2; i++) {
254
- if (rewarderAmounts[i] === 0)
255
- continue;
256
- result.push({
257
- symbol: symbols[i],
258
- amount: rewarderAmounts[i]
259
- });
260
- }
261
- }
262
- return result;
263
- });
264
- }
265
- }
266
- exports.default = AccountLendingPool;
@@ -1,29 +0,0 @@
1
- import AccountLendingPool from "./AccountLendingPool";
2
- import PoolToken from "./PoolToken";
3
- import { PoolTokenType } from '../config/types';
4
- export default class AccountPoolToken {
5
- accountLendingPool: AccountLendingPool;
6
- poolToken: PoolToken;
7
- cache: {
8
- availableBalance?: Promise<number>;
9
- deposited?: Promise<number>;
10
- };
11
- constructor(accountLendingPool: AccountLendingPool, poolTokenType: PoolTokenType);
12
- cleanCache(): void;
13
- getAccount: () => string;
14
- getNetwrok: () => import("../config/types").Networks;
15
- getEth: () => any;
16
- getDust: () => number;
17
- getUiMargin: () => number;
18
- getTokenPriceAccurate: () => Promise<number>;
19
- getSupplyAPR: () => Promise<number>;
20
- getBorrowRate: () => Promise<number>;
21
- getAccrualTimestamp: () => Promise<number>;
22
- private initializeAvailableBalance;
23
- getAvailableBalance(): Promise<number>;
24
- getAvailableBalanceUSD(): Promise<number>;
25
- private initializeDeposited;
26
- getDeposited(): Promise<number>;
27
- getDepositedUSD(): Promise<number>;
28
- getMaxWithdrawable(): Promise<number>;
29
- }
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const weths_1 = require("../config/contracts/weths");
13
- class AccountPoolToken {
14
- constructor(accountLendingPool, poolTokenType) {
15
- this.cache = {};
16
- // Shortcuts
17
- this.getAccount = () => this.accountLendingPool.account.account;
18
- this.getNetwrok = () => this.accountLendingPool.account.router.network;
19
- this.getEth = () => this.accountLendingPool.account.router.web3.eth;
20
- this.getDust = () => this.accountLendingPool.account.router.dust;
21
- this.getUiMargin = () => this.accountLendingPool.account.router.uiMargin;
22
- this.getTokenPriceAccurate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getTokenPriceAccurate(); });
23
- this.getSupplyAPR = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getSupplyAPR(); });
24
- this.getBorrowRate = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getBorrowRate(); });
25
- this.getAccrualTimestamp = () => __awaiter(this, void 0, void 0, function* () { return (yield this.poolToken.getSubgraphPoolToken()).getAccrualTimestamp(); });
26
- this.accountLendingPool = accountLendingPool;
27
- this.poolToken = accountLendingPool.lendingPool.poolTokens[poolTokenType];
28
- }
29
- cleanCache() {
30
- this.cache = {};
31
- }
32
- // Available Balance
33
- initializeAvailableBalance() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const token = yield this.poolToken.getToken();
36
- if (token._address.toLowerCase() == weths_1.WETH[this.getNetwrok()].toLowerCase()) {
37
- return (yield this.getEth().getBalance(this.getAccount())) / 1e18 / this.getDust();
38
- }
39
- const balance = yield token.methods.balanceOf(this.getAccount()).call();
40
- return (yield this.poolToken.normalize(balance)) / this.getDust();
41
- });
42
- }
43
- getAvailableBalance() {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (!this.cache.availableBalance)
46
- this.cache.availableBalance = this.initializeAvailableBalance();
47
- return this.cache.availableBalance;
48
- });
49
- }
50
- getAvailableBalanceUSD() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const availableBalance = yield this.getAvailableBalance();
53
- const tokenPrice = yield this.getTokenPriceAccurate();
54
- return availableBalance * tokenPrice;
55
- });
56
- }
57
- // Deposited
58
- initializeDeposited() {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- const poolToken = yield this.poolToken.getPoolToken();
61
- const exchangeRate = yield this.poolToken.getExchangeRate();
62
- const balance = yield poolToken.methods.balanceOf(this.getAccount()).call();
63
- return (yield this.poolToken.normalize(balance)) * exchangeRate;
64
- });
65
- }
66
- getDeposited() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- if (!this.cache.deposited)
69
- this.cache.deposited = this.initializeDeposited();
70
- return this.cache.deposited;
71
- });
72
- }
73
- getDepositedUSD() {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const deposited = yield this.getDeposited();
76
- const tokenPrice = yield this.getTokenPriceAccurate();
77
- return deposited * tokenPrice;
78
- });
79
- }
80
- // Max Withdrawable
81
- getMaxWithdrawable() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- const deposited = yield this.getDeposited();
84
- const availableCash = yield this.poolToken.getTotalBalance();
85
- return Math.min(deposited, availableCash) / this.getDust();
86
- });
87
- }
88
- }
89
- exports.default = AccountPoolToken;