-
Notifications
You must be signed in to change notification settings - Fork 6
/
Tiltfile
224 lines (199 loc) · 10.4 KB
/
Tiltfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
load("ext://uibutton", "cmd_button", "location", "text_input")
rpc_port_anvil = "9545"
rpc_url_anvil = "http://127.0.0.1:%s" % rpc_port_anvil
ws_url_anvil = "ws://127.0.0.1:%s" % rpc_port_anvil
rpc_port_solana = "8899"
rpc_port_solana_ws = "8900"
rpc_url_solana = "http://127.0.0.1:%s" % rpc_port_solana
ws_url_solana = "ws://127.0.0.1:%s" % rpc_port_solana_ws
# Default anvil private key
private_key = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
block_time = "2"
# evm resources
local_resource(
"evm-anvil",
serve_cmd="anvil --gas-limit 500000000000000000 --block-time %s -p %s"
% (block_time, rpc_port_anvil),
readiness_probe=probe(
period_secs=5,
exec=exec_action(
["cast", "cid", "--rpc-url", rpc_url_anvil]
), # get chain id as a readiness probe
),
)
forge_base_command = (
"forge script script/Vault.s.sol --via-ir --private-key $PRIVATE_KEY --fork-url %s -vvv"
% rpc_url_anvil
)
# we set automine to true before deployment and then set the interval to the block time after the deployment
# to speed up the deployment
local_resource(
"evm-deploy-contracts",
"cast rp --rpc-url http://localhost:9545 evm_setAutomine true; "
+ forge_base_command
+ " --sig 'setUpLocalnet()' --broadcast; "
+ "cast rp --rpc-url http://localhost:9545 evm_setIntervalMining %s" % block_time,
dir="contracts/evm",
env={"PRIVATE_KEY": private_key},
resource_deps=["evm-anvil"],
)
cmd_button(
"vault state",
argv=[
"sh",
"-c",
"cd contracts/evm; "
+ forge_base_command
+ " --sig 'getVault(uint256)' $VAULT --broadcast",
],
location=location.NAV,
resource="evm-deploy-contracts",
env=["PRIVATE_KEY=" + private_key],
icon_name="search",
text="Get vault state",
inputs=[
text_input("VAULT", placeholder="Enter vault number"),
],
)
cmd_button(
"create new vault",
argv=[
"sh",
"-c",
"cd contracts/evm; "
+ forge_base_command
+ " --sig 'createLiquidatableVault()' --broadcast",
],
location=location.NAV,
resource="evm-deploy-contracts",
env=["PRIVATE_KEY=" + private_key],
icon_name="add",
text="Add Evm Opportunity",
)
local_resource(
"create-server-configs", "poetry -C tilt-scripts run python3 integration.py %s %s" % (rpc_url_anvil, ws_url_anvil), resource_deps=["evm-deploy-contracts","svm-setup-accounts"]
)
local_resource(
"svm-build-programs",
"cargo build-sbf && anchor build",
dir="contracts/svm",
)
# creates mints for sell and buy tokens, creates and funds ATAs for searcher and admin
local_resource(
"svm-create-mints",
"""solana-keygen new -o keypairs/mint_buy.json -f --no-bip39-passphrase \
&& solana-keygen new -o keypairs/mint_sell.json -f --no-bip39-passphrase \
&& spl-token create-token -u localhost --fee-payer keypairs/admin.json --mint-authority keypairs/admin.json keypairs/mint_sell.json \
&& spl-token create-token -u localhost --fee-payer keypairs/admin.json --mint-authority keypairs/admin.json keypairs/mint_buy.json \
&& spl-token create-account -u localhost keypairs/mint_buy.json --fee-payer keypairs/admin.json --owner keypairs/searcher_js.json \
&& spl-token create-account -u localhost keypairs/mint_sell.json --fee-payer keypairs/admin.json --owner keypairs/searcher_js.json \
&& spl-token create-account -u localhost keypairs/mint_buy.json --fee-payer keypairs/admin.json --owner keypairs/searcher_py.json \
&& spl-token create-account -u localhost keypairs/mint_sell.json --fee-payer keypairs/admin.json --owner keypairs/searcher_py.json \
&& spl-token create-account -u localhost keypairs/mint_buy.json --fee-payer keypairs/admin.json --owner keypairs/admin.json \
&& spl-token create-account -u localhost keypairs/mint_sell.json --fee-payer keypairs/admin.json --owner keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_buy.json 1000000000 --recipient-owner keypairs/searcher_js.json --mint-authority keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_sell.json 1000000000 --recipient-owner keypairs/searcher_js.json --mint-authority keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_buy.json 1000000000 --recipient-owner keypairs/searcher_py.json --mint-authority keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_sell.json 1000000000 --recipient-owner keypairs/searcher_py.json --mint-authority keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_buy.json 1000000000 --recipient-owner keypairs/admin.json --mint-authority keypairs/admin.json \
&& spl-token mint -u localhost keypairs/mint_sell.json 1000000000 --recipient-owner keypairs/admin.json --mint-authority keypairs/admin.json""",
resource_deps=["svm-setup-accounts"]
)
# setup limo global config and vaults for buy and sell tokens
RUN_CLI= "ADMIN=../../keypairs/admin.json RPC_ENV=localnet npm exec limo-cli --"
SET_GLOBAL_CONFIG = "LIMO_GLOBAL_CONFIG=$(solana-keygen pubkey ../../keypairs/limo_global_config.json)"
MINT_SELL= "$(solana-keygen pubkey ../../keypairs/mint_sell.json)"
MINT_BUY= "$(solana-keygen pubkey ../../keypairs/mint_buy.json)"
local_resource(
"svm-limo-setup",
"""solana-keygen new -o ../../keypairs/limo_global_config.json -f --no-bip39-passphrase \
&& {RUN_CLI} init-global-config --global-config-file-path ../../keypairs/limo_global_config.json \
&& {SET_GLOBAL_CONFIG} {RUN_CLI} init-vault --mint {MINT_SELL} --mode execute \
&& {SET_GLOBAL_CONFIG} {RUN_CLI} init-vault --mint {MINT_BUY} --mode execute"""
.format(RUN_CLI=RUN_CLI, SET_GLOBAL_CONFIG=SET_GLOBAL_CONFIG, MINT_SELL=MINT_SELL, MINT_BUY=MINT_BUY),
resource_deps=["svm-create-mints"], dir="contracts/svm",
)
# create a single limo order for the searcher to bid on
local_resource(
"svm-limo-create-order",
"{SET_GLOBAL_CONFIG} {RUN_CLI} place-ask --quote {MINT_SELL} --base {MINT_BUY} --price 10000 --quote-amount 20"
.format(RUN_CLI=RUN_CLI, SET_GLOBAL_CONFIG=SET_GLOBAL_CONFIG, MINT_SELL=MINT_SELL, MINT_BUY=MINT_BUY),
resource_deps=["svm-limo-setup"], dir="contracts/svm",
)
local_resource(
"auction-server",
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",
serve_dir="auction-server",
resource_deps=["create-server-configs", "svm-build-programs", "svm-setup-accounts"],
readiness_probe=probe(period_secs=5, http_get=http_get_action(port=9000)),
)
monitor_command = (
"source tilt-resources.env; "
+ "poetry -C tilt-scripts run "
+ "python3 -m tilt-scripts.protocols.token_vault_monitor "
+ "--chain-id development "
+ "--rpc-url %s " % (rpc_url_anvil)
+ "--vault-contract $TOKEN_VAULT "
+ "--weth-contract $WETH "
+ "--liquidation-server-url http://localhost:9000 "
+ "--mock-pyth"
)
local_resource(
"evm-monitor",
serve_cmd=monitor_command,
resource_deps=["evm-deploy-contracts", "auction-server", "create-server-configs"],
)
evm_searcher_command = (
"source tilt-resources.env;"
+ "cargo run -p testing-searcher "
)
local_resource(
"evm-searcher",
serve_cmd=evm_searcher_command,
resource_deps=["evm-deploy-contracts", "auction-server", "create-server-configs"],
)
local_resource(
"svm-localnet",
serve_cmd="solana-test-validator $(./test-validator-params.sh)",
serve_dir="contracts/svm",
# check readiness by sending a health GET query to the RPC url
readiness_probe=probe(
period_secs=10,
http_get = http_get_action(port=int(rpc_port_solana), host="localhost", scheme="http", path="/health")
),
resource_deps=["svm-build-programs"],
)
local_resource(
"svm-setup-accounts",
"poetry -C tilt-scripts run python3 -m tilt-scripts.svm.setup_accounts --rpc-url %s" % rpc_url_solana,
resource_deps=["svm-localnet"],
)
# need to run initialize instructions for the programs one time, script skips if already initialized
local_resource(
"svm-initialize-programs",
"poetry -C tilt-scripts run python3 -m tilt-scripts.svm.initialize_programs -v --file-private-key-payer keypairs/searcher_py.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --express-relay-program PytERJFhAKuNNuaiXkApLfWzwNwSNDACpigT3LwQfou --rpc-url %s" % rpc_url_solana,
resource_deps=["svm-setup-accounts"]
)
# craft dummy tx, submits as a bid to auction server or submits relayer-signed tx directly to solana cluster
local_resource(
"svm-submit-bid",
"poetry -C tilt-scripts run python3 -m tilt-scripts.svm.dummy_tx -v --file-private-key-searcher keypairs/searcher_py.json --file-private-key-relayer-signer keypairs/relayer_signer.json --bid 100000000 --auction-server-url http://localhost:9000 --express-relay-program PytERJFhAKuNNuaiXkApLfWzwNwSNDACpigT3LwQfou --dummy-program DUmmYXYFZugRn2DS4REc5F9UbQNoxYsHP1VMZ6j5U7kZ --rpc-url %s --use-lookup-table" % rpc_url_solana,
resource_deps=["svm-initialize-programs", "auction-server"],
)
local_resource(
"svm-limonade",
serve_cmd="pnpm run --prefix scripts/limonade limonade --global-config $(solana-keygen pubkey keypairs/limo_global_config.json) --endpoint http://127.0.0.1:9000 --chain-id development-solana --api-key $(poetry -C tilt-scripts run python3 create_limo_profile.py) --rpc-endpoint %s" % rpc_url_solana,
resource_deps=["svm-initialize-programs", "auction-server"],
)
local_resource(
"svm-searcher-py",
serve_cmd="poetry run python3 -m express_relay.searcher.examples.testing_searcher_svm --endpoint-express-relay http://127.0.0.1:9000 --chain-id development-solana --private-key-json-file ../../keypairs/searcher_js.json --endpoint-svm http://127.0.0.1:8899 --bid 10000000 --fill-rate 4 --bid-margin 100 --with-latency",
serve_dir="sdk/python",
resource_deps=["svm-initialize-programs", "auction-server"],
)
local_resource(
"svm-searcher-js",
serve_cmd="pnpm run testing-searcher-limo --endpoint-express-relay http://127.0.0.1:9000 --chain-id development-solana --private-key-json-file ../../keypairs/searcher_py.json --endpoint-svm http://127.0.0.1:8899 --bid 10000000 --fill-rate 4 --bid-margin 100 --with-latency",
serve_dir="sdk/js",
resource_deps=["svm-initialize-programs", "auction-server"],
)