forked from wormhole-foundation/example-swap-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
solana: auction participant example processes (#87)
Co-authored-by: gator-boi <[email protected]> Co-authored-by: A5 Pickle <[email protected]>
- Loading branch information
1 parent
05e36a8
commit ed261b1
Showing
38 changed files
with
2,622 additions
and
287 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,114 @@ | ||
# Example Token Router on Solana | ||
# Example Liquidity Layer on Solana | ||
|
||
## Dependencies | ||
## Assets | ||
|
||
- Matching Engine | ||
- Token Router | ||
- Upgrade Manager | ||
|
||
> **Warning** | ||
> Only Solana versions >= 1.14.14 and < 1.15 are supported. | ||
## Dependencies | ||
|
||
First, you will need `cargo` and `anchor` CLI tools. If you need these tools, | ||
please visit the [Anchor book] for more details. | ||
- cargo -- Get started using [rustup](https://rustup.rs/) | ||
- npm -- Get started using [nvm](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) | ||
- solana -- Install the latest version [here](https://docs.solanalabs.com/cli/install#use-solanas-install-tool) | ||
- anchor -- Install [avm](https://book.anchor-lang.com/getting_started/installation.html#anchor) | ||
|
||
## Build | ||
|
||
Once you have the above CLI tools, you can build the programs by simply running: | ||
Currently there are two features that represent target Solana | ||
networks: | ||
|
||
- `NETWORK=testnet make` | ||
- localnet (Solana Test Validator) | ||
- testnet (Solana devnet) | ||
|
||
This will also install this subdirectory's dependencies, such as | ||
`node_modules` and the Wormhole programs from the `solana` directory of the | ||
[Wormhole repo]. This will also create a keypair for the program in the | ||
`target/deploy/`. This keypair can be used for devnet, testnet and mainnet. Do not delete this | ||
key after deploying to the network of your choice. | ||
Make sure the program pubkeys for whichever network you plan on deploying for is set as the correct | ||
const values found in [this lib.rs file](modules/common/src/lib.rs). | ||
|
||
## Tests | ||
So for testnet, you would specify the NETWORK env and execute `make build`. For example: | ||
|
||
To run both unit and integration tests, run `make test`. If you want to isolate | ||
your testing, use either of these commands: | ||
```sh | ||
NETWORK=testnet make build | ||
``` | ||
|
||
- `make unit-test` - Runs `cargo clippy` and `cargo test` | ||
- `make integration-test` - Spawns a solana local validator and uses `ts-mocha` | ||
with `@solana/web3.js` to interact with the example programs. | ||
This will create an artifacts directory (in the example above, _artifacts_testnet_). | ||
|
||
## Deployment | ||
## Tests | ||
|
||
First, generate a program public key by running the following command: | ||
To run both unit and integration tests, run `make test`. | ||
|
||
- `solana-keygen pubkey target/deploy/token_bridge_relayer-keypair.json` | ||
## Deployment | ||
|
||
Add your program's public key to the following file: | ||
First [build](#build) for a specific network. | ||
|
||
- `programs/src/lib.rs` | ||
Following the same example in the build section, assuming your keypair reflects the Upgrade | ||
Manager's pubkey `ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt`, you would deploy a new program by | ||
running the following command using the Solana CLI: | ||
|
||
Then, build based on the target network. The deployment options are `devnet`, `testnet` and `mainnet`. We will use `testnet` as an example for this README. | ||
```sh | ||
solana program deploy -u d --program-id ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt artifacts-testnet/upgrade_manager.so | ||
``` | ||
|
||
- `NETWORK=testnet make build` | ||
## Managing Upgrades | ||
|
||
Next, we will need to create some keypairs for the deployment. The keypair that is used to deploy the program will become the `owner` of the program. Optionally, you can create a new keypair for the `assistant` and the `fee_recipient`, however, the same keypair can be used for all three. Create the keypair(s) in a location of your choice by running: | ||
TODO | ||
|
||
- `solana-keygen new -o path/to/keypair.json` | ||
## Testnet Example Solver | ||
|
||
Then set the `FEE_RECIPIENT`, `ASSISTANT` and `TOKEN_ROUTER_PID` in the `env/tesnet.env` file. This env file will be used for your deployment, as well as setting up the program. | ||
The example solver is split up into three processes: `vaaAuctionRelayer`, `improveOffer` and | ||
`executeOrder`. All three rely on the same configuration file, which can created by copying the | ||
sample file `cfg/testnet/sample.config.json`. | ||
|
||
Finally, deploy the program (from the `solana`) directory with the following command: | ||
To get started, create a durable nonce account (see these | ||
[instructions](https://solana.com/developers/guides/advanced/introduction-to-durable-nonces)) with | ||
your Solana keypair. Copy the public key and move it to the `nonceAccount` field in your config. | ||
|
||
``` | ||
solana program deploy target/deploy/token_bridge_relayer.so \ | ||
--program-id target/deploy/token_bridge_relayer-keypair.json \ | ||
--commitment confirmed \ | ||
-u your_testnet_rpc \ | ||
-k your_deployment_keypair.json` | ||
``` | ||
**NOTE: We encourage using a durable nonce to avoid an expired blockhash error in case there is | ||
network congestion. We demonstrate how to use this nonce account in the `vaaAuctionRelayer` | ||
process.** | ||
|
||
## Program Setup | ||
Next, you'll need an RPC for each network that you wish to relay `FastMarketOrders` from. Add each | ||
RPC to the config for the corresponding chain name. | ||
|
||
### Step 1: Env File | ||
Finally, you will need a funded USDC Associated Token Account (ATA), whose owner is your keypair. | ||
|
||
You should still have your environment file from the [deployment](#deployment) section of this README. However (if you deleted it) create a new one and set the `FEE_RECIPIENT`, `ASSISTANT` and `TOKEN_ROUTER_PID` environment variables. | ||
### Vaa Auction Relayer | ||
|
||
### Step 2: Setup Configuration File | ||
The `vaaAuctionRelayer` listens for `FastMarketOrder` VAAs emitted by the Liquidity Layer's network | ||
of contracts. It determines if the `maxFee` encoded in the `FastMarketOrder` VAA is high enough to | ||
participate in an auction, if it is, it executes a `place_initial_offer` instruction on the Solana | ||
`MatchingEngine`. If any known token accounts are the highest bidder at the end of an auction, this | ||
process will settle the auction by executing the `settle_auction_complete` instruction and posting | ||
the finalized VAA associated with the auction's `FastMarketOrder` VAA. | ||
|
||
Depending on your target network, there should be an example config file in the `cfg` directory. Open your file of choice and configure it to your liking. DO NOT change the name of this file. | ||
To run the `vaaAuctionRelayer` execute the following command: | ||
|
||
### Step 3: Initialize the program | ||
```sh | ||
npx ts-node ts/auction-participant/vaaAuctionRelayer/app.ts path/to/config/your.config.json | ||
``` | ||
|
||
Run the following command to initialize the program. Make sure to supply the keypair that was used to deploy the program: | ||
### Improve Offers | ||
|
||
- `source env/testnet.env && yarn initialize -k your_deployment_keypair.json` | ||
The `improveOffer` process listens for `AuctionUpdated` events on the `MatchingEngine` via | ||
websocket. Once an auction has been initiated, this process will determine if it is willing to | ||
improve the offer based on the `pricing` parameters in your config. | ||
|
||
### Step 4: Register Foreign Contracts | ||
To run the `improveOffer` script, execute the following command: | ||
|
||
- `source env/testnet.env && yarn register-contracts -k your_deployment_keypair.json -n testnet` | ||
```sh | ||
npx ts-node ts/auction-participant/improveOffer/app.ts path/to/config/your.config.json | ||
``` | ||
|
||
### Step 5: Register Tokens (Sets Swap Rate and Max Swap Amount) | ||
### Execute Fast Orders | ||
|
||
- `source env/testnet.env && yarn register-tokens -k your_deployment_keypair.json -n testnet` | ||
The `executeOrder` process listens for `AuctionUpdated` events on the `MatchingEngine` via | ||
websocket. At the end of an auction's duration (see `endSlot` of the `AuctionUpdated` event), this | ||
process will execute the order reflecting this auction within the auction's grace period. | ||
|
||
### Step 6: Set Relayer Fees | ||
**NOTE: You will need an address lookup table for the execute order instructions because these | ||
instructions require so many accounts. This LUT address can be added to your config.** | ||
|
||
- `source env/testnet.env && yarn set-relayer-fees -k your_deployment_keypair.json -n testnet` | ||
To run the `executeOrder` script, execute the following command: | ||
|
||
[anchor book]: https://book.anchor-lang.com/getting_started/installation.html | ||
[wormhole repo]: https://github.com/wormhole-foundation/wormhole/tree/dev.v2/solana | ||
```sh | ||
npx ts-node ts/auction-participant/executeOrder/app.ts path/to/config/your.config.json | ||
``` |
Oops, something went wrong.