Add OPG token Permit2 approval utilities for x402 payments#8
Merged
adambalogh merged 2 commits intomainfrom May 5, 2026
Merged
Add OPG token Permit2 approval utilities for x402 payments#8adambalogh merged 2 commits intomainfrom
adambalogh merged 2 commits intomainfrom
Conversation
Port ensureOpgApproval from the Python SDK (src/opengradient/client/opg_token.py). Checks the Permit2 allowance for the OPG token on Base mainnet and only sends an approve tx when the current allowance falls below minAllowance, approving approveAmount (default 2x minAllowance) so subsequent restarts are free. Uses viem and the PERMIT2_ADDRESS constant re-exported from @x402/evm.
Mirrors the OPG Token Approval section in the Python SDK README so users discover the approval step before their first LLM call.
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
This PR adds utilities for managing OPG token Permit2 approvals on Base mainnet, enabling seamless integration with x402 payment infrastructure. The new module provides a high-level API for ensuring sufficient allowances with minimal transaction overhead.
Key Changes
New
opgToken.tsmodule with Permit2 approval management:ensureOpgApproval()- Main function that checks and maintains minimum Permit2 allowance thresholdsExported public API:
ensureOpgApproval()- Idempotent approval function for backend servicesBASE_OPG_ADDRESS- OPG token contract address on BaseBASE_MAINNET_RPC- Base mainnet RPC endpoint (configurable via env var)Permit2ApprovalResult- Type for approval operation resultsUpdated
index.tsto export new OPG approval utilitiesNotable Implementation Details
BASE_MAINNET_RPCenvironment variable for custom RPC endpoints