@merkl/api 0.20.34 → 0.20.36
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/engine/opportunityMetadata/implementations/Radiant.d.ts +1 -1
- package/dist/src/engine/opportunityMetadata/implementations/Radiant.js +18 -1
- package/dist/src/modules/v4/chain/chain.service.js +3 -1
- package/dist/src/modules/v4/opportunity/opportunity.service.js +4 -2
- package/dist/src/modules/v4/protocol/protocol.service.d.ts +1 -0
- package/dist/src/modules/v4/protocol/protocol.service.js +13 -10
- package/dist/src/modules/v4/token/token.service.js +9 -13
- package/dist/tsconfig.package.tsbuildinfo +1 -1
- package/package.json +1 -1
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { ProtocolId } from "@/modules/v4/protocol/protocol.model";
|
2
|
-
import type
|
2
|
+
import { type Campaign as CampaignEnum, type CampaignParameters, type ChainId } from "@sdk";
|
3
3
|
import type { MetadataBuilder } from "../interface";
|
4
4
|
type campaignType = CampaignEnum.RADIANT;
|
5
5
|
export declare class RadiantMetadata implements MetadataBuilder<campaignType> {
|
@@ -1,11 +1,28 @@
|
|
1
|
+
import { log } from "@/utils/logger";
|
1
2
|
import { OpportunityAction } from "@db/api";
|
3
|
+
import { ChainInteractionService, NETWORK_LABELS, RadiantInterface, } from "@sdk";
|
2
4
|
import { getAddress } from "viem";
|
3
5
|
export class RadiantMetadata {
|
4
6
|
async build(computeChainId, params, subType) {
|
7
|
+
const tokens = [{ chainId: computeChainId, address: params.targetToken }];
|
8
|
+
try {
|
9
|
+
const result = await ChainInteractionService(computeChainId).fetchState([
|
10
|
+
{
|
11
|
+
target: params.targetToken,
|
12
|
+
allowFailure: true,
|
13
|
+
callData: RadiantInterface.encodeFunctionData("UNDERLYING_ASSET_ADDRESS"),
|
14
|
+
},
|
15
|
+
]);
|
16
|
+
const underlyingAddress = getAddress(RadiantInterface.decodeFunctionResult("UNDERLYING_ASSET_ADDRESS", result[0].returnData)[0]);
|
17
|
+
tokens.push({ chainId: computeChainId, address: underlyingAddress });
|
18
|
+
}
|
19
|
+
catch {
|
20
|
+
log.warn(`failed to fetch underlying asset address on ${NETWORK_LABELS[computeChainId]} for radiant token ${params.targetToken}`);
|
21
|
+
}
|
5
22
|
return {
|
6
23
|
action: subType <= 1 ? OpportunityAction.LEND : OpportunityAction.BORROW,
|
7
24
|
name: [subType <= 1 ? "Lend" : "Borrow", params.symbolTargetToken].join(" "),
|
8
|
-
tokens
|
25
|
+
tokens,
|
9
26
|
mainProtocol: "radiant",
|
10
27
|
explorerAddress: getAddress(params.targetToken),
|
11
28
|
};
|
@@ -6,8 +6,10 @@ export class ChainService {
|
|
6
6
|
static async get(chainId) {
|
7
7
|
return ChainRepository.read(chainId);
|
8
8
|
}
|
9
|
-
//TODO: determine find vs get nomenclature and cache handling
|
10
9
|
static async findMany(query) {
|
10
|
+
// Bypass cache in test mode
|
11
|
+
if (query.test)
|
12
|
+
return ChainRepository.findMany(query);
|
11
13
|
return await CacheService.wrap(TTLPresets.MIN_10, ChainRepository.findMany, query);
|
12
14
|
}
|
13
15
|
static async countMany(query) {
|
@@ -166,9 +166,11 @@ export class OpportunityService {
|
|
166
166
|
* @returns A list of opportunities
|
167
167
|
*/
|
168
168
|
static async findMany(query) {
|
169
|
+
// Bypass cache in test mode
|
170
|
+
if (query.test)
|
171
|
+
return (await OpportunityRepository.findMany(query)).map(c => OpportunityService.formatResponse(c));
|
169
172
|
return await CacheService.wrap(TTLPresets.MIN_5, async (query) => {
|
170
|
-
|
171
|
-
return opportunities.map(c => OpportunityService.formatResponse(c));
|
173
|
+
return (await OpportunityRepository.findMany(query)).map(c => OpportunityService.formatResponse(c));
|
172
174
|
}, query);
|
173
175
|
}
|
174
176
|
/**
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { CreateProtocolModel, GetProtocolsQueryModel, Protocol, ProtocolId, UpdateProtocolModel } from "./protocol.model";
|
2
2
|
export declare abstract class ProtocolService {
|
3
|
+
#private;
|
3
4
|
static findMany(query: GetProtocolsQueryModel): Promise<Protocol["model"][]>;
|
4
5
|
static countMany(query: GetProtocolsQueryModel): Promise<number>;
|
5
6
|
static getFromId(id: ProtocolId | string): Promise<Protocol["model"] | null>;
|
@@ -6,17 +6,20 @@ import { TTLPresets } from "../cache/cache.model";
|
|
6
6
|
import { ProtocolRepository } from "./protocol.repository";
|
7
7
|
// ─── Protocols Services ──────────────────────────────────────────────────────
|
8
8
|
export class ProtocolService {
|
9
|
+
static async #findMany(query) {
|
10
|
+
const protocols = await ProtocolRepository.findMany(query);
|
11
|
+
const enrichedProtocols = protocols.map(({ MainOpportunities, ...protocol }) => ({
|
12
|
+
...protocol,
|
13
|
+
dailyRewards: MainOpportunities.reduce((sum, opportunity) => sum + opportunity.dailyRewards, 0),
|
14
|
+
numberOfLiveCampaigns: MainOpportunities.reduce((sum, opportunity) => sum + opportunity.Campaigns.length, 0),
|
15
|
+
opportunityLiveTags: [...new Set(MainOpportunities.flatMap(opportunity => opportunity.action))], // ensure uniqness of tags
|
16
|
+
}));
|
17
|
+
return enrichedProtocols;
|
18
|
+
}
|
9
19
|
static async findMany(query) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
...protocol,
|
14
|
-
dailyRewards: MainOpportunities.reduce((sum, opportunity) => sum + opportunity.dailyRewards, 0),
|
15
|
-
numberOfLiveCampaigns: MainOpportunities.reduce((sum, opportunity) => sum + opportunity.Campaigns.length, 0),
|
16
|
-
opportunityLiveTags: [...new Set(MainOpportunities.flatMap(opportunity => opportunity.action))], // ensure uniqness of tags
|
17
|
-
}));
|
18
|
-
return enrichedProtocols;
|
19
|
-
}, query);
|
20
|
+
if (query.test)
|
21
|
+
return await ProtocolRepository.findMany(query);
|
22
|
+
return await CacheService.wrap(TTLPresets.MIN_10, ProtocolService.#findMany, query);
|
20
23
|
}
|
21
24
|
static async countMany(query) {
|
22
25
|
return ProtocolRepository.countMany(query);
|
@@ -8,8 +8,6 @@ import { Prisma } from "@db/api";
|
|
8
8
|
import { ChainInteractionService, DistributionCreatorService, NETWORK_LABELS, bigIntToNumber, } from "@sdk";
|
9
9
|
import { getAddress, parseUnits } from "viem";
|
10
10
|
import { BucketService } from "../bucket/bucket.service";
|
11
|
-
import { CacheService } from "../cache";
|
12
|
-
import { TTLPresets } from "../cache/cache.model";
|
13
11
|
import { IconService } from "../icon/icon.service";
|
14
12
|
import { PriceService } from "../price";
|
15
13
|
import { TokenRepository } from "./token.repository";
|
@@ -272,17 +270,15 @@ export class TokenService {
|
|
272
270
|
}));
|
273
271
|
}
|
274
272
|
static async getValidRewardTokens(chainId) {
|
275
|
-
|
276
|
-
|
277
|
-
return
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
});
|
285
|
-
}, chainId);
|
273
|
+
const validRewardTokens = await DistributionCreatorService(chainId).validRewardTokens();
|
274
|
+
return (await TokenRepository.findList(chainId, validRewardTokens.map(t => getAddress(t.token)))).map(x => {
|
275
|
+
return {
|
276
|
+
...x,
|
277
|
+
minimumAmountPerHour: validRewardTokens
|
278
|
+
.find(t => getAddress(t.token) === x.address)
|
279
|
+
?.minimumAmountPerEpoch.toString(),
|
280
|
+
};
|
281
|
+
});
|
286
282
|
}
|
287
283
|
static async update(id, data) {
|
288
284
|
return await TokenRepository.update(id, data);
|