impermax-sdk 2.1.64 → 2.1.69

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 (25) hide show
  1. package/lib/config/private-api.js +3 -1
  2. package/lib/offchain/account/offchainMultichainAccount.d.ts +7 -0
  3. package/lib/offchain/account/offchainMultichainAccount.js +31 -1
  4. package/lib/onchain/account/lendingPool/onchainAccountBorrowable.d.ts +1 -16
  5. package/lib/onchain/account/lendingPool/onchainAccountBorrowable.js +0 -84
  6. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.d.ts +15 -0
  7. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV2.js +85 -0
  8. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.d.ts +8 -1
  9. package/lib/onchain/account/lendingPool/onchainAccountBorrowableV3.js +22 -2
  10. package/lib/onchain/account/lendingPool/onchainAccountCollateral.d.ts +0 -1
  11. package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.d.ts +1 -1
  12. package/lib/onchain/account/lendingPool/onchainAccountCollateralV3.js +1 -1
  13. package/lib/onchain/account/lendingPool/onchainAccountLendingPool.d.ts +0 -6
  14. package/lib/onchain/account/lendingPool/onchainAccountLendingPool.js +0 -74
  15. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.d.ts +4 -0
  16. package/lib/onchain/account/lendingPool/onchainAccountLendingPoolV2.js +32 -0
  17. package/lib/onchain/account/onchainAccount.d.ts +2 -3
  18. package/lib/onchain/account/onchainAccount.js +23 -25
  19. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.d.ts +0 -1
  20. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPool.js +0 -23
  21. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.d.ts +1 -0
  22. package/lib/onchain/interactions/lendingPool/onchainInteractionsLendingPoolV2.js +14 -0
  23. package/lib/onchain/interactions/onchainInteractions.d.ts +1 -2
  24. package/lib/onchain/interactions/onchainInteractions.js +39 -35
  25. package/package.json +1 -1
@@ -59,6 +59,8 @@ exports.IMPERMAX_VAULT_API = {
59
59
  [types_1.Networks.Blast]: {
60
60
  [types_1.VaultType.LENDING]: "https://blast-lendingvaults-production.up.railway.app/vaults/"
61
61
  },
62
- [types_1.Networks.Sonic]: {},
62
+ [types_1.Networks.Sonic]: {
63
+ [types_1.VaultType.LENDING]: "https://sonic-lendingvaults-production.up.railway.app/vaults/"
64
+ },
63
65
  };
64
66
  // Add more here
