Test a solver
Settling Real Orders
Once I understood how a solver works, I wanted to solve a real order. To test this out without setting up the orderbook I used a little trick. I created an order in a production orderbook, but I set up an impossible limit order. For that I used the staging orderbook in the gnosis-chain. I deployed a yvUSDC vault, and I created an LP USDC/yvUSDC in Honeyswap. You have different options to create a limit order:- https://docs.cow.fi/tutorials/cowswap-trades-with-a-gnosis-safe-wallet
- https://bafybeias5x3tgdshkhj5umriqze2wioy5mjw4fdo2zzp2sl4pacq7rnwtm.ipfs.infura-ipfs.io/?orderbook=https://barn.api.cow.fi/xdai
- You call the API by hand
https://barn.gnosis-protocol.io/gc/orders/0xcc37de3ba70474948f838e8b4af9c6b66577c08202323a4a3060a645b2918dae2813a7e97fd0bc1b80cb63afe136510d940ddc236208633c I am trading 10 USDC for 91.412 yvUSDC, which of course will never settle by regular solvers, since 1
USDC == 1 yvUSDC (price per share is 1).
Now that we have the real order, the orderbook will return it in the solvable_orders endpoint.
To consume it, we will need to use the driver.
The cow-dex-solver repo now has a nice README with an explanation of how to run the driver:
https://github.com/gnosis/cow-dex-solver#how-to-run-simulations-together-with-the-cowswap-official-driver
The way I had it running was:
- orderbook-url: points to the gnosis staging version
- node-url connects to gnosis-chain (VERY IMPORTANT, liquidity sources are based on this)
- cow-dex-ag-solver-url our running solver instance
- solver-account An address that has permissions to run txs in the settlement contract
- solvers just use our CowDexAg instance
- transaction-strategy DryRun will give us a tenderly link after running
Full E2E testing
Is your solver working and you want to try a more real order? You will need to run your own orderbook. For that, you will need docker. Follow the steps at: https://github.com/gnosis/gp-v2-services/#db-migrationinitialization I run my orderbook with:- Orderbook at http://localhost:8080 is returning your order in the
solvable_ordersendpoint - Driver will fetch orders from your orderbook and query your
- Solver at http://localhost:8000
How to test a solver locally
In this short tutorial, we describe the steps needed in order to set up the Driver locally and allow a custom Solver to interact with it.Installing Rust
The first step is to install Rust by using the Rustup tool. We strongly encourage the reader to follow the steps described here: https://www.rust-lang.org/learn/get-started Once we are done with the installation, we turn to the Driver setup.Driver setup
Reading the state of the blockchain requires issuing RPC calls to an Ethereum node. The simplest way to do so is by using a third party service like Infura to get access to an Ethereum node; thus, in this tutorial we use Infura. After registering for a free Infura account, Infura offers “endpoints” for mainnet and different testnets. We will refer to those as node-urls. Since CoW Protocol only runs on mainnet, Sepolia, and Gnosis Chain, we need to select one of those. In order to start the Driver, we can execute the following command in a terminal:INFURA_KEY entry should be replaced with the key associated with our Infura account.
We clarify that the cow-dex-ag-solver-url is just a placeholder flag that indicates where the http solver (i.e., a custom solver) receives requests (which, in our case, will be a localhost server whose IP address is the standard 127.0.0.1), and CowDexAg is just a dummy name for the solver we will use. These should not be edited!
Sample Test Instances
In this section, we provide sample instances following the json format described in the previous sections, along with the optimal solution, again in the appropriate json format. These can be used for testing purposes while developing a solver. We clarify that the solutions provided are optimal up to a very small factor (caused by rounding very small amounts).- Single order Instances
- Multiple-orders on single token pairs Instances
- Multiple orders on multiple token pairs Instances
- Example Instance with solution containing calldata
- [prod] https://solver-instances.s3.eu-central-1.amazonaws.com/prod-mainnet/$AUCTION_ID.json
- [barn] https://solver-instances.s3.eu-central-1.amazonaws.com/staging-mainnet/$AUCTION_ID.json