Skip to content
This repository was archived by the owner on Feb 8, 2026. It is now read-only.

fix payroll data structures & policy validation#125

Merged
webpiratt merged 1 commit into
mainfrom
payroll-fixes
Jul 9, 2025
Merged

fix payroll data structures & policy validation#125
webpiratt merged 1 commit into
mainfrom
payroll-fixes

Conversation

@webpiratt

@webpiratt webpiratt commented Jul 9, 2025

Copy link
Copy Markdown
Contributor
  • Fix some data & marshalling & validation;
  • Use contract addresses instead of tokens symbols, it would be correct for financial system. For example there are few valid USDC with same symbol (at least two: Circle and Wormhole bridged);

Ref: #124

Summary by CodeRabbit

  • New Features

    • Added support for specifying a "token" parameter in payroll rules, enabling selection of ERC20/TRC20 contract addresses for transactions.
  • Improvements

    • Simplified token ID extraction in payroll transactions by using parameter constraints instead of external chain lookups.
    • Increased the allowed number of parameter constraints in rules to accommodate the new "token" parameter.
    • Updated scheduling limits to allow unlimited scheduled executions.
  • Bug Fixes

    • Improved error handling when decoding and parsing policy schedules.
  • Documentation

    • Added clarifying comments regarding the "token" parameter in recipe specifications.

@coderabbitai

coderabbitai Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This set of changes updates the payroll plugin to support a "token" parameter in policy rules, simplifies token ID extraction from rule parameter constraints, and switches policy deserialization from JSON to base64-decoded protobuf. It also adds related validation logic, updates scheduling limits, and includes a minor comment addition for local debugging.

Changes

File(s) Change Summary
api/plugin.go Added a TODO comment regarding local debugging and signature validation in CreatePluginPolicy.
internal/scheduler/scheduler.go Changed policy deserialization from JSON to base64-decoded protobuf in GetTriggerFromPolicy.
plugin/payroll/policy.go Added validateToken method; updated checkRule to recognize "token" parameter.
plugin/payroll/transaction.go Simplified token ID extraction with getTokenID helper; removed unused imports; updated scheduling and parameter constraint logic; clarified comments.

Sequence Diagram(s)

sequenceDiagram
    participant Scheduler
    participant Policy
    participant Protobuf

    Scheduler->>Policy: GetTriggerFromPolicy(policy)
    Policy->>Scheduler: policy.Recipe (base64 string)
    Scheduler->>Protobuf: base64 decode + proto.Unmarshal
    Protobuf-->>Scheduler: Policy object
    Scheduler->>Scheduler: Proceed with trigger extraction
Loading
sequenceDiagram
    participant Plugin
    participant Rule
    participant getTokenID

    Plugin->>Rule: Access parameter constraints
    Plugin->>getTokenID: getTokenID(rule)
    getTokenID->>Rule: Find "token" constraint
    getTokenID-->>Plugin: Return token ID or zero address
    Plugin->>Plugin: Use token ID in transaction proposal
Loading

Possibly related PRs

Suggested reviewers

  • johnnyluo

Poem

In the meadow of code where payroll hops,
A token now joins, and old logic stops.
Protobuf and base64, a new recipe to chew,
Constraints are checked, with validation anew.
The scheduler leaps, the plugin delights,
Hopping ahead with more elegant bytes! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
plugin/payroll/transaction.go (1)

404-404: Unlimited scheduled executions may impact performance.

The change from MaxScheduledExecutions: 100 to MaxScheduledExecutions: -1 (infinite) removes the execution limit, which could lead to performance issues or resource exhaustion.

Consider whether unlimited executions are truly needed or if a higher but finite limit would be more appropriate for production environments. You might also want to implement monitoring and alerting for policies with high execution counts.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80db263 and bdacaca.