@@ -15,9 +15,15 @@ export declare enum SupplyPositionsOrderBy {
15
15
  export declare enum VaultPositionsOrderBy {
16
16
  TVL = 0
17
17
  }
18
+ export declare enum BorrowPositionsOrderBy {
19
+ TVL = 0
20
+ }
18
21
  export interface SupplyPositionsParams {
19
22
  networks?: Array<Networks>;
20
23
  }
24
+ export interface BorrowPositionsParams {
25
+ networks?: Array<Networks>;
26
+ }
21
27
  export interface VaultPositionsParams {
22
28
  networks?: Array<Networks>;
23
29
  }
@@ -47,6 +53,7 @@ export default class OffchainMultichainAccount {
47
53
  getOffchainAccount(network: Networks): OffchainAccount;
48
54
  getLeveragedPositions(params?: LeveragedPositionsParams, orderBy?: LeveragedPositionsOrderBy): Promise<Array<OffchainLeveragedPosition>>;
49
55
  getSupplyPositions(params?: SupplyPositionsParams, orderBy?: SupplyPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
56
+ getBorrowPositions(params?: BorrowPositionsParams, orderBy?: BorrowPositionsOrderBy): Promise<Array<OffchainAccountLendingPool>>;
50
57
  getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
51
58
  getTopPositions(params?: TopPositionsParams): Promise<Array<AccountPosition>>;
52
59
  getTotalBalanceUSD(): Promise<number>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.PositionType = exports.VaultPositionsOrderBy = exports.SupplyPositionsOrderBy = exports.LeveragedPositionsOrderBy = void 0;
12
+ exports.PositionType = exports.BorrowPositionsOrderBy = exports.VaultPositionsOrderBy = exports.SupplyPositionsOrderBy = exports.LeveragedPositionsOrderBy = void 0;
13
13
  const types_1 = require("../../config/types");
14
14
  var LeveragedPositionsOrderBy;
15
15
  (function (LeveragedPositionsOrderBy) {
@@ -23,6 +23,10 @@ var VaultPositionsOrderBy;
23
23
  (function (VaultPositionsOrderBy) {
24
24
  VaultPositionsOrderBy[VaultPositionsOrderBy["TVL"] = 0] = "TVL";
25
25
  })(VaultPositionsOrderBy = exports.VaultPositionsOrderBy || (exports.VaultPositionsOrderBy = {}));
26
+ var BorrowPositionsOrderBy;
27
+ (function (BorrowPositionsOrderBy) {
28
+ BorrowPositionsOrderBy[BorrowPositionsOrderBy["TVL"] = 0] = "TVL";
29
+ })(BorrowPositionsOrderBy = exports.BorrowPositionsOrderBy || (exports.BorrowPositionsOrderBy = {}));
26
30
  var PositionType;
27
31
  (function (PositionType) {
28
32
  PositionType["MARKET"] = "Market";
@@ -75,6 +79,32 @@ class OffchainMultichainAccount {
75
79
  return results.flat();
76
80
  });
77
81
  }
82
+ // NOTE: Should this return OffchainCollateral?
83
+ getBorrowPositions(params = {}, orderBy = BorrowPositionsOrderBy.TVL) {
84
+ var _a;
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const allNetworks = (_a = params.networks) !== null && _a !== void 0 ? _a : Object.values(types_1.Networks);
87
+ // Get user supply positions in each network
88
+ const networkPromises = allNetworks.map((network) => __awaiter(this, void 0, void 0, function* () {
89
+ const offchainAccount = this.getOffchainAccount(network);
90
+ const userData = yield offchainAccount.getUserData();
91
+ if (!userData)
92
+ return [];
93
+ const positions = [];
94
+ // Get network positions in each factory
95
+ const borrowPositions = yield offchainAccount.getBorrowPositions();
96
+ for (const factory in borrowPositions) {
97
+ const poolsOfFactory = borrowPositions[factory];
98
+ for (const poolAddress of poolsOfFactory) {
99
+ positions.push(offchainAccount.getLendingPool(factory, poolAddress));
100
+ }
101
+ }
102
+ return Promise.all(positions);
103
+ }));
104
+ const results = yield Promise.all(networkPromises);
105
+ return results.flat();
106
+ });
107
+ }
78
108
  getVaultPositions(params = {}, orderBy = VaultPositionsOrderBy.TVL) {
79
109
  var _a;
80
110
  return __awaiter(this, void 0, void 0, function* () {
@@ -7,12 +7,7 @@ import OffchainAccountBorrowable from '../../../offchain/account/lendingPool/off
7
7
  export default abstract class OnchainAccountBorrowable extends OnchainAccountPoolToken {
8
8
  protected readonly lendingPool: OnchainAccountLendingPool;
9
9
  protected readonly poolToken: OnchainBorrowable;
10
- protected borrowableCache: {
11
- borrowed?: Promise<number>;
12
- farmingShares?: Promise<number>;
13
- availableFarmingReward?: Promise<number>;
14
- availableRewarderReward?: Promise<number>;
15
- };
10
+ protected borrowableCache: {};
16
11
  constructor(lendingPool: OnchainAccountLendingPool, borrowable: Borrowable);
17
12
  getLendingPool: () => OnchainAccountLendingPool;
18
13
  getPoolToken: () => OnchainBorrowable;
@@ -26,14 +21,4 @@ export default abstract class OnchainAccountBorrowable extends OnchainAccountPoo
26
21
  getSupplyAPR: () => Promise<number>;
27
22
  getBorrowRate: () => Promise<number>;
28
23
  getAccrualTimestamp: () => Promise<number>;
29
- private initializeBorrowed;
30
- getBorrowed(): Promise<number>;
31
- getBorrowedUSD(): Promise<number>;
32
- abstract getMaxBorrowable(): Promise<number>;
33
- private initializeFarmingShares;
34
- getFarmingShares(): Promise<number>;
35
- private initializeAvailableFarmingReward;
36
- getAvailableFarmingReward(): Promise<number>;
37
- private initializeAvailableRewarderReward;
38
- getAvailableRewarderReward(): Promise<number>;
39
24
  }
@@ -43,89 +43,5 @@ class OnchainAccountBorrowable extends onchainAccountPoolToken_1.default {
43
43
  super.cleanCache();
44
44
  this.borrowableCache = {};
45
45
  }
46
- // Borrowed
47
- initializeBorrowed() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const borrowable = yield this.poolToken.getPoolToken();
50
- const balance = yield borrowable.methods.borrowBalance(this.getAccountAddress()).call();
51
- const storedAmount = yield yield this.poolToken.normalize(balance);
52
- const accrualTimestamp = yield this.getAccrualTimestamp();
53
- const borrowRate = yield this.getBorrowRate();
54
- return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
55
- });
56
- }
57
- getBorrowed() {
58
- return __awaiter(this, void 0, void 0, function* () {
59
- if (!this.borrowableCache.borrowed)
60
- this.borrowableCache.borrowed = this.initializeBorrowed();
61
- return this.borrowableCache.borrowed;
62
- });
63
- }
64
- getBorrowedUSD() {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const borrowed = yield this.getBorrowed();
67
- const tokenPrice = yield this.getTokenPriceAccurate();
68
- return borrowed * tokenPrice;
69
- });
70
- }
71
- // Farming Shares
72
- initializeFarmingShares() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- if (!(yield this.poolToken.hasImpermaxChef()))
75
- return 0;
76
- return (yield this.poolToken.getImpermaxChef().methods.userInfo(yield this.poolToken.getPoolTokenAddress(), this.getAccountAddress()).call()).shares;
77
- });
78
- }
79
- getFarmingShares() {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (!this.borrowableCache.farmingShares)
82
- this.borrowableCache.farmingShares = this.initializeFarmingShares();
83
- return this.borrowableCache.farmingShares;
84
- });
85
- }
86
- // Available Reward
87
- initializeAvailableFarmingReward() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- if (!(yield this.poolToken.hasImpermaxChef()))
90
- return 0;
91
- const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
92
- try {
93
- return (yield this.poolToken.getImpermaxChef().methods.pendingReward(borrowableAddress, this.getAccountAddress()).call()) / 1e18;
94
- }
95
- catch (_a) {
96
- console.log("Warning: pending reward negative");
97
- return 0;
98
- }
99
- });
100
- }
101
- getAvailableFarmingReward() {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- if (!this.borrowableCache.availableFarmingReward)
104
- this.borrowableCache.availableFarmingReward = this.initializeAvailableFarmingReward();
105
- return this.borrowableCache.availableFarmingReward;
106
- });
107
- }
108
- initializeAvailableRewarderReward() {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- if (!(yield this.poolToken.hasRewarder()))
111
- return 0;
112
- const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
113
- const rewarder = yield this.poolToken.getRewarder();
114
- try {
115
- return (yield rewarder.methods.pendingReward(borrowableAddress, this.getAccountAddress()).call()) / 1e18;
116
- }
117
- catch (_a) {
118
- console.log("Warning: pending reward negative");
119
- return 0;
120
- }
121
- });
122
- }
123
- getAvailableRewarderReward() {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- if (!this.borrowableCache.availableRewarderReward)
126
- this.borrowableCache.availableRewarderReward = this.initializeAvailableRewarderReward();
127
- return this.borrowableCache.availableRewarderReward;
128
- });
129
- }
130
46
  }
