@merkl/api 0.12.12 → 0.13.2

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.
Files changed (28) hide show
  1. package/dist/src/backgroundJobs/index.js +4 -2
  2. package/dist/src/backgroundJobs/jobs/priceUpdater.d.ts +1 -0
  3. package/dist/src/backgroundJobs/jobs/priceUpdater.js +9 -4
  4. package/dist/src/eden/index.d.ts +10 -0
  5. package/dist/src/index.d.ts +2 -0
  6. package/dist/src/jobs/etl/prices.js +3 -0
  7. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EqualizerGaugeProcessor.js +0 -3
  8. package/dist/src/libs/campaigns/utils/getUniswapV4Pools.js +1 -1
  9. package/dist/src/modules/v4/enso/enso.model.d.ts +11 -0
  10. package/dist/src/modules/v4/enso/enso.model.js +14 -0
  11. package/dist/src/modules/v4/enso/enso.service.d.ts +19 -1
  12. package/dist/src/modules/v4/enso/enso.service.js +67 -0
  13. package/dist/src/modules/v4/interaction/interaction.controller.d.ts +2 -0
  14. package/dist/src/modules/v4/interaction/interaction.model.d.ts +47 -1
  15. package/dist/src/modules/v4/interaction/interaction.service.d.ts +23 -8
  16. package/dist/src/modules/v4/interaction/interaction.service.js +32 -68
  17. package/dist/src/modules/v4/kyberzap/kyberzap.model.d.ts +39 -0
  18. package/dist/src/modules/v4/kyberzap/kyberzap.model.js +1 -1
  19. package/dist/src/modules/v4/kyberzap/kyberzap.service.d.ts +22 -3
  20. package/dist/src/modules/v4/kyberzap/kyberzap.service.js +95 -7
  21. package/dist/src/modules/v4/router.d.ts +2 -0
  22. package/dist/src/utils/pricer.d.ts +3 -1
  23. package/dist/src/utils/pricer.js +1 -0
  24. package/dist/src/utils/prices/priceService.js +0 -22
  25. package/dist/tsconfig.package.tsbuildinfo +1 -1
  26. package/package.json +2 -2
  27. package/dist/src/jobs/update-prices.js +0 -10
  28. /package/dist/src/jobs/{update-prices.d.ts → etl/prices.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- import { InteractionService } from "../interaction/interaction.service";
1
+ import { TokenService } from "../token";
2
2
  import { chainToKyberLabel, dexIdToProtocolId, } from "./kyberzap.model";
3
3
  const KYBERZAP = `https://zap-api.kyberswap.com/`;
4
4
  export class KyberZapService {
@@ -45,6 +45,69 @@ export class KyberZapService {
45
45
  static getFullRangeTicks() {
46
46
  return [-886800, 886800];
47
47
  }
48
+ /**
49
+ * Converts the breakdown of actions
50
+ * @param zapActions
51
+ * @returns provider-agnostic interaction actions
52
+ */
53
+ static async getActions(chainId, zapActions) {
54
+ const actions = [];
55
+ const processors = {
56
+ ACTION_TYPE_PROTOCOL_FEE: async ({ protocolFee: { tokens: zapTokens } }) => {
57
+ const tokens = await TokenService.getManyOrCreate(zapTokens.map(({ address }) => ({ address, chainId })));
58
+ return [
59
+ {
60
+ action: "fee",
61
+ tokens: tokens.filter(t => !!t).map((t, i) => ({ ...t, amount: BigInt(zapTokens[i].amount) })),
62
+ },
63
+ ];
64
+ },
65
+ ACTION_TYPE_AGGREGATOR_SWAP: async ({ aggregatorSwap: { swaps } }) => {
66
+ const swapActions = [];
67
+ for (const { tokenIn, tokenOut } of swaps) {
68
+ const [from, to] = await TokenService.getManyOrCreate([
69
+ { address: tokenIn.address, chainId },
70
+ { address: tokenOut.address, chainId },
71
+ ]);
72
+ swapActions.push({
73
+ action: "swap",
74
+ from: { ...from, amount: BigInt(tokenIn.amount) },
75
+ to: { ...to, amount: BigInt(tokenOut.amount) },
76
+ });
77
+ }
78
+ return swapActions;
79
+ },
80
+ ACTION_TYPE_POOL_SWAP: async ({ poolSwap: { swaps } }) => {
81
+ const swapActions = [];
82
+ for (const { tokenIn, tokenOut } of swaps) {
83
+ const [from, to] = await TokenService.getManyOrCreate([
84
+ { address: tokenIn.address, chainId },
85
+ { address: tokenOut.address, chainId },
86
+ ]);
87
+ swapActions.push({
88
+ action: "swap",
89
+ from: { ...from, amount: BigInt(tokenIn.amount) },
90
+ to: { ...to, amount: BigInt(tokenOut.amount) },
91
+ });
92
+ }
93
+ return swapActions;
94
+ },
95
+ ACTION_TYPE_ADD_LIQUIDITY: async ({ addLiquidity: { tokens: zapTokens } }) => {
96
+ const tokens = await TokenService.getManyOrCreate(zapTokens.map(({ address }) => ({ address, chainId })));
97
+ return [
98
+ {
99
+ action: "deposit",
100
+ tokens: tokens.filter(t => !!t).map((t, i) => ({ ...t, amount: BigInt(zapTokens[i].amount) })),
101
+ },
102
+ ];
103
+ },
104
+ };
105
+ for (const { type, ...zapAction } of zapActions) {
106
+ const action = await processors[type](zapAction);
107
+ actions.push(...action);
108
+ }
109
+ return actions;
110
+ }
48
111
  static async getTransaction(chainId, protocol, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage) {
49
112
  const [lower, upper] = KyberZapService.getFullRangeTicks();
50
113
  const { data: route } = await KyberZapService.#fetch("/api/v1/in/route", {
@@ -60,6 +123,11 @@ export class KyberZapService {
60
123
  },
61
124
  chainId,
62
125
  });
126
+ const actions = await KyberZapService.getActions(chainId, route.zapDetails.actions);
127
+ const [tokenIn] = await TokenService.getManyOrCreate([{ address: fromTokenAddress, chainId }]);
128
+ const deposit = actions.findLast(({ action }) => action === "deposit");
129
+ const tokenInValue = await TokenService.getValue([{ ...tokenIn, amount: fromTokenAmount }]);
130
+ const depositValue = await TokenService.getValue(deposit.tokens);
63
131
  const { data: transaction } = await KyberZapService.#post("/api/v1/in/route/build", {
64
132
  query: {},
65
133
  body: {
@@ -72,16 +140,36 @@ export class KyberZapService {
72
140
  },
73
141
  chainId,
74
142
  });
75
- const { allowance, approval, approved } = await InteractionService.getApproval(chainId, userAddress, route.routerAddress, fromTokenAddress, fromTokenAmount);
76
143
  return {
77
- allowance,
78
- approval,
79
- approved,
80
- amountIn: fromTokenAmount,
144
+ actions,
145
+ depositValue,
81
146
  transaction: {
82
147
  to: transaction.routerAddress,
83
148
  data: transaction.callData,
84
- value: !!transaction.value && BigInt(transaction.value),
149
+ value: transaction.value,
150
+ },
151
+ };
152
+ }
153
+ /**
154
+ * Defines abstract router functions
155
+ * @returns Router
156
+ */
157
+ static getRouter() {
158
+ return {
159
+ name: "zap",
160
+ async getTarget(chainId, protocolId, identifier) {
161
+ const dexId = KyberZapService.getDexId(protocolId);
162
+ const chainLabel = KyberZapService.getChainLabel(chainId);
163
+ if (!dexId || !chainLabel)
164
+ return;
165
+ return {
166
+ provider: "zap",
167
+ chainId: chainId,
168
+ identifier: identifier,
169
+ };
170
+ },
171
+ async getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, options) {
172
+ return await KyberZapService.getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, options.slippage);
85
173
  },
