@merkl/api 0.16.14 → 0.16.16

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 (26) hide show
  1. package/dist/src/eden/index.d.ts +270 -0
  2. package/dist/src/entities/opportunity.js +7 -200
  3. package/dist/src/index.d.ts +62 -0
  4. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType.js +1 -1
  5. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AuraProcessor.d.ts +8 -0
  6. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/AuraProcessor.js +10 -12
  7. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerPoolProcessor.d.ts +8 -1
  8. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerPoolProcessor.js +11 -15
  9. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/BalancerV3PoolProcessor.js +4 -5
  10. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/GenericProcessor.js +6 -1
  11. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/StakingProcessor.js +1 -0
  12. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/VicunaProcessor.js +0 -1
  13. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/curveProcessor.d.ts +2 -0
  14. package/dist/src/libs/campaigns/campaignTypes/ERC20SubTypes/processor/curveProcessor.js +2 -0
  15. package/dist/src/modules/v4/referral/referral.controller.d.ts +82 -0
  16. package/dist/src/modules/v4/referral/referral.controller.js +25 -0
  17. package/dist/src/modules/v4/referral/referral.model.d.ts +10 -0
  18. package/dist/src/modules/v4/referral/referral.model.js +12 -0
  19. package/dist/src/modules/v4/referral/referral.service.d.ts +216 -0
  20. package/dist/src/modules/v4/referral/referral.service.js +170 -0
  21. package/dist/src/modules/v4/router.d.ts +62 -0
  22. package/dist/src/modules/v4/router.js +3 -1
  23. package/dist/src/utils/generateIcons.d.ts +3 -0
  24. package/dist/src/utils/generateIcons.js +53 -0
  25. package/dist/tsconfig.package.tsbuildinfo +1 -1
  26. package/package.json +1 -1
