From d56150ce3e0605e941a4b4b5c81c028cdccb21f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Kraiz Date: Fri, 13 May 2022 09:13:29 +0400 Subject: [PATCH] Added new atomics methods --- package.json | 2 +- src/services/OrionBlockchain/index.ts | 73 +++++++++++++++++++++++---- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 66a1baa..cf9ce42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.5.10", + "version": "0.5.11", "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 810ac93..f3b9e6d 100644 --- a/src/services/OrionBlockchain/index.ts +++ b/src/services/OrionBlockchain/index.ts @@ -83,8 +83,9 @@ class OrionBlockchain { this.getTargetAtomicSwapHistory = this.getTargetAtomicSwapHistory.bind(this); this.checkPoolInformation = this.checkPoolInformation.bind(this); this.checkIfHashUsed = this.checkIfHashUsed.bind(this); - this.getQueueLength = this.getQueueLength.bind(this); this.getBlockNumber = this.getBlockNumber.bind(this); + this.getRedeemOrderBySecretHash = this.getRedeemOrderBySecretHash.bind(this); + this.claimOrder = this.claimOrder.bind(this); } get orionBlockchainWsUrl() { @@ -114,29 +115,78 @@ class OrionBlockchain { }; } - getAuthToken = () => fetchWithValidation(`https://${this.apiUrl}/api/auth/token`, z.object({ token: z.string() })); + getAuthToken = () => fetchWithValidation( + `https://${this.apiUrl}/api/auth/token`, + z.object({ token: z.string() }), + ); - getCirculatingSupply = () => fetchWithValidation(`https://${this.apiUrl}/api/circulating-supply`, z.number()); + getCirculatingSupply = () => fetchWithValidation( + `https://${this.apiUrl}/api/circulating-supply`, + z.number(), + ); getInfo = () => fetchWithValidation(`https://${this.apiUrl}/api/info`, infoSchema); - getPoolsConfig = () => fetchWithValidation(`https://${this.apiUrl}/api/pools/config`, poolsConfigSchema); + getPoolsConfig = () => fetchWithValidation( + `https://${this.apiUrl}/api/pools/config`, + poolsConfigSchema, + ); - getPoolsInfo = () => fetchWithValidation(`https://${this.apiUrl}/api/pools/info`, poolsInfoSchema); + getPoolsInfo = () => fetchWithValidation( + `https://${this.apiUrl}/api/pools/info`, + poolsInfoSchema, + ); - getHistory = (address: string) => fetchWithValidation(`https://${this.apiUrl}/api/history/${address}`, historySchema); + getHistory = (address: string) => fetchWithValidation( + `https://${this.apiUrl}/api/history/${address}`, + historySchema, + ); - getPrices = () => fetchWithValidation(`https://${this.apiUrl}/api/prices`, z.record(z.string()).transform(makePartial)); + getPrices = () => fetchWithValidation( + `https://${this.apiUrl}/api/prices`, + z.record(z.string()).transform(makePartial), + ); - getTokensFee = () => fetchWithValidation(`https://${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial)); + getTokensFee = () => fetchWithValidation( + `https://${this.apiUrl}/api/tokensFee`, + z.record(z.string()).transform(makePartial), + ); - getGasPriceWei = () => fetchWithValidation(`https://${this.apiUrl}/api/gasPrice`, z.string()); + getGasPriceWei = () => fetchWithValidation( + `https://${this.apiUrl}/api/gasPrice`, + z.string(), + ); checkFreeRedeemAvailable = (walletAddress: string) => fetchWithValidation( `https://${this.apiUrl}/api/atomic/has-free-redeem/${walletAddress}`, z.boolean(), ); + getRedeemOrderBySecretHash = (secretHash: string) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/redeem-order/${secretHash}`, + z.object({ + secretHash: z.string(), + secret: z.string(), + redeemTxHash: z.string(), + }), + ); + + claimOrder = (secretHash: string, targetNetwork: string, redeemTxHash?: string) => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/claim-order`, + z.string(), + { + method: 'POST', + body: JSON.stringify({ + secretHash, + targetNetwork, + redeemTxHash, + }), + headers: { + 'Content-Type': 'application/json', + }, + }, + ); + redeemAtomicSwap = ( redeemOrder: z.infer, secret: string, @@ -237,7 +287,10 @@ class OrionBlockchain { pairStatusSchema, ); - getAtomicSwapAssets = () => fetchWithValidation(`https://${this.apiUrl}/api/atomic/swap-assets`, z.array(z.string())); + getAtomicSwapAssets = () => fetchWithValidation( + `https://${this.apiUrl}/api/atomic/swap-assets`, + z.array(z.string()), + ); /** * Sender is user address in source Orion Blockchain instance \