-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
276 lines (249 loc) · 9.81 KB
/
build.rs
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
use std::error::Error;
#[cfg(feature = "generate-contracts")]
mod evm {
use super::*;
use ethers::contract::Abigen;
fn parse_and_write_abigen(
path: &str,
out: &str,
contract_name: &str,
) -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=./{}", path);
println!("cargo:rerun-if-changed=./{}", out);
let generated_tokens = Abigen::new(contract_name, path)?
.add_derive("serde::Serialize")?
.add_derive("serde::Deserialize")?
.format(false) // don't use rustfmt for now.
.generate()?
.to_string();
let syntax_tree = syn::parse_file(&generated_tokens).unwrap();
let formatted = prettyplease::unparse(&syntax_tree);
std::fs::write(out, formatted)?;
Ok(())
}
pub fn build_protocol_solidity_vanchor_verifier(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/VAnchorVerifier.json",
"src/evm/contract/protocol_solidity/vanchor_verifier.rs",
"VAnchorVerifierContract",
)
}
pub fn build_protocol_solidity_verifier_2_2() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/Verifier2_2.json",
"src/evm/contract/protocol_solidity/verifier_2_2.rs",
"Verifier2x2Contract",
)
}
pub fn build_protocol_solidity_verifier_2_16() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/Verifier2_16.json",
"src/evm/contract/protocol_solidity/verifier_2_16.rs",
"Verifier2x16Contract",
)
}
pub fn build_protocol_solidity_verifier_8_2() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/Verifier8_2.json",
"src/evm/contract/protocol_solidity/verifier_8_2.rs",
"Verifier8x2Contract",
)
}
pub fn build_protocol_solidity_verifier_8_16() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/Verifier8_16.json",
"src/evm/contract/protocol_solidity/verifier_8_16.rs",
"Verifier8x16Contract",
)
}
pub fn build_protocol_tangle_signing_rules() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/tangle/VotableSigningRules.json",
"src/evm/contract/tangle/votable_signing_rules.rs",
"SigningRulesContract",
)
}
pub fn build_protocol_solidity_vanchor_base() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/VAnchorBase.json",
"src/evm/contract/protocol_solidity/vanchor_base.rs",
"VAnchorBaseContract",
)
}
pub fn build_protocol_solidity_vanchor() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/VAnchor.json",
"src/evm/contract/protocol_solidity/variable_anchor.rs",
"VAnchorContract",
)
}
pub fn build_protocol_solidity_vanchor_tree() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/VAnchorTree.json",
"src/evm/contract/protocol_solidity/variable_anchor_tree.rs",
"VAnchorTreeContract",
)
}
pub fn build_protocol_solidity_vanchor_encode_inputs(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/VAnchorEncodeInputs.json",
"src/evm/contract/protocol_solidity/vanchor_encode_inputs.rs",
"VAnchorEncodeInputsContract",
)
}
pub fn build_protocol_solidity_anchor_handler() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/AnchorHandler.json",
"src/evm/contract/protocol_solidity/anchor_handler.rs",
"AnchorHandlerContract",
)
}
pub fn build_protocol_solidity_signature_bridge(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/SignatureBridge.json",
"src/evm/contract/protocol_solidity/signature_bridge.rs",
"SignatureBridgeContract",
)
}
pub fn build_protocol_solidity_fungible_token_wrapper(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/FungibleTokenWrapper.json",
"src/evm/contract/protocol_solidity/fungible_token_wrapper.rs",
"FungibleTokenWrapperContract",
)
}
pub fn build_protocol_solidity_token_wrapper() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/TokenWrapper.json",
"src/evm/contract/protocol_solidity/token_wrapper.rs",
"TokenWrapperContract",
)
}
pub fn build_protocol_solidity_treasury() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/Treasury.json",
"src/evm/contract/protocol_solidity/treasury.rs",
"TreasuryContract",
)
}
pub fn build_protocol_solidity_treasury_handler(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/TreasuryHandler.json",
"src/evm/contract/protocol_solidity/treasury_handler.rs",
"TreasuryHandlerContract",
)
}
pub fn build_protocol_solidity_token_wrapper_handler(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/TokenWrapperHandler.json",
"src/evm/contract/protocol_solidity/token_wrapper_handler.rs",
"TokenWrapperHandlerContract",
)
}
pub fn build_protocol_solidity_erc20_preset_minter_pauser(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/ERC20PresetMinterPauser.json",
"src/evm/contract/protocol_solidity/erc20_preset_minter_pauser.rs",
"ERC20PresetMinterPauserContract",
)
}
pub fn build_protocol_solidity_poseidon_t3() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/PoseidonT3.json",
"src/evm/contract/protocol_solidity/poseidon_t3.rs",
"PoseidonT3Contract",
)
}
pub fn build_protocol_solidity_poseidon_t4() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/PoseidonT4.json",
"src/evm/contract/protocol_solidity/poseidon_t4.rs",
"PoseidonT4Contract",
)
}
pub fn build_protocol_solidity_poseidon_t6() -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/PoseidonT6.json",
"src/evm/contract/protocol_solidity/poseidon_t6.rs",
"PoseidonT6Contract",
)
}
pub fn build_protocol_solidity_poseidon_hasher(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/PoseidonHasher.json",
"src/evm/contract/protocol_solidity/poseidon_hasher.rs",
"PoseidonHasherContract",
)
}
pub fn build_protocol_solidity_masp_vanchor_batch_tree(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/MultiAssetVAnchorBatchTree.json",
"src/evm/contract/protocol_solidity/masp_vanchor_batch_tree.rs",
"MultiAssetVAnchorBatchTreeContract",
)
}
pub fn build_protocol_solidity_masp_vanchor_tree(
) -> Result<(), Box<dyn Error>> {
parse_and_write_abigen(
"contracts/protocol-solidity/MultiAssetVAnchorTree.json",
"src/evm/contract/protocol_solidity/masp_vanchor_tree.rs",
"MultiAssetVAnchorTreeContract",
)
}
pub fn build_protocol_solidity_masp_vanchor() -> Result<(), Box<dyn Error>>
{
parse_and_write_abigen(
"contracts/protocol-solidity/MultiAssetVAnchor.json",
"src/evm/contract/protocol_solidity/masp_vanchor.rs",
"MultiAssetVAnchorContract",
)
}
}
fn main() -> Result<(), Box<dyn Error>> {
#[cfg(feature = "generate-contracts")]
{
evm::build_protocol_tangle_signing_rules()?;
evm::build_protocol_solidity_vanchor_base()?;
evm::build_protocol_solidity_vanchor()?;
evm::build_protocol_solidity_vanchor_verifier()?;
evm::build_protocol_solidity_verifier_2_2()?;
evm::build_protocol_solidity_verifier_2_16()?;
evm::build_protocol_solidity_verifier_8_2()?;
evm::build_protocol_solidity_verifier_8_16()?;
evm::build_protocol_solidity_vanchor_tree()?;
evm::build_protocol_solidity_vanchor_encode_inputs()?;
evm::build_protocol_solidity_anchor_handler()?;
evm::build_protocol_solidity_signature_bridge()?;
evm::build_protocol_solidity_token_wrapper()?;
evm::build_protocol_solidity_fungible_token_wrapper()?;
evm::build_protocol_solidity_token_wrapper_handler()?;
evm::build_protocol_solidity_treasury()?;
evm::build_protocol_solidity_treasury_handler()?;
evm::build_protocol_solidity_erc20_preset_minter_pauser()?;
evm::build_protocol_solidity_poseidon_t3()?;
evm::build_protocol_solidity_poseidon_t4()?;
evm::build_protocol_solidity_poseidon_t6()?;
evm::build_protocol_solidity_poseidon_hasher()?;
evm::build_protocol_solidity_masp_vanchor_batch_tree()?;
evm::build_protocol_solidity_masp_vanchor_tree()?;
evm::build_protocol_solidity_masp_vanchor()?;
}
Ok(())
}