diff --git a/package.json b/package.json index cebbbfd..06f2b5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.77", + "version": "0.19.58-rc6", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", @@ -114,3 +114,4 @@ "tsconfig-paths": "^4.0.0" } } + 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/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/BlockchainService/index.ts b/src/services/BlockchainService/index.ts index df239e9..8ac862e 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,48 @@ 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, fromWidget }: { + assetIn?: string | undefined, + assetOut?: string | undefined, + walletAddress?: string | undefined, + fromWidget?: string | undefined + } + ) => { + const url = new URL(`${this.apiUrl}/api/platform-fees`); + + if (assetIn !== undefined) { + url.searchParams.append('assetIn', assetIn); + } + + if (assetOut !== undefined) { + url.searchParams.append('assetOut', assetOut); + } + + 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), + { headers: this.basicAuthHeaders } + ) + }; + getGasPriceWei = () => fetchWithValidation( `${this.apiUrl}/api/gasPrice`, z.string(), diff --git a/src/services/ReferralSystem/index.ts b/src/services/ReferralSystem/index.ts index 7711906..bd5c860 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,13 @@ type SignatureType = { signature: string }; +type submitTransactionDataForWidgetPayload = { + partner_domain: string + sender_address: string + tx_hash: string + chain_id: number +} + class ReferralSystem { private readonly apiUrl: string @@ -65,6 +73,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 +273,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';