feat(test-cli): Settlement with on chain liquidity - #98
Conversation
…lement-with-on-chain-liquidity
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Warning Review the following alerts detected in dependencies. According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.
|
Drives the new `AddSolver` instruction (#119) from the dev CLI: ``` cow solver add <address> [--manager <keypair-path>] ``` - New `test-cli/src/cmd/solver.rs`: a `solver` command group whose `add` subcommand builds `cow_settlement_client::instructions::AddSolver` against the derived state PDA, sends it, and prints a summary (signature, solver, manager, statePda). - `AddSolver` needs both the manager's and the payer's signature, so `--manager` takes a *keypair path*, not an address. It defaults to by the same as `--keypair`, which is the payer. ## Verification I deployed a testing program for this base branch for the change at `7hwEhpgqZy1qRNMdFvVh4YjerBrZnMR7qGZUbLJTFSxg` To test adding a solver: ``` ➜ solana-programs git:(kaze/sc-299-add-functions-to-addremove-solvers) ./target/debug/cow solver add B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5 --program-id 7hwEhpgqZy1qRNMdFvVh4YjerBrZnMR7qGZUbLJTFSxg signature = 2dsTvWAGvxL2w9MVWTHiMn76oKM73XH29GWh5eaKAGfh739A3CrB4ZRhh1hF72HppJdJyRHSmCTUY1gKi6DzwcXE solver = B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5 manager = B6acm3swJK9pJ7fe4i4GQgP7x5A3RndvsdV2bKhcA1i5 statePda = HkqW1CPzMddJzZm5eFfFBK3wH6uUasLLQ5TczrM2o5VQ ``` The specified solver account can now be used for a settlement as in #98 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Federico Giacon <58218759+fedgiac@users.noreply.github.com>
Description
Adds ability to use Orca Whirlpools to fulfill swap outputs in
cow settlecommandsMotivation
Up til now it has only been possible to trade CoW only orders (settlements whose order's swap outputs were less than all swap inputs)
Now the funds can actually be traded on an on-chain DEX. CoW + DEX transactions are supported and they look great.
Example transactions:
Fym2NNEw7S4sjukTr5JXCmA29Rhywk54k67L7UGe952usells 0.3 WSOL for 3 USDCG3gex9BqZHWRb95J4Mhzf2cdEuEpRnbBJJtM5vKj18v5sells 1 USDC for 0.1 WSOLChanges Overview
A new folder
src/liquiditywas added which containsorca.rs.In order to send needed swap funds to the orca, the
settleinternals were updated to generatePullto route funds to the necessary orca swap signer.Additional swap backends could be added in the future by adding new modules to the
liquidityfolder and updating the settle command'srunfunction to try all liquidity sources, picking the one with the most favorable overall outcome.Issues
orca-whirlpoolspackage was added to thetest-cliin order to simplify the integration of Orca. However, this library drags in the use oftokio(the async library which we haven't used anywhere yet) andsolana-client, . Additionally,solana-client = 4is not supported, so we have to usesolana-client = 3even though all the other solana library packages we currently consume have been migrated to v4.Orca necessarily uses tokio so the tokio runtime is kept self-contained in
orca.rsand the rest of the codebase remains synchronous as before.It also needs a couple hacks to work with our less than general requirements:
Surplus
As was the case in the previous test-cli PR to add settlements, sending of surplus to the user is not currently supported. Only the minimum amount of funds required to satisfy the limit price is sent. This continues to be reflected in the behavior of the orca code, swapping only the minimum amount necessary to fulfill the order.
How to test
It is now possible to execute a swap with the test cli with only one transaction. Orca does support the existing test tokens WSOL and USDC on devnet that have been used up til now (see )
So armed with:
As there have been a lot of breaking changes, I have deployed a temporary settlement program at a new address for testing of this program for the current branch at
59QTx9Di2dGNLgvwgd2eRisGmymVveqNGHmyuWLwcawb, so please ensure to use--program-id 59QTx9Di2dGNLgvwgd2eRisGmymVveqNGHmyuWLwcawbExecute a swap:
You can also CoW with another order (optionally from a separate trader account)
Be sure to set the output limit price! Otherwise, no surplus will be sent and your swap input will simply be consumed.