131
47
  exports.default = OnchainAccountBorrowable;
@@ -4,7 +4,22 @@ import { OnchainBorrowableV2 } from "../../impermaxFactory/lendingPool";
4
4
  export default class OnchainAccountBorrowableV2 extends OnchainAccountBorrowable {
5
5
  protected readonly lendingPool: OnchainAccountLendingPoolV2;
6
6
  protected readonly poolToken: OnchainBorrowableV2;
7
+ protected borrowableCache: {
8
+ borrowed?: Promise<number>;
9
+ farmingShares?: Promise<number>;
10
+ availableFarmingReward?: Promise<number>;
11
+ availableRewarderReward?: Promise<number>;
12
+ };
7
13
  getLendingPool: () => OnchainAccountLendingPoolV2;
8
14
  getPoolToken: () => OnchainBorrowableV2;
15
+ private initializeBorrowed;
16
+ getBorrowed(): Promise<number>;
17
+ getBorrowedUSD(): Promise<number>;
9
18
  getMaxBorrowable(): Promise<number>;
19
+ private initializeFarmingShares;
20
+ getFarmingShares(): Promise<number>;
21
+ private initializeAvailableFarmingReward;
22
+ getAvailableFarmingReward(): Promise<number>;
23
+ private initializeAvailableRewarderReward;
24
+ getAvailableRewarderReward(): Promise<number>;
10
25
  }
@@ -17,9 +17,35 @@ const onchainAccountBorrowable_1 = __importDefault(require("./onchainAccountBorr
17
17
  class OnchainAccountBorrowableV2 extends onchainAccountBorrowable_1.default {
18
18
  constructor() {
19
19
  super(...arguments);
20
+ this.borrowableCache = {};
20
21
  this.getLendingPool = () => this.lendingPool;
21
22
  this.getPoolToken = () => this.poolToken;
22
23
  }
24
+ // Borrowed
25
+ initializeBorrowed() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const borrowable = yield this.poolToken.getPoolToken();
28
+ const balance = yield borrowable.methods.borrowBalance(this.getAccountAddress()).call();
29
+ const storedAmount = yield yield this.poolToken.normalize(balance);
30
+ const accrualTimestamp = yield this.getAccrualTimestamp();
31
+ const borrowRate = yield this.getBorrowRate();
32
+ return storedAmount * (1 + (Date.now() / 1000 - accrualTimestamp) * borrowRate);
33
+ });
34
+ }
35
+ getBorrowed() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ if (!this.borrowableCache.borrowed)
38
+ this.borrowableCache.borrowed = this.initializeBorrowed();
39
+ return this.borrowableCache.borrowed;
40
+ });
41
+ }
42
+ getBorrowedUSD() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const borrowed = yield this.getBorrowed();
45
+ const tokenPrice = yield this.getTokenPriceAccurate();
46
+ return borrowed * tokenPrice;
47
+ });
48
+ }
23
49
  // Max OffchainBorrowable
24
50
  // binary search approach
25
51
  getMaxBorrowable() {
@@ -51,5 +77,64 @@ class OnchainAccountBorrowableV2 extends onchainAccountBorrowable_1.default {
51
77
  return bestAmount;
52
78
  });
53
79
  }
