diff --git a/package.json b/package.json index eb48507..898a692 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "@orionprotocol/sdk", - "version": "0.15.29", + "name": "@orionprotocol/sdk", + "version": "0.15.27-rc.7", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/OrionUnit/index.ts b/src/OrionUnit/index.ts index 7e8c720..b991580 100644 --- a/src/OrionUnit/index.ts +++ b/src/OrionUnit/index.ts @@ -145,7 +145,7 @@ export default class OrionUnit { this.orionAnalytics = new OrionAnalytics(orionAnalyticsUrl); this.exchange = new Exchange(this); this.farmingManager = new FarmingManager(this); - this.referralSystem = new ReferralSystem(`${options?.api ?? customApi}/referral-api/referer`); + this.referralSystem = new ReferralSystem(options?.api ?? customApi, env); } get siblings() { diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 7db8219..81c698a 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -19,23 +19,47 @@ type SignatureType = { class ReferralSystem { private apiUrl: string; - constructor(apiUrl: string) { - this.apiUrl = apiUrl; + constructor(apiUrl: string, env: string) { + this.apiUrl = ReferralSystem.getActualApiUrl(apiUrl, env); this.getLink = this.getLink.bind(this); this.getSubscribersList = this.getSubscribersList.bind(this); this.createReferralLink = this.createReferralLink.bind(this); this.subscribeToReferral = this.subscribeToReferral.bind(this); + this.getMyReferral = this.getMyReferral.bind(this); } - getLink = (refererAddress: string) => fetchWithValidation(`${this.apiUrl}/view/link`, linkSchema, { + // ресурсы реферальной системы в тестинг окружении имеют вид + // testing.orionprotocol.io/referral-api вместо обычного + // testing.orionprotocol.io/bsc-testnet/referral-api, поэтому лишняя часть вырезается + static getActualApiUrl = (apiUrl: string, env: string) => { + if (env === 'testing' || env === 'custom') { + const { protocol, hostname } = new URL(apiUrl); + + return `${protocol}//${hostname}/referral-api`; + } + + return `${apiUrl}/referral-api`; + }; + + 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, + }, + }, + ); + getSubscribersList = (refererAddress: string) => fetchWithValidation( - `${this.apiUrl}/view/distinct-analytics`, + `${this.apiUrl}/referer/view/distinct-analytics`, distinctAnalyticsSchema, { headers: { @@ -45,7 +69,7 @@ class ReferralSystem { ); createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation( - `${this.apiUrl}/create`, + `${this.apiUrl}/referer/create`, linkSchema, { headers: { @@ -57,7 +81,7 @@ class ReferralSystem { ); subscribeToReferral = (payload: SubscribePayloadType, signature: SignatureType) => fetchWithValidation( - `${this.apiUrl}/subscribe`, + `${this.apiUrl}/referer/subscribe`, linkSchema, { headers: { diff --git a/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts b/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts index bd5ded8..620aef0 100644 --- a/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts +++ b/src/services/ReferralSystem/schemas/distinctAnalyticsSchema.ts @@ -2,16 +2,21 @@ import { z } from 'zod'; const distinctAnalyticsSchema = z.object({ referer: z.string(), - - refs_info: z.array( + refs_info: z.record( + z.string(), z.object({ referral_address: z.string(), referral_earned_fees: z.number(), referer_earned_fees: z.number(), relative_ref_level: z.number(), + reward_record_hash: z.string(), timestamp: z.number(), + latest_timestamp: z.number(), + latest_block: z.number(), }), ), + total_earned: z.number(), + total_sent_to_governance: z.number(), }); export default distinctAnalyticsSchema;