Skip to content

abi: support merkl#71

Draft
RaghavSood wants to merge 2 commits intomainfrom
feat/merkl_abi
Draft

abi: support merkl#71
RaghavSood wants to merge 2 commits intomainfrom
feat/merkl_abi

Conversation

@RaghavSood
Copy link
Collaborator

@RaghavSood RaghavSood commented Aug 31, 2025

Adds basic merkl claims contract ABI support

We only require the claim function, so the rest of the ABI is omitted for brevity.

Summary by CodeRabbit

  • New Features
    • Added support for Angle Merkl Distributor reward claims, with guidance and validation for required parameters to prevent malformed transactions.
    • Supports multi-user and multi-token claim workflows with Merkle-proof inputs.
    • Integrated into the protocol registry for immediate availability across the app, with clearer error messages when required fields are missing.
  • Tests
    • Introduced unit tests for valid claim scenarios to ensure reliability and correctness of the new validation and integration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 31, 2025

Walkthrough

Adds ABI entry for a new claim function, implements AngleMerklDistributor validator with customization and validation for claim, registers it in the loader, and introduces a unit test validating the claim parameters flow.

Changes

Cohort / File(s) Summary
ABI update
abi/angle_merkl_distributor.json
Adds nonpayable function claim(address[] users, address[] tokens, uint256[] amounts, bytes32[][] proofs) with no return values.
Protocol validator implementation
ethereum/angle_merkl_distributor.go
Introduces AngleMerklDistributor with constructor, protocol ID, function customization for claim, and transaction validation requiring users; includes helper functions.
Validator registration
ethereum/loader.go
Registers AngleMerklDistributor in registerProtocolValidators via GlobalValidatorRegistry.
Unit tests
ethereum/angle_merkl_distributor_test.go
Adds test for ValidateTransaction("claim", ...) ensuring no error on a populated parameter set.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Loader
  participant LR as GlobalValidatorRegistry
  participant AMD as AngleMerklDistributor

  Dev->>AMD: NewAngleMerklDistributor()
  AMD-->>Dev: *instance*
  Dev->>LR: Register(AMD.GetProtocolID(), AMD)
  LR-->>Dev: ok
Loading
sequenceDiagram
  autonumber
  actor Client
  participant VF as Validator (AMD)
  participant ABI as ABIFunction
  participant ETH as types.Function

  Client->>VF: CustomizeFunctions(ETH, ABI) for "claim"
  VF->>ABI: Set description, annotate params (users, tokens, amounts, proofs)
  ABI-->>Client: Customized metadata

  Client->>VF: ValidateTransaction("claim", params)
  alt claim validation
    VF->>VF: validateClaimTransaction(params)
    VF-->>Client: nil (if 'users' present)
  else other function
    VF-->>Client: nil
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my ears at merkl’d trees,
New claims hop in on chain-side breeze.
A validator thumps, “All clear!”
Users in rows, proofs appear.
I stamp my paw—tests run, delight—
Another carrot merged tonight. 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/merkl_abi

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (5)
abi/angle_merkl_distributor.json (1)

20-23: Confirm proofs dimensionality (bytes32[][]) vs. actual contract signature.

The test passes a flat []string for proofs, while the ABI declares bytes32[][]. If the builder enforces ABI shapes, this mismatch will break encoding at runtime. Verify whether the contract expects bytes32[] or bytes32[][]. Adjust either the ABI or input normalization accordingly.

Would you like me to normalize flat proofs to [][] at validation time if the ABI keeps bytes32[][]?

ethereum/angle_merkl_distributor.go (3)

19-26: Nit: Proper-case “Merkl” in description.

Small polish for user-facing text.

Apply:

-        f.Description = "Claim tokens from the merkl distributor"
+        f.Description = "Claim tokens from the Merkl distributor"

37-50: Enrich parameter descriptions with expectations (lengths, units, shape).

Clarify required relationships to reduce user error.

Apply:

-        case "users":
-            param.Description = "Array of addresses to claim tokens for"
+        case "users":
+            param.Description = "Addresses being claimed for (EIP-55 strings; non-empty)"
-        case "tokens":
-            param.Description = "Array of token addresses to claim"
+        case "tokens":
+            param.Description = "ERC-20 token addresses; must align 1:1 with amounts"
-        case "amounts":
-            param.Description = "Array of amounts to claim"
+        case "amounts":
+            param.Description = "Amounts (uint256, as decimals string or number); same length as tokens"
-        case "proofs":
-            param.Description = "Array of proofs to claim"
+        case "proofs":
+            param.Description = "Merkle proofs; either bytes32[] (flat) or bytes32[][] (per-claim)"

