Merge pull request #178 from orionprotocol/feat/platform-fees

Feat: platform fees
This commit is contained in:
Mikhail Gladchenko
2023-08-31 13:31:08 +01:00
committed by GitHub
7 changed files with 70 additions and 5 deletions

View File

@@ -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"
}
}

View File

@@ -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)();

View File

@@ -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)();

View File

@@ -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)();

View File

@@ -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,
};

View File

@@ -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(),

View File

@@ -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';