diff --git a/package.json b/package.json index cab4618..2a14fad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.17.28", + "version": "0.17.29-rc.0", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 790e4d9..8da976c 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -1,23 +1,32 @@ -import { z } from 'zod'; import fetchWithValidation from '../../fetchWithValidation'; -import { errorSchema, miniStatsSchema, rewardsMappingSchema } from './schemas'; -import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema'; -import globalAnalyticsSchema from './schemas/globalAnalyticsSchema'; -import linkSchema from './schemas/linkSchema'; +import { + errorSchema, + miniStatsSchema, + rewardsMappingSchema, + distinctAnalyticsSchema, + globalAnalyticsSchema, + rewardsClaimedSchema, + linkSchema, +} from './schemas'; type CreateLinkPayloadType = { referer: string link_option: number -} +}; + +type ClaimRewardsPayload = { + reward_recipient: string + chain_id: number +}; type SubscribePayloadType = { ref_target: string referral: string -} +}; type SignatureType = { signature: string -} +}; class ReferralSystem { private readonly apiUrl: string; @@ -34,56 +43,58 @@ class ReferralSystem { this.createReferralLink = this.createReferralLink.bind(this); this.subscribeToReferral = this.subscribeToReferral.bind(this); this.getMyReferral = this.getMyReferral.bind(this); + this.getGlobalAnalytics = this.getGlobalAnalytics.bind(this); + this.getMiniStats = this.getMiniStats.bind(this); + this.getRewardsMapping = this.getRewardsMapping.bind(this); + this.claimRewards = this.claimRewards.bind(this); } - getLink = (refererAddress: string) => fetchWithValidation(`${this.apiUrl}/referer/view/link`, linkSchema, { - headers: { - 'referer-address': refererAddress, - }, - }); - - getMyReferral = (myWalletAddress: string) => fetchWithValidation( - `${this.apiUrl}/referral/view/link`, - linkSchema, - { - headers: { - referral: myWalletAddress, - }, - }, - ); - - getDistinctAnalytics = (refererAddress: string) => fetchWithValidation( - `${this.apiUrl}/referer/view/distinct-analytics`, - distinctAnalyticsSchema, - { + getLink = (refererAddress: string) => + fetchWithValidation(`${this.apiUrl}/referer/view/link`, linkSchema, { headers: { 'referer-address': refererAddress, }, - }, - errorSchema, - ); + }); - getGlobalAnalytics = () => fetchWithValidation( - `${this.apiUrl}/referer/view/global-analytics`, - globalAnalyticsSchema, - ); + getMyReferral = (myWalletAddress: string) => + fetchWithValidation(`${this.apiUrl}/referral/view/link`, linkSchema, { + headers: { + referral: myWalletAddress, + }, + }); + + getDistinctAnalytics = (refererAddress: string) => + fetchWithValidation( + `${this.apiUrl}/referer/view/distinct-analytics`, + distinctAnalyticsSchema, + { + headers: { + 'referer-address': refererAddress, + }, + }, + errorSchema + ); + + getGlobalAnalytics = () => + fetchWithValidation( + `${this.apiUrl}/referer/view/global-analytics`, + globalAnalyticsSchema + ); /** * @param refererAddress Address without 0x prefix */ - getMiniStats = (refererAddress: string) => fetchWithValidation( - `${this.apiUrl}/referer/view/mini-latest-stats`, - miniStatsSchema, - { - headers: { - 'referer-address': refererAddress, + getMiniStats = (refererAddress: string) => + fetchWithValidation( + `${this.apiUrl}/referer/view/mini-latest-stats`, + miniStatsSchema, + { + headers: { + 'referer-address': refererAddress, + }, }, - }, - z.object({ - status: z.string(), - message: z.string(), - }), - ); + errorSchema + ); getRewardsMapping = ( referralAddress: string, @@ -97,33 +108,50 @@ class ReferralSystem { headers: { referral: referralAddress, }, - }, + } ); - createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation( - `${this.apiUrl}/referer/create`, - linkSchema, - { - headers: { - 'Content-type': 'application/json', - }, - method: 'POST', - body: JSON.stringify({ payload, signature }), - }, - ); + claimRewards = (payload: ClaimRewardsPayload, signature: SignatureType) => + fetchWithValidation( + `${this.apiUrl}/referer/governance/claim-rewards`, + rewardsClaimedSchema, + { + headers: { + 'Content-type': 'application/json', + }, + method: 'POST', + body: JSON.stringify({ payload, signature }), + } + ); - subscribeToReferral = (payload: SubscribePayloadType, signature: SignatureType) => fetchWithValidation( - `${this.apiUrl}/referer/subscribe`, - linkSchema, - { + createReferralLink = ( + payload: CreateLinkPayloadType, + signature: SignatureType + ) => + fetchWithValidation(`${this.apiUrl}/referer/create`, linkSchema, { headers: { 'Content-type': 'application/json', }, method: 'POST', body: JSON.stringify({ payload, signature }), - }, - errorSchema, - ); + }); + + subscribeToReferral = ( + payload: SubscribePayloadType, + signature: SignatureType + ) => + fetchWithValidation( + `${this.apiUrl}/referer/subscribe`, + linkSchema, + { + headers: { + 'Content-type': 'application/json', + }, + method: 'POST', + body: JSON.stringify({ payload, signature }), + }, + errorSchema + ); } export * as schemas from './schemas'; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index 9a5edf5..2578222 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -3,3 +3,5 @@ export { default as distinctAnalyticsSchema } from './distinctAnalyticsSchema'; export { default as errorSchema } from './errorSchema'; export { default as miniStatsSchema } from './miniStatsSchema'; export { default as rewardsMappingSchema } from './rewardsMappingSchema'; +export { default as rewardsClaimedSchema } from './rewardsClaimedSchema'; +export { default as globalAnalyticsSchema } from './globalAnalyticsSchema'; diff --git a/src/services/ReferralSystem/schemas/rewardsClaimedSchema.ts b/src/services/ReferralSystem/schemas/rewardsClaimedSchema.ts new file mode 100644 index 0000000..ef47199 --- /dev/null +++ b/src/services/ReferralSystem/schemas/rewardsClaimedSchema.ts @@ -0,0 +1,9 @@ +import { z } from 'zod'; + +const rewardsClaimedSchema = z.object({ + referer: z.string(), + amount: z.string(), + signature: z.string(), +}); + +export default rewardsClaimedSchema;