80
+ // Farming Shares
81
+ initializeFarmingShares() {
82
+ return __awaiter(this, void 0, void 0, function* () {
83
+ if (!(yield this.poolToken.hasImpermaxChef()))
84
+ return 0;
85
+ return (yield this.poolToken.getImpermaxChef().methods.userInfo(yield this.poolToken.getPoolTokenAddress(), this.getAccountAddress()).call()).shares;
86
+ });
87
+ }
88
+ getFarmingShares() {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ if (!this.borrowableCache.farmingShares)
91
+ this.borrowableCache.farmingShares = this.initializeFarmingShares();
92
+ return this.borrowableCache.farmingShares;
93
+ });
94
+ }
95
+ // Available Reward
96
+ initializeAvailableFarmingReward() {
97
+ return __awaiter(this, void 0, void 0, function* () {
98
+ if (!(yield this.poolToken.hasImpermaxChef()))
99
+ return 0;
100
+ const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
101
+ try {
102
+ return (yield this.poolToken.getImpermaxChef().methods.pendingReward(borrowableAddress, this.getAccountAddress()).call()) / 1e18;
103
+ }
104
+ catch (_a) {
105
+ console.log("Warning: pending reward negative");
106
+ return 0;
107
+ }
108
+ });
109
+ }
110
+ getAvailableFarmingReward() {
111
+ return __awaiter(this, void 0, void 0, function* () {
112
+ if (!this.borrowableCache.availableFarmingReward)
113
+ this.borrowableCache.availableFarmingReward = this.initializeAvailableFarmingReward();
114
+ return this.borrowableCache.availableFarmingReward;
115
+ });
116
+ }
117
+ initializeAvailableRewarderReward() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ if (!(yield this.poolToken.hasRewarder()))
120
+ return 0;
121
+ const borrowableAddress = yield this.poolToken.getPoolTokenAddress();
122
+ const rewarder = yield this.poolToken.getRewarder();
123
+ try {
124
+ return (yield rewarder.methods.pendingReward(borrowableAddress, this.getAccountAddress()).call()) / 1e18;
125
+ }
126
+ catch (_a) {
127
+ console.log("Warning: pending reward negative");
128
+ return 0;
129
+ }
130
+ });
131
+ }
132
+ getAvailableRewarderReward() {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ if (!this.borrowableCache.availableRewarderReward)
135
+ this.borrowableCache.availableRewarderReward = this.initializeAvailableRewarderReward();
136
+ return this.borrowableCache.availableRewarderReward;
137
+ });
138
+ }
54
139
  }
55
140
  exports.default = OnchainAccountBorrowableV2;
@@ -4,7 +4,14 @@ import OnchainAccountLendingPoolV3 from "./onchainAccountLendingPoolV3";
4
4
  export default class OnchainAccountBorrowableV3 extends OnchainAccountBorrowable {
5
5
  protected readonly lendingPool: OnchainAccountLendingPoolV3;
6
6
  protected readonly poolToken: OnchainBorrowableV3;
7
+ protected borrowableCache: {
8
+ borrowed?: {
9
+ [keys in number]: Promise<number>;
10
+ };
11
+ };
7
12
  getLendingPool: () => OnchainAccountLendingPoolV3;
8
13
  getPoolToken: () => OnchainBorrowableV3;
9
- getMaxBorrowable(): Promise<number>;
14
+ private initializeBorrowed;
15
+ getBorrowed(tokenId: number): Promise<number>;
16
+ getBorrowedUSD(tokenId: number): Promise<number>;
10
17
  }
@@ -16,12 +16,32 @@ const onchainAccountBorrowable_1 = __importDefault(require("./onchainAccountBorr
16
16
  class OnchainAccountBorrowableV3 extends onchainAccountBorrowable_1.default {
17
17
  constructor() {
18
18
  super(...arguments);
19
+ this.borrowableCache = {};
19
20
  this.getLendingPool = () => this.lendingPool;
20
21
  this.getPoolToken = () => this.poolToken;
21
22
  }
22
- getMaxBorrowable() {
23
+ // Borrowed
24
+ initializeBorrowed(tokenId) {
23
25
  return __awaiter(this, void 0, void 0, function* () {
24
- return 0;
26
+ const borrowable = yield this.poolToken.getPoolToken();
27
+ const balance = yield borrowable.methods.currentBorrowBalance(tokenId).call();
28
+ return this.poolToken.normalize(balance);
29
+ });
30
+ }
31
+ getBorrowed(tokenId) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ if (!this.borrowableCache.borrowed)
34
+ this.borrowableCache.borrowed = {};
35
+ if (!this.borrowableCache.borrowed[tokenId])
36
+ this.borrowableCache.borrowed[tokenId] = this.initializeBorrowed(tokenId);
37
+ return this.borrowableCache.borrowed[tokenId];
38
+ });
39
+ }
40
+ getBorrowedUSD(tokenId) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const borrowed = yield this.getBorrowed(tokenId);
43
+ const tokenPrice = yield this.getTokenPriceAccurate();
44
+ return borrowed * tokenPrice;
25
45
  });
26
46
  }
27
47
  }
@@ -6,5 +6,4 @@ export default abstract class OnchainAccountCollateral {
6
6
  getAccount: () => import("..").default;
7
7
  getInteractionsCollateral(): import("../../..").OnchainInteractionsCollateral;
8
8
  getOffchainAccountCollateral(): Promise<OffchainAccountCollateral>;
9
- abstract getDepositedUSD(): Promise<number>;
10
9
  }