86
174
  };
87
175
  }
@@ -2727,6 +2727,8 @@ export declare const v4: Elysia<"/v4", false, {
2727
2727
  approved: boolean;
2728
2728
  transaction: import("./interaction/interaction.model").UserTransaction;
2729
2729
  approval: import("./interaction/interaction.model").UserTransaction;
2730
+ actions?: import("./interaction/interaction.model").InteractionAction[] | undefined;
2731
+ depositValue?: number | undefined;
2730
2732
  } | undefined;
2731
2733
  };
2732
2734
  };
@@ -48,5 +48,7 @@ export declare class Pricer {
48
48
  /** Saves the current price data in the cache */
49
49
  save(): Promise<void>;
50
50
  /** Recomputes all prices and saves them in the cache */
51
- update(): Promise<void>;
51
+ update(): Promise<{
52
+ [token: string]: number;
53
+ }>;
52
54
  }
@@ -176,5 +176,6 @@ export class Pricer {
176
176
  }
177
177
  } // Update extraPricesData
178
178
  await this.save();
179
+ return this.prices;
179
180
  }
180
181
  }
@@ -76,16 +76,6 @@ export default class PriceService {
76
76
  this._prices["0x3Df8AAC90Eb2FeeA4378368D46a72AF47eBDc268"] = uni_WETH_YIELD;
77
77
  }
78
78
  }));
79
- promises.push((async () => {
80
- try {
81
- const d = await new Contract("0x3a29cab2e124919d14a6f735b6033a3aad2b260f", ["function discount() external view returns(uint256)"], providers[ChainId.POLYGON]).discount();
82
- this._prices["oRETRO"] = this._prices["RETRO"] * (1 - Number.parseInt(d.toString()) / 100);
83
- }
84
- catch (e) {
85
- log.error(`❌ error fetching oRetro discount:`, e);
86
- this._prices["oRETRO"] = this._prices["RETRO"] * 0.6;
87
- }
88
- })());
89
79
  this.setConstantPrices(tokenPriceSources);
90
80
  this.setEqualsToPrices(tokenPriceSources);
91
81
  /** Hardcoded prices */
@@ -251,18 +241,6 @@ export default class PriceService {
251
241
  catch (error) {
252
242
  log.error("❌ call to fetch blueprint api price failed", error);
253
243
  }
254
- promises.push((async () => {
255
- try {
256
- const d = await new Contract("0xEdb73D4ED90bE7A49D06d0D940055e6d181d22fa", ["function discount() external view returns(uint256)"], providers[ChainId.MAINNET]).discount();
257
- this._prices["oBLUE"] = this._prices["BLUE"] * (1 - Number.parseInt(d.toString()) / 100);
258
- }
259
- catch (e) {
260
- log.error("❌ error fetching oBLUE discount:", e);
261
- this._prices["oBLUE"] = this._prices["BLUE"] * 0.6;
262
- }
263
- })());
264
- this._prices["bveBLUE"] = this._prices["oBLUE"] * 0.85;
265
- this._prices["BVEBLUE"] = this._prices["bveBLUE"];
266
244
  /** Flux price completion */
267
245
  promises.push((async () => {
268
246
  try {