mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Merge branch 'main' into OP-2812-show-order-route-path-and-benefits
# Conflicts: # package.json
This commit is contained in:
14
package.json
14
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.15.23-rc.2",
|
||||
"version": "0.15.25-rc.0",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
@@ -37,7 +37,7 @@
|
||||
"url": "https://github.com/orionprotocol/sdk/issues"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.11.15",
|
||||
"@types/node": "^18.11.9",
|
||||
"@types/socket.io-client": "1.4.33",
|
||||
"@types/uuid": "^8.3.4",
|
||||
"@types/ws": "^8.5.3",
|
||||
@@ -57,14 +57,14 @@
|
||||
"webpack-cli": "^4.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/abstract-signer": "^5.7.0",
|
||||
"@ethersproject/providers": "^5.7.2",
|
||||
"@ethersproject/abstract-signer": "^5.6.0",
|
||||
"@ethersproject/providers": "^5.6.2",
|
||||
"@lukeed/csprng": "^1.0.1",
|
||||
"@orionprotocol/contracts": "0.0.10",
|
||||
"bignumber.js": "^9.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"ethers": "^5.7.2",
|
||||
"ethers": "^5.6.2",
|
||||
"isomorphic-unfetch": "^3.1.0",
|
||||
"isomorphic-ws": "^5.0.0",
|
||||
"just-clone": "^5.0.1",
|
||||
@@ -72,8 +72,8 @@
|
||||
"stream-browserify": "^3.0.0",
|
||||
"tiny-invariant": "^1.2.0",
|
||||
"uuid": "^8.3.2",
|
||||
"ws": "^8.11.0",
|
||||
"zod": "^3.20.2"
|
||||
"ws": "^8.5.0",
|
||||
"zod": "^3.17.3"
|
||||
},
|
||||
"homepage": "https://github.com/orionprotocol/sdk#readme",
|
||||
"files": [
|
||||
|
||||
@@ -8,6 +8,7 @@ import Exchange from './Exchange';
|
||||
import FarmingManager from './FarmingManager';
|
||||
import { chains, envs } from '../config';
|
||||
import { isValidChainId } from '../utils';
|
||||
import { ReferralSystem } from '../services/ReferralSystem';
|
||||
|
||||
const orionAnalyticsUrl = 'https://trade.orionprotocol.io';
|
||||
|
||||
@@ -49,6 +50,8 @@ export default class OrionUnit {
|
||||
|
||||
public readonly apiUrl: string;
|
||||
|
||||
public readonly referralSystem: ReferralSystem;
|
||||
|
||||
constructor(
|
||||
chain: string,
|
||||
env: string,
|
||||
@@ -142,6 +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`);
|
||||
}
|
||||
|
||||
get siblings() {
|
||||
|
||||
73
src/services/ReferralSystem/index.ts
Normal file
73
src/services/ReferralSystem/index.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import fetchWithValidation from '../../fetchWithValidation';
|
||||
import distinctAnalyticsSchema from './schemas/distinctAnalyticsSchema';
|
||||
import linkSchema from './schemas/linkSchema';
|
||||
|
||||
type CreateLinkPayloadType = {
|
||||
referer: string;
|
||||
link_option: number;
|
||||
};
|
||||
|
||||
type SubscribePayloadType = {
|
||||
ref_target: string;
|
||||
referral: string;
|
||||
}
|
||||
|
||||
type SignatureType = {
|
||||
signature: string;
|
||||
};
|
||||
|
||||
class ReferralSystem {
|
||||
private apiUrl: string;
|
||||
|
||||
constructor(apiUrl: string) {
|
||||
this.apiUrl = apiUrl;
|
||||
|
||||
this.getLink = this.getLink.bind(this);
|
||||
this.getSubscribersList = this.getSubscribersList.bind(this);
|
||||
this.createReferralLink = this.createReferralLink.bind(this);
|
||||
this.subscribeToReferral = this.subscribeToReferral.bind(this);
|
||||
}
|
||||
|
||||
getLink = (refererAddress: string) => fetchWithValidation(`${this.apiUrl}/view/link`, linkSchema, {
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
});
|
||||
|
||||
getSubscribersList = (refererAddress: string) => fetchWithValidation(
|
||||
`${this.apiUrl}/view/distinct-analytics`,
|
||||
distinctAnalyticsSchema,
|
||||
{
|
||||
headers: {
|
||||
'referer-address': refererAddress,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
createReferralLink = (payload: CreateLinkPayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/create`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
);
|
||||
|
||||
subscribeToReferral = (payload: SubscribePayloadType, signature: SignatureType) => fetchWithValidation(
|
||||
`${this.apiUrl}/subscribe`,
|
||||
linkSchema,
|
||||
{
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ payload, signature }),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export * as schemas from './schemas';
|
||||
export { ReferralSystem };
|
||||
@@ -0,0 +1,17 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const distinctAnalyticsSchema = z.object({
|
||||
referer: z.string(),
|
||||
|
||||
refs_info: z.array(
|
||||
z.object({
|
||||
referral_address: z.string(),
|
||||
referral_earned_fees: z.number(),
|
||||
referer_earned_fees: z.number(),
|
||||
relative_ref_level: z.number(),
|
||||
timestamp: z.number(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export default distinctAnalyticsSchema;
|
||||
2
src/services/ReferralSystem/schemas/index.ts
Normal file
2
src/services/ReferralSystem/schemas/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { default as linkSchema } from './linkSchema';
|
||||
export { default as distinctAnalyticsSchema } from './distinctAnalyticsSchema';
|
||||
9
src/services/ReferralSystem/schemas/linkSchema.ts
Normal file
9
src/services/ReferralSystem/schemas/linkSchema.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const linkSchema = z.object({
|
||||
referer: z.string(),
|
||||
ref_link: z.string(),
|
||||
option: z.number(),
|
||||
});
|
||||
|
||||
export default linkSchema;
|
||||
Reference in New Issue
Block a user