-
Notifications
You must be signed in to change notification settings - Fork 112
Feat/Delta -- depositNativeAndPreSign #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andriy-shymkiv
wants to merge
20
commits into
master
Choose a base branch
from
feat/delta_depositNativeAndPreSign
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+510
−13
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
379c6c6
depositNativeAndPreSign
andriy-shymkiv f6a3c5e
constructPreSignDeltaOrder/better naming
andriy-shymkiv 067a7d3
PreSignatureModuleAbi/correct abi
andriy-shymkiv e52cee2
Release 9.3.3-dev.1
andriy-shymkiv 7abd087
deltaTokenModule/create constructDeltaTokenModule with combined Delta…
andriy-shymkiv 229c56f
cancelDeltaOrder/revert to non-generic API-only cancel
andriy-shymkiv e54663f
preSignDeltaOrder/remove depositNativeAndPreSign from PreSignatureModule
andriy-shymkiv 6544151
delta/wire constructDeltaTokenModule into SDK exports and types
andriy-shymkiv b07162c
deltaTokenModule/use actual ABI
andriy-shymkiv d8c1ced
deltaTokenModule/default bridgeOverride and cosignature
andriy-shymkiv 881e5bb
cancelAndWithdrawDeltaOrder/remove SDK defaults
andriy-shymkiv 01c0704
Merge branch 'master' of github.com:VeloraDEX/sdk into feat/delta_dep…
andriy-shymkiv 4521cdb
Release 9.3.4-dev.1
andriy-shymkiv dce35b9
remove comment
andriy-shymkiv 4ac84b3
deltaTokenModule/change params and provide defaults to some functions
andriy-shymkiv 100dc36
reexport deltaTokenModule types from index.ts
andriy-shymkiv 3dc09e1
CLAUDE.md: document all delta module files with constructors and patt…
andriy-shymkiv ac55dd9
bring the comment about return type back and remove it for constructC…
andriy-shymkiv 3c66a15
Release 9.3.4-dev.4
andriy-shymkiv 06d1c6e
cancelAndWithdrawDeltaOrder/provide defaults
andriy-shymkiv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # Velora SDK — Architecture Guide | ||
|
|
||
| TypeScript SDK for the Paraswap/Velora Delta protocol (on-chain order-based DEX). | ||
|
|
||
| ## Composable Constructor Pattern | ||
|
|
||
| Every feature module exports a `constructXxx(options) => XxxFunctions` factory: | ||
| - `options` is `ConstructProviderFetchInput<T, D>` or a `Pick` of it | ||
| - `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` | ||
|
|
||
| ## Key Patterns | ||
|
|
||
| ### On-Chain Transaction (reference: `src/methods/delta/preSignDeltaOrder.ts`) | ||
| 1. Define minimal ABI inline as `const XxxAbi = [...] as const` | ||
| 2. Extract method names: `type AvailableMethods = ExtractAbiMethodNames<typeof XxxAbi>` | ||
| 3. Constructor takes `ConstructProviderFetchInput<T, 'transactCall'>` | ||
| 4. Get contract address: `const { getDeltaContract } = constructGetDeltaContract(options)` | ||
| 5. Call contract: `options.contractCaller.transactCall<AvailableMethods>({ address, abi, contractMethod, args, overrides })` | ||
|
|
||
| ### API Call (reference: `src/methods/delta/cancelDeltaOrder.ts` sign/post methods) | ||
| 1. Sign EIP-712 typed data via `options.contractCaller.signTypedDataCall(typedData)` | ||
| 2. POST to API via `options.fetcher<ResponseType>({ url, method, data })` | ||
|
|
||
| ## Key File Locations | ||
|
|
||
| ### Delta Module (`src/methods/delta/`) | ||
| | File | Constructor | Purpose | Generic? | Pattern | | ||
| |------|-------------|---------|----------|---------| | ||
| | `index.ts` | `constructSubmitDeltaOrder`, `constructAllDeltaOrdersHandlers` | Composite: orchestrates all modules, defines `DeltaOrderHandlers<T>` | `submitDelta`: No, `allHandlers`: `<T>` | Composite | | ||
| | `buildDeltaOrder.ts` | `constructBuildDeltaOrder` | Build `SignableDeltaOrderData` from params (fetches contract + partner fee, then local computation) | No | API fetch + local | | ||
| | `signDeltaOrder.ts` | `constructSignDeltaOrder` | EIP-712 sign order via `signTypedDataCall` → returns signature `string` | No (`any`) | `signTypedDataCall` | | ||
| | `postDeltaOrder.ts` | `constructPostDeltaOrder` | POST signed order to API → `DeltaOrderApiResponse` | No | `fetcher` POST | | ||
| | `getDeltaPrice.ts` | `constructGetDeltaPrice` | Fetch quote/price from API. Overloaded: returns `DeltaPrice` (same-chain) or `BridgePrice` (cross-chain when `destChainId` present) | No | `fetcher` GET | | ||
| | `getDeltaOrders.ts` | `constructGetDeltaOrders` | Query orders from API: `getDeltaOrderById`, `getDeltaOrderByHash`, `getDeltaOrders` (list), `getRequiredBalanceForDeltaLimitOrders` | No | `fetcher` GET | | ||
| | `getDeltaContract.ts` | `constructGetDeltaContract` | Resolve ParaswapDelta contract address from contracts endpoint | No | `fetcher` GET | | ||
| | `approveForDelta.ts` | `constructApproveTokenForDelta` | ERC-20 `approve` with ParaswapDelta as spender (delegates to `approveTokenMethodFactory`) | `<T>` | `transactCall` | | ||
| | `preSignDeltaOrder.ts` | `constructPreSignDeltaOrder` | On-chain `setPreSignature` + order hashing helpers (`hashDeltaOrderTypedData`, `hashDeltaOrder`, `preSignDeltaOrder`) | `<T>` | `transactCall` | | ||
| | `cancelDeltaOrder.ts` | `constructCancelDeltaOrder` | API cancel: `signCancelLimitDeltaOrderRequest` → `postCancelLimitDeltaOrderRequest` → `cancelLimitDeltaOrders` (orchestrator) | No (`any`) | `signTypedDataCall` + `fetcher` POST | | ||
| | `deltaTokenModule.ts` | `constructDeltaTokenModule` | On-chain `cancelAndWithdrawDeltaOrder`, `withdrawDeltaNative`, `depositNativeAndPreSign`, `depositNativeAndPreSignDeltaOrder` | `<T>` | `transactCall` | | ||
| | `getPartnerFee.ts` | `constructGetPartnerFee` | Fetch partner fee info (internally cached per partner in a `Map`) | No | `fetcher` GET | | ||
| | `getBridgeInfo.ts` | `constructGetBridgeInfo` | `getBridgeInfo` (supported routes) + `getBridgeProtocols` | No | `fetcher` GET | | ||
| | `isTokenSupportedInDelta.ts` | `constructIsTokenSupportedInDelta` | Check if a token is supported → `boolean` | No | `fetcher` GET | | ||
| | `constants.ts` | — | `DEFAULT_BRIDGE` constant (all-zero values for same-chain orders) | — | — | | ||
|
|
||
| ### Delta Helpers (`src/methods/delta/helpers/`) | ||
| - `types.ts` — `DeltaAuctionOrder`, `Bridge`, `DeltaAuction`, `DeltaAuctionStatus`, `BridgeMetadata`, `BridgeStatus`, `BridgePriceInfo`, `SwapSideToOrderKind` | ||
| - `buildDeltaOrderData.ts` — `buildDeltaSignableOrderData`, `produceDeltaOrderTypedData`, `SignableDeltaOrderData`, `BuildDeltaOrderDataInput`, `DELTA_DEFAULT_EXPIRY` | ||
| - `buildCancelDeltaOrderData.ts` — `buildCancelDeltaOrderSignableData`, `SignableCancelDeltaOrderData`, `CancelDeltaOrderData` | ||
| - `misc.ts` — `sanitizeDeltaOrderData` (strips extra fields from order data before signing/hashing) | ||
|
|
||
| ### Core Types (`src/`) | ||
| - `types.ts` — `ConstructProviderFetchInput`, `ContractCallerFunctions`, `TxSendOverrides` | ||
| - `helpers/misc.ts` — `ExtractAbiMethodNames<T>` | ||
| - `sdk/partial.ts` — `constructPartialSDK`, `InferWithTxResponse` type tuple | ||
|
|
||
| ## Checklist: Adding a New On-Chain Method | ||
|
|
||
| 1. Add ABI to the module file (inline `as const`) | ||
| 2. Add `type AvailableMethods = ExtractAbiMethodNames<typeof Abi>` | ||
| 3. Make constructor generic `<T>` if not already | ||
| 4. Add `'transactCall'` to the `ConstructProviderFetchInput` `Pick` | ||
| 5. Implement function using `options.contractCaller.transactCall<AvailableMethods>({...})` | ||
| 6. Export function type + param types | ||
| 7. Update `DeltaOrderHandlers<T>` in `src/methods/delta/index.ts` (make generic if was non-generic) | ||
| 8. Add to `InferWithTxResponse` tuple in `src/sdk/partial.ts` (import + add to array) | ||
| 9. Export new types from `src/index.ts` | ||
| 10. Run `npx tsc --noEmit` to verify | ||
|
|
||
| ## Solidity ABI: Order Struct Mapping | ||
|
|
||
| When writing inline ABI for functions that take the `Order` struct: | ||
|
|
||
| ``` | ||
| Order tuple (maps to DeltaAuctionOrder in TS): | ||
| owner → address | ||
| beneficiary → address | ||
| srcToken → address | ||
| destToken → address | ||
| srcAmount → uint256 | ||
| destAmount → uint256 | ||
| expectedAmount → uint256 | ||
| kind → uint8 (enum OrderKind) | ||
| metadata → bytes32 | ||
| deadline → uint256 | ||
| nonce → uint256 | ||
| permit → bytes | ||
| partnerAndFee → uint256 | ||
| bridge → tuple (Bridge) | ||
| protocolSelector → bytes4 | ||
| destinationChainId → uint64 | ||
| outputToken → address | ||
| scalingFactor → uint32 | ||
| protocolData → bytes | ||
|
|
||
| OrderWithSig tuple: | ||
| order → tuple (Order) | ||
| signature → bytes | ||
| ``` | ||
|
|
||
| ## Key Conventions | ||
| - Contract address is always resolved via `constructGetDeltaContract(options).getDeltaContract()` | ||
| - EIP-712 domain: `{ name: 'Portikus', version: '2.0.0', chainId, verifyingContract }` | ||
| - Order hash: computed via viem's `hashTypedData` in `produceDeltaOrderHash()` | ||
| - ABI style: always inline `const ... as const`, never imported from external ABI files | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { ZERO_ADDRESS } from '../common/orders/buildOrderData'; | ||
| import { Bridge } from './helpers/types'; | ||
|
|
||
| // for same-chain Orders, all 0 params | ||
| export const DEFAULT_BRIDGE = { | ||
| protocolSelector: '0x00000000', // 4 bytes | ||
| destinationChainId: 0, | ||
| outputToken: ZERO_ADDRESS, | ||
| scalingFactor: 0, | ||
| protocolData: '0x', | ||
| } as const satisfies Bridge; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.