# ✨ Feature Request: Implement Offset Helper with Matrix Index Support
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
## What
Implement an offset helper that allows users to specify argument locations using a string format "number.number.number" (e.g., "0.1.3") to represent matrix indices. Replace the current `offsetIndex` in the `Rule` type with `offsetPath`.
## Why
- Provide more flexibility in specifying argument locations, especially for complex data structures like matrices and nested arrays
- Simplify the process of calculating offsets for users by handling the multiplication by 32 internally
- Improve the accuracy of offset calculations for various data types, including arrays and bytes
- Align with Solidity's ABI specification for argument encoding
## How
1. Update the `Rule` type in the smart sessions module:
```typescript
type Rule = {
// ... other properties
offsetPath: string // Format: "number.number.number"
}
```
2. Implement an offset helper function:
```typescript
function calculateOffset(functionSignature: string, offsetPath: string): number {
// Parse the function signature
// Calculate the base offset based on the argument position
// Handle special cases for arrays, bytes, and nested structures
// Apply the offsetPath to navigate through nested structures
// Return the final offset (always a multiple of 32)
}
```
3. Utilize viem's `encodeFunctionData` and `decodeFunctionData` methods to assist in parsing function signatures and argument structures
4. Implement special handling for arrays and bytes as per the Solidity ABI specification
5. Add validation for the `offsetPath` format to ensure it's correctly formatted
6. Update existing code that uses `offsetIndex` to use the new `offsetPath` and `calculateOffset` function
7. Create unit tests covering various scenarios:
- Simple arguments
- Arrays
- Nested structures
- Edge cases (e.g., very long arrays, complex nested structures)
8. Update documentation to explain the new `offsetPath` format and provide examples of its usage
9. Create a migration guide for users updating from `offsetIndex` to `offsetPath`
## References
- [Solidity ABI Specification](https://docs.soliditylang.org/en/develop/abi-spec.html)
- [viem decodeFunctionData](https://viem.sh/docs/contract/decodeFunctionData.html)
- [viem encodeFunctionData](https://viem.sh/docs/contract/encodeFunctionData.html)
- [Smart Sessions Module Types](node_modules/@rhinestone/module-sdk/module/smart-sessions/types.ts)
---
- [x] I agree to follow this project's Code of Conduct.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.