Merge pull request #101 from orionprotocol/OP-3440.referral

OP-3440 - Referral updates
This commit is contained in:
demidn
2023-05-10 09:49:06 +03:00
committed by GitHub
4 changed files with 97 additions and 7864 deletions

7872
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.18.28",
"version": "0.18.29",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,4 +1,4 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import {fetchWithValidation} from 'simple-typed-fetch';
import {
errorSchema,
miniStatsSchema,
@@ -11,6 +11,7 @@ import {
claimInfoSchema,
aggregatedHistorySchema,
} from './schemas/index.js';
import {SupportedChainId} from "../../types.js";
type CreateLinkPayloadType = {
referer: string
@@ -127,7 +128,7 @@ class ReferralSystem {
'Content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify({ payload, signature }),
body: JSON.stringify({payload, signature}),
}
);
@@ -140,7 +141,7 @@ class ReferralSystem {
'Content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify({ payload, signature }),
body: JSON.stringify({payload, signature}),
});
subscribeToReferral = (
@@ -155,26 +156,24 @@ class ReferralSystem {
'Content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify({ payload, signature }),
body: JSON.stringify({payload, signature}),
},
errorSchema
);
getRating = (refererAddress: string) =>
getRating = (refererAddress: string | undefined, chainId: SupportedChainId) =>
fetchWithValidation(
`${this.apiUrl}/referer/ve/rating-table-leaderboard`,
`${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`,
ratingSchema,
{
headers: {
'referer-address': refererAddress,
},
headers: refererAddress !== undefined ? {'referer-address': refererAddress} : {},
},
errorSchema
);
getClamInfo = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/claim-info-with-stats`,
`${this.apiUrl}/referer/view/claim-info-with-stats?&suppress_error=1`,
claimInfoSchema,
{
headers: {
@@ -184,9 +183,31 @@ class ReferralSystem {
errorSchema
);
getAggregatedHistory = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history`,
getAggregatedHistory = (
refererAddress: string,
chainId: SupportedChainId | undefined,
types: string[] | undefined,
itemPerPage: number,
page: number
) => {
const queryParams: Record<string, string | number> = {
n_per_page: itemPerPage,
page,
suppress_error: 1
};
if (chainId !== undefined) {
queryParams['chain_id'] = chainId;
}
if (types !== undefined) {
queryParams['history_filter'] = encodeURIComponent(types.join(','));
}
const queryString = Object.entries(queryParams).map(([k, v]) => `${k}=${v}`).join('&')
return fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history?${queryString}`,
aggregatedHistorySchema,
{
headers: {
@@ -195,7 +216,8 @@ class ReferralSystem {
},
errorSchema
);
}
}
export * as schemas from './schemas/index.js';
export { ReferralSystem };
export {ReferralSystem};

View File

@@ -1,20 +1,25 @@
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()
}))
const aggregatedHistorySchema = z.object({
data: z.array(z.object({
history_type: z.string(),
chain_type: z.string(),
chain_comp: z.string(),
chain_id: z.number(),
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()
})),
pagination_info: z.object({
c_page: z.number(),
t_pages: z.number()
})
})
export default aggregatedHistorySchema;