@merkl/api 0.10.389 → 0.10.391

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.
@@ -2320,7 +2320,13 @@ declare const eden: {
2320
2320
  fetch?: RequestInit | undefined;
2321
2321
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
2322
2322
  200: {
2323
- totalAmount: number;
2323
+ total: number;
2324
+ breakdown: {
2325
+ [key: number]: {
2326
+ chainAmount: number;
2327
+ percentage: number;
2328
+ };
2329
+ };
2324
2330
  };
2325
2331
  }>>;
2326
2332
  "per-month": ((params: {
@@ -6468,7 +6474,13 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
6468
6474
  };
6469
6475
  response: {
6470
6476
  200: {
6471
- totalAmount: number;
6477
+ total: number;
6478
+ breakdown: {
6479
+ [key: number]: {
6480
+ chainAmount: number;
6481
+ percentage: number;
6482
+ };
6483
+ };
6472
6484
  };
6473
6485
  };
6474
6486
  };
@@ -10496,7 +10508,13 @@ export declare const MerklApi: (domain: string | import("elysia").default<"", fa
10496
10508
  fetch?: RequestInit | undefined;
10497
10509
  }) => Promise<import("@elysiajs/eden").Treaty.TreatyResponse<{
10498
10510
  200: {
10499
- totalAmount: number;
10511
+ total: number;
10512
+ breakdown: {
10513
+ [key: number]: {
10514
+ chainAmount: number;
10515
+ percentage: number;
10516
+ };
10517
+ };
10500
10518
  };
10501
10519
  }>>;
10502
10520
  "per-month": ((params: {
@@ -2829,7 +2829,13 @@ declare const app: Elysia<"", false, {
2829
2829
  };
2830
2830
  response: {
2831
2831
  200: {
2832
- totalAmount: number;
2832
+ total: number;
2833
+ breakdown: {
2834
+ [key: number]: {
2835
+ chainAmount: number;
2836
+ percentage: number;
2837
+ };
2838
+ };
2833
2839
  };
2834
2840
  };
2835
2841
  };
@@ -1,4 +1,4 @@
1
- import { BN2Number, HyperdriveTargetInterface, } from "@sdk";
1
+ import { BN2Number, ETH_ADDRESS, HyperDriveSubCampaignType, HyperdriveTargetInterface, } from "@sdk";
2
2
  import { Pricer } from "../../../utils/pricer";
3
3
  export async function HyperdriveDynamicData(chainId, campaigns) {
4
4
  const pricer = await Pricer.load();
@@ -12,10 +12,6 @@ export async function HyperdriveDynamicData(chainId, campaigns) {
12
12
  allowFailure: false,
13
13
  callData: HyperdriveTargetInterface.encodeFunctionData("getPoolConfig"),
14
14
  target: campaign.campaignParameters.targetToken,
15
- }, {
16
- allowFailure: false,
17
- callData: HyperdriveTargetInterface.encodeFunctionData("totalSupply", [campaign.campaignParameters.tokenId]),
18
- target: campaign.campaignParameters.targetToken,
19
15
  });
20
16
  }
21
17
  return {
@@ -29,27 +25,34 @@ export async function HyperdriveDynamicData(chainId, campaigns) {
29
25
  for (const campaign of campaigns) {
30
26
  const poolInfo = HyperdriveTargetInterface.decodeFunctionResult("getPoolInfo", result[i++])[0];
31
27
  const poolConfig = HyperdriveTargetInterface.decodeFunctionResult("getPoolConfig", result[i++])[0];
32
- const totalSupplyVaultToken = BN2Number(HyperdriveTargetInterface.decodeFunctionResult("totalSupply", result[i++])[0]);
33
28
  const priceRewardToken = (await pricer.get({
34
29
  address: campaign.rewardToken,
35
30
  chainId,
36
31
  symbol: campaign.campaignParameters.symbolRewardToken,
37
32
  })) ?? 0;
38
- const priceTargetToken = (await pricer.get({
39
- address: campaign.campaignParameters.targetToken,
40
- chainId,
41
- symbol: campaign.campaignParameters.symbolTargetToken,
42
- })) ?? 0;
43
- const priceBaseToken = (await pricer.get({
44
- address: campaign.campaignParameters.baseToken,
45
- chainId,
46
- symbol: campaign.campaignParameters.baseTokenSymbol,
47
- })) ?? 0;
48
- const supply = totalSupplyVaultToken;
33
+ const lpSupply = BN2Number(poolInfo.lpTotalSupply, 18);
34
+ const longSupply = BN2Number(poolInfo.longsOutstanding, 18);
35
+ const shortSupply = BN2Number(poolInfo.shortsOutstanding, 18);
36
+ const marketSupply = lpSupply * BN2Number(poolInfo.lpSharePrice, 18);
37
+ const priceBaseToken = (poolConfig.baseToken === ETH_ADDRESS
38
+ ? await pricer.get({
39
+ chainId,
40
+ symbol: "ETH",
41
+ })
42
+ : await pricer.get({
43
+ address: campaign.campaignParameters.baseToken,
44
+ chainId,
45
+ symbol: campaign.campaignParameters.baseTokenSymbol,
46
+ })) ?? 0;
47
+ const tvl = campaign.campaignSubType === HyperDriveSubCampaignType.LP
48
+ ? priceBaseToken * marketSupply
49
+ : campaign.campaignSubType === HyperDriveSubCampaignType.LONG
50
+ ? priceBaseToken * longSupply
51
+ : priceBaseToken * shortSupply;
49
52
  dynamicData.push({
50
53
  ...campaign,
51
- totalSupplyTargetToken: supply,
52
- tvl: 0,
54
+ totalSupplyTargetToken: marketSupply,
55
+ tvl: tvl,
53
56
  apr: 0,
54
57
  priceRewardToken: priceRewardToken,
55
58
  });
@@ -51,7 +51,13 @@ export declare const AccountingController: Elysia<"/accounting", false, {
51
51
  };
52
52
  response: {
53
53
  200: {
54
- totalAmount: number;
54
+ total: number;
55
+ breakdown: {
56
+ [key: number]: {
57
+ chainAmount: number;
58
+ percentage: number;
59
+ };
60
+ };
55
61
  };
56
62
  };
57
63
  };
@@ -12,7 +12,7 @@ export const AccountingController = new Elysia({ prefix: "/accounting", detail:
12
12
  })
13
13
  .group("/revenues", app => {
14
14
  return app
15
- .get("", async () => await AccountingService.getRevenue(), {
15
+ .get("", async () => await AccountingService.getAllRevenueBreakdownByChain(), {
16
16
  headers: AuthorizationHeadersDto,
17
17
  beforeHandle: async ({ headers }) => {
18
18
  await BackOfficeGuard({ headers });
@@ -1,5 +1,5 @@
1
1
  import type { GetTransactionsQueryModel } from "./";
2
- import type { ChainId } from "@sdk";
2
+ import { ChainId } from "@sdk";
3
3
  export declare class AccountingService {
4
4
  static hashId(chainId: ChainId, fromTokenId: string, toTokenId: string, timestamp: number): string;
5
5
  static getTokenId(chainId: number, address: string): string;
@@ -21,6 +21,15 @@ export declare class AccountingService {
21
21
  static getRevenueByChain(chainId: number): Promise<{
22
22
  totalAmount: number;
23
23
  }>;
24
+ static getAllRevenueBreakdownByChain(): Promise<{
25
+ total: number;
26
+ breakdown: {
27
+ [key: number]: {
28
+ chainAmount: number;
29
+ percentage: number;
30
+ };
31
+ };
32
+ }>;
24
33
  static getMonthlyRevenue(year: number, month: number): Promise<{
25
34
  totalAmount: number;
26
35
  from: string;
@@ -1,5 +1,6 @@
1
1
  import { AccountingRepository } from "./accounting.repository";
2
2
  import { TokenService } from "../token";
3
+ import { ChainId } from "@sdk";
3
4
  export class AccountingService {
4
5
  static hashId(chainId, fromTokenId, toTokenId, timestamp) {
5
6
  return Bun.hash(`${chainId}${fromTokenId}${toTokenId}${timestamp}`).toString();
@@ -26,6 +27,24 @@ export class AccountingService {
26
27
  }
27
28
  return { totalAmount };
28
29
  }
30
+ static async getAllRevenueBreakdownByChain() {
31
+ const breakdown = {};
32
+ let consolidatedAmount = 0;
33
+ for (const chainId of Object.values(ChainId).filter(id => typeof id === "number")) {
34
+ const data = await AccountingRepository.getForMultisigByChain(chainId);
35
+ let totalAmount = 0;
36
+ for (const tx of data) {
37
+ totalAmount += Number(tx.amountIn);
38
+ }
39
+ breakdown[chainId] = { chainAmount: totalAmount, percentage: 0 };
40
+ consolidatedAmount += totalAmount;
41
+ }
42
+ for (const chainId of Object.values(ChainId).filter(id => typeof id === "number")) {
43
+ const totalAmount = breakdown[chainId].chainAmount;
44
+ breakdown[chainId] = { chainAmount: totalAmount, percentage: (totalAmount * 100) / consolidatedAmount };
45
+ }
46
+ return { total: consolidatedAmount, breakdown };
47
+ }
29
48
  static async getMonthlyRevenue(year, month) {
30
49
  const startDate = new Date(year, month - 1, 1);
31
50
  const endDate = new Date(year, month, 0, 23, 59, 59);
@@ -85,7 +85,7 @@ export class OpportunityService {
85
85
  return getEulerMetadata(chainId, campaign.campaignId, campaign.subType, campaign.rewardTokenAddress, campaign.amount, campaignParams);
86
86
  case "HYPERDRIVELOGPROCESSOR":
87
87
  case "HYPERDRIVELOGFIXPROCESSOR":
88
- return getHyperdriveMetadata(chainId, campaign.subType, campaignParams);
88
+ return getHyperdriveMetadata(chainId, campaignParams.subCampaignType, campaignParams);
89
89
  case "INVALID":
90
90
  return {
91
91
  name: "Invalid Campaigns",
@@ -1,3 +1,3 @@
1
- import type { ChainId, HyperDriveLogCampaign } from "@sdk";
1
+ import { type ChainId, type HyperDriveLogCampaign } from "@sdk";
2
2
  import type { OpportunityMetadata } from "../opportunity.model";
3
3
  export declare const getHyperdriveMetadata: (chainId: ChainId, campaignSubType: HyperDriveLogCampaign["campaignSubType"], params: HyperDriveLogCampaign["campaignParameters"]) => OpportunityMetadata;
@@ -1,10 +1,14 @@
1
1
  import { OpportunityAction } from "../../../../../database/api/.generated";
2
+ import { HyperDriveSubCampaignType } from "@sdk";
2
3
  export const getHyperdriveMetadata = (chainId, campaignSubType, params) => {
3
4
  const subtypes = [
4
5
  { name: "Add Liquidity on", action: OpportunityAction.POOL },
5
6
  { name: "Open Long on", action: OpportunityAction.LONG },
6
7
  { name: "Open Short on", action: OpportunityAction.SHORT },
7
8
  ];
9
+ if (campaignSubType === HyperDriveSubCampaignType.LP) {
10
+ campaignSubType = 0;
11
+ }
8
12
  const subtype = subtypes[campaignSubType];
9
13
  return {
10
14
  action: subtype.action,
@@ -361,6 +361,8 @@ export class RewardService {
361
361
  return { timestamp, total: 0, breakdowns: [] };
362
362
  const breakdowns = [];
363
363
  for (const { amount, rewardToken: address, chainId, startTimestamp: start, endTimestamp: end, campaignId, } of dynamicData) {
364
+ if (end < moment().unix())
365
+ continue;
364
366
  const timespan = Math.abs(end - start);
365
367
  const isWithinTimespan = moment().unix() > start && moment().unix() < end;
366
368
  const dayspan = Math.max(1, Math.floor(timespan / DAY));
@@ -2707,7 +2707,13 @@ export declare const v4: Elysia<"/v4", false, {
2707
2707
  };
2708
2708
  response: {
2709
2709
  200: {
2710
- totalAmount: number;
2710
+ total: number;
2711
+ breakdown: {
2712
+ [key: number]: {
2713
+ chainAmount: number;
2714
+ percentage: number;
2715
+ };
2716
+ };
2711
2717
  };
2712
2718
  };
2713
2719
  };