From 3aa49b43e3d424a5f932a4f35ae59471c34d7cd1 Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Mon, 28 Aug 2023 08:31:21 +0300 Subject: [PATCH 01/12] Referral: Add invite code --- package.json | 2 +- src/services/ReferralSystem/index.ts | 71 ++++++++++++++----- src/services/ReferralSystem/schemas/index.ts | 1 + .../schemas/inviteCodeLinkSchema.ts | 24 +++++++ 4 files changed, 81 insertions(+), 17 deletions(-) create mode 100644 src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts diff --git a/package.json b/package.json index ec6f57c..baca832 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.70", + "version": "0.19.70-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 0a8aff0..7ce4cc4 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -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,12 @@ type ClaimRewardsPayload = { chain_id: number }; +type SubmitInviteCodekWithLinkPayload = { + inviteCode: string + referer: string + linkOption: number +}; + type SubscribePayloadType = { ref_target: string referral: string @@ -34,7 +41,7 @@ type SignatureType = { }; class ReferralSystem { - private readonly apiUrl: string; + private readonly apiUrl: string get api() { return this.apiUrl; @@ -48,6 +55,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 +82,35 @@ class ReferralSystem { }, }); + getMyInviteCodeAndLink = (refererAddress: string) => + fetchWithValidation( + `${this.apiUrl}/referer/invite/status2`, + inviteCodeLinkSchema, + { + headers: { + 'referer-address': refererAddress, + }, + } + ); + + submitInviteCodeWithLink = ({ + inviteCode, + referer, + linkOption, + }: SubmitInviteCodekWithLinkPayload) => + fetchWithValidation( + `${this.apiUrl}/referer/invite/submit-code2`, + inviteCodeLinkSchema, + { + headers: { + 'Content-type': 'application/json', + 'invite-code': inviteCode, + }, + method: 'POST', + body: JSON.stringify({ referer, link_option: linkOption }), + } + ); + 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 = { 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 }; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index c181860..f1a1391 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -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'; diff --git a/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts b/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts new file mode 100644 index 0000000..78ca8ac --- /dev/null +++ b/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts @@ -0,0 +1,24 @@ +import { z } from 'zod'; + +const inviteCodeLinkSchema = z.object({ + link: z + .object({ + referer: z.string(), + ref_link: z.string(), + option: z.number(), + }) + .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; From a787c9b8dd879792aeec3311d87f43ac9b75de9d Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Mon, 28 Aug 2023 08:53:43 +0300 Subject: [PATCH 02/12] Referral: Update invite code --- package.json | 2 +- src/services/ReferralSystem/index.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index baca832..bbed3e3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.70-rc1", + "version": "0.19.70-rc2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 7ce4cc4..3dc0640 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -29,6 +29,7 @@ type SubmitInviteCodekWithLinkPayload = { inviteCode: string referer: string linkOption: number + suppressError: boolean }; type SubscribePayloadType = { @@ -97,6 +98,7 @@ class ReferralSystem { inviteCode, referer, linkOption, + suppressError, }: SubmitInviteCodekWithLinkPayload) => fetchWithValidation( `${this.apiUrl}/referer/invite/submit-code2`, @@ -107,7 +109,11 @@ class ReferralSystem { 'invite-code': inviteCode, }, method: 'POST', - body: JSON.stringify({ referer, link_option: linkOption }), + body: JSON.stringify({ + referer, + link_option: linkOption, + suppress_error: Number(suppressError), + }), } ); From b226d8e72c1afab56eb874676d4ba72f9584e8bb Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Mon, 28 Aug 2023 09:05:38 +0300 Subject: [PATCH 03/12] Referral: Fix invite code --- package.json | 2 +- src/services/ReferralSystem/index.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bbed3e3..3704ec6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.70-rc2", + "version": "0.19.70-rc3", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 3dc0640..59c4499 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -29,7 +29,6 @@ type SubmitInviteCodekWithLinkPayload = { inviteCode: string referer: string linkOption: number - suppressError: boolean }; type SubscribePayloadType = { @@ -83,9 +82,11 @@ class ReferralSystem { }, }); - getMyInviteCodeAndLink = (refererAddress: string) => + getMyInviteCodeAndLink = (refererAddress: string, suppressError = false) => fetchWithValidation( - `${this.apiUrl}/referer/invite/status2`, + `${this.apiUrl}/referer/invite/status2?suppress_error=${Number( + suppressError + )}`, inviteCodeLinkSchema, { headers: { @@ -98,7 +99,6 @@ class ReferralSystem { inviteCode, referer, linkOption, - suppressError, }: SubmitInviteCodekWithLinkPayload) => fetchWithValidation( `${this.apiUrl}/referer/invite/submit-code2`, @@ -112,7 +112,6 @@ class ReferralSystem { body: JSON.stringify({ referer, link_option: linkOption, - suppress_error: Number(suppressError), }), } ); From bf3d3e2765fa4ecac7e90be507650c2704ae2f93 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 28 Aug 2023 13:43:05 +0300 Subject: [PATCH 04/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3704ec6..3ff9055 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.70-rc3", + "version": "0.19.71", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 8a31ac8dc4796e6b034f84551b699e67ecd4b053 Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Mon, 28 Aug 2023 14:40:40 +0300 Subject: [PATCH 05/12] Referral update --- src/services/ReferralSystem/index.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 59c4499..7711906 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -28,7 +28,6 @@ type ClaimRewardsPayload = { type SubmitInviteCodekWithLinkPayload = { inviteCode: string referer: string - linkOption: number }; type SubscribePayloadType = { @@ -98,7 +97,6 @@ class ReferralSystem { submitInviteCodeWithLink = ({ inviteCode, referer, - linkOption, }: SubmitInviteCodekWithLinkPayload) => fetchWithValidation( `${this.apiUrl}/referer/invite/submit-code2`, @@ -109,10 +107,7 @@ class ReferralSystem { 'invite-code': inviteCode, }, method: 'POST', - body: JSON.stringify({ - referer, - link_option: linkOption, - }), + body: JSON.stringify({ referer }), } ); From 44a478a4f6c3959138ddb639b3f944f208a21810 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Mon, 28 Aug 2023 14:41:21 +0300 Subject: [PATCH 06/12] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ff9055..1e33656 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.71", + "version": "0.19.72", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From a7b3a83fbf5588dc679e5bbc2204a463360ba743 Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Mon, 28 Aug 2023 15:32:07 +0300 Subject: [PATCH 07/12] Referral schema update --- package.json | 2 +- src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 1e33656..2e51c1f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.72", + "version": "0.19.73", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts b/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts index 78ca8ac..248ff96 100644 --- a/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts +++ b/src/services/ReferralSystem/schemas/inviteCodeLinkSchema.ts @@ -5,7 +5,6 @@ const inviteCodeLinkSchema = z.object({ .object({ referer: z.string(), ref_link: z.string(), - option: z.number(), }) .nullable(), invite: z From 3e2d87a3fd5bc843697f1cecb06e0ea5de167da2 Mon Sep 17 00:00:00 2001 From: lomonoshka Date: Tue, 29 Aug 2023 17:26:12 +0400 Subject: [PATCH 08/12] Changed polygon mumbai rpc --- src/config/chains.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/chains.json b/src/config/chains.json index bddd7fb..7fd6966 100644 --- a/src/config/chains.json +++ b/src/config/chains.json @@ -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": "", From 12375f4d5b119b48d088b4378e6f295714aa780c Mon Sep 17 00:00:00 2001 From: lomonoshka Date: Tue, 29 Aug 2023 17:26:41 +0400 Subject: [PATCH 09/12] bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e51c1f..437e057 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.73", + "version": "0.19.74", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 841ad83888053340b7c680e2d331480d563c4bc5 Mon Sep 17 00:00:00 2001 From: Dmitry Leleko Date: Tue, 29 Aug 2023 19:57:58 +0300 Subject: [PATCH 10/12] Update referral linkSchema --- package.json | 2 +- src/services/ReferralSystem/schemas/linkSchema.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 437e057..5b3fff9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.74", + "version": "0.19.75", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/ReferralSystem/schemas/linkSchema.ts b/src/services/ReferralSystem/schemas/linkSchema.ts index 2e9022b..20545f2 100644 --- a/src/services/ReferralSystem/schemas/linkSchema.ts +++ b/src/services/ReferralSystem/schemas/linkSchema.ts @@ -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; From 1fec02f0dae9212b1562a013edf999d7ef6913b7 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Wed, 30 Aug 2023 10:48:14 +0300 Subject: [PATCH 11/12] update schema --- package-lock.json | 4 ++-- package.json | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 4 ++-- src/services/BlockchainService/schemas/infoSchema.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index ccf76bd..cb6ad22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index 5b3fff9..47623c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.75", + "version": "0.19.76", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index bf18f6e..5c48375 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -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); @@ -235,7 +235,7 @@ async function generateOrion3Calls( async function generateCurveStableSwapCalls( amount: BigNumberish, exchangeContractAddress: string, - executorAddress: string, + executorAddress: string | undefined, path: SafeArray, provider: ethers.providers.JsonRpcProvider, curveRegistry: string diff --git a/src/services/BlockchainService/schemas/infoSchema.ts b/src/services/BlockchainService/schemas/infoSchema.ts index 472a895..2c9ef32 100644 --- a/src/services/BlockchainService/schemas/infoSchema.ts +++ b/src/services/BlockchainService/schemas/infoSchema.ts @@ -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(), From b6266a78f03d833f8d57910d1a904198c70a9f17 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Wed, 30 Aug 2023 10:59:39 +0300 Subject: [PATCH 12/12] fix --- package.json | 2 +- src/Unit/Exchange/generateSwapCalldata.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 47623c1..cebbbfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.76", + "version": "0.19.77", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Unit/Exchange/generateSwapCalldata.ts b/src/Unit/Exchange/generateSwapCalldata.ts index 5c48375..e96b992 100644 --- a/src/Unit/Exchange/generateSwapCalldata.ts +++ b/src/Unit/Exchange/generateSwapCalldata.ts @@ -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 @@ -235,7 +235,7 @@ async function generateOrion3Calls( async function generateCurveStableSwapCalls( amount: BigNumberish, exchangeContractAddress: string, - executorAddress: string | undefined, + executorAddress: string, path: SafeArray, provider: ethers.providers.JsonRpcProvider, curveRegistry: string