Merge remote-tracking branch 'origin/main' into feat/platform-fees

# Conflicts:
#	package.json
This commit is contained in:
Mikhail Gladchenko
2023-08-30 09:31:29 +01:00
9 changed files with 87 additions and 25 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.48-dev.6-rc-0",
"version": "0.19.76",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.19.48-dev.6-rc-0",
"version": "0.19.76",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {

View File

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

View File

@@ -64,7 +64,7 @@ export default async function generateSwapCalldata({
}
const wethAddress = safeGet(unit.contracts, "WETH")
const curveRegistryAddress = safeGet(unit.contracts, "curveRegistry")
const {assetToAddress, swapExecutorContractAddress, exchangeContractAddress} = await simpleFetch(unit.blockchainService.getInfo)();
const { assetToAddress, swapExecutorContractAddress, exchangeContractAddress } = await simpleFetch(unit.blockchainService.getInfo)();
let path = SafeArray.from(path_).map((swapInfo) => {
swapInfo.assetIn = safeGet(assetToAddress, swapInfo.assetIn);
swapInfo.assetOut = safeGet(assetToAddress, swapInfo.assetOut);
@@ -78,7 +78,7 @@ export default async function generateSwapCalldata({
const swapDescription: ExchangeWithGenericSwap.SwapDescriptionStruct = {
srcToken: path.first().assetIn,
dstToken: path.last().assetOut,
srcReceiver: swapExecutorContractAddress,
srcReceiver: swapExecutorContractAddress ?? '',
dstReceiver: receiverAddress,
amount: amount,
minReturnAmount: minReturnAmount,
@@ -127,7 +127,7 @@ export default async function generateSwapCalldata({
calldata = await generateCurveStableSwapCalls(
amountNativeDecimals,
exchangeContractAddress,
swapExecutorContractAddress,
swapExecutorContractAddress ?? '',
path,
unit.provider,
curveRegistryAddress

View File

@@ -122,7 +122,7 @@
"shortName": "Polygon Mumbai",
"code": "polygon",
"baseCurrencyName": "MATIC",
"rpc": "https://rpc-mumbai.matic.today",
"rpc": "https://rpc.ankr.com/polygon_mumbai",
"explorer": "https://mumbai.polygonscan.com/",
"contracts": {
"WETH": "",

View File

@@ -11,7 +11,7 @@ const infoSchema = z.object({
chainId: z.number(),
chainName: z.string(),
exchangeContractAddress: z.string(),
swapExecutorContractAddress: z.string(),
swapExecutorContractAddress: z.string().optional(),
oracleContractAddress: z.string(),
matcherAddress: z.string(),
orderFeePercent: z.number(),

View File

@@ -1,4 +1,4 @@
import {fetchWithValidation} from 'simple-typed-fetch';
import { fetchWithValidation } from 'simple-typed-fetch';
import {
errorSchema,
miniStatsSchema,
@@ -10,9 +10,10 @@ import {
ratingSchema,
claimInfoSchema,
aggregatedHistorySchema,
inviteCodeLinkSchema,
contractsAddressesSchema,
} from './schemas/index.js';
import {SupportedChainId} from "../../types.js";
import contractsAddressesSchema from './schemas/contractsAddressesSchema.js';
import type { SupportedChainId } from '../../types.js';
type CreateLinkPayloadType = {
referer: string
@@ -24,6 +25,11 @@ type ClaimRewardsPayload = {
chain_id: number
};
type SubmitInviteCodekWithLinkPayload = {
inviteCode: string
referer: string
};
type SubscribePayloadType = {
ref_target: string
referral: string
@@ -34,7 +40,7 @@ type SignatureType = {
};
class ReferralSystem {
private readonly apiUrl: string;
private readonly apiUrl: string
get api() {
return this.apiUrl;
@@ -48,6 +54,8 @@ class ReferralSystem {
this.createReferralLink = this.createReferralLink.bind(this);
this.subscribeToReferral = this.subscribeToReferral.bind(this);
this.getMyReferral = this.getMyReferral.bind(this);
this.getMyInviteCodeAndLink = this.getMyInviteCodeAndLink.bind(this);
this.submitInviteCodeWithLink = this.submitInviteCodeWithLink.bind(this);
this.getGlobalAnalytics = this.getGlobalAnalytics.bind(this);
this.getMiniStats = this.getMiniStats.bind(this);
this.getRewardsMapping = this.getRewardsMapping.bind(this);
@@ -73,6 +81,36 @@ class ReferralSystem {
},
});
getMyInviteCodeAndLink = (refererAddress: string, suppressError = false) =>
fetchWithValidation(
`${this.apiUrl}/referer/invite/status2?suppress_error=${Number(
suppressError
)}`,
inviteCodeLinkSchema,
{
headers: {
'referer-address': refererAddress,
},
}
);
submitInviteCodeWithLink = ({
inviteCode,
referer,
}: SubmitInviteCodekWithLinkPayload) =>
fetchWithValidation(
`${this.apiUrl}/referer/invite/submit-code2`,
inviteCodeLinkSchema,
{
headers: {
'Content-type': 'application/json',
'invite-code': inviteCode,
},
method: 'POST',
body: JSON.stringify({ referer }),
}
);
getDistinctAnalytics = (refererAddress: string) =>
fetchWithValidation(
`${this.apiUrl}/referer/view/distinct-analytics`,
@@ -130,13 +168,11 @@ class ReferralSystem {
'Content-type': 'application/json',
},
method: 'POST',
body: JSON.stringify({payload, signature}),
body: JSON.stringify({ payload, signature }),
}
);
createReferralLink = (
payload: CreateLinkPayloadType
) =>
createReferralLink = (payload: CreateLinkPayloadType) =>
fetchWithValidation(`${this.apiUrl}/referer/create2`, linkSchema, {
headers: {
'Content-type': 'application/json',
@@ -145,9 +181,7 @@ class ReferralSystem {
body: JSON.stringify(payload),
});
subscribeToReferral = (
payload: SubscribePayloadType
) =>
subscribeToReferral = (payload: SubscribePayloadType) =>
fetchWithValidation(
`${this.apiUrl}/referer/subscribe2`,
linkSchema,
@@ -166,7 +200,10 @@ class ReferralSystem {
`${this.apiUrl}/referer/ve/rating-table-leaderboard?chain_id=${chainId}`,
ratingSchema,
{
headers: refererAddress !== undefined ? {'referer-address': refererAddress} : {},
headers:
refererAddress !== undefined
? { 'referer-address': refererAddress }
: {},
},
errorSchema
);
@@ -201,7 +238,7 @@ class ReferralSystem {
const queryParams: Record<string, string | number> = {
n_per_page: itemPerPage,
page,
suppress_error: 1
suppress_error: 1,
};
if (chainId !== undefined) {
@@ -212,7 +249,9 @@ class ReferralSystem {
queryParams['history_filter'] = encodeURIComponent(types.join(','));
}
const queryString = Object.entries(queryParams).map(([k, v]) => `${k}=${v}`).join('&')
const queryString = Object.entries(queryParams)
.map(([k, v]) => `${k}=${v}`)
.join('&');
return fetchWithValidation(
`${this.apiUrl}/referer/view/aggregated-history?${queryString}`,
@@ -224,8 +263,8 @@ class ReferralSystem {
},
errorSchema
);
}
};
}
export * as schemas from './schemas/index.js';
export {ReferralSystem};
export { ReferralSystem };

View File

@@ -9,3 +9,4 @@ export { default as ratingSchema } from './ratingSchema.js';
export { default as claimInfoSchema } from './claimInfoSchema.js';
export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js';
export { default as contractsAddressesSchema } from './contractsAddressesSchema.js';
export { default as inviteCodeLinkSchema } from './inviteCodeLinkSchema.js';

View File

@@ -0,0 +1,23 @@
import { z } from 'zod';
const inviteCodeLinkSchema = z.object({
link: z
.object({
referer: z.string(),
ref_link: z.string(),
})
.nullable(),
invite: z
.object({
code: z.string(),
data: z.null(),
limits: z.object({
tag: z.string(),
max_invites: z.number(),
max_ref_depth: z.number(),
}),
})
.nullable(),
});
export default inviteCodeLinkSchema;

View File

@@ -3,7 +3,6 @@ import { z } from 'zod';
const linkSchema = z.object({
referer: z.string(),
ref_link: z.string(),
option: z.number(),
});
export default linkSchema;