mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-17 00:31:34 +03:00
feat: add platform fees endpoint
This commit is contained in:
@@ -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)();
|
||||
|
||||
|
||||
@@ -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)();
|
||||
|
||||
@@ -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)();
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user