@@ -17,5 +17,5 @@ export default class OnchainAccountCollateralV3 extends OnchainAccountCollateral
17
17
  getInteractionsCollateral(): OnchainInteractionsCollateralV3;
18
18
  getOffchainAccountCollateral(): Promise<OffchainAccountCollateral>;
19
19
  cleanCache(): void;
20
- getDepositedUSD(): Promise<number>;
20
+ getDepositedUSD(tokenId: number): Promise<number>;
21
21
  }
@@ -37,7 +37,7 @@ class OnchainAccountCollateralV3 extends onchainAccountCollateral_1.default {
37
37
  cleanCache() {
38
38
  this.collateralCache = {};
39
39
  }
40
- getDepositedUSD() {
40
+ getDepositedUSD(tokenId) {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  return 0;
43
43
  });
@@ -2,7 +2,6 @@ import OnchainAccount from '../index';
2
2
  import { Borrowable } from '../../../config/types';
3
3
  import OnchainAccountCollateral from './onchainAccountCollateral';
4
4
  import OnchainAccountBorrowable from './onchainAccountBorrowable';
5
- import { PendingRewardUI } from '../../onchainTypes';
6
5
  import OnchainLendingPool from '../../impermaxFactory/lendingPool';
7
6
  import OnchainInteractionsLendingPool from '../../interactions/lendingPool';
8
7
  import OffchainAccountLendingPool from '../../../offchain/account/lendingPool';
@@ -32,11 +31,6 @@ export default abstract class OnchainAccountLendingPool {
32
31
  getUiMargin: () => number;
33
32
  getInteractionsLendingPool(): OnchainInteractionsLendingPool;
34
33
  getOffchainAccountLendingPool(): Promise<OffchainAccountLendingPool>;
35
- getBalanceUSD(): Promise<number>;
36
34
  getSuppliedUSD(): Promise<number>;
37
- getDebtUSD(): Promise<number>;
38
- getEquityUSD(): Promise<number>;
39
- getLPEquityUSD(): Promise<number>;
40
35
  getAccountAPR(): Promise<number>;
41
- getAvailableReward(): Promise<PendingRewardUI[]>;
42
36
  }
@@ -45,15 +45,6 @@ class OnchainAccountLendingPool {
45
45
  getOffchainAccountLendingPool() {
46
46
  return this.account.getOffchainAccount().getLendingPool(this.getFactory(), this.getId());
47
47
  }
48
- // Balance
49
- getBalanceUSD() {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const depositedAUSD = yield this.getBorrowableA().getDepositedUSD();
52
- const depositedBUSD = yield this.getBorrowableB().getDepositedUSD();
53
- const depositedCUSD = yield this.getCollateral().getDepositedUSD();
54
- return depositedAUSD + depositedBUSD + depositedCUSD;
55
- });
56
- }
57
48
  // Supplied
58
49
  getSuppliedUSD() {
59
50
  return __awaiter(this, void 0, void 0, function* () {
@@ -62,29 +53,6 @@ class OnchainAccountLendingPool {
62
53
  return depositedAUSD + depositedBUSD;
63
54
  });
64
55
  }
65
- // Debt
66
- getDebtUSD() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const borrowedAUSD = yield this.getBorrowableA().getBorrowedUSD();
69
- const borrowedBUSD = yield this.getBorrowableB().getBorrowedUSD();
70
- return borrowedAUSD + borrowedBUSD;
71
- });
72
- }
73
- // Equity
74
- getEquityUSD() {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const balanceUSD = yield this.getBalanceUSD();
77
- const debtUSD = yield this.getDebtUSD();
78
- return balanceUSD - debtUSD;
79
- });
80
- }
81
- getLPEquityUSD() {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- const collateralUSD = yield this.getCollateral().getDepositedUSD();
84
- const debtUSD = yield this.getDebtUSD();
85
- return collateralUSD - debtUSD;
86
- });
87
- }
88
56
  // APR