@@ -0,0 +1,170 @@
1
+ import { ChainId, ChainInteractionService } from "@sdk";
2
+ import { decodeFunctionResult, encodeFunctionData, parseAbi, } from "viem";
3
+ export class ReferralService {
4
+ static abi = parseAbi([
5
+ "function getReferralKeys() external view returns (string[] memory)",
6
+ "function getReferrerStatus(string calldata key, address user) external view returns (bytes32)",
7
+ "function referrerCodeMapping(string key, address user) external view returns (string)",
8
+ "function codeToReferrer(string key, string user) external view returns (address)",
9
+ "function getReferrer(string calldata key, address user) external view returns (address)",
10
+ "function getReferredUsers(string calldata key, address user) external view returns (address[] memory)",
11
+ "function acknowledgeReferrerByKey(string calldata key, string calldata referrerCode) external",
12
+ "function getCostOfReferral(string calldata key) external view returns (uint256)",
13
+ "function getPaymentToken(string calldata key) external view returns (address)",
14
+ "function getReferrerStatusByKey(string calldata key, address referrer) external view returns (uint8)",
15
+ "function requiresAuthorization(string calldata key) external view returns (bool)",
16
+ "function requiresRefererToBeSet(string calldata key) external view returns (bool)",
17
+ "function becomeReferrer(string calldata key, string calldata referrerCode) external payable",
18
+ ]);
19
+ static getReferralContract(chainId) {
20
+ if (chainId === ChainId.ETHERLINK)
21
+ return "0xF39CC381B91f36238c77f42B9fF4D45376F80E5b";
22
+ return;
23
+ }
24
+ /**
25
+ * Makes an on-chain call to the referral contract
26
+ * @param chainId
27
+ * @param functionName
28
+ * @param args
29
+ * @returns
30
+ */
31
+ static async #call(chainId, functionName, args) {
32
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
33
+ if (!referralContractAddress)
34
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
35
+ return await ChainInteractionService(chainId).fetchAndDecode({
36
+ target: referralContractAddress,
37
+ allowFailure: true,
38
+ callData: encodeFunctionData({
39
+ abi: ReferralService.abi,
40
+ functionName,
41
+ args,
42
+ }),
43
+ }, (r) => decodeFunctionResult({
44
+ abi: ReferralService.abi,
45
+ functionName,
46
+ data: r?.returnData,
47
+ }));
48
+ }
49
+ static async isKeyAvailable(key, chainId) {
50
+ const referralKeys = await ReferralService.#call(chainId, "getReferralKeys", []);
51
+ return referralKeys.includes(key);
52
+ }
53
+ static async getReferredUsers(chainId, key, address) {
54
+ const isReferralKeyAvailable = ReferralService.isKeyAvailable(key, chainId);
55
+ if (!isReferralKeyAvailable)
56
+ throw new Error(`Referral key ${key} not available on ${chainId}`);
57
+ return await ReferralService.#call(chainId, "getReferredUsers", [key, address]);
58
+ }
59
+ static async getReferralStatus(chainId, key, address) {
60
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
61
+ const isReferralKeyAvailable = ReferralService.isKeyAvailable(key, chainId);
62
+ if (!referralContractAddress)
63
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
64
+ if (!isReferralKeyAvailable)
65
+ throw new Error(`Referral key ${key} not available on ${chainId}`);
66
+ const shouldCheckStatus = await ReferralService.#call(chainId, "requiresAuthorization", [key]);
67
+ if (!shouldCheckStatus)
68
+ return true;
69
+ const referralStatus = await ReferralService.#call(chainId, "getReferrerStatusByKey", [
70
+ key,
71
+ address,
72
+ ]);
73
+ return referralStatus === 1;
74
+ }
75
+ static generateCode(chainId, key, address) {
76
+ return Bun.hash([chainId, key, address].join("-")).toString().slice(0, 12);
77
+ }
78
+ static async getCode(chainId, key, address) {
79
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
80
+ if (!referralContractAddress)
81
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
82
+ const code = await ReferralService.#call(chainId, "referrerCodeMapping", [key, address]);
83
+ return code === "" ? undefined : code;
84
+ }
85
+ /**
86
+ * Get state & transaction for creating a referral code
87
+ * @param chainId of the referral contract
88
+ * @param key of referral
89
+ * @param address of the creator
90
+ */
91
+ static async getCodeOrTransaction(chainId, key, address) {
92
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
93
+ const isReferralKeyAvailable = ReferralService.isKeyAvailable(key, chainId);
94
+ if (!referralContractAddress)
95
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
96
+ if (!isReferralKeyAvailable)
97
+ throw new Error(`Referral key ${key} not available on ${chainId}`);
98
+ const contractCode = await ReferralService.getCode(chainId, key, address);
99
+ if (!contractCode) {
100
+ const code = ReferralService.generateCode(chainId, key, address);
101
+ return {
102
+ code,
103
+ referrer: false,
104
+ referredUsers: [],
105
+ transaction: {
106
+ to: referralContractAddress,
107
+ data: encodeFunctionData({
108
+ abi: ReferralService.abi,
109
+ functionName: "becomeReferrer",
110
+ args: [key, code],
111
+ }),
112
+ },
113
+ };
114
+ }
115
+ const code = await ReferralService.getCode(chainId, key, address);
116
+ const referredUsers = await ReferralService.getReferredUsers(chainId, key, address);
117
+ return {
118
+ code,
119
+ referrer: true,
120
+ referredUsers,
121
+ };
122
+ }
123
+ /**
124
+ * Checks if code exists in the contracts
125
+ * @param chainId of the referral contract
126
+ * @param key of referral
127
+ * @param code user referral code
128
+ * @returns referrerAddress if code exitst
129
+ */
130
+ static async isCodeRegistered(chainId, key, code) {
131
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
132
+ if (!referralContractAddress)
133
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
134
+ const referrerAddress = await ReferralService.#call(chainId, "codeToReferrer", [key, code]);
135
+ return referrerAddress === "" ? undefined : referrerAddress;
136
+ }
137
+ /**
138
+ * Get state & transaction for redeeming a referral code
139
+ * @param chainId of the referral contract
140
+ * @param key of referral
141
+ * @param code user referral code
142
+ */
143
+ static async getReferralTransaction(chainId, key, code) {
144
+ const referralContractAddress = ReferralService.getReferralContract(chainId);
145
+ const isReferralKeyAvailable = ReferralService.isKeyAvailable(key, chainId);
146
+ if (!referralContractAddress)
147
+ throw new Error(`Referral contract not deployed on chain ${chainId}`);
148
+ if (!isReferralKeyAvailable)
149
+ throw new Error(`Referral key ${key} not available on ${chainId}`);
150
+ const referrerAddress = await ReferralService.isCodeRegistered(chainId, key, code);
151
+ if (!referrerAddress) {
152
+ return {
153
+ code,
154
+ referrer: referrerAddress,
155
+ };
156
+ }
157
+ return {
158
+ code,
159
+ referrer: referrerAddress,
160
+ transaction: {
161
+ to: referralContractAddress,
162
+ data: encodeFunctionData({
163
+ abi: ReferralService.abi,
164
+ functionName: "acknowledgeReferrerByKey",
165
+ args: [key, code],
166
+ }),
167
+ },
168
+ };
169
+ }
170
+ }
@@ -3789,6 +3789,68 @@ export declare const v4: Elysia<"/v4", false, {
3789
3789
  };
3790
3790
  };
3791
3791
  };
