mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
feat: added methods to get referral system analytics
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
11
src/services/ReferralSystem/schemas/globalAnalyticsSchema.ts
Normal file
11
src/services/ReferralSystem/schemas/globalAnalyticsSchema.ts
Normal file
@@ -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;
|
||||
@@ -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';
|
||||
|
||||
12
src/services/ReferralSystem/schemas/miniStatsSchema.ts
Normal file
12
src/services/ReferralSystem/schemas/miniStatsSchema.ts
Normal file
@@ -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;
|
||||
23
src/services/ReferralSystem/schemas/rewardsMappingSchema.ts
Normal file
23
src/services/ReferralSystem/schemas/rewardsMappingSchema.ts
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user