89
57
  getAccountAPR() {
90
58
  return __awaiter(this, void 0, void 0, function* () {
@@ -96,47 +64,5 @@ class OnchainAccountLendingPool {
96
64
  return totalSupplied > 0 ? (depositedAUSD * supplyAPRA + depositedBUSD * supplyAPRB) / totalSupplied : 0;
97
65
  });
98
66
  }
99
- // Available Reward
100
- getAvailableReward() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- const result = [];
103
- const farmingAmount = (yield this.getBorrowableA().getAvailableFarmingReward()) + (yield this.getBorrowableB().getAvailableFarmingReward());
104
- if (farmingAmount > 0) {
105
- const farmingSymbol = yield this.getBorrowableA().getPoolToken().getFarmingTokenSymbol();
106
- result.push({
107
- symbol: farmingSymbol,
108
- amount: farmingAmount
109
- });
110
- }
111
- const rewarderSymbols = [
112
- yield this.getBorrowableA().getPoolToken().getRewarderTokenSymbol(),
113
- yield this.getBorrowableB().getPoolToken().getRewarderTokenSymbol()
114
- ];
115
- const rewarderAmounts = [
116
- yield this.getBorrowableA().getAvailableRewarderReward(),
117
- yield this.getBorrowableB().getAvailableRewarderReward()
118
- ];
119
- if (rewarderSymbols[0] === rewarderSymbols[1]) {
120
- const rewarderAmount = rewarderAmounts[0] + rewarderAmounts[1];
121
- if (rewarderAmount === 0)
122
- return result;
123
- result.push({
124
- symbol: rewarderSymbols[0],
125
- amount: rewarderAmount
126
- });
127
- }
128
- else {
129
- for (let i = 0; i < 2; i++) {
130
- if (rewarderAmounts[i] === 0)
131
- continue;
132
- result.push({
133
- symbol: rewarderSymbols[i],
134
- amount: rewarderAmounts[i]
135
- });
136
- }
137
- }
138
- return result;
139
- });
140
- }
141
67
  }
142
68
  exports.default = OnchainAccountLendingPool;
@@ -20,6 +20,10 @@ export default class OnchainAccountLendingPoolV2 extends OnchainAccountLendingPo
20
20
  getBorrowableB: () => OnchainAccountBorrowableV2;
21
21
  getCollateral: () => OnchainAccountCollateralV2;
22
22
  getInteractionsLendingPool(): OnchainInteractionsLendingPoolV2;
23
+ getBalanceUSD(): Promise<number>;
24
+ getDebtUSD(): Promise<number>;
25
+ getEquityUSD(): Promise<number>;
26
+ getLPEquityUSD(): Promise<number>;
23
27
  getLPEquity(): Promise<number>;
24
28
  getValuesFromPrice(changes: Changes, priceA: number, priceB: number): Promise<{
25
29
  valueCollateral: number;
@@ -39,6 +39,38 @@ class OnchainAccountLendingPoolV2 extends onchainAccountLendingPool_1.default {
39
39
  getInteractionsLendingPool() {
40
40
  return this.account.getInteractions().getLendingPool(this.getFactory(), this.getId());
41
41
  }
42
+ // Balance
43
+ getBalanceUSD() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const depositedAUSD = yield this.getBorrowableA().getDepositedUSD();
46
+ const depositedBUSD = yield this.getBorrowableB().getDepositedUSD();
47
+ const depositedCUSD = yield this.getCollateral().getDepositedUSD();
48
+ return depositedAUSD + depositedBUSD + depositedCUSD;
49
+ });
50
+ }
51
+ // Debt
52
+ getDebtUSD() {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ const borrowedAUSD = yield this.getBorrowableA().getBorrowedUSD();
55
+ const borrowedBUSD = yield this.getBorrowableB().getBorrowedUSD();
56
+ return borrowedAUSD + borrowedBUSD;
57
+ });
58
+ }
59
+ // Equity
60
+ getEquityUSD() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const balanceUSD = yield this.getBalanceUSD();
63
+ const debtUSD = yield this.getDebtUSD();
64
+ return balanceUSD - debtUSD;
65
+ });
66
+ }
67
+ getLPEquityUSD() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ const collateralUSD = yield this.getCollateral().getDepositedUSD();
70
+ const debtUSD = yield this.getDebtUSD();
71
+ return collateralUSD - debtUSD;
72
+ });
73
+ }
42
74
  // LP equity number in LPs
