Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ebd55bb
twap types and some global exports
andriy-shymkiv Mar 24, 2026
109eee6
export more types
andriy-shymkiv Mar 24, 2026
a609486
TWAP core
andriy-shymkiv Mar 25, 2026
373bb4e
PostTWAPDeltaOrderParams/degenMode + prettify
andriy-shymkiv Mar 25, 2026
e01cd72
export more twap types
andriy-shymkiv Mar 25, 2026
f3fcdd1
export DeltaOrderToPost from index
andriy-shymkiv Mar 26, 2026
1092d27
buildTWAPDeltaOrder/maxSrcAmount for BUY slippage
andriy-shymkiv Mar 26, 2026
f09df90
constructPostTWAPDeltaOrder/consistend posting
andriy-shymkiv Mar 26, 2026
872b5fa
Release 9.4.1-dev.1
andriy-shymkiv Mar 26, 2026
3bdbcf4
constructBuildTWAPDeltaOrder/ nullify bridge.protocolData by default
andriy-shymkiv Mar 27, 2026
5ea2eb1
add comment
andriy-shymkiv Mar 27, 2026
389e3d4
Release 9.4.1-dev.2
andriy-shymkiv Mar 27, 2026
bc559db
twap/clarifying comments
andriy-shymkiv Mar 27, 2026
ed86d9a
constructSubmitTWAPDeltaOrder/degenMode
andriy-shymkiv Apr 8, 2026
aa6ac67
rename types
andriy-shymkiv Apr 8, 2026
2de995d
merge with master
andriy-shymkiv Apr 8, 2026
b711a70
buildTWAPSignableOrderData/default deadline enough for all slices to …
andriy-shymkiv Apr 8, 2026
36a6a86
constructDeltaTokenModule/cancelTWAPAndWithdraw & cancelTWAPBuyAndWit…
andriy-shymkiv Apr 8, 2026
667cb80
delta/fix some tests
andriy-shymkiv Apr 8, 2026
320c2ba
Release 9.4.3-dev.1
andriy-shymkiv Apr 9, 2026
bf20619
constructDeltaTokenModule/sanitizeOrderData
andriy-shymkiv Apr 13, 2026
95e4c07
get rid of ethersV5 dependency
andriy-shymkiv Apr 13, 2026
dc32f22
Release 9.5.0
andriy-shymkiv Apr 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@velora-dex/sdk",
"version": "9.4.0",
"version": "9.4.1-dev.2",
"main": "dist/index.js",
"module": "dist/sdk.esm.js",
"typings": "dist/index.d.ts",
Expand Down
63 changes: 63 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,20 @@ import type {
DeltaAuctionOrder,
DeltaAuction,
DeltaAuctionStatus,
DeltaAuctionTransaction,
BridgeMetadata,
BridgeStatus,
Bridge,
ExternalDeltaOrder,
TWAPDeltaOrder,
TWAPBuyDeltaOrder,
TWAPOnChainOrderType,
OnChainOrderType,
SwapSideUnion,
AmountsWithSlippage,
AmountsSellSlippage,
AmountsBuySlippage,
AmountsExplicit,
Comment thread
andriy-shymkiv marked this conversation as resolved.
Outdated
} from './methods/delta/helpers/types';
import {
BuildDeltaOrderDataParams,
Expand All @@ -156,6 +164,7 @@ import {
} from './methods/delta/buildDeltaOrder';
import {
constructPostDeltaOrder,
DeltaOrderToPost,
PostDeltaOrderFunctions,
PostDeltaOrderParams,
} from './methods/delta/postDeltaOrder';
Expand Down Expand Up @@ -224,6 +233,28 @@ import {
PreSignExternalDeltaOrderFunctions,
} from './methods/delta/preSignExternalDeltaOrder';

import {
BuildTWAPDeltaOrderParams,
BuildTWAPSellOrderParams,
BuildTWAPBuyOrderParams,
BuildTWAPDeltaOrderFunctions,
constructBuildTWAPDeltaOrder,
} from './methods/delta/buildTWAPDeltaOrder';
import type { SignableTWAPOrderData } from './methods/delta/helpers/buildTWAPOrderData';
import {
constructSignTWAPDeltaOrder,
SignTWAPDeltaOrderFunctions,
} from './methods/delta/signTWAPDeltaOrder';
import {
constructPostTWAPDeltaOrder,
PostTWAPDeltaOrderFunctions,
PostTWAPDeltaOrderParams,
} from './methods/delta/postTWAPDeltaOrder';
import {
constructPreSignTWAPDeltaOrder,
PreSignTWAPDeltaOrderFunctions,
} from './methods/delta/preSignTWAPDeltaOrder';

import {
constructGetQuote,
GetQuoteFunctions,
Expand All @@ -244,6 +275,10 @@ import {
DepositNativeAndPreSignParams,
DepositNativeAndPreSignDeltaOrderParams,
} from './methods/delta/deltaTokenModule';
import {
CancelDeltaOrderData,
SignableCancelDeltaOrderData,
} from './methods/delta/helpers/buildCancelDeltaOrderData';

export { constructSwapSDK, SwapSDKMethods } from './methods/swap';

Expand All @@ -257,9 +292,11 @@ export {
constructAllDeltaOrdersHandlers,
constructSubmitDeltaOrder,
constructSubmitExternalDeltaOrder,
constructSubmitTWAPDeltaOrder,
DeltaOrderHandlers,
SubmitDeltaOrderParams,
SubmitExternalDeltaOrderParams,
SubmitTWAPDeltaOrderParams,
} from './methods/delta';

export type {
Expand Down Expand Up @@ -337,6 +374,11 @@ export {
constructSignExternalDeltaOrder,
constructPostExternalDeltaOrder,
constructPreSignExternalDeltaOrder,
// TWAP Delta methods
constructBuildTWAPDeltaOrder,
constructSignTWAPDeltaOrder,
constructPostTWAPDeltaOrder,
constructPreSignTWAPDeltaOrder,
// Quote methods
constructGetQuote,
// different helpers
Expand Down Expand Up @@ -409,8 +451,11 @@ export type {
DeltaAuctionOrder,
DeltaAuction,
DeltaAuctionStatus,
DeltaAuctionTransaction,
DeltaOrderFilterByStatus,
DeltaOrderFromAPI,
CancelDeltaOrderData,
SignableCancelDeltaOrderData,
// bridge part of DeltaOrder
BridgeMetadata,
BridgeStatus,
Expand All @@ -421,6 +466,7 @@ export type {
BuildDeltaOrderDataParams,
BuildDeltaOrderFunctions,
SignableDeltaOrderData,
DeltaOrderToPost,
PostDeltaOrderFunctions,
PostDeltaOrderParams,
SignDeltaOrderFunctions,
Expand All @@ -436,14 +482,31 @@ export type {
DepositNativeAndPreSignDeltaOrderParams,
// External Delta types
ExternalDeltaOrder,
TWAPDeltaOrder,
TWAPBuyDeltaOrder,
TWAPOnChainOrderType,
OnChainOrderType,
AmountsWithSlippage,
AmountsSellSlippage,
AmountsBuySlippage,
AmountsExplicit,
SignableExternalOrderData,
BuildExternalDeltaOrderParams,
BuildExternalDeltaOrderFunctions,
SignExternalDeltaOrderFunctions,
PostExternalDeltaOrderFunctions,
PostExternalDeltaOrderParams,
PreSignExternalDeltaOrderFunctions,
// TWAP Delta types
BuildTWAPDeltaOrderParams,
BuildTWAPSellOrderParams,
BuildTWAPBuyOrderParams,
BuildTWAPDeltaOrderFunctions,
SignableTWAPOrderData,
SignTWAPDeltaOrderFunctions,
PostTWAPDeltaOrderFunctions,
PostTWAPDeltaOrderParams,
PreSignTWAPDeltaOrderFunctions,
// types for Quote methods
GetQuoteFunctions,
QuoteParams,
Expand Down
187 changes: 187 additions & 0 deletions src/methods/delta/buildTWAPDeltaOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import type { ConstructFetchInput, RequestParameters } from '../../types';
import { DEFAULT_BRIDGE } from './constants';
import { constructGetDeltaContract } from './getDeltaContract';
import type { BridgePrice } from './getDeltaPrice';
import { constructGetPartnerFee } from './getPartnerFee';
import {
buildTWAPSignableOrderData,
TWAPOrderCommonInput,
type BuildTWAPOrderDataInput,
type SignableTWAPOrderData,
} from './helpers/buildTWAPOrderData';
import { applySlippage, resolvePartnerFee } from './helpers/misc';
import type { MarkOptional } from 'ts-essentials';
export type { SignableTWAPOrderData } from './helpers/buildTWAPOrderData';

type BuildTWAPDeltaOrderParamsBase = {
/** @description The address of the order owner */
owner: string;
/** @description The address of the order beneficiary */
beneficiary?: string;
/** @description The address of the src token */
srcToken: string;
/** @description The address of the dest token. For Crosschain Order - destination token on the destination chain */
destToken: string;
/** @description The deadline for the order */
deadline?: number;
/** @description The nonce of the order */
nonce?: number | string;
/** @description Optional permit signature for the src token */
permit?: string;
/** @description Partner string */
partner?: string;
/** @description Destination Chain ID for Crosschain Orders */
destChainId?: number;
/** @description Seconds between slice executions (min 60) */
interval: number;
/** @description Number of slices (min 2) */
numSlices: number;
/** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5% */
slippage?: number;

/** @description price response received from /delta/prices (getDeltaPrice method) for a single slice */
deltaPrice: MarkOptional<
Pick<
BridgePrice,
| 'destAmount'
| 'partner'
| 'partnerFee'
| 'destToken'
| 'srcAmount'
| 'bridge'
>,
'partner' | 'partnerFee'
>;

/** @description partner fee in basis points (bps), 50bps=0.5% */
partnerFeeBps?: number;
/** @description partner address */
partnerAddress?: string;
/** @description take surplus */
partnerTakesSurplus?: boolean;
/** @description A boolean indicating whether the surplus should be capped. True by default */
capSurplus?: boolean;
/** @description Metadata for the order, hex string */
metadata?: string;
};

export type BuildTWAPSellOrderParams = BuildTWAPDeltaOrderParamsBase & {
/** @description Must be "TWAPOrder" for sell orders */
onChainOrderType: 'TWAPOrder';
/** @description Total source token amount across all slices */
totalSrcAmount: string;
};

export type BuildTWAPBuyOrderParams = BuildTWAPDeltaOrderParamsBase & {
/** @description Must be "TWAPBuyOrder" for buy orders */
onChainOrderType: 'TWAPBuyOrder';
/** @description Total destination token amount to buy across all slices */
totalDestAmount: string;
/** @description Maximum source token amount willing to spend */
maxSrcAmount: string;
};

export type BuildTWAPDeltaOrderParams =
| BuildTWAPSellOrderParams
| BuildTWAPBuyOrderParams;

type BuildTWAPDeltaOrder = (
buildOrderParams: BuildTWAPDeltaOrderParams,
requestParams?: RequestParameters
) => Promise<SignableTWAPOrderData>;

export type BuildTWAPDeltaOrderFunctions = {
/** @description Build TWAP Orders (sell or buy) to be posted to Delta API for execution */
buildTWAPDeltaOrder: BuildTWAPDeltaOrder;
};

export const constructBuildTWAPDeltaOrder = (
options: ConstructFetchInput
): BuildTWAPDeltaOrderFunctions => {
const { chainId } = options;

const { getDeltaContract } = constructGetDeltaContract(options);
const { getPartnerFee } = constructGetPartnerFee(options);

const buildTWAPDeltaOrder: BuildTWAPDeltaOrder = async (
params,
requestParams
) => {
const ParaswapDelta = await getDeltaContract(requestParams);
if (!ParaswapDelta) {
throw new Error(`Delta is not available on chain ${chainId}`);
}

const { partnerAddress, partnerFeeBps, partnerTakesSurplus } =
await resolvePartnerFee(params, getPartnerFee, requestParams);

const commonInput: TWAPOrderCommonInput = {
owner: params.owner,
beneficiary: params.beneficiary,
srcToken: params.srcToken,
destToken: params.deltaPrice.destToken,
deadline: params.deadline,
nonce: params.nonce?.toString(10),
permit: params.permit,
metadata: params.metadata,
interval: params.interval,
numSlices: params.numSlices,
Comment thread
andriy-shymkiv marked this conversation as resolved.
bridge: {
...params.deltaPrice.bridge,
// TWAP child orders get their bridge data at execution time
protocolData: DEFAULT_BRIDGE.protocolData,
Comment thread
andriy-shymkiv marked this conversation as resolved.
},

chainId,
paraswapDeltaAddress: ParaswapDelta,
partnerAddress,
partnerTakesSurplus,
partnerFeeBps,
capSurplus: params.capSurplus,
};

let input: BuildTWAPOrderDataInput;

if (params.onChainOrderType === 'TWAPOrder') {
const slippage = params.slippage ?? 0;
const destAmountPerSlice =
slippage > 0
? applySlippage({
amount: params.deltaPrice.destAmount,
slippageBps: slippage,
increase: false,
})
: params.deltaPrice.destAmount;

input = {
...commonInput,
onChainOrderType: 'TWAPOrder',
destAmountPerSlice,
totalSrcAmount: params.totalSrcAmount,
};
} else {
const slippage = params.slippage ?? 0;
const maxSrcAmount =
slippage > 0
? applySlippage({
amount: params.maxSrcAmount,
slippageBps: slippage,
increase: true,
})
: params.maxSrcAmount;
Comment thread
cursor[bot] marked this conversation as resolved.

input = {
...commonInput,
onChainOrderType: 'TWAPBuyOrder',
totalDestAmount: params.totalDestAmount,
maxSrcAmount,
};
}

return buildTWAPSignableOrderData(input);
};

return {
buildTWAPDeltaOrder,
};
};
Loading
Loading