impermax-sdk 2.1.321 → 2.1.322
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/config/whitelist.js +1 -1
- package/lib/index.d.ts +4 -2
- package/lib/index.js +6 -2
- package/lib/offchain/lendingPool/offchainBorrowable.d.ts +1 -1
- package/lib/offchain/lendingPool/offchainBorrowable.js +1 -1
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +1 -1
- package/lib/utils/{borrowableEntity → borrowable/borrowableEntity}/index.d.ts +9 -4
- package/lib/utils/{borrowableEntity → borrowable/borrowableEntity}/index.js +51 -18
- package/lib/utils/borrowable/borrowablePosition/index.d.ts +27 -0
- package/lib/utils/borrowable/borrowablePosition/index.js +51 -0
- package/lib/utils/position/genericPosition.d.ts +1 -1
- package/lib/utils/position/genericPosition.js +1 -1
- package/lib/utils/position/uniswapV2/index.d.ts +1 -1
- package/lib/utils/position/uniswapV3/index.d.ts +1 -1
- package/lib/utils/vault/lendingVaultEntity/index.d.ts +32 -0
- package/lib/utils/vault/lendingVaultEntity/index.js +123 -0
- package/package.json +1 -1
package/lib/config/whitelist.js
CHANGED
|
@@ -411,7 +411,6 @@ exports.WHITELISTED_OLD = {
|
|
|
411
411
|
// SolidLizard
|
|
412
412
|
"0x1229aAC120Ae75301aB1c3A2A04ec14183493584",
|
|
413
413
|
"0x463Ec151258370a07431068BB3BdC98B5a6bA18f",
|
|
414
|
-
"0x85de0B4E00e27fB197FF6aB705825f21Bc683a3f",
|
|
415
414
|
"0xD191B203c893BEb5323c25D2efFbB3EA1f7dFd84",
|
|
416
415
|
"0x9e9631f83832455FE4B83CC7Ed9D3460dbD03529",
|
|
417
416
|
"0x568683dc1FDC8828230896BfC20d6Eaf91f76239",
|
|
@@ -702,6 +701,7 @@ exports.BLACKLISTED = {
|
|
|
702
701
|
"0x1bE5e42f53B54F3eC887340Db1A7394a0A664c95", //USDC-DAI SwapFish
|
|
703
702
|
],
|
|
704
703
|
[types_1.Factory.SOLV2]: [
|
|
704
|
+
"0x85de0B4E00e27fB197FF6aB705825f21Bc683a3f",
|
|
705
705
|
"0xb600D52952878Db5D7c7c0bE06389c85762f8222",
|
|
706
706
|
"0x01a464e2BF76Bd4A3A50073026fF2335584D67d8", //GND-gmUSD Chronos
|
|
707
707
|
]
|
package/lib/index.d.ts
CHANGED
|
@@ -48,7 +48,9 @@ import { MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice } from "./util
|
|
|
48
48
|
import UniswapV3Position from './utils/position/uniswapV3';
|
|
49
49
|
import UniswapV2Position from './utils/position/uniswapV2';
|
|
50
50
|
import Position from './utils/position/interface';
|
|
51
|
-
import { BorrowableEntity } from './utils/borrowableEntity';
|
|
51
|
+
import { BorrowableEntity } from './utils/borrowable/borrowableEntity';
|
|
52
|
+
import { BorrowablePosition } from './utils/borrowable/borrowablePosition';
|
|
53
|
+
import { LendingVaultEntity } from './utils/vault/lendingVaultEntity';
|
|
52
54
|
import OffchainLendingPoolV2 from './offchain/lendingPool/offchainLendingPoolV2';
|
|
53
55
|
import OffchainBorrowableV2 from './offchain/lendingPool/offchainBorrowableV2';
|
|
54
56
|
import OffchainCollateralV2 from './offchain/lendingPool/offchainCollateralV2';
|
|
@@ -68,4 +70,4 @@ import OnchainAccountNftlp from './onchain/account/lendingPool/nftlp';
|
|
|
68
70
|
import OffchainAccountBorrowableV3 from './offchain/account/lendingPool/offchainAccountBorrowableV3';
|
|
69
71
|
import { PairState } from "./config/whitelist";
|
|
70
72
|
import { AccountMarketData } from './offchain/account/offchainAccount';
|
|
71
|
-
export { offchain, OffchainMultichain, Offchain, OffchainPoolToken, OffchainLendingPool, OffchainCollateral, OffchainBorrowable, OffchainLendingPoolV2, OffchainCollateralV2, OffchainBorrowableV2, OffchainLendingPoolV3, OffchainCollateralV3, OffchainBorrowableV3, OffchainNftlp, OffchainNftlpUniswapV3, OffchainVault, OffchainLeveragedVault, OffchainLendingVault, OffchainHedgedVault, OffchainConfigManager, OffchainPairConfig, OffchainProposal, OffchainMultichainAccount, OffchainAccount, OffchainAccountPoolToken, OffchainAccountLendingPool, OffchainAccountCollateral, OffchainAccountBorrowable, OffchainAccountLendingPoolV2, OffchainAccountCollateralV2, OffchainAccountBorrowableV2, OffchainAccountLendingPoolV3, OffchainAccountCollateralV3, OffchainAccountBorrowableV3, OffchainAccountNftlp, OffchainAccountNftlpUniswapV3, 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, OnchainImpermaxFactory, OnchainImpermaxFactoryV2, OnchainImpermaxFactoryV3, OnchainPoolToken, OnchainLendingPool, OnchainBorrowable, OnchainCollateral, OnchainLendingPoolV2, OnchainBorrowableV2, OnchainCollateralV2, OnchainLendingPoolV3, OnchainBorrowableV3, OnchainCollateralV3, OnchainNftlp, OnchainNftlpUniswapV3, OnchainLendingVault, OnchainConfigManager, OnchainProposal, OnchainPairConfig, OnchainAccount, OnchainAccountPoolToken, OnchainAccountLendingPool, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingPoolV2, OnchainAccountBorrowableV2, OnchainAccountCollateralV2, OnchainAccountLendingPoolV3, OnchainAccountBorrowableV3, OnchainAccountCollateralV3, OnchainAccountNftlp, OnchainAccountNftlpUniswapV3, OnchainAccountLendingVault, OnchainContractsHelper, OnchainInteractions, OnchainInteractionsPoolToken, OnchainInteractionsLendingPool, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingPoolV2, OnchainInteractionsCollateralV2, OnchainInteractionsBorrowableV2, OnchainInteractionsLendingPoolV3, OnchainInteractionsCollateralV3, OnchainInteractionsBorrowableV3, OnchainInteractionsNftlp, OnchainInteractionsNftlpUniswapV3, 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, decimalToBalance, MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice, isV3Factory, UniswapV3Position, UniswapV2Position, Position, BorrowableEntity, PairState, SupplyPositionsParams, BorrowPositionsParams, TopPositionsParams, VaultPositionsParams, AccountEarningsParams, AccountMarketData };
|
|
73
|
+
export { offchain, OffchainMultichain, Offchain, OffchainPoolToken, OffchainLendingPool, OffchainCollateral, OffchainBorrowable, OffchainLendingPoolV2, OffchainCollateralV2, OffchainBorrowableV2, OffchainLendingPoolV3, OffchainCollateralV3, OffchainBorrowableV3, OffchainNftlp, OffchainNftlpUniswapV3, OffchainVault, OffchainLeveragedVault, OffchainLendingVault, OffchainHedgedVault, OffchainConfigManager, OffchainPairConfig, OffchainProposal, OffchainMultichainAccount, OffchainAccount, OffchainAccountPoolToken, OffchainAccountLendingPool, OffchainAccountCollateral, OffchainAccountBorrowable, OffchainAccountLendingPoolV2, OffchainAccountCollateralV2, OffchainAccountBorrowableV2, OffchainAccountLendingPoolV3, OffchainAccountCollateralV3, OffchainAccountBorrowableV3, OffchainAccountNftlp, OffchainAccountNftlpUniswapV3, 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, OnchainImpermaxFactory, OnchainImpermaxFactoryV2, OnchainImpermaxFactoryV3, OnchainPoolToken, OnchainLendingPool, OnchainBorrowable, OnchainCollateral, OnchainLendingPoolV2, OnchainBorrowableV2, OnchainCollateralV2, OnchainLendingPoolV3, OnchainBorrowableV3, OnchainCollateralV3, OnchainNftlp, OnchainNftlpUniswapV3, OnchainLendingVault, OnchainConfigManager, OnchainProposal, OnchainPairConfig, OnchainAccount, OnchainAccountPoolToken, OnchainAccountLendingPool, OnchainAccountBorrowable, OnchainAccountCollateral, OnchainAccountLendingPoolV2, OnchainAccountBorrowableV2, OnchainAccountCollateralV2, OnchainAccountLendingPoolV3, OnchainAccountBorrowableV3, OnchainAccountCollateralV3, OnchainAccountNftlp, OnchainAccountNftlpUniswapV3, OnchainAccountLendingVault, OnchainContractsHelper, OnchainInteractions, OnchainInteractionsPoolToken, OnchainInteractionsLendingPool, OnchainInteractionsCollateral, OnchainInteractionsBorrowable, OnchainInteractionsLendingPoolV2, OnchainInteractionsCollateralV2, OnchainInteractionsBorrowableV2, OnchainInteractionsLendingPoolV3, OnchainInteractionsCollateralV3, OnchainInteractionsBorrowableV3, OnchainInteractionsNftlp, OnchainInteractionsNftlpUniswapV3, 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, decimalToBalance, MAX_TICK, MIN_TICK, formatPriceSqrtX96, uniV3TickToPrice, isV3Factory, UniswapV3Position, UniswapV2Position, Position, BorrowableEntity, BorrowablePosition, LendingVaultEntity, PairState, SupplyPositionsParams, BorrowPositionsParams, TopPositionsParams, VaultPositionsParams, AccountEarningsParams, AccountMarketData };
|
package/lib/index.js
CHANGED
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.OnchainBorrowable = exports.OnchainLendingPool = exports.OnchainPoolToken = exports.OnchainImpermaxFactoryV3 = exports.OnchainImpermaxFactoryV2 = exports.OnchainImpermaxFactory = exports.Onchain = exports.onchain = exports.VaultType = exports.VaultRisk = exports.OffchainSolidexHelper = exports.OffchainPriceHelper = exports.OffchainAccountVault = exports.OffchainLeveragedPosition = exports.OffchainAccountNftlpUniswapV3 = exports.OffchainAccountNftlp = exports.OffchainAccountBorrowableV3 = exports.OffchainAccountCollateralV3 = exports.OffchainAccountLendingPoolV3 = exports.OffchainAccountBorrowableV2 = exports.OffchainAccountCollateralV2 = exports.OffchainAccountLendingPoolV2 = exports.OffchainAccountBorrowable = exports.OffchainAccountCollateral = exports.OffchainAccountLendingPool = exports.OffchainAccountPoolToken = exports.OffchainAccount = exports.OffchainMultichainAccount = exports.OffchainProposal = exports.OffchainPairConfig = exports.OffchainConfigManager = exports.OffchainHedgedVault = exports.OffchainLendingVault = exports.OffchainLeveragedVault = exports.OffchainVault = exports.OffchainNftlpUniswapV3 = exports.OffchainNftlp = exports.OffchainBorrowableV3 = exports.OffchainCollateralV3 = exports.OffchainLendingPoolV3 = exports.OffchainBorrowableV2 = exports.OffchainCollateralV2 = exports.OffchainLendingPoolV2 = exports.OffchainBorrowable = exports.OffchainCollateral = exports.OffchainLendingPool = exports.OffchainPoolToken = exports.Offchain = exports.OffchainMultichain = exports.offchain = void 0;
|
|
30
30
|
exports.getNetworkFactories = exports.IMPERMAX_FACTORY = exports.IMX = exports.IMPERMAX_CHEF = exports.CLAIM_AGGREGATOR = exports.NO_CHANGES = exports.ApprovalType = exports.OnchainInteractionsConfigManager = exports.OnchainInteractionsLendingVault = exports.OnchainInteractionsNftlpUniswapV3 = exports.OnchainInteractionsNftlp = exports.OnchainInteractionsBorrowableV3 = exports.OnchainInteractionsCollateralV3 = exports.OnchainInteractionsLendingPoolV3 = exports.OnchainInteractionsBorrowableV2 = exports.OnchainInteractionsCollateralV2 = exports.OnchainInteractionsLendingPoolV2 = exports.OnchainInteractionsBorrowable = exports.OnchainInteractionsCollateral = exports.OnchainInteractionsLendingPool = exports.OnchainInteractionsPoolToken = exports.OnchainInteractions = exports.OnchainContractsHelper = exports.OnchainAccountLendingVault = exports.OnchainAccountNftlpUniswapV3 = exports.OnchainAccountNftlp = exports.OnchainAccountCollateralV3 = exports.OnchainAccountBorrowableV3 = exports.OnchainAccountLendingPoolV3 = exports.OnchainAccountCollateralV2 = exports.OnchainAccountBorrowableV2 = exports.OnchainAccountLendingPoolV2 = exports.OnchainAccountCollateral = exports.OnchainAccountBorrowable = exports.OnchainAccountLendingPool = exports.OnchainAccountPoolToken = exports.OnchainAccount = exports.OnchainPairConfig = exports.OnchainProposal = exports.OnchainConfigManager = exports.OnchainLendingVault = exports.OnchainNftlpUniswapV3 = exports.OnchainNftlp = exports.OnchainCollateralV3 = exports.OnchainBorrowableV3 = exports.OnchainLendingPoolV3 = exports.OnchainCollateralV2 = exports.OnchainBorrowableV2 = exports.OnchainLendingPoolV2 = exports.OnchainCollateral = void 0;
|
|
31
31
|
exports.PermitType = exports.PositionType = exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Extension = 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 = void 0;
|
|
32
|
-
exports.BorrowableEntity = exports.UniswapV2Position = exports.UniswapV3Position = exports.isV3Factory = exports.uniV3TickToPrice = exports.formatPriceSqrtX96 = exports.MIN_TICK = exports.MAX_TICK = exports.decimalToBalance = exports.Borrowable = void 0;
|
|
32
|
+
exports.LendingVaultEntity = exports.BorrowablePosition = exports.BorrowableEntity = exports.UniswapV2Position = exports.UniswapV3Position = exports.isV3Factory = exports.uniV3TickToPrice = exports.formatPriceSqrtX96 = exports.MIN_TICK = exports.MAX_TICK = exports.decimalToBalance = exports.Borrowable = void 0;
|
|
33
33
|
const offchain_1 = __importStar(require("./offchain"));
|
|
34
34
|
exports.Offchain = offchain_1.default;
|
|
35
35
|
Object.defineProperty(exports, "OffchainAccount", { enumerable: true, get: function () { return offchain_1.OffchainAccount; } });
|
|
@@ -223,8 +223,12 @@ const uniswapV3_1 = __importDefault(require("./utils/position/uniswapV3"));
|
|
|
223
223
|
exports.UniswapV3Position = uniswapV3_1.default;
|
|
224
224
|
const uniswapV2_1 = __importDefault(require("./utils/position/uniswapV2"));
|
|
225
225
|
exports.UniswapV2Position = uniswapV2_1.default;
|
|
226
|
-
const borrowableEntity_1 = require("./utils/borrowableEntity");
|
|
226
|
+
const borrowableEntity_1 = require("./utils/borrowable/borrowableEntity");
|
|
227
227
|
Object.defineProperty(exports, "BorrowableEntity", { enumerable: true, get: function () { return borrowableEntity_1.BorrowableEntity; } });
|
|
228
|
+
const borrowablePosition_1 = require("./utils/borrowable/borrowablePosition");
|
|
229
|
+
Object.defineProperty(exports, "BorrowablePosition", { enumerable: true, get: function () { return borrowablePosition_1.BorrowablePosition; } });
|
|
230
|
+
const lendingVaultEntity_1 = require("./utils/vault/lendingVaultEntity");
|
|
231
|
+
Object.defineProperty(exports, "LendingVaultEntity", { enumerable: true, get: function () { return lendingVaultEntity_1.LendingVaultEntity; } });
|
|
228
232
|
const offchainLendingPoolV2_1 = __importDefault(require("./offchain/lendingPool/offchainLendingPoolV2"));
|
|
229
233
|
exports.OffchainLendingPoolV2 = offchainLendingPoolV2_1.default;
|
|
230
234
|
const offchainBorrowableV2_1 = __importDefault(require("./offchain/lendingPool/offchainBorrowableV2"));
|
|
@@ -2,7 +2,7 @@ import { BorrowablePastData, PoolTokenData } from "../offchainTypes";
|
|
|
2
2
|
import { Address, Borrowable } from "../../config/types";
|
|
3
3
|
import OffchainPoolToken from "../offchainPoolToken";
|
|
4
4
|
import OffchainLendingPool from "./offchainLendingPool";
|
|
5
|
-
import { BorrowableEntity } from "../../utils/borrowableEntity";
|
|
5
|
+
import { BorrowableEntity } from "../../utils/borrowable/borrowableEntity";
|
|
6
6
|
export default class OffchainBorrowable extends OffchainPoolToken {
|
|
7
7
|
protected readonly lendingPool: OffchainLendingPool;
|
|
8
8
|
protected readonly borrowable: Borrowable;
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("../../utils");
|
|
7
7
|
const offchainPoolToken_1 = __importDefault(require("../offchainPoolToken"));
|
|
8
|
-
const borrowableEntity_1 = require("../../utils/borrowableEntity");
|
|
8
|
+
const borrowableEntity_1 = require("../../utils/borrowable/borrowableEntity");
|
|
9
9
|
class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
10
10
|
async createBorrowableObject(lockStateChange = false) {
|
|
11
11
|
const { kinkBorrowRate } = await this._calculateBorrowRate();
|
|
@@ -3,7 +3,7 @@ import { Address, Borrowable } from '../../../config/types';
|
|
|
3
3
|
import OnchainLendingPool from './index';
|
|
4
4
|
import OnchainPoolToken from '../../onchainPoolToken';
|
|
5
5
|
import OffchainBorrowable from '../../../offchain/lendingPool/offchainBorrowable';
|
|
6
|
-
import { BorrowableEntity } from "../../../utils/borrowableEntity";
|
|
6
|
+
import { BorrowableEntity } from "../../../utils/borrowable/borrowableEntity";
|
|
7
7
|
export default abstract class OnchainBorrowable extends OnchainPoolToken {
|
|
8
8
|
protected readonly lendingPool: OnchainLendingPool;
|
|
9
9
|
protected readonly borrowable: Borrowable;
|
|
@@ -33,11 +33,16 @@ export declare class BorrowableEntity {
|
|
|
33
33
|
getSupplyRate(): number;
|
|
34
34
|
getBorrowAPR(): number;
|
|
35
35
|
getSupplyAPR(): number;
|
|
36
|
+
getKinkSupplyRate(): number;
|
|
37
|
+
calculateUtilizationForRate(rate: number): number;
|
|
38
|
+
calculateAmountForRate(rate: number): number;
|
|
36
39
|
/**
|
|
37
40
|
* PUBLIC SETTERS
|
|
38
41
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
resetSupply(): void;
|
|
43
|
+
supply(amount: number, relative?: boolean): void;
|
|
44
|
+
withdraw(amount: number, relative?: boolean): void;
|
|
45
|
+
resetBorrow(): void;
|
|
46
|
+
borrow(amount: number, relative?: boolean): void;
|
|
47
|
+
repay(amount: number, relative?: boolean): void;
|
|
43
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BorrowableEntity = void 0;
|
|
4
|
-
const index_1 = require("
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
5
|
class BorrowableEntity {
|
|
6
6
|
constructor(params) {
|
|
7
7
|
this.totalSupply = params.totalSupply;
|
|
@@ -17,7 +17,7 @@ class BorrowableEntity {
|
|
|
17
17
|
}
|
|
18
18
|
checkLock() {
|
|
19
19
|
if (this.lockStateChange)
|
|
20
|
-
throw Error("Can't change state of original position object");
|
|
20
|
+
throw new Error("Can't change state of original position object");
|
|
21
21
|
else
|
|
22
22
|
this.state++;
|
|
23
23
|
}
|
|
@@ -66,34 +66,67 @@ class BorrowableEntity {
|
|
|
66
66
|
getSupplyAPR() {
|
|
67
67
|
return (0, index_1.toAPR)(this.getSupplyRate());
|
|
68
68
|
}
|
|
69
|
+
getKinkSupplyRate() {
|
|
70
|
+
return this.kinkBorrowRate * this.kinkUtilizationRate * (1 - this.reserveFactor);
|
|
71
|
+
}
|
|
72
|
+
calculateUtilizationForRate(rate) {
|
|
73
|
+
if (rate < this.getKinkSupplyRate()) {
|
|
74
|
+
return Math.sqrt(rate / this.getKinkSupplyRate()) * this.kinkUtilizationRate;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const a = this.kinkMultiplier - 1;
|
|
78
|
+
const b = this.kinkUtilizationRate * this.kinkMultiplier - 1;
|
|
79
|
+
const c = rate * this.kinkUtilizationRate * (1 - this.kinkUtilizationRate) / this.getKinkSupplyRate();
|
|
80
|
+
return (b + Math.sqrt(b * b + 4 * a * c)) / (a * 2);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
calculateAmountForRate(rate) {
|
|
84
|
+
if (rate <= 0)
|
|
85
|
+
throw new Error("Target rate is 0 or negative");
|
|
86
|
+
if (rate > this.getSupplyRate())
|
|
87
|
+
throw new Error("Target rate is higher than current rate");
|
|
88
|
+
const targetUtilizationRate = this.calculateUtilizationForRate(rate);
|
|
89
|
+
const targetSupply = this.totalBorrows / targetUtilizationRate;
|
|
90
|
+
if (targetSupply < this.totalSupply)
|
|
91
|
+
throw new Error("Target supply is lower than current supply");
|
|
92
|
+
return targetSupply - this.totalSupply;
|
|
93
|
+
}
|
|
69
94
|
/**
|
|
70
95
|
* PUBLIC SETTERS
|
|
71
96
|
*/
|
|
72
|
-
|
|
97
|
+
resetSupply() {
|
|
98
|
+
this.totalSupply = this.initialTotalSupply;
|
|
99
|
+
}
|
|
100
|
+
supply(amount, relative = false) {
|
|
73
101
|
this.checkLock();
|
|
74
|
-
|
|
102
|
+
if (!relative)
|
|
103
|
+
this.resetSupply();
|
|
104
|
+
this.totalSupply += amount;
|
|
75
105
|
}
|
|
76
|
-
withdraw(amount) {
|
|
106
|
+
withdraw(amount, relative = false) {
|
|
77
107
|
this.checkLock();
|
|
78
|
-
if (
|
|
108
|
+
if (!relative)
|
|
109
|
+
this.resetSupply();
|
|
110
|
+
if (amount > this.getAvailableToWithdraw())
|
|
79
111
|
throw new Error("Trying to withdraw more than available liquidity");
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
this.totalSupply -= amount;
|
|
113
|
+
}
|
|
114
|
+
resetBorrow() {
|
|
115
|
+
this.totalBorrows = this.initialTotalBorrows;
|
|
84
116
|
}
|
|
85
|
-
borrow(amount) {
|
|
117
|
+
borrow(amount, relative = false) {
|
|
86
118
|
this.checkLock();
|
|
87
|
-
if (
|
|
119
|
+
if (!relative)
|
|
120
|
+
this.resetBorrow();
|
|
121
|
+
if (amount > this.getAvailableToBorrow())
|
|
88
122
|
throw new Error("Trying to borrow more than available liquidity");
|
|
89
|
-
|
|
90
|
-
else {
|
|
91
|
-
this.totalBorrows = this.initialTotalBorrows + amount;
|
|
92
|
-
}
|
|
123
|
+
this.totalBorrows += amount;
|
|
93
124
|
}
|
|
94
|
-
repay(amount) {
|
|
125
|
+
repay(amount, relative = false) {
|
|
95
126
|
this.checkLock();
|
|
96
|
-
|
|
127
|
+
if (!relative)
|
|
128
|
+
this.resetBorrow();
|
|
129
|
+
this.totalBorrows = Math.max(this.totalBorrows - amount, 0);
|
|
97
130
|
}
|
|
98
131
|
}
|
|
99
132
|
exports.BorrowableEntity = BorrowableEntity;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BorrowableEntity } from "../borrowableEntity";
|
|
2
|
+
export interface BorrowablePositionParams {
|
|
3
|
+
borrowable: BorrowableEntity;
|
|
4
|
+
amount: number;
|
|
5
|
+
lockStateChange?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class BorrowablePosition {
|
|
8
|
+
lockStateChange: boolean;
|
|
9
|
+
containsErrors: boolean;
|
|
10
|
+
state: number;
|
|
11
|
+
borrowable: BorrowableEntity;
|
|
12
|
+
amount: number;
|
|
13
|
+
initialAmount: number;
|
|
14
|
+
constructor(params: BorrowablePositionParams);
|
|
15
|
+
protected checkLock(): void;
|
|
16
|
+
/**
|
|
17
|
+
* PUBLIC GETTERS
|
|
18
|
+
*/
|
|
19
|
+
getAvailableToWithdraw(): number;
|
|
20
|
+
getInitialAvailableToWithdraw(): number;
|
|
21
|
+
/**
|
|
22
|
+
* PUBLIC SETTERS
|
|
23
|
+
*/
|
|
24
|
+
reset(): void;
|
|
25
|
+
supply(amount: number, relative?: boolean): void;
|
|
26
|
+
withdraw(amount: number, relative?: boolean): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BorrowablePosition = void 0;
|
|
4
|
+
class BorrowablePosition {
|
|
5
|
+
constructor(params) {
|
|
6
|
+
this.borrowable = params.borrowable;
|
|
7
|
+
this.amount = params.amount;
|
|
8
|
+
this.initialAmount = params.amount;
|
|
9
|
+
this.lockStateChange = params.lockStateChange ?? true;
|
|
10
|
+
this.state = 0;
|
|
11
|
+
}
|
|
12
|
+
checkLock() {
|
|
13
|
+
if (this.lockStateChange)
|
|
14
|
+
throw new Error("Can't change state of original position object");
|
|
15
|
+
else
|
|
16
|
+
this.state++;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* PUBLIC GETTERS
|
|
20
|
+
*/
|
|
21
|
+
getAvailableToWithdraw() {
|
|
22
|
+
return Math.min(this.amount, this.borrowable.getAvailableToWithdraw());
|
|
23
|
+
}
|
|
24
|
+
getInitialAvailableToWithdraw() {
|
|
25
|
+
return Math.min(this.initialAmount, this.borrowable.getInitialAvailableToWithdraw());
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* PUBLIC SETTERS
|
|
29
|
+
*/
|
|
30
|
+
reset() {
|
|
31
|
+
this.amount = this.initialAmount;
|
|
32
|
+
this.borrowable.resetSupply();
|
|
33
|
+
}
|
|
34
|
+
supply(amount, relative = false) {
|
|
35
|
+
this.checkLock();
|
|
36
|
+
if (!relative)
|
|
37
|
+
this.reset();
|
|
38
|
+
this.borrowable.supply(amount);
|
|
39
|
+
this.amount += amount;
|
|
40
|
+
}
|
|
41
|
+
withdraw(amount, relative = false) {
|
|
42
|
+
this.checkLock();
|
|
43
|
+
if (!relative)
|
|
44
|
+
this.reset();
|
|
45
|
+
if (amount > this.getAvailableToWithdraw())
|
|
46
|
+
throw new Error("Trying to withdraw more than available to withdraw");
|
|
47
|
+
this.borrowable.withdraw(amount);
|
|
48
|
+
this.amount -= amount;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.BorrowablePosition = BorrowablePosition;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import GenericPosition from "../genericPosition";
|
|
2
|
-
import { BorrowableEntity } from "../../borrowableEntity";
|
|
2
|
+
import { BorrowableEntity } from "../../borrowable/borrowableEntity";
|
|
3
3
|
export interface UniswapV3PositionParams {
|
|
4
4
|
liquidity: number;
|
|
5
5
|
unclaimedFeesX: number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { BorrowablePosition } from "../../borrowable/borrowablePosition";
|
|
2
|
+
export interface LendingVaultEntityParams {
|
|
3
|
+
positions: Array<BorrowablePosition>;
|
|
4
|
+
totalBalance: number;
|
|
5
|
+
reserveFactor: number;
|
|
6
|
+
lockStateChange?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare class LendingVaultEntity {
|
|
9
|
+
lockStateChange: boolean;
|
|
10
|
+
containsErrors: boolean;
|
|
11
|
+
state: number;
|
|
12
|
+
positions: Array<BorrowablePosition>;
|
|
13
|
+
totalBalance: number;
|
|
14
|
+
initialTotalBalance: number;
|
|
15
|
+
reserveFactor: number;
|
|
16
|
+
constructor(params: LendingVaultEntityParams);
|
|
17
|
+
protected checkLock(): void;
|
|
18
|
+
/**
|
|
19
|
+
* PUBLIC GETTERS
|
|
20
|
+
*/
|
|
21
|
+
getTotalSupply(): number;
|
|
22
|
+
getAvailableLiquidity(): number;
|
|
23
|
+
getSupplyRate(): number;
|
|
24
|
+
getSupplyAPR(): number;
|
|
25
|
+
/**
|
|
26
|
+
* PUBLIC SETTERS
|
|
27
|
+
*/
|
|
28
|
+
reset(): void;
|
|
29
|
+
supply(amount: number, relative?: boolean): void;
|
|
30
|
+
withdraw(amount: number, relative?: boolean): void;
|
|
31
|
+
reallocate(withdrawAmount?: number): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LendingVaultEntity = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class LendingVaultEntity {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
this.positions = params.positions;
|
|
8
|
+
this.totalBalance = params.totalBalance;
|
|
9
|
+
this.initialTotalBalance = params.totalBalance;
|
|
10
|
+
this.reserveFactor = params.reserveFactor;
|
|
11
|
+
this.lockStateChange = params.lockStateChange ?? true;
|
|
12
|
+
this.state = 0;
|
|
13
|
+
}
|
|
14
|
+
checkLock() {
|
|
15
|
+
if (this.lockStateChange)
|
|
16
|
+
throw new Error("Can't change state of original position object");
|
|
17
|
+
else
|
|
18
|
+
this.state++;
|
|
19
|
+
}
|
|
20
|
+
// TODO recreate reallocate algorithm
|
|
21
|
+
/**
|
|
22
|
+
* PUBLIC GETTERS
|
|
23
|
+
*/
|
|
24
|
+
getTotalSupply() {
|
|
25
|
+
let acc = this.totalBalance;
|
|
26
|
+
for (let position of this.positions) {
|
|
27
|
+
acc += position.amount;
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}
|
|
31
|
+
getAvailableLiquidity() {
|
|
32
|
+
let acc = this.totalBalance;
|
|
33
|
+
for (let position of this.positions) {
|
|
34
|
+
acc += position.getAvailableToWithdraw();
|
|
35
|
+
}
|
|
36
|
+
return acc;
|
|
37
|
+
}
|
|
38
|
+
getSupplyRate() {
|
|
39
|
+
let acc = 0;
|
|
40
|
+
for (let position of this.positions) {
|
|
41
|
+
acc += position.amount * position.borrowable.getSupplyRate();
|
|
42
|
+
}
|
|
43
|
+
return acc / this.getTotalSupply();
|
|
44
|
+
}
|
|
45
|
+
getSupplyAPR() {
|
|
46
|
+
return (0, index_1.toAPR)(this.getSupplyRate());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* PUBLIC SETTERS
|
|
50
|
+
*/
|
|
51
|
+
reset() {
|
|
52
|
+
this.totalBalance = this.initialTotalBalance;
|
|
53
|
+
for (let position of this.positions) {
|
|
54
|
+
position.reset();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
supply(amount, relative = false) {
|
|
58
|
+
this.checkLock();
|
|
59
|
+
if (!relative)
|
|
60
|
+
this.reset();
|
|
61
|
+
this.totalBalance += amount;
|
|
62
|
+
this.reallocate();
|
|
63
|
+
}
|
|
64
|
+
withdraw(amount, relative = false) {
|
|
65
|
+
this.checkLock();
|
|
66
|
+
if (!relative)
|
|
67
|
+
this.reset();
|
|
68
|
+
this.reallocate(amount);
|
|
69
|
+
}
|
|
70
|
+
// TODO this should reallocate only across enabled borrowables
|
|
71
|
+
reallocate(withdrawAmount = 0) {
|
|
72
|
+
if (this.positions.length === 0)
|
|
73
|
+
return;
|
|
74
|
+
for (let position of this.positions) {
|
|
75
|
+
const amount = position.getAvailableToWithdraw();
|
|
76
|
+
position.withdraw(amount, true);
|
|
77
|
+
this.totalBalance += amount;
|
|
78
|
+
}
|
|
79
|
+
if (withdrawAmount > this.totalBalance)
|
|
80
|
+
throw new Error("Withdraw amount exceeds totalBalance");
|
|
81
|
+
this.totalBalance -= withdrawAmount;
|
|
82
|
+
const sortedPositions = [...this.positions];
|
|
83
|
+
sortedPositions.sort((a, b) => b.borrowable.getSupplyRate() - a.borrowable.getSupplyRate());
|
|
84
|
+
// Allocate in the pool with the highest APR an amount such that the next APR matches the one
|
|
85
|
+
// of the pool with the second highest APR.
|
|
86
|
+
// Repeat until all the pools with the highest APR have the same APR.
|
|
87
|
+
let i;
|
|
88
|
+
for (i = 1; i < sortedPositions.length; i++) {
|
|
89
|
+
const targetRate = sortedPositions[i].borrowable.getSupplyRate();
|
|
90
|
+
if (targetRate === 0)
|
|
91
|
+
break;
|
|
92
|
+
let amountThisCycle = 0;
|
|
93
|
+
const amounts = [];
|
|
94
|
+
for (let j = 0; j < i; j++) {
|
|
95
|
+
if (sortedPositions[j].borrowable.getSupplyRate() <= targetRate)
|
|
96
|
+
break;
|
|
97
|
+
const targetAmount = sortedPositions[j].borrowable.calculateAmountForRate(targetRate);
|
|
98
|
+
amounts.push(targetAmount);
|
|
99
|
+
amountThisCycle += targetAmount;
|
|
100
|
+
}
|
|
101
|
+
if (amountThisCycle > this.totalBalance)
|
|
102
|
+
break;
|
|
103
|
+
for (let j = 0; j < amounts.length; j++) {
|
|
104
|
+
sortedPositions[j].supply(amounts[j], true);
|
|
105
|
+
this.totalBalance -= amounts[j];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const lastCycle = i;
|
|
109
|
+
// distribute the amount left equally among pools with highest APR proportionally to their total supply
|
|
110
|
+
let globalTotalSupply = 0;
|
|
111
|
+
const totalAmountToAllocate = this.totalBalance;
|
|
112
|
+
for (i = 0; i < lastCycle; i++) {
|
|
113
|
+
globalTotalSupply += sortedPositions[i].borrowable.totalSupply;
|
|
114
|
+
}
|
|
115
|
+
for (i = 0; i < lastCycle && this.totalBalance > 0; i++) {
|
|
116
|
+
const amount = globalTotalSupply === 0 ? this.totalBalance
|
|
117
|
+
: sortedPositions[i].borrowable.totalSupply * totalAmountToAllocate / globalTotalSupply;
|
|
118
|
+
sortedPositions[i].supply(amount, true);
|
|
119
|
+
this.totalBalance -= amount;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.LendingVaultEntity = LendingVaultEntity;
|