impermax-sdk 2.1.59 → 2.1.60
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/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as onchain from './onchain';
|
|
|
5
5
|
import { CLAIM_AGGREGATOR } from './config/contracts/claim-aggregators';
|
|
6
6
|
import { IMPERMAX_CHEF } from './config/contracts/impermax-chef';
|
|
7
7
|
import { IMX } from './config/contracts/imxes';
|
|
8
|
-
import { IMPERMAX_FACTORY, getNetworkFactories } from './config/contracts/impermax-factories';
|
|
8
|
+
import { IMPERMAX_FACTORY, getNetworkFactories, getFactoryByAddress } from './config/contracts/impermax-factories';
|
|
9
9
|
import { MERKLE_DISTRIBUTOR_ETH, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2 } from './config/contracts/merkle-distributors';
|
|
10
10
|
import { MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2 } from './config/endpoints/merkle-distributors';
|
|
11
11
|
import { ROUTER } from './config/contracts/routers';
|
|
@@ -36,4 +36,5 @@ import OffchainVault, { OffchainLendingVault, OffchainLeveragedVault, OffchainHe
|
|
|
36
36
|
import { SortDirection, VaultListOrderBy, VaultListParams, LendingPoolListParams, LendingPoolListOrderBy } from "./offchain/offchainMultichain";
|
|
37
37
|
import { VaultRisk } from "./offchain/vault/offchainVault";
|
|
38
38
|
import { LendingPoolVersion } from "./offchain/lendingPool/offchainLendingPool";
|
|
39
|
-
|
|
39
|
+
import { PositionType, AccountPosition } from "./offchain/account/offchainMultichainAccount";
|
|
40
|
+
export { offchain, OffchainMultichain, Offchain, OffchainLendingPool, OffchainPoolToken, OffchainCollateral, OffchainBorrowable, OffchainVault, OffchainLeveragedVault, OffchainLendingVault, OffchainHedgedVault, OffchainConfigManager, OffchainPairConfig, OffchainProposal, OffchainMultichainAccount, OffchainAccount, OffchainAccountLendingPool, OffchainAccountPoolToken, OffchainAccountCollateral, OffchainAccountBorrowable, OffchainLeveragedPosition, OffchainAccountVault, OffchainPriceHelper, OffchainSolidexHelper, PoolTokenData, BorrowableData, CollateralData, BorrowablePastData, TokenData, RewardData, PairData, FarmingPoolData, LendingPoolPastData, LendingPoolData, CollateralPosition, SupplyPosition, BorrowPosition, UserData, TvlData, XimxData, LendingVaultData, VaultPosition, PairConfigData, ProposalData, ProposalMetadata, VaultRisk, VaultType, onchain, Onchain, OnchainLendingPool, OnchainPoolToken, OnchainBorrowable, OnchainCollateral, OnchainLendingVault, OnchainConfigManager, OnchainProposal, OnchainPairConfig, OnchainAccount, OnchainAccountLendingPool, OnchainAccountPoolToken, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingVault, OnchainContractsHelper, OnchainImpermaxFactory, OnchainInteractions, OnchainInteractionsLendingPool, OnchainInteractionsPoolToken, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingVault, OnchainInteractionsConfigManager, Contract, ApprovalType, PermitData, OnchainConfig, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, CollateralConfig, BorrowableConfig, PairConfig, CLAIM_AGGREGATOR, IMPERMAX_CHEF, IMX, IMPERMAX_FACTORY, getNetworkFactories, getFactoryByAddress, LENDING_VAULT_WATCHER, MERKLE_DISTRIBUTOR_IBEX, MERKLE_DISTRIBUTOR_IBEX_2, MERKLE_DISTRIBUTOR_ETH, ROUTER, SIMPLE_UNISWAP_ORACLE, WETH, MERKLE_URL_ETH, MERKLE_URL_IBEX, MERKLE_URL_IBEX_2, hrAmms, AMM_FACTORY, getAmmByFactory, AMM_SUBGRAPH_URLS, ADD_LIQUIDITY_URLS, AMM_LP_FEE, DEBANK_IDS, ETH_SYMBOL, ETH_NAME, SOLIDEX_FACTORIES, BORROW_FEE_FACTORIES, OLD_KINK_MULTIPLIER_FACTORIES, LIQUIDATION_FEE_FACTORIES, V2_FACTORIES, Farms, hrFarms, FarmIndex, STAKED_LP_FACTORY, getFarmByStakedLPFactory, NOT_SYNCED, DEADLINE, ZERO, APPROVE_AMOUNT, IMPERMAX_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, BLOCKS_SUBGRAPH_URL, XIMX_SUBGRAPH_URL, Networks, Factory, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable };
|
package/lib/index.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.OnchainInteractionsLendingVault = exports.OnchainInteractionsBorrowable = exports.OnchainInteractionsCollateral = exports.OnchainInteractionsPoolToken = exports.OnchainInteractionsLendingPool = exports.OnchainInteractions = exports.OnchainImpermaxFactory = exports.OnchainContractsHelper = exports.OnchainAccountLendingVault = exports.OnchainAccountCollateral = exports.OnchainAccountBorrowable = exports.OnchainAccountPoolToken = exports.OnchainAccountLendingPool = exports.OnchainAccount = exports.OnchainPairConfig = exports.OnchainProposal = exports.OnchainConfigManager = exports.OnchainLendingVault = exports.OnchainCollateral = exports.OnchainBorrowable = exports.OnchainPoolToken = exports.OnchainLendingPool = exports.Onchain = exports.onchain = exports.VaultType = exports.VaultRisk = exports.OffchainSolidexHelper = exports.OffchainPriceHelper = exports.OffchainAccountVault = exports.OffchainLeveragedPosition = exports.OffchainAccountBorrowable = exports.OffchainAccountCollateral = exports.OffchainAccountPoolToken = exports.OffchainAccountLendingPool = exports.OffchainAccount = exports.OffchainMultichainAccount = exports.OffchainProposal = exports.OffchainPairConfig = exports.OffchainConfigManager = exports.OffchainHedgedVault = exports.OffchainLendingVault = exports.OffchainLeveragedVault = exports.OffchainVault = exports.OffchainBorrowable = exports.OffchainCollateral = exports.OffchainPoolToken = exports.OffchainLendingPool = exports.Offchain = exports.OffchainMultichain = exports.offchain = void 0;
|
|
27
|
-
exports.
|
|
28
|
-
exports.Borrowable = exports.PermitType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = void 0;
|
|
27
|
+
exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Factory = exports.Networks = exports.XIMX_SUBGRAPH_URL = exports.BLOCKS_SUBGRAPH_URL = exports.IMPERMAX_CHEF_SUBGRAPH_URL = exports.IMPERMAX_SUBGRAPH_URL = exports.APPROVE_AMOUNT = exports.ZERO = exports.DEADLINE = exports.NOT_SYNCED = exports.getFarmByStakedLPFactory = exports.STAKED_LP_FACTORY = exports.hrFarms = exports.Farms = exports.V2_FACTORIES = exports.LIQUIDATION_FEE_FACTORIES = exports.OLD_KINK_MULTIPLIER_FACTORIES = exports.BORROW_FEE_FACTORIES = exports.SOLIDEX_FACTORIES = exports.ETH_NAME = exports.ETH_SYMBOL = exports.DEBANK_IDS = exports.AMM_LP_FEE = exports.ADD_LIQUIDITY_URLS = exports.AMM_SUBGRAPH_URLS = exports.getAmmByFactory = exports.AMM_FACTORY = exports.hrAmms = exports.MERKLE_URL_IBEX_2 = exports.MERKLE_URL_IBEX = exports.MERKLE_URL_ETH = exports.WETH = exports.SIMPLE_UNISWAP_ORACLE = exports.ROUTER = exports.MERKLE_DISTRIBUTOR_ETH = exports.MERKLE_DISTRIBUTOR_IBEX_2 = exports.MERKLE_DISTRIBUTOR_IBEX = exports.LENDING_VAULT_WATCHER = exports.getFactoryByAddress = exports.getNetworkFactories = exports.IMPERMAX_FACTORY = exports.IMX = exports.IMPERMAX_CHEF = exports.CLAIM_AGGREGATOR = exports.NO_CHANGES = exports.ApprovalType = exports.OnchainInteractionsConfigManager = void 0;
|
|
28
|
+
exports.Borrowable = exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = void 0;
|
|
29
29
|
const offchain_1 = __importStar(require("./offchain"));
|
|
30
30
|
exports.Offchain = offchain_1.default;
|
|
31
31
|
Object.defineProperty(exports, "OffchainAccount", { enumerable: true, get: function () { return offchain_1.OffchainAccount; } });
|
|
@@ -55,6 +55,7 @@ Object.defineProperty(exports, "IMX", { enumerable: true, get: function () { ret
|
|
|
55
55
|
const impermax_factories_1 = require("./config/contracts/impermax-factories");
|
|
56
56
|
Object.defineProperty(exports, "IMPERMAX_FACTORY", { enumerable: true, get: function () { return impermax_factories_1.IMPERMAX_FACTORY; } });
|
|
57
57
|
Object.defineProperty(exports, "getNetworkFactories", { enumerable: true, get: function () { return impermax_factories_1.getNetworkFactories; } });
|
|
58
|
+
Object.defineProperty(exports, "getFactoryByAddress", { enumerable: true, get: function () { return impermax_factories_1.getFactoryByAddress; } });
|
|
58
59
|
const merkle_distributors_1 = require("./config/contracts/merkle-distributors");
|
|
59
60
|
Object.defineProperty(exports, "MERKLE_DISTRIBUTOR_ETH", { enumerable: true, get: function () { return merkle_distributors_1.MERKLE_DISTRIBUTOR_ETH; } });
|
|
60
61
|
Object.defineProperty(exports, "MERKLE_DISTRIBUTOR_IBEX", { enumerable: true, get: function () { return merkle_distributors_1.MERKLE_DISTRIBUTOR_IBEX; } });
|
|
@@ -170,3 +171,5 @@ const offchainVault_1 = require("./offchain/vault/offchainVault");
|
|
|
170
171
|
Object.defineProperty(exports, "VaultRisk", { enumerable: true, get: function () { return offchainVault_1.VaultRisk; } });
|
|
171
172
|
const offchainLendingPool_1 = require("./offchain/lendingPool/offchainLendingPool");
|
|
172
173
|
Object.defineProperty(exports, "LendingPoolVersion", { enumerable: true, get: function () { return offchainLendingPool_1.LendingPoolVersion; } });
|
|
174
|
+
const offchainMultichainAccount_1 = require("./offchain/account/offchainMultichainAccount");
|
|
175
|
+
Object.defineProperty(exports, "PositionType", { enumerable: true, get: function () { return offchainMultichainAccount_1.PositionType; } });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Networks } from "../../config/types";
|
|
1
|
+
import { Address, Factory, Networks } from "../../config/types";
|
|
2
2
|
import OffchainAccountLendingPool from "./lendingPool";
|
|
3
3
|
import OffchainAccountVault from "./vault";
|
|
4
4
|
import OffchainMultichain from "../offchainMultichain";
|
|
@@ -21,6 +21,20 @@ export declare enum VaultPositionsOrderBy {
|
|
|
21
21
|
export interface VaultPositionsParams {
|
|
22
22
|
networks?: Array<Networks>;
|
|
23
23
|
}
|
|
24
|
+
export declare enum PositionType {
|
|
25
|
+
MARKET = "Market",
|
|
26
|
+
VAULT = "Vault",
|
|
27
|
+
OTHER = "Other"
|
|
28
|
+
}
|
|
29
|
+
export type AccountPosition = {
|
|
30
|
+
id: Address;
|
|
31
|
+
network: Networks;
|
|
32
|
+
value: number;
|
|
33
|
+
type: PositionType;
|
|
34
|
+
name: string;
|
|
35
|
+
percentage: number;
|
|
36
|
+
factory: Factory | undefined;
|
|
37
|
+
};
|
|
24
38
|
export default class OffchainMultichainAccount {
|
|
25
39
|
readonly offchainMultichain: OffchainMultichain;
|
|
26
40
|
readonly accountAddress: Address;
|
|
@@ -33,5 +47,7 @@ export default class OffchainMultichainAccount {
|
|
|
33
47
|
getVaultPositions(params?: VaultPositionsParams, orderBy?: VaultPositionsOrderBy): Promise<Array<OffchainAccountVault>>;
|
|
34
48
|
getTotalBalanceUSD(): Promise<number>;
|
|
35
49
|
getVaultsBalanceUSD(): Promise<number>;
|
|
50
|
+
getSupplyBalanceUSD(): Promise<number>;
|
|
51
|
+
getTopPositions(limit?: number): Promise<Array<AccountPosition>>;
|
|
36
52
|
getNetAPR(): Promise<number>;
|
|
37
53
|
}
|
|
@@ -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.VaultPositionsOrderBy = exports.SupplyPositionsOrderBy = exports.LeveragedPositionsOrderBy = void 0;
|
|
12
|
+
exports.PositionType = 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,13 @@ var VaultPositionsOrderBy;
|
|
|
23
23
|
(function (VaultPositionsOrderBy) {
|
|
24
24
|
VaultPositionsOrderBy[VaultPositionsOrderBy["TVL"] = 0] = "TVL";
|
|
25
25
|
})(VaultPositionsOrderBy = exports.VaultPositionsOrderBy || (exports.VaultPositionsOrderBy = {}));
|
|
26
|
+
var PositionType;
|
|
27
|
+
(function (PositionType) {
|
|
28
|
+
PositionType["MARKET"] = "Market";
|
|
29
|
+
PositionType["VAULT"] = "Vault";
|
|
30
|
+
PositionType["OTHER"] = "Other";
|
|
31
|
+
})(PositionType = exports.PositionType || (exports.PositionType = {}));
|
|
32
|
+
// TODO: Collateral positions
|
|
26
33
|
class OffchainMultichainAccount {
|
|
27
34
|
constructor(offchainMultichain, account) {
|
|
28
35
|
this.getOffchainMultichain = () => this.offchainMultichain;
|
|
@@ -94,8 +101,11 @@ class OffchainMultichainAccount {
|
|
|
94
101
|
// Account stats
|
|
95
102
|
getTotalBalanceUSD() {
|
|
96
103
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
const [vaultBalanceUSD, supplyBalanceUSD] = yield Promise.all([
|
|
105
|
+
this.getVaultsBalanceUSD(),
|
|
106
|
+
this.getSupplyBalanceUSD(),
|
|
107
|
+
]);
|
|
108
|
+
return vaultBalanceUSD + supplyBalanceUSD;
|
|
99
109
|
});
|
|
100
110
|
}
|
|
101
111
|
getVaultsBalanceUSD() {
|
|
@@ -105,6 +115,87 @@ class OffchainMultichainAccount {
|
|
|
105
115
|
return depositedValue.reduce((acc, val) => acc + val, 0);
|
|
106
116
|
});
|
|
107
117
|
}
|
|
118
|
+
getSupplyBalanceUSD() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const supplyPositions = yield this.getSupplyPositions();
|
|
121
|
+
const suppliedValue = yield Promise.all(supplyPositions.map((pool) => __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const [valueA, valueB] = yield Promise.all([
|
|
123
|
+
pool.getBorrowableA().getValue(),
|
|
124
|
+
pool.getBorrowableB().getValue(),
|
|
125
|
+
]);
|
|
126
|
+
return valueA + valueB;
|
|
127
|
+
})));
|
|
128
|
+
return suppliedValue.reduce((acc, val) => acc + val, 0);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
// Gets the top positions for a user
|
|
132
|
+
getTopPositions(limit = 10) {
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const [supplyPositions, vaultPositions] = yield Promise.all([
|
|
135
|
+
this.getSupplyPositions(),
|
|
136
|
+
this.getVaultPositions(),
|
|
137
|
+
]);
|
|
138
|
+
// Lending Market positions
|
|
139
|
+
const supplyValues = yield Promise.all(supplyPositions.map((pool) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const [valueA, valueB, symbolA, symbolB, network, data, factory] = yield Promise.all([
|
|
141
|
+
pool.getBorrowableA().getValue(),
|
|
142
|
+
pool.getBorrowableB().getValue(),
|
|
143
|
+
pool.getBorrowableA().getPoolToken().getSymbol(),
|
|
144
|
+
pool.getBorrowableB().getPoolToken().getSymbol(),
|
|
145
|
+
pool.getLendingPool().getOffchain().network,
|
|
146
|
+
pool.getLendingPool().getLendingPoolData(),
|
|
147
|
+
pool.getLendingPool().getFactory()
|
|
148
|
+
]);
|
|
149
|
+
const totalValue = valueA + valueB;
|
|
150
|
+
return {
|
|
151
|
+
name: `${symbolA}/${symbolB}`,
|
|
152
|
+
value: totalValue,
|
|
153
|
+
type: PositionType.MARKET,
|
|
154
|
+
network: network,
|
|
155
|
+
id: data.id,
|
|
156
|
+
factory: factory
|
|
157
|
+
};
|
|
158
|
+
})));
|
|
159
|
+
// Vault positions
|
|
160
|
+
const vaultValues = yield Promise.all(vaultPositions.map((vault) => __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const [value, symbol, network, data] = yield Promise.all([
|
|
162
|
+
vault.getValue(),
|
|
163
|
+
vault.getPoolToken().getSymbol(),
|
|
164
|
+
vault.getPoolToken().getOffchain().network,
|
|
165
|
+
vault.getPoolToken().getPoolTokenData()
|
|
166
|
+
]);
|
|
167
|
+
return {
|
|
168
|
+
name: symbol,
|
|
169
|
+
value: value,
|
|
170
|
+
type: PositionType.VAULT,
|
|
171
|
+
network: network,
|
|
172
|
+
id: data.id,
|
|
173
|
+
factory: undefined
|
|
174
|
+
};
|
|
175
|
+
})));
|
|
176
|
+
const allPositions = [...supplyValues, ...vaultValues].sort((a, b) => b.value - a.value);
|
|
177
|
+
const totalValue = allPositions.reduce((sum, pos) => sum + pos.value, 0);
|
|
178
|
+
if (allPositions.length <= limit || limit <= 1) {
|
|
179
|
+
return allPositions.map((pos) => (Object.assign(Object.assign({}, pos), { percentage: (pos.value / totalValue) * 100 })));
|
|
180
|
+
}
|
|
181
|
+
// Top N-1 positions and calculate "Other"
|
|
182
|
+
const topNMinusOne = allPositions.slice(0, limit - 1);
|
|
183
|
+
const remainingPositions = allPositions.slice(limit - 1);
|
|
184
|
+
const remainingValue = remainingPositions.reduce((sum, pos) => sum + pos.value, 0);
|
|
185
|
+
const result = [
|
|
186
|
+
...topNMinusOne,
|
|
187
|
+
{
|
|
188
|
+
name: "Other",
|
|
189
|
+
value: remainingValue,
|
|
190
|
+
type: PositionType.OTHER,
|
|
191
|
+
network: types_1.Networks.Mainnet,
|
|
192
|
+
id: "",
|
|
193
|
+
factory: undefined
|
|
194
|
+
},
|
|
195
|
+
].map((pos) => (Object.assign(Object.assign({}, pos), { percentage: (pos.value / totalValue) * 100 })));
|
|
196
|
+
return result;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
108
199
|
getNetAPR() {
|
|
109
200
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
201
|
return 1;
|