impermax-sdk 2.1.128 → 2.1.130
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 +2 -2
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +2 -2
- package/lib/onchain/configManager/onchainPairConfig.d.ts +6 -3
- package/lib/onchain/configManager/onchainPairConfig.js +6 -2
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +1 -1
- package/lib/onchain/onchainTypes.d.ts +10 -1
- package/lib/onchain/onchainTypes.js +9 -1
- package/lib/utils/nftlpMath/uniswapV3Position.d.ts +28 -6
- package/lib/utils/nftlpMath/uniswapV3Position.js +83 -26
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { FarmIndex, Farms, getFarmByStakedLPFactory, hrFarms, STAKED_LP_FACTORY
|
|
|
19
19
|
import { APPROVE_AMOUNT, DEADLINE, NOT_SYNCED, ZERO } from './config/general';
|
|
20
20
|
import { BLOCKS_SUBGRAPH_URL, IMPERMAX_CHEF_SUBGRAPH_URL, IMPERMAX_SUBGRAPH_URL, XIMX_SUBGRAPH_URL } from './config/subgraphs';
|
|
21
21
|
import { Address, AddressIndex, AmmIndex, DistributorDetails, Factory, Extension, FactoryIndex, LendingPoolIndex, NetworkFactoryIndex, NetworkIndex, Networks, PoolTokenType, ProposalState, WhitelistState, VaultType, Borrowable } from './config/types';
|
|
22
|
-
import { AirdropData, ApprovalType, Changes, Contract, OnchainConfig, NO_CHANGES, PendingRewardUI, PermitData, Values, CollateralConfig,
|
|
22
|
+
import { AirdropData, ApprovalType, Changes, Contract, OnchainConfig, NO_CHANGES, PendingRewardUI, PermitData, Values, CollateralConfig, BorrowableV2Config, BorrowableV3Config, PairConfig, Permits, Permit, PermitType } from './onchain/onchainTypes';
|
|
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';
|
|
@@ -42,4 +42,4 @@ import { decimalToBalance } from './utils/ether-utils';
|
|
|
42
42
|
import OffchainAccountLendingPoolV3 from "./offchain/account/lendingPool/offchainAccountLendingPoolV3";
|
|
43
43
|
import OffchainAccountNftlpUniswapV3 from './offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3';
|
|
44
44
|
import { MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice } from "./utils/nftlpMath/uniswapV3General";
|
|
45
|
-
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,
|
|
45
|
+
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, 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 };
|
|
@@ -76,8 +76,8 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
|
|
|
76
76
|
}
|
|
77
77
|
createNewPositionObject(fee, priceA, priceB, lockStateChange = false) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
-
|
|
80
|
-
0, 0, yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), priceA, priceB, yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
79
|
+
// TODO check for priceA/priceB sanity
|
|
80
|
+
return new uniswapV3Position_1.default(0, 0, 0, yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), priceA, priceB, yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
getPositionObject(tokenId) {
|
|
@@ -21,18 +21,21 @@ export default class OnchainPairConfig {
|
|
|
21
21
|
getReserveFactor: () => Promise<number>;
|
|
22
22
|
getKinkUtilizationRate: () => Promise<number>;
|
|
23
23
|
getAdjustSpeed: () => Promise<number>;
|
|
24
|
-
getBorrowTracker: () => Promise<Address>;
|
|
24
|
+
getBorrowTracker: () => Promise<Address | undefined>;
|
|
25
|
+
getDebtCeiling: () => Promise<string | undefined>;
|
|
25
26
|
};
|
|
26
27
|
getBorrowableA: () => {
|
|
27
28
|
getReserveFactor: () => Promise<number>;
|
|
28
29
|
getKinkUtilizationRate: () => Promise<number>;
|
|
29
30
|
getAdjustSpeed: () => Promise<number>;
|
|
30
|
-
getBorrowTracker: () => Promise<Address>;
|
|
31
|
+
getBorrowTracker: () => Promise<Address | undefined>;
|
|
32
|
+
getDebtCeiling: () => Promise<string | undefined>;
|
|
31
33
|
};
|
|
32
34
|
getBorrowableB: () => {
|
|
33
35
|
getReserveFactor: () => Promise<number>;
|
|
34
36
|
getKinkUtilizationRate: () => Promise<number>;
|
|
35
37
|
getAdjustSpeed: () => Promise<number>;
|
|
36
|
-
getBorrowTracker: () => Promise<Address>;
|
|
38
|
+
getBorrowTracker: () => Promise<Address | undefined>;
|
|
39
|
+
getDebtCeiling: () => Promise<string | undefined>;
|
|
37
40
|
};
|
|
38
41
|
}
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const types_1 = require("../../config/types");
|
|
13
13
|
const impermax_factories_1 = require("../../config/contracts/impermax-factories");
|
|
14
|
+
const onchainTypes_1 = require("../onchainTypes");
|
|
14
15
|
class OnchainPairConfig {
|
|
15
16
|
constructor(proposal, pairConfig) {
|
|
16
17
|
this.getProposal = () => this.proposal;
|
|
@@ -36,7 +37,7 @@ class OnchainPairConfig {
|
|
|
36
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
38
|
if (!this.lendingPool)
|
|
38
39
|
this.lendingPool = (() => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
const impermaxFactory =
|
|
40
|
+
const impermaxFactory = this.getOnchain().getImpermaxFactory(yield this.getFactory());
|
|
40
41
|
return impermaxFactory.getLendingPool(yield this.getPairAddress());
|
|
41
42
|
}))();
|
|
42
43
|
return this.lendingPool;
|
|
@@ -77,7 +78,10 @@ class OnchainPairConfig {
|
|
|
77
78
|
return parseInt(borrowableConfig.adjustSpeed) / 1e18;
|
|
78
79
|
}),
|
|
79
80
|
getBorrowTracker: () => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
return borrowableConfig.borrowTracker;
|
|
81
|
+
return (0, onchainTypes_1.isBorrowableV2Config)(borrowableConfig) ? borrowableConfig.borrowTracker : undefined;
|
|
82
|
+
}),
|
|
83
|
+
getDebtCeiling: () => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
return (0, onchainTypes_1.isBorrowableV3Config)(borrowableConfig) ? borrowableConfig.debtCeiling : undefined;
|
|
81
85
|
}),
|
|
82
86
|
};
|
|
83
87
|
}
|
|
@@ -72,7 +72,7 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
72
72
|
throw new Error("Opposite depositADelta and depositBDelta signs");
|
|
73
73
|
const router = this.getUniswapV3Router();
|
|
74
74
|
const actionsGetter = this.getActionsGetter();
|
|
75
|
-
const optimalLiquidity = positionObject.
|
|
75
|
+
const optimalLiquidity = positionObject.getOptimalLiquidity(depositADelta, depositBDelta);
|
|
76
76
|
depositADelta = optimalLiquidity.amountX;
|
|
77
77
|
depositBDelta = optimalLiquidity.amountY;
|
|
78
78
|
// slightly increase repayAmount if we are repaying 100%
|
|
@@ -60,12 +60,19 @@ export interface CollateralConfig {
|
|
|
60
60
|
liquidationIncentive: string;
|
|
61
61
|
liquidationFee: string;
|
|
62
62
|
}
|
|
63
|
-
export interface
|
|
63
|
+
export interface BorrowableV2Config {
|
|
64
64
|
reserveFactor: string;
|
|
65
65
|
kinkUtilizationRate: string;
|
|
66
66
|
adjustSpeed: string;
|
|
67
67
|
borrowTracker: string;
|
|
68
68
|
}
|
|
69
|
+
export interface BorrowableV3Config {
|
|
70
|
+
reserveFactor: string;
|
|
71
|
+
kinkUtilizationRate: string;
|
|
72
|
+
adjustSpeed: string;
|
|
73
|
+
debtCeiling: string;
|
|
74
|
+
}
|
|
75
|
+
export type BorrowableConfig = BorrowableV2Config | BorrowableV3Config;
|
|
69
76
|
export interface PairConfig {
|
|
70
77
|
factory: string;
|
|
71
78
|
pair: string;
|
|
@@ -74,3 +81,5 @@ export interface PairConfig {
|
|
|
74
81
|
borrowable0Config: BorrowableConfig;
|
|
75
82
|
borrowable1Config: BorrowableConfig;
|
|
76
83
|
}
|
|
84
|
+
export declare const isBorrowableV2Config: (config: BorrowableConfig) => config is BorrowableV2Config;
|
|
85
|
+
export declare const isBorrowableV3Config: (config: BorrowableConfig) => config is BorrowableV3Config;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NO_CHANGES = exports.PermitType = exports.ApprovalType = void 0;
|
|
3
|
+
exports.isBorrowableV3Config = exports.isBorrowableV2Config = exports.NO_CHANGES = exports.PermitType = exports.ApprovalType = void 0;
|
|
4
4
|
var ApprovalType;
|
|
5
5
|
(function (ApprovalType) {
|
|
6
6
|
ApprovalType[ApprovalType["POOL_TOKEN"] = 0] = "POOL_TOKEN";
|
|
@@ -19,3 +19,11 @@ exports.NO_CHANGES = {
|
|
|
19
19
|
changeBorrowedB: 0,
|
|
20
20
|
changeCollateral: 0,
|
|
21
21
|
};
|
|
22
|
+
const isBorrowableV2Config = (config) => {
|
|
23
|
+
return 'borrowTracker' in config;
|
|
24
|
+
};
|
|
25
|
+
exports.isBorrowableV2Config = isBorrowableV2Config;
|
|
26
|
+
const isBorrowableV3Config = (config) => {
|
|
27
|
+
return 'debtCeiling' in config;
|
|
28
|
+
};
|
|
29
|
+
exports.isBorrowableV3Config = isBorrowableV3Config;
|
|
@@ -14,15 +14,37 @@ export default class UniswapV3Position {
|
|
|
14
14
|
liquidationPenalty: number;
|
|
15
15
|
constructor(_liquidity: number, _debtX: number, _debtY: number, _marketPrice: number, _oraclePrice: number, _priceA: number, _priceB: number, _safetyMargin: number, _liquidationPenalty: number, _lockStateChange: boolean);
|
|
16
16
|
private checkLock;
|
|
17
|
+
/**
|
|
18
|
+
* PRIVATE
|
|
19
|
+
*/
|
|
20
|
+
private getRealXGivenLiquidityAndPrice;
|
|
21
|
+
private getRealYGivenLiquidityAndPrice;
|
|
22
|
+
private getRealXGivenLiquidity;
|
|
23
|
+
private getRealYGivenLiquidity;
|
|
24
|
+
private getRealXGivenPrice;
|
|
25
|
+
private getRealYGivenPrice;
|
|
26
|
+
private getLiquidity;
|
|
27
|
+
/**
|
|
28
|
+
* PUBLIC SETTERS
|
|
29
|
+
*/
|
|
17
30
|
setLiquidity(_liquidity: number): void;
|
|
31
|
+
setRealX(amountX: number): void;
|
|
32
|
+
setRealY(amountY: number): void;
|
|
18
33
|
setDebtX(_debtX: number): void;
|
|
19
34
|
setDebtY(_debtY: number): void;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
/**
|
|
36
|
+
* PUBLIC GETTERS
|
|
37
|
+
*/
|
|
38
|
+
getRealX(): number;
|
|
39
|
+
getRealY(): number;
|
|
40
|
+
getNetX(): number;
|
|
41
|
+
getNetY(): number;
|
|
42
|
+
getLiquidationRange(): {
|
|
43
|
+
priceA: number;
|
|
44
|
+
priceB: number;
|
|
45
|
+
};
|
|
46
|
+
leverage(): void;
|
|
47
|
+
getOptimalLiquidity(amountX: number, amountY: number): {
|
|
26
48
|
liquidity: number;
|
|
27
49
|
amountX: number;
|
|
28
50
|
amountY: number;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function getVirtualX(liquidity, price) {
|
|
4
|
+
return liquidity / Math.sqrt(price);
|
|
5
|
+
}
|
|
6
|
+
function getVirtualY(liquidity, price) {
|
|
7
|
+
return liquidity * Math.sqrt(price);
|
|
8
|
+
}
|
|
9
|
+
function getRealX(liquidity, price, priceA, priceB) {
|
|
10
|
+
const surplusX = getVirtualX(liquidity, priceB);
|
|
11
|
+
const virtualX = getVirtualX(liquidity, Math.max(price, priceA));
|
|
12
|
+
return Math.max(virtualX - surplusX, 0);
|
|
13
|
+
}
|
|
14
|
+
function getRealY(liquidity, price, priceA, priceB) {
|
|
15
|
+
const surplusY = getVirtualY(liquidity, priceA);
|
|
16
|
+
const virtualY = getVirtualY(liquidity, Math.min(price, priceB));
|
|
17
|
+
return Math.max(virtualY - surplusY, 0);
|
|
18
|
+
}
|
|
3
19
|
class UniswapV3Position {
|
|
4
20
|
// TODO add fee logic
|
|
5
21
|
constructor(_liquidity, _debtX, _debtY, _marketPrice, _oraclePrice, _priceA, _priceB, _safetyMargin, _liquidationPenalty, _lockStateChange) {
|
|
@@ -18,10 +34,53 @@ class UniswapV3Position {
|
|
|
18
34
|
if (this.lockStateChange)
|
|
19
35
|
throw Error("Can't change state of original position object");
|
|
20
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* PRIVATE
|
|
39
|
+
*/
|
|
40
|
+
getRealXGivenLiquidityAndPrice(liquidity, price) {
|
|
41
|
+
return getRealX(liquidity, price, this.priceA, this.priceB);
|
|
42
|
+
}
|
|
43
|
+
getRealYGivenLiquidityAndPrice(liquidity, price) {
|
|
44
|
+
return getRealY(liquidity, price, this.priceA, this.priceB);
|
|
45
|
+
}
|
|
46
|
+
getRealXGivenLiquidity(liquidity) {
|
|
47
|
+
return this.getRealXGivenLiquidityAndPrice(liquidity, this.marketPrice);
|
|
48
|
+
}
|
|
49
|
+
getRealYGivenLiquidity(liquidity) {
|
|
50
|
+
return this.getRealYGivenLiquidityAndPrice(liquidity, this.marketPrice);
|
|
51
|
+
}
|
|
52
|
+
getRealXGivenPrice(price) {
|
|
53
|
+
return this.getRealXGivenLiquidityAndPrice(this.liquidity, price);
|
|
54
|
+
}
|
|
55
|
+
getRealYGivenPrice(price) {
|
|
56
|
+
return this.getRealYGivenLiquidityAndPrice(this.liquidity, price);
|
|
57
|
+
}
|
|
58
|
+
getLiquidity(price, amountX, amountY) {
|
|
59
|
+
if (amountX == 0) {
|
|
60
|
+
return amountY / Math.sqrt(price);
|
|
61
|
+
}
|
|
62
|
+
if (amountY == 0) {
|
|
63
|
+
return amountX * Math.sqrt(price);
|
|
64
|
+
}
|
|
65
|
+
return amountX / (1 / Math.sqrt(price) - 1 / Math.sqrt(this.priceB));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* PUBLIC SETTERS
|
|
69
|
+
*/
|
|
21
70
|
setLiquidity(_liquidity) {
|
|
22
71
|
this.checkLock();
|
|
23
72
|
this.liquidity = _liquidity;
|
|
24
73
|
}
|
|
74
|
+
setRealX(amountX) {
|
|
75
|
+
this.checkLock();
|
|
76
|
+
const { liquidity } = this.getOptimalLiquidity(amountX, Infinity);
|
|
77
|
+
this.liquidity = liquidity;
|
|
78
|
+
}
|
|
79
|
+
setRealY(amountY) {
|
|
80
|
+
this.checkLock();
|
|
81
|
+
const { liquidity } = this.getOptimalLiquidity(Infinity, amountY);
|
|
82
|
+
this.liquidity = liquidity;
|
|
83
|
+
}
|
|
25
84
|
setDebtX(_debtX) {
|
|
26
85
|
this.checkLock();
|
|
27
86
|
this.debtX = _debtX;
|
|
@@ -30,40 +89,38 @@ class UniswapV3Position {
|
|
|
30
89
|
this.checkLock();
|
|
31
90
|
this.debtY = _debtY;
|
|
32
91
|
}
|
|
33
|
-
|
|
34
|
-
|
|
92
|
+
/**
|
|
93
|
+
* PUBLIC GETTERS
|
|
94
|
+
*/
|
|
95
|
+
getRealX() {
|
|
96
|
+
return this.getRealXGivenLiquidityAndPrice(this.liquidity, this.marketPrice);
|
|
35
97
|
}
|
|
36
|
-
|
|
37
|
-
return this.liquidity
|
|
98
|
+
getRealY() {
|
|
99
|
+
return this.getRealYGivenLiquidityAndPrice(this.liquidity, this.marketPrice);
|
|
38
100
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const virtualX = this.getVirtualX(Math.max(price, this.priceA));
|
|
42
|
-
return Math.max(virtualX - surplusX, 0);
|
|
101
|
+
getNetX() {
|
|
102
|
+
return this.getRealX() - this.debtX;
|
|
43
103
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const virtualY = this.getVirtualY(Math.min(price, this.priceB));
|
|
47
|
-
return Math.max(virtualY - surplusY, 0);
|
|
104
|
+
getNetY() {
|
|
105
|
+
return this.getRealY() - this.debtY;
|
|
48
106
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
107
|
+
getLiquidationRange() {
|
|
108
|
+
// TODO
|
|
109
|
+
return {
|
|
110
|
+
priceA: 0,
|
|
111
|
+
priceB: Infinity,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
leverage() {
|
|
57
115
|
}
|
|
58
116
|
// amountX and amountY are expected to have the same sign
|
|
59
|
-
|
|
60
|
-
let liquidity;
|
|
117
|
+
getOptimalLiquidity(amountX, amountY) {
|
|
61
118
|
if (amountX != 0 && amountY != 0) {
|
|
62
|
-
const sampleX = this.
|
|
63
|
-
const sampleY = this.
|
|
119
|
+
const sampleX = this.getRealXGivenLiquidity(1);
|
|
120
|
+
const sampleY = this.getRealYGivenLiquidity(1);
|
|
64
121
|
if (sampleX == 0)
|
|
65
122
|
amountX = 0;
|
|
66
|
-
else if (
|
|
123
|
+
else if (sampleY == 0)
|
|
67
124
|
amountY = 0;
|
|
68
125
|
else {
|
|
69
126
|
if (Math.abs(amountX) / sampleX > Math.abs(amountY) / sampleY)
|
|
@@ -72,7 +129,7 @@ class UniswapV3Position {
|
|
|
72
129
|
amountY = amountX / sampleX * sampleY;
|
|
73
130
|
}
|
|
74
131
|
}
|
|
75
|
-
liquidity = this.getLiquidity(this.marketPrice, amountX, amountY);
|
|
132
|
+
const liquidity = this.getLiquidity(this.marketPrice, amountX, amountY);
|
|
76
133
|
return { liquidity, amountX, amountY };
|
|
77
134
|
}
|
|
78
135
|
}
|