@merkl/api 0.20.36 → 0.20.38

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.
@@ -172,7 +172,8 @@ export class UniswapV4DynamicData {
172
172
  const poolBalanceToken0WithoutBlacklist = poolBalanceToken0;
173
173
  const poolBalanceToken1WithoutBlacklist = poolBalanceToken1;
174
174
  // const poolLiquidityWithoutBlacklist = poolTotalLiquidity - (blacklistedLiquidity ?? 0);
175
- const tvl = poolBalanceToken0WithoutBlacklist * priceToken0 + poolBalanceToken1WithoutBlacklist * priceToken1;
175
+ const tvl = (!!priceToken0 ? poolBalanceToken0 * priceToken0 : 0) +
176
+ (!!priceToken1 ? poolBalanceToken1 * priceToken1 : 0);
176
177
  distributionMeanAPR = (yearlyToken0Rewards + yearlyToken1Rewards + yearlyFeeRewards) / tvl;
177
178
  distributionMeanAPR = !distributionMeanAPR || Number.isNaN(distributionMeanAPR) ? 0 : distributionMeanAPR;
178
179
  /**
@@ -1,5 +1,5 @@
1
1
  import type { Pricer } from "@/utils/pricer";
2
- import { type Campaign, type CampaignParameters } from "@sdk";
2
+ import type { Campaign, CampaignParameters } from "@sdk";
3
3
  import { GenericProcessor, type dataType, type mandatoryCallKeys } from "../GenericProcessor";
4
4
  import type { tokenType } from "../helpers/tokenType";
5
5
  type callType = {
@@ -10,6 +10,7 @@ type callType = {
10
10
  };
11
11
  type callKeysxU308 = mandatoryCallKeys & {
12
12
  pool: string;
13
+ sqrtPriceX96: string;
13
14
  _token0: string;
14
15
  _token1: string;
15
16
  symbolToken0: string;
@@ -32,6 +33,6 @@ export declare class xU308Processor extends GenericProcessor<callKeysxU308, data
32
33
  round4: callType[];
33
34
  };
34
35
  processingRound2(typeInfo: dataRawxU308): void;
35
- processingRound5(_index: number, type: tokenType, typeInfo: dataRawxU308, _calls: string[], campaign: CampaignParameters<Campaign.ERC20> | CampaignParameters<Campaign.EULER>, pricer: Pricer): Promise<dataTypexU308>;
36
+ processingRound5(_index: number, type: tokenType, typeInfo: dataRawxU308, _calls: string[], campaign: CampaignParameters<Campaign.ERC20> | CampaignParameters<Campaign.EULER>, _pricer: Pricer): Promise<dataTypexU308>;
36
37
  }
37
38
  export {};
@@ -1,5 +1,4 @@
1
1
  import { generateCardName } from "@/utils/generateCardName";
2
- import { BN2Number } from "@sdk";
3
2
  import { GenericProcessor } from "../GenericProcessor";
4
3
  export class xU308Processor extends GenericProcessor {
5
4
  rounds = {
@@ -7,6 +6,7 @@ export class xU308Processor extends GenericProcessor {
7
6
  round2: [
8
7
  { key: "_token0", call: "token0", target: "pool" },
9
8
  { key: "_token1", call: "token1", target: "pool" },
9
+ { key: "sqrtPriceX96", call: "sqrtPriceX96", target: "pool" },
10
10
  ],
11
11
  round3: [
12
12
  { key: "symbolToken0", call: "symbol", target: "_token0" },
@@ -22,19 +22,11 @@ export class xU308Processor extends GenericProcessor {
22
22
  processingRound2(typeInfo) {
23
23
  typeInfo.pool = "0xB387D0A73619791420De4a1e5e710023Cb0f49c0";
24
24
  }
25
- async processingRound5(_index, type, typeInfo, _calls, campaign, pricer) {
25
+ async processingRound5(_index, type, typeInfo, _calls, campaign, _pricer) {
26
26
  const { whitelistedSupplyTargetToken, totalSupply, blacklistedSupply } = this.handleWhiteListBlacklistRound5(typeInfo, campaign);
27
- let priceTargetToken = 0;
28
- if (typeInfo._token0 !== typeInfo.tokenAddress) {
29
- const priceToken0 = (await pricer.get({ symbol: typeInfo.symbolToken0 })) ?? 0;
30
- priceTargetToken =
31
- (priceToken0 * BN2Number(typeInfo.balanceToken0, Number(typeInfo.decimalsToken0))) /
32
- BN2Number(typeInfo.balanceToken1, Number(typeInfo.decimalsToken1));
33
- }
34
- const priceToken1 = (await pricer.get({ symbol: typeInfo.symbolToken1 })) ?? 0;
35
- priceTargetToken =
36
- (priceToken1 * BN2Number(typeInfo.balanceToken1, Number(typeInfo.decimalsToken1))) /
37
- BN2Number(typeInfo.balanceToken0, Number(typeInfo.decimalsToken0));
27
+ const srtPrice = BigInt(typeInfo.sqrtPriceX96);
28
+ const price = Number(srtPrice) ** 2 / 2 ** 192;
29
+ const priceTargetToken = price * 10 ** 12;
38
30
  const tvl = priceTargetToken * totalSupply;
39
31
  return {
40
32
  ...typeInfo,
@@ -0,0 +1,58 @@
1
+ import { TokenService } from "@/modules/v4/token/token.service";
2
+ import { log } from "@/utils/logger";
3
+ import { apiDbClient } from "@db";
4
+ const tokens = await apiDbClient.token.findMany({
5
+ select: {
6
+ address: true,
7
+ chainId: true,
8
+ name: true,
9
+ symbol: true,
10
+ },
11
+ where: {
12
+ symbol: "UNKNOWN",
13
+ },
14
+ orderBy: {
15
+ id: "asc",
16
+ },
17
+ });
18
+ log.info(`found ${tokens.length} tokens with UNKNOWN symbol`);
19
+ for (const token of tokens) {
20
+ try {
21
+ const onchainData = await TokenService.fetchOnChain({
22
+ chainId: token.chainId,
23
+ address: token.address,
24
+ });
25
+ if (onchainData.name !== token.name) {
26
+ await apiDbClient.token.update({
27
+ where: {
28
+ chainId_address: {
29
+ address: token.address,
30
+ chainId: token.chainId,
31
+ },
32
+ },
33
+ data: {
34
+ name: onchainData.name,
35
+ },
36
+ });
37
+ log.info(`updated name for ${token.address} on ${token.chainId} from ${token.name} to ${onchainData.name}`);
38
+ }
39
+ if (onchainData.symbol !== token.symbol) {
40
+ await apiDbClient.token.update({
41
+ where: {
42
+ chainId_address: {
43
+ address: token.address,
44
+ chainId: token.chainId,
45
+ },
46
+ },
47
+ data: {
48
+ symbol: onchainData.symbol,
49
+ },
50
+ });
51
+ log.info(`updated name for ${token.address} on ${token.chainId} from ${token.name} to ${onchainData.name}`);
52
+ }
53
+ }
54
+ catch (e) {
55
+ console.error(e);
56
+ }
57
+ }
58
+ process.exit(0);
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ // One-off script to modify opportunity metadata
1
2
  import { metadataBuilderFactory } from "@/engine/opportunityMetadata/factory";
2
3
  import { log } from "@/utils/logger";
3
4
  import { apiDbClient } from "@db";
@@ -1,11 +1,13 @@
1
1
  import { tokenType } from "@/engine/erc20SubTypeProcessors/helpers/tokenType";
2
- import { AaveInterface, AccountantWithRateProvidersInterface, AuraInterface, AuraOperatorInterface, BalancerGaugeInterface, BalancerPoolInterface, BalancerV3StablePoolInterface, BalancerVaultInterface, BeefyInterface, BunniV2HubInterface, BunniV2TokenInterface, CPMMGammaPoolMainInterface, CompoundInterface, CurveInterface, CurveLPTokenInterface, CurveStableSwapNGInterface, DefutureVaultInterface, ERC20Interface, ERC4626Interface, EnzymeInterface, EulerInterface, FactoryInterface, FluidInterface, FraxlendInterface, GearboxVaultInterface, HourglassERC20TBTInterface, HourglassVedaLockDepositorV2Interface, IonicInterface, LPManagerHelperInterface, LPManagerInterface, LayerBankERC20Interface, LayerBankInterface, LendleInterface, MaverickBPLensInterface, MetamorphoInterface, MoonwellInterface, OneInchStakingInterface, PendleInterface, PendleYTInterface, RadiantInterface, RfxInterface, RswEthStrategyInterface, SpectraYTInterface, SturdyInterface, SymetricAmbientStrategyInterface, SyncSwapClassicPoolInterface, TorosInterface, UniswapV2PoolInterface, VePufferInterface, ZFStableLPINterface, ZFStableSwapThreePoolInterface, } from "@sdk";
2
+ import { AaveInterface, AccountantWithRateProvidersInterface, AuraInterface, AuraOperatorInterface, BalancerGaugeInterface, BalancerPoolInterface, BalancerV3StablePoolInterface, BalancerVaultInterface, BeefyInterface, BunniV2HubInterface, BunniV2TokenInterface, CPMMGammaPoolMainInterface, CompoundInterface, CurveInterface, CurveLPTokenInterface, CurveStableSwapNGInterface, DefutureVaultInterface, ERC20Interface, ERC4626Interface, EnzymeInterface, EulerInterface, FactoryInterface, FluidInterface, FraxlendInterface, GearboxVaultInterface, HourglassERC20TBTInterface, HourglassVedaLockDepositorV2Interface, IonicInterface, LPManagerHelperInterface, LPManagerInterface, LayerBankERC20Interface, LayerBankInterface, LendleInterface, MaverickBPLensInterface, MetamorphoInterface, MoonwellInterface, OneInchStakingInterface, PendleInterface, PendleYTInterface, RadiantInterface, RfxInterface, RswEthStrategyInterface, SpectraYTInterface, SturdyInterface, SymetricAmbientStrategyInterface, SyncSwapClassicPoolInterface, TorosInterface, UniswapV2PoolInterface, UniswapV3PoolInterface, VePufferInterface, ZFStableLPINterface, ZFStableSwapThreePoolInterface, } from "@sdk";
3
3
  export function decodeCall(calls, index, key, type) {
4
4
  const returnData = calls[index];
5
5
  return decodeReturnValue(returnData, key, type);
6
6
  }
7
7
  export function decodeReturnValue(returnData, key, type) {
8
8
  switch (key) {
9
+ case "sqrtPriceX96":
10
+ return UniswapV3PoolInterface.decodeFunctionResult("slot0", returnData)[0];
9
11
  case "tokens":
10
12
  return LPManagerInterface.decodeFunctionResult("tokens", returnData)[0];
11
13
  case "getTokensCount":
@@ -1,7 +1,9 @@
1
1
  import { tokenType } from "@/engine/erc20SubTypeProcessors/helpers/tokenType";
2
- import { AaveInterface, AccountantWithRateProvidersInterface, AuraInterface, AuraOperatorInterface, BalancerGaugeInterface, BalancerPoolInterface, BalancerV3StablePoolInterface, BalancerVaultInterface, BeefyInterface, BunniV2HubInterface, BunniV2TokenInterface, CPMMGammaPoolMainInterface, CompoundInterface, CurveInterface, CurveLPTokenInterface, CurveStableSwapNGInterface, DefutureVaultInterface, ERC20Interface, ERC4626Interface, EnzymeInterface, EulerInterface, FactoryInterface, FluidInterface, FraxlendInterface, GearboxVaultInterface, HourglassERC20TBTInterface, HourglassVedaLockDepositorV2Interface, IonicInterface, LPManagerHelperInterface, LPManagerInterface, LayerBankInterface, LendleInterface, MaverickBPLensInterface, MetamorphoInterface, MoonwellInterface, OneInchStakingInterface, PendleInterface, PendleYTInterface, RadiantInterface, RfxDatastoreInterface, RswEthStrategyInterface, SpectraYTInterface, SturdyInterface, SymetricAmbientStrategyInterface, SyncSwapClassicPoolInterface, TorosInterface, UniswapV2PoolInterface, VePufferInterface, ZFStableLPINterface, } from "@sdk";
2
+ import { AaveInterface, AccountantWithRateProvidersInterface, AuraInterface, AuraOperatorInterface, BalancerGaugeInterface, BalancerPoolInterface, BalancerV3StablePoolInterface, BalancerVaultInterface, BeefyInterface, BunniV2HubInterface, BunniV2TokenInterface, CPMMGammaPoolMainInterface, CompoundInterface, CurveInterface, CurveLPTokenInterface, CurveStableSwapNGInterface, DefutureVaultInterface, ERC20Interface, ERC4626Interface, EnzymeInterface, EulerInterface, FactoryInterface, FluidInterface, FraxlendInterface, GearboxVaultInterface, HourglassERC20TBTInterface, HourglassVedaLockDepositorV2Interface, IonicInterface, LPManagerHelperInterface, LPManagerInterface, LayerBankInterface, LendleInterface, MaverickBPLensInterface, MetamorphoInterface, MoonwellInterface, OneInchStakingInterface, PendleInterface, PendleYTInterface, RadiantInterface, RfxDatastoreInterface, RswEthStrategyInterface, SpectraYTInterface, SturdyInterface, SymetricAmbientStrategyInterface, SyncSwapClassicPoolInterface, TorosInterface, UniswapV2PoolInterface, UniswapV3PoolInterface, VePufferInterface, ZFStableLPINterface, } from "@sdk";
3
3
  export function createCall(target, key, type, metaData) {
4
4
  switch (key) {
5
+ case "sqrtPriceX96":
6
+ return { allowFailure: true, callData: UniswapV3PoolInterface.encodeFunctionData("slot0"), target };
5
7
  case "tokens":
6
8
  return { allowFailure: true, callData: LPManagerInterface.encodeFunctionData("tokens", [metaData]), target };
7
9
  case "getTokensCount":