@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
@@ -29,10 +29,12 @@ new Elysia({
29
29
  .use(healthCheck) // /v3/health
30
30
  .use(sync) // GET /jobs/api/sync-with-engine
31
31
  .get("/eulerUpdate", async () => {
32
- await Redis.safeSet("EulerV2Vaults", getEulerV2Vaults);
32
+ log.info("🔃 updating Euler vaults...");
33
+ await Redis.safeSet("EulerV2Vaults", await getEulerV2Vaults());
33
34
  })
34
35
  .get("/uniswapv4Update", async () => {
35
- await Redis.safeSet("UniswapV4Pools", getUniswapV4Pools);
36
+ log.info("🔃 updating UniswapV4 pools...");
37
+ await Redis.safeSet("UniswapV4Pools", await getUniswapV4Pools());
36
38
  })
37
39
  .group("/v4", app => {
38
40
  return app.use(DungeonKeeperController);
@@ -1,4 +1,5 @@
1
1
  import type Elysia from "elysia";
2
+ export declare const updatePrices: () => Promise<void>;
2
3
  export declare const priceUpdater: (app: Elysia) => Elysia<"", false, {
3
4
  decorator: {};
4
5
  store: {};
@@ -1,12 +1,17 @@
1
1
  import { TokenService } from "../../modules/v4";
2
2
  import { log } from "../../utils/logger";
3
3
  import { Pricer } from "../../utils/pricer";
4
+ export const updatePrices = async () => {
5
+ const pricer = await Pricer.load();
6
+ const prices = await pricer.update();
7
+ log.info(`✅ ${Object.keys(prices).length} prices cache updated successfully`);
8
+ log.info("⏳ Updating API database...");
9
+ await TokenService.updatePrices(pricer);
10
+ log.info("✅ API database updated successfully!");
11
+ };
4
12
  export const priceUpdater = (app) => {
5
13
  return app.get("/v3/updatePrices", async () => {
6
- const pricer = await Pricer.load();
7
- await pricer.update();
8
- log.info("✅ price cache updated successfully");
9
- await TokenService.updatePrices(pricer);
14
+ await updatePrices();
10
15
  return new Response(JSON.stringify({
11
16
  status: "success",
12
17
  }), {
@@ -2328,6 +2328,8 @@ declare const eden: {
2328
2328
  approved: boolean;
2329
2329
  transaction: import("../modules/v4/interaction/interaction.model").UserTransaction;
2330
2330
  approval: import("../modules/v4/interaction/interaction.model").UserTransaction;
2331
+ actions?: import("../modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
2332
+ depositValue?: number | undefined;
2331
2333
  } | undefined;
2332
2334
  }>>;
2333
2335
  };
@@ -5329,6 +5331,8 @@ declare const eden: {
5329
5331
  approved: boolean;
5330
5332
  transaction: import("../modules/v4/interaction/interaction.model").UserTransaction;
5331
5333
  approval: import("../modules/v4/interaction/interaction.model").UserTransaction;
5334
+ actions?: import("../modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
5335
+ depositValue?: number | undefined;
5332
5336
  } | undefined;
5333
5337
  }>>;
5334
5338
  };
@@ -9548,6 +9552,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
9548
9552
  approved: boolean;
9549
9553
  transaction: import("../modules/v4/interaction/interaction.model").UserTransaction;
9550
9554
  approval: import("../modules/v4/interaction/interaction.model").UserTransaction;
9555
+ actions?: import("../modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
9556
+ depositValue?: number | undefined;
9551
9557
  } | undefined;
9552
9558
  };
9553
9559
  };
@@ -13635,6 +13641,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
13635
13641
  approved: boolean;
13636
13642
  transaction: import("../modules/v4/interaction/interaction.model").UserTransaction;
13637
13643
  approval: import("../modules/v4/interaction/interaction.model").UserTransaction;
13644
+ actions?: import("../modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
13645
+ depositValue?: number | undefined;
13638
13646
  } | undefined;
13639
13647
  }>>;
13640
13648
  };
@@ -16636,6 +16644,8 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
16636
16644
  approved: boolean;
16637
16645
  transaction: import("../modules/v4/interaction/interaction.model").UserTransaction;
16638
16646
  approval: import("../modules/v4/interaction/interaction.model").UserTransaction;
16647
+ actions?: import("../modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
16648
+ depositValue?: number | undefined;
16639
16649
  } | undefined;
16640
16650
  }>>;
16641
16651
  };
@@ -2857,6 +2857,8 @@ declare const app: Elysia<"", false, {
2857
2857
  approved: boolean;
2858
2858
  transaction: import("./modules/v4/interaction/interaction.model").UserTransaction;
2859
2859
  approval: import("./modules/v4/interaction/interaction.model").UserTransaction;
2860
+ actions?: import("./modules/v4/interaction/interaction.model").InteractionAction[] | undefined;
2861
+ depositValue?: number | undefined;
2860
2862
  } | undefined;
2861
2863
  };
2862
2864
  };
