Improved OPG allowance management methods#209
Merged
adambalogh merged 25 commits intomainfrom Mar 27, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the OPG Permit2 allowance/approval flow to reduce unnecessary on-chain approvals across restarts by introducing a minimum-allowance threshold, optional buffered approval amounts, and balance-aware approval behavior, and then propagates the new API through docs, examples, and tests.
Changes:
- Refactors
ensure_opg_approvalto usemin_allowance/approve_amount, adds_send_approve_tx, balance checks, and logging. - Updates unit/integration tests and various examples/tutorials to call the new API.
- Adjusts documentation to reflect updated behavior and related return types.
Reviewed changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/opengradient/client/opg_token.py |
Implements new allowance threshold + buffered approval logic, balance checks, helper extraction, logging. |
src/opengradient/client/llm.py |
Updates LLM.ensure_opg_approval signature/docs and delegates to updated token helper. |
tests/opg_token_test.py |
Reworks unit tests to cover new threshold/buffer/balance behaviors. |
tests/llm_test.py |
Updates import paths and removes now-obsolete ensure_opg_approval validation test. |
tests/tee_connection_test.py |
Refactors multi-patch() usage to parenthesized context manager form. |
integrationtest/llm/test_llm_chat.py |
Adds ERC-20 balanceOf ABI and waits for OPG balance visibility; updates approval call. |
examples/llm_chat.py |
Updates to min_allowance API. |
examples/llm_chat_streaming.py |
Updates to min_allowance API. |
examples/llm_tool_calling.py |
Updates to min_allowance API and adjusts wording. |
examples/langchain_react_agent.py |
Updates to min_allowance API and adjusts wording. |
stresstest/llm.py |
Updates to min_allowance API. |
tutorials/01-verifiable-ai-agent.md |
Updates tutorial text/code to min_allowance. |
tutorials/02-streaming-multi-provider.md |
Updates tutorial text/code to min_allowance. |
tutorials/03-verified-tool-calling.md |
Updates tutorial text/code to min_allowance. |
README.md |
Updates approval section to describe threshold-based behavior and new param name. |
docs/opengradient/index.md |
Updates example call to min_allowance. |
docs/opengradient/client/index.md |
Updates example call to min_allowance. |
docs/opengradient/client/llm.md |
Updates ensure_opg_approval docs/signature and semantics. |
docs/opengradient/client/model_hub.md |
Aligns documented return/exception types with current code. |
docs/CLAUDE_SDK_USERS.md |
Updates example call to min_allowance. |
src/opengradient/__init__.py |
Updates top-level example call to min_allowance. |
src/opengradient/client/__init__.py |
Updates package example call to min_allowance. |
docs/opengradient/client/opg_token.md |
Removes the opg_token doc page content (affects cross-links). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: kukac <adambalogh@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
configurable buffer amount (defaults to 2x) to reduce on-chain transactions across restarts
Test plan