impermax-sdk 2.1.173 → 2.1.175

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
@@ -23,7 +23,7 @@ import { AirdropData, ApprovalType, Changes, Contract, OnchainConfig, NO_CHANGES
23
23
  import { BorrowableData, BorrowablePastData, BorrowPosition, CollateralData, CollateralPosition, FarmingPoolData, LendingPoolData, LendingPoolPastData, PairData, PoolTokenData, RewardData, SupplyPosition, TokenData, TvlData, UserData, XimxData, LendingVaultData, VaultPosition, PairConfigData, ProposalData, ProposalMetadata, isV3Factory } from './offchain/offchainTypes';
24
24
  import { OffchainBorrowable, OffchainCollateral } from './offchain/lendingPool';
25
25
  import OffchainConfigManager, { OffchainPairConfig, OffchainProposal } from './offchain/configManager';
26
- import OffchainAccountLendingPool, { OffchainAccountBorrowable, OffchainAccountCollateral, OffchainLeveragedPosition } from './offchain/account/lendingPool';
26
+ import OffchainAccountLendingPool, { OffchainAccountBorrowable, OffchainAccountCollateral, OffchainLeveragedPosition, OffchainAccountCollateralV2 } from './offchain/account/lendingPool';
27
27
  import { OffchainAccountVault, OffchainAccountPoolToken, OffchainMultichainAccount } from './offchain/account';
28
28
  import OnchainLendingPool, { OnchainBorrowable, OnchainCollateral } from './onchain/impermaxFactory/lendingPool';
29
29
  import OnchainConfigManager, { OnchainPairConfig, OnchainProposal } from './onchain/configManager';
@@ -47,4 +47,4 @@ import OffchainAccountNftlpUniswapV3 from './offchain/account/lendingPool/nftlp/
47
47
  import { MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice } from "./utils/nftlpMath/uniswapV3General";
48
48
  import UniswapV3Position from './utils/position/uniswapV3';
49
49
  import UniswapV2Position from './utils/position/uniswapV2';
50
- 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, OnchainAccountLendingPoolV2, OnchainAccountLendingPoolV3, OnchainAccountNftlpUniswapV3, OnchainAccountPoolToken, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingVault, OnchainContractsHelper, OnchainImpermaxFactory, OnchainInteractions, OnchainInteractionsLendingPool, OnchainInteractionsPoolToken, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingVault, OnchainInteractionsConfigManager, Contract, ApprovalType, PermitData, OnchainConfig, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, CollateralConfig, BorrowableV2Config, BorrowableV3Config, 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, Extension, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable, OnchainInteractionsLendingPoolV3, OnchainInteractionsNftlpUniswapV3, decimalToBalance, OffchainAccountLendingPoolV3, OffchainAccountNftlpUniswapV3, MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice, isV3Factory, UniswapV3Position, UniswapV2Position, };
50
+ 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, OnchainAccountLendingPoolV2, OnchainAccountLendingPoolV3, OnchainAccountNftlpUniswapV3, OnchainAccountPoolToken, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingVault, OnchainContractsHelper, OnchainImpermaxFactory, OnchainInteractions, OnchainInteractionsLendingPool, OnchainInteractionsPoolToken, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingVault, OnchainInteractionsConfigManager, Contract, ApprovalType, PermitData, OnchainConfig, Changes, NO_CHANGES, Values, AirdropData, PendingRewardUI, CollateralConfig, BorrowableV2Config, BorrowableV3Config, 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, Extension, PoolTokenType, Amms, Address, NetworkIndex, FactoryIndex, AddressIndex, NetworkFactoryIndex, LendingPoolIndex, AmmIndex, DistributorDetails, ProposalState, WhitelistState, VaultListOrderBy, VaultListParams, LendingPoolListOrderBy, LendingPoolListParams, SortDirection, LendingPoolVersion, PositionType, AccountPosition, PermitType, Permits, Permit, Borrowable, OnchainInteractionsLendingPoolV3, OnchainInteractionsNftlpUniswapV3, decimalToBalance, OffchainAccountLendingPoolV3, OffchainAccountNftlpUniswapV3, MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice, isV3Factory, UniswapV3Position, UniswapV2Position, OffchainAccountCollateralV2 };
package/lib/index.js CHANGED
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.OnchainInteractionsPoolToken = exports.OnchainInteractionsLendingPool = exports.OnchainInteractions = exports.OnchainImpermaxFactory = exports.OnchainContractsHelper = exports.OnchainAccountLendingVault = exports.OnchainAccountCollateral = exports.OnchainAccountBorrowable = exports.OnchainAccountPoolToken = exports.OnchainAccountNftlpUniswapV3 = exports.OnchainAccountLendingPoolV3 = exports.OnchainAccountLendingPoolV2 = 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;
30
30
  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 = exports.OnchainInteractionsLendingVault = exports.OnchainInteractionsBorrowable = exports.OnchainInteractionsCollateral = void 0;
31
- exports.UniswapV2Position = exports.UniswapV3Position = exports.isV3Factory = exports.uniV3TickToPrice = exports.formatPriceSqrtX96 = exports.MIN_TICK = exports.MAX_TICK = exports.OffchainAccountNftlpUniswapV3 = exports.OffchainAccountLendingPoolV3 = exports.decimalToBalance = exports.OnchainInteractionsNftlpUniswapV3 = exports.OnchainInteractionsLendingPoolV3 = exports.Borrowable = exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Extension = void 0;
31
+ exports.OffchainAccountCollateralV2 = exports.UniswapV2Position = exports.UniswapV3Position = exports.isV3Factory = exports.uniV3TickToPrice = exports.formatPriceSqrtX96 = exports.MIN_TICK = exports.MAX_TICK = exports.OffchainAccountNftlpUniswapV3 = exports.OffchainAccountLendingPoolV3 = exports.decimalToBalance = exports.OnchainInteractionsNftlpUniswapV3 = exports.OnchainInteractionsLendingPoolV3 = exports.Borrowable = exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Extension = void 0;
32
32
  const offchain_1 = __importStar(require("./offchain"));
33
33
  exports.Offchain = offchain_1.default;
34
34
  Object.defineProperty(exports, "OffchainAccount", { enumerable: true, get: function () { return offchain_1.OffchainAccount; } });
@@ -134,6 +134,7 @@ exports.OffchainAccountLendingPool = lendingPool_2.default;
134
134
  Object.defineProperty(exports, "OffchainAccountBorrowable", { enumerable: true, get: function () { return lendingPool_2.OffchainAccountBorrowable; } });
135
135
  Object.defineProperty(exports, "OffchainAccountCollateral", { enumerable: true, get: function () { return lendingPool_2.OffchainAccountCollateral; } });
136
136
  Object.defineProperty(exports, "OffchainLeveragedPosition", { enumerable: true, get: function () { return lendingPool_2.OffchainLeveragedPosition; } });
137
+ Object.defineProperty(exports, "OffchainAccountCollateralV2", { enumerable: true, get: function () { return lendingPool_2.OffchainAccountCollateralV2; } });
137
138
  const account_1 = require("./offchain/account");
138
139
  Object.defineProperty(exports, "OffchainAccountVault", { enumerable: true, get: function () { return account_1.OffchainAccountVault; } });
139
140
  Object.defineProperty(exports, "OffchainAccountPoolToken", { enumerable: true, get: function () { return account_1.OffchainAccountPoolToken; } });
@@ -2,5 +2,6 @@ import OffchainAccountCollateral from "./offchainAccountCollateral";
2
2
  import OffchainAccountBorrowable from "./offchainAccountBorrowable";
3
3
  import OffchainAccountLendingPool from "./offchainAccountLendingPool";
4
4
  import OffchainLeveragedPosition from "./offchainLeveragedPosition";
5
- export { OffchainAccountBorrowable, OffchainAccountCollateral, OffchainLeveragedPosition, };
5
+ import OffchainAccountCollateralV2 from "./offchainAccountCollateralV2";
6
+ export { OffchainAccountBorrowable, OffchainAccountCollateral, OffchainLeveragedPosition, OffchainAccountCollateralV2 };
6
7
  export default OffchainAccountLendingPool;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OffchainLeveragedPosition = exports.OffchainAccountCollateral = exports.OffchainAccountBorrowable = void 0;
6
+ exports.OffchainAccountCollateralV2 = exports.OffchainLeveragedPosition = exports.OffchainAccountCollateral = exports.OffchainAccountBorrowable = void 0;
7
7
  const offchainAccountCollateral_1 = __importDefault(require("./offchainAccountCollateral"));
8
8
  exports.OffchainAccountCollateral = offchainAccountCollateral_1.default;
9
9
  const offchainAccountBorrowable_1 = __importDefault(require("./offchainAccountBorrowable"));
@@ -11,4 +11,6 @@ exports.OffchainAccountBorrowable = offchainAccountBorrowable_1.default;
11
11
  const offchainAccountLendingPool_1 = __importDefault(require("./offchainAccountLendingPool"));
12
12
  const offchainLeveragedPosition_1 = __importDefault(require("./offchainLeveragedPosition"));
13
13
  exports.OffchainLeveragedPosition = offchainLeveragedPosition_1.default;
14
+ const offchainAccountCollateralV2_1 = __importDefault(require("./offchainAccountCollateralV2"));
15
+ exports.OffchainAccountCollateralV2 = offchainAccountCollateralV2_1.default;
14
16
  exports.default = offchainAccountLendingPool_1.default;
@@ -6,6 +6,9 @@ import { UniswapV2Position } from "../../../utils/position";
6
6
  export default class OffchainAccountCollateralV2 extends OffchainAccountPoolToken implements OffchainAccountCollateral {
7
7
  protected readonly lendingPool: OffchainAccountLendingPoolV2;
8
8
  protected readonly poolToken: OffchainCollateralV2;
9
+ protected cache: {
10
+ positionsObject?: Promise<UniswapV2Position>;
11
+ };
9
12
  constructor(lendingPool: OffchainAccountLendingPoolV2);
10
13
  getAccount: () => import("..").default;
11
14
  getLendingPool: () => OffchainAccountLendingPoolV2;
@@ -14,4 +17,6 @@ export default class OffchainAccountCollateralV2 extends OffchainAccountPoolToke
14
17
  getAmount(): Promise<number>;
15
18
  private getLiquidity;
16
19
  createPositionObject(lockStateChange?: boolean): Promise<UniswapV2Position>;
20
+ createNewPositionObject(lockStateChange?: boolean): Promise<UniswapV2Position>;
21
+ getPositionObject(): Promise<UniswapV2Position>;
17
22
  }
@@ -8,6 +8,7 @@ const position_1 = require("../../../utils/position");
8
8
  class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
9
9
  constructor(lendingPool) {
10
10
  super();
11
+ this.cache = {};
11
12
  this.getAccount = () => this.getLendingPool().getAccount();
12
13
  this.getLendingPool = () => this.lendingPool;
13
14
  this.getCollateral = () => this.lendingPool.getLendingPool().getCollateral();
@@ -37,5 +38,13 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
37
38
  return new position_1.UniswapV2Position(await this.getLiquidity(), await this.getLendingPool().getBorrowableA().getBorrowedAmount(), await this.getLendingPool().getBorrowableB().getBorrowedAmount(), await this.getLendingPool().getLendingPool().getMarketPrice(), await this.getLendingPool().getLendingPool().getMarketPrice(), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
38
39
  //}
39
40
  }
41
+ async createNewPositionObject(lockStateChange = false) {
42
+ return new position_1.UniswapV2Position(0, 0, 0, await this.getLendingPool().getLendingPool().getMarketPrice(), await this.getLendingPool().getLendingPool().getMarketPrice(), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
43
+ }
44
+ async getPositionObject() {
45
+ if (!this.cache.positionsObject)
46
+ this.cache.positionsObject = this.createPositionObject();
47
+ return this.cache.positionsObject;
48
+ }
40
49
  }
41
50
  exports.default = OffchainAccountCollateralV2;
@@ -44,7 +44,8 @@ class OffchainCollateralV2 extends offchainPoolToken_1.default {
44
44
  const reserve0 = parseFloat(lendingPoolData.pair.reserve0);
45
45
  const reserve1 = parseFloat(lendingPoolData.pair.reserve1);
46
46
  const totalSupply = parseFloat(lendingPoolData.pair.totalSupply);
47
- return Math.sqrt(reserve0 * reserve1) / totalSupply;
47
+ const exchangeRate = await this.getExchangeRate();
48
+ return Math.sqrt(reserve0 * reserve1) / totalSupply * exchangeRate;
48
49
  }
49
50
  //
50
51
  // Pricing
@@ -4,6 +4,7 @@ import OnchainAccountCollateral from "./onchainAccountCollateral";
4
4
  import { OnchainCollateralV2 } from "../../impermaxFactory/lendingPool";
5
5
  import OnchainAccountLendingPoolV2 from "./onchainAccountLendingPoolV2";
6
6
  import OnchainInteractionsCollateralV2 from "../../interactions/lendingPool/onchainInteractionsCollateralV2";
7
+ import { UniswapV2Position } from "../../../utils/position";
7
8
  export default class OnchainAccountCollateralV2 extends OnchainAccountPoolToken implements OnchainAccountCollateral {
8
9
  protected readonly lendingPool: OnchainAccountLendingPoolV2;
9
10
  protected readonly poolToken: OnchainCollateralV2;
@@ -18,6 +19,8 @@ export default class OnchainAccountCollateralV2 extends OnchainAccountPoolToken
18
19
  getOffchainAccountPoolToken(): Promise<OffchainAccountCollateralV2>;
19
20
  getOffchainAccountCollateral: () => Promise<OffchainAccountCollateralV2>;
20
21
  cleanCache(): void;
22
+ private getLiquidity;
23
+ createPositionObject(lockStateChange?: boolean): Promise<UniswapV2Position>;
21
24
  fixStakedLPExchangeRate(n: Promise<number>): Promise<number>;
22
25
  getAvailableBalanceUSD(): Promise<number>;
23
26
  getDepositedUSD(): Promise<number>;
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const onchainTypes_1 = require("../../onchainTypes");
7
7
  const onchainAccountPoolToken_1 = __importDefault(require("../onchainAccountPoolToken"));
8
+ const position_1 = require("../../../utils/position");
8
9
  class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
9
10
  constructor(lendingPool) {
10
11
  super();
@@ -29,6 +30,18 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
29
30
  super.cleanCache();
30
31
  this.collateralCache = {};
31
32
  }
33
+ async getLiquidity() {
34
+ // todo check if growth factor works
35
+ return await this.getDeposited() * await this.getCollateral().getGrowthFactor();
36
+ }
37
+ // Notice: createNewPositionObject is not needed for V2
38
+ async createPositionObject(lockStateChange = false) {
39
+ //if (await this.getLendingPool().getLendingPool().isStable()) {
40
+ // TODO return stablePosition
41
+ //} else {
42
+ return new position_1.UniswapV2Position(await this.getLiquidity(), await this.getLendingPool().getBorrowableA().getBorrowed(), await this.getLendingPool().getBorrowableB().getBorrowed(), await this.getLendingPool().getLendingPool().getMarketPrice(), await this.getLendingPool().getLendingPool().getTWAPPrice(), await this.getLendingPool().getSafetyMargin(), await this.getLendingPool().getLiquidationPenalty(), lockStateChange);
43
+ //}
44
+ }
32
45
  async fixStakedLPExchangeRate(n) {
33
46
  const stakedLPExchangeRate = await this.poolToken.getLendingPool().getStakedLPExchangeRate();
34
47
  return await n / stakedLPExchangeRate;
@@ -17,4 +17,5 @@ export default class OnchainCollateralV2 extends OnchainPoolToken implements Onc
17
17
  protected initializePoolToken(): Promise<Contract>;
18
18
  protected initializeToken(): Promise<Contract>;
19
19
  protected initializeExchangeRate(): Promise<number>;
20
+ getGrowthFactor(): Promise<number>;
20
21
  }
@@ -34,5 +34,12 @@ class OnchainCollateralV2 extends onchainPoolToken_1.default {
34
34
  let exchangeRate = await super.initializeExchangeRate();
35
35
  return exchangeRate * await this.lendingPool.getStakedLPExchangeRate();
36
36
  }
37
+ async getGrowthFactor() {
38
+ const [reserve0, reserve1] = await this.getLendingPool().getReserves();
39
+ const totalSupply = await this.getLendingPool().getLPTotalSupply();
40
+ const stakedLPExchangeRate = await this.getLendingPool().getStakedLPExchangeRate();
41
+ const exchangeRate = await this.getExchangeRate();
42
+ return Math.sqrt(reserve0 * reserve1) / totalSupply * stakedLPExchangeRate * exchangeRate;
43
+ }
37
44
  }
38
45
  exports.default = OnchainCollateralV2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.173",
3
+ "version": "2.1.175",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",