diff --git a/package.json b/package.json index 962c9a0..20b3548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.16.0-rc.3", + "version": "0.16.0-rc.4", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/OrionBlockchain/index.ts b/src/services/OrionBlockchain/index.ts index 37987b8..76777cc 100644 --- a/src/services/OrionBlockchain/index.ts +++ b/src/services/OrionBlockchain/index.ts @@ -10,7 +10,8 @@ import { userEarnedSchema, PairStatusEnum, pairStatusSchema, - CFDContractsSchema, + cfdContractsSchema, + cfdHistorySchema, } from './schemas'; import redeemOrderSchema from '../OrionAggregator/schemas/redeemOrderSchema'; import { sourceAtomicHistorySchema, targetAtomicHistorySchema } from './schemas/atomicHistorySchema'; @@ -53,6 +54,12 @@ type AtomicSwapHistoryTargetQuery = AtomicSwapHistoryBaseQuery & { expiredRedeem?: 0 | 1, state?: 'REDEEMED' | 'BEFORE-REDEEM', } + +type CfdHistoryQuery = { + instrument?: string, + page?: number, + limit?: number, +} class OrionBlockchain { private readonly apiUrl: string; @@ -92,6 +99,7 @@ class OrionBlockchain { this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this); this.claimOrder = this.claimOrder.bind(this); this.getCFDContracts = this.getCFDContracts.bind(this); + this.getCFDHistory = this.getCFDHistory.bind(this); } get orionBlockchainWsUrl() { @@ -382,8 +390,17 @@ class OrionBlockchain { getCFDContracts = () => fetchWithValidation( `${this.apiUrl}/api/cfd/contracts`, - CFDContractsSchema, + cfdContractsSchema, ); + + getCFDHistory = (address: string, query: CfdHistoryQuery) => { + const url = new URL(`${this.apiUrl}/api/cfd/deposit-withdraw/${address}`); + + Object.entries(query) + .forEach(([key, value]) => url.searchParams.append(key, value.toString())); + + return fetchWithValidation(url.toString(), cfdHistorySchema); + }; } export * as schemas from './schemas'; diff --git a/src/services/OrionBlockchain/schemas/CFDContractsSchema.ts b/src/services/OrionBlockchain/schemas/cfdContractsSchema.ts similarity index 79% rename from src/services/OrionBlockchain/schemas/CFDContractsSchema.ts rename to src/services/OrionBlockchain/schemas/cfdContractsSchema.ts index c120891..e453343 100644 --- a/src/services/OrionBlockchain/schemas/CFDContractsSchema.ts +++ b/src/services/OrionBlockchain/schemas/cfdContractsSchema.ts @@ -1,6 +1,6 @@ import { z } from 'zod'; -const CFDContractsSchema = z.array(z.object({ +const cfdContractsSchema = z.array(z.object({ name: z.string(), alias: z.string(), address: z.string(), @@ -14,4 +14,4 @@ const CFDContractsSchema = z.array(z.object({ priceIndex: z.number(), })); -export default CFDContractsSchema; +export default cfdContractsSchema; diff --git a/src/services/OrionBlockchain/schemas/cfdHistorySchema.ts b/src/services/OrionBlockchain/schemas/cfdHistorySchema.ts new file mode 100644 index 0000000..d45b405 --- /dev/null +++ b/src/services/OrionBlockchain/schemas/cfdHistorySchema.ts @@ -0,0 +1,15 @@ +import { z } from 'zod'; + +const cfdHistorySchema = z.array(z.object({ + address: z.string(), + instrument: z.string(), + balance: z.string(), + position: z.string(), + reason: z.string(), + positionPrice: z.string(), + fundingRate: z.string(), + transactionHash: z.string(), + blockNumber: z.number(), +})); + +export default cfdHistorySchema; diff --git a/src/services/OrionBlockchain/schemas/index.ts b/src/services/OrionBlockchain/schemas/index.ts index 7fd1c5f..570f71a 100644 --- a/src/services/OrionBlockchain/schemas/index.ts +++ b/src/services/OrionBlockchain/schemas/index.ts @@ -12,4 +12,5 @@ export { default as atomicSummarySchema } from './atomicSummarySchema'; export { default as poolsLpAndStakedSchema } from './poolsLpAndStakedSchema'; export { default as userVotesSchema } from './userVotesSchema'; export { default as userEarnedSchema } from './userEarnedSchema'; -export { default as CFDContractsSchema } from './CFDContractsSchema'; +export { default as cfdContractsSchema } from './cfdContractsSchema'; +export { default as cfdHistorySchema } from './cfdHistorySchema';