52-60: Validate all required fields, lengths, and proofs shape.

Current check only ensures presence of users; weak validation risks malformed transactions.

Apply:

 func (a *AngleMerklDistributor) validateClaimTransaction(params map[string]interface{}) error {
-	// Get users
-	_, ok := params["users"]
-	if !ok {
-		return fmt.Errorf("users are required")
-	}
-
-	return nil
+	// users
+	users, ok := params["users"].([]string)
+	if !ok || len(users) == 0 {
+		return fmt.Errorf("users are required and must be a non-empty array")
+	}
+
+	// tokens and amounts
+	tokens, tokOK := params["tokens"].([]string)
+	amts, amtOK := params["amounts"].([]string)
+	if !tokOK || !amtOK || len(tokens) == 0 || len(amts) == 0 {
+		return fmt.Errorf("tokens and amounts are required and must be non-empty string arrays")
+	}
+	if len(tokens) != len(amts) {
+		return fmt.Errorf("tokens and amounts must have the same length")
+	}
+
+	// proofs: accept []string or [][]string
+	pf, pfOK := params["proofs"]
+	if !pfOK {
+		return fmt.Errorf("proofs are required")
+	}
+	switch p := pf.(type) {
+	case []string:
+		if len(p) == 0 {
+			return fmt.Errorf("proofs cannot be empty")
+		}
+	case [][]string:
+		if len(p) != len(tokens) {
+			return fmt.Errorf("proofs length must match tokens length")
+		}
+		for i := range p {
+			if len(p[i]) == 0 {
+				return fmt.Errorf("proofs[%d] cannot be empty", i)
+			}
+		}
+	default:
+		return fmt.Errorf("proofs must be []string or [][]string")
+	}
+
+	return nil
 }

I can also add basic EIP-55 address and uint256 string checks if desired.

ethereum/angle_merkl_distributor_test.go (1)

45-68: Align test input shape for proofs with ABI or validator acceptance.

Test passes a flat []string while ABI is bytes32[][]. Either wrap as [][]string with one inner slice or keep flat and rely on validator normalization.

If we keep bytes32[][] in the ABI, update the test to:

-            "proofs": []string{ /* ... */ },
+            "proofs": [][]string{
+                { /* existing proofs... */ },
+            },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 89e1e46 and f315dc1.

📒 Files selected for processing (4)
  • abi/angle_merkl_distributor.json (1 hunks)
  • ethereum/angle_merkl_distributor.go (1 hunks)
  • ethereum/angle_merkl_distributor_test.go (1 hunks)
  • ethereum/loader.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
ethereum/loader.go (2)
ethereum/angle_merkl_distributor.go (1)
  • NewAngleMerklDistributor (11-13)
ethereum/validator.go (1)
  • GlobalValidatorRegistry (59-59)
ethereum/angle_merkl_distributor_test.go (1)
ethereum/angle_merkl_distributor.go (1)
  • NewAngleMerklDistributor (11-13)
ethereum/angle_merkl_distributor.go (1)
types/protocol.go (1)
  • Function (20-32)
🔇 Additional comments (2)
abi/angle_merkl_distributor.json (1)

25-29: ABI entry looks consistent and minimal.

Name, mutability, and no outputs align with a typical claim function. Good addition.

ethereum/loader.go (1)

106-111: LGTM: Validator registration is correct and ID matches ABI filename.

The protocol ID “angle_merkl_distributor” aligns with the ABI name derived from angle_merkl_distributor.json.

Comment on lines +3 to +5
import (
"testing"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix compile error: use strings.Contains (helper not defined).

The call to contains(...) will not compile.

Apply:

 import (
-	"testing"
+	"strings"
+	"testing"
 )
@@
-				if tt.errorContains != "" && !contains(err.Error(), tt.errorContains) {
+				if tt.errorContains != "" && !strings.Contains(err.Error(), tt.errorContains) {

Also applies to: 83-85

🤖 Prompt for AI Agents
In ethereum/angle_merkl_distributor_test.go around lines 3-5 (and also at usages
around lines 83-85), the helper contains(...) is undefined causing a compile
error; import the standard "strings" package in the import block and replace
calls to contains(...) with strings.Contains(haystack, needle) (or
strings.Contains(err.Error(), "text") as appropriate) so the code compiles.

@RaghavSood RaghavSood marked this pull request as draft September 16, 2025 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant