Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Each file exports `constructContractCaller(provider, account)` → `ContractCall

- `delta/` — Core feature: Delta auction orders (server-side order building, route-based pricing, paginated orders; see detail below)
- `swap/` — Token swap: rates, transaction building, approvals, balances
- `limitOrders/` — **Deprecated.** EIP-712 signed limit orders
- `otcOrders/` — EIP-712 signed OTC orders
Comment thread
Velenir marked this conversation as resolved.
- `nftOrders/` — **Deprecated.** EIP-712 signed NFT orders
- `quote/` — Unified `/v2/quote` endpoint (mode-selectable Delta v2 price / market / fallback)

Expand All @@ -58,7 +58,7 @@ Every feature module exports a `constructXxx(options) => XxxFunctions` factory:
- `D` selects required caller methods: `'transactCall'` | `'signTypedDataCall'` | both
- Generic `<T>` = transaction response type (e.g., `TxHash`, `ethers.ContractTransaction`)
- Non-generic constructors use `any` (for API-only flows that don't return tx responses)
- All Delta constructors are combined in `constructAllDeltaOrdersHandlers` in `src/methods/delta/index.ts`. **Convention:** bind each `constructXxx(options)` call to a named local (`const deltaPrice = constructGetDeltaPrice(options)`), then spread those locals into the returned object — don't spread the constructor calls inline. (Matches `constructAllLimitOrdersHandlers`.)
- All Delta constructors are combined in `constructAllDeltaOrdersHandlers` in `src/methods/delta/index.ts`. **Convention:** bind each `constructXxx(options)` call to a named local (`const deltaPrice = constructGetDeltaPrice(options)`), then spread those locals into the returned object — don't spread the constructor calls inline.

## Key Patterns

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@size-limit/preset-small-lib": "^12.1.0",
"@tsconfig/recommended": "^1.0.8",
"@types/jest": "^30.0.0",
"@types/node": "^22.8.5",
"@wagmi/connectors": "^8.0.13",
"@wagmi/core": "^3.4.11",
"axios": "^1.13.2",
Expand Down Expand Up @@ -131,4 +132,4 @@
},
"bugs": "https://github.com/VeloraDEX/paraswap-sdk/issues",
"packageManager": "pnpm@11.1.2"
}
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions src/examples/limitOrders_all.ts → src/examples/otcOrders_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import {
constructPartialSDK,
constructEthersContractCaller,
constructAxiosFetcher,
// limitOrders methods
constructAllLimitOrdersHandlers,
// OTCOrders methods
constructAllOTCOrdersHandlers,
// extra types
LimitOrderFromApi,
OTCOrder,
SwappableOrder,
} from '..';

const account = '0x1234...';
const takerAccount = '0x5678...';

const fetcher = constructAxiosFetcher(axios);

Expand All @@ -30,17 +31,17 @@ const contractCaller = constructEthersContractCaller(
account
);

// type BuildLimitOrderFunctions
// & SignLimitOrderFunctions
// & CancelLimitOrderFunctions<ethers.ContractTransaction>
// type BuildOTCOrderFunctions
// & SignOTCOrderFunctions
// & CancelOTCOrderFunctions<ethers.ContractTransaction>
// & ApproveTokenFunctions<ethers.ContractTransaction>
const limitOrderSDK = constructPartialSDK(
const OTCOrderSDK = constructPartialSDK(
{
chainId: 1,
fetcher,
contractCaller,
},
constructAllLimitOrdersHandlers
constructAllOTCOrdersHandlers
);

const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
Expand All @@ -54,26 +55,25 @@ const orderInput = {
makerAmount: (1e18).toString(10),
takerAmount: (8e18).toString(10),
maker: account,
taker: takerAccount,
};

async function run() {
// approve token for the limit order
// approve token for the OTC order
const tx1: ethers.ContractTransaction =
await limitOrderSDK.approveMakerTokenForLimitOrder(
await OTCOrderSDK.approveMakerTokenForOTCOrder(
orderInput.makerAmount,
orderInput.makerAsset
);

// builds + signs + posts order to API
// new limit order returned from API
const newLimitOrder: LimitOrderFromApi = await limitOrderSDK.submitLimitOrder(
orderInput
);
// new OTC order returned from API
const newOTCOrder: OTCOrder = await OTCOrderSDK.submitOTCOrder(orderInput);

// to act as order taker
const anotherAccount = '0x5678...';

const limitOrdersSDKForTaker = constructPartialSDK(
const OTCOrdersSDKForTaker = constructPartialSDK(
{
chainId: 1,
fetcher,
Expand All @@ -85,22 +85,22 @@ async function run() {
anotherAccount
),
},
constructAllLimitOrdersHandlers
constructAllOTCOrdersHandlers
);

const tx2: ethers.ContractTransaction =
await limitOrdersSDKForTaker.approveTakerTokenForLimitOrder(
await OTCOrdersSDKForTaker.approveTakerTokenForOTCOrder(
orderInput.takerAmount,
orderInput.takerAsset
);

const executingOrder: SwappableOrder = {
...newLimitOrder,
permitMakerAsset: newLimitOrder.permitMakerAsset || undefined,
...newOTCOrder,
permitMakerAsset: newOTCOrder.permitMakerAsset || undefined,
};

const { gas: payloadGas, ...LOPayloadTxParams } =
await limitOrdersSDKForTaker.buildLimitOrderTx({
await OTCOrdersSDKForTaker.buildOTCOrderTx({
srcDecimals: 18,
destDecimals: 18,
userAddress: anotherAccount, // taker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import {
constructPartialSDK,
constructEthersContractCaller,
constructAxiosFetcher,
// limitOrders methods
constructBuildLimitOrder,
constructCancelLimitOrder,
constructSignLimitOrder,
constructGetLimitOrders,
constructPostLimitOrder,
constructApproveTokenForLimitOrder,
// OTCOrders methods
constructBuildOTCOrder,
constructCancelOTCOrder,
constructSignOTCOrder,
constructGetOTCOrders,
constructPostOTCOrder,
constructApproveTokenForOTCOrder,
// extra types
SignableOrderData,
LimitOrderToSend,
constructBuildLimitOrderTx,
OTCOrderToPost,
constructBuildOTCOrderTx,
} from '..';

const account = '0x1234...';
const takerAccount = '0x5678...';

const fetcher = constructAxiosFetcher(axios);

Expand All @@ -36,22 +37,22 @@ const contractCaller = constructEthersContractCaller(
account
);

// type BuildLimitOrderFunctions
// & SignLimitOrderFunctions
// & CancelLimitOrderFunctions<ethers.ContractTransaction>
// type BuildOTCOrderFunctions
// & SignOTCOrderFunctions
// & CancelOTCOrderFunctions<ethers.ContractTransaction>
// & ApproveTokenFunctions<ethers.ContractTransaction>
const limitOrderSDK = constructPartialSDK(
const OTCOrderSDK = constructPartialSDK(
{
chainId: 1,
fetcher,
contractCaller,
},
constructBuildLimitOrder,
constructCancelLimitOrder,
constructSignLimitOrder,
constructPostLimitOrder,
constructGetLimitOrders,
constructApproveTokenForLimitOrder
constructBuildOTCOrder,
constructCancelOTCOrder,
constructSignOTCOrder,
constructPostOTCOrder,
constructGetOTCOrders,
constructApproveTokenForOTCOrder
);

const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
Expand All @@ -65,55 +66,56 @@ const orderInput = {
makerAmount: (1e18).toString(10),
takerAmount: (8e18).toString(10),
maker: account,
taker: takerAccount,
};

async function run() {
/// cancelling current orders
const { orders: currentOrders } = await limitOrderSDK.getLimitOrders({
const { orders: currentOrders } = await OTCOrderSDK.getOTCOrders({
maker: account,
type: 'LIMIT',
});

if (currentOrders[0]?.orderHash) {
const tx1: ethers.ContractTransaction =
await limitOrderSDK.cancelLimitOrder(currentOrders[0].orderHash);
const tx1: ethers.ContractTransaction = await OTCOrderSDK.cancelOTCOrder(
currentOrders[0].orderHash
);
}

const moreOrderHashes = currentOrders
.slice(1, 2)
.map((order) => order.orderHash);

const tx2: ethers.ContractTransaction =
await limitOrderSDK.cancelLimitOrderBulk(moreOrderHashes);
const tx2: ethers.ContractTransaction = await OTCOrderSDK.cancelOTCOrdersBulk(
moreOrderHashes
);

/// creating a new order

const tx3: ethers.ContractTransaction =
await limitOrderSDK.approveMakerTokenForLimitOrder(
await OTCOrderSDK.approveMakerTokenForOTCOrder(
orderInput.makerAmount,
orderInput.makerAsset
);

const signableOrderData: SignableOrderData =
await limitOrderSDK.buildLimitOrder(orderInput);

const signature: string = await limitOrderSDK.signLimitOrder(
signableOrderData
const signableOrderData: SignableOrderData = await OTCOrderSDK.buildOTCOrder(
orderInput
);

const orderToPostToApi: LimitOrderToSend = {
const signature: string = await OTCOrderSDK.signOTCOrder(signableOrderData);

const orderToPostToApi: OTCOrderToPost = {
...signableOrderData.data,
signature,
};

const newOrder = await limitOrderSDK.postLimitOrder(orderToPostToApi);
const newOrder = await OTCOrderSDK.postOTCOrder(orderToPostToApi);

/// filling an order

// to act as order taker
const anotherAccount = '0x5678...';

const limitOrderSDKForTaker = constructPartialSDK(
const OTCOrderSDKForTaker = constructPartialSDK(
{
chainId: 1,
fetcher,
Expand All @@ -125,18 +127,18 @@ async function run() {
anotherAccount
),
},
constructBuildLimitOrderTx,
constructApproveTokenForLimitOrder
constructBuildOTCOrderTx,
constructApproveTokenForOTCOrder
);

const tx4: ethers.ContractTransaction =
await limitOrderSDKForTaker.approveTakerTokenForLimitOrder(
await OTCOrderSDKForTaker.approveTakerTokenForOTCOrder(
orderInput.takerAmount,
orderInput.takerAsset
);

const { gas: payloadGas, ...LOPayloadTxParams } =
await limitOrderSDKForTaker.buildLimitOrderTx({
await OTCOrderSDKForTaker.buildOTCOrderTx({
srcDecimals: 18,
destDecimals: 18,
userAddress: anotherAccount, // taker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ import {
constructPartialSDK,
constructEthersContractCaller,
constructAxiosFetcher,
// limitOrders methods
constructBuildLimitOrder,
constructSignLimitOrder,
constructPostLimitOrder,
// OTCOrders methods
constructBuildOTCOrder,
constructSignOTCOrder,
constructPostOTCOrder,
// extra types
SignableOrderData,
LimitOrderToSend,
OTCOrderToPost,
} from '..';

const wallet = ethers.Wallet.createRandom();
const takerAccount = '0x5678...';

const fetcher = constructAxiosFetcher(axios);

Expand All @@ -29,19 +30,19 @@ const contractCaller = constructEthersContractCaller(
wallet.address
);

// type BuildLimitOrderFunctions
// & SignLimitOrderFunctions
// & PostLimitOrderFunctions
// type BuildOTCOrderFunctions
// & SignOTCOrderFunctions
// & PostOTCOrderFunctions

const limitOrderSDK = constructPartialSDK(
const OTCOrderSDK = constructPartialSDK(
{
chainId: 1,
fetcher,
contractCaller,
},
constructBuildLimitOrder,
constructSignLimitOrder,
constructPostLimitOrder
constructBuildOTCOrder,
constructSignOTCOrder,
constructPostOTCOrder
);

const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
Expand All @@ -55,22 +56,22 @@ const orderInput = {
makerAmount: (1e18).toString(10),
takerAmount: (8e18).toString(10),
maker: wallet.address,
taker: takerAccount,
};

async function run() {
const signableOrderData: SignableOrderData =
await limitOrderSDK.buildLimitOrder(orderInput);

const signature: string = await limitOrderSDK.signLimitOrder(
signableOrderData
const signableOrderData: SignableOrderData = await OTCOrderSDK.buildOTCOrder(
orderInput
);

const orderToPostToApi: LimitOrderToSend = {
const signature: string = await OTCOrderSDK.signOTCOrder(signableOrderData);

const orderToPostToApi: OTCOrderToPost = {
...signableOrderData.data,
signature,
};

const newOrder = await limitOrderSDK.postLimitOrder(orderToPostToApi);
const newOrder = await OTCOrderSDK.postOTCOrder(orderToPostToApi);
console.log(newOrder);
}

Expand Down
Loading
Loading