|
1 |
| -Solvers |
2 |
| -------- |
| 1 | +## Testnet Example Solver |
3 | 2 |
|
4 |
| -To use the Typescript SDK, at the root of this repository, run: |
| 3 | +The example solver is split up into three processes: `vaaAuctionRelayer`, `improveOffer` and |
| 4 | +`executeOrder`. All three rely on the same configuration file, which can created by copying the |
| 5 | +sample file `cfg/testnet/sample.config.json`. |
| 6 | + |
| 7 | +To get started, create a durable nonce account (see these |
| 8 | +[instructions](https://solana.com/developers/guides/advanced/introduction-to-durable-nonces)) with |
| 9 | +your Solana keypair. Copy the public key and move it to the `nonceAccount` field in your config. |
| 10 | + |
| 11 | +**NOTE: We encourage using a durable nonce to avoid an expired blockhash error in case there is |
| 12 | +network congestion. We demonstrate how to use this nonce account in the `vaaAuctionRelayer` |
| 13 | +process.** |
| 14 | + |
| 15 | +Next, you'll need an RPC for each network that you wish to relay `FastMarketOrders` from. Add each |
| 16 | +RPC to the config for the corresponding chain name. |
| 17 | + |
| 18 | +Finally, you will need a funded USDC Associated Token Account (ATA), whose owner is your keypair. |
| 19 | +Ensure that your private key is securely stored in the `.env` file under the `SOLANA_PRIVATE_KEY` |
| 20 | +variable. This key is essential for signing transactions and interacting with the blockchain. |
| 21 | +Format the private key as a base64 string before adding it to the `.env` file. |
| 22 | + |
| 23 | +### Vaa Auction Relayer |
| 24 | + |
| 25 | +The `vaaAuctionRelayer` listens for `FastMarketOrder` VAAs emitted by the Liquidity Layer's network |
| 26 | +of contracts. It determines if the `maxFee` encoded in the `FastMarketOrder` VAA is high enough to |
| 27 | +participate in an auction, if it is, it executes a `place_initial_offer` instruction on the Solana |
| 28 | +`MatchingEngine`. |
| 29 | + |
| 30 | +If any known token accounts are the highest bidder at the end of an auction, this process will settle |
| 31 | +the auction by executing the `settle_auction_complete` instruction and posting the finalized VAA |
| 32 | +associated with the auction's `FastMarketOrder` VAA. For the `vaaAuctionRelayer` to recognize executed |
| 33 | +fast transfers and execute the `settle_auction_complete` instruction, add the owner's public key to the |
| 34 | +`knownAtaOwners` array field in the configuration file. |
| 35 | + |
| 36 | +The `vaaAuctionRelayer` relies on the [Beacon](https://github.com/pyth-network/beacon) as the `VaaSpy` to listen for `FastMarketOrder` VAAs. To set up the |
| 37 | +Beacon, increase the UDP buffer size for the OS: |
5 | 38 |
|
6 | 39 | ```sh
|
7 |
| -npm ci && npm run build && npm run pack |
| 40 | +# for linux |
| 41 | +sudo sysctl -w net.core.rmem_max=2097152 |
| 42 | +sudo sysctl -w net.core.rmem_default=2097152 |
| 43 | +# for macos |
| 44 | +sudo sysctl -w net.inet.udp.recvspace=2097152 |
8 | 45 | ```
|
9 | 46 |
|
10 |
| -Which will produce a `.tgz` file that can be installed using npm or any other package manager like: |
| 47 | +Then, make sure Docker is running and execute the following command to run Beacon in a detached mode: |
11 | 48 |
|
12 | 49 | ```sh
|
13 |
| -npm install /path/to/example-liquidity-layer/wormhole-foundation-example-liquidity-layer-solana-0.0.1.tgz |
| 50 | +make wormhole-spy-up NETWORK=testnet |
14 | 51 | ```
|
15 | 52 |
|
16 |
| -Once installed, it can be used like any other package: |
| 53 | +To stop or restart the beacon |
17 | 54 |
|
18 |
| -```ts |
| 55 | +```sh |
| 56 | +make wormhole-spy-down |
| 57 | +make wormhole-spy-restart NETWORK=testnet |
| 58 | +``` |
19 | 59 |
|
20 |
| -// ... |
21 |
| -import * as tokenRouterSdk from "@wormhole-foundation/example-liquidity-layer-solana/tokenRouter"; |
22 |
| -import { LiquidityLayerDeposit, LiquidityLayerMessage } from "@wormhole-foundation/example-liquidity-layer-solana/common"; |
23 |
| -import { PreparedOrder } from "@wormhole-foundation/example-liquidity-layer-solana/tokenRouter/state"; |
24 |
| -// ... |
| 60 | +`vaaAuctionRelayer` depends on the `@wormhole-foundation/example-liquidity-layer-solana` Typescript SDK. To make sure we can use this SDK, in the root directory of the repository: |
25 | 61 |
|
| 62 | +```sh |
| 63 | +npm ci && npm run build |
26 | 64 | ```
|
27 | 65 |
|
| 66 | +To run the `vaaAuctionRelayer` execute the following command: |
| 67 | + |
| 68 | +```sh |
| 69 | +npm run relayer -- path/to/config/your.config.json |
| 70 | +``` |
| 71 | + |
| 72 | +### Improve Offers |
| 73 | + |
| 74 | +The `improveOffer` process listens for `AuctionUpdated` events on the `MatchingEngine` via |
| 75 | +websocket. Once an auction has been initiated, this process will determine if it is willing to |
| 76 | +improve the offer based on the `pricing` parameters in your config. |
| 77 | + |
| 78 | +To run the `improveOffer` script, execute the following command: |
| 79 | + |
| 80 | +```sh |
| 81 | +npm run improve -- path/to/config/your.config.json |
| 82 | +``` |
| 83 | + |
| 84 | +### Execute Fast Orders |
| 85 | + |
| 86 | +The `executeOrder` process listens for `AuctionUpdated` events on the `MatchingEngine` via |
| 87 | +websocket. At the end of an auction's duration (see `endSlot` of the `AuctionUpdated` event), this |
| 88 | +process will execute the order reflecting this auction within the auction's grace period. |
| 89 | + |
| 90 | +**NOTE: You will need an address lookup table for the execute order instructions because these |
| 91 | +instructions require so many accounts. This LUT address can be added to your config.** |
| 92 | + |
| 93 | +To run the `executeOrder` script, execute the following command: |
| 94 | + |
| 95 | +```sh |
| 96 | +npm run execute -- path/to/config/your.config.json |
| 97 | +``` |
0 commit comments