@@ -0,0 +1,3 @@
1
+ import { updatePrices } from "../../backgroundJobs/jobs/priceUpdater";
2
+ await updatePrices();
3
+ process.exit(0);
@@ -38,9 +38,6 @@ export class EqualizerGaugeProcessor extends GenericProcessor {
38
38
  }
39
39
  }
40
40
  catch (e) { }
41
- try {
42
- }
43
- catch (e) { }
44
41
  const priceTargetToken = tvl / totalSupply;
45
42
  //const displayName = `Stake into ${data[typeInfo.tokenAddress].pair.displayName} Equalizer Gauge`;
46
43
  return {
@@ -20,7 +20,7 @@ export async function getUniswapV4Pools() {
20
20
  try {
21
21
  // 1_ Get latest euler vaults from chain
22
22
  const storedPoolsPerChain = storedPools.filter(pool => pool.chainId === chainId);
23
- log.info(`found ${storedPoolsPerChain.length} already stored vaults on ${NETWORK_LABELS[chainId]}`);
23
+ log.info(`found ${storedPoolsPerChain.length} already stored pools on ${NETWORK_LABELS[chainId]}`);
24
24
  let fromBlock;
25
25
  if (storedPoolsPerChain.length > 0) {
26
26
  fromBlock = Math.max(...storedPools.map(x => x.fetchAtBlock)) + 1;
@@ -142,6 +142,17 @@ export declare const apiTypes: {
142
142
  priceImpact: import("@sinclair/typebox").TNumber;
143
143
  feeAmount: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
144
144
  createAt: import("@sinclair/typebox").TNumber;
145
+ route: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
146
+ action: import("@sinclair/typebox").TLiteral<"swap">;
147
+ protocol: import("@sinclair/typebox").TString;
148
+ tokenIn: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
149
+ tokenOut: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
150
+ }>, import("@sinclair/typebox").TObject<{
151
+ action: import("@sinclair/typebox").TLiteral<"deposit">;
152
+ primary: import("@sinclair/typebox").TString;
153
+ tokenIn: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
154
+ tokenOut: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
155
+ }>]>>;
145
156
  tx: import("@sinclair/typebox").TObject<{
146
157
  data: import("@sinclair/typebox").TString;
147
158
  to: import("@sinclair/typebox").TString;
@@ -122,6 +122,20 @@ export const apiTypes = {
122
122
  priceImpact: t.Number(),
123
123
  feeAmount: t.Array(t.String()),
124
124
  createAt: t.Number(),
125
+ route: t.Array(t.Union([
126
+ t.Object({
127
+ action: t.Literal("swap"),
128
+ protocol: t.String(),
129
+ tokenIn: t.Array(t.String()),
130
+ tokenOut: t.Array(t.String()),
131
+ }),
132
+ t.Object({
133
+ action: t.Literal("deposit"),
134
+ primary: t.String(),
135
+ tokenIn: t.Array(t.String()),
136
+ tokenOut: t.Array(t.String()),
137
+ }),
138
+ ])),
125
139
  tx: t.Object({
126
140
  data: t.String(),
127
141
  to: t.String(),
@@ -1,4 +1,4 @@
1
- import type { GetParticipateProtocolsQuery } from "../interaction/interaction.model";
1
+ import type { GetParticipateProtocolsQuery, InteractionAction, InteractionTarget, Router } from "../interaction/interaction.model";
2
2
  import { type ProtocolId } from "../protocol";
3
3
  import { type EnsoApi, type EnsoSlug } from "./enso.model";
4
4
  export declare abstract class EnsoService {
@@ -32,6 +32,17 @@ export declare abstract class EnsoService {
32
32
  priceImpact: number;
33
33
  }>;
34
34
  static getTransaction(query: EnsoApi<"/v1/shortcuts/route">["query"]["static"]): Promise<{
35
+ route: ({
36
+ protocol: string;
37
+ action: "swap";
38
+ tokenIn: string[];
39
+ tokenOut: string[];
40
+ } | {
41
+ action: "deposit";
42
+ primary: string;
43
+ tokenIn: string[];
44
+ tokenOut: string[];
45
+ })[];
35
46
  amountOut: string;
36
47
  gas: string;
37
48
  feeAmount: string[];
@@ -44,4 +55,11 @@ export declare abstract class EnsoService {
44
55
  to: string;
45
56
  };
46
57
  }>;
58
+ static getActions(chainId: number, route: EnsoApi<"/v1/shortcuts/route">["response"]["static"]["route"], amountOut: bigint): Promise<InteractionAction[]>;
59
+ static getTargetsFromTokens(tokens: Awaited<ReturnType<typeof EnsoService.getTokens>>): Promise<InteractionTarget[]>;
60
+ /**
61
+ * Defines abstract router functions
62
+ * @returns Router
63
+ */
64
+ static getRouter(): Router;
47
65
  }
@@ -1,4 +1,5 @@
1
1
  import { ProtocolService } from "../protocol";
2
+ import { TokenService } from "../token";
2
3
  import { slugToProtocolId } from "./enso.model";
3
4
  const ENSO = `https://api.enso.finance/api`;
4
5
  export class EnsoService {
@@ -43,4 +44,70 @@ export class EnsoService {
43
44
  static async getTransaction(query) {
44
45
  return await EnsoService.#fetch("/v1/shortcuts/route", { query });
45
46
  }
47
+ static async getActions(chainId, route, amountOut) {
48
+ return await Promise.all(route.map(async (r) => {
49
+ switch (r.action) {
50
+ case "deposit": {
51
+ const tokensIn = await TokenService.getManyOrCreate(r.tokenIn.map(t => ({ address: t, chainId })));
52
+ const [tokenOut] = await TokenService.getManyOrCreate(r.tokenOut.map(t => ({ address: t, chainId })));
53
+ return {
54
+ action: "deposit",
55
+ tokens: tokensIn.filter(a => !!a),
56
+ tokensOut: [{ ...tokenOut, amount: amountOut }],
57
+ };
58
+ }
59
+ case "swap": {
60
+ const [from] = await TokenService.getManyOrCreate(r.tokenIn.map(t => ({ address: t, chainId })));
61
+ const [to] = await TokenService.getManyOrCreate(r.tokenOut.map(t => ({ address: t, chainId })));
62
+ return { action: "swap", from: from, to: to };
63
+ }
64
+ }
65
+ }));
66
+ }
67
+ static async getTargetsFromTokens(tokens) {
68
+ const targets = [];
69
+ for (const { address, underlyingTokens, ...target } of tokens) {
70
+ try {
71
+ targets.push({
72
+ provider: "enso",
73
+ chainId: target.chainId,
74
+ identifier: address,
75
+ });
76
+ }
77
+ catch { }
78
+ }
79
+ return targets;
80
+ }
81
+ /**
82
+ * Defines abstract router functions
83
+ * @returns Router
84
+ */
85
+ static getRouter() {
86
+ return {
87
+ name: "enso",
88
+ async getTarget(chainId, protocolId, identifier) {
89
+ const slug = EnsoService.getSlug(protocolId);
90
+ if (!slug)
91
+ return;
92
+ const tokens = await EnsoService.getTokens(chainId, slug, identifier);
93
+ const targets = await EnsoService.getTargetsFromTokens(tokens);
94
+ return targets?.[0];
95
+ },
96
+ async getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, options) {
97
+ const { tx, ...quote } = await EnsoService.getTransaction({
98
+ fromAddress: userAddress,
99
+ tokenIn: [fromTokenAddress],
100
+ tokenOut: [identifier],
101
+ routingStrategy: "router",
102
+ chainId,
103
+ amountIn: [fromTokenAmount.toString()],
104
+ slippage: options.slippage?.toString(),
105
+ });
106
+ const [LpToken] = await TokenService.getManyOrCreate([{ address: identifier, chainId }]);
107
+ const depositValue = await TokenService.getValue([{ ...LpToken, amount: BigInt(quote.amountOut) }]);
108
+ const actions = await EnsoService.getActions(chainId, quote.route, BigInt(quote.amountOut));
109
+ return { transaction: tx, depositValue: depositValue, actions };
110
+ },
111
+ };
112
+ }
46
113
  }
@@ -75,6 +75,8 @@ export declare const InteractionController: Elysia<"/interaction", false, {
75
75
  approved: boolean;
76
76
  transaction: import("./interaction.model").UserTransaction;
77
77
  approval: import("./interaction.model").UserTransaction;
78
+ actions?: import("./interaction.model").InteractionAction[] | undefined;
79
+ depositValue?: number | undefined;
78
80
  } | undefined;
79
81
  };
80
82
  };
@@ -1,3 +1,15 @@
1
+ import type { ProtocolId } from "../protocol";
2
+ import type { Token } from "../token";
3
+ /**
4
+ * Interaction Route
5
+ */
6
+ export interface Router {
7
+ name: string;
8
+ getTarget: (chainId: number, protocolId: ProtocolId, identifier: string) => Promise<InteractionTarget | undefined>;
9
+ getTransaction: (chainId: number, protocolId: ProtocolId, identifier: string, userAddress: string, fromTokenAddress: string, fromTokenAmount: bigint, options: {
10
+ slippage?: number;
11
+ }) => Promise<Pick<InteractionQuote, "actions" | "transaction" | "depositValue">>;
12
+ }
1
13
  export declare const participateInputTypes: readonly ["tokenAmount", "token"];
2
14
  export type InteractionInputType = (typeof participateInputTypes)[number];
3
15
  export type InteractionInput<T extends InteractionInputType = InteractionInputType> = {
@@ -35,7 +47,7 @@ export type UserTransaction = {
35
47
  data: string;
36
48
  to: string;
37
49
  from?: string;
38
- value?: bigint;
50
+ value?: string;
39
51
  };
40
52
  export type InteractionQuote = {
41
53
  amountIn: bigint;
@@ -43,7 +55,41 @@ export type InteractionQuote = {
43
55
  approved: boolean;
44
56
  transaction: UserTransaction;
45
57
  approval: UserTransaction;
58
+ actions?: InteractionAction[];
59
+ depositValue?: number;
46
60
  };
61
+ export type InteractionActions = {
62
+ /**
63
+ * Fee taken by the router and/or Merkl
64
+ */
65
+ fee: {
66
+ tokens: (Token["model"] & {
67
+ amount?: bigint;
68
+ })[];
69
+ };
70
+ /**
71
+ * Amount deposited
72
+ */
73
+ deposit: {
74
+ tokens: (Token["model"] & {
75
+ amount?: bigint;
76
+ })[];
77
+ tokensOut?: (Token["model"] & {
78
+ amount?: bigint;
79
+ })[];
80
+ };
81
+ swap: {
82
+ from: Token["model"] & {
83
+ amount?: bigint;
84
+ };
85
+ to: Token["model"] & {
86
+ amount?: bigint;
87
+ };
88
+ };
89
+ };
90
+ export type InteractionAction<Action extends keyof InteractionActions = keyof InteractionActions> = {
91
+ action: Action;
92
+ } & InteractionActions[Action];
47
93
  export declare const GetInteractionTargetsQueryDto: import("@sinclair/typebox").TObject<{
48
94
  chainId: import("@sinclair/typebox").TNumber;
49
95
  protocolId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
@@ -1,12 +1,28 @@
1
- import { EnsoService } from "../enso/enso.service";
2
1
  import type { ProtocolId } from "../protocol";
3
- import type { InteractionQuote, InteractionTarget } from "./interaction.model";
2
+ import type { InteractionQuote } from "./interaction.model";
4
3
  export declare abstract class InteractionService {
5
- static getTarget(chainId: number, protocolId: ProtocolId, identifier: string): Promise<InteractionTarget[]>;
6
- static getTargetFromKyberZap(chainId: number, protocolId: ProtocolId, identifier: string): InteractionTarget | undefined;
7
- static getTargetFromEnso(chainId: number, protocolId: ProtocolId, identifier: string): Promise<InteractionTarget | undefined>;
8
- static getTargetsFromEnsoTokens(tokens: Awaited<ReturnType<typeof EnsoService.getTokens>>): Promise<InteractionTarget[]>;
9
- static getTargets(chainId: number, protocolId: ProtocolId, identifier: string): Promise<InteractionTarget[]>;
4
+ static routers: import("./interaction.model").Router[];
5
+ /**
6
+ * Returns a target entry for each router, indicating the possiblity to deposit
7
+ * @param chainId compute
8
+ * @param protocolId i.e. "aave", "venus"
9
+ * @param identifier i.e. mainParameter, poolAddress
10
+ * @returns information about available routers
11
+ */
12
+ static getTargets(chainId: number, protocolId: ProtocolId, identifier: string): Promise<import("./interaction.model").InteractionTarget[]>;
13
+ /**
14
+ * Gets transaction to interact on opportunity via a router
15
+ * @param provider i.e. "enso" or "zap"
16
+ * @param chainId compute
17
+ * @param protocolId i.e. "aave", "venus"
18
+ * @param identifier i.e. mainParameter, poolAddress
19
+ * @param userAddress
20
+ * @param fromTokenAddress
21
+ * @param fromTokenAmount
22
+ * @param slippage
23
+ * @returns transaction and approval state
24
+ */
25
+ static getTransaction(provider: string, chainId: number, protocolId: ProtocolId, identifier: string, userAddress: string, fromTokenAddress: string, fromTokenAmount: bigint, slippage?: number): Promise<InteractionQuote>;
10
26
  /**
11
27
  * Gets approval information onchain
12
28
  * @returns approved?, approval tx & allowance amount
@@ -19,5 +35,4 @@ export declare abstract class InteractionService {
19
35
  data: `0x${string}`;
20
36
  };
21
37
  }>;
22
- static getTransaction(provider: InteractionTarget["provider"], chainId: number, protocolId: ProtocolId, identifier: string, userAddress: string, fromTokenAddress: string, fromTokenAmount: bigint, slippage?: number): Promise<InteractionQuote>;
23
38
  }
@@ -1,60 +1,41 @@
1
1
  import { ETH_ADDRESS, ETH_ZKSYNC_ADDRESS } from "@sdk";
2
2
  import { decodeFunctionResult, encodeFunctionData, parseAbi } from "viem";
3
3
  import { ChainInteractionService } from "../chainInteraction";
4
- import { EnsoService } from "../enso/enso.service";
5
4
  import { KyberZapService } from "../kyberzap/kyberzap.service";
6
5
  export class InteractionService {
7
- static async getTarget(chainId, protocolId, identifier) {
8
- const targets = [];
9
- const slug = EnsoService.getSlug(protocolId);
10
- if (slug) {
11
- const tokens = await EnsoService.getTokens(chainId, slug, identifier);
12
- const ensoTargets = await InteractionService.getTargetsFromEnsoTokens(tokens);
13
- targets.push(ensoTargets?.[0]);
14
- }
15
- return targets;
16
- }
17
- static getTargetFromKyberZap(chainId, protocolId, identifier) {
18
- const dexId = KyberZapService.getDexId(protocolId);
19
- const chainLabel = KyberZapService.getChainLabel(chainId);
20
- if (!dexId || !chainLabel)
21
- return;
22
- return {
23
- provider: "zap",
24
- chainId: chainId,
25
- identifier: identifier,
26
- };
27
- }
28
- static async getTargetFromEnso(chainId, protocolId, identifier) {
29
- const slug = EnsoService.getSlug(protocolId);
30
- if (!slug)
31
- return;
32
- const tokens = await EnsoService.getTokens(chainId, slug, identifier);
33
- const ensoTargets = await InteractionService.getTargetsFromEnsoTokens(tokens);
34
- return ensoTargets?.[0];
35
- }
36
- static async getTargetsFromEnsoTokens(tokens) {
37
- const targets = [];
38
- for (const { address, underlyingTokens, ...target } of tokens) {
39
- try {
40
- targets.push({
41
- provider: "enso",
42
- chainId: target.chainId,
43
- identifier: address,
44
- });
45
- }
46
- catch { }
47
- }
48
- return targets;
49
- }
6
+ static routers = [KyberZapService].map(service => service.getRouter());
7
+ /**
8
+ * Returns a target entry for each router, indicating the possiblity to deposit
9
+ * @param chainId compute
10
+ * @param protocolId i.e. "aave", "venus"
11
+ * @param identifier i.e. mainParameter, poolAddress
12
+ * @returns information about available routers
13
+ */
50
14
  static async getTargets(chainId, protocolId, identifier) {
51
- const targets = [];
52
- // const ensoTarget = await InteractionService.getTargetFromEnso(chainId, protocolId, identifier);
53
- const zapTarget = InteractionService.getTargetFromKyberZap(chainId, protocolId, identifier);
54
- if (zapTarget)
55
- targets.push(zapTarget);
56
- // if (ensoTarget) targets.push(ensoTarget);
57
- return targets;
15
+ return (await Promise.all(InteractionService.routers?.map(router => router.getTarget(chainId, protocolId, identifier)))).filter(a => a !== undefined);
16
+ }
17
+ /**
18
+ * Gets transaction to interact on opportunity via a router
19
+ * @param provider i.e. "enso" or "zap"
20
+ * @param chainId compute
21
+ * @param protocolId i.e. "aave", "venus"
22
+ * @param identifier i.e. mainParameter, poolAddress
23
+ * @param userAddress
24
+ * @param fromTokenAddress
25
+ * @param fromTokenAmount
26
+ * @param slippage
27
+ * @returns transaction and approval state
28
+ */
29
+ static async getTransaction(provider, chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage) {
30
+ const router = InteractionService.routers.find(({ name }) => name === provider);
31
+ if (!router)
32
+ throw new Error(`Router "${provider} not found`);
33
+ // Normalizing ETH on ZKSync
34
+ if (fromTokenAddress === ETH_ZKSYNC_ADDRESS)
35
+ fromTokenAddress = ETH_ADDRESS;
36
+ const transaction = await router.getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, { slippage });
37
+ const { allowance, approval, approved } = await InteractionService.getApproval(chainId, userAddress, transaction.transaction.to, fromTokenAddress, fromTokenAmount);
38
+ return { amountIn: fromTokenAmount, ...transaction, allowance, approval, approved };
58
39
  }
59
40
  /**
60
41
  * Gets approval information onchain
@@ -110,21 +91,4 @@ export class InteractionService {
110
91
  },
111
92
  };
112
93
  }
113
- static async getTransaction(provider, chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage) {
114
- // Normalizing ETH on ZKSync
115
- if (fromTokenAddress === ETH_ZKSYNC_ADDRESS)
116
- fromTokenAddress = ETH_ADDRESS;
117
- if (provider === "zap")
118
- return await KyberZapService.getTransaction(chainId, protocolId, identifier, userAddress, fromTokenAddress, fromTokenAmount, slippage);
119
- const { tx, ...quote } = await EnsoService.getTransaction({
120
- fromAddress: userAddress,
121
- tokenIn: [fromTokenAddress],
122
- tokenOut: [identifier],
123
- amountIn: [fromTokenAmount.toString()],
124
- routingStrategy: "router",
125
- chainId,
126
- });
127
- const { allowance, approval, approved } = await InteractionService.getApproval(chainId, userAddress, tx.to, fromTokenAddress, fromTokenAmount);
128
- return { ...quote, allowance, approval, approved, transaction: tx };
129
- }
130
94
  }
@@ -68,6 +68,45 @@ export declare const apiTypes: {
68
68
  }>;
69
69
  };
70
70
  };
71
+ export type ZapToken = {
72
+ address: string;
73
+ amount: string;
74
+ amountUsd: string;
75
+ };
76
+ export type ZapActions = {
77
+ ACTION_TYPE_PROTOCOL_FEE: {
78
+ protocolFee: {
79
+ pcm: number;
80
+ tokens: ZapToken[];
81
+ };
82
+ };
83
+ ACTION_TYPE_AGGREGATOR_SWAP: {
84
+ aggregatorSwap: {
85
+ swaps: {
86
+ tokenIn: ZapToken;
87
+ tokenOut: ZapToken;
88
+ }[];
89
+ };
90
+ };
91
+ ACTION_TYPE_POOL_SWAP: {
92
+ poolSwap: {
93
+ swaps: {
94
+ tokenIn: ZapToken;
95
+ tokenOut: ZapToken;
96
+ }[];
97
+ };
98
+ };
99
+ ACTION_TYPE_ADD_LIQUIDITY: {
100
+ addLiquidity: {
101
+ tokens: ZapToken[];
102
+ token0: ZapToken;
103
+ token1: ZapToken;
104
+ };
105
+ };
106
+ };
107
+ export type ZapAction<Action extends keyof ZapActions = keyof ZapActions> = {
108
+ type: Action;
109
+ } & ZapActions[Action];
71
110
  export type KyberZapRoute = keyof typeof apiTypes;
72
111
  export type KyberZapPostRoute = {
73
112
  [R in KyberZapRoute]: "body" extends keyof KyberZapApi<R> ? R : never;
@@ -51,7 +51,7 @@ export const apiTypes = {
51
51
  poolDetails: t.Object({}),
52
52
  positionDetails: t.Object({}),
53
53
  zapDetails: t.Object({
54
- actions: t.Array(t.Object({})),
54
+ actions: t.Array(t.Object({}, { description: "ZapActions" })),
55
55
  finalAmountUsd: t.String(),
56
56
  priceImpact: t.Number(),
57
57
  }),
@@ -1,6 +1,6 @@
1
- import type { InteractionQuote } from "../interaction/interaction.model";
1
+ import type { InteractionAction, Router } from "../interaction/interaction.model";
2
2
  import type { ProtocolId } from "../protocol";
3
- import { type KyberZapDexId } from "./kyberzap.model";
3
+ import { type KyberZapDexId, type ZapAction } from "./kyberzap.model";
4
4
  export declare abstract class KyberZapService {
5
5
  #private;
6
6
  static getDexId(protocolId: ProtocolId | string): KyberZapDexId | undefined;
@@ -11,5 +11,24 @@ export declare abstract class KyberZapService {
11
11
  * @param param0
12
12
  */
13
13
  static getFullRangeTicks(): number[];
14
- static getTransaction(chainId: number, protocol: ProtocolId, identifier: string, userAddress: string, fromTokenAddress: string, fromTokenAmount: bigint, slippage?: number): Promise<InteractionQuote>;
14
+ /**
15
+ * Converts the breakdown of actions
16
+ * @param zapActions
17
+ * @returns provider-agnostic interaction actions
18
+ */
19
+ static getActions(chainId: number, zapActions: ZapAction[]): Promise<InteractionAction[]>;
20
+ static getTransaction(chainId: number, protocol: ProtocolId, identifier: string, userAddress: string, fromTokenAddress: string, fromTokenAmount: bigint, slippage?: number): Promise<{
21
+ actions: InteractionAction[];
22
+ depositValue: number;
23
+ transaction: {
24
+ to: string;
25
+ data: string;
26
+ value: string;
27
+ };
28
+ }>;
29
+ /**
30
+ * Defines abstract router functions
31
+ * @returns Router
32
+ */
33
+ static getRouter(): Router;
15
34
  }