AI agents with wallets need strict spending limits to prevent catastrophic token approvals that could drain your entire balance. The APPROVE_AMOUNT_LIMIT policy in WAIaaS caps how much your AI can approve for spending by DeFi protocols, blocking unlimited approvals that create massive security holes.
Why Token Approval Limits Matter
When your AI agent interacts with DeFi protocols, it needs to approve tokens for spending. Most protocols request unlimited approval (2^256 - 1) to avoid repeated approval transactions. This creates a critical vulnerability: if the protocol gets hacked or your agent makes an error, attackers can drain your entire token balance.
The stakes are high. Unlimited token approvals have enabled some of the largest DeFi hacks in history. Your AI agent might approve 1,000 USDC for a swap, but the protocol now has permission to take everything. Traditional wallet UIs warn users about unlimited approvals, but AI agents execute transactions programmatically without human oversight.
How APPROVE_AMOUNT_LIMIT Works
WAIaaS provides granular control over token approvals through the APPROVE_AMOUNT_LIMIT policy. This policy sets maximum approval amounts and can completely block unlimited approvals, forcing protocols to request only what they need.
Here's how to create an approval limit policy:
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
"type": "APPROVE_AMOUNT_LIMIT",
"rules": {
"maxAmount": "1000000000000000000000",
"blockUnlimited": true,
"tokenLimits": {
"EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v": "10000000000"
}
}
}'
The policy enforces these rules:
-
maxAmount: Global maximum approval amount (in token's smallest unit) -
blockUnlimited: Reject any approval for2^256 - 1or similar unlimited values -
tokenLimits: Per-token approval limits that override the global maximum
When your AI agent attempts a token approval, WAIaaS checks the requested amount against these limits. Approvals exceeding the limit are either blocked or escalated to higher security tiers based on your SPENDING_LIMIT policy configuration.
Multi-Layer Approval Protection
APPROVE_AMOUNT_LIMIT works with other WAIaaS policies to create defense-in-depth:
Layer 1: Token Whitelist
The ALLOWED_TOKENS policy implements default-deny for token transfers. Your agent can only approve tokens you've explicitly whitelisted:
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
"type": "ALLOWED_TOKENS",
"rules": {
"tokens": [
{"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "symbol": "USDC", "chain": "solana"},
{"address": "native:solana", "symbol": "SOL", "chain": "solana"}
]
}
}'
Layer 2: Spender Whitelist
The APPROVED_SPENDERS policy restricts which contracts can receive approvals:
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
"type": "APPROVED_SPENDERS",
"rules": {
"spenders": [
{"address": "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4", "name": "Jupiter", "maxAmount": "1000000000"}
]
}
}'
Layer 3: Security Tiers
Use APPROVE_TIER_OVERRIDE to force all approvals through human approval regardless of amount:
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: my-secret-password' \
-d '{
"walletId": "019c47d6-51ef-7f43-a76b-d50e875d95f4",
"type": "APPROVE_TIER_OVERRIDE",
"rules": {
"tier": "APPROVAL"
}
}'
Real-World Approval Scenarios
Scenario 1: DEX Trading
Your AI trading bot needs to swap tokens on Jupiter. Without limits, it would approve unlimited USDC spending. With APPROVE_AMOUNT_LIMIT, it approves exactly what's needed for the trade plus a small buffer.
Scenario 2: Lending Protocol
Your agent supplies tokens to Aave for yield. The protocol requests unlimited approval to withdraw your supply and interest. The policy caps this to your intended supply amount, preventing over-withdrawal if Aave gets compromised.
Scenario 3: Yield Farming
Your agent deposits LP tokens into a yield farm. Unlimited approval would let the farm drain all your LP tokens. The limit ensures only your intended farming amount is at risk.
Monitoring and Alerts
WAIaaS provides real-time monitoring of approval transactions through its notification system. When your agent makes approvals, you get instant alerts showing:
- Which token was approved
- The approved amount vs. your policy limit
- Which protocol received the approval
- Whether the approval was capped or blocked
Set up push notifications to your phone when approval policies trigger:
waiaas notification setup --push --approval-alerts
Integration with Your Trading Strategy
If you're building AI trading bots, approval limits need to balance security with functionality. Here's a practical approach:
- Start Conservative: Set low approval limits initially
- Monitor Usage: Track how much your agent actually needs
- Adjust Gradually: Increase limits based on real usage patterns
- Segment by Strategy: Different agents get different approval policies
For high-frequency trading, you might allow larger approvals but with strict spender whitelists. For experimental strategies, enforce human approval for all token approvals.
Quick Start: Secure Your Agent's Approvals
- Install WAIaaS and create a wallet:
npm install -g @waiaas/cli
waiaas init
waiaas start
waiaas wallet create --name trading-bot --chain solana
- Set up approval limits:
# Block unlimited approvals, cap at 1000 tokens
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: your-password' \
-d '{"walletId": "<wallet-id>", "type": "APPROVE_AMOUNT_LIMIT", "rules": {"maxAmount": "1000000000", "blockUnlimited": true}}'
- Configure token and spender whitelists:
# Only allow USDC approvals to Jupiter
curl -X POST http://localhost:3100/v1/policies \
-H 'Content-Type: application/json' \
-H 'X-Master-Password: your-password' \
-d '{"walletId": "<wallet-id>", "type": "ALLOWED_TOKENS", "rules": {"tokens": [{"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "symbol": "USDC", "chain": "solana"}]}}'
- Test with a small approval:
# Your agent can now safely interact with DeFi protocols
curl -X POST http://localhost:3100/v1/actions/jupiter-swap/swap \
-H 'Authorization: Bearer wai_sess_<token>' \
-d '{"inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", "outputMint": "So11111111111111111111111111111111111111112", "amount": "1000000"}'
- Monitor approval activity:
# View recent transactions including approvals
curl http://localhost:3100/v1/transactions \
-H 'Authorization: Bearer wai_sess_<token>'
Token approval limits are just one piece of WAIaaS's comprehensive security model. The platform provides 21 policy types across 4 security tiers, creating multiple checkpoints between your AI agent and potential financial losses.
What's Next
Start experimenting with approval limits in testnet mode, then gradually deploy to mainnet with conservative limits. As your agent's behavior becomes predictable, you can fine-tune the policies for optimal security-performance balance.
Ready to secure your AI agent's token approvals? Get started with the open-source code at https://github.com/minhoyoo-iotrust/WAIaaS or explore the full documentation at https://waiaas.ai.
Top comments (0)