3792
+ } & {
3793
+ v4: {
3794
+ referral: {
3795
+ code: {
3796
+ get: {
3797
+ body: unknown;
3798
+ params: {};
3799
+ query: {
3800
+ chainId: number;
3801
+ address: string;
3802
+ referralKey: string;
3803
+ };
3804
+ headers: unknown;
3805
+ response: {
3806
+ 200: {
3807
+ code: string;
3808
+ referrer: boolean;
3809
+ referredUsers: never[];
3810
+ transaction: {
3811
+ to: string;
3812
+ data: `0x${string}`;
3813
+ };
3814
+ } | {
3815
+ code: any;
3816
+ referrer: boolean;
3817
+ referredUsers: any;
3818
+ transaction?: undefined;
3819
+ };
3820
+ };
3821
+ };
3822
+ };
3823
+ };
3824
+ } & {
3825
+ referral: {
3826
+ redeem: {
3827
+ get: {
3828
+ body: unknown;
3829
+ params: {};
3830
+ query: {
3831
+ code: string;
3832
+ chainId: number;
3833
+ referralKey: string;
3834
+ };
3835
+ headers: unknown;
3836
+ response: {
3837
+ 200: {
3838
+ code: string;
3839
+ referrer: any;
3840
+ transaction?: undefined;
3841
+ } | {
3842
+ code: string;
3843
+ referrer: any;
3844
+ transaction: {
3845
+ to: string;
3846
+ data: `0x${string}`;
3847
+ };
3848
+ };
3849
+ };
3850
+ };
3851
+ };
3852
+ };
3853
+ };
3792
3854
  }, {
3793
3855
  derive: {};
3794
3856
  resolve: {};
@@ -27,6 +27,7 @@ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
27
27
  import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-node";
28
28
  import { PrismaInstrumentation } from "@prisma/instrumentation";
29
29
  import Elysia from "elysia";
30
+ import { ReferralController } from "./referral/referral.controller";
30
31
  // ─── V4 Router ───────────────────────────────────────────────────────────────
31
32
  export const v4 = new Elysia({ tags: ["v4"], prefix: "/v4" })
32
33
  // ─── OpenTelemetry ───────────────────────────────────────────────────
@@ -71,4 +72,5 @@ export const v4 = new Elysia({ tags: ["v4"], prefix: "/v4" })
71
72
  .use(ProgramPayloadController)
72
73
  .use(BoostController)
73
74
  .use(ComputedValueController)
74
- .use(CreatorController);
75
+ .use(CreatorController)
76
+ .use(ReferralController);
@@ -0,0 +1,3 @@
1
+ import { tokenType } from "../libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType";
2
+ import type { Campaign, CampaignParameters } from "@sdk";
3
+ export declare function generateIcons(type: tokenType, typeInfo: any, campaign: CampaignParameters<Campaign.ERC20> | CampaignParameters<Campaign.ERC20LOGPROCESSOR> | CampaignParameters<Campaign.ERC20REBASELOGPROCESSOR> | CampaignParameters<Campaign.EULER>, symbols?: string[]): string[];
@@ -0,0 +1,53 @@
1
+ import { tokenType } from "../libs/campaigns/campaignTypes/ERC20SubTypes/helpers/tokenType";
2
+ import { OpportunityAction } from "../../database/api/.generated";
3
+ export function generateIcons(type, typeInfo, campaign, symbols = [""]) {
4
+ const action = typeInfo.action ? typeInfo.action : "HOLD";
5
+ switch (action) {
6
+ case OpportunityAction.POOL:
7
+ switch (type) {
8
+ case tokenType.balancerGauge:
9
+ case tokenType.balancerPool:
10
+ case tokenType.aura:
11
+ return Object.values(typeInfo.poolTokens ?? {})
12
+ .map(tkn => tkn?.symbol)
13
+ .filter(tkn => tkn && !tkn.includes("/"));
14
+ case tokenType.curve:
15
+ case tokenType.curve_2:
16
+ case tokenType.crosscurve: {
17
+ const icons = [];
18
+ for (let i = 0; i < typeInfo.numberTokens; i++) {
19
+ if (typeInfo[`symbolToken${i}`])
20
+ icons.push(typeInfo[`symbolToken${i}`]);
21
+ }
22
+ return icons;
23
+ }
24
+ case tokenType.rfx_slv:
25
+ return [typeInfo.symbolAsset];
26
+ case tokenType.rfx:
27
+ return [typeInfo.symbolShortToken, typeInfo.symbolLongToken];
28
+ case tokenType.maverickBoostedPosition:
29
+ return [typeInfo.symbolTokenA, typeInfo.symbolTokenB];
30
+ default:
31
+ return [typeInfo.symbolToken0, typeInfo.symbolToken1];
32
+ }
33
+ case OpportunityAction.LEND:
34
+ switch (type) {
35
+ case tokenType.compound:
36
+ return [typeInfo.symbolBaseToken];
37
+ default:
38
+ return [typeInfo.symbolUnderlyingToken];
39
+ }
40
+ case OpportunityAction.BORROW:
41
+ return [typeInfo.symbolUnderlyingToken];
42
+ case OpportunityAction.HOLD:
43
+ switch (type) {
44
+ case tokenType.toros:
45
+ case tokenType.enzyme:
46
+ return [typeInfo.symbolUnderlyingToken];
47
+ default:
48
+ return [campaign.campaignParameters.symbolTargetToken];
49
+ }
50
+ default:
51
+ return [];
52
+ }
53
+ }