@velora-dex/sdk
Version:
295 lines • 11.9 kB
TypeScript
import type { NonEmptyArray, Prettify } from 'ts-essentials';
import { Bridge, DeltaAuctionOrder, ExternalDeltaOrder, OnChainOrderType, ProductiveDeltaOrder, SwapSideUnion, TWAPBuyDeltaOrder, TWAPDeltaOrder, DeltaOrderUnion, UnifiedDeltaOrderData } from './types';
import type { DeltaAuction, DeltaTransaction } from '../types';
/**
* Delta order helpers.
*
* The on-chain order structs (`auction.order`) and the `onChainOrderType` union
* are shared across all order families, so the order-struct guards, auction
* discriminant guards, and order-level getters operate purely on those shapes.
*
* The *auction* envelope is the integrator-facing v2 shape:
* - `status` is the integrator-facing `DeltaOrderStatus`
* (PENDING/ACTIVE/COMPLETED/…),
* - amounts live on `input`/`output` (`DeltaTokenSide`) and `transactions`
* (`DeltaTransaction`),
* - `side` is carried explicitly on the auction.
*/
/**
* @description Checks whether an order is a TWAP Sell or TWAP Buy order.
*/
declare function isTWAPOrder(order: DeltaOrderUnion): order is TWAPDeltaOrder | TWAPBuyDeltaOrder;
/**
* @description Checks whether an order is a TWAP Sell order.
*/
declare function isTWAPSellOrder(order: DeltaOrderUnion): order is TWAPDeltaOrder;
/**
* @description Checks whether an order is a TWAP Buy order.
*/
declare function isTWAPBuyOrder(order: DeltaOrderUnion): order is TWAPBuyDeltaOrder;
/**
* @description Checks whether an order is an External order.
*/
declare function isExternalOrder(order: DeltaOrderUnion): order is ExternalDeltaOrder;
/**
* @description Checks whether an order is a regular Delta auction order.
*/
declare function isDeltaOrder(order: DeltaOrderUnion): order is DeltaAuctionOrder;
/**
* @description Checks whether an order is a Productive Delta order
* (strategy-routed order without an explicit OrderKind).
*/
declare function isProductiveOrder(order: DeltaOrderUnion): order is ProductiveDeltaOrder;
/**
* @description Checks whether an auction is a TWAP auction.
*/
declare function isTWAPAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: ('TWAPOrder' | 'TWAPBuyOrder') & T;
};
/**
* @description Checks whether an auction is a TWAP Sell auction.
*/
declare function isTWAPSellAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: 'TWAPOrder' & T;
};
/**
* @description Checks whether an auction is a TWAP Buy auction.
*/
declare function isTWAPBuyAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: 'TWAPBuyOrder' & T;
};
/**
* @description Checks whether an auction is a Delta auction.
*/
declare function isDeltaAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: 'Order' & T;
};
/**
* @description Checks whether an auction is an External auction.
*/
declare function isExternalAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: 'ExternalOrder' & T;
};
/**
* @description Checks whether an auction is a Productive auction.
*/
declare function isProductiveAuction<T extends OnChainOrderType>(auction: {
onChainOrderType: T;
}): auction is {
onChainOrderType: 'ProductiveOrder' & T;
};
/**
* @description Checks whether an auction is a Fillable auction.
* `FillableOrder` is the `onChainOrderType` the server reports for a
* `partiallyFillable` Standard order; it carries the same order struct as
* `Order`. Consumers that don't distinguish the two should treat
* `isDeltaAuction(a) || isFillableAuction(a)` as "is a standard order".
*/
declare function isFillableAuction<T extends Pick<DeltaAuction, 'onChainOrderType'>>(auction: T): auction is T & {
onChainOrderType: 'FillableOrder';
};
/**
* @description Checks whether an auction is fully executed (settled on every chain).
*/
declare function isCompletedAuction<T extends Pick<DeltaAuction, 'status'>>(auction: T): auction is T & {
status: 'COMPLETED';
};
declare const failedAuctionStatuses: readonly ["FAILED", "EXPIRED", "CANCELLED", "REFUNDED", "REFUNDING"];
/**
* @description Checks whether an auction is in a terminal failure state
* (failed, expired, cancelled, or refunded).
*/
declare function isFailedAuction<T extends Pick<DeltaAuction, 'status'>>(auction: T): auction is T & {
status: (typeof failedAuctionStatuses)[number];
};
/**
* @description Checks whether an auction status is cancelled.
*/
declare function isCanceledAuction<T extends Pick<DeltaAuction, 'status'>>(auction: T): auction is T & {
status: 'CANCELLED';
};
/**
* @description Checks whether an auction status is expired.
*/
declare function isExpiredAuction<T extends Pick<DeltaAuction, 'status'>>(auction: T): auction is T & {
status: 'EXPIRED';
};
declare const pendingAuctionStatuses: readonly ["PENDING", "AWAITING_SIGNATURE", "ACTIVE", "BRIDGING"];
/**
* @description Checks whether an auction is still in flight (not yet settled
* and not failed): awaiting signature, pending, actively executing, or bridging.
*/
declare function isPendingAuction<T extends Pick<DeltaAuction, 'status'>>(auction: T): auction is T & {
status: (typeof pendingAuctionStatuses)[number];
};
/**
* @description Checks whether an auction has been partially executed:
* it has at least one transaction and an overall filled percent strictly
* between 0 and 100.
*/
declare function isPartiallyExecutedAuction<T extends Pick<DeltaAuction, 'order' | 'transactions'>>(auction: T): auction is T & {
transactions: NonEmptyArray<DeltaTransaction>;
};
/**
* @description Checks whether an order includes valid cross-chain bridge details.
*/
declare function isOrderCrosschain<T extends {
bridge?: Bridge;
} | object>(order: T): order is Prettify<Extract<T, {
bridge?: Bridge;
}> & {
bridge: Bridge;
}>;
/**
* @description Returns swap side from a Delta or External order kind.
*/
declare function getSwapSideFromDeltaOrder(order: DeltaAuctionOrder | ExternalDeltaOrder): SwapSideUnion;
/**
* @description Returns swap side from TWAP on-chain order type.
*/
declare function getSwapSideFromTwapOrderType(onChainOrderType: 'TWAPOrder' | 'TWAPBuyOrder'): SwapSideUnion;
/**
* @description Returns source and destination token addresses for an order.
*/
declare function getOrderTokenAddresses(order: DeltaAuction['order']): {
srcToken: string;
destToken: string;
};
/**
* @description Returns the expected source amount for a TWAP order.
*/
declare function getExpectedTwapSrcAmount(order: Pick<TWAPDeltaOrder, 'totalSrcAmount'> | Pick<TWAPBuyDeltaOrder, 'maxSrcAmount'>): string;
/**
* @description Returns the expected destination amount for a TWAP order.
*/
declare function getExpectedTwapDestAmount(order: Pick<TWAPDeltaOrder, 'destAmountPerSlice' | 'numSlices' | 'bridge'> | Pick<TWAPBuyDeltaOrder, 'totalDestAmount' | 'bridge'>): string;
/**
* @description Returns expected source and destination amounts for a TWAP order.
*/
declare function getExpectedTwapOrderAmounts(order: TWAPDeltaOrder | TWAPBuyDeltaOrder): {
srcAmount: string;
destAmount: string;
};
/**
* @description Returns the source chain id for the auction (the input side's chain).
*/
declare function getAuctionSrcChainId(auction: Pick<DeltaAuction, 'input'>): number;
/**
* @description Returns the destination chain id for the auction (the output side's chain).
* Equals the source chain id for same-chain orders.
*/
declare function getAuctionDestChainId(auction: Pick<DeltaAuction, 'output'>): number;
/**
* @description Returns the swap side for any auction. The auction carries `side`
* directly, so no order introspection is needed.
*/
declare function getAuctionSwapSide(auction: Pick<DeltaAuction, 'side'>): SwapSideUnion;
/**
* @description Returns source and destination token addresses for the auction,
* read from the input/output sides (already resolved to the dest-chain token
* for cross-chain orders).
*/
declare function getAuctionTokenAddresses(auction: Pick<DeltaAuction, 'input' | 'output'>): {
srcToken: string;
destToken: string;
};
/**
* @description Aggregates transaction amounts into total spent (src) and
* received (dest) values.
*/
declare function getTransactionAmounts(transactions: DeltaTransaction[]): {
srcAmount: string;
destAmount: string;
};
/**
* @description Calculates the overall filled percent (0–100) from the
* per-transaction `filledPercent` values. For cross-chain orders,
* only transactions with a `destinationTx` are counted towards the filled percent.
*/
declare function getFilledPercent({ order, transactions, }: Pick<DeltaAuction, 'order' | 'transactions'>): number;
/**
* @description Returns expected and minimal amounts and, once the auction is completed,
* executed amounts. Executed amounts prefer the `executedAmount` baked onto the
* token sides and fall back to summing transactions.
*/
declare function getAuctionAmounts(auction: Pick<DeltaAuction, 'status' | 'order' | 'input' | 'output' | 'transactions'>): {
expected: {
srcAmount: string;
destAmount: string;
};
minimal: {
srcAmount: string;
destAmount: string;
};
executed?: undefined;
} | {
expected: {
srcAmount: string;
destAmount: string;
};
executed: {
srcAmount: string;
destAmount: string;
};
minimal: {
srcAmount: string;
destAmount: string;
};
};
/**
* @description Returns unified order data with normalized amounts, tokens,
* chain ids, and side, built from the auction envelope.
*/
declare function getUnifiedDeltaOrderData(auction: DeltaAuction): UnifiedDeltaOrderData;
export declare const OrderHelpers: {
checks: {
isTWAPOrder: typeof isTWAPOrder;
isTWAPSellOrder: typeof isTWAPSellOrder;
isTWAPBuyOrder: typeof isTWAPBuyOrder;
isExternalOrder: typeof isExternalOrder;
isDeltaOrder: typeof isDeltaOrder;
isProductiveOrder: typeof isProductiveOrder;
isOrderCrosschain: typeof isOrderCrosschain;
isTWAPAuction: typeof isTWAPAuction;
isTWAPSellAuction: typeof isTWAPSellAuction;
isTWAPBuyAuction: typeof isTWAPBuyAuction;
isDeltaAuction: typeof isDeltaAuction;
isExternalAuction: typeof isExternalAuction;
isProductiveAuction: typeof isProductiveAuction;
isFillableAuction: typeof isFillableAuction;
isCompletedAuction: typeof isCompletedAuction;
isFailedAuction: typeof isFailedAuction;
isCanceledAuction: typeof isCanceledAuction;
isExpiredAuction: typeof isExpiredAuction;
isPendingAuction: typeof isPendingAuction;
isPartiallyExecutedAuction: typeof isPartiallyExecutedAuction;
};
getters: {
getUnifiedDeltaOrderData: typeof getUnifiedDeltaOrderData;
getAuctionTokenAddresses: typeof getAuctionTokenAddresses;
getAuctionSrcChainId: typeof getAuctionSrcChainId;
getAuctionDestChainId: typeof getAuctionDestChainId;
getAuctionSwapSide: typeof getAuctionSwapSide;
getTransactionAmounts: typeof getTransactionAmounts;
getAuctionAmounts: typeof getAuctionAmounts;
getFilledPercent: typeof getFilledPercent;
getOrderTokenAddresses: typeof getOrderTokenAddresses;
getSwapSideFromDeltaOrder: typeof getSwapSideFromDeltaOrder;
getSwapSideFromTwapOrderType: typeof getSwapSideFromTwapOrderType;
getExpectedTwapSrcAmount: typeof getExpectedTwapSrcAmount;
getExpectedTwapDestAmount: typeof getExpectedTwapDestAmount;
getExpectedTwapOrderAmounts: typeof getExpectedTwapOrderAmounts;
};
};
export {};
//# sourceMappingURL=orders.d.ts.map