From ff1725b5fb85d52ac87d118bebfd7f31507c21e9 Mon Sep 17 00:00:00 2001 From: Demid Date: Fri, 14 Apr 2023 09:34:50 +0300 Subject: [PATCH] Referral schema / request updates --- package-lock.json | 4 +-- package.json | 2 +- src/services/ReferralSystem/index.ts | 30 ++++++++++++++++++ .../schemas/aggregatedHistorySchema.ts | 20 ++++++++++++ .../ReferralSystem/schemas/claimInfoSchema.ts | 31 +++++++++++++++++++ src/services/ReferralSystem/schemas/index.ts | 2 ++ 6 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts create mode 100644 src/services/ReferralSystem/schemas/claimInfoSchema.ts diff --git a/package-lock.json b/package-lock.json index c3a0b1b..a528e4c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.18.14", + "version": "0.18.16", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.18.14", + "version": "0.18.16", "license": "ISC", "dependencies": { "@babel/runtime": "^7.21.0", diff --git a/package.json b/package.json index 88569aa..2fa71f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.18.15", + "version": "0.18.16", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index cbb4aeb..376f2b5 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -8,6 +8,8 @@ import { rewardsClaimedSchema, linkSchema, ratingSchema, + claimInfoSchema, + aggregatedHistorySchema, } from './schemas/index.js'; type CreateLinkPayloadType = { @@ -48,6 +50,10 @@ class ReferralSystem { this.getMiniStats = this.getMiniStats.bind(this); this.getRewardsMapping = this.getRewardsMapping.bind(this); this.claimRewards = this.claimRewards.bind(this); + this.getRating = this.getRating.bind(this); + this.getRating = this.getRating.bind(this); + this.getClamInfo = this.getClamInfo.bind(this); + this.getAggregatedHistory = this.getAggregatedHistory.bind(this); } getLink = (refererAddress: string) => @@ -161,6 +167,30 @@ class ReferralSystem { {}, errorSchema ); + + getClamInfo = (refererAddress: string) => + fetchWithValidation( + `${this.apiUrl}/referer/view/claim-info-with-stats`, + claimInfoSchema, + { + headers: { + 'referer-address': refererAddress, + }, + }, + errorSchema + ); + + getAggregatedHistory = (refererAddress: string) => + fetchWithValidation( + `${this.apiUrl}/referer/view/aggregated-history`, + aggregatedHistorySchema, + { + headers: { + 'referer-address': refererAddress, + }, + }, + errorSchema + ); } export * as schemas from './schemas/index.js'; diff --git a/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts b/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts new file mode 100644 index 0000000..648e2d9 --- /dev/null +++ b/src/services/ReferralSystem/schemas/aggregatedHistorySchema.ts @@ -0,0 +1,20 @@ +import { z } from 'zod'; + +const aggregatedHistorySchema = z.array(z.object({ + history_type: z.object({ + RewardDistribution: z.string() + }), + chain_type: z.string(), + chain_comp: z.string(), + date_unix: z.number(), + date_time_local: z.string(), + date_time_utc: z.string(), + amount_orn: z.string(), + amount_orn_fmt: z.number(), + amount_usd: z.string(), + amount_usd_fmt: z.number(), + orn_price: z.string(), + orn_price_fmt: z.number() +})) + +export default aggregatedHistorySchema; diff --git a/src/services/ReferralSystem/schemas/claimInfoSchema.ts b/src/services/ReferralSystem/schemas/claimInfoSchema.ts new file mode 100644 index 0000000..7ed1135 --- /dev/null +++ b/src/services/ReferralSystem/schemas/claimInfoSchema.ts @@ -0,0 +1,31 @@ +import { z } from 'zod'; + +const claimInfoSchema = z.object({ + global: z.object({ + total_non_accrued: z.number(), + total_non_accrued_orn: z.number(), + total_non_accrued_usd: z.number() + }), + chain_to_reward_info: z.record( + z.string(), + z.object({ + total_accrued: z.number(), + total_accrued_orn: z.number(), + total_accrued_usd: z.number(), + total_non_accrued: z.number(), + total_non_accrued_orn: z.number(), + total_non_accrued_usd: z.number(), + total_earned: z.number() + }) + ), + mini_stats: 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 claimInfoSchema; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index 434f7a3..cc96dce 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -6,3 +6,5 @@ export { default as rewardsMappingSchema } from './rewardsMappingSchema.js'; export { default as rewardsClaimedSchema } from './rewardsClaimedSchema.js'; export { default as globalAnalyticsSchema } from './globalAnalyticsSchema.js'; export { default as ratingSchema } from './ratingSchema.js'; +export { default as claimInfoSchema } from './claimInfoSchema.js'; +export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js';