Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `tokenDecimals` field on `SignetSystemConstants` for testnet overrides
- PARMIGIANA now includes `tokenDecimals: { WUSD: 18 }` override
- `Flow` type export (`"passage"` | `"orders"`)
- `OrderEvent`, `FilledEvent`, `SweepEvent` typed event result interfaces for `parseEventLogs` DX
- RPC Patterns documentation section in README

### Changed
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,53 @@ const serialized = serializeCallBundle(callBundle);
// Use with signet_callBundle RPC method
```

### Parsing RollupOrders Events

Use viem's `parseEventLogs` with the SDK's ABI and event types for typed event indexing:

```typescript
import { createPublicClient, http, parseEventLogs } from "viem";
import {
rollupOrdersAbi,
MAINNET,
type OrderEvent,
type FilledEvent,
type SweepEvent,
} from "@signet-sh/sdk";

const client = createPublicClient({ chain, transport: http(rpcUrl) });

// Fetch logs from a block range
const logs = await client.getLogs({
address: MAINNET.rollupOrders,
fromBlock: 100n,
toBlock: 200n,
});

// Parse all RollupOrders events with full type safety
const events = parseEventLogs({ abi: rollupOrdersAbi, logs });

for (const event of events) {
switch (event.eventName) {
case "Order": {
const { deadline, inputs, outputs } = event.args as OrderEvent;
console.log(`Order with ${inputs.length} inputs, deadline ${deadline}`);
break;
}
case "Filled": {
const { outputs } = event.args as FilledEvent;
console.log(`Filled ${outputs.length} outputs`);
break;
}
case "Sweep": {
const { recipient, token, amount } = event.args as SweepEvent;
console.log(`Sweep ${amount} of ${token} to ${recipient}`);
break;
}
}
}
```

## RPC Patterns

The SDK exports ABIs and token utilities. Use viem directly for RPC operations.
Expand Down Expand Up @@ -386,6 +433,9 @@ const balances = await Promise.all(
- `Permit2Batch` - Permit2 batch transfer data
- `Output` - Order output specification
- `TokenPermissions` - Token permission for Permit2
- `OrderEvent` - Parsed args from an `Order` event
- `FilledEvent` - Parsed args from a `Filled` event
- `SweepEvent` - Parsed args from a `Sweep` event
- `Flow` - Entry mechanism type: `"passage"` or `"orders"`
- `TokenSymbol` - Supported token symbols

Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ export type {
Bytes,
CallBundleTransactionResult,
ChainConfig,
FilledEvent,
Hex,
Input,
OrderEvent,
Output,
Permit2Batch,
PermitBatchTransferFrom,
Expand All @@ -73,6 +75,7 @@ export type {
SignetCallBundle,
SignetCallBundleResponse,
SignetEthBundle,
SweepEvent,
TokenPermissions,
UnsignedOrderParams,
} from "./types/index.js";
Expand Down
39 changes: 39 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Event result types for RollupOrders contract events.
* These types represent the `args` returned by viem's `parseEventLogs`.
*/
import type { Address } from "viem";

import type { Input, Output } from "./primitives.js";

/**
* Parsed args from an `Order` event emitted when an order is initiated.
*/
export interface OrderEvent {
/** Order expiration deadline (unix timestamp) */
readonly deadline: bigint;
/** Tokens offered by the user */
readonly inputs: readonly Input[];
/** Tokens the user wants to receive */
readonly outputs: readonly Output[];
}

/**
* Parsed args from a `Filled` event emitted when outputs are filled.
*/
export interface FilledEvent {
/** Outputs that were filled */
readonly outputs: readonly Output[];
}

/**
* Parsed args from a `Sweep` event emitted when tokens are swept.
*/
export interface SweepEvent {
/** Recipient of the swept tokens */
readonly recipient: Address;
/** Token contract address */
readonly token: Address;
/** Amount swept */
readonly amount: bigint;
}
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export type {

export type { SignedFill } from "./fill.js";

export type { FilledEvent, OrderEvent, SweepEvent } from "./events.js";

export {
OUTPUT_WITNESS_TYPE_STRING,
PERMIT_BATCH_WITNESS_TRANSFER_FROM_TYPES,
Expand Down