mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
feat: claim rewards
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.17.28",
|
||||
"version": "0.17.29-rc.0",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
import { z } from 'zod';
|
||||
import fetchWithValidation from '../../fetchWithValidation';
|
||||
import { errorSchema, miniStatsSchema, rewardsMappingSchema } from './schemas';
|
||||
import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema';
|
||||
import globalAnalyticsSchema from './schemas/globalAnalyticsSchema';
|
||||
import linkSchema from './schemas/linkSchema';
|
||||
import {
|
||||
errorSchema,
|
||||
miniStatsSchema,
|
||||
rewardsMappingSchema,
|
||||
distinctAnalyticsSchema,
|
||||
globalAnalyticsSchema,
|
||||
rewardsClaimedSchema,
|
||||
linkSchema,
|
||||
} from './schemas';
|
||||
|
||||
type CreateLinkPayloadType = {
|
||||
referer: string
|
||||
link_option: number
|
||||
}
|
||||
};
|
||||
|
||||
type ClaimRewardsPayload = {
|
||||
reward_recipient: string
|
||||
chain_id: number
|
||||
};
|
||||
|
||||
type SubscribePayloadType = {
|
||||
ref_target: string
|
||||
referral: string
|
||||
}
|
||||
};
|
||||
|
||||
type SignatureType = {
|
||||
signature: string
|
||||
}
|
||||
};
|
||||
|
||||
class ReferralSystem {
|
||||
private readonly apiUrl: string;
|
||||
@@ -34,56 +43,58 @@ class ReferralSystem {
|
||||
this.createReferralLink = this.createReferralLink.bind(this);
|
||||
this.subscribeToReferral = this.subscribeToReferral.bind(this);
|
||||
this.getMyReferral = this.getMyReferral.bind(this);
|
||||
this.getGlobalAnalytics = this.getGlobalAnalytics.bind(this);
|
||||
this.getMiniStats = this.getMiniStats.bind(this);
|
||||
this.getRewardsMapping = this.getRewardsMapping.bind(this);
|
||||
this.claimRewards = this.claimRewards.bind(this);
|
||||
}
|
||||
|
||||
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,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
getDistinctAnalytics = (refererAddress: string) => fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/distinct-analytics`,
|
||||
distinctAnalyticsSchema,
|
||||
{
|
||||
getLink = (refererAddress: string) =>
|
||||
fetchWithValidation(`${this.apiUrl}/referer/view/link`, linkSchema, {
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
},
|
||||
errorSchema,
|
||||
);
|
||||
});
|
||||
|
||||
getGlobalAnalytics = () => fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/global-analytics`,
|
||||
globalAnalyticsSchema,
|
||||
);
|
||||
getMyReferral = (myWalletAddress: string) =>
|
||||
fetchWithValidation(`${this.apiUrl}/referral/view/link`, linkSchema, {
|
||||
headers: {
|
||||
referral: myWalletAddress,
|
||||
},
|
||||
});
|
||||
|
||||
getDistinctAnalytics = (refererAddress: string) =>
|
||||
fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/distinct-analytics`,
|
||||
distinctAnalyticsSchema,
|
||||
{
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
},
|
||||
errorSchema
|
||||
);
|
||||
|
||||
getGlobalAnalytics = () =>
|
||||
fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/global-analytics`,
|
||||
globalAnalyticsSchema
|
||||
);
|
||||
|
||||
/**
|
||||
* @param refererAddress Address without 0x prefix
|
||||
*/
|
||||
getMiniStats = (refererAddress: string) => fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/mini-latest-stats`,
|
||||
miniStatsSchema,
|
||||
{
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
getMiniStats = (refererAddress: string) =>
|
||||
fetchWithValidation(
|
||||
`${this.apiUrl}/referer/view/mini-latest-stats`,
|
||||
miniStatsSchema,
|
||||
{
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
},
|
||||
},
|
||||
z.object({
|
||||
status: z.string(),
|
||||
message: z.string(),
|
||||
}),
|
||||
);
|
||||
errorSchema
|
||||
);
|
||||
|
||||
getRewardsMapping = (
|
||||
referralAddress: string,
|
||||
@@ -97,33 +108,50 @@ class ReferralSystem {
|
||||
headers: {
|
||||
referral: referralAddress,
|
||||
},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/referer/create`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
);
|
||||
claimRewards = (payload: ClaimRewardsPayload, signature: SignatureType) =>
|
||||
fetchWithValidation(
|
||||
`${this.apiUrl}/referer/governance/claim-rewards`,
|
||||
rewardsClaimedSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
}
|
||||
);
|
||||
|
||||
subscribeToReferral = (payload: SubscribePayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/referer/subscribe`,
|
||||
linkSchema,
|
||||
{
|
||||
createReferralLink = (
|
||||
payload: CreateLinkPayloadType,
|
||||
signature: SignatureType
|
||||
) =>
|
||||
fetchWithValidation(`${this.apiUrl}/referer/create`, linkSchema, {
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
errorSchema,
|
||||
);
|
||||
});
|
||||
|
||||
subscribeToReferral = (
|
||||
payload: SubscribePayloadType,
|
||||
signature: SignatureType
|
||||
) =>
|
||||
fetchWithValidation(
|
||||
`${this.apiUrl}/referer/subscribe`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
errorSchema
|
||||
);
|
||||
}
|
||||
|
||||
export * as schemas from './schemas';
|
||||
|
||||
@@ -3,3 +3,5 @@ export { default as distinctAnalyticsSchema } from './distinctAnalyticsSchema';
|
||||
export { default as errorSchema } from './errorSchema';
|
||||
export { default as miniStatsSchema } from './miniStatsSchema';
|
||||
export { default as rewardsMappingSchema } from './rewardsMappingSchema';
|
||||
export { default as rewardsClaimedSchema } from './rewardsClaimedSchema';
|
||||
export { default as globalAnalyticsSchema } from './globalAnalyticsSchema';
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const rewardsClaimedSchema = z.object({
|
||||
referer: z.string(),
|
||||
amount: z.string(),
|
||||
signature: z.string(),
|
||||
});
|
||||
|
||||
export default rewardsClaimedSchema;
|
||||
Reference in New Issue
Block a user