feat: added methods to get referral system analytics

This commit is contained in:
kuduzow
2023-02-01 01:56:01 +03:00
parent a61e2c4c8a
commit fec435565d
6 changed files with 76 additions and 2 deletions

View File

@@ -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",

View File

@@ -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,

View 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;

View File

@@ -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';

View 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;

View 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;