From de268b3de1e5bf399f916b3a82984550faa1d0a2 Mon Sep 17 00:00:00 2001 From: Oleg Nechiporenko Date: Tue, 22 Aug 2023 15:11:23 +0200 Subject: [PATCH 1/5] feat: add platform fees endpoint --- src/Unit/Exchange/getSwapInfo.ts | 6 +++-- src/Unit/Exchange/swapLimit.ts | 2 +- src/Unit/Exchange/swapMarket.ts | 2 +- src/services/BlockchainService/index.ts | 32 +++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/Unit/Exchange/getSwapInfo.ts b/src/Unit/Exchange/getSwapInfo.ts index e6c0f9e..aa3e315 100644 --- a/src/Unit/Exchange/getSwapInfo.ts +++ b/src/Unit/Exchange/getSwapInfo.ts @@ -18,7 +18,8 @@ export type GetSwapInfoParams = { options?: { instantSettlement?: boolean poolOnly?: boolean - } + }, + walletAddress?: string, } export default async function getSwapInfo({ @@ -30,6 +31,7 @@ export default async function getSwapInfo({ blockchainService, aggregator, options, + walletAddress, }: GetSwapInfoParams) { if (amount === '') throw new Error('Amount can not be empty'); if (assetIn === '') throw new Error('AssetIn can not be empty'); @@ -45,7 +47,7 @@ export default async function getSwapInfo({ } = await simpleFetch(blockchainService.getInfo)(); const nativeCryptocurrencyName = getNativeCryptocurrencyName(assetToAddress); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); diff --git a/src/Unit/Exchange/swapLimit.ts b/src/Unit/Exchange/swapLimit.ts index 3b62706..11a9d06 100644 --- a/src/Unit/Exchange/swapLimit.ts +++ b/src/Unit/Exchange/swapLimit.ts @@ -89,7 +89,7 @@ export default async function swapLimit({ const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress); const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); const { factories } = await simpleFetch(blockchainService.getPoolsConfig)(); diff --git a/src/Unit/Exchange/swapMarket.ts b/src/Unit/Exchange/swapMarket.ts index 2ac8e2f..22ceaf1 100644 --- a/src/Unit/Exchange/swapMarket.ts +++ b/src/Unit/Exchange/swapMarket.ts @@ -74,7 +74,7 @@ export default async function swapMarket({ const nativeCryptocurrency = getNativeCryptocurrencyName(assetToAddress); const exchangeContract = Exchange__factory.connect(exchangeContractAddress, provider); - const feeAssets = await simpleFetch(blockchainService.getTokensFee)(); + const feeAssets = await simpleFetch(blockchainService.getPlatformFees)({ walletAddress, assetIn, assetOut }); const allPrices = await simpleFetch(blockchainService.getPricesWithQuoteAsset)(); const gasPriceWei = await simpleFetch(blockchainService.getGasPriceWei)(); const { factories } = await simpleFetch(blockchainService.getPoolsConfig)(); diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index df239e9..5cda0ff 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -86,6 +86,7 @@ class BlockchainService { this.getHistory = this.getHistory.bind(this); this.getPricesWithQuoteAsset = this.getPricesWithQuoteAsset.bind(this); this.getTokensFee = this.getTokensFee.bind(this); + this.getPlatformFees = this.getPlatformFees.bind(this); this.getGasPriceWei = this.getGasPriceWei.bind(this); this.checkFreeRedeemAvailable = this.checkFreeRedeemAvailable.bind(this); this.redeemAtomicSwap = this.redeemAtomicSwap.bind(this); @@ -221,12 +222,43 @@ class BlockchainService { { headers: this.basicAuthHeaders } ); + /** + * @deprecated In favor of getPlatformFees + */ getTokensFee = () => fetchWithValidation( `${this.apiUrl}/api/tokensFee`, z.record(z.string()).transform(makePartial), { headers: this.basicAuthHeaders } ); + getPlatformFees = ( + { assetIn, assetOut, walletAddress }: { + assetIn?: string | undefined, + assetOut?: string | undefined, + walletAddress?: string | undefined + } + ) => { + const url = new URL(`${this.apiUrl}/api/platform-fees`); + + if (assetIn) { + url.searchParams.append('assetIn', assetIn); + } + + if (assetOut) { + url.searchParams.append('assetOut', assetOut); + } + + if (walletAddress) { + url.searchParams.append('walletAddress', walletAddress); + } + + return fetchWithValidation( + url.toString(), + z.record(z.string()).transform(makePartial), + { headers: this.basicAuthHeaders } + ) + }; + getGasPriceWei = () => fetchWithValidation( `${this.apiUrl}/api/gasPrice`, z.string(), From 9d8d436949935a7c378ce7889d3c18ede562938f Mon Sep 17 00:00:00 2001 From: Oleg Nechiporenko Date: Tue, 22 Aug 2023 15:15:10 +0200 Subject: [PATCH 2/5] chore: bump version@58-rc0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 32255a1..54447f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.57", + "version": "0.19.58-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 1de01439d117abcf920e85075cfde6cf99bf891a Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 30 Aug 2023 09:37:08 +0100 Subject: [PATCH 3/5] Network code was added --- package.json | 2 +- src/services/BlockchainService/index.ts | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 1590d92..853e433 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.58-rc3", + "version": "0.19.58-rc4", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index 5cda0ff..8ac862e 100644 --- a/src/services/BlockchainService/index.ts +++ b/src/services/BlockchainService/index.ts @@ -232,26 +232,31 @@ class BlockchainService { ); getPlatformFees = ( - { assetIn, assetOut, walletAddress }: { + { assetIn, assetOut, walletAddress, fromWidget }: { assetIn?: string | undefined, assetOut?: string | undefined, - walletAddress?: string | undefined + walletAddress?: string | undefined, + fromWidget?: string | undefined } ) => { const url = new URL(`${this.apiUrl}/api/platform-fees`); - - if (assetIn) { + + if (assetIn !== undefined) { url.searchParams.append('assetIn', assetIn); } - if (assetOut) { + if (assetOut !== undefined) { url.searchParams.append('assetOut', assetOut); } - if (walletAddress) { + if (walletAddress !== undefined) { url.searchParams.append('walletAddress', walletAddress); } + if (fromWidget !== undefined) { + url.searchParams.append('fromWidget', fromWidget); + } + return fetchWithValidation( url.toString(), z.record(z.string()).transform(makePartial), From 6444463e2156272b11321cb1732e38e27b5662e5 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Wed, 30 Aug 2023 15:35:40 +0100 Subject: [PATCH 4/5] feature: updated placeOrder and added submitTransactionDataForWidget methods --- package.json | 2 +- src/services/Aggregator/index.ts | 2 ++ src/services/ReferralSystem/index.ts | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 853e433..7205cce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.58-rc4", + "version": "0.19.58-rc5", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/Aggregator/index.ts b/src/services/Aggregator/index.ts index 7a220b3..6da1b14 100644 --- a/src/services/Aggregator/index.ts +++ b/src/services/Aggregator/index.ts @@ -196,6 +196,7 @@ class Aggregator { isCreateInternalOrder: boolean, isReversedOrder?: boolean, partnerId?: string, + fromWidget?: boolean, ) => { const headers = { 'Content-Type': 'application/json', @@ -204,6 +205,7 @@ class Aggregator { 'X-Reverse-Order': isReversedOrder ? 'true' : 'false', }, ...(partnerId !== undefined) && { 'X-Partner-Id': partnerId }, + ...(fromWidget !== undefined) && { 'X-From-Widget': fromWidget ? 'true' : 'false' }, ...this.basicAuthHeaders, }; diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 7711906..79d0c0f 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -1,3 +1,4 @@ +import { z } from 'zod'; import { fetchWithValidation } from 'simple-typed-fetch'; import { errorSchema, @@ -39,6 +40,12 @@ type SignatureType = { signature: string }; +type submitTransactionDataForWidgetPayload = { + partner_domain: string + sender_address: string + tx_hash: string +} + class ReferralSystem { private readonly apiUrl: string @@ -65,6 +72,7 @@ class ReferralSystem { this.getContractsAddresses = this.getContractsAddresses.bind(this); this.getClaimInfo = this.getClaimInfo.bind(this); this.getAggregatedHistory = this.getAggregatedHistory.bind(this); + this.submitTransactionDataForWidget = this.submitTransactionDataForWidget.bind(this); } getLink = (refererAddress: string) => @@ -264,6 +272,20 @@ class ReferralSystem { errorSchema ); }; + + submitTransactionDataForWidget = (payload: submitTransactionDataForWidgetPayload) => { + return fetchWithValidation( + `${this.apiUrl}/referer/widget/submit`, + z.unknown(), + { + headers: { + 'Content-type': 'application/json', + }, + method: 'POST', + body: JSON.stringify(payload) + } + ); + }; } export * as schemas from './schemas/index.js'; From 9d969c88c183005dfd70a2ae154f8d06c1bc1c66 Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Thu, 31 Aug 2023 10:52:06 +0100 Subject: [PATCH 5/5] feature: added chain_id parameter to payload --- package.json | 2 +- src/services/ReferralSystem/index.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7205cce..06f2b5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.58-rc5", + "version": "0.19.58-rc6", "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 79d0c0f..bd5c860 100644 --- a/src/services/ReferralSystem/index.ts +++ b/src/services/ReferralSystem/index.ts @@ -44,6 +44,7 @@ type submitTransactionDataForWidgetPayload = { partner_domain: string sender_address: string tx_hash: string + chain_id: number } class ReferralSystem {