diff --git a/package.json b/package.json index 31d5907..d9d4a28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.16.1", + "version": "0.16.2-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 7473634..c75a860 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -1,6 +1,7 @@ import fetchWithValidation from '../../fetchWithValidation'; -import { errorSchema } from './schemas'; +import { errorSchema, miniStatsSchema, rewardsMappingSchema } from './schemas'; import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema'; +import globalAnalyticsSchema from './schemas/globalAnalyticsSchema'; import linkSchema from './schemas/linkSchema'; type CreateLinkPayloadType = { @@ -69,6 +70,31 @@ class ReferralSystem { }, ); + getGlobalAnalytics = () => fetchWithValidation( + `${this.apiUrl}/referer/view/global-analytics`, + globalAnalyticsSchema, + ); + + getMiniStats = (refererAddress: string) => fetchWithValidation( + `${this.apiUrl}/referer/view/mini-latest-stats`, + miniStatsSchema, + { + headers: { + 'referer-address': refererAddress, + }, + }, + ); + + getRewardsMapping = (referralAddress: string) => fetchWithValidation( + `${this.apiUrl}/referer/view/rewards-mapping`, + rewardsMappingSchema, + { + headers: { + referral: referralAddress, + }, + }, + ); + createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation( `${this.apiUrl}/referer/create`, linkSchema, diff --git a/src/services/ReferralSystem/schemas/globalAnalyticsSchema.ts b/src/services/ReferralSystem/schemas/globalAnalyticsSchema.ts new file mode 100644 index 0000000..1c10461 --- /dev/null +++ b/src/services/ReferralSystem/schemas/globalAnalyticsSchema.ts @@ -0,0 +1,11 @@ +import { z } from 'zod'; + +const globalAnalyticsSchema = z.object({ + ref_to_rewards: z.record(z.string(), z.number()), + total_earned_by_refs: z.number(), + total_sent_to_governance: z.number(), + reward_dist_count_in_general: z.record(z.string(), z.number()), + total_ref_system_actors: z.number(), +}); + +export default globalAnalyticsSchema; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index 8ea348a..9a5edf5 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -1,3 +1,5 @@ export { default as linkSchema } from './linkSchema'; export { default as distinctAnalyticsSchema } from './distinctAnalyticsSchema'; export { default as errorSchema } from './errorSchema'; +export { default as miniStatsSchema } from './miniStatsSchema'; +export { default as rewardsMappingSchema } from './rewardsMappingSchema'; diff --git a/src/services/ReferralSystem/schemas/miniStatsSchema.ts b/src/services/ReferralSystem/schemas/miniStatsSchema.ts new file mode 100644 index 0000000..97c2c8c --- /dev/null +++ b/src/services/ReferralSystem/schemas/miniStatsSchema.ts @@ -0,0 +1,12 @@ +import { z } from 'zod'; + +const miniStatsSchema = z.object({ + earned_on_referrals_orn: z.number(), + earned_on_referrals_usd: z.number(), + orn_usd: z.number(), + registered_via_link_count: z.number(), + earned_in_a_week_orn: z.number(), + earned_in_a_week_usd: z.number(), +}); + +export default miniStatsSchema; diff --git a/src/services/ReferralSystem/schemas/rewardsMappingSchema.ts b/src/services/ReferralSystem/schemas/rewardsMappingSchema.ts new file mode 100644 index 0000000..4075424 --- /dev/null +++ b/src/services/ReferralSystem/schemas/rewardsMappingSchema.ts @@ -0,0 +1,23 @@ +import { z } from 'zod'; + +const rewardsMappingSchema = z.array( + z.object({ + distribution: z.object({ + dist: z.object({ + orion: z.number(), + referers_list: z.array(z.number()), + }), + address_to_reward_mapping: z.record(z.string(), z.number()), + ref_offset_to_rewarded_actors: z.record(z.string(), z.string()), + governance_reward_only: z.number(), + total_reward: z.number(), + trade_initiator: z.string(), + }), + timestamp_ms: z.number(), + block_height: z.number(), + tx_hash: z.string(), + price_feed_meta_info: z.record(z.string(), z.record(z.string(), z.number())), + }), +); + +export default rewardsMappingSchema;