From 31f6985a647d2af98fb4b98d8a880782bf7b9c8c Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Fri, 16 Jun 2023 09:24:28 +0300 Subject: [PATCH 1/3] feat: fetch referral contract addresses --- package.json | 4 ++-- src/services/ReferralSystem/index.ts | 14 ++++++++++++-- .../schemas/getContractsAddressesSchema.ts | 10 ++++++++++ src/services/ReferralSystem/schemas/index.ts | 1 + 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts diff --git a/package.json b/package.json index 343572d..f53fe14 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.24", + "version": "0.19.26-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", @@ -108,4 +108,4 @@ "overrides": { "tsconfig-paths": "^4.0.0" } -} \ No newline at end of file +} diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 2cf3905..d6bcab4 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -12,6 +12,7 @@ import { aggregatedHistorySchema, } from './schemas/index.js'; import {SupportedChainId} from "../../types.js"; +import getContractsAddressesSchema from './schemas/getContractsAddressesSchema.js'; type CreateLinkPayloadType = { referer: string @@ -53,7 +54,8 @@ class ReferralSystem { this.claimRewards = this.claimRewards.bind(this); this.getRating = this.getRating.bind(this); this.getRating = this.getRating.bind(this); - this.getClamInfo = this.getClamInfo.bind(this); + this.getContractsAddresses = this.getContractsAddresses.bind(this); + this.getClaimInfo = this.getClaimInfo.bind(this); this.getAggregatedHistory = this.getAggregatedHistory.bind(this); } @@ -169,7 +171,15 @@ class ReferralSystem { errorSchema ); - getClamInfo = (refererAddress: string) => + getContractsAddresses = () => + fetchWithValidation( + `${this.apiUrl}/referer/view/contracts`, + getContractsAddressesSchema, + undefined, + errorSchema + ); + + getClaimInfo = (refererAddress: string) => fetchWithValidation( `${this.apiUrl}/referer/view/claim-info-with-stats?&suppress_error=1`, claimInfoSchema, diff --git a/src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts b/src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts new file mode 100644 index 0000000..399a2d1 --- /dev/null +++ b/src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts @@ -0,0 +1,10 @@ +import { z } from 'zod'; +import { SupportedChainId } from '../../../types.js'; +import { isAddress } from 'ethers/lib/utils.js'; + +const getContractsAddressesSchema = z.record( + z.nativeEnum(SupportedChainId), + z.string().refine(isAddress) +); + +export default getContractsAddressesSchema; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index cc96dce..1edcd87 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -8,3 +8,4 @@ export { default as globalAnalyticsSchema } from './globalAnalyticsSchema.js'; export { default as ratingSchema } from './ratingSchema.js'; export { default as claimInfoSchema } from './claimInfoSchema.js'; export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js'; +export { default as getContractsAddressesSchema } from './getContractsAddressesSchema.js'; From c80d0d990d8754b8c01da8ca8f6a0fcb1d2475aa Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Fri, 16 Jun 2023 16:36:29 +0300 Subject: [PATCH 2/3] fix: change schema name --- src/services/ReferralSystem/index.ts | 4 ++-- ...ontractsAddressesSchema.ts => contractsAddressesSchema.ts} | 4 ++-- src/services/ReferralSystem/schemas/index.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) rename src/services/ReferralSystem/schemas/{getContractsAddressesSchema.ts => contractsAddressesSchema.ts} (68%) diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index d6bcab4..0a8aff0 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -12,7 +12,7 @@ import { aggregatedHistorySchema, } from './schemas/index.js'; import {SupportedChainId} from "../../types.js"; -import getContractsAddressesSchema from './schemas/getContractsAddressesSchema.js'; +import contractsAddressesSchema from './schemas/contractsAddressesSchema.js'; type CreateLinkPayloadType = { referer: string @@ -174,7 +174,7 @@ class ReferralSystem { getContractsAddresses = () => fetchWithValidation( `${this.apiUrl}/referer/view/contracts`, - getContractsAddressesSchema, + contractsAddressesSchema, undefined, errorSchema ); diff --git a/src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts b/src/services/ReferralSystem/schemas/contractsAddressesSchema.ts similarity index 68% rename from src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts rename to src/services/ReferralSystem/schemas/contractsAddressesSchema.ts index 399a2d1..caa3a85 100644 --- a/src/services/ReferralSystem/schemas/getContractsAddressesSchema.ts +++ b/src/services/ReferralSystem/schemas/contractsAddressesSchema.ts @@ -2,9 +2,9 @@ import { z } from 'zod'; import { SupportedChainId } from '../../../types.js'; import { isAddress } from 'ethers/lib/utils.js'; -const getContractsAddressesSchema = z.record( +const contractsAddressesSchema = z.record( z.nativeEnum(SupportedChainId), z.string().refine(isAddress) ); -export default getContractsAddressesSchema; +export default contractsAddressesSchema; diff --git a/src/services/ReferralSystem/schemas/index.ts b/src/services/ReferralSystem/schemas/index.ts index 1edcd87..c181860 100644 --- a/src/services/ReferralSystem/schemas/index.ts +++ b/src/services/ReferralSystem/schemas/index.ts @@ -8,4 +8,4 @@ export { default as globalAnalyticsSchema } from './globalAnalyticsSchema.js'; export { default as ratingSchema } from './ratingSchema.js'; export { default as claimInfoSchema } from './claimInfoSchema.js'; export { default as aggregatedHistorySchema } from './aggregatedHistorySchema.js'; -export { default as getContractsAddressesSchema } from './getContractsAddressesSchema.js'; +export { default as contractsAddressesSchema } from './contractsAddressesSchema.js'; From fd09635a7b1b66d8ebd4bb42e3bd4ff690cb39e1 Mon Sep 17 00:00:00 2001 From: kigastu Date: Fri, 16 Jun 2023 16:38:10 +0300 Subject: [PATCH 3/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f53fe14..3980afc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.26-rc1", + "version": "0.19.26-rc2", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js",