@merkl/api 0.12.11 → 0.13.1
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/priceUpdater.d.ts +1 -0
- package/dist/src/backgroundJobs/jobs/priceUpdater.js +9 -4
- package/dist/src/eden/index.d.ts +10 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/jobs/etl/prices.js +3 -0
- package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EqualizerGaugeProcessor.js +21 -2
- package/dist/src/modules/v4/enso/enso.model.d.ts +11 -0
- package/dist/src/modules/v4/enso/enso.model.js +14 -0
- package/dist/src/modules/v4/enso/enso.service.d.ts +19 -1
- package/dist/src/modules/v4/enso/enso.service.js +67 -0
- package/dist/src/modules/v4/interaction/interaction.controller.d.ts +2 -0
- package/dist/src/modules/v4/interaction/interaction.model.d.ts +47 -1
- package/dist/src/modules/v4/interaction/interaction.service.d.ts +23 -8
- package/dist/src/modules/v4/interaction/interaction.service.js +32 -68
- package/dist/src/modules/v4/kyberzap/kyberzap.model.d.ts +39 -0
- package/dist/src/modules/v4/kyberzap/kyberzap.model.js +1 -1
- package/dist/src/modules/v4/kyberzap/kyberzap.service.d.ts +22 -3
- package/dist/src/modules/v4/kyberzap/kyberzap.service.js +95 -7
- package/dist/src/modules/v4/router.d.ts +2 -0
- package/dist/src/utils/pricer.d.ts +3 -1
- package/dist/src/utils/pricer.js +1 -0
- package/dist/src/utils/prices/priceService.js +0 -22
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/jobs/update-prices.js +0 -10
- /package/dist/src/jobs/{update-prices.d.ts → etl/prices.d.ts} +0 -0
@@ -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
|
-
|
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
|
}), {
|
package/dist/src/eden/index.d.ts
CHANGED
@@ -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
|
};
|
package/dist/src/index.d.ts
CHANGED
@@ -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
|
};
|
package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/EqualizerGaugeProcessor.js
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
import { generateCardName } from "../../../../../utils/generateCardName";
|
2
2
|
import axios from "axios";
|
3
3
|
import { GenericProcessor } from "./GenericProcessor";
|
4
|
+
const findObjectByFarm = (dict, farmAddress) => {
|
5
|
+
for (const key in dict) {
|
6
|
+
if (dict[key].config && dict[key].config.farm === farmAddress) {
|
7
|
+
return dict[key];
|
8
|
+
}
|
9
|
+
}
|
10
|
+
return null;
|
11
|
+
};
|
4
12
|
export class EqualizerGaugeProcessor extends GenericProcessor {
|
5
13
|
rounds = {
|
6
14
|
round1: [],
|
@@ -15,8 +23,19 @@ export class EqualizerGaugeProcessor extends GenericProcessor {
|
|
15
23
|
let tvl = 0;
|
16
24
|
let displayName = "Stake into Equalizer Gauge";
|
17
25
|
try {
|
18
|
-
|
19
|
-
|
26
|
+
if (!!data[typeInfo.tokenAddress]) {
|
27
|
+
tvl = data[typeInfo.tokenAddress].token0.reserveUsd + data[typeInfo.tokenAddress].token1.reserveUsd;
|
28
|
+
displayName = `Stake into ${data[typeInfo.tokenAddress].pair.displayName} Equalizer Gauge`;
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
const EXTERNAL_EQUALIZER_CL_ENDPOINT = "https://eqapi-sonic-prod-ltanm.ondigitalocean.app/sonic/v4/clsets";
|
32
|
+
const data = (await axios(EXTERNAL_EQUALIZER_CL_ENDPOINT)).data.data;
|
33
|
+
const pool = findObjectByFarm(data, typeInfo.tokenAddress);
|
34
|
+
if (!!pool) {
|
35
|
+
tvl = pool.integration.equalizerPair.tvlUsd;
|
36
|
+
displayName = `Stake into ${pool.name} Equalizer Gauge`;
|
37
|
+
}
|
38
|
+
}
|
20
39
|
}
|
21
40
|
catch (e) { }
|
22
41
|
const priceTargetToken = tvl / totalSupply;
|
@@ -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?:
|
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
|
2
|
+
import type { InteractionQuote } from "./interaction.model";
|
4
3
|
export declare abstract class InteractionService {
|
5
|
-
static
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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 {
|
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
|
-
|
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
|
}
|