Repository navigation
feat: add Cleave action provider - #1620
Open
cleave-protocol wants to merge 4 commits into
Open
cleave-protocol wants to merge 4 commits into
cleave-protocol wants to merge 4 commits into
Conversation
Adds cleaveActionProvider with find_token, plan_swap, execute_swap, track_swap, quote_gas and buy_gas for Ethereum, Arbitrum, Base, BNB Chain, Polygon and Optimism. Every plan and gas offer is checked with @cleave-protocol/ai-sdk/core against Cleave's published contracts before the wallet sends or signs anything. execute_swap and buy_gas require confirmed: true; the wallet address and current chain are taken from the wallet provider.
… check claims - execute_swap records each hash as soon as it is sent (userOpHash on smart wallets, with the mined txHash once known). If a send or a receipt wait throws, it returns outcome_unknown with every sent hash and asks to track the swap before any retry. - execute_swap takes an optional minimumReceive from the confirmed plan and refuses when the new plan's minimum is lower. - README and descriptions state what the address checks cover and what they leave to the user. - plan_swap no longer passes the API's next text on; gas top-ups refuse on BNB Chain before the API call; a smart contract wallet must name the recipient for a swap to another chain; error text sent to the model has URLs removed; a duplicate call check is gone.
… wallet - plan_swap keeps each checked plan in memory with the wallet address and chain it was made for. execute_swap takes requestId and confirmed: true and sends exactly that plan, once, before validUntil, from the same wallet on the same chain; it never plans again. minimumReceive is removed. - execute_swap needs sellToken and buyToken given as addresses or as USDC or the native or wrapped native coin. For other sell tokens it reads decimals() through the wallet provider and needs the approve to be for exactly the requested amount. - The wallet's address and chain are checked again before every send and before signing a gas authorization. - buy_gas refuses smart wallet providers by type before reading code. - Every response to the model has URLs removed and the API's next text dropped; the gas authorization signature is redacted from every post-submit response. - A smart wallet's user operation is waited for once more before an unknown outcome, which then points to the wallet's user operation.
- A swap to another chain is executed only when its transfer pays the recipient (or the wallet) directly; a route that swaps on arrival through a destination message stays plan only. - For every ERC-20 sell, the main call must take exactly the requested amount in the token's decimals (known for USDC and the wrapped native coin, read from the chain for a token given by address); a wallet that already holds an allowance works, and measured routes that take more stay plan only. - A kept plan also expires by the local clock; only CDP smart wallets are treated as returning user operation hashes; the approve note in a failure is given only when the last call failed.
🟡 Heimdall Review Status
|
This branch has not been deployed
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.
Description
Adds
cleaveActionProvider, an action provider for Cleave by Cleave Protocol: a DEX aggregator on Ethereum, Arbitrum, Base, BNB Chain, Polygon and Optimism. It splits swaps over pools and paths, runs swaps between these chains, and sells native gas (ETH, BNB, POL) for USDC. Its agent API needs no API key.Actions:
find_token: finds a token by symbol or contract address.plan_swap: plans a swap from the wallet on its current chain and returns the route, the amounts, the third-party costs, the notices and the checked unsigned calls. It sends nothing.execute_swap: sends a plan thatplan_swapreturned, by itsrequestId, withconfirmed: true.track_swap: reports the status of a sent swap or gas top-up.quote_gas: quotes native gas paid in USDC. It signs nothing.buy_gas: signs a checked gas offer's single USDC authorization with the wallet and submits it, withconfirmed: true.How the provider uses the wallet:
@cleave-protocol/ai-sdk/corebefore it is returned. The checks cover the calls' targets and functions on Cleave's published contract list, the approve spender and amount, the wallet, the chain and the recipient. For gas offers they also cover the order hash, the payment address and the pinned contracts.execute_swapsends exactly the plan the user saw: once, before itsvalidUntil, and only from the wallet address and chain it was made for. It never plans again, and it checks the wallet's address and chain again before every call.outcome_unknownwith every sent hash.buy_gasrefuses smart wallet providers and smart contract wallets. The signature is never returned to the model.The new dependency
@cleave-protocol/ai-sdkis used only through its/coreentry: the API client and the address checks. That entry has noaiorzodimport, and the package is published with npm provenance. The lockfile change is limited to that package, andCI=true pnpm installleavespnpm-lock.yamlunchanged.Tests
Unit tests,
typescript/agentkit:cleaveActionProvider.test.tshas 56 tests. They use live API answers as fixtures and cover:pnpm run lint,pnpm run format:checkandpnpm run checkpass.Read-only live check:
Checklist