@merkl/api 0.20.37 → 0.20.39
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/eden/index.d.ts +243 -0
- package/dist/src/engine/dynamicData/implementations/UniswapV4.js +2 -1
- package/dist/src/index.d.ts +55 -0
- package/dist/src/jobs/update-uniswap-v4-pools.js +2 -2
- package/dist/src/libs/merklChainData.js +0 -2
- package/dist/src/modules/v4/price/price.repository.d.ts +1 -1
- package/dist/src/modules/v4/price/price.service.d.ts +1 -1
- package/dist/src/modules/v4/reward/reward.repository.d.ts +1 -1
- package/dist/src/modules/v4/reward/reward.repository.js +19 -1
- package/dist/src/modules/v4/reward/reward.service.d.ts +1 -1
- package/dist/src/modules/v4/reward/reward.service.js +2 -2
- package/dist/src/modules/v4/router.d.ts +55 -0
- package/dist/src/modules/v4/router.js +3 -1
- package/dist/src/modules/v4/token/token.service.js +3 -3
- package/dist/src/modules/v4/uniswap/uniswap.controller.d.ts +75 -0
- package/dist/src/modules/v4/uniswap/uniswap.controller.js +34 -0
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.model.d.ts → uniswap/uniswap.model.d.ts} +6 -0
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.model.js → uniswap/uniswap.model.js} +9 -0
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.repository.d.ts → uniswap/uniswap.repository.d.ts} +2 -2
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.repository.js → uniswap/uniswap.repository.js} +1 -1
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.service.d.ts → uniswap/uniswap.service.d.ts} +3 -2
- package/dist/src/modules/v4/{uniswapV4/uniswapV4.service.js → uniswap/uniswap.service.js} +48 -4
- package/dist/src/routes/v1/prices.js +1 -1
- package/dist/src/routes/v3/uniswapv4.js +1 -1
- package/dist/src/scripts/fill-unknown-tokens.js +58 -0
- package/dist/src/scripts/reparse-opportunities.d.ts +1 -0
- package/dist/src/{jobs → scripts}/reparse-opportunities.js +1 -0
- package/dist/src/utils/prices/priceService.js +1 -1
- package/dist/src/utils/prices/services/erc4626Service.js +1 -1
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/modules/v4/price/index.d.ts +0 -3
- package/dist/src/modules/v4/price/index.js +0 -3
- package/dist/src/modules/v4/uniswapV4/index.d.ts +0 -4
- package/dist/src/modules/v4/uniswapV4/index.js +0 -4
- package/dist/src/modules/v4/uniswapV4/uniswapV4.controller.d.ts +0 -53
- package/dist/src/modules/v4/uniswapV4/uniswapV4.controller.js +0 -12
- /package/dist/src/{jobs/reparse-opportunities.d.ts → scripts/fill-unknown-tokens.d.ts} +0 -0
@@ -4,6 +4,11 @@ import type { MerklChainId, UniswapV4PoolType } from "@sdk";
|
|
4
4
|
export declare const Bytes32Dto: import("@sinclair/typebox").TObject<{
|
5
5
|
poolId: import("@sinclair/typebox").TRegExp;
|
6
6
|
}>;
|
7
|
+
export declare const RewardsPerV3PositionDto: import("@sinclair/typebox").TObject<{
|
8
|
+
address: import("@sinclair/typebox").TString;
|
9
|
+
poolAddress: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
10
|
+
positionId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
11
|
+
}>;
|
7
12
|
export declare const UniswapV4PoolsDto: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TObject<{
|
8
13
|
poolKey: import("@sinclair/typebox").TObject<{
|
9
14
|
currency0: import("@sinclair/typebox").TString;
|
@@ -25,3 +30,4 @@ export type UniswapV4PoolsReturnType = {
|
|
25
30
|
};
|
26
31
|
export type UniswapV4PoolsEntity = typeof UniswapV4PoolsDto.static;
|
27
32
|
export type LoggedCreateBody = Prisma.Args<typeof apiDbClient.logged, "createMany">["data"];
|
33
|
+
export type RewardsPerPositionModel = typeof RewardsPerV3PositionDto.static;
|
@@ -19,4 +19,13 @@ export const Bytes32Dto = t.Object({
|
|
19
19
|
description: "A 32-byte hexadecimal string (bytes32)",
|
20
20
|
}),
|
21
21
|
});
|
22
|
+
export const RewardsPerV3PositionDto = t.Object({
|
23
|
+
address: t.String({ description: "Address of the rewarded user" }),
|
24
|
+
poolAddress: t.Optional(t.String({
|
25
|
+
description: "Address of the Uniswap pool. Default: returns rewards for all pools.",
|
26
|
+
})),
|
27
|
+
positionId: t.Optional(t.String({
|
28
|
+
description: "PositionId of the Uniswap position. Can be a tokenId if the position is an NFT or a bytes32 id if held directly on the pool. Default: returns rewards for all positions on the pools.",
|
29
|
+
})),
|
30
|
+
});
|
22
31
|
export const UniswapV4PoolsDto = t.Record(t.String(), UniswapV4PoolDto);
|
package/dist/src/modules/v4/{uniswapV4/uniswapV4.repository.d.ts → uniswap/uniswap.repository.d.ts}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { LoggedCreateBody } from "./
|
2
|
-
export declare abstract class
|
1
|
+
import type { LoggedCreateBody } from "./uniswap.model";
|
2
|
+
export declare abstract class UniswapRepository {
|
3
3
|
static getStoredPools(): Promise<{
|
4
4
|
id: string;
|
5
5
|
type: import("@db/api").$Enums.LoggedEntityType;
|
package/dist/src/modules/v4/{uniswapV4/uniswapV4.repository.js → uniswap/uniswap.repository.js}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { apiDbClient } from "@db";
|
2
2
|
import { LoggedEntityType } from "@db/api";
|
3
|
-
export class
|
3
|
+
export class UniswapRepository {
|
4
4
|
static async getStoredPools() {
|
5
5
|
return await apiDbClient.logged.findMany({
|
6
6
|
where: { type: LoggedEntityType.UNISWAP_V4 },
|
package/dist/src/modules/v4/{uniswapV4/uniswapV4.service.d.ts → uniswap/uniswap.service.d.ts}
RENAMED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { type MerklChainId } from "@sdk";
|
2
|
-
import type { UniswapV4PoolsReturnType } from "./
|
2
|
+
import type { RewardsPerPositionModel, UniswapV4PoolsReturnType } from "./uniswap.model";
|
3
3
|
export declare const PoolManagerInterface: any;
|
4
|
-
export declare abstract class
|
4
|
+
export declare abstract class UniswapService {
|
5
|
+
static findV3RewardsPerPosition(query: RewardsPerPositionModel): Promise<Record<string, Record<string, any[]>>>;
|
5
6
|
static getPoolsByChain(chainId: MerklChainId): Promise<{
|
6
7
|
[x: string]: {
|
7
8
|
poolId: string;
|
@@ -5,9 +5,53 @@ import { providers } from "@/utils/providers";
|
|
5
5
|
import { LoggedEntityType } from "@db/api";
|
6
6
|
import { ChainInteractionService, ERC20Interface, NETWORK_LABELS, NULL_ADDRESS, UniswapV4Addresses, UniswapV4PoolManagerInterface, UniswapV4PoolManager__factory, getContractCreationBlock, } from "@sdk";
|
7
7
|
import { utils } from "ethers";
|
8
|
-
import {
|
8
|
+
import { getAddress } from "viem";
|
9
|
+
import { BlacklistService } from "../blacklist";
|
10
|
+
import { ChainService } from "../chain/chain.service";
|
11
|
+
import { MerklRootService } from "../merklRoot";
|
12
|
+
import { OpportunityService } from "../opportunity";
|
13
|
+
import { RewardService } from "../reward";
|
14
|
+
import { UniswapRepository } from "./uniswap.repository";
|
9
15
|
export const PoolManagerInterface = UniswapV4PoolManager__factory.createInterface();
|
10
|
-
export class
|
16
|
+
export class UniswapService {
|
17
|
+
static async findV3RewardsPerPosition(query) {
|
18
|
+
/** Check if the user is blacklisted */
|
19
|
+
const isBlacklisted = !!(await BlacklistService.isBlacklisted(query.address));
|
20
|
+
// pool address => NFT or Position ID => [rewards]
|
21
|
+
const res = {};
|
22
|
+
if (isBlacklisted)
|
23
|
+
return res;
|
24
|
+
const chains = await ChainService.findMany({});
|
25
|
+
const chainIds = chains.map(({ id }) => id);
|
26
|
+
/** Fetch current Merkle Roots */
|
27
|
+
const merkleRootsPromises = await Promise.allSettled(chainIds.map(chainId => MerklRootService.fetchFromCache(chainId)));
|
28
|
+
const merkleRoots = merkleRootsPromises
|
29
|
+
.filter(({ status }) => status === "fulfilled")
|
30
|
+
.map(x => x.value);
|
31
|
+
const rewards = RewardService.format(await RewardService.getByRecipient(query.address, merkleRoots.map(({ live }) => live), true, false, null, "UniswapV3"));
|
32
|
+
for (const reward of rewards) {
|
33
|
+
const rewardToken = reward.token;
|
34
|
+
for (const breakdown of reward.breakdowns) {
|
35
|
+
let poolAddress = breakdown.opportunity.explorerAddress;
|
36
|
+
if (!!poolAddress) {
|
37
|
+
poolAddress = getAddress(poolAddress);
|
38
|
+
res[poolAddress] = res[poolAddress] ?? {};
|
39
|
+
if (!query.poolAddress || poolAddress === query.poolAddress) {
|
40
|
+
const positionId = breakdown.reason.split("_")[1];
|
41
|
+
if (!res[poolAddress][positionId])
|
42
|
+
res[poolAddress][positionId] = [];
|
43
|
+
const { opportunity, ...props } = breakdown;
|
44
|
+
res[poolAddress][positionId].push({
|
45
|
+
...props,
|
46
|
+
opportunity: OpportunityService.formatResponseBase(opportunity),
|
47
|
+
rewardToken: rewardToken,
|
48
|
+
});
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
return res;
|
54
|
+
}
|
11
55
|
static async getPoolsByChain(chainId) {
|
12
56
|
const lastBlock = await providers[chainId].getBlockNumber();
|
13
57
|
const logs = await safeFetchLogs(chainId, [PoolManagerInterface.getEventTopic("Initialize")], ["0xE8E23e97Fa135823143d6b9Cba9c699040D51F70"], 0, lastBlock);
|
@@ -77,7 +121,7 @@ export class UniswapV4Service {
|
|
77
121
|
const UNIV4_CHAINIDS = Object.keys(UniswapV4Addresses).map((x) => Number(x));
|
78
122
|
const pools = {};
|
79
123
|
// 0_ Fetch all euler vaults from database
|
80
|
-
const storedPools = await
|
124
|
+
const storedPools = await UniswapRepository.getStoredPools();
|
81
125
|
const res = await Promise.all(UNIV4_CHAINIDS.map(async (chainId) => {
|
82
126
|
chainId = chainId;
|
83
127
|
const perChainIdRes = {};
|
@@ -212,7 +256,7 @@ export class UniswapV4Service {
|
|
212
256
|
for (const chainId of UNIV4_CHAINIDS) {
|
213
257
|
if (tableData.filter(p => p.chainId === chainId).length > 0) {
|
214
258
|
try {
|
215
|
-
await
|
259
|
+
await UniswapRepository.createMany(tableData
|
216
260
|
.filter(point => point.chainId === chainId)
|
217
261
|
.map(pool => ({
|
218
262
|
fetchAtBlock: pool.fetchedAtBlock,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PriceService } from "@/modules/v4/price";
|
1
|
+
import { PriceService } from "@/modules/v4/price/price.service";
|
2
2
|
import { t } from "elysia";
|
3
3
|
export const response = t.Array(t.Object({ rate: t.Number(), token: t.String() }));
|
4
4
|
export default (app) => app.get("/prices", async () => {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { Redis } from "@/cache";
|
2
2
|
import { UniV4ChainIdArray, getUniswapV4Pools } from "@/engine/dynamicData/utils/getUniswapV4Pools";
|
3
3
|
import { ChainUniqueDto } from "@/modules/v4/chain/chain.model";
|
4
|
-
import { Bytes32Dto } from "@/modules/v4/
|
4
|
+
import { Bytes32Dto } from "@/modules/v4/uniswap/uniswap.model";
|
5
5
|
import { UnsupportedNetwork } from "@/utils/error";
|
6
6
|
export default (app) => app.group("/uniswapv4", router => router
|
7
7
|
.get("/", async () => {
|
@@ -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,5 +1,5 @@
|
|
1
1
|
import { getTokensListWithCache } from "@/libs/getTokensList";
|
2
|
-
import { PriceService as PriceSourceService } from "@/modules/v4/price";
|
2
|
+
import { PriceService as PriceSourceService } from "@/modules/v4/price/price.service";
|
3
3
|
import { PriceSourceMethod } from "@db/api";
|
4
4
|
import { BN2Number, ChainId, Stable, registry } from "@sdk";
|
5
5
|
import axios from "axios";
|