@merkl/api 0.19.6 → 0.19.8
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/dist/src/backgroundJobs/jobs/campaignsCacheUpdater.js +4 -3
- package/dist/src/eden/index.d.ts +85 -48
- package/dist/src/engine/dynamicData/factory.d.ts +3 -0
- package/dist/src/engine/dynamicData/factory.js +54 -0
- package/dist/src/engine/dynamicData/implementations/Ajna.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Ajna.js +101 -0
- package/dist/src/engine/dynamicData/implementations/Ambiant.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Ambiant.js +227 -0
- package/dist/src/engine/dynamicData/implementations/Badger.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Badger.js +84 -0
- package/dist/src/engine/dynamicData/implementations/Clamm.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Clamm.js +970 -0
- package/dist/src/engine/dynamicData/implementations/Compound.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Compound.js +136 -0
- package/dist/src/engine/dynamicData/implementations/Dolomite.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Dolomite.js +53 -0
- package/dist/src/engine/dynamicData/implementations/EigenLayer.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/EigenLayer.js +64 -0
- package/dist/src/engine/dynamicData/implementations/Encompassing.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Encompassing.js +26 -0
- package/dist/src/engine/dynamicData/implementations/Erc20.d.ts +6 -0
- package/dist/src/engine/dynamicData/implementations/Erc20.js +159 -0
- package/dist/src/engine/dynamicData/implementations/Erc20Snapshot.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Erc20Snapshot.js +32 -0
- package/dist/src/engine/dynamicData/implementations/EventBased.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/EventBased.js +104 -0
- package/dist/src/engine/dynamicData/implementations/Hyperdrive.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Hyperdrive.js +96 -0
- package/dist/src/engine/dynamicData/implementations/Morpho.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Morpho.js +109 -0
- package/dist/src/engine/dynamicData/implementations/Radiant.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/Radiant.js +117 -0
- package/dist/src/engine/dynamicData/implementations/Silo.d.ts +9 -0
- package/dist/src/engine/dynamicData/implementations/Silo.js +109 -0
- package/dist/src/engine/dynamicData/implementations/UniswapV4.d.ts +7 -0
- package/dist/src/engine/dynamicData/implementations/UniswapV4.js +249 -0
- package/dist/src/engine/dynamicData/implementations/Vest.d.ts +9 -0
- package/dist/src/engine/dynamicData/implementations/Vest.js +58 -0
- package/dist/src/engine/dynamicData/implementations/default.d.ts +5 -0
- package/dist/src/engine/dynamicData/implementations/default.js +5 -0
- package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getEulerV2Vaults.js +1 -1
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/GenericProcessor.d.ts +1 -1
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/tokenType.d.ts +2 -1
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/tokenType.js +2 -0
- package/dist/src/engine/erc20SubTypeProcessors/implementations/BunniV2Processor.d.ts +45 -0
- package/dist/src/engine/erc20SubTypeProcessors/implementations/BunniV2Processor.js +87 -0
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/processorMapping.js +2 -0
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound1.js +2 -0
- package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound2.d.ts +1 -1
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/Erc20.js +3 -3
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/Euler.d.ts +1 -1
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/Euler.js +7 -7
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/EventBased.d.ts +1 -1
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/EventBased.js +2 -2
- package/dist/src/{factories → engine}/opportunityMetadata/implementations/Vest.js +1 -1
- package/dist/src/index.d.ts +19 -16
- package/dist/src/jobs/update-euler-vaults.js +2 -2
- package/dist/src/modules/v4/apr/apr.service.d.ts +1 -1
- package/dist/src/modules/v4/apr/apr.service.js +4 -4
- package/dist/src/modules/v4/campaign/campaign.controller.d.ts +5 -0
- package/dist/src/modules/v4/campaign/campaign.model.d.ts +1 -0
- package/dist/src/modules/v4/campaign/campaign.model.js +1 -0
- package/dist/src/modules/v4/campaign/campaign.repository.d.ts +4 -0
- package/dist/src/modules/v4/campaign/campaign.repository.js +2 -1
- package/dist/src/modules/v4/campaign/campaign.service.d.ts +0 -8
- package/dist/src/modules/v4/campaign/campaign.service.js +0 -13
- package/dist/src/modules/v4/dynamicData/dynamicData.service.js +3 -4
- package/dist/src/modules/v4/opportunity/opportunity.controller.d.ts +8 -0
- package/dist/src/modules/v4/opportunity/opportunity.converter.js +2 -2
- package/dist/src/modules/v4/opportunity/opportunity.model.d.ts +2 -0
- package/dist/src/modules/v4/opportunity/opportunity.model.js +2 -0
- package/dist/src/modules/v4/opportunity/opportunity.repository.d.ts +1 -1
- package/dist/src/modules/v4/opportunity/opportunity.repository.js +14 -10
- package/dist/src/modules/v4/opportunity/opportunity.service.d.ts +2 -2
- package/dist/src/modules/v4/opportunity/opportunity.service.js +5 -5
- package/dist/src/modules/v4/router.d.ts +14 -0
- package/dist/src/modules/v4/token/token.controller.d.ts +1 -0
- package/dist/src/modules/v4/token/token.model.d.ts +1 -0
- package/dist/src/modules/v4/token/token.model.js +1 -0
- package/dist/src/modules/v4/token/token.service.d.ts +3 -1
- package/dist/src/modules/v4/token/token.service.js +18 -0
- package/dist/src/modules/v4/uniswapV4/uniswapV4.controller.d.ts +2 -2
- package/dist/src/modules/v4/uniswapV4/uniswapV4.service.d.ts +2 -2
- package/dist/src/modules/v4/uniswapV4/uniswapV4.service.js +1 -1
- package/dist/src/routes/v3/campaigns.d.ts +1 -1
- package/dist/src/routes/v3/compoundV2.d.ts +2 -10
- package/dist/src/routes/v3/compoundV2.js +1 -1
- package/dist/src/routes/v3/dolomite.js +1 -1
- package/dist/src/routes/v3/euler.js +1 -1
- package/dist/src/routes/v3/router.d.ts +5 -16
- package/dist/src/routes/v3/uniswapv4.d.ts +2 -5
- package/dist/src/routes/v3/uniswapv4.js +1 -1
- package/dist/src/utils/decodeCalls.d.ts +1 -1
- package/dist/src/utils/decodeCalls.js +8 -2
- package/dist/src/utils/encodeCalls.d.ts +1 -1
- package/dist/src/utils/encodeCalls.js +20 -2
- package/dist/src/utils/generateCardName.d.ts +1 -1
- package/dist/src/utils/generateCardName.js +3 -1
- package/dist/src/utils/generateIcons.d.ts +1 -1
- package/dist/src/utils/generateIcons.js +1 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/factories/dynamicData/factory.d.ts +0 -0
- package/dist/src/factories/dynamicData/factory.js +0 -10
- package/dist/src/libs/campaigns/campaignTypes/AjnaDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/AjnaDynamicData.js +0 -111
- package/dist/src/libs/campaigns/campaignTypes/AmbientDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/AmbientDynamicData.js +0 -243
- package/dist/src/libs/campaigns/campaignTypes/BadgerDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/BadgerDynamicData.js +0 -93
- package/dist/src/libs/campaigns/campaignTypes/CLAMMDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/CLAMMDynamicData.js +0 -986
- package/dist/src/libs/campaigns/campaignTypes/CompoundDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/CompoundDynamicData.js +0 -139
- package/dist/src/libs/campaigns/campaignTypes/DolomiteDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/DolomiteDynamicData.js +0 -60
- package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.d.ts +0 -4
- package/dist/src/libs/campaigns/campaignTypes/ERC20DynamicData.js +0 -164
- package/dist/src/libs/campaigns/campaignTypes/ERC20_SNAPSHOTDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/ERC20_SNAPSHOTDynamicData.js +0 -38
- package/dist/src/libs/campaigns/campaignTypes/EigenLayerDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/EigenLayerDynamicData.js +0 -67
- package/dist/src/libs/campaigns/campaignTypes/EncompassingDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/EncompassingDynamicData.js +0 -34
- package/dist/src/libs/campaigns/campaignTypes/EventBasedDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/EventBasedDynamicData.js +0 -114
- package/dist/src/libs/campaigns/campaignTypes/HyperdriveDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/HyperdriveDynamicData.js +0 -99
- package/dist/src/libs/campaigns/campaignTypes/JSON_AIRDROPDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/JSON_AIRDROPDynamicData.js +0 -19
- package/dist/src/libs/campaigns/campaignTypes/MORPHODynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/MORPHODynamicData.js +0 -112
- package/dist/src/libs/campaigns/campaignTypes/RadiantDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/RadiantDynamicData.js +0 -122
- package/dist/src/libs/campaigns/campaignTypes/SILODynamicData.d.ts +0 -7
- package/dist/src/libs/campaigns/campaignTypes/SILODynamicData.js +0 -115
- package/dist/src/libs/campaigns/campaignTypes/UniswapV4DynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignTypes/UniswapV4DynamicData.js +0 -265
- package/dist/src/libs/campaigns/campaignTypes/VestDynamicData.d.ts +0 -5
- package/dist/src/libs/campaigns/campaignTypes/VestDynamicData.js +0 -61
- package/dist/src/libs/campaigns/campaignsDynamicData.d.ts +0 -3
- package/dist/src/libs/campaigns/campaignsDynamicData.js +0 -131
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchA51Strategies.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchA51Strategies.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchAmbientInfo.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchAmbientInfo.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchClamInfo.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchClamInfo.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchLogs.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/fetchLogs.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getCompV2ForksVaults.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getCompV2ForksVaults.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getContractCreationBlock.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getContractCreationBlock.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getDolomiteMarkets.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getDolomiteMarkets.js +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getEulerV2Vaults.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getUniswapV4Pools.d.ts +0 -0
- /package/dist/src/{libs/campaigns → engine/dynamicData}/utils/getUniswapV4Pools.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/GenericProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/eulerVaultNames.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/eulerVaultNames.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/factoryFinder.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/factoryFinder.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/getBlacklistedSupply.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/getBlacklistedSupply.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/hardcoded.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/hardcoded.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/metamorphoTvl.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/metamorphoTvl.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/ownerFinder.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/ownerFinder.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/spliceTVL.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/helpers/spliceTVL.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AaveProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AaveProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AnglesLiquid.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AnglesLiquid.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AssetProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AssetProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AuraProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/AuraProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerGaugeProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerGaugeProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerPoolProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerPoolProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerV3PoolProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BalancerV3PoolProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BeefyProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/BeefyProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/CompoundProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/CompoundProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/ERC4626Processor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/ERC4626Processor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EnzymeProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EnzymeProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EqualizerGaugeProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EqualizerGaugeProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EulerBorrowProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EulerBorrowProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EulerLendProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/EulerLendProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/FluidProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/FluidProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/FraxProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/FraxProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/GammaProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/GammaProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/GearboxProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/GearboxProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HanjiVaultProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HanjiVaultProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HoldStationProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HoldStationProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HourglassProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/HourglassProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/MaverickBPProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/MaverickBPProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/MetamorphoProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/MetamorphoProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/NoLinkVaultProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/NoLinkVaultProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/PendleProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/PendleProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/PendleYTProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/PendleYTProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/RadiantProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/RadiantProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/RfxProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/RfxProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/Satlayer.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/Satlayer.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpectraProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpectraProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpectraYTProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpectraYTProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpliceProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SpliceProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SturdySiloProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/SturdySiloProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TempestVaultProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TempestVaultProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TemplateProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TemplateProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TorosProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/TorosProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/UniswapProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/UniswapProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/VicunaProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/VicunaProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/WoofiProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/WoofiProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/ZkSwapThreePoolProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/ZkSwapThreePoolProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/curveNPoolProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/curveNPoolProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/curveProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/curveProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/processorMapping.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/stakedCurveProcessor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/stakedCurveProcessor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/xU308Processor.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/implementations/xU308Processor.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesPrices.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesPrices.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound1.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound2.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound3.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound3.js +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound4.d.ts +0 -0
- /package/dist/src/{libs/campaigns/campaignTypes/ERC20SubTypes → engine/erc20SubTypeProcessors}/subtypesRound4.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/factory.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/factory.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ajna.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ajna.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ambiant.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ambiant.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Badger.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Badger.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Clamm.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Clamm.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Compound.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Compound.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Default.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Default.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Dolomite.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Dolomite.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/EigenLayer.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/EigenLayer.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Encompassing.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Encompassing.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Erc20.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Erc20Snapshot.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Erc20Snapshot.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Hyperdrive.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Hyperdrive.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Invalid.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Invalid.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ion.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Ion.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/JsonAirdrop.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/JsonAirdrop.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Morpho.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Morpho.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Radiant.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Radiant.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Silo.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Silo.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/UniswapV4.d.ts +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/UniswapV4.js +0 -0
- /package/dist/src/{factories → engine}/opportunityMetadata/implementations/Vest.d.ts +0 -0
@@ -0,0 +1,970 @@
|
|
1
|
+
import { nftPositionByIdsQuery, positionMultipleOwnersQuery } from "@/libs/positions/clamm/thegraph";
|
2
|
+
import { fetchFarmedPositions } from "@/libs/positions/clamm/thegraph/fetchFarmedPositions";
|
3
|
+
import { TokenService } from "@/modules/v4/token/token.service";
|
4
|
+
import { A51Factory__factory, ALM, ALMMapping, AMM, AMMAlgorithm, AMMAlgorithmMapping, BN2Number, ChainInteractionService, DecodeLiquidity, EAprBreakdownType, ERC20Interface, Forwarder, JonesDoubleRewardTracker__factory, Liquidity, NETWORK_LABELS, NitroInterface, PoolInterface, PoolState, PriorityAMM, SqrtPrice, almName, ammName, getAmountsForLiquidity, getTickAtSqrtRatio, isBlacklisted, isWhitelisted, merklSubgraphAMMEndpoints, shortenAddress, spNFTInterface, withTimeout, } from "@sdk";
|
5
|
+
import axios from "axios";
|
6
|
+
import { BigNumber, utils } from "ethers";
|
7
|
+
import request from "graphql-request";
|
8
|
+
import JSBI from "jsbi";
|
9
|
+
import moment from "moment";
|
10
|
+
import { MERKL_ALM_POSITION_FETCHING_TIMEOUT } from "../../../constants";
|
11
|
+
import { log } from "../../../utils/logger";
|
12
|
+
import { Pricer } from "../../../utils/pricer";
|
13
|
+
import { isStrykeCampaign } from "../../../utils/stryke";
|
14
|
+
import { fetchA51Strategies } from "../utils/fetchA51Strategies";
|
15
|
+
export class ClammDynamicData {
|
16
|
+
async build(chainId, campaigns) {
|
17
|
+
const dynamicData = [];
|
18
|
+
const pricer = await Pricer.load();
|
19
|
+
const calls = [];
|
20
|
+
const A51Interface = A51Factory__factory.createInterface();
|
21
|
+
/** Dedupe pools from campaigns to build pool list */
|
22
|
+
let poolList = [];
|
23
|
+
for (const campaign of campaigns ?? []) {
|
24
|
+
/** Loop through all campaigns to add pools */
|
25
|
+
if (!poolList?.map(p => p.mainParameter.toLowerCase()).includes(campaign.mainParameter.toLowerCase())) {
|
26
|
+
if (AMMAlgorithmMapping[campaign.campaignParameters.amm] === undefined) {
|
27
|
+
console.log("Invalid AMM", campaign.campaignParameters.amm);
|
28
|
+
continue;
|
29
|
+
}
|
30
|
+
poolList.push({
|
31
|
+
address: campaign.campaignParameters.poolAddress,
|
32
|
+
mainParameter: campaign.mainParameter, // main parameter containes info of poolAddress + AMM (in case its a priority AMM)
|
33
|
+
alms: [],
|
34
|
+
amm: campaign.campaignParameters.amm,
|
35
|
+
});
|
36
|
+
}
|
37
|
+
/** Now we have an entry with campaign.mainParameter in poolList */
|
38
|
+
const poolIndex = poolList
|
39
|
+
?.map(p => p.mainParameter.toLowerCase())
|
40
|
+
.findIndex(a => a === campaign.mainParameter.toLowerCase());
|
41
|
+
/** Fill ALMs per pools */
|
42
|
+
for (const forwarder of campaign.campaignParameters.forwarders
|
43
|
+
.filter(f => f.forwarderType === Forwarder.CLAMM)
|
44
|
+
.sort((a, b) => a.priority - b.priority)) {
|
45
|
+
const alm = {
|
46
|
+
address: forwarder.sender,
|
47
|
+
...(!!forwarder.owner && { owner: forwarder.owner?.toLowerCase() }),
|
48
|
+
target: forwarder.target.toLowerCase(),
|
49
|
+
type: forwarder.type,
|
50
|
+
priority: forwarder.priority,
|
51
|
+
};
|
52
|
+
/** If the ALM is not found - add it */
|
53
|
+
if (poolList[poolIndex].alms.findIndex(a => alm.address === a.address && alm.target === a.target) === -1) {
|
54
|
+
poolList[poolIndex].alms.push(alm);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
poolList = poolList.filter(p => p.amm !== undefined && p.amm !== null);
|
59
|
+
if (!!poolList) {
|
60
|
+
// Prepare A51 fetching
|
61
|
+
const A51Pools = [];
|
62
|
+
for (const pool of poolList) {
|
63
|
+
for (const _ of pool.alms.filter(a => a.type === ALM.A51)) {
|
64
|
+
A51Pools.push(pool.address.toLowerCase());
|
65
|
+
}
|
66
|
+
}
|
67
|
+
let A51Strategies = {};
|
68
|
+
if (A51Pools.length > 0) {
|
69
|
+
A51Strategies = await fetchA51Strategies(chainId, [...new Set(A51Pools)]);
|
70
|
+
}
|
71
|
+
for (const pool of poolList) {
|
72
|
+
const poolInterface = PoolInterface[AMMAlgorithmMapping[pool.amm]];
|
73
|
+
const d = campaigns?.filter(campaign => campaign.mainParameter.toLowerCase() === pool.mainParameter.toLowerCase())[0];
|
74
|
+
calls.push({
|
75
|
+
allowFailure: true,
|
76
|
+
callData: poolInterface.encodeFunctionData(Liquidity[AMMAlgorithmMapping[pool.amm]]),
|
77
|
+
target: pool.address,
|
78
|
+
}, {
|
79
|
+
allowFailure: true,
|
80
|
+
callData: poolInterface.encodeFunctionData(PoolState[AMMAlgorithmMapping[pool.amm]]),
|
81
|
+
target: pool.address,
|
82
|
+
}, {
|
83
|
+
allowFailure: true,
|
84
|
+
callData: ERC20Interface.encodeFunctionData("balanceOf", [pool.address]),
|
85
|
+
target: d.campaignParameters.token0,
|
86
|
+
}, {
|
87
|
+
allowFailure: true,
|
88
|
+
callData: ERC20Interface.encodeFunctionData("balanceOf", [pool.address]),
|
89
|
+
target: d.campaignParameters.token1,
|
90
|
+
});
|
91
|
+
/** Direct ALMs */
|
92
|
+
for (const alm of pool.alms.filter(a => a.target.toLowerCase() === pool.address.toLowerCase() && a.type !== ALM.A51)) {
|
93
|
+
let almAddress = alm.address;
|
94
|
+
if (alm.type === ALM.Beefy) {
|
95
|
+
almAddress = alm.owner ?? alm.address;
|
96
|
+
}
|
97
|
+
calls.push({
|
98
|
+
allowFailure: true,
|
99
|
+
callData: ERC20Interface.encodeFunctionData("totalSupply"),
|
100
|
+
target: alm.address,
|
101
|
+
});
|
102
|
+
calls.push({
|
103
|
+
allowFailure: true,
|
104
|
+
callData: ERC20Interface.encodeFunctionData("balanceOf", [almAddress]),
|
105
|
+
target: d.campaignParameters.token0,
|
106
|
+
});
|
107
|
+
calls.push({
|
108
|
+
allowFailure: true,
|
109
|
+
callData: ERC20Interface.encodeFunctionData("balanceOf", [almAddress]),
|
110
|
+
target: d.campaignParameters.token1,
|
111
|
+
});
|
112
|
+
}
|
113
|
+
/** Multi-hop ALMs */
|
114
|
+
for (const alm of pool.alms.filter(a => a.target !== pool.address.toLowerCase())) {
|
115
|
+
if (alm.type === ALM.spNFT) {
|
116
|
+
calls.push({
|
117
|
+
allowFailure: true,
|
118
|
+
callData: spNFTInterface.encodeFunctionData("getPoolInfo"),
|
119
|
+
target: alm.address,
|
120
|
+
});
|
121
|
+
}
|
122
|
+
else if (alm.type === ALM.kpNFT) {
|
123
|
+
calls.push({
|
124
|
+
allowFailure: true,
|
125
|
+
callData: spNFTInterface.encodeFunctionData("getPoolInfo"),
|
126
|
+
target: alm.address,
|
127
|
+
});
|
128
|
+
}
|
129
|
+
else if (alm.type === ALM.Nitro) {
|
130
|
+
calls.push({
|
131
|
+
allowFailure: true,
|
132
|
+
callData: NitroInterface.encodeFunctionData("totalDepositAmount"),
|
133
|
+
target: alm.address,
|
134
|
+
});
|
135
|
+
}
|
136
|
+
else if ([ALM.ConcentricStaker, ALM.GammaChef].includes(alm.type)) {
|
137
|
+
calls.push({
|
138
|
+
allowFailure: true,
|
139
|
+
callData: ERC20Interface.encodeFunctionData("balanceOf", [alm.address]),
|
140
|
+
target: alm.target,
|
141
|
+
});
|
142
|
+
}
|
143
|
+
else if (alm.type === ALM.JonesTracker) {
|
144
|
+
calls.push({
|
145
|
+
allowFailure: true,
|
146
|
+
callData: JonesDoubleRewardTracker__factory.createInterface().encodeFunctionData("totalStakedAmount"),
|
147
|
+
target: alm.address,
|
148
|
+
});
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
calls.push({
|
152
|
+
allowFailure: true,
|
153
|
+
callData: ERC20Interface.encodeFunctionData("totalSupply"),
|
154
|
+
target: alm.address,
|
155
|
+
});
|
156
|
+
}
|
157
|
+
}
|
158
|
+
/** A51 Strategies */
|
159
|
+
for (const w of pool.alms.filter(a => a.type === ALM.A51)) {
|
160
|
+
const strategies = A51Strategies?.[pool.address.toLowerCase()]?.[w.address] ?? [];
|
161
|
+
for (const strategy of strategies) {
|
162
|
+
calls.push({
|
163
|
+
allowFailure: true,
|
164
|
+
callData: A51Interface.encodeFunctionData("strategies", [strategy.id]),
|
165
|
+
target: w.address,
|
166
|
+
});
|
167
|
+
}
|
168
|
+
}
|
169
|
+
}
|
170
|
+
/**
|
171
|
+
* Fetch all ALM vaults positions for the pools.
|
172
|
+
* @dev Do it in parallel with 1 call / AMM subgraph to save time.
|
173
|
+
*/
|
174
|
+
const positions = {};
|
175
|
+
const positionsPromise = Object.keys(AMM)
|
176
|
+
.filter(amm => !!merklSubgraphAMMEndpoints[chainId][Number.parseInt(amm)])
|
177
|
+
.map(async (amm) => {
|
178
|
+
const tgURL = merklSubgraphAMMEndpoints[chainId][Number.parseInt(amm)];
|
179
|
+
let targetAddressesList = [];
|
180
|
+
if (!!poolList) {
|
181
|
+
for (const pool of poolList) {
|
182
|
+
if (pool.amm === Number.parseInt(amm)) {
|
183
|
+
/** Add direct alm addresses */
|
184
|
+
targetAddressesList = targetAddressesList.concat(pool.alms
|
185
|
+
.filter(a => a.target.toLowerCase() === pool.address.toLowerCase())
|
186
|
+
?.map(w => {
|
187
|
+
return !!w?.owner && Number.parseInt(amm) !== AMM.Stryke
|
188
|
+
? w.owner.toLowerCase()
|
189
|
+
: w.address.toLowerCase();
|
190
|
+
}) ?? []);
|
191
|
+
/** Add blacklisted / whitelisted addresses (optional) */
|
192
|
+
for (const campaign of campaigns.filter(campaign => campaign.mainParameter.toLowerCase() === pool.mainParameter.toLowerCase())) {
|
193
|
+
const distributionBlacklist = campaign.campaignId === "0x4a805dd97d823dfbc34d138af3d09536ac792b6ad73079573df082c71d4b057c"
|
194
|
+
? [...campaign.campaignParameters.blacklist, "0x657e6d2073A99aF61952beb7EE564169616b90C1"]
|
195
|
+
: campaign.campaignParameters.blacklist;
|
196
|
+
if (!!distributionBlacklist && distributionBlacklist.length > 0)
|
197
|
+
targetAddressesList = targetAddressesList.concat(distributionBlacklist.map((address) => address.toLowerCase()));
|
198
|
+
let distributionWhitelist = campaign.campaignParameters?.whitelist;
|
199
|
+
if (distributionWhitelist.length === 1 &&
|
200
|
+
distributionWhitelist[0].toLowerCase() ===
|
201
|
+
"0xE4bA6740aF4c666325D49B3112E4758371386aDc".toLowerCase()) {
|
202
|
+
distributionWhitelist = ["0xe11d346757d052214686bCbC860C94363AfB4a9A"];
|
203
|
+
}
|
204
|
+
if (!isStrykeCampaign(pool.amm) && !!distributionWhitelist && distributionWhitelist.length > 0)
|
205
|
+
targetAddressesList = targetAddressesList.concat(distributionWhitelist.map((address) => address.toLowerCase()));
|
206
|
+
}
|
207
|
+
}
|
208
|
+
}
|
209
|
+
}
|
210
|
+
targetAddressesList = targetAddressesList.filter((a, index, self) => self.indexOf(a) === index); // Dedupe
|
211
|
+
if (targetAddressesList?.length > 0) {
|
212
|
+
positions[Number.parseInt(amm)] = [];
|
213
|
+
/** Fetch NFT Wrapper positions */
|
214
|
+
const farmedPositionsList = await fetchFarmedPositions(chainId, targetAddressesList, Number(amm));
|
215
|
+
const farmedPositionsById = Object.keys(farmedPositionsList).reduce((acc, curr) => {
|
216
|
+
for (const pos of farmedPositionsList[curr]) {
|
217
|
+
acc[pos.id] = pos;
|
218
|
+
}
|
219
|
+
return acc;
|
220
|
+
}, {});
|
221
|
+
if (Object.keys(farmedPositionsById).length > 0) {
|
222
|
+
let hasFollowingPage = true;
|
223
|
+
let skip = 0;
|
224
|
+
const res = { nft: [] };
|
225
|
+
while (hasFollowingPage) {
|
226
|
+
const auxRes = await request(tgURL, nftPositionByIdsQuery, {
|
227
|
+
ids: Object.keys(farmedPositionsById),
|
228
|
+
skip,
|
229
|
+
});
|
230
|
+
res.nft = res.nft.concat(auxRes.nft ?? []);
|
231
|
+
if (auxRes.nft.length < 1000) {
|
232
|
+
hasFollowingPage = false;
|
233
|
+
}
|
234
|
+
skip += 1000;
|
235
|
+
}
|
236
|
+
if (!!res.nft) {
|
237
|
+
for (const pos of res.nft) {
|
238
|
+
positions[Number.parseInt(amm)]?.push({
|
239
|
+
...pos,
|
240
|
+
owner: farmedPositionsById[pos.id].holder,
|
241
|
+
});
|
242
|
+
}
|
243
|
+
}
|
244
|
+
}
|
245
|
+
await withTimeout((async () => {
|
246
|
+
let hasFollowingPage = true;
|
247
|
+
let skip = 0;
|
248
|
+
const res = { direct: [], nft: [] };
|
249
|
+
while (hasFollowingPage) {
|
250
|
+
const auxRes = await request(tgURL, positionMultipleOwnersQuery, {
|
251
|
+
owners: targetAddressesList,
|
252
|
+
skip,
|
253
|
+
});
|
254
|
+
res.direct = res.direct.concat(auxRes.direct ?? []);
|
255
|
+
res.nft = res.nft.concat(auxRes.nft ?? []);
|
256
|
+
if (auxRes.direct.length < 1000 && auxRes.nft.length < 1000) {
|
257
|
+
hasFollowingPage = false;
|
258
|
+
}
|
259
|
+
skip += 1000;
|
260
|
+
}
|
261
|
+
return res;
|
262
|
+
})().then(res => {
|
263
|
+
if (!!res.direct) {
|
264
|
+
for (const pos of res.direct) {
|
265
|
+
positions[Number.parseInt(amm)]?.push(pos);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
if (!!res.nft) {
|
269
|
+
for (const pos of res.nft) {
|
270
|
+
positions[Number.parseInt(amm)]?.push(pos);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
}), MERKL_ALM_POSITION_FETCHING_TIMEOUT).catch(error => {
|
274
|
+
const service = `Merkl AMM Subgraph for ${NETWORK_LABELS[chainId]} ${AMM[Number.parseInt(amm)]}`;
|
275
|
+
log.error(service, error, service, tgURL);
|
276
|
+
});
|
277
|
+
}
|
278
|
+
});
|
279
|
+
const result = await ChainInteractionService(chainId).fetchState(calls);
|
280
|
+
// Wait for position fetching before finalizing the data
|
281
|
+
await Promise.all(positionsPromise);
|
282
|
+
let i = 0;
|
283
|
+
if (!!poolList) {
|
284
|
+
for (const pool of poolList) {
|
285
|
+
const poolInterface = PoolInterface[AMMAlgorithmMapping[pool.amm]];
|
286
|
+
// This liquidity call gives the active liquidity on the pool. To get the total liquidity we would need to loop over all positions
|
287
|
+
let poolTotalLiquidity;
|
288
|
+
let sqrtPrice;
|
289
|
+
let poolBalanceToken0;
|
290
|
+
let poolBalanceToken1;
|
291
|
+
const d = campaigns?.filter(campaign => campaign.mainParameter.toLowerCase() === pool.mainParameter.toLowerCase())[0];
|
292
|
+
const decimalsToken0 = d.campaignParameters.decimalsToken0;
|
293
|
+
const decimalsToken1 = d.campaignParameters.decimalsToken1;
|
294
|
+
const symbolToken0 = d.campaignParameters.symbolToken0;
|
295
|
+
const symbolToken1 = d.campaignParameters.symbolToken1;
|
296
|
+
const prevI = i;
|
297
|
+
try {
|
298
|
+
poolTotalLiquidity = BN2Number(poolInterface.decodeFunctionResult(Liquidity[AMMAlgorithmMapping[pool.amm]], result[i++].returnData)[DecodeLiquidity[AMMAlgorithmMapping[pool.amm]]]);
|
299
|
+
sqrtPrice = poolInterface
|
300
|
+
.decodeFunctionResult(PoolState[AMMAlgorithmMapping[pool.amm]], result[i++].returnData)[SqrtPrice[AMMAlgorithmMapping[pool.amm]]].toString();
|
301
|
+
poolBalanceToken0 = BN2Number(ERC20Interface.decodeFunctionResult("balanceOf", result[i++].returnData)[0], decimalsToken0);
|
302
|
+
poolBalanceToken1 = BN2Number(ERC20Interface.decodeFunctionResult("balanceOf", result[i++].returnData)[0], decimalsToken1);
|
303
|
+
}
|
304
|
+
catch (e) {
|
305
|
+
log.warn(`merklDynamic data - failed to decode state of pool ${pool.address} on ${NETWORK_LABELS[chainId]}`);
|
306
|
+
i = prevI + 4;
|
307
|
+
continue;
|
308
|
+
}
|
309
|
+
const priceToken0 = (await pricer.get({
|
310
|
+
address: d.campaignParameters.token0,
|
311
|
+
chainId: chainId,
|
312
|
+
symbol: symbolToken0,
|
313
|
+
}));
|
314
|
+
const priceToken1 = (await pricer.get({
|
315
|
+
address: d.campaignParameters.token1,
|
316
|
+
chainId: chainId,
|
317
|
+
symbol: symbolToken1,
|
318
|
+
}));
|
319
|
+
const almDetails = [];
|
320
|
+
/** Direct ALMs */
|
321
|
+
for (const w of pool.alms.filter(a => a.target.toLowerCase() === pool.address.toLowerCase() && a.type !== ALM.A51)) {
|
322
|
+
const prevI = i;
|
323
|
+
try {
|
324
|
+
const totalSupply = BN2Number(ERC20Interface.decodeFunctionResult("totalSupply", result[i++].returnData)[0]);
|
325
|
+
const almIdleBalance0 = BN2Number(ERC20Interface.decodeFunctionResult("balanceOf", result[i++].returnData)[0], d.campaignParameters.decimalsToken0);
|
326
|
+
let almBalance0 = almIdleBalance0;
|
327
|
+
const almIdleBalance1 = BN2Number(ERC20Interface.decodeFunctionResult("balanceOf", result[i++].returnData)[0], d.campaignParameters.decimalsToken1);
|
328
|
+
let almBalance1 = almIdleBalance1;
|
329
|
+
let almTotalLiquidity = 0;
|
330
|
+
let almInRangeLiquidity = 0;
|
331
|
+
const almPositions = positions?.[pool.amm]?.filter(pos => pos.pool.id === pool.address.toLowerCase() &&
|
332
|
+
[w.address.toLowerCase(), ...[!!w?.owner && w.owner.toLowerCase()]].includes(pos.owner.toLowerCase()));
|
333
|
+
const almPositionsWithAPIType = [];
|
334
|
+
if (!!almPositions) {
|
335
|
+
for (const position of almPositions) {
|
336
|
+
const upperTick = Number.parseInt(position.tickUpper);
|
337
|
+
const lowerTick = Number.parseInt(position.tickLower);
|
338
|
+
const [amount0, amount1] = getAmountsForLiquidity(sqrtPrice, lowerTick, upperTick, BigNumber.from(position.liquidity));
|
339
|
+
const balance0 = BN2Number(amount0, decimalsToken0);
|
340
|
+
const balance1 = BN2Number(amount1, decimalsToken1);
|
341
|
+
const totalLiquidity = BN2Number(position.liquidity);
|
342
|
+
const inRangeLiquidity = balance0 > 0 && balance1 > 0 ? (BN2Number(position.liquidity) ?? 0) : 0;
|
343
|
+
almTotalLiquidity += totalLiquidity;
|
344
|
+
almInRangeLiquidity += inRangeLiquidity;
|
345
|
+
almBalance0 += balance0;
|
346
|
+
almBalance1 += balance1;
|
347
|
+
almPositionsWithAPIType.push({
|
348
|
+
balance0,
|
349
|
+
balance1,
|
350
|
+
id: position.id,
|
351
|
+
inRangeLiquidity,
|
352
|
+
lowerTick,
|
353
|
+
totalLiquidity,
|
354
|
+
tvl: priceToken0 * balance0 + priceToken1 * balance1,
|
355
|
+
upperTick,
|
356
|
+
});
|
357
|
+
}
|
358
|
+
// The wrapper type can exist in the subgraph without being declared in the SDK which can lead to type errors
|
359
|
+
if (!!ALMMapping[pool.amm] && w.type in ALMMapping[pool.amm]) {
|
360
|
+
almDetails.push({
|
361
|
+
almAPR: 0, // filled later on
|
362
|
+
almAddress: utils.getAddress(w.address),
|
363
|
+
almBalance0,
|
364
|
+
almIdleBalance0,
|
365
|
+
almIdleBalance1,
|
366
|
+
almBalance1,
|
367
|
+
almInRangeLiquidity,
|
368
|
+
almTVL: almBalance0 * priceToken0 + almBalance1 * priceToken1,
|
369
|
+
almTotalLiquidity,
|
370
|
+
forwarderType: Forwarder.CLAMM,
|
371
|
+
label: `${ALMMapping[pool.amm]?.[w.type]} ${w.address}`,
|
372
|
+
origin: w.type,
|
373
|
+
positions: almPositionsWithAPIType,
|
374
|
+
priority: 0,
|
375
|
+
sender: utils.getAddress(w.address),
|
376
|
+
target: w.target,
|
377
|
+
owner: utils.getAddress(w.owner ?? w.address),
|
378
|
+
totalSupply,
|
379
|
+
type: w.type,
|
380
|
+
});
|
381
|
+
}
|
382
|
+
}
|
383
|
+
}
|
384
|
+
catch (e) {
|
385
|
+
log.warn(`merklDynamic data - failed to handle direct alm data of pool ${pool.address} on ${NETWORK_LABELS[chainId]} - ${w.address}`);
|
386
|
+
i = prevI + 3;
|
387
|
+
}
|
388
|
+
}
|
389
|
+
/** Multi-hop ALMs */
|
390
|
+
for (const w of pool.alms.filter(a => a.target !== pool.address.toLowerCase())) {
|
391
|
+
const prevI = i;
|
392
|
+
try {
|
393
|
+
let totalSupply;
|
394
|
+
if (w.type === ALM.spNFT) {
|
395
|
+
totalSupply = BN2Number(spNFTInterface.decodeFunctionResult("getPoolInfo", result[i++].returnData)[5]);
|
396
|
+
}
|
397
|
+
else if (w.type === ALM.kpNFT) {
|
398
|
+
totalSupply = BN2Number(spNFTInterface.decodeFunctionResult("getPoolInfo", result[i++].returnData)[5]);
|
399
|
+
}
|
400
|
+
else if (w.type === ALM.Nitro) {
|
401
|
+
totalSupply = BN2Number(NitroInterface.decodeFunctionResult("totalDepositAmount", result[i++].returnData)[0]);
|
402
|
+
}
|
403
|
+
else if ([ALM.ConcentricStaker, ALM.GammaChef].includes(w.type)) {
|
404
|
+
totalSupply = BN2Number(ERC20Interface.decodeFunctionResult("balanceOf", result[i++].returnData)[0]);
|
405
|
+
}
|
406
|
+
else if (w.type === ALM.JonesTracker) {
|
407
|
+
totalSupply = BN2Number(JonesDoubleRewardTracker__factory.createInterface().decodeFunctionResult("totalStakedAmount", result[i++].returnData)[0]);
|
408
|
+
}
|
409
|
+
else {
|
410
|
+
totalSupply = BN2Number(ERC20Interface.decodeFunctionResult("totalSupply", result[i++].returnData)[0]);
|
411
|
+
}
|
412
|
+
const wrappedALM = almDetails.filter(a => utils.getAddress(a.almAddress) === utils.getAddress(w.target))[0];
|
413
|
+
if (!!wrappedALM && !!wrappedALM.totalSupply) {
|
414
|
+
const ratio = totalSupply / wrappedALM.totalSupply;
|
415
|
+
almDetails.push({
|
416
|
+
almAPR: 0,
|
417
|
+
// filled later on
|
418
|
+
almAddress: w.address,
|
419
|
+
almIdleBalance0: 0,
|
420
|
+
almIdleBalance1: 0,
|
421
|
+
almBalance0: ratio * wrappedALM.almBalance0,
|
422
|
+
almBalance1: ratio * wrappedALM.almBalance1,
|
423
|
+
almInRangeLiquidity: ratio * wrappedALM.almInRangeLiquidity,
|
424
|
+
almTVL: ratio * wrappedALM.almTVL,
|
425
|
+
almTotalLiquidity: ratio * wrappedALM.almTotalLiquidity,
|
426
|
+
forwarderType: Forwarder.CLAMM,
|
427
|
+
label: `${ALMMapping[pool.amm]?.[w.type]} ${w.address}`,
|
428
|
+
origin: w.type,
|
429
|
+
positions: wrappedALM.positions.map(pos => {
|
430
|
+
return {
|
431
|
+
...pos,
|
432
|
+
balance0: ratio * pos.balance0,
|
433
|
+
balance1: ratio * pos.balance1,
|
434
|
+
inRangeLiquidity: ratio * pos.inRangeLiquidity,
|
435
|
+
totalLiquidity: ratio * pos.totalLiquidity,
|
436
|
+
tvl: ratio * pos.tvl,
|
437
|
+
};
|
438
|
+
}),
|
439
|
+
priority: wrappedALM.priority + 1,
|
440
|
+
sender: utils.getAddress(w.address),
|
441
|
+
target: w.target,
|
442
|
+
owner: w.owner ?? w.address,
|
443
|
+
totalSupply,
|
444
|
+
type: w.type,
|
445
|
+
});
|
446
|
+
}
|
447
|
+
else {
|
448
|
+
log.local(`Target ALM not found (${NETWORK_LABELS[chainId]}). Address: ${w.address}, Target: ${w.target}`);
|
449
|
+
}
|
450
|
+
}
|
451
|
+
catch {
|
452
|
+
log.warn(`merklDynamic data - failed to handle multi hop alm data of pool ${pool.address} on ${NETWORK_LABELS[chainId]} - ${w.address}`);
|
453
|
+
i = prevI + 1;
|
454
|
+
}
|
455
|
+
}
|
456
|
+
/** A51 Strategies */
|
457
|
+
for (const w of pool.alms.filter(a => a.type === ALM.A51)) {
|
458
|
+
const prevI = i;
|
459
|
+
const strategies = A51Strategies?.[pool.address.toLowerCase()]?.[w.address] ?? [];
|
460
|
+
let j = 0;
|
461
|
+
for (const strategy of strategies) {
|
462
|
+
j++;
|
463
|
+
const almPositionsWithAPIType = [];
|
464
|
+
let almTotalLiquidity = 0;
|
465
|
+
let almInRangeLiquidity = 0;
|
466
|
+
let almBalance0 = 0;
|
467
|
+
let almBalance1 = 0;
|
468
|
+
try {
|
469
|
+
// struct StrategyData {
|
470
|
+
// StrategyKey key; 0
|
471
|
+
// address owner; 1
|
472
|
+
// bytes actions; 2
|
473
|
+
// bytes actionStatus; 3
|
474
|
+
// bool isCompound; 4
|
475
|
+
// bool isPrivate; 5
|
476
|
+
// uint256 managementFee; 6
|
477
|
+
// uint256 performanceFee; 7
|
478
|
+
// Account account; 8
|
479
|
+
// }
|
480
|
+
const strategyAccount = A51Interface.decodeFunctionResult("strategies", result[i++].returnData)[8];
|
481
|
+
// struct Account {
|
482
|
+
// uint256 fee0; 0
|
483
|
+
// uint256 fee1; 1
|
484
|
+
// uint256 balance0; 2
|
485
|
+
// uint256 balance1; 3
|
486
|
+
// uint256 totalShares; 4
|
487
|
+
// uint128 uniswapLiquidity;
|
488
|
+
// uint256 feeGrowthInside0LastX128;
|
489
|
+
// uint256 feeGrowthInside1LastX128;
|
490
|
+
// uint256 feeGrowthOutside0LastX128;
|
491
|
+
// uint256 feeGrowthOutside1LastX128;
|
492
|
+
// }
|
493
|
+
const a51Positions = positions?.[pool.amm]?.filter(pos => pos.pool.id === pool.address.toLowerCase() &&
|
494
|
+
pos.owner === w.address.toLowerCase() &&
|
495
|
+
pos.tickLower === strategy.tickLower.toString() &&
|
496
|
+
pos.tickUpper === strategy.tickUpper.toString());
|
497
|
+
if (!!a51Positions) {
|
498
|
+
for (const position of a51Positions) {
|
499
|
+
const upperTick = Number.parseInt(position.tickUpper);
|
500
|
+
const lowerTick = Number.parseInt(position.tickLower);
|
501
|
+
const [amount0, amount1] = getAmountsForLiquidity(sqrtPrice, lowerTick, upperTick, BigNumber.from(position.liquidity));
|
502
|
+
const balance0 = BN2Number(amount0, decimalsToken0);
|
503
|
+
const balance1 = BN2Number(amount1, decimalsToken1);
|
504
|
+
const totalLiquidity = BN2Number(position.liquidity);
|
505
|
+
const inRangeLiquidity = balance0 > 0 && balance1 > 0 ? (BN2Number(position.liquidity) ?? 0) : 0;
|
506
|
+
almTotalLiquidity += totalLiquidity;
|
507
|
+
almInRangeLiquidity += inRangeLiquidity;
|
508
|
+
almBalance0 += balance0;
|
509
|
+
almBalance1 += balance1;
|
510
|
+
almPositionsWithAPIType.push({
|
511
|
+
balance0,
|
512
|
+
balance1,
|
513
|
+
id: position.id,
|
514
|
+
inRangeLiquidity,
|
515
|
+
lowerTick,
|
516
|
+
totalLiquidity,
|
517
|
+
tvl: priceToken0 * balance0 + priceToken1 * balance1,
|
518
|
+
upperTick,
|
519
|
+
});
|
520
|
+
}
|
521
|
+
}
|
522
|
+
if (!!ALMMapping[pool.amm] && w.type in ALMMapping[pool.amm]) {
|
523
|
+
almDetails.push({
|
524
|
+
almAPR: 0,
|
525
|
+
// filled later on
|
526
|
+
almAddress: utils.getAddress(w.address),
|
527
|
+
almBalance0,
|
528
|
+
almBalance1,
|
529
|
+
almIdleBalance0: 0,
|
530
|
+
almIdleBalance1: 0,
|
531
|
+
almInRangeLiquidity,
|
532
|
+
almTVL: almBalance0 * priceToken0 + almBalance1 * priceToken1,
|
533
|
+
almTotalLiquidity,
|
534
|
+
forwarderType: Forwarder.CLAMM,
|
535
|
+
label: `${ALMMapping[pool.amm]?.[w.type]} ${w.address} - ${strategy.id}`,
|
536
|
+
origin: w.type,
|
537
|
+
positions: almPositionsWithAPIType,
|
538
|
+
priority: 0,
|
539
|
+
sender: w.address,
|
540
|
+
target: w.target,
|
541
|
+
owner: w.owner ?? w.address,
|
542
|
+
totalSupply: strategyAccount[4].toString(),
|
543
|
+
type: w.type,
|
544
|
+
});
|
545
|
+
}
|
546
|
+
}
|
547
|
+
catch (e) {
|
548
|
+
log.warn(`merklDynamic data - failed to handle A51 data of pool ${pool.address} on ${NETWORK_LABELS[chainId]} - ${w.address}`);
|
549
|
+
i = prevI + j;
|
550
|
+
}
|
551
|
+
}
|
552
|
+
}
|
553
|
+
/** Iterate over distributions to compute APRs */
|
554
|
+
for (const campaign of campaigns.filter(campaign => campaign.mainParameter.toLowerCase() === pool.mainParameter.toLowerCase())) {
|
555
|
+
const c = campaign;
|
556
|
+
const amount = BN2Number(c.amount, c.campaignParameters.decimalsRewardToken);
|
557
|
+
const startTimestamp = BN2Number(c.startTimestamp, 0);
|
558
|
+
const endTimestamp = BN2Number(c.endTimestamp, 0);
|
559
|
+
const isLive = moment().unix() > startTimestamp && moment().unix() < endTimestamp;
|
560
|
+
const totalWeight = BN2Number(c.campaignParameters.weightFees, 4) +
|
561
|
+
BN2Number(c.campaignParameters.weightToken0, 4) +
|
562
|
+
BN2Number(c.campaignParameters.weightToken1, 4);
|
563
|
+
// Proportions in percentage
|
564
|
+
const propFees = (BN2Number(c.campaignParameters.weightFees, 4) / totalWeight) * 100;
|
565
|
+
const propToken0 = (BN2Number(c.campaignParameters.weightToken0, 4) / totalWeight) * 100;
|
566
|
+
const propToken1 = (BN2Number(c.campaignParameters.weightToken1, 4) / totalWeight) * 100;
|
567
|
+
let distributionMeanAPR = 0;
|
568
|
+
let blacklistedBalance0 = 0;
|
569
|
+
let blacklistedBalance1 = 0;
|
570
|
+
let blacklistedLiquidity = 0;
|
571
|
+
/**
|
572
|
+
* @dev In case there is a super amm handling some other amm lp positions,
|
573
|
+
* we only need to check the positions associated to this super amm subgraph
|
574
|
+
* in order to compute the APRs.
|
575
|
+
* Yet, the pool will still be labelled with the main amm
|
576
|
+
*/
|
577
|
+
const amm = c.campaignParameters.whitelist.length > 0 && !!PriorityAMM?.[chainId]?.[c.campaignParameters.whitelist[0]]
|
578
|
+
? PriorityAMM[chainId]?.[c.campaignParameters.whitelist[0]]
|
579
|
+
: pool.amm;
|
580
|
+
const aprs = {};
|
581
|
+
const aprBreakdowns = [];
|
582
|
+
/** Clear alm APRs */
|
583
|
+
const distributionForwarders = almDetails.map(x => ({ ...x }));
|
584
|
+
let priceRewardToken = 0;
|
585
|
+
if (isLive && c.campaignParameters.symbolRewardToken !== "aglaMerkl") {
|
586
|
+
// priceRewardToken = (await pricer.get({
|
587
|
+
// address: c.rewardToken,
|
588
|
+
// chainId: chainId,
|
589
|
+
// symbol: c.campaignParameters.symbolRewardToken,
|
590
|
+
// })) as number;
|
591
|
+
priceRewardToken = await TokenService.getRewardTokenPrice(campaign);
|
592
|
+
/**
|
593
|
+
* Handle whitelisted/blacklisted addresses to compute APR
|
594
|
+
*/
|
595
|
+
if (c.campaignParameters.whitelist.length > 0) {
|
596
|
+
blacklistedBalance0 = poolBalanceToken0;
|
597
|
+
blacklistedBalance1 = poolBalanceToken1;
|
598
|
+
blacklistedLiquidity = poolTotalLiquidity;
|
599
|
+
// Get all beefy staker is whitelisted, get a list of all senders
|
600
|
+
let targetToMatch = "";
|
601
|
+
for (const alm of almDetails.filter(a => a.type === ALM.BeefyStaker)) {
|
602
|
+
if (c.campaignParameters.whitelist.includes(alm.sender)) {
|
603
|
+
targetToMatch = alm.target;
|
604
|
+
}
|
605
|
+
}
|
606
|
+
if (targetToMatch !== "") {
|
607
|
+
for (const alm of almDetails.filter(a => a.type === ALM.Beefy)) {
|
608
|
+
if (targetToMatch === alm.sender.toLowerCase()) {
|
609
|
+
c.campaignParameters.whitelist.push(alm.owner);
|
610
|
+
}
|
611
|
+
}
|
612
|
+
}
|
613
|
+
positions?.[pool.amm]?.forEach(pos => {
|
614
|
+
if (pos.pool.id === pool.address.toLowerCase() &&
|
615
|
+
(isWhitelisted(pos.owner, c.campaignParameters.whitelist) || isStrykeCampaign(pool.amm))) {
|
616
|
+
let [amount0, amount1] = [BigNumber.from(0), BigNumber.from(0)];
|
617
|
+
try {
|
618
|
+
[amount0, amount1] = getAmountsForLiquidity(sqrtPrice, Number.parseInt(pos.tickLower), Number.parseInt(pos.tickUpper), BigNumber.from(pos.liquidity));
|
619
|
+
}
|
620
|
+
catch {
|
621
|
+
log.warn(`merklDynamic data - failed to handle whitelisted positions of pool ${pool.address} on ${NETWORK_LABELS[chainId]} - ${pos.owner} ${pos.tickLower} ${pos.tickUpper} ${pos.liquidity}`);
|
622
|
+
}
|
623
|
+
blacklistedBalance0 -= BN2Number(amount0, decimalsToken0);
|
624
|
+
blacklistedBalance1 -= BN2Number(amount1, decimalsToken1);
|
625
|
+
if (c.campaignParameters.isOutOfRangeIncentivized
|
626
|
+
? BN2Number(amount0, decimalsToken0) > 0 || BN2Number(amount1, decimalsToken1) > 0
|
627
|
+
: BN2Number(amount0, decimalsToken0) > 0 && BN2Number(amount1, decimalsToken1) > 0)
|
628
|
+
blacklistedLiquidity -= BN2Number(pos.liquidity);
|
629
|
+
}
|
630
|
+
// Handling the case of a ALM of priority 2 being whitelisted
|
631
|
+
else if (pos.pool.id === pool.address.toLowerCase() &&
|
632
|
+
almDetails.map(a => a.target.toLowerCase()).includes(pos.owner.toLowerCase()) // If pos owner is an ALM
|
633
|
+
) {
|
634
|
+
// If we're in this branch it means the ALM owning the position is not whitelisted
|
635
|
+
const almHolding = almDetails.filter(a => a.almAddress.toLowerCase() === pos.owner.toLowerCase())[0];
|
636
|
+
for (const whitelistedAddress of c.campaignParameters.whitelist) {
|
637
|
+
const forwarderIndex = distributionForwarders.findIndex(f => utils.getAddress(f.almAddress) === utils.getAddress(whitelistedAddress));
|
638
|
+
if (forwarderIndex !== -1 &&
|
639
|
+
almHolding.almAddress.toLowerCase() ===
|
640
|
+
distributionForwarders[forwarderIndex].target.toLowerCase()) {
|
641
|
+
// If we are here it means one of the ALM whitelisted is a "child" of the ALM holding the position
|
642
|
+
const childALM = distributionForwarders[forwarderIndex];
|
643
|
+
let [amount0, amount1] = [BigNumber.from(0), BigNumber.from(0)];
|
644
|
+
try {
|
645
|
+
[amount0, amount1] = getAmountsForLiquidity(sqrtPrice, Number.parseInt(pos.tickLower), Number.parseInt(pos.tickUpper), BigNumber.from(pos.liquidity));
|
646
|
+
}
|
647
|
+
catch {
|
648
|
+
log.warn(`merklDynamic data - failed to handle whitelisted positions of pool ${pool.address} on ${NETWORK_LABELS[chainId]} - ${pos.owner} ${pos.tickLower} ${pos.tickUpper} ${pos.liquidity}`);
|
649
|
+
}
|
650
|
+
blacklistedBalance0 -=
|
651
|
+
(BN2Number(amount0, decimalsToken0) * childALM.almBalance0) / almHolding.almBalance0;
|
652
|
+
blacklistedBalance1 -=
|
653
|
+
(BN2Number(amount1, decimalsToken1) * childALM.almBalance1) / almHolding.almBalance1;
|
654
|
+
if (c.campaignParameters.isOutOfRangeIncentivized
|
655
|
+
? BN2Number(amount0, decimalsToken0) > 0 || BN2Number(amount1, decimalsToken1) > 0
|
656
|
+
: BN2Number(amount0, decimalsToken0) > 0 && BN2Number(amount1, decimalsToken1) > 0)
|
657
|
+
blacklistedLiquidity -=
|
658
|
+
(BN2Number(pos.liquidity) * childALM.almTotalLiquidity) / almHolding.almTotalLiquidity;
|
659
|
+
}
|
660
|
+
}
|
661
|
+
}
|
662
|
+
});
|
663
|
+
}
|
664
|
+
else if (c.campaignParameters.blacklist.length > 0) {
|
665
|
+
blacklistedBalance0 = 0;
|
666
|
+
blacklistedBalance1 = 0;
|
667
|
+
blacklistedLiquidity = 0;
|
668
|
+
for (const blacklistedAddress of c.campaignParameters.blacklist) {
|
669
|
+
const blackAddressPositions = positions?.[amm]?.filter(pos => pos.pool.id === pool.address.toLowerCase() && pos.owner === blacklistedAddress.toLowerCase());
|
670
|
+
if (!!blackAddressPositions) {
|
671
|
+
for (const position of blackAddressPositions) {
|
672
|
+
const [amount0, amount1] = getAmountsForLiquidity(sqrtPrice, Number.parseInt(position.tickLower), Number.parseInt(position.tickUpper), BigNumber.from(position.liquidity));
|
673
|
+
blacklistedBalance0 += BN2Number(amount0, decimalsToken0);
|
674
|
+
blacklistedBalance1 += BN2Number(amount1, decimalsToken1);
|
675
|
+
if (BN2Number(amount0, decimalsToken0) > 0 && BN2Number(amount1, decimalsToken1) > 0)
|
676
|
+
blacklistedLiquidity += BN2Number(position.liquidity);
|
677
|
+
}
|
678
|
+
}
|
679
|
+
}
|
680
|
+
}
|
681
|
+
/** Yearly rewards in $ */
|
682
|
+
const yearlyToken0Rewards = (propToken0 * priceRewardToken * amount * (365 * 24 * 3_600)) / (endTimestamp - startTimestamp);
|
683
|
+
const yearlyToken1Rewards = (propToken1 * priceRewardToken * amount * (365 * 24 * 3_600)) / (endTimestamp - startTimestamp);
|
684
|
+
const yearlyFeeRewards = (propFees * priceRewardToken * amount * (365 * 24 * 3_600)) / (endTimestamp - startTimestamp);
|
685
|
+
let poolAPRkey = "";
|
686
|
+
// /**
|
687
|
+
// * @notice Stryke users receive rewards with respect to their LP positions (they hold through
|
688
|
+
// * Stryke contracts and the `used liquidity` hold in the Stryke option market contracts
|
689
|
+
// */
|
690
|
+
// if (amm === AMM.Stryke || amm === AMM.StrykePCS) {
|
691
|
+
// try {
|
692
|
+
// poolBalanceToken0 +=
|
693
|
+
// BN2Number(
|
694
|
+
// await Erc20__factory.connect(c.campaignParameters.token0, providers[chainId]).balanceOf(
|
695
|
+
// DOPEX_OPTION_MARKET[pool.address.toLowerCase()]
|
696
|
+
// ),
|
697
|
+
// c.campaignParameters.decimalsToken0
|
698
|
+
// ) / 2;
|
699
|
+
// poolBalanceToken1 +=
|
700
|
+
// BN2Number(
|
701
|
+
// await Erc20__factory.connect(c.campaignParameters.token1, providers[chainId]).balanceOf(
|
702
|
+
// DOPEX_OPTION_MARKET[pool.address.toLowerCase()]
|
703
|
+
// ),
|
704
|
+
// c.campaignParameters.decimalsToken1
|
705
|
+
// ) / 2;
|
706
|
+
// } catch {
|
707
|
+
// log.error(
|
708
|
+
// "clamm dynamic data fetching",
|
709
|
+
// `failed to handle dopex option market - ${pool.address}`
|
710
|
+
// );
|
711
|
+
// }
|
712
|
+
// }
|
713
|
+
/**
|
714
|
+
* General APR (@notice potentially with a boost)
|
715
|
+
*/
|
716
|
+
let poolBalanceToken0WithoutBlacklist = poolBalanceToken0 - (blacklistedBalance0 ?? 0);
|
717
|
+
poolBalanceToken0WithoutBlacklist = !!poolBalanceToken0WithoutBlacklist
|
718
|
+
? poolBalanceToken0WithoutBlacklist
|
719
|
+
: 0.00001;
|
720
|
+
let poolBalanceToken1WithoutBlacklist = poolBalanceToken1 - (blacklistedBalance1 ?? 0);
|
721
|
+
poolBalanceToken1WithoutBlacklist = !!poolBalanceToken1WithoutBlacklist
|
722
|
+
? poolBalanceToken1WithoutBlacklist
|
723
|
+
: 0.00001;
|
724
|
+
const poolLiquidityWithoutBlacklist = poolTotalLiquidity - (blacklistedLiquidity ?? 0);
|
725
|
+
const tvl = isStrykeCampaign(amm)
|
726
|
+
? (await axios.get(`https://api.stryke.xyz/clamm/stats/tvl/${pool.address}?chainId=${chainId}`))
|
727
|
+
.data
|
728
|
+
: poolBalanceToken0WithoutBlacklist * priceToken0 + poolBalanceToken1WithoutBlacklist * priceToken1;
|
729
|
+
distributionMeanAPR = (yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) / tvl;
|
730
|
+
distributionMeanAPR = !distributionMeanAPR || Number.isNaN(distributionMeanAPR) ? 0 : distributionMeanAPR;
|
731
|
+
/**
|
732
|
+
* @dev We cannot include a whitelisted distrib apr into the mean APR
|
733
|
+
*/
|
734
|
+
if (c.campaignParameters.whitelist.length === 0) {
|
735
|
+
poolAPRkey = "Average APR (rewards / pool TVL)";
|
736
|
+
if (!aprs[poolAPRkey])
|
737
|
+
aprs[poolAPRkey] = 0;
|
738
|
+
aprs[poolAPRkey] += distributionMeanAPR;
|
739
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
740
|
+
aprBreakdowns.push({
|
741
|
+
address: pool.address,
|
742
|
+
value: distributionMeanAPR,
|
743
|
+
type: EAprBreakdownType.AVERAGE,
|
744
|
+
label: "Average APR (rewards / pool TVL)",
|
745
|
+
});
|
746
|
+
// APR per token
|
747
|
+
poolAPRkey = `APR for holding ${c.campaignParameters.symbolToken0} in pool`;
|
748
|
+
if (!aprs[poolAPRkey])
|
749
|
+
aprs[poolAPRkey] = 0;
|
750
|
+
aprs[poolAPRkey] += yearlyToken0Rewards / (poolBalanceToken0WithoutBlacklist * priceToken0);
|
751
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
752
|
+
aprBreakdowns.push({
|
753
|
+
address: pool.address,
|
754
|
+
value: yearlyToken0Rewards / (poolBalanceToken0WithoutBlacklist * priceToken0),
|
755
|
+
type: EAprBreakdownType.TOKEN1,
|
756
|
+
label: c.campaignParameters.symbolToken0,
|
757
|
+
});
|
758
|
+
poolAPRkey = `APR for holding ${c.campaignParameters.symbolToken1} in pool`;
|
759
|
+
if (!aprs[poolAPRkey])
|
760
|
+
aprs[poolAPRkey] = 0;
|
761
|
+
aprs[poolAPRkey] += yearlyToken1Rewards / (poolBalanceToken1WithoutBlacklist * priceToken1);
|
762
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
763
|
+
aprBreakdowns.push({
|
764
|
+
address: pool.address,
|
765
|
+
value: yearlyToken1Rewards / (poolBalanceToken1WithoutBlacklist * priceToken1),
|
766
|
+
type: EAprBreakdownType.TOKEN2,
|
767
|
+
label: c.campaignParameters.symbolToken1,
|
768
|
+
});
|
769
|
+
}
|
770
|
+
else {
|
771
|
+
for (const whitelistedAddress of c.campaignParameters.whitelist) {
|
772
|
+
const forwarderIndex = distributionForwarders.findIndex(f => utils.getAddress(f.almAddress) === utils.getAddress(whitelistedAddress));
|
773
|
+
const poolAPRkey = `Whitelisted campaign on ${ammName(amm)} via address ${shortenAddress(c.campaignParameters.whitelist[0])} Average APR`;
|
774
|
+
if (!aprs[poolAPRkey])
|
775
|
+
aprs[poolAPRkey] = 0;
|
776
|
+
// Account for idle liquidity
|
777
|
+
if (forwarderIndex > -1) {
|
778
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
779
|
+
const breakdownWl = {
|
780
|
+
address: c.campaignParameters.whitelist[0],
|
781
|
+
value: 0,
|
782
|
+
type: EAprBreakdownType.WHITELIST,
|
783
|
+
label: ammName(amm),
|
784
|
+
};
|
785
|
+
if (distributionForwarders[forwarderIndex].priority === 2) {
|
786
|
+
distributionMeanAPR =
|
787
|
+
(yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) /
|
788
|
+
(tvl +
|
789
|
+
distributionForwarders[forwarderIndex].almBalance0 * priceToken0 +
|
790
|
+
distributionForwarders[forwarderIndex].almBalance1 * priceToken1);
|
791
|
+
}
|
792
|
+
else {
|
793
|
+
distributionMeanAPR =
|
794
|
+
(yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) /
|
795
|
+
(tvl +
|
796
|
+
distributionForwarders[forwarderIndex].almIdleBalance0 * priceToken0 +
|
797
|
+
distributionForwarders[forwarderIndex].almIdleBalance1 * priceToken1);
|
798
|
+
}
|
799
|
+
distributionMeanAPR =
|
800
|
+
!distributionMeanAPR || Number.isNaN(distributionMeanAPR) ? 0 : distributionMeanAPR;
|
801
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
802
|
+
breakdownWl.value = distributionMeanAPR;
|
803
|
+
aprBreakdowns.push(breakdownWl);
|
804
|
+
}
|
805
|
+
}
|
806
|
+
aprs[poolAPRkey] += distributionMeanAPR;
|
807
|
+
}
|
808
|
+
/**
|
809
|
+
* ALM APRs
|
810
|
+
* @notice given a campaign
|
811
|
+
* */
|
812
|
+
distributionForwarders.forEach((alm, index) => {
|
813
|
+
const targetForwarder = distributionForwarders.filter(f => f.almAddress.toLowerCase() === alm.target.toLowerCase())?.[0];
|
814
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
815
|
+
const aprsBreakdown = getForwarderAprbreakDown(distributionForwarders, alm, c, pool, yearlyToken0Rewards, yearlyToken1Rewards, yearlyFeeRewards, poolBalanceToken0WithoutBlacklist, poolBalanceToken1WithoutBlacklist, poolLiquidityWithoutBlacklist, tvl, distributionMeanAPR, index, chainId, amm);
|
816
|
+
// @Hugo wip: new way to structure aprBreakdowns
|
817
|
+
aprsBreakdown && aprBreakdowns.push(aprsBreakdown);
|
818
|
+
const isALMWhitelisted = c.campaignParameters.whitelist.length > 0
|
819
|
+
? isStrykeCampaign(pool.amm)
|
820
|
+
? true
|
821
|
+
: isWhitelisted(alm.sender, c.campaignParameters.whitelist) ||
|
822
|
+
isWhitelisted(alm.almAddress, c.campaignParameters.whitelist) ||
|
823
|
+
isWhitelisted(!!alm?.owner ? alm.owner : "", c.campaignParameters.whitelist) ||
|
824
|
+
isWhitelisted(!!alm?.target ? alm.target : "", c.campaignParameters.whitelist) ||
|
825
|
+
(!!targetForwarder?.owner &&
|
826
|
+
isWhitelisted(targetForwarder?.owner, c.campaignParameters.whitelist))
|
827
|
+
: true;
|
828
|
+
const isBlacklistedByCampaign = isBlacklisted(alm.sender, c.campaignParameters.blacklist) ||
|
829
|
+
isBlacklisted(alm.almAddress, c.campaignParameters.blacklist) ||
|
830
|
+
(!!alm?.target && isBlacklisted(alm?.target, c.campaignParameters.blacklist)) ||
|
831
|
+
!isALMWhitelisted;
|
832
|
+
if (!isBlacklistedByCampaign && !!alm.almTVL && alm.almTVL > 0) {
|
833
|
+
try {
|
834
|
+
poolAPRkey = `${almName(alm.origin)} ${alm.almAddress}`;
|
835
|
+
if (!aprs[poolAPRkey])
|
836
|
+
aprs[poolAPRkey] = 0;
|
837
|
+
// Token 0 APR
|
838
|
+
const almToken0APR = (yearlyToken0Rewards * (alm?.almBalance0 ?? 0 - alm?.almIdleBalance0 ?? 0)) /
|
839
|
+
poolBalanceToken0WithoutBlacklist /
|
840
|
+
alm.almTVL;
|
841
|
+
aprs[poolAPRkey] += almToken0APR;
|
842
|
+
// Token 1 APR
|
843
|
+
const almToken1APR = (yearlyToken1Rewards * (alm?.almBalance1 ?? 0 - alm?.almIdleBalance1 ?? 0)) /
|
844
|
+
poolBalanceToken1WithoutBlacklist /
|
845
|
+
alm.almTVL;
|
846
|
+
((alm.almBalance1 / (alm?.almBalance1 ?? 0 + alm?.almIdleBalance1 ?? 0)) *
|
847
|
+
alm.almBalance1 *
|
848
|
+
yearlyToken1Rewards) /
|
849
|
+
poolBalanceToken1WithoutBlacklist /
|
850
|
+
alm.almTVL;
|
851
|
+
aprs[poolAPRkey] += almToken1APR;
|
852
|
+
// Fee APR
|
853
|
+
const almFeeAPR = (yearlyFeeRewards * (alm?.almInRangeLiquidity ?? 0)) / poolLiquidityWithoutBlacklist / alm.almTVL;
|
854
|
+
aprs[poolAPRkey] += almFeeAPR;
|
855
|
+
if (isStrykeCampaign(amm)) {
|
856
|
+
// computation is less precise here as we don't have the details of balances
|
857
|
+
aprs[poolAPRkey] = (yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) / tvl;
|
858
|
+
}
|
859
|
+
/** Fix to tackle discrepancies in the APRs when there is a whitelist */
|
860
|
+
if ((c.campaignParameters.whitelist?.length === 1 &&
|
861
|
+
(isWhitelisted(alm.sender, c.campaignParameters.whitelist) ||
|
862
|
+
isWhitelisted(alm.almAddress, c.campaignParameters.whitelist) ||
|
863
|
+
isWhitelisted(!!alm?.target ? alm.target : "", c.campaignParameters.whitelist) ||
|
864
|
+
isWhitelisted(!!alm?.owner ? alm.owner : "", c.campaignParameters.whitelist))) ||
|
865
|
+
(!!targetForwarder?.owner &&
|
866
|
+
isWhitelisted(targetForwarder?.owner, c.campaignParameters.whitelist))) {
|
867
|
+
if (aprs[poolAPRkey] < distributionMeanAPR || !aprs[poolAPRkey] || aprs[poolAPRkey] > 1e12) {
|
868
|
+
aprs[poolAPRkey] = distributionMeanAPR;
|
869
|
+
}
|
870
|
+
}
|
871
|
+
distributionForwarders[index].almAPR = aprs[poolAPRkey];
|
872
|
+
}
|
873
|
+
catch (e) {
|
874
|
+
log.error("CLAMMDynamicData", `failed to compute ALM APR for ${alm.almAddress} (sender ${alm.sender}) on ${NETWORK_LABELS[chainId]}: ${e}`);
|
875
|
+
}
|
876
|
+
}
|
877
|
+
});
|
878
|
+
}
|
879
|
+
dynamicData.push({
|
880
|
+
...campaign,
|
881
|
+
amm: pool.amm,
|
882
|
+
ammAlgo: AMMAlgorithmMapping[pool.amm],
|
883
|
+
ammAlgoName: AMMAlgorithm[AMMAlgorithmMapping[pool.amm]],
|
884
|
+
ammName: AMM[pool.amm],
|
885
|
+
apr: distributionMeanAPR,
|
886
|
+
aprs,
|
887
|
+
aprBreakdowns,
|
888
|
+
blacklistedBalance0,
|
889
|
+
blacklistedBalance1,
|
890
|
+
blacklistedLiquidity,
|
891
|
+
forwarders: distributionForwarders,
|
892
|
+
isLive,
|
893
|
+
isMock: c.campaignParameters.symbolRewardToken === "aglaMerkl",
|
894
|
+
poolBalanceToken0,
|
895
|
+
poolBalanceToken1,
|
896
|
+
poolTotalLiquidity,
|
897
|
+
symbolToken0,
|
898
|
+
symbolToken1,
|
899
|
+
tick: getTickAtSqrtRatio(JSBI.BigInt(sqrtPrice)),
|
900
|
+
priceRewardToken: priceRewardToken,
|
901
|
+
tvl: isStrykeCampaign(pool.amm)
|
902
|
+
? (await axios.get(`https://api.stryke.xyz/clamm/stats/tvl/${pool.address}?chainId=${chainId}`))
|
903
|
+
.data
|
904
|
+
: poolBalanceToken0 * priceToken0 + poolBalanceToken1 * priceToken1,
|
905
|
+
});
|
906
|
+
}
|
907
|
+
}
|
908
|
+
}
|
909
|
+
}
|
910
|
+
return dynamicData;
|
911
|
+
}
|
912
|
+
}
|
913
|
+
function getForwarderAprbreakDown(distributionForwarders, alm, campaign, pool, yearlyToken0Rewards, yearlyToken1Rewards, yearlyFeeRewards, poolBalanceToken0WithoutBlacklist, poolBalanceToken1WithoutBlacklist, poolLiquidityWithoutBlacklist, tvl, distributionMeanAPR, index, chainId, amm) {
|
914
|
+
if (!distributionForwarders)
|
915
|
+
return null;
|
916
|
+
let aprBreakdowns = null;
|
917
|
+
const targetForwarder = distributionForwarders.filter(f => f.almAddress.toLowerCase() === alm.target.toLowerCase())?.[0];
|
918
|
+
const isALMWhitelisted = campaign.campaignParameters.whitelist.length > 0
|
919
|
+
? isStrykeCampaign(pool.amm)
|
920
|
+
? true
|
921
|
+
: isWhitelisted(alm.sender, campaign.campaignParameters.whitelist) ||
|
922
|
+
isWhitelisted(alm.almAddress, campaign.campaignParameters.whitelist) ||
|
923
|
+
isWhitelisted(!!alm?.owner ? alm.owner : "", campaign.campaignParameters.whitelist) ||
|
924
|
+
isWhitelisted(!!alm?.target ? alm.target : "", campaign.campaignParameters.whitelist) ||
|
925
|
+
(!!targetForwarder?.owner && isWhitelisted(targetForwarder?.owner, campaign.campaignParameters.whitelist))
|
926
|
+
: true;
|
927
|
+
const isBlacklistedByCampaign = isBlacklisted(alm.sender, campaign.campaignParameters.blacklist) ||
|
928
|
+
isBlacklisted(alm.almAddress, campaign.campaignParameters.blacklist) ||
|
929
|
+
(!!alm?.target && isBlacklisted(alm?.target, campaign.campaignParameters.blacklist)) ||
|
930
|
+
!isALMWhitelisted;
|
931
|
+
if (!isBlacklistedByCampaign && !!alm.almTVL && alm.almTVL > 0) {
|
932
|
+
try {
|
933
|
+
// Token 0 APR
|
934
|
+
const almToken0APR = (yearlyToken0Rewards * (alm?.almBalance0 ?? 0 - alm?.almIdleBalance0 ?? 0)) /
|
935
|
+
poolBalanceToken0WithoutBlacklist /
|
936
|
+
alm.almTVL;
|
937
|
+
// Token 1 APR
|
938
|
+
const almToken1APR = (yearlyToken1Rewards * (alm?.almBalance1 ?? 0 - alm?.almIdleBalance1 ?? 0)) /
|
939
|
+
poolBalanceToken1WithoutBlacklist /
|
940
|
+
alm.almTVL;
|
941
|
+
// Fee APR
|
942
|
+
const almFeeAPR = (yearlyFeeRewards * (alm?.almInRangeLiquidity ?? 0)) / poolLiquidityWithoutBlacklist / alm.almTVL;
|
943
|
+
let aprValue = almToken0APR + almToken1APR + almFeeAPR;
|
944
|
+
// computation is less precise here as we don't have the details of balances
|
945
|
+
if (isStrykeCampaign(amm))
|
946
|
+
aprValue = (yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) / tvl;
|
947
|
+
/** Fix to tackle discrepancies in the APRs when there is a whitelist */
|
948
|
+
if ((campaign.campaignParameters.whitelist?.length === 1 &&
|
949
|
+
(isWhitelisted(alm.sender, campaign.campaignParameters.whitelist) ||
|
950
|
+
isWhitelisted(alm.almAddress, campaign.campaignParameters.whitelist) ||
|
951
|
+
isWhitelisted(!!alm?.target ? alm.target : "", campaign.campaignParameters.whitelist) ||
|
952
|
+
isWhitelisted(!!alm?.owner ? alm.owner : "", campaign.campaignParameters.whitelist))) ||
|
953
|
+
(!!targetForwarder?.owner && isWhitelisted(targetForwarder?.owner, campaign.campaignParameters.whitelist))) {
|
954
|
+
if (aprValue < distributionMeanAPR || !aprValue || aprValue > 1e12)
|
955
|
+
aprValue = distributionMeanAPR;
|
956
|
+
}
|
957
|
+
aprBreakdowns = {
|
958
|
+
address: pool.address,
|
959
|
+
value: aprValue,
|
960
|
+
type: EAprBreakdownType.FORWARDER,
|
961
|
+
label: almName(alm.origin),
|
962
|
+
};
|
963
|
+
distributionForwarders[index].almAPR = aprValue; // @Hugo wip: new way to structure aprBreakdowns + check this
|
964
|
+
}
|
965
|
+
catch (e) {
|
966
|
+
log.error("CLAMMDynamicData", `failed to compute ALM APR for ${alm.almAddress} (sender ${alm.sender}) on ${NETWORK_LABELS[chainId]}: ${e}`);
|
967
|
+
}
|
968
|
+
}
|
969
|
+
return aprBreakdowns;
|
970
|
+
}
|