Skip to content

Commit 9ccd5f3

Browse files
authored
add express relay skeleton (#123)
* add express relay skeleton * positive unit tests added * add tests with dummy protocol * permission id -> permission key * add lookup tables * minor improvements * few improvements + notes on what else to test * address comments * refactor to litesvm + changes * moar tests, refactoring * remove ts tests * for a few tests moar * minor changes * address some comments * minor changes * some moar tests * 1fix * address some moar comments * add readme * revert the use of option for protocol_config * add more docs * initial tilt setup for solana * got bidding to server working * fix some tilt things * peanuts * some refactoring * reorg a few things * address comments * add check for single submit_bid ix * address comments
1 parent 4fb5de2 commit 9ccd5f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+9141
-104
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ contracts/latestEnvironment.json
2424
**/target/
2525
node_modules
2626
.idea
27+
28+
# Ignore stored SVM keypairs
29+
keypairs/*.json

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,33 @@ The checks are also performed in the CI to ensure the code follows consistent fo
2424

2525
Since express relay is a multi-service project, we use [Tilt](https://tilt.dev/) to manage the development environment.
2626
It is a great tool for local development and testing.
27-
Tilt requires `anvil`, `forge`, `poetry`, and rust to be installed on your machine.
27+
Tilt requires `anvil`, `forge`, `poetry`, rust, and the Solana CLI to be installed on your machine.
2828

2929
Here are the installation instructions for each:
3030

3131
- Rust: https://www.rust-lang.org/tools/install
3232
- Foundry (anvil,forge,cast, etc.): https://book.getfoundry.sh/getting-started/installation
3333
- Poetry: https://python-poetry.org/docs/#installation
3434
- Tilt: https://docs.tilt.dev/install.html
35+
- Solana CLI: https://docs.solanalabs.com/cli/install
36+
37+
Note that for the Solana CLI, you may need to alter your terminal's `PATH` variable to include the Solana programs. To make this work with Tilt, you should include the `PATH` update in your `~/.bashrc` or `~/.zshrc` file depending on which shell your machine uses.
3538

3639
Run `tilt up` in the root of the repo to start the development environment.
3740
You can access the ui at `http://localhost:10350/`.
3841

3942
Here is what tilt up does in order:
4043

41-
1. Starts `anvil`: local EVM chain to test the contracts with
42-
2. Deploy express relay contracts
43-
3. Start the auction server
44-
4. Start the liquidation monitor
45-
5. Start the simple searcher
44+
1. [EVM] Starts `anvil`: local EVM chain to test the contracts with
45+
2. [EVM] Deploy express relay contracts
46+
3. [SVM] Builds Solana programs
47+
4. [SVM] Starts `solana-test-validator`: Solana localnet to test the programs with
48+
5. [SVM] Airdrops SOL to searcher, admin, and relayer signer wallet
49+
6. [SVM] Initializes the SVM programs on the localnet
50+
7. Start the auction server
51+
8. [EVM] Start the liquidation monitor
52+
9. [EVM] Start the simple searcher
53+
10. [SVM] Submits an SVM transaction bid to the auction server
4654

4755
There are some useful gadgets in Tilt ui for creating new vaults and checking the vault status.
4856
You can use them to test the system end to end.

Tiltfile

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
11
load("ext://uibutton", "cmd_button", "location", "text_input")
22

33

4-
rpc_port = "9545"
5-
rpc_url = "http://127.0.0.1:%s" % rpc_port
6-
ws_url = "ws://127.0.0.1:%s" % rpc_port
4+
rpc_port_anvil = "9545"
5+
rpc_url_anvil = "http://127.0.0.1:%s" % rpc_port_anvil
6+
ws_url_anvil = "ws://127.0.0.1:%s" % rpc_port_anvil
7+
8+
rpc_port_solana = "8899"
9+
rpc_port_solana_ws = "8900"
10+
rpc_url_solana = "http://127.0.0.1:%s" % rpc_port_solana
11+
ws_url_solana = "ws://127.0.0.1:%s" % rpc_port_solana_ws
712

813
# Default anvil private key
914
private_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
10-
1115
block_time = "2"
16+
17+
# evm resources
1218
local_resource(
13-
"anvil",
19+
"evm-anvil",
1420
serve_cmd="anvil --gas-limit 500000000000000000 --block-time %s -p %s"
15-
% (block_time, rpc_port),
21+
% (block_time, rpc_port_anvil),
1622
readiness_probe=probe(
1723
period_secs=5,
1824
exec=exec_action(
19-
["cast", "cid", "--rpc-url", rpc_url]
25+
["cast", "cid", "--rpc-url", rpc_url_anvil]
2026
), # get chain id as a readiness probe
2127
),
2228
)
2329

2430
forge_base_command = (
2531
"forge script script/Vault.s.sol --via-ir --private-key $PRIVATE_KEY --fork-url %s -vvv"
26-
% rpc_url
32+
% rpc_url_anvil
2733
)
2834

2935
# we set automine to true before deployment and then set the interval to the block time after the deployment
3036
# to speed up the deployment
3137
local_resource(
32-
"deploy-contracts",
38+
"evm-deploy-contracts",
3339
"cast rp --rpc-url http://localhost:9545 evm_setAutomine true; "
3440
+ forge_base_command
3541
+ " --sig 'setUpLocalnet()' --broadcast; "
3642
+ "cast rp --rpc-url http://localhost:9545 evm_setIntervalMining %s" % block_time,
3743
dir="contracts",
3844
env={"PRIVATE_KEY": private_key},
39-
resource_deps=["anvil"],
45+
resource_deps=["evm-anvil"],
4046
)
4147

4248
cmd_button(
@@ -49,7 +55,7 @@ cmd_button(
4955
+ " --sig 'getVault(uint256)' $VAULT --broadcast",
5056
],
5157
location=location.NAV,
52-
resource="deploy-contracts",
58+
resource="evm-deploy-contracts",
5359
env=["PRIVATE_KEY=" + private_key],
5460
icon_name="search",
5561
text="Get vault state",
@@ -68,43 +74,42 @@ cmd_button(
6874
+ " --sig 'createLiquidatableVault()' --broadcast",
6975
],
7076
location=location.NAV,
71-
resource="deploy-contracts",
77+
resource="evm-deploy-contracts",
7278
env=["PRIVATE_KEY=" + private_key],
7379
icon_name="add",
7480
)
7581

7682
local_resource(
77-
"create-configs", "python3 integration.py %s %s" % (rpc_url, ws_url), resource_deps=["deploy-contracts"]
83+
"evm-create-configs", "python3 evm_integration.py %s %s" % (rpc_url_anvil, ws_url_anvil), resource_deps=["evm-deploy-contracts"]
7884
)
7985

8086
local_resource(
8187
"auction-server",
8288
serve_cmd="source ../tilt-resources.env; source ./.env; cargo run -- run --database-url $DATABASE_URL --subwallet-private-key $RELAYER_PRIVATE_KEY --secret-key $SECRET_KEY",
8389
serve_dir="auction-server",
84-
resource_deps=["create-configs"],
90+
resource_deps=["evm-create-configs"],
8591
readiness_probe=probe(period_secs=5, http_get=http_get_action(port=9000)),
8692
)
8793

88-
8994
monitor_command = (
9095
"source tilt-resources.env; "
9196
+ "poetry -C per_sdk run "
9297
+ "python3 -m per_sdk.protocols.token_vault_monitor "
9398
+ "--chain-id development "
94-
+ "--rpc-url %s " % (rpc_url)
99+
+ "--rpc-url %s " % (rpc_url_anvil)
95100
+ "--vault-contract $TOKEN_VAULT "
96101
+ "--weth-contract $WETH "
97102
+ "--liquidation-server-url http://localhost:9000 "
98103
+ "--mock-pyth"
99104
)
100105

101106
local_resource(
102-
"monitor",
107+
"evm-monitor",
103108
serve_cmd=monitor_command,
104-
resource_deps=["deploy-contracts", "auction-server", "create-configs"],
109+
resource_deps=["evm-deploy-contracts", "auction-server", "evm-create-configs"],
105110
)
106111

107-
searcher_command = (
112+
evm_searcher_command = (
108113
"source tilt-resources.env;"
109114
+ "poetry -C per_sdk run "
110115
+ "python3 -m per_sdk.searcher.simple_searcher "
@@ -119,7 +124,47 @@ searcher_command = (
119124
+ "--permit2-address $PERMIT2 "
120125
)
121126
local_resource(
122-
"searcher",
123-
serve_cmd=searcher_command,
124-
resource_deps=["deploy-contracts", "auction-server", "create-configs"],
127+
"evm-searcher",
128+
serve_cmd=evm_searcher_command,
129+
resource_deps=["evm-deploy-contracts", "auction-server", "evm-create-configs"],
130+
)
131+
132+
133+
# svm resources
134+
local_resource(
135+
"svm-build-programs",
136+
"cargo build-sbf",
137+
dir="express_relay",
138+
)
139+
140+
local_resource(
141+
"svm-localnet",
142+
serve_cmd="solana-test-validator $(./test-validator-params.sh)",
143+
serve_dir="express_relay",
144+
# check readiness by sending a health GET query to the RPC url
145+
readiness_probe=probe(
146+
period_secs=10,
147+
http_get = http_get_action(port=int(rpc_port_solana), host="localhost", scheme="http", path="/health")
148+
),
149+
resource_deps=["svm-build-programs"],
150+
)
151+
152+
local_resource(
153+
"svm-setup-accounts",
154+
"poetry -C per_sdk run python3 -m per_sdk.svm.setup_accounts --rpc-url %s" % rpc_url_solana,
155+
resource_deps=["svm-localnet"]
156+
)
157+
158+
# need to run initialize instructions for the programs one time, script skips if already initialized
159+
local_resource(
160+
"svm-initialize-programs",
161+
"poetry -C per_sdk run python3 -m per_sdk.svm.initialize_programs -v --file-private-key-payer keypairs/searcher.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --dummy-program HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3 --rpc-url %s" % rpc_url_solana,
162+
resource_deps=["svm-setup-accounts"]
163+
)
164+
165+
# craft dummy tx, submits as a bid to auction server or submits relayer-signed tx directly to solana cluster
166+
local_resource(
167+
"svm-submit-bid",
168+
"poetry -C per_sdk run python3 -m per_sdk.svm.dummy_tx -v --file-private-key-searcher keypairs/searcher.json --file-private-key-relayer-signer keypairs/relayer_signer.json --bid 100 --auction-server-url http://localhost:9000 --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --dummy-program HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3",
169+
resource_deps=["svm-initialize-programs", "auction-server"],
125170
)
File renamed without changes.

express_relay/.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.anchor
2+
.DS_Store
3+
target
4+
**/*.rs.bk
5+
node_modules
6+
test-ledger
7+
.yarn

express_relay/.prettierignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.anchor
2+
.DS_Store
3+
target
4+
node_modules
5+
dist
6+
build
7+
test-ledger

express_relay/Anchor.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[toolchain]
2+
3+
[features]
4+
resolution = true
5+
skip-lint = false
6+
7+
[programs.localnet]
8+
dummy = "HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3"
9+
express_relay = "GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM"
10+
11+
[registry]
12+
url = "https://api.apr.dev"
13+
14+
[provider]
15+
cluster = "Localnet"
16+
wallet = "~/.config/solana/id.json"

0 commit comments

Comments
 (0)