43
75
  getLPEquity() {
44
76
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,8 +1,8 @@
1
1
  import OnChain from '../index';
2
- import { Address, Factory, FactoryIndex, LendingPoolIndex } from '../../config/types';
2
+ import { Address, Factory } from '../../config/types';
3
3
  import OnchainAccountLendingPool from './lendingPool';
4
4
  import OnchainAccountLendingVault from './onchainAccountLendingVault';
5
- import { AirdropData, PendingRewardUI } from '../onchainTypes';
5
+ import { AirdropData } from '../onchainTypes';
6
6
  export default class OnchainAccount {
7
7
  private readonly onchain;
8
8
  private readonly accountAddress;
@@ -19,7 +19,6 @@ export default class OnchainAccount {
19
19
  getLendingPool(factory: Factory, pair: Address): OnchainAccountLendingPool;
20
20
  private initializeLendingVault;
21
21
  getLendingVault(vaultAddress: Address): OnchainAccountLendingVault;
22
- getMassAvailableReward(pairs: FactoryIndex<Address[]>): Promise<LendingPoolIndex<PendingRewardUI[]>>;
23
22
  private initializeAirdropData;
24
23
  private getAirdropData;
25
24
  getIbexAirdropData(): Promise<AirdropData>;
@@ -61,32 +61,30 @@ class OnchainAccount {
61
61
  this.lendingVaults[vaultAddress] = this.initializeLendingVault(vaultAddress);
62
62
  return this.lendingVaults[vaultAddress];
63
63
  }
64
+ /*
64
65
  // Mass Available Reward (only supports ImpermaxChef)
65
- getMassAvailableReward(pairs) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const result = {};
68
- if (!pairs)
69
- return result;
70
- const requests = [];
71
- for (const factory in pairs) {
72
- const requestsLocal = [];
73
- for (const pairAddress of pairs[factory]) {
74
- requestsLocal.push((yield this.getLendingPool(factory, pairAddress)).getAvailableReward());
75
- }
76
- requests.push(Promise.all(requestsLocal));
77
- }
78
- const data = yield Promise.all(requests);
79
- let i = 0;
80
- for (const factory in pairs) {
81
- result[factory] = {};
82
- for (let j = 0; j < pairs[factory].length; j++) {
83
- result[factory][pairs[factory][j]] = data[i][j];
84
- }
85
- i++;
86
- }
87
- return result;
88
- });
89
- }
66
+ public async getMassAvailableReward(pairs: FactoryIndex<Address[]>) : Promise<LendingPoolIndex<PendingRewardUI[]>> {
67
+ const result: LendingPoolIndex<PendingRewardUI[]> = {};
68
+ if (!pairs) return result;
69
+ const requests: Array<Promise<PendingRewardUI[][]>> = [];
70
+ for (const factory in pairs) {
71
+ const requestsLocal: Promise<PendingRewardUI[]>[] = [];
72
+ for (const pairAddress of pairs[factory]) {
73
+ requestsLocal.push((await this.getLendingPool(factory as Factory, pairAddress)).getAvailableReward());
74
+ }
75
+ requests.push(Promise.all(requestsLocal));
76
+ }
77
+ const data = await Promise.all(requests);
78
+ let i = 0;
79
+ for (const factory in pairs) {
80
+ result[factory] = {};
81
+ for (let j = 0; j < pairs[factory].length; j++) {
82
+ result[factory][pairs[factory][j]] = data[i][j];
83
+ }
84
+ i++;
85
+ }
86
+ return result;
87
+ }*/
90
88
  // Airdrop Data
91
89
  initializeAirdropData(airdropURL, merkleDistributor) {
92
90
  return __awaiter(this, void 0, void 0, function* () {
@@ -27,5 +27,4 @@ export default abstract class OnchainInteractionsLendingPool {
27
27
  getAccountAddress: () => string;
28
28
  getAccountLendingPool(): OnchainAccountLendingPool;
29
29
  send: (method: any, onTransactionHash: Function) => Promise<any>;
30
- trackBorrows(onTransactionHash: Function): Promise<any>;
31
30
  }
@@ -1,13 +1,4 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const types_1 = require("../../../config/types");
13
4
  class OnchainInteractionsLendingPool {
@@ -35,19 +26,5 @@ class OnchainInteractionsLendingPool {
35
26
  getAccountLendingPool() {
36
27
  return this.interactions.getAccount().getLendingPool(this.getFactory(), this.getId());
37
28
  }
38
- trackBorrows(onTransactionHash) {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- const account = this.getAccountAddress();
41
- const claimAggregator = this.interactions.getOnchain().getContractHelper().claimAggregator;
42
- const toTrack = [];
43
- const accountLendingPool = yield this.getAccountLendingPool();
44
- for (const b of [accountLendingPool.getBorrowableA(), accountLendingPool.getBorrowableB()]) {
45
- if ((yield b.getBorrowed()) === 0 || (yield b.getFarmingShares()) > 0)
46
- continue;
47
- toTrack.push(yield b.getPoolToken().getPoolTokenAddress());
48
- }
49
- return this.send(claimAggregator.methods.trackBorrows(account, toTrack), onTransactionHash);
50
- });
51
- }
52
29
  }
53
30
  exports.default = OnchainInteractionsLendingPool;
@@ -39,4 +39,5 @@ export default class OnchainInteractionsLendingPoolV2 extends OnchainInteraction
39
39
  }>;
40
40
  deleverage(tokens: BigNumber, amountAMin: BigNumber, amountBMin: BigNumber, permitData: PermitData, onTransactionHash: Function): Promise<any>;
41
41
  reinvest(onTransactionHash: Function): Promise<any>;
42
+ trackBorrows(onTransactionHash: Function): Promise<any>;
42
43
  }
@@ -110,5 +110,19 @@ class OnchainInteractionsLendingPoolV2 extends onchainInteractionsLendingPool_1.
110
110
  return this.send(stakedLPToken.methods.reinvest(), onTransactionHash);
111
111
  });
112
112
  }
113
+ trackBorrows(onTransactionHash) {
114
+ return __awaiter(this, void 0, void 0, function* () {
115
+ const account = this.getAccountAddress();
116
+ const claimAggregator = this.interactions.getOnchain().getContractHelper().claimAggregator;
117
+ const toTrack = [];
118
+ const accountLendingPool = yield this.getAccountLendingPool();
119
+ for (const b of [accountLendingPool.getBorrowableA(), accountLendingPool.getBorrowableB()]) {
120
+ if ((yield b.getBorrowed()) === 0 || (yield b.getFarmingShares()) > 0)
121
+ continue;
122
+ toTrack.push(yield b.getPoolToken().getPoolTokenAddress());
123
+ }
124
+ return this.send(claimAggregator.methods.trackBorrows(account, toTrack), onTransactionHash);
125
+ });
126
+ }
113
127
  }
114
128
  exports.default = OnchainInteractionsLendingPoolV2;
@@ -1,5 +1,5 @@
1
1
  import Onchain from '../index';
2
- import { Address, Factory, FactoryIndex } from '../../config/types';
2
+ import { Address, Factory } from '../../config/types';
3
3
  import OnchainInteractionsLendingPool from './lendingPool';
4
4
  import OnchainInteractionsLendingVault from './onchainInteractionsLendingVault';
5
5
  import { AirdropData, Contract } from '../onchainTypes';
@@ -27,6 +27,5 @@ export default class OnchainInteractions {
27
27
  getDefaultRouterContract(): any;
28
28
  getPoolTokenRouter(): any;
29
29
  claimAirdrop(airdropData: AirdropData, merkleDistributor: Contract, onTransactionHash: Function): Promise<any>;
30
- claims(pairAddresses: FactoryIndex<Address[]>, onTransactionHash: Function): Promise<any>;
31
30
  claimDistributor(claimableAddress: Address, onTransactionHash: Function): Promise<any>;
32
31
  }
@@ -103,41 +103,45 @@ class OnchainInteractions {
103
103
  return this.send(merkleDistributor.methods.claim(airdropData.index, this.accountAddress, airdropData.amount, airdropData.proof), onTransactionHash);
104
104
  });
105
105
  }
106
- claims(pairAddresses, onTransactionHash) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- const requests = [];
109
- for (const factory in pairAddresses) {
110
- for (const pairAddress of pairAddresses[factory]) {
111
- const accountLendingPool = yield this.getAccount().getLendingPool(factory, pairAddress);
112
- for (const accountBorrowable of [
113
- accountLendingPool.getBorrowableA(),
114
- accountLendingPool.getBorrowableB(),
115
- ]) {
116
- requests.push((() => __awaiter(this, void 0, void 0, function* () {
117
- const borrowable = accountBorrowable.getPoolToken();
118
- const pendingReward = (yield accountBorrowable.getAvailableFarmingReward()) + (yield accountBorrowable.getAvailableRewarderReward());
119
- return {
120
- hasPendingReward: pendingReward > 0,
121
- hasImpermaxChef: yield borrowable.hasImpermaxChef(),
122
- borrowableAddress: yield borrowable.getPoolTokenAddress(),
123
- };
124
- }))());
125
- }
126
- }
127
- }
128
- const data = yield Promise.all(requests);
129
- const toClaim = [];
130
- for (const borrowable of data) {
131
- if (!borrowable.hasPendingReward)
132
- continue;
133
- toClaim.push(borrowable.borrowableAddress);
134
- }
135
- if (toClaim.length > 0) {
136
- const impermaxChef = this.onchain.getContractHelper().impermaxChef;
137
- return this.send(impermaxChef.methods.massHarvest(toClaim, this.accountAddress), onTransactionHash);
138
- }
139
- });
140
- }
106
+ /*
107
+ public async claims(pairAddresses: FactoryIndex<Address[]>, onTransactionHash: Function) {
108
+ const requests: Array<Promise<{
109
+ hasPendingReward: boolean,
110
+ hasImpermaxChef: boolean,
111
+ borrowableAddress: Address,
112
+ }>> = [];
113
+ for (const factory in pairAddresses) {
114
+ for (const pairAddress of pairAddresses[factory]) {
115
+ const accountLendingPool = await this.getAccount().getLendingPool(factory as Factory, pairAddress);
116
+ for (const accountBorrowable of [
117
+ accountLendingPool.getBorrowableA(),
118
+ accountLendingPool.getBorrowableB(),
119
+ ]) {
120
+ requests.push((async () => {
121
+ const borrowable = accountBorrowable.getPoolToken();
122
+ const pendingReward = await accountBorrowable.getAvailableFarmingReward() + await accountBorrowable.getAvailableRewarderReward();
123
+ return {
124
+ hasPendingReward: pendingReward > 0,
125
+ hasImpermaxChef: await borrowable.hasImpermaxChef(),
126
+ borrowableAddress: await borrowable.getPoolTokenAddress(),
127
+ }
128
+ })());
129
+ }
130
+ }
131
+ }
132
+ const data = await Promise.all(requests);
133
+
134
+ const toClaim: Address[] = [];
135
+ for (const borrowable of data) {
136
+ if (!borrowable.hasPendingReward) continue;
137
+ toClaim.push(borrowable.borrowableAddress);
138
+ }
139
+
140
+ if (toClaim.length > 0) {
141
+ const impermaxChef = this.onchain.getContractHelper().impermaxChef;
142
+ return this.send(impermaxChef.methods.massHarvest(toClaim, this.accountAddress), onTransactionHash);
143
+ }
144
+ }*/
141
145
  claimDistributor(claimableAddress, onTransactionHash) {
142
146
  return __awaiter(this, void 0, void 0, function* () {
143
147
  const claimable = this.onchain.getContractHelper().newClaimable(claimableAddress);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.64",
3
+ "version": "2.1.69",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",