impermax-sdk 2.1.449 → 2.1.451
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/subgraphs.js +2 -2
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -4
- package/lib/offchain/account/lendingPool/nftlp/{offchainAccountNftlpAerodromeV3.d.ts → offchainAccountNftlpAeroCL.d.ts} +3 -3
- package/lib/offchain/account/lendingPool/nftlp/{offchainAccountNftlpAerodromeV3.js → offchainAccountNftlpAeroCL.js} +2 -2
- package/lib/offchain/lendingPool/nftlp/index.d.ts +2 -2
- package/lib/offchain/lendingPool/nftlp/index.js +3 -3
- package/lib/offchain/lendingPool/nftlp/offchainNftlpAeroCL.d.ts +12 -0
- package/lib/offchain/lendingPool/nftlp/offchainNftlpAeroCL.js +57 -0
- package/lib/offchain/lendingPool/nftlp/offchainNftlpGenericCL.d.ts +35 -0
- package/lib/offchain/lendingPool/nftlp/offchainNftlpGenericCL.js +129 -0
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.d.ts +5 -40
- package/lib/offchain/lendingPool/nftlp/offchainNftlpUniswapV3.js +48 -145
- package/lib/offchain/lendingPool/offchainCollateralV3.js +1 -1
- package/lib/offchain/offchainTypes.d.ts +5 -21
- package/lib/offchain/queries/apis/ponder/index.d.ts +1 -1
- package/lib/offchain/queries/apis/ponder/index.js +12 -34
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpGenericCL.js +0 -1
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpAeroCL.js +1 -1
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpGenericCL.d.ts +2 -2
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpGenericCL.js +0 -1
- package/package.json +1 -1
- package/lib/offchain/lendingPool/nftlp/offchainNftlpAerodromeV3.d.ts +0 -47
- package/lib/offchain/lendingPool/nftlp/offchainNftlpAerodromeV3.js +0 -231
package/lib/config/subgraphs.js
CHANGED
|
@@ -114,7 +114,7 @@ exports.IMPERMAX_SUBGRAPH_URL = {
|
|
|
114
114
|
],
|
|
115
115
|
[types_1.Factory.V3]: [
|
|
116
116
|
"https://base-factory-v3-production.up.railway.app/",
|
|
117
|
-
"https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/deployments/id/
|
|
117
|
+
"https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/deployments/id/QmNfoQmpxoKWxE4mqMiAJhchwyQGwLpBCTKwZ2oYtFP24V"
|
|
118
118
|
],
|
|
119
119
|
},
|
|
120
120
|
[types_1.Networks.Scroll]: {
|
|
@@ -164,7 +164,7 @@ exports.IMPERMAX_SUBGRAPH_URL = {
|
|
|
164
164
|
[types_1.Networks.Unichain]: {
|
|
165
165
|
[types_1.Factory.V3]: [
|
|
166
166
|
'https://unichain-factoryv3-production.up.railway.app/',
|
|
167
|
-
'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/deployments/id/
|
|
167
|
+
'https://gateway.thegraph.com/api/e9bbf185bbf657f7ea313387cdf0e5ce/deployments/id/QmQCqDoFncFWGqadCZqFmkvPQ5TbH49vPvVcSzwaCmqCha'
|
|
168
168
|
]
|
|
169
169
|
},
|
|
170
170
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ import OnchainAccountLendingPoolV2 from './onchain/account/lendingPool/onchainAc
|
|
|
45
45
|
import { decimalToBalance } from './utils/ether-utils';
|
|
46
46
|
import OffchainAccountLendingPoolV3 from "./offchain/account/lendingPool/offchainAccountLendingPoolV3";
|
|
47
47
|
import OffchainAccountNftlpUniswapV3 from './offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3';
|
|
48
|
-
import
|
|
48
|
+
import OffchainAccountNftlpAeroCL from './offchain/account/lendingPool/nftlp/offchainAccountNftlpAeroCL';
|
|
49
49
|
import { MAX_TICK, MIN_TICK, formatPriceSqrtX96, clTickToPrice } from "./utils/nftlpMath/CLGeneral";
|
|
50
50
|
import GenericCLPosition from './utils/position/cl';
|
|
51
51
|
import UniswapV2Position from './utils/position/uniswapV2';
|
|
@@ -58,7 +58,7 @@ import OffchainBorrowableV2 from './offchain/lendingPool/offchainBorrowableV2';
|
|
|
58
58
|
import OffchainCollateralV2 from './offchain/lendingPool/offchainCollateralV2';
|
|
59
59
|
import OffchainBorrowableV3 from './offchain/lendingPool/offchainBorrowableV3';
|
|
60
60
|
import OffchainLendingPoolV3 from './offchain/lendingPool/offchainLendingPoolV3';
|
|
61
|
-
import OffchainNftlp, { OffchainNftlpUniswapV3,
|
|
61
|
+
import OffchainNftlp, { OffchainNftlpUniswapV3, OffchainNftlpAeroCL } from './offchain/lendingPool/nftlp';
|
|
62
62
|
import OffchainCollateralV3 from './offchain/lendingPool/offchainCollateralV3';
|
|
63
63
|
import OffchainAccountLendingPoolV2 from './offchain/account/lendingPool/offchainAccountLendingPoolV2';
|
|
64
64
|
import OffchainAccountBorrowableV2 from './offchain/account/lendingPool/offchainAccountBorrowableV2';
|
|
@@ -77,4 +77,4 @@ import OffchainAccountStakingModule from './offchain/account/staking';
|
|
|
77
77
|
import OnchainStakingModule from './onchain';
|
|
78
78
|
import OnchainInteractionsStakingModule from './onchain/interactions/onchainInteractionsStakingModule';
|
|
79
79
|
import OnchainAccountStakingModule from './onchain/account/onchainAccountStakingModule';
|
|
80
|
-
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,
|
|
80
|
+
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, OffchainAccountNftlpAeroCL, OffchainNftlpAeroCL, PoolTokenData, BorrowableData, CollateralData, BorrowablePastData, TokenData, RewardData, PairData, FarmingPoolData, LendingPoolPastData, LendingPoolData, CollateralPosition, SupplyPosition, BorrowPosition, UserData, TvlData, XIbexData, 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, XIBEX_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, clTickToPrice, isV3Factory, GenericCLPosition, UniswapV2Position, Position, BorrowableEntity, BorrowablePosition, LendingVaultEntity, PairState, SupplyPositionsParams, BorrowPositionsParams, TopPositionsParams, VaultPositionsParams, AccountEarningsParams, AccountMarketData, OffchainStakingModule, IBEX, XIBEX, OffchainAccountStakingModule, OnchainStakingModule, OnchainInteractionsStakingModule, OnchainAccountStakingModule };
|
package/lib/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.OnchainPoolToken = exports.OnchainImpermaxFactoryV3 = exports.OnchainImpermaxFactoryV2 = exports.OnchainImpermaxFactory = exports.Onchain = exports.onchain = exports.VaultType = exports.VaultRisk = exports.
|
|
29
|
+
exports.OnchainPoolToken = exports.OnchainImpermaxFactoryV3 = exports.OnchainImpermaxFactoryV2 = exports.OnchainImpermaxFactory = exports.Onchain = exports.onchain = exports.VaultType = exports.VaultRisk = exports.OffchainNftlpAeroCL = exports.OffchainAccountNftlpAeroCL = 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.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 = exports.OnchainBorrowable = exports.OnchainLendingPool = void 0;
|
|
31
31
|
exports.LendingPoolVersion = exports.SortDirection = exports.LendingPoolListOrderBy = exports.VaultListOrderBy = exports.WhitelistState = exports.ProposalState = exports.Amms = exports.PoolTokenType = exports.Extension = exports.Factory = exports.Networks = exports.XIBEX_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 = void 0;
|
|
32
32
|
exports.OnchainAccountStakingModule = exports.OnchainInteractionsStakingModule = exports.OnchainStakingModule = exports.OffchainAccountStakingModule = exports.XIBEX = exports.IBEX = exports.OffchainStakingModule = exports.LendingVaultEntity = exports.BorrowablePosition = exports.BorrowableEntity = exports.UniswapV2Position = exports.GenericCLPosition = exports.isV3Factory = exports.clTickToPrice = exports.formatPriceSqrtX96 = exports.MIN_TICK = exports.MAX_TICK = exports.decimalToBalance = exports.Borrowable = exports.PermitType = exports.PositionType = void 0;
|
|
@@ -217,8 +217,8 @@ const offchainAccountLendingPoolV3_1 = __importDefault(require("./offchain/accou
|
|
|
217
217
|
exports.OffchainAccountLendingPoolV3 = offchainAccountLendingPoolV3_1.default;
|
|
218
218
|
const offchainAccountNftlpUniswapV3_1 = __importDefault(require("./offchain/account/lendingPool/nftlp/offchainAccountNftlpUniswapV3"));
|
|
219
219
|
exports.OffchainAccountNftlpUniswapV3 = offchainAccountNftlpUniswapV3_1.default;
|
|
220
|
-
const
|
|
221
|
-
exports.
|
|
220
|
+
const offchainAccountNftlpAeroCL_1 = __importDefault(require("./offchain/account/lendingPool/nftlp/offchainAccountNftlpAeroCL"));
|
|
221
|
+
exports.OffchainAccountNftlpAeroCL = offchainAccountNftlpAeroCL_1.default;
|
|
222
222
|
const CLGeneral_1 = require("./utils/nftlpMath/CLGeneral");
|
|
223
223
|
Object.defineProperty(exports, "MAX_TICK", { enumerable: true, get: function () { return CLGeneral_1.MAX_TICK; } });
|
|
224
224
|
Object.defineProperty(exports, "MIN_TICK", { enumerable: true, get: function () { return CLGeneral_1.MIN_TICK; } });
|
|
@@ -247,7 +247,7 @@ exports.OffchainLendingPoolV3 = offchainLendingPoolV3_1.default;
|
|
|
247
247
|
const nftlp_2 = __importStar(require("./offchain/lendingPool/nftlp"));
|
|
248
248
|
exports.OffchainNftlp = nftlp_2.default;
|
|
249
249
|
Object.defineProperty(exports, "OffchainNftlpUniswapV3", { enumerable: true, get: function () { return nftlp_2.OffchainNftlpUniswapV3; } });
|
|
250
|
-
Object.defineProperty(exports, "
|
|
250
|
+
Object.defineProperty(exports, "OffchainNftlpAeroCL", { enumerable: true, get: function () { return nftlp_2.OffchainNftlpAeroCL; } });
|
|
251
251
|
const offchainCollateralV3_1 = __importDefault(require("./offchain/lendingPool/offchainCollateralV3"));
|
|
252
252
|
exports.OffchainCollateralV3 = offchainCollateralV3_1.default;
|
|
253
253
|
const offchainAccountLendingPoolV2_1 = __importDefault(require("./offchain/account/lendingPool/offchainAccountLendingPoolV2"));
|
|
@@ -16,10 +16,10 @@ interface PositionData {
|
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
-
export type
|
|
19
|
+
export type AeroCLPositionData = NftlpPosition & {
|
|
20
20
|
nftlp: PositionData;
|
|
21
21
|
};
|
|
22
|
-
export default class
|
|
22
|
+
export default class OffchainAccountNftlpAeroCL extends OffchainAccountNftlp {
|
|
23
23
|
protected cache: {
|
|
24
24
|
positionsData?: {
|
|
25
25
|
[keys in number]: Promise<PositionData>;
|
|
@@ -32,7 +32,7 @@ export default class OffchainAccountNftlpAerodromeV3 extends OffchainAccountNftl
|
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
getNftlp: () => any;
|
|
35
|
-
getTokenPositions(): Promise<Record<string,
|
|
35
|
+
getTokenPositions(): Promise<Record<string, AeroCLPositionData>>;
|
|
36
36
|
getPositionData(tokenId: number): Promise<PositionData>;
|
|
37
37
|
getFee(tokenId: number): Promise<number>;
|
|
38
38
|
getTickLower(tokenId: number): Promise<number>;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const offchainAccountNftlp_1 = __importDefault(require("./offchainAccountNftlp"));
|
|
7
7
|
const CLGeneral_1 = require("../../../../utils/nftlpMath/CLGeneral");
|
|
8
8
|
const cl_1 = __importDefault(require("../../../../utils/position/cl"));
|
|
9
|
-
class
|
|
9
|
+
class OffchainAccountNftlpAeroCL extends offchainAccountNftlp_1.default {
|
|
10
10
|
constructor() {
|
|
11
11
|
super(...arguments);
|
|
12
12
|
this.cache = {};
|
|
@@ -109,4 +109,4 @@ class OffchainAccountNftlpAerodromeV3 extends offchainAccountNftlp_1.default {
|
|
|
109
109
|
return storedTotalRewardEarned + newlyEarnedReward;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
exports.default =
|
|
112
|
+
exports.default = OffchainAccountNftlpAeroCL;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OffchainNftlp from './offchainNftlp';
|
|
2
2
|
import OffchainNftlpUniswapV3 from './offchainNftlpUniswapV3';
|
|
3
|
-
import
|
|
4
|
-
export { OffchainNftlp, OffchainNftlpUniswapV3,
|
|
3
|
+
import OffchainNftlpAeroCL from './offchainNftlpAeroCL';
|
|
4
|
+
export { OffchainNftlp, OffchainNftlpUniswapV3, OffchainNftlpAeroCL };
|
|
5
5
|
export default OffchainNftlp;
|
|
@@ -3,11 +3,11 @@ 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.
|
|
6
|
+
exports.OffchainNftlpAeroCL = exports.OffchainNftlpUniswapV3 = exports.OffchainNftlp = void 0;
|
|
7
7
|
const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
|
|
8
8
|
exports.OffchainNftlp = offchainNftlp_1.default;
|
|
9
9
|
const offchainNftlpUniswapV3_1 = __importDefault(require("./offchainNftlpUniswapV3"));
|
|
10
10
|
exports.OffchainNftlpUniswapV3 = offchainNftlpUniswapV3_1.default;
|
|
11
|
-
const
|
|
12
|
-
exports.
|
|
11
|
+
const offchainNftlpAeroCL_1 = __importDefault(require("./offchainNftlpAeroCL"));
|
|
12
|
+
exports.OffchainNftlpAeroCL = offchainNftlpAeroCL_1.default;
|
|
13
13
|
exports.default = offchainNftlp_1.default;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
|
|
2
|
+
import OffchainAccountNftlpAeroCL from "../../account/lendingPool/nftlp/offchainAccountNftlpAeroCL";
|
|
3
|
+
import { Extension } from "../../../config/types";
|
|
4
|
+
import OffchainNftlpGenericCL from "./offchainNftlpGenericCL";
|
|
5
|
+
export default class OffchainNftlpAeroCL extends OffchainNftlpGenericCL {
|
|
6
|
+
getExtension(): Extension;
|
|
7
|
+
getNewAccountNftlpObject(accountCollateral: OffchainAccountCollateralV3): OffchainAccountNftlpAeroCL;
|
|
8
|
+
protected tickSpacings: () => number[];
|
|
9
|
+
initializeFullRangeRateAccurate(tickSpacing: number): Promise<number>;
|
|
10
|
+
getRewardsToken(): Promise<string | undefined>;
|
|
11
|
+
getRewardsTokenPrice(): Promise<number>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const offchainAccountNftlpAeroCL_1 = __importDefault(require("../../account/lendingPool/nftlp/offchainAccountNftlpAeroCL"));
|
|
7
|
+
const types_1 = require("../../../config/types");
|
|
8
|
+
const offchainNftlpGenericCL_1 = __importDefault(require("./offchainNftlpGenericCL"));
|
|
9
|
+
const aeroCLGeneral_1 = require("../../../utils/nftlpMath/aeroCLGeneral");
|
|
10
|
+
const Q128 = 2 ** 128;
|
|
11
|
+
const Q256 = BigInt(2) ** BigInt(256);
|
|
12
|
+
const AERO_POOL_CONFIGS = [
|
|
13
|
+
{ tickSpacing: 1, fee: 100 / 10000 },
|
|
14
|
+
{ tickSpacing: 50, fee: 500 / 10000 },
|
|
15
|
+
{ tickSpacing: 100, fee: 500 / 10000 },
|
|
16
|
+
{ tickSpacing: 200, fee: 3000 / 10000 },
|
|
17
|
+
{ tickSpacing: 2000, fee: 10000 / 10000 },
|
|
18
|
+
];
|
|
19
|
+
class OffchainNftlpAeroCL extends offchainNftlpGenericCL_1.default {
|
|
20
|
+
constructor() {
|
|
21
|
+
super(...arguments);
|
|
22
|
+
this.tickSpacings = () => aeroCLGeneral_1.AERO_TICK_SPACINGS;
|
|
23
|
+
}
|
|
24
|
+
getExtension() {
|
|
25
|
+
return types_1.Extension.AeroCL;
|
|
26
|
+
}
|
|
27
|
+
getNewAccountNftlpObject(accountCollateral) {
|
|
28
|
+
return new offchainAccountNftlpAeroCL_1.default(accountCollateral);
|
|
29
|
+
}
|
|
30
|
+
// TODO
|
|
31
|
+
/*public async getFullRangeRateAndTvl(tickSpacing: number): Promise<{
|
|
32
|
+
fullRangeRate: number,
|
|
33
|
+
tvlUsd: number,
|
|
34
|
+
}> {
|
|
35
|
+
const zero = { fullRangeRate: 0, tvlUsd: 0 };
|
|
36
|
+
return zero;
|
|
37
|
+
// TODO
|
|
38
|
+
}*/
|
|
39
|
+
async initializeFullRangeRateAccurate(tickSpacing) {
|
|
40
|
+
return 0;
|
|
41
|
+
// TODO
|
|
42
|
+
}
|
|
43
|
+
async getRewardsToken() {
|
|
44
|
+
return undefined;
|
|
45
|
+
// TODO
|
|
46
|
+
//const nftlpData = await this.getNftlpData() as NftlpGenericCLData;
|
|
47
|
+
//return nftlpData.factory?.rewardsToken?.id
|
|
48
|
+
}
|
|
49
|
+
async getRewardsTokenPrice() {
|
|
50
|
+
const rewardsToken = await this.getRewardsToken();
|
|
51
|
+
if (!rewardsToken)
|
|
52
|
+
return 0;
|
|
53
|
+
const offchain = this.getLendingPool().getOffchain();
|
|
54
|
+
return offchain.getPriceHelper().getTokenPrice(offchain.network, rewardsToken);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = OffchainNftlpAeroCL;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import OffchainNftlp from "./offchainNftlp";
|
|
2
|
+
import { Address } from "../../../config/types";
|
|
3
|
+
export default abstract class OffchainNftlpGenericCL extends OffchainNftlp {
|
|
4
|
+
protected cache: {
|
|
5
|
+
marketPrice?: Promise<number>;
|
|
6
|
+
oraclePrice?: Promise<number>;
|
|
7
|
+
clPools?: {
|
|
8
|
+
[key in number]: Promise<{
|
|
9
|
+
address?: Address;
|
|
10
|
+
liquidity: number;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
fullRangeRateAccurate?: {
|
|
14
|
+
[key in number]: Promise<number>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
protected abstract tickSpacings(): Array<number>;
|
|
18
|
+
private priceAdjustment;
|
|
19
|
+
tickToPrice(tick: number): Promise<number>;
|
|
20
|
+
protected initializeMarketPrice(): Promise<number>;
|
|
21
|
+
protected initializeGenericCLPool(tickSpacing: number): Promise<{
|
|
22
|
+
address?: Address;
|
|
23
|
+
liquidity: number;
|
|
24
|
+
}>;
|
|
25
|
+
getGenericCLPool(tickSpacing: number): Promise<{
|
|
26
|
+
address?: Address;
|
|
27
|
+
liquidity: number;
|
|
28
|
+
}>;
|
|
29
|
+
getGlobalTvl(tickSpacing: number): Promise<number>;
|
|
30
|
+
abstract initializeFullRangeRateAccurate(tickSpacing: number): Promise<number>;
|
|
31
|
+
getFullRangeRateAccurate(tickSpacing: number): Promise<number>;
|
|
32
|
+
getFullRangeRate(tickSpacing: number): Promise<number>;
|
|
33
|
+
getBestFullRangeRate(): Promise<number>;
|
|
34
|
+
getTotalAPR(): Promise<number>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
|
|
7
|
+
const CLGeneral_1 = require("../../../utils/nftlpMath/CLGeneral");
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
9
|
+
class OffchainNftlpGenericCL extends offchainNftlp_1.default {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
this.cache = {};
|
|
13
|
+
}
|
|
14
|
+
async priceAdjustment() {
|
|
15
|
+
const decimalsA = await this.getLendingPool().getBorrowableA().getDecimals();
|
|
16
|
+
const decimalsB = await this.getLendingPool().getBorrowableB().getDecimals();
|
|
17
|
+
return (0, CLGeneral_1.clPriceAdjustment)(decimalsA, decimalsB);
|
|
18
|
+
}
|
|
19
|
+
async tickToPrice(tick) {
|
|
20
|
+
const priceAdjustment = await this.priceAdjustment();
|
|
21
|
+
return (0, CLGeneral_1.clTickToPrice)(tick, priceAdjustment);
|
|
22
|
+
}
|
|
23
|
+
async initializeMarketPrice() {
|
|
24
|
+
const lendingPool = this.getLendingPool();
|
|
25
|
+
const [priceA, priceB] = await Promise.all([
|
|
26
|
+
lendingPool.getBorrowableA().getTokenPriceAccurate(),
|
|
27
|
+
lendingPool.getBorrowableB().getTokenPriceAccurate()
|
|
28
|
+
]);
|
|
29
|
+
if (!priceA || !priceB) {
|
|
30
|
+
console.warn("Can't calculate price for", await this.getLendingPool().getBorrowableA().getSymbol(), await this.getLendingPool().getBorrowableB().getSymbol());
|
|
31
|
+
return NaN;
|
|
32
|
+
}
|
|
33
|
+
return priceA / priceB;
|
|
34
|
+
}
|
|
35
|
+
// get basic UniswapV3Pool info given the tickSpacing
|
|
36
|
+
// used for calculating the apr
|
|
37
|
+
async initializeGenericCLPool(tickSpacing) {
|
|
38
|
+
const nftlpUniswapV3Data = await this.getNftlpData();
|
|
39
|
+
const pools = nftlpUniswapV3Data.uniswapV3Pools;
|
|
40
|
+
for (let pool of pools) {
|
|
41
|
+
if (parseInt(pool.tickSpacing) == tickSpacing) {
|
|
42
|
+
const liquidity = parseInt(pool.liquidity);
|
|
43
|
+
const decimalsA = await this.getLendingPool().getBorrowableA().getDecimals();
|
|
44
|
+
const decimalsB = await this.getLendingPool().getBorrowableB().getDecimals();
|
|
45
|
+
return {
|
|
46
|
+
address: pool.uniswapV3PoolId,
|
|
47
|
+
liquidity: (0, CLGeneral_1.formatCLLiquidity)(liquidity, decimalsA, decimalsB),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
address: undefined,
|
|
53
|
+
liquidity: 0,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
async getGenericCLPool(tickSpacing) {
|
|
57
|
+
if (!this.cache.clPools)
|
|
58
|
+
this.cache.clPools = {};
|
|
59
|
+
if (!this.cache.clPools[tickSpacing])
|
|
60
|
+
this.cache.clPools[tickSpacing] = this.initializeGenericCLPool(tickSpacing);
|
|
61
|
+
return this.cache.clPools[tickSpacing];
|
|
62
|
+
}
|
|
63
|
+
/*
|
|
64
|
+
* TVL AND APR
|
|
65
|
+
*/
|
|
66
|
+
// TODO is getFullRangeRateAndTvl still needed?
|
|
67
|
+
/*public abstract getFullRangeRateAndTvl(tickSpacing: number): Promise<{
|
|
68
|
+
fullRangeRate: number,
|
|
69
|
+
tvlUsd: number,
|
|
70
|
+
}>;
|
|
71
|
+
public async getFullRangeRateDefillama(tickSpacing: number) {
|
|
72
|
+
return (await this.getFullRangeRateAndTvl(tickSpacing)).fullRangeRate;
|
|
73
|
+
}
|
|
74
|
+
public async getGlobalTvlDefillama(tickSpacing: number) {
|
|
75
|
+
return (await this.getFullRangeRateAndTvl(tickSpacing)).tvlUsd;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// calculate apr based on the weighted avg of all the available fees
|
|
79
|
+
public async getWeightedAvgFullRangeRate() {
|
|
80
|
+
let totalTvl = 0;
|
|
81
|
+
let totalCompoundedRate = 0;
|
|
82
|
+
for (const tickSpacing of this.tickSpacings()) {
|
|
83
|
+
const { fullRangeRate, tvlUsd } = await this.getFullRangeRateAndTvl(tickSpacing);
|
|
84
|
+
totalTvl += tvlUsd;
|
|
85
|
+
totalCompoundedRate += fullRangeRate * tvlUsd;
|
|
86
|
+
}
|
|
87
|
+
return totalTvl > 0 ? totalCompoundedRate / totalTvl : 0;
|
|
88
|
+
}*/
|
|
89
|
+
async getGlobalTvl(tickSpacing) {
|
|
90
|
+
const nftlpUniswapV3Data = await this.getNftlpData();
|
|
91
|
+
const pools = nftlpUniswapV3Data.uniswapV3Pools;
|
|
92
|
+
for (let pool of pools) {
|
|
93
|
+
if (parseInt(pool.tickSpacing) == tickSpacing) {
|
|
94
|
+
const reserve0 = parseFloat(pool.reserve0);
|
|
95
|
+
const reserve1 = parseFloat(pool.reserve1);
|
|
96
|
+
const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
|
|
97
|
+
const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
|
|
98
|
+
return reserve0 * priceA + reserve1 * priceB;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
async getFullRangeRateAccurate(tickSpacing) {
|
|
104
|
+
if (!this.cache.fullRangeRateAccurate)
|
|
105
|
+
this.cache.fullRangeRateAccurate = {};
|
|
106
|
+
if (!this.cache.fullRangeRateAccurate[tickSpacing])
|
|
107
|
+
this.cache.fullRangeRateAccurate[tickSpacing] = this.initializeFullRangeRateAccurate(tickSpacing);
|
|
108
|
+
return this.cache.fullRangeRateAccurate[tickSpacing];
|
|
109
|
+
}
|
|
110
|
+
async getFullRangeRate(tickSpacing) {
|
|
111
|
+
return await this.getFullRangeRateAccurate(tickSpacing);
|
|
112
|
+
}
|
|
113
|
+
async getBestFullRangeRate() {
|
|
114
|
+
let bestRate = 0;
|
|
115
|
+
for (const tickSpacing of this.tickSpacings()) {
|
|
116
|
+
const rate = await this.getFullRangeRateAccurate(tickSpacing);
|
|
117
|
+
bestRate = Math.max(bestRate, rate);
|
|
118
|
+
}
|
|
119
|
+
return bestRate;
|
|
120
|
+
}
|
|
121
|
+
// calculate the pair APR assuming a +-8% price range
|
|
122
|
+
async getTotalAPR() {
|
|
123
|
+
const fullRangeAPR = await this.getBestFullRangeRate() * utils_1.SECONDS_IN_YEAR;
|
|
124
|
+
const isStable = await this.getLendingPool().isStablePair();
|
|
125
|
+
const adjustment = isStable ? 1.0005 : 1.08;
|
|
126
|
+
return fullRangeAPR * (0, CLGeneral_1.clConcentrationFactor)(1 / adjustment, adjustment);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.default = OffchainNftlpGenericCL;
|
|
@@ -1,45 +1,10 @@
|
|
|
1
|
-
import OffchainNftlp from "./offchainNftlp";
|
|
2
1
|
import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
|
|
3
2
|
import OffchainAccountNftlpUniswapV3 from "../../account/lendingPool/nftlp/offchainAccountNftlpUniswapV3";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
marketPrice?: Promise<number>;
|
|
8
|
-
oraclePrice?: Promise<number>;
|
|
9
|
-
uniswapV3Pools?: {
|
|
10
|
-
[key in number]: Promise<{
|
|
11
|
-
address?: Address;
|
|
12
|
-
liquidity: number;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
|
-
fullRangeRateAccurate?: {
|
|
16
|
-
[key in number]: Promise<number>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
3
|
+
import { Extension } from "../../../config/types";
|
|
4
|
+
import OffchainNftlpGenericCL from "./offchainNftlpGenericCL";
|
|
5
|
+
export default class OffchainNftlpUniswapV3 extends OffchainNftlpGenericCL {
|
|
19
6
|
getExtension(): Extension;
|
|
20
7
|
getNewAccountNftlpObject(accountCollateral: OffchainAccountCollateralV3): OffchainAccountNftlpUniswapV3;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
protected initializeMarketPrice(): Promise<number>;
|
|
24
|
-
protected initializeUniswapV3Pool(fee: number): Promise<{
|
|
25
|
-
address?: Address;
|
|
26
|
-
liquidity: number;
|
|
27
|
-
}>;
|
|
28
|
-
getUniswapV3Pool(fee: number): Promise<{
|
|
29
|
-
address?: Address;
|
|
30
|
-
liquidity: number;
|
|
31
|
-
}>;
|
|
32
|
-
getFullRangeRateAndTvl(fee: number): Promise<{
|
|
33
|
-
fullRangeRate: number;
|
|
34
|
-
tvlUsd: number;
|
|
35
|
-
}>;
|
|
36
|
-
getFullRangeRateDefillama(fee: number): Promise<number>;
|
|
37
|
-
getGlobalTvlDefillama(fee: number): Promise<number>;
|
|
38
|
-
getGlobalTvl(fee: number): Promise<number>;
|
|
39
|
-
initializeFullRangeRateAccurate(fee: number): Promise<number>;
|
|
40
|
-
getFullRangeRateAccurate(fee: number): Promise<number>;
|
|
41
|
-
getFullRangeRate(fee: number): Promise<number>;
|
|
42
|
-
getWeightedAvgFullRangeRate(): Promise<number>;
|
|
43
|
-
getBestFullRangeRate(): Promise<number>;
|
|
44
|
-
getTotalAPR(): Promise<number>;
|
|
8
|
+
protected tickSpacings: () => number[];
|
|
9
|
+
initializeFullRangeRateAccurate(tickSpacing: number): Promise<number>;
|
|
45
10
|
}
|
|
@@ -3,19 +3,16 @@ 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
|
-
// offchainNftlpUniswapV3.ts
|
|
7
|
-
const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
|
|
8
6
|
const offchainAccountNftlpUniswapV3_1 = __importDefault(require("../../account/lendingPool/nftlp/offchainAccountNftlpUniswapV3"));
|
|
9
|
-
const CLGeneral_1 = require("../../../utils/nftlpMath/CLGeneral");
|
|
10
7
|
const types_1 = require("../../../config/types");
|
|
11
|
-
const utils_1 = require("../../../utils");
|
|
12
8
|
const uniswapV3General_1 = require("../../../utils/nftlpMath/uniswapV3General");
|
|
9
|
+
const offchainNftlpGenericCL_1 = __importDefault(require("./offchainNftlpGenericCL"));
|
|
13
10
|
const Q128 = 2 ** 128;
|
|
14
11
|
const Q256 = BigInt(2) ** BigInt(256);
|
|
15
|
-
class OffchainNftlpUniswapV3 extends
|
|
12
|
+
class OffchainNftlpUniswapV3 extends offchainNftlpGenericCL_1.default {
|
|
16
13
|
constructor() {
|
|
17
14
|
super(...arguments);
|
|
18
|
-
this.
|
|
15
|
+
this.tickSpacings = () => uniswapV3General_1.UNIV3_TICK_SPACINGS;
|
|
19
16
|
}
|
|
20
17
|
getExtension() {
|
|
21
18
|
return types_1.Extension.UniswapV3;
|
|
@@ -23,117 +20,59 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
23
20
|
getNewAccountNftlpObject(accountCollateral) {
|
|
24
21
|
return new offchainAccountNftlpUniswapV3_1.default(accountCollateral);
|
|
25
22
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return (0, CLGeneral_1.clPriceAdjustment)(decimalsA, decimalsB);
|
|
30
|
-
}
|
|
31
|
-
async tickToPrice(tick) {
|
|
32
|
-
const priceAdjustment = await this.priceAdjustment();
|
|
33
|
-
return (0, CLGeneral_1.clTickToPrice)(tick, priceAdjustment);
|
|
34
|
-
}
|
|
35
|
-
async initializeMarketPrice() {
|
|
36
|
-
const lendingPool = this.getLendingPool();
|
|
37
|
-
const [priceA, priceB] = await Promise.all([
|
|
38
|
-
lendingPool.getBorrowableA().getTokenPriceAccurate(),
|
|
39
|
-
lendingPool.getBorrowableB().getTokenPriceAccurate()
|
|
40
|
-
]);
|
|
41
|
-
if (!priceA || !priceB) {
|
|
42
|
-
console.warn("Can't calculate price for", await this.getLendingPool().getBorrowableA().getSymbol(), await this.getLendingPool().getBorrowableB().getSymbol());
|
|
43
|
-
return NaN;
|
|
44
|
-
}
|
|
45
|
-
return priceA / priceB;
|
|
46
|
-
}
|
|
47
|
-
// get basic UniswapV3Pool info given a fee
|
|
48
|
-
// used for calculating the apr
|
|
49
|
-
async initializeUniswapV3Pool(fee) {
|
|
50
|
-
const feeRaw = fee * 1000000;
|
|
51
|
-
const nftlpUniswapV3Data = await this.getNftlpData();
|
|
52
|
-
const pools = nftlpUniswapV3Data.uniswapV3Pools;
|
|
53
|
-
for (let pool of pools) {
|
|
54
|
-
if (parseInt(pool.fee) == feeRaw) {
|
|
55
|
-
const liquidity = parseInt(pool.liquidity);
|
|
56
|
-
const decimalsA = await this.getLendingPool().getBorrowableA().getDecimals();
|
|
57
|
-
const decimalsB = await this.getLendingPool().getBorrowableB().getDecimals();
|
|
58
|
-
return {
|
|
59
|
-
address: pool.uniswapV3PoolId,
|
|
60
|
-
liquidity: (0, CLGeneral_1.formatCLLiquidity)(liquidity, decimalsA, decimalsB),
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
address: undefined,
|
|
66
|
-
liquidity: 0,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
async getUniswapV3Pool(fee) {
|
|
70
|
-
if (!this.cache.uniswapV3Pools)
|
|
71
|
-
this.cache.uniswapV3Pools = {};
|
|
72
|
-
if (!this.cache.uniswapV3Pools[fee])
|
|
73
|
-
this.cache.uniswapV3Pools[fee] = this.initializeUniswapV3Pool(fee);
|
|
74
|
-
return this.cache.uniswapV3Pools[fee];
|
|
75
|
-
}
|
|
23
|
+
/*
|
|
24
|
+
* TVL AND APR
|
|
25
|
+
*/
|
|
76
26
|
// thorugh the fullRangeRate we can calculate the rate of all ranges
|
|
77
27
|
// this is the fastest way to get the APR but returns a more volatile result
|
|
78
|
-
async getFullRangeRateAndTvl(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (parseInt(pool.fee) == feeRaw) {
|
|
119
|
-
const reserve0 = parseFloat(pool.reserve0);
|
|
120
|
-
const reserve1 = parseFloat(pool.reserve1);
|
|
121
|
-
const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
|
|
122
|
-
const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
|
|
123
|
-
return reserve0 * priceA + reserve1 * priceB;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return 0;
|
|
127
|
-
return this.getGlobalTvlDefillama(fee);
|
|
128
|
-
}
|
|
28
|
+
/*public async getFullRangeRateAndTvl(tickSpacing: number): Promise<{
|
|
29
|
+
fullRangeRate: number,
|
|
30
|
+
tvlUsd: number,
|
|
31
|
+
}> {
|
|
32
|
+
const zero = { fullRangeRate: 0, tvlUsd: 0 };
|
|
33
|
+
|
|
34
|
+
// get a pool or return 0
|
|
35
|
+
const pool = await this.getGenericCLPool(tickSpacing);
|
|
36
|
+
if (!pool.address) return zero;
|
|
37
|
+
|
|
38
|
+
// use llama API to get the APR based on last 7 days fees
|
|
39
|
+
// the APR is calculated as: total reward / tvl
|
|
40
|
+
const offchain = this.getLendingPool().getOffchain();
|
|
41
|
+
const {
|
|
42
|
+
apyBase,
|
|
43
|
+
volumeUsd1d,
|
|
44
|
+
volumeUsd7d,
|
|
45
|
+
tvlUsd,
|
|
46
|
+
} = await offchain.getAPRHelper().getLlamaYieldsUniswapV3(pool.address, offchain.network);
|
|
47
|
+
if (tvlUsd === 0) return zero;
|
|
48
|
+
//const llamaApyBase = apyBase / 100;
|
|
49
|
+
//const apr1dFees = volumeUsd1d * fee * 365 / tvlUsd;
|
|
50
|
+
const apr7dFees = volumeUsd7d * uniV3TickSpacingToFee(tickSpacing) / 1e6 / 7 * 365 / tvlUsd;
|
|
51
|
+
|
|
52
|
+
// convert llama apy to rate
|
|
53
|
+
const avgRate = apr7dFees / SECONDS_IN_YEAR;
|
|
54
|
+
|
|
55
|
+
// calculate the usd price of 1 unit of formatted liquidity
|
|
56
|
+
const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
|
|
57
|
+
const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
|
|
58
|
+
const baseLiquidityPrice = Math.sqrt(priceA * priceB) * 2;
|
|
59
|
+
|
|
60
|
+
// baseLiqudiityUsd -> how much the liquidity would be worth if it wasn't concentrated
|
|
61
|
+
const baseLiquidityUsd = pool.liquidity * baseLiquidityPrice;
|
|
62
|
+
if (baseLiquidityUsd === 0) return zero;
|
|
63
|
+
|
|
64
|
+
const avgConcentrationFactor = baseLiquidityUsd / tvlUsd;
|
|
65
|
+
const fullRangeRate = avgRate / avgConcentrationFactor;
|
|
66
|
+
return { fullRangeRate, tvlUsd };
|
|
67
|
+
}*/
|
|
129
68
|
// The more accurate way to get the apr is to calculate the delta between the current feeGrowthGlobal
|
|
130
69
|
// and a feeGrowthGlobal at a previous point in time,
|
|
131
70
|
// but this currently requires a separate call for each fee tier
|
|
132
|
-
async initializeFullRangeRateAccurate(
|
|
71
|
+
async initializeFullRangeRateAccurate(tickSpacing) {
|
|
133
72
|
// To calculate the apr, we compare the current feeGrowthGlobal with the feeGrowthGlobal of 7 days ago.
|
|
134
73
|
// If less than 7 days of data are available, then we use the oldest feeGrowthGlobal available
|
|
135
74
|
const OLDEST_USABLE_DATA = 7 * 24 * 60 * 60;
|
|
136
|
-
const { address } = await this.
|
|
75
|
+
const { address } = await this.getGenericCLPool(tickSpacing);
|
|
137
76
|
if (!address)
|
|
138
77
|
return 0;
|
|
139
78
|
let feeGrowthData = [];
|
|
@@ -174,41 +113,5 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
174
113
|
// which essentially is the full range rewardRate
|
|
175
114
|
return Math.sqrt(rewardRate0 * rewardRate1);
|
|
176
115
|
}
|
|
177
|
-
async getFullRangeRateAccurate(fee) {
|
|
178
|
-
if (!this.cache.fullRangeRateAccurate)
|
|
179
|
-
this.cache.fullRangeRateAccurate = {};
|
|
180
|
-
if (!this.cache.fullRangeRateAccurate[fee])
|
|
181
|
-
this.cache.fullRangeRateAccurate[fee] = this.initializeFullRangeRateAccurate(fee);
|
|
182
|
-
return this.cache.fullRangeRateAccurate[fee];
|
|
183
|
-
}
|
|
184
|
-
async getFullRangeRate(fee) {
|
|
185
|
-
return await this.getFullRangeRateAccurate(fee);
|
|
186
|
-
}
|
|
187
|
-
// calculate apr based on the weighted avg of all the available fees
|
|
188
|
-
async getWeightedAvgFullRangeRate() {
|
|
189
|
-
let totalTvl = 0;
|
|
190
|
-
let totalCompoundedRate = 0;
|
|
191
|
-
for (const tickSpacing of uniswapV3General_1.UNIV3_TICK_SPACINGS) {
|
|
192
|
-
const { fullRangeRate, tvlUsd } = await this.getFullRangeRateAndTvl(tickSpacing);
|
|
193
|
-
totalTvl += tvlUsd;
|
|
194
|
-
totalCompoundedRate += fullRangeRate * tvlUsd;
|
|
195
|
-
}
|
|
196
|
-
return totalTvl > 0 ? totalCompoundedRate / totalTvl : 0;
|
|
197
|
-
}
|
|
198
|
-
async getBestFullRangeRate() {
|
|
199
|
-
let bestRate = 0;
|
|
200
|
-
for (const tickSpacing of uniswapV3General_1.UNIV3_TICK_SPACINGS) {
|
|
201
|
-
const rate = await this.getFullRangeRateAccurate(tickSpacing);
|
|
202
|
-
bestRate = Math.max(bestRate, rate);
|
|
203
|
-
}
|
|
204
|
-
return bestRate;
|
|
205
|
-
}
|
|
206
|
-
// calculate the pair APR assuming a +-8% price range
|
|
207
|
-
async getTotalAPR() {
|
|
208
|
-
const fullRangeAPR = await this.getBestFullRangeRate() * utils_1.SECONDS_IN_YEAR;
|
|
209
|
-
const isStable = await this.getLendingPool().isStablePair();
|
|
210
|
-
const adjustment = isStable ? 1.0005 : 1.08;
|
|
211
|
-
return fullRangeAPR * (0, CLGeneral_1.clConcentrationFactor)(1 / adjustment, adjustment);
|
|
212
|
-
}
|
|
213
116
|
}
|
|
214
117
|
exports.default = OffchainNftlpUniswapV3;
|
|
@@ -14,7 +14,7 @@ class OffchainCollateralV3 extends offchainCollateral_1.default {
|
|
|
14
14
|
case types_1.Extension.UniswapV3:
|
|
15
15
|
return new offchainNftlpUniswapV3_1.default(this);
|
|
16
16
|
case types_1.Extension.AeroCL:
|
|
17
|
-
return new nftlp_1.
|
|
17
|
+
return new nftlp_1.OffchainNftlpAeroCL(this);
|
|
18
18
|
case types_1.Extension.UniswapV2:
|
|
19
19
|
throw new Error(`NFTLP UniswapV2 not yet implemented`);
|
|
20
20
|
case types_1.Extension.AerodromeV2:
|
|
@@ -137,19 +137,20 @@ export interface NftlpFactory {
|
|
|
137
137
|
allNftlpsLength: string;
|
|
138
138
|
oracle: Address;
|
|
139
139
|
}
|
|
140
|
-
export interface
|
|
140
|
+
export interface GenericCLPoolData {
|
|
141
141
|
liquidity: string;
|
|
142
|
+
tickSpacing: string;
|
|
142
143
|
fee: string;
|
|
143
144
|
reserve0: string;
|
|
144
145
|
reserve1: string;
|
|
145
146
|
uniswapV3PoolId: Address;
|
|
146
147
|
}
|
|
147
|
-
export interface
|
|
148
|
+
export interface NftlpGenericCLData {
|
|
148
149
|
dex: Extension;
|
|
149
150
|
id: Address;
|
|
150
151
|
dexFactory: Address;
|
|
151
152
|
factory: NftlpFactory;
|
|
152
|
-
uniswapV3Pools:
|
|
153
|
+
uniswapV3Pools: GenericCLPoolData[];
|
|
153
154
|
}
|
|
154
155
|
export interface NftlpUniswapV2Data {
|
|
155
156
|
dex: Extension;
|
|
@@ -157,24 +158,7 @@ export interface NftlpUniswapV2Data {
|
|
|
157
158
|
factory: NftlpFactory;
|
|
158
159
|
dexFactory: Address;
|
|
159
160
|
}
|
|
160
|
-
export
|
|
161
|
-
liquidity: string;
|
|
162
|
-
tickSpacing: string;
|
|
163
|
-
fee: string;
|
|
164
|
-
reserve0: string;
|
|
165
|
-
reserve1: string;
|
|
166
|
-
aerodromeV3PoolId: Address;
|
|
167
|
-
}
|
|
168
|
-
export interface NftlpAerodromeV3Data {
|
|
169
|
-
dex: Extension;
|
|
170
|
-
id: Address;
|
|
171
|
-
dexFactory: Address;
|
|
172
|
-
factory: NftlpFactory & {
|
|
173
|
-
rewardsToken: TokenData;
|
|
174
|
-
};
|
|
175
|
-
aerodromeV3Pools: AerodromeV3PoolData[];
|
|
176
|
-
}
|
|
177
|
-
export type NftlpData = NftlpUniswapV3Data | NftlpUniswapV2Data | NftlpAerodromeV3Data;
|
|
161
|
+
export type NftlpData = NftlpGenericCLData | NftlpUniswapV2Data;
|
|
178
162
|
export interface NftlpPosition {
|
|
179
163
|
id: string;
|
|
180
164
|
tokenId: string;
|
|
@@ -18,7 +18,7 @@ export declare class PonderQueryBuilder implements IQueryBuilder {
|
|
|
18
18
|
nftlpsQuery(extension: Extension, network: Networks): DocumentNode;
|
|
19
19
|
nftlpPositionQuery(extension: Extension, positionIds: string[]): DocumentNode;
|
|
20
20
|
private nftlpUniswapV3PositionsQuery;
|
|
21
|
-
private
|
|
21
|
+
private nftlpAeroCLPositionsQuery;
|
|
22
22
|
borrowersListQuery(factory: Factory): DocumentNode;
|
|
23
23
|
borrowersListQueryV2(): DocumentNode;
|
|
24
24
|
borrowersListQueryV3(): DocumentNode;
|
|
@@ -416,7 +416,7 @@ class PonderQueryBuilder {
|
|
|
416
416
|
* NFTLP
|
|
417
417
|
*-----------------------------*/
|
|
418
418
|
nftlpsQuery(extension, network) {
|
|
419
|
-
if (extension === types_1.Extension.UniswapV3) {
|
|
419
|
+
if (extension === types_1.Extension.UniswapV3 || extension === types_1.Extension.AeroCL) {
|
|
420
420
|
return (0, graphql_tag_1.default) `{
|
|
421
421
|
nftlps(limit: 1000) {
|
|
422
422
|
items {
|
|
@@ -428,6 +428,7 @@ class PonderQueryBuilder {
|
|
|
428
428
|
uniswapV3Pools {
|
|
429
429
|
items {
|
|
430
430
|
liquidity
|
|
431
|
+
tickSpacing
|
|
431
432
|
fee
|
|
432
433
|
uniswapV3PoolId
|
|
433
434
|
reserve0
|
|
@@ -444,35 +445,6 @@ class PonderQueryBuilder {
|
|
|
444
445
|
if (extension === types_1.Extension.UniswapV2) {
|
|
445
446
|
// TODO
|
|
446
447
|
}
|
|
447
|
-
if (extension === types_1.Extension.AeroCL) {
|
|
448
|
-
return (0, graphql_tag_1.default) `{
|
|
449
|
-
nftlps(limit: 1000) {
|
|
450
|
-
items {
|
|
451
|
-
id
|
|
452
|
-
dexFactory
|
|
453
|
-
factory {
|
|
454
|
-
oracle
|
|
455
|
-
rewardsToken {
|
|
456
|
-
id
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
aerodromeV3Pools {
|
|
460
|
-
items {
|
|
461
|
-
liquidity
|
|
462
|
-
tickSpacing
|
|
463
|
-
fee
|
|
464
|
-
aerodromeV3PoolId
|
|
465
|
-
reserve0
|
|
466
|
-
reserve1
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
_meta {
|
|
472
|
-
status
|
|
473
|
-
}
|
|
474
|
-
}`;
|
|
475
|
-
}
|
|
476
448
|
console.warn(`nftlpsQuery not implemented for extension: ${extension}`);
|
|
477
449
|
return (0, graphql_tag_1.default) `{}`;
|
|
478
450
|
}
|
|
@@ -480,7 +452,7 @@ class PonderQueryBuilder {
|
|
|
480
452
|
if (extension === types_1.Extension.UniswapV3)
|
|
481
453
|
return this.nftlpUniswapV3PositionsQuery(positionIds);
|
|
482
454
|
if (extension === types_1.Extension.AeroCL)
|
|
483
|
-
return this.
|
|
455
|
+
return this.nftlpAeroCLPositionsQuery(positionIds);
|
|
484
456
|
return (0, graphql_tag_1.default) `{}`;
|
|
485
457
|
}
|
|
486
458
|
nftlpUniswapV3PositionsQuery(positionIds) {
|
|
@@ -489,7 +461,6 @@ class PonderQueryBuilder {
|
|
|
489
461
|
nftlpPositions(where: { id_in: [${ids}] }, limit: 1000) {
|
|
490
462
|
items {
|
|
491
463
|
liquidity
|
|
492
|
-
fee
|
|
493
464
|
nftlpId
|
|
494
465
|
tickLower
|
|
495
466
|
tickUpper
|
|
@@ -506,6 +477,10 @@ class PonderQueryBuilder {
|
|
|
506
477
|
id
|
|
507
478
|
}
|
|
508
479
|
}
|
|
480
|
+
uniswapV3Pool {
|
|
481
|
+
fee
|
|
482
|
+
tickSpacing
|
|
483
|
+
}
|
|
509
484
|
}
|
|
510
485
|
}
|
|
511
486
|
_meta {
|
|
@@ -513,7 +488,7 @@ class PonderQueryBuilder {
|
|
|
513
488
|
}
|
|
514
489
|
}`;
|
|
515
490
|
}
|
|
516
|
-
|
|
491
|
+
nftlpAeroCLPositionsQuery(positionIds) {
|
|
517
492
|
const ids = positionIds.map(id => `"${id}"`).join(', ');
|
|
518
493
|
return (0, graphql_tag_1.default) `{
|
|
519
494
|
nftlpPositions(where: { id_in: [${ids}] }, limit: 1000) {
|
|
@@ -529,9 +504,12 @@ class PonderQueryBuilder {
|
|
|
529
504
|
nftlp {
|
|
530
505
|
factory {
|
|
531
506
|
id
|
|
507
|
+
rewardsToken {
|
|
508
|
+
id
|
|
509
|
+
}
|
|
532
510
|
}
|
|
533
511
|
}
|
|
534
|
-
|
|
512
|
+
uniswapV3Pool {
|
|
535
513
|
fee
|
|
536
514
|
tickSpacing
|
|
537
515
|
gauge {
|
|
@@ -59,7 +59,6 @@ class OnchainAccountNftlpGenericCL extends onchainAccountNftlp_1.default {
|
|
|
59
59
|
liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
|
|
60
60
|
borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(lockStateChange),
|
|
61
61
|
borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(lockStateChange),
|
|
62
|
-
// todo getFullRangeRate should take tickSpacing as argument
|
|
63
62
|
fullRangeRate: await (await this.getNftlp().getOffchainNftlp()).getFullRangeRate(await this.getTickSpacing(tokenId)),
|
|
64
63
|
lockStateChange,
|
|
65
64
|
});
|
|
@@ -12,7 +12,7 @@ class OnchainNftlpAeroCL extends onchainNftlpGenericCL_1.default {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
super(...arguments);
|
|
14
14
|
// TODO uncomment
|
|
15
|
-
//public getOffchainNftlp = async () => (await this.getLendingPool().getOffchainLendingPool() as OffchainLendingPoolV3).getNftlp() as
|
|
15
|
+
//public getOffchainNftlp = async () => (await this.getLendingPool().getOffchainLendingPool() as OffchainLendingPoolV3).getNftlp() as OffchainNftlpAeroCL;
|
|
16
16
|
this.tickSpacings = () => aeroCLGeneral_1.AERO_TICK_SPACINGS;
|
|
17
17
|
}
|
|
18
18
|
getExtension() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import OnchainNftlp from "./onchainNftlp";
|
|
2
2
|
import { Contract } from "../../../onchainTypes";
|
|
3
|
-
import
|
|
3
|
+
import OffchainNftlpGenericCL from "../../../../offchain/lendingPool/nftlp/offchainNftlpGenericCL";
|
|
4
4
|
export default abstract class OnchainNftlpGenericCL extends OnchainNftlp {
|
|
5
5
|
protected cache: {
|
|
6
6
|
nftlp?: Contract;
|
|
@@ -10,7 +10,7 @@ export default abstract class OnchainNftlpGenericCL extends OnchainNftlp {
|
|
|
10
10
|
marketPrice?: Promise<number>;
|
|
11
11
|
oraclePrice?: Promise<number>;
|
|
12
12
|
};
|
|
13
|
-
getOffchainNftlp: () => Promise<
|
|
13
|
+
getOffchainNftlp: () => Promise<OffchainNftlpGenericCL>;
|
|
14
14
|
protected abstract tickSpacings(): Array<number>;
|
|
15
15
|
protected initializeNftlp(): any;
|
|
16
16
|
protected abstract initializeCLPool(tickSpacing: number): Promise<Contract | null>;
|
|
@@ -9,7 +9,6 @@ class OnchainNftlpGenericCL extends onchainNftlp_1.default {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
|
11
11
|
this.cache = {};
|
|
12
|
-
// TODO CHANGE THIS TYPE TO OffchainNftlpGenericCL
|
|
13
12
|
this.getOffchainNftlp = async () => (await this.getLendingPool().getOffchainLendingPool()).getNftlp();
|
|
14
13
|
}
|
|
15
14
|
initializeNftlp() {
|
package/package.json
CHANGED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import OffchainNftlp from "./offchainNftlp";
|
|
2
|
-
import OffchainAccountCollateralV3 from "../../account/lendingPool/offchainAccountCollateralV3";
|
|
3
|
-
import OffchainAccountNftlpAerodromeV3 from "../../account/lendingPool/nftlp/offchainAccountNftlpAerodromeV3";
|
|
4
|
-
import { Address, Extension } from "../../../config/types";
|
|
5
|
-
export default class OffchainNftlpAerodromeV3 extends OffchainNftlp {
|
|
6
|
-
protected cache: {
|
|
7
|
-
marketPrice?: Promise<number>;
|
|
8
|
-
oraclePrice?: Promise<number>;
|
|
9
|
-
aerodromeV3Pools?: {
|
|
10
|
-
[key in number]: Promise<{
|
|
11
|
-
address?: Address;
|
|
12
|
-
liquidity: number;
|
|
13
|
-
}>;
|
|
14
|
-
};
|
|
15
|
-
fullRangeRateAccurate?: {
|
|
16
|
-
[key in number]: Promise<number>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
getExtension(): Extension;
|
|
20
|
-
getNewAccountNftlpObject(accountCollateral: OffchainAccountCollateralV3): OffchainAccountNftlpAerodromeV3;
|
|
21
|
-
private priceAdjustment;
|
|
22
|
-
tickToPrice(tick: number): Promise<number>;
|
|
23
|
-
protected initializeMarketPrice(): Promise<number>;
|
|
24
|
-
protected initializeAerodromeV3Pool(fee: number): Promise<{
|
|
25
|
-
address?: Address;
|
|
26
|
-
liquidity: number;
|
|
27
|
-
}>;
|
|
28
|
-
getAerodromeV3Pool(fee: number): Promise<{
|
|
29
|
-
address?: Address;
|
|
30
|
-
liquidity: number;
|
|
31
|
-
}>;
|
|
32
|
-
getFullRangeRateAndTvl(fee: number): Promise<{
|
|
33
|
-
fullRangeRate: number;
|
|
34
|
-
tvlUsd: number;
|
|
35
|
-
}>;
|
|
36
|
-
getFullRangeRateDefillama(fee: number): Promise<number>;
|
|
37
|
-
getGlobalTvlDefillama(fee: number): Promise<number>;
|
|
38
|
-
getGlobalTvl(fee: number): Promise<number>;
|
|
39
|
-
initializeFullRangeRateAccurate(fee: number): Promise<number>;
|
|
40
|
-
getFullRangeRateAccurate(fee: number): Promise<number>;
|
|
41
|
-
getFullRangeRate(fee: number): Promise<number>;
|
|
42
|
-
getWeightedAvgFullRangeRate(): Promise<number>;
|
|
43
|
-
getBestFullRangeRate(): Promise<number>;
|
|
44
|
-
getTotalAPR(): Promise<number>;
|
|
45
|
-
getRewardsToken(): Promise<string | undefined>;
|
|
46
|
-
getRewardsTokenPrice(): Promise<number>;
|
|
47
|
-
}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// offchainNftlpAerodromeV3.ts
|
|
7
|
-
const offchainNftlp_1 = __importDefault(require("./offchainNftlp"));
|
|
8
|
-
const offchainAccountNftlpAerodromeV3_1 = __importDefault(require("../../account/lendingPool/nftlp/offchainAccountNftlpAerodromeV3"));
|
|
9
|
-
const CLGeneral_1 = require("../../../utils/nftlpMath/CLGeneral");
|
|
10
|
-
const types_1 = require("../../../config/types");
|
|
11
|
-
const utils_1 = require("../../../utils");
|
|
12
|
-
const Q128 = 2 ** 128;
|
|
13
|
-
const Q256 = BigInt(2) ** BigInt(256);
|
|
14
|
-
const AERO_POOL_CONFIGS = [
|
|
15
|
-
{ tickSpacing: 1, fee: 100 / 10000 },
|
|
16
|
-
{ tickSpacing: 50, fee: 500 / 10000 },
|
|
17
|
-
{ tickSpacing: 100, fee: 500 / 10000 },
|
|
18
|
-
{ tickSpacing: 200, fee: 3000 / 10000 },
|
|
19
|
-
{ tickSpacing: 2000, fee: 10000 / 10000 },
|
|
20
|
-
];
|
|
21
|
-
class OffchainNftlpAerodromeV3 extends offchainNftlp_1.default {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
this.cache = {};
|
|
25
|
-
}
|
|
26
|
-
getExtension() {
|
|
27
|
-
return types_1.Extension.AeroCL;
|
|
28
|
-
}
|
|
29
|
-
getNewAccountNftlpObject(accountCollateral) {
|
|
30
|
-
return new offchainAccountNftlpAerodromeV3_1.default(accountCollateral);
|
|
31
|
-
}
|
|
32
|
-
async priceAdjustment() {
|
|
33
|
-
const decimalsA = await this.getLendingPool().getBorrowableA().getDecimals();
|
|
34
|
-
const decimalsB = await this.getLendingPool().getBorrowableB().getDecimals();
|
|
35
|
-
return (0, CLGeneral_1.clPriceAdjustment)(decimalsA, decimalsB);
|
|
36
|
-
}
|
|
37
|
-
async tickToPrice(tick) {
|
|
38
|
-
const priceAdjustment = await this.priceAdjustment();
|
|
39
|
-
return (0, CLGeneral_1.clTickToPrice)(tick, priceAdjustment);
|
|
40
|
-
}
|
|
41
|
-
async initializeMarketPrice() {
|
|
42
|
-
const lendingPool = this.getLendingPool();
|
|
43
|
-
const [priceA, priceB] = await Promise.all([
|
|
44
|
-
lendingPool.getBorrowableA().getTokenPriceAccurate(),
|
|
45
|
-
lendingPool.getBorrowableB().getTokenPriceAccurate()
|
|
46
|
-
]);
|
|
47
|
-
if (!priceA || !priceB) {
|
|
48
|
-
console.warn("Can't calculate price for", await this.getLendingPool().getBorrowableA().getSymbol(), await this.getLendingPool().getBorrowableB().getSymbol());
|
|
49
|
-
return NaN;
|
|
50
|
-
}
|
|
51
|
-
return priceA / priceB;
|
|
52
|
-
}
|
|
53
|
-
// get basic AerodromeV3Pool info given a fee
|
|
54
|
-
// used for calculating the apr
|
|
55
|
-
async initializeAerodromeV3Pool(fee) {
|
|
56
|
-
const feeRaw = fee * 1000000;
|
|
57
|
-
const nftlpAerodromeV3Data = await this.getNftlpData();
|
|
58
|
-
const pools = nftlpAerodromeV3Data.aerodromeV3Pools;
|
|
59
|
-
for (let pool of pools) {
|
|
60
|
-
if (parseInt(pool.fee) == feeRaw) {
|
|
61
|
-
const liquidity = parseInt(pool.liquidity);
|
|
62
|
-
const decimalsA = await this.getLendingPool().getBorrowableA().getDecimals();
|
|
63
|
-
const decimalsB = await this.getLendingPool().getBorrowableB().getDecimals();
|
|
64
|
-
return {
|
|
65
|
-
address: pool.aerodromeV3PoolId,
|
|
66
|
-
liquidity: (0, CLGeneral_1.formatCLLiquidity)(liquidity, decimalsA, decimalsB),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
address: undefined,
|
|
72
|
-
liquidity: 0,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
async getAerodromeV3Pool(fee) {
|
|
76
|
-
if (!this.cache.aerodromeV3Pools)
|
|
77
|
-
this.cache.aerodromeV3Pools = {};
|
|
78
|
-
if (!this.cache.aerodromeV3Pools[fee])
|
|
79
|
-
this.cache.aerodromeV3Pools[fee] = this.initializeAerodromeV3Pool(fee);
|
|
80
|
-
return this.cache.aerodromeV3Pools[fee];
|
|
81
|
-
}
|
|
82
|
-
// thorugh the fullRangeRate we can calculate the rate of all ranges
|
|
83
|
-
// this is the fastest way to get the APR but returns a more volatile result
|
|
84
|
-
async getFullRangeRateAndTvl(fee) {
|
|
85
|
-
const zero = { fullRangeRate: 0, tvlUsd: 0 };
|
|
86
|
-
// get a pool or return 0
|
|
87
|
-
const pool = await this.getAerodromeV3Pool(fee);
|
|
88
|
-
if (!pool.address)
|
|
89
|
-
return zero;
|
|
90
|
-
// use llama API to get the APR based on last 7 days fees
|
|
91
|
-
// the APR is calculated as: total reward / tvl
|
|
92
|
-
const offchain = this.getLendingPool().getOffchain();
|
|
93
|
-
const { apyBase, volumeUsd1d, volumeUsd7d, tvlUsd, } = await offchain.getAPRHelper().getLlamaYieldsUniswapV3(pool.address, offchain.network);
|
|
94
|
-
if (tvlUsd === 0)
|
|
95
|
-
return zero;
|
|
96
|
-
//const llamaApyBase = apyBase / 100;
|
|
97
|
-
//const apr1dFees = volumeUsd1d * fee * 365 / tvlUsd;
|
|
98
|
-
const apr7dFees = volumeUsd7d * fee / 7 * 365 / tvlUsd;
|
|
99
|
-
// convert llama apy to rate
|
|
100
|
-
const avgRate = apr7dFees / utils_1.SECONDS_IN_YEAR;
|
|
101
|
-
// calculate the usd price of 1 unit of formatted liquidity
|
|
102
|
-
const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
|
|
103
|
-
const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
|
|
104
|
-
const baseLiquidityPrice = Math.sqrt(priceA * priceB) * 2;
|
|
105
|
-
// baseLiqudiityUsd -> how much the liquidity would be worth if it wasn't concentrated
|
|
106
|
-
const baseLiquidityUsd = pool.liquidity * baseLiquidityPrice;
|
|
107
|
-
if (baseLiquidityUsd === 0)
|
|
108
|
-
return zero;
|
|
109
|
-
const avgConcentrationFactor = baseLiquidityUsd / tvlUsd;
|
|
110
|
-
const fullRangeRate = avgRate / avgConcentrationFactor;
|
|
111
|
-
return { fullRangeRate, tvlUsd };
|
|
112
|
-
}
|
|
113
|
-
async getFullRangeRateDefillama(fee) {
|
|
114
|
-
return (await this.getFullRangeRateAndTvl(fee)).fullRangeRate;
|
|
115
|
-
}
|
|
116
|
-
async getGlobalTvlDefillama(fee) {
|
|
117
|
-
return (await this.getFullRangeRateAndTvl(fee)).tvlUsd;
|
|
118
|
-
}
|
|
119
|
-
async getGlobalTvl(fee) {
|
|
120
|
-
const feeRaw = fee * 1000000;
|
|
121
|
-
const nftlpAerodromeV3Data = await this.getNftlpData();
|
|
122
|
-
const pools = nftlpAerodromeV3Data.aerodromeV3Pools;
|
|
123
|
-
for (let pool of pools) {
|
|
124
|
-
if (parseInt(pool.fee) == feeRaw) {
|
|
125
|
-
const reserve0 = parseFloat(pool.reserve0);
|
|
126
|
-
const reserve1 = parseFloat(pool.reserve1);
|
|
127
|
-
const priceA = await this.getLendingPool().getBorrowableA().getTokenPriceFast();
|
|
128
|
-
const priceB = await this.getLendingPool().getBorrowableB().getTokenPriceFast();
|
|
129
|
-
return reserve0 * priceA + reserve1 * priceB;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return 0;
|
|
133
|
-
return this.getGlobalTvlDefillama(fee);
|
|
134
|
-
}
|
|
135
|
-
// The more accurate way to get the apr is to calculate the delta between the current feeGrowthGlobal
|
|
136
|
-
// and a feeGrowthGlobal at a previous point in time,
|
|
137
|
-
// but this currently requires a separate call for each fee tier
|
|
138
|
-
async initializeFullRangeRateAccurate(fee) {
|
|
139
|
-
// To calculate the apr, we compare the current feeGrowthGlobal with the feeGrowthGlobal of 7 days ago.
|
|
140
|
-
// If less than 7 days of data are available, then we use the oldest feeGrowthGlobal available
|
|
141
|
-
const OLDEST_USABLE_DATA = 7 * 24 * 60 * 60;
|
|
142
|
-
const { address } = await this.getAerodromeV3Pool(fee);
|
|
143
|
-
if (!address)
|
|
144
|
-
return 0;
|
|
145
|
-
let feeGrowthData = [];
|
|
146
|
-
try {
|
|
147
|
-
feeGrowthData = await this.getLendingPool().getOffchain().getAerodromeV3Charts(address.toLowerCase());
|
|
148
|
-
}
|
|
149
|
-
catch (err) { }
|
|
150
|
-
if (!feeGrowthData || feeGrowthData.length < 2) {
|
|
151
|
-
console.log(`No historic fee growth data available for aerodromeV3 pool: ${address}`);
|
|
152
|
-
return 0;
|
|
153
|
-
}
|
|
154
|
-
// the endpoint returns an array ordered from most recent to least recent
|
|
155
|
-
const mostRecentTimestamp = feeGrowthData[0].timestamp;
|
|
156
|
-
const currentFeeGrowthGlobal0X128 = BigInt(feeGrowthData[0].feeGrowthGlobal0X128);
|
|
157
|
-
const currentFeeGrowthGlobal1X128 = BigInt(feeGrowthData[0].feeGrowthGlobal1X128);
|
|
158
|
-
let leastRecentTimestamp;
|
|
159
|
-
let pastFeeGrowthGlobal0X128;
|
|
160
|
-
let pastFeeGrowthGlobal1X128;
|
|
161
|
-
for (const data of feeGrowthData) {
|
|
162
|
-
if (mostRecentTimestamp - data.timestamp > OLDEST_USABLE_DATA)
|
|
163
|
-
break;
|
|
164
|
-
leastRecentTimestamp = data.timestamp;
|
|
165
|
-
pastFeeGrowthGlobal0X128 = BigInt(data.feeGrowthGlobal0X128);
|
|
166
|
-
pastFeeGrowthGlobal1X128 = BigInt(data.feeGrowthGlobal1X128);
|
|
167
|
-
}
|
|
168
|
-
const deltaTime = mostRecentTimestamp - leastRecentTimestamp;
|
|
169
|
-
let delta0 = currentFeeGrowthGlobal0X128 - pastFeeGrowthGlobal0X128;
|
|
170
|
-
let delta1 = currentFeeGrowthGlobal1X128 - pastFeeGrowthGlobal1X128;
|
|
171
|
-
if (delta0 < 0)
|
|
172
|
-
delta0 += Q256;
|
|
173
|
-
if (delta1 < 0)
|
|
174
|
-
delta1 += Q256;
|
|
175
|
-
// how much reward we would earn every second for each unit of liquidity
|
|
176
|
-
const rewardRate0 = Number(delta0) / Q128 / deltaTime;
|
|
177
|
-
const rewardRate1 = Number(delta1) / Q128 / deltaTime;
|
|
178
|
-
// liquidity is calculated as: sqrt(amount0 * amount1)
|
|
179
|
-
// using rewardRate as amount0 and amount1 we obtain: liquidityPerSecondPerUnitOfLiquidity
|
|
180
|
-
// which essentially is the full range rewardRate
|
|
181
|
-
return Math.sqrt(rewardRate0 * rewardRate1);
|
|
182
|
-
}
|
|
183
|
-
async getFullRangeRateAccurate(fee) {
|
|
184
|
-
if (!this.cache.fullRangeRateAccurate)
|
|
185
|
-
this.cache.fullRangeRateAccurate = {};
|
|
186
|
-
if (!this.cache.fullRangeRateAccurate[fee])
|
|
187
|
-
this.cache.fullRangeRateAccurate[fee] = this.initializeFullRangeRateAccurate(fee);
|
|
188
|
-
return this.cache.fullRangeRateAccurate[fee];
|
|
189
|
-
}
|
|
190
|
-
async getFullRangeRate(fee) {
|
|
191
|
-
return await this.getFullRangeRateAccurate(fee);
|
|
192
|
-
}
|
|
193
|
-
// calculate apr based on the weighted avg of all the available fees
|
|
194
|
-
async getWeightedAvgFullRangeRate() {
|
|
195
|
-
let totalTvl = 0;
|
|
196
|
-
let totalCompoundedRate = 0;
|
|
197
|
-
for (const poolConfig of AERO_POOL_CONFIGS) {
|
|
198
|
-
const { fullRangeRate, tvlUsd } = await this.getFullRangeRateAndTvl(poolConfig.fee);
|
|
199
|
-
totalTvl += tvlUsd;
|
|
200
|
-
totalCompoundedRate += fullRangeRate * tvlUsd;
|
|
201
|
-
}
|
|
202
|
-
return totalTvl > 0 ? totalCompoundedRate / totalTvl : 0;
|
|
203
|
-
}
|
|
204
|
-
async getBestFullRangeRate() {
|
|
205
|
-
let bestRate = 0;
|
|
206
|
-
for (const poolConfig of AERO_POOL_CONFIGS) {
|
|
207
|
-
const rate = await this.getFullRangeRateAccurate(poolConfig.fee);
|
|
208
|
-
bestRate = Math.max(bestRate, rate);
|
|
209
|
-
}
|
|
210
|
-
return bestRate;
|
|
211
|
-
}
|
|
212
|
-
// calculate the pair APR assuming a +-8% price range for volatile, 0.05% for stable
|
|
213
|
-
async getTotalAPR() {
|
|
214
|
-
const fullRangeAPR = await this.getBestFullRangeRate() * utils_1.SECONDS_IN_YEAR;
|
|
215
|
-
const isStable = await this.getLendingPool().isStablePair();
|
|
216
|
-
const adjustment = isStable ? 1.0005 : 1.08;
|
|
217
|
-
return fullRangeAPR * (0, CLGeneral_1.clConcentrationFactor)(1 / adjustment, adjustment);
|
|
218
|
-
}
|
|
219
|
-
async getRewardsToken() {
|
|
220
|
-
const nftlpData = await this.getNftlpData();
|
|
221
|
-
return nftlpData.factory?.rewardsToken?.id;
|
|
222
|
-
}
|
|
223
|
-
async getRewardsTokenPrice() {
|
|
224
|
-
const rewardsToken = await this.getRewardsToken();
|
|
225
|
-
if (!rewardsToken)
|
|
226
|
-
return 0;
|
|
227
|
-
const offchain = this.getLendingPool().getOffchain();
|
|
228
|
-
return offchain.getPriceHelper().getTokenPrice(offchain.network, rewardsToken);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
exports.default = OffchainNftlpAerodromeV3;
|