Merge branch 'main' into futures_list

# Conflicts:
#	package.json
This commit is contained in:
Mikhail Gladchenko
2023-01-24 12:19:56 +00:00
4 changed files with 39 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.16.0-rc.24",
"version": "0.16.0-rc.25",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -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() {

View File

@@ -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: {

View File

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