mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-17 00:31:34 +03:00
make props as object
This commit is contained in:
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.21.0-rc4",
|
||||
"version": "0.21.0-rc5",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.21.0-rc4",
|
||||
"version": "0.21.0-rc5",
|
||||
"hasInstallScript": true,
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.21.0-rc4",
|
||||
"version": "0.21.0-rc5",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./lib/index.js",
|
||||
|
||||
@@ -5,7 +5,11 @@ import getBalances from '../../utils/getBalances.js';
|
||||
import BalanceGuard from '../../BalanceGuard.js';
|
||||
import getAvailableSources from '../../utils/getAvailableFundsSources.js';
|
||||
import type Unit from '../index.js';
|
||||
import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants/index.js';
|
||||
import {
|
||||
INTERNAL_PROTOCOL_PRECISION,
|
||||
NATIVE_CURRENCY_PRECISION,
|
||||
SWAP_THROUGH_ORION_POOL_GAS_LIMIT
|
||||
} from '../../constants/index.js';
|
||||
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
|
||||
import { calculateFeeInFeeAsset, denormalizeNumber, normalizeNumber } from '../../utils/index.js';
|
||||
import { signOrder } from '../../crypt/index.js';
|
||||
@@ -212,7 +216,7 @@ export default async function swapLimit({
|
||||
if (options.developer.route === 'pool' && !priceIsBTEMP) {
|
||||
throw new Error(
|
||||
'CONFLICT: Pool execution is not available for this swap.' +
|
||||
' Price is worse than market price. Please unset "route" option or set it to "aggregator"'
|
||||
' Price is worse than market price. Please unset "route" option or set it to "aggregator"'
|
||||
);
|
||||
}
|
||||
route = options.developer.route;
|
||||
@@ -221,17 +225,17 @@ export default async function swapLimit({
|
||||
if (!priceIsBTEMP) {
|
||||
throw new Error(
|
||||
'CONFLICT: Pool execution is not available for this swap.' +
|
||||
' Price is worse than market price. Please disable "poolOnly" option'
|
||||
' Price is worse than market price. Please disable "poolOnly" option'
|
||||
);
|
||||
}
|
||||
options.logger?.('Swap is through pool (because "poolOnly" option is true)');
|
||||
route = 'pool';
|
||||
} else if (
|
||||
poolExchangesList.length > 0 &&
|
||||
swapExchanges.length === 1 &&
|
||||
firstSwapExchange !== undefined &&
|
||||
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange) &&
|
||||
priceIsBTEMP
|
||||
swapExchanges.length === 1 &&
|
||||
firstSwapExchange !== undefined &&
|
||||
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange) &&
|
||||
priceIsBTEMP
|
||||
) {
|
||||
options?.logger?.(`Swap is through pool [via ${firstSwapExchange}] (detected by "exchanges" field)`);
|
||||
route = 'pool';
|
||||
@@ -439,19 +443,19 @@ export default async function swapLimit({
|
||||
|
||||
await balanceGuard.check(options?.autoApprove);
|
||||
|
||||
const signedOrder = await signOrder(
|
||||
const signedOrder = await signOrder({
|
||||
baseAssetAddress,
|
||||
quoteAssetAddress,
|
||||
swapInfo.orderInfo.side,
|
||||
safePriceWithAppliedPrecision.toString(),
|
||||
swapInfo.orderInfo.amount,
|
||||
totalFeeInFeeAsset,
|
||||
walletAddress,
|
||||
side: swapInfo.orderInfo.side,
|
||||
price: safePriceWithAppliedPrecision.toString(),
|
||||
amount: swapInfo.orderInfo.amount,
|
||||
matcherFee: totalFeeInFeeAsset,
|
||||
senderAddress: walletAddress,
|
||||
matcherAddress,
|
||||
feeAssetAddress,
|
||||
serviceFeeAssetAddress: feeAssetAddress,
|
||||
signer,
|
||||
chainId,
|
||||
);
|
||||
});
|
||||
const orderIsOk = await exchangeContract.validateOrder(signedOrder);
|
||||
if (!orderIsOk) throw new Error('Order is not valid');
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ import { Exchange__factory } from '@orionprotocol/contracts/lib/ethers-v6/index.
|
||||
import getBalances from '../../utils/getBalances.js';
|
||||
import BalanceGuard from '../../BalanceGuard.js';
|
||||
import getAvailableSources from '../../utils/getAvailableFundsSources.js';
|
||||
import { INTERNAL_PROTOCOL_PRECISION, NATIVE_CURRENCY_PRECISION, SWAP_THROUGH_ORION_POOL_GAS_LIMIT } from '../../constants';
|
||||
import {
|
||||
INTERNAL_PROTOCOL_PRECISION,
|
||||
NATIVE_CURRENCY_PRECISION,
|
||||
SWAP_THROUGH_ORION_POOL_GAS_LIMIT
|
||||
} from '../../constants';
|
||||
import getNativeCryptocurrencyName from '../../utils/getNativeCryptocurrencyName.js';
|
||||
import { calculateFeeInFeeAsset, denormalizeNumber, normalizeNumber } from '../../utils/index.js';
|
||||
import { signOrder } from '../../crypt/index.js';
|
||||
@@ -178,9 +182,9 @@ export default async function swapMarket({
|
||||
route = 'pool';
|
||||
} else if (
|
||||
poolExchangesList.length > 0 &&
|
||||
swapExchanges.length === 1 &&
|
||||
firstSwapExchange !== undefined &&
|
||||
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
|
||||
swapExchanges.length === 1 &&
|
||||
firstSwapExchange !== undefined &&
|
||||
poolExchangesList.some((poolExchange) => poolExchange === firstSwapExchange)
|
||||
) {
|
||||
options?.logger?.(`Swap is through pool [via ${firstSwapExchange}] (detected by "exchanges" field)`);
|
||||
route = 'pool';
|
||||
@@ -398,19 +402,19 @@ export default async function swapMarket({
|
||||
|
||||
await balanceGuard.check(options?.autoApprove);
|
||||
|
||||
const signedOrder = await signOrder(
|
||||
const signedOrder = await signOrder({
|
||||
baseAssetAddress,
|
||||
quoteAssetAddress,
|
||||
swapInfo.orderInfo.side,
|
||||
safePriceWithAppliedPrecision.toString(),
|
||||
swapInfo.orderInfo.amount,
|
||||
totalFeeInFeeAsset,
|
||||
walletAddress,
|
||||
side: swapInfo.orderInfo.side,
|
||||
price: safePriceWithAppliedPrecision.toString(),
|
||||
amount: swapInfo.orderInfo.amount,
|
||||
matcherFee: totalFeeInFeeAsset,
|
||||
senderAddress: walletAddress,
|
||||
matcherAddress,
|
||||
feeAssetAddress,
|
||||
serviceFeeAssetAddress: feeAssetAddress,
|
||||
signer,
|
||||
chainId,
|
||||
);
|
||||
});
|
||||
const orderIsOk = await exchangeContract.validateOrder(signedOrder);
|
||||
if (!orderIsOk) throw new Error('Order is not valid');
|
||||
|
||||
|
||||
@@ -10,20 +10,35 @@ import generateSecret from '../utils/generateSecret';
|
||||
|
||||
const DEFAULT_EXPIRATION = 29 * 24 * 60 * 60 * 1000; // 29 days
|
||||
|
||||
export const signOrder = async (
|
||||
baseAssetAddr: string,
|
||||
quoteAssetAddr: string,
|
||||
side: 'BUY' | 'SELL',
|
||||
price: BigNumber.Value,
|
||||
amount: BigNumber.Value,
|
||||
matcherFee: BigNumber.Value,
|
||||
senderAddress: string,
|
||||
matcherAddress: string,
|
||||
serviceFeeAssetAddr: string,
|
||||
signer: ethers.Signer,
|
||||
chainId: SupportedChainId,
|
||||
targetChainId?: SupportedChainId,
|
||||
) => {
|
||||
type SignOrderProps = {
|
||||
baseAssetAddress: string
|
||||
quoteAssetAddress: string
|
||||
side: 'BUY' | 'SELL'
|
||||
price: BigNumber.Value
|
||||
amount: BigNumber.Value
|
||||
matcherFee: BigNumber.Value
|
||||
senderAddress: string
|
||||
matcherAddress: string
|
||||
serviceFeeAssetAddress: string
|
||||
signer: ethers.Signer
|
||||
chainId: SupportedChainId
|
||||
targetChainId?: SupportedChainId
|
||||
}
|
||||
|
||||
export const signOrder = async ({
|
||||
amount,
|
||||
signer,
|
||||
side,
|
||||
baseAssetAddress,
|
||||
quoteAssetAddress,
|
||||
serviceFeeAssetAddress,
|
||||
matcherFee,
|
||||
matcherAddress,
|
||||
senderAddress,
|
||||
targetChainId,
|
||||
chainId,
|
||||
price
|
||||
}: SignOrderProps) => {
|
||||
const nonce = Date.now();
|
||||
const expiration = nonce + DEFAULT_EXPIRATION;
|
||||
const secret = generateSecret();
|
||||
@@ -34,9 +49,9 @@ export const signOrder = async (
|
||||
const order: Order | CrossOrder = {
|
||||
senderAddress,
|
||||
matcherAddress,
|
||||
baseAsset: baseAssetAddr,
|
||||
quoteAsset: quoteAssetAddr,
|
||||
matcherFeeAsset: serviceFeeAssetAddr,
|
||||
baseAsset: baseAssetAddress,
|
||||
quoteAsset: quoteAssetAddress,
|
||||
matcherFeeAsset: serviceFeeAssetAddress,
|
||||
amount: Number(normalizeNumber(
|
||||
amount,
|
||||
INTERNAL_PROTOCOL_PRECISION,
|
||||
|
||||
Reference in New Issue
Block a user