📒 Files selected for processing (4)
  • api/plugin.go (1 hunks)
  • internal/scheduler/scheduler.go (3 hunks)
  • plugin/payroll/policy.go (2 hunks)
  • plugin/payroll/transaction.go (5 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:178-183
Timestamp: 2025-06-18T18:28:19.759Z
Learning: In the payroll plugin, the Hash field in PluginKeysignRequest is intentionally set to the unsigned transaction hex (same as Message field) because computing a hash with empty V,R,S signature fields doesn't make sense, and it's documented as "not on-chain hash without signature". This is a deliberate placeholder approach.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
api/plugin.go (1)
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
internal/scheduler/scheduler.go (1)
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
plugin/payroll/policy.go (3)
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:510-514
Timestamp: 2025-06-18T18:20:59.510Z
Learning: The erc20ABI constant is defined in plugin/payroll/constants.go within the payroll package, making it accessible to other files in the same package like transaction.go.
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
plugin/payroll/transaction.go (5)
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:0-0
Timestamp: 2025-06-18T18:23:20.077Z
Learning: In the payroll plugin (plugin/payroll/transaction.go), signRequest.Transaction is stored with the "0x" prefix, making it compatible with gcommon.FromHex which requires 0x-prefixed hex strings.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:510-514
Timestamp: 2025-06-18T18:20:59.510Z
Learning: The erc20ABI constant is defined in plugin/payroll/constants.go within the payroll package, making it accessible to other files in the same package like transaction.go.
Learnt from: webpiratt
PR: vultisig/plugin#96
File: plugin/payroll/transaction.go:43-44
Timestamp: 2025-06-18T18:22:06.358Z
Learning: In the vultisig/plugin codebase, the hardcoded ethereumEvmChainID = big.NewInt(1) in plugin/payroll/transaction.go is intentional for the current implementation phase. The team is implementing ETH first, with plans to add other EVM chains later. The functions/methods are already designed to work with all EVM chains.
Learnt from: garry-sharp
PR: vultisig/plugin#117
File: plugin/fees/policy.go:46-47
Timestamp: 2025-07-04T10:47:47.927Z
Learning: For the fee plugin in plugin/fees/policy.go, the resource validation and recipe specification are intentionally configured to accept only USDC transfers ("ethereum.usdc.transfer"), not general ERC20 transfers ("ethereum.erc20.transfer"), as fees are only collected in USDC.
Learnt from: RaghavSood
PR: vultisig/plugin#36
File: api/server.go:21-33
Timestamp: 2025-05-07T08:23:45.882Z
Learning: The import path `github.com/vultisig/verifier/plugin` refers to an external dependency that provides the plugin interface, and should not be changed to `github.com/vultisig/plugin/plugin` as these are distinct packages with different purposes.
🧬 Code Graph Analysis (1)
plugin/payroll/policy.go (1)
plugin/payroll/payroll.go (1)
  • PayrollPlugin (19-29)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
api/plugin.go (1)

191-191: Development note acknowledged.

The TODO comment serves as a helpful reminder for local debugging scenarios involving recipe mocks and signature validation.

internal/scheduler/scheduler.go (1)

188-195: Policy serialization format changes verified

All occurrences of policy.Recipe now consistently use protobuf-encoded, base64 strings:

  • common/util.go – RecipeToBase64: proto.Marshal + base64 encode
  • internal/scheduler/scheduler.go – GetTriggerFromPolicy: base64 decode + proto.Unmarshal
  • plugin/payroll/policy.go & plugin/fees/policy.go – base64 decode + proto.Unmarshal
  • No remaining JSON Unmarshal of policy.Recipe in production code

No further action required.

plugin/payroll/transaction.go (1)

449-449: Parameter constraints limit increase is logical.

The increase from 2 to 3 parameter constraints aligns with the addition of the "token" parameter alongside existing "recipient" and "amount" parameters.

Comment thread plugin/payroll/policy.go
Comment thread plugin/payroll/policy.go
Comment thread plugin/payroll/transaction.go

@johnnyluo johnnyluo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants