time_primitives/
gmp.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
#[cfg(feature = "std")]
use crate::TssSignature;
use crate::{NetworkId, TssPublicKey};
#[cfg(feature = "std")]
use anyhow::{Context, Result};
use scale_codec::{Decode, DecodeWithMemTracking, Encode};
use scale_info::{prelude::vec::Vec, TypeInfo};
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
#[cfg(feature = "std")]
use std::ops::Range;
#[cfg(feature = "std")]
use std::sync::Arc;

pub type Address32 = [u8; 32];
pub type MessageId = [u8; 32];
pub type Hash = [u8; 32];
pub type BatchId = u64;

const GMP_VERSION: &str = "Analog GMP v3";

pub trait FixedSizeEncodable {
	fn left_pad_32(&self) -> [u8; 32];
}

macro_rules! impl_fixed_size_encodable {
    ($($n:expr),*) => {
        $(
            impl FixedSizeEncodable for [u8; $n] {
                fn left_pad_32(&self) -> [u8; 32] {
                    let mut out = [0u8; 32];
                    out[32-$n..].copy_from_slice(self);
                    out
                }
            }
        )*
    }
}

impl_fixed_size_encodable!(
	0, 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
);

#[derive(Debug, Clone, Decode, DecodeWithMemTracking, Encode, TypeInfo, PartialEq)]
pub struct GmpParams {
	pub network: NetworkId,
	pub gateway: Address32,
}

impl GmpParams {
	pub fn new(network: NetworkId, gateway: Address32) -> Self {
		Self { network, gateway }
	}

	pub fn hash(&self, payload: &[u8]) -> Vec<u8> {
		let mut data: Vec<u8> = Vec::new();
		data.extend_from_slice(GMP_VERSION.as_bytes());
		data.extend_from_slice(&self.network.to_be_bytes());
		data.extend_from_slice(&self.gateway);
		data.extend_from_slice(payload);
		data
	}
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize,))]
#[cfg_attr(not(feature = "std"), derive(Debug,))]
#[derive(
	Clone, Default, Decode, DecodeWithMemTracking, Encode, TypeInfo, Eq, PartialEq, Ord, PartialOrd,
)]
pub struct GmpMessage {
	pub src_network: NetworkId,
	pub dest_network: NetworkId,
	pub src: Address32,
	pub dest: Address32,
	pub nonce: u64,
	pub gas_limit: u64,
	pub bytes: Vec<u8>,
}

impl GmpMessage {
	const HEADER_LEN: usize = 224;

	pub fn encoded_len(&self) -> usize {
		Self::HEADER_LEN + self.bytes.len()
	}

	fn encode_header(&self) -> [u8; Self::HEADER_LEN] {
		let mut hdr = [0u8; Self::HEADER_LEN];
		hdr[32..64].copy_from_slice(&self.src.left_pad_32());
		hdr[64..96].copy_from_slice(&self.src_network.to_be_bytes().left_pad_32());
		hdr[96..128].copy_from_slice(&self.dest.left_pad_32());
		hdr[128..160].copy_from_slice(&self.dest_network.to_be_bytes().left_pad_32());
		hdr[160..192].copy_from_slice(&self.gas_limit.to_be_bytes().left_pad_32());
		hdr[192..Self::HEADER_LEN].copy_from_slice(&self.nonce.to_be_bytes().left_pad_32());
		hdr
	}

	pub fn message_id(&self) -> MessageId {
		let header = self.encode_header();
		Keccak256::digest(header).into()
	}
}

#[cfg(feature = "std")]
impl std::fmt::Display for GmpMessage {
	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
		f.write_str(&hex::encode(self.message_id()))
	}
}

#[cfg(feature = "std")]
impl std::fmt::Debug for GmpMessage {
	fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
		fmt.debug_struct("GmpMessage")
			.field("_id", &format_args!("{}", &hex::encode(self.message_id())))
			.field("src_network", &self.src_network)
			.field("dest_network", &self.dest_network)
			.field("src", &format_args!("{}", &hex::encode(self.src)))
			.field("dest", &format_args!("{}", &hex::encode(self.dest)))
			.field("noce", &self.nonce)
			.field("gas_limit", &self.gas_limit)
			.field("bytes", &format_args!("{}", &hex::encode(&self.bytes)))
			.finish()
	}
}

#[derive(
	Debug,
	Default,
	Clone,
	Copy,
	Decode,
	DecodeWithMemTracking,
	Encode,
	TypeInfo,
	PartialEq,
	Eq,
	Serialize,
	Deserialize,
)]
pub struct BatchGasParams {
	pub batch_gas_limit: u64,
	pub batch_exec_gas: u64,
	pub reg_op_exec_gas: u64,
	pub unreg_op_exec_gas: u64,
	pub msg_op_exec_gas: u64,
	pub msg_byte_gas: u64,
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Decode, DecodeWithMemTracking, Encode, TypeInfo, PartialEq)]
pub enum GatewayOp {
	SendMessage(GmpMessage),
	RegisterShard(
		#[cfg_attr(feature = "std", serde(with = "crate::shard::serde_tss_public_key"))]
		TssPublicKey,
		u16,
	),
	UnregisterShard(
		#[cfg_attr(feature = "std", serde(with = "crate::shard::serde_tss_public_key"))]
		TssPublicKey,
		u16,
	),
}

impl GatewayOp {
	fn code(&self) -> u8 {
		match self {
			GatewayOp::SendMessage(_) => 1,
			GatewayOp::RegisterShard(_, _) => 2,
			GatewayOp::UnregisterShard(_, _) => 3,
		}
	}

	fn hash(&self) -> [u8; 32] {
		let mut bytes = [0; 96];
		match self {
			Self::SendMessage(msg) => {
				let data = Keccak256::digest(&msg.bytes);
				bytes[..32].copy_from_slice(&msg.message_id());
				bytes[32..64].copy_from_slice(&data);
				return Keccak256::digest(&bytes[..64]).into();
			},
			Self::RegisterShard(pubkey, sessions) => {
				bytes[31..64].copy_from_slice(pubkey);
				bytes[64..96].copy_from_slice(&sessions.to_be_bytes().left_pad_32());
			},
			Self::UnregisterShard(pubkey, sessions) => {
				bytes[31..64].copy_from_slice(pubkey);
				bytes[64..96].copy_from_slice(&sessions.to_be_bytes().left_pad_32());
			},
		}
		Keccak256::digest(bytes).into()
	}

	pub fn gas(&self, params: &BatchGasParams) -> u64 {
		match self {
			Self::SendMessage(msg) => {
				params.msg_op_exec_gas
					+ msg.bytes.len() as u64 * params.msg_byte_gas
					+ msg.gas_limit
			},
			Self::RegisterShard(_, _) => params.reg_op_exec_gas,
			Self::UnregisterShard(_, _) => params.unreg_op_exec_gas,
		}
	}
}

#[cfg(feature = "std")]
impl std::fmt::Display for GatewayOp {
	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
		match self {
			Self::SendMessage(msg) => {
				writeln!(f, "send_message {}", hex::encode(msg.message_id()))
			},
			Self::RegisterShard(key, sessions) => {
				writeln!(f, "register_shard {} {}", hex::encode(key), sessions)
			},
			Self::UnregisterShard(key, sessions) => {
				writeln!(f, "unregister_shard {} {}", hex::encode(key), sessions)
			},
		}
	}
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Decode, DecodeWithMemTracking, Encode, TypeInfo, PartialEq)]
pub struct GatewayMessage {
	pub ops: Vec<GatewayOp>,
}

impl GatewayMessage {
	pub fn new(ops: Vec<GatewayOp>) -> Self {
		Self { ops }
	}

	pub fn hash(&self, batch_id: BatchId) -> [u8; 32] {
		let mut ops_hash = [0; 32];
		for op in &self.ops {
			let mut ops_hasher = Keccak256::new();
			ops_hasher.update(ops_hash);

			let mut op_code = [0; 32];
			op_code[31] = op.code();
			ops_hasher.update(op_code);

			let op_hash = op.hash();
			ops_hasher.update(op_hash);

			ops_hash = ops_hasher.finalize().into();
		}

		let mut buf = [0; 96];
		// include version in buffer
		buf[..32].copy_from_slice(&[0u8; 32]);
		// include batch id padded to uint256
		buf[32..64].copy_from_slice(&batch_id.to_be_bytes().left_pad_32());
		buf[64..].copy_from_slice(&ops_hash);
		Keccak256::digest(buf).into()
	}

	pub fn gas(&self, params: &BatchGasParams) -> u64 {
		self.ops.iter().fold(0u64, |acc, op| acc.saturating_add(op.gas(params)))
	}
}

pub struct BatchBuilder {
	params: BatchGasParams,
	gas: u64,
	ops: Vec<GatewayOp>,
}

impl BatchBuilder {
	pub fn new(params: BatchGasParams) -> Self {
		Self {
			gas: params.batch_exec_gas,
			params,
			ops: Default::default(),
		}
	}

	pub fn take_batch(&mut self) -> Option<GatewayMessage> {
		if self.ops.is_empty() {
			return None;
		}
		self.gas = 0;
		let ops = core::mem::take(&mut self.ops);
		Some(GatewayMessage::new(ops))
	}

	pub fn push(&mut self, op: GatewayOp) -> Option<GatewayMessage> {
		let gas = op.gas(&self.params);
		let batch =
			if self.gas + gas > self.params.batch_gas_limit { self.take_batch() } else { None };
		self.ops.push(op);
		batch
	}
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(
	Debug, Clone, Decode, DecodeWithMemTracking, Encode, TypeInfo, Eq, PartialEq, Ord, PartialOrd,
)]
pub enum GmpEvent {
	ShardRegistered(
		#[cfg_attr(feature = "std", serde(with = "crate::shard::serde_tss_public_key"))]
		TssPublicKey,
	),
	ShardUnregistered(
		#[cfg_attr(feature = "std", serde(with = "crate::shard::serde_tss_public_key"))]
		TssPublicKey,
	),
	MessageReceived(GmpMessage),
	MessageExecuted(MessageId),
	BatchExecuted {
		batch_id: BatchId,
		tx_hash: Option<Hash>,
	},
}

#[cfg(feature = "std")]
impl std::fmt::Display for GmpEvent {
	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
		match self {
			Self::ShardRegistered(key) => {
				writeln!(f, "shard_registered {}", hex::encode(key))
			},
			Self::ShardUnregistered(key) => {
				writeln!(f, "shard_unregistered {}", hex::encode(key))
			},
			Self::MessageReceived(msg) => {
				writeln!(f, "message_received {}", hex::encode(msg.message_id()))
			},
			Self::MessageExecuted(msg) => {
				writeln!(f, "message_executed {}", hex::encode(msg))
			},
			Self::BatchExecuted { batch_id, tx_hash } => {
				let tx_hash = tx_hash.as_ref().map_or("None".to_string(), hex::encode);
				writeln!(f, "batch_executed {batch_id} with tx_hash {tx_hash}")
			},
		}
	}
}

#[cfg(feature = "std")]
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub struct Route {
	/// Destination network Id
	pub network_id: NetworkId,
	/// Destination gateway
	pub gateway: Address32,
	/// Maximum amount of gas a message is allowed to spend on destination network
	pub max_gas_limit: u64,
	/// Gas per message.
	pub msg_gas: u64,
	/// Gas per message byte.
	pub msg_byte_gas: u64,
	/// Gas price on destination network, expressed in source network token
	pub gas_price: f64,
	/// GMP protocol fee for message delivery to the destination network, expressed in source network token
	pub msg_fee: u64,
}

#[cfg(feature = "std")]
#[async_trait::async_trait]
pub trait IConnect: Send + Sync + 'static {
	fn chain(&self) -> &dyn IChain;
	async fn connect(&self, url: String) -> Result<Arc<dyn IConnector>>;
	async fn connect_admin(&self, url: String) -> Result<Arc<dyn IConnectorAdmin>>;
}

#[cfg(feature = "std")]
pub trait IChain: Send + Sync + 'static {
	/// Network identifier.
	fn network_id(&self) -> NetworkId;
	/// Human readable connector account identifier.
	fn address(&self) -> Address32;
	/// Formats an address into a string.
	fn format_address(&self, address: Address32) -> String;
	/// Parses an address from a string.
	fn parse_address(&self, address: &str) -> Result<Address32>;
}

#[cfg(feature = "std")]
#[async_trait::async_trait]
pub trait IConnector: Send + Sync + 'static {
	/// Returns an IChain implementation.
	fn chain(&self) -> &dyn IChain;
	/// Returns the last finalized block.
	async fn finalized_block(&self) -> Result<u64>;
	/// Reads gmp messages from the target chain.
	async fn read_events(&self, gateway: Address32, blocks: Range<u64>) -> Result<Vec<GmpEvent>>;
	/// Submits a gmp message to the target chain.
	async fn submit_commands(
		&self,
		gateway: Address32,
		batch: BatchId,
		msg: GatewayMessage,
		gas_price: u128,
		signer: TssPublicKey,
		sig: TssSignature,
	) -> Result<(), String>;
	/// Get EIP1559 `max_fee_per_gas` estimate for a chain.
	async fn gas_price(&self) -> Result<u128>;
}

#[cfg(feature = "std")]
#[async_trait::async_trait]
pub trait IConnectorAdmin: IConnector {
	/// Uses a faucet to fund the account when possible.
	async fn faucet(&self, balance: u128) -> Result<()>;
	/// Transfers an amount to an account.
	async fn transfer(&self, address: Address32, amount: u128) -> Result<()>;
	/// Queries the account balance.
	async fn balance(&self, address: Address32) -> Result<u128>;
	/// Deploys the proxy contract.
	async fn deploy_gateway(&self, proxy: &[u8], gateway: &[u8]) -> Result<(Address32, u64)>;
	/// Redeploys the gateway contract.
	async fn redeploy_gateway(&self, proxy: Address32, gateway: &[u8]) -> Result<()>;
	/// Contract bytecode matches.
	async fn contract_bytecode_matches(&self, address: Address32, bytecode: &[u8]) -> Result<bool>;
	/// Proxy implementation address.
	async fn implementation(&self, proxy: Address32) -> Result<Address32>;
	/// Returns the gateway admin.
	async fn admin(&self, gateway: Address32) -> Result<Address32>;
	/// Sets the gateway admin.
	async fn set_admin(&self, gateway: Address32, admin: Address32) -> Result<()>;
	/// Returns the registered shard keys.
	async fn shards(&self, gateway: Address32) -> Result<Vec<TssPublicKey>>;
	/// Sets the registered shard keys. Overwrites any other keys.
	async fn set_shards(
		&self,
		gateway: Address32,
		register: &[(TssPublicKey, u16)],
		revoke: &[(TssPublicKey, u16)],
	) -> Result<()>;
	/// Returns the gateway routing table.
	async fn routes(&self, gateway: Address32) -> Result<Vec<Route>>;
	/// Updates an entry in the gateway routing table.
	async fn set_route(&self, gateway: Address32, route: Route) -> Result<()>;
	/// Updates the prices for all routes in the gateway.
	async fn set_prices(&self, gateway: Address32, prices: &[f64]) -> Result<()>;
	/// Deploys a test contract.
	async fn deploy_tester(&self, gateway: Address32, tester: &[u8]) -> Result<(Address32, u64)>;
	/// Estimates the message gas limit.
	async fn estimate_message_gas_limit(
		&self,
		contract: Address32,
		src_network: NetworkId,
		src: Address32,
		payload: Vec<u8>,
	) -> Result<u64>;
	/// Estimates the message cost.
	async fn estimate_message_cost(
		&self,
		gateway: Address32,
		dest_network: NetworkId,
		msg_size: u16,
		gas_limit: u64,
	) -> Result<u128>;
	/// Sends a message using the test contract and returns the message id.
	#[allow(clippy::too_many_arguments)]
	async fn send_messages(
		&self,
		src: Address32,
		dest_network: NetworkId,
		dest: Address32,
		gas_limit: u64,
		msg_cost: u128,
		payload: Vec<u8>,
		amplification: u16,
	) -> Result<Vec<MessageId>>;
	/// Receives messages from test contract.
	async fn recv_messages(
		&self,
		contract: Address32,
		blocks: Range<u64>,
	) -> Result<Vec<GmpMessage>>;
	/// Calculate returns the latest block gas_limit for a chain.
	async fn block_gas_limit(&self) -> Result<u64>;
	/// Withdraw gateway funds.
	async fn withdraw_funds(
		&self,
		gateway: Address32,
		amount: u128,
		address: Address32,
	) -> Result<()>;
	/// Debug a transaction.
	async fn debug_transaction(&self, tx: Hash) -> Result<String>;
}

#[cfg(feature = "std")]
pub struct AdminConnector<T>(T);

#[cfg(feature = "std")]
impl<T: IConnector> AdminConnector<T> {
	pub fn new(connector: T) -> Self {
		Self(connector)
	}

	fn context(&self, method: &str) -> String {
		format!("{}: {method} failed", self.0.chain().network_id())
	}
}

#[cfg(feature = "std")]
#[async_trait::async_trait]
impl<T: IConnector> IConnector for AdminConnector<T> {
	fn chain(&self) -> &dyn IChain {
		self.0.chain()
	}
	async fn finalized_block(&self) -> Result<u64> {
		self.0.finalized_block().await.with_context(|| self.context("finalized_block"))
	}
	async fn read_events(&self, gateway: Address32, blocks: Range<u64>) -> Result<Vec<GmpEvent>> {
		self.0
			.read_events(gateway, blocks)
			.await
			.with_context(|| self.context("read_events"))
	}
	async fn submit_commands(
		&self,
		gateway: Address32,
		batch: BatchId,
		msg: GatewayMessage,
		gas_price: u128,
		signer: TssPublicKey,
		sig: TssSignature,
	) -> Result<(), String> {
		self.0.submit_commands(gateway, batch, msg, gas_price, signer, sig).await
	}
	async fn gas_price(&self) -> Result<u128> {
		self.0.gas_price().await.with_context(|| self.context("gas_price"))
	}
}

#[cfg(feature = "std")]
#[async_trait::async_trait]
impl<T: IConnectorAdmin> IConnectorAdmin for AdminConnector<T> {
	async fn faucet(&self, balance: u128) -> Result<()> {
		self.0.faucet(balance).await.with_context(|| self.context("faucet"))
	}
	async fn transfer(&self, address: Address32, amount: u128) -> Result<()> {
		self.0.transfer(address, amount).await.with_context(|| self.context("transfer"))
	}
	async fn balance(&self, address: Address32) -> Result<u128> {
		self.0.balance(address).await.with_context(|| self.context("balance"))
	}
	async fn deploy_gateway(&self, proxy: &[u8], gateway: &[u8]) -> Result<(Address32, u64)> {
		self.0
			.deploy_gateway(proxy, gateway)
			.await
			.with_context(|| self.context("deploy_gateway"))
	}
	async fn redeploy_gateway(&self, proxy: Address32, gateway: &[u8]) -> Result<()> {
		self.0
			.redeploy_gateway(proxy, gateway)
			.await
			.with_context(|| self.context("redeploy_gateway"))
	}
	async fn contract_bytecode_matches(&self, address: Address32, bytecode: &[u8]) -> Result<bool> {
		self.0
			.contract_bytecode_matches(address, bytecode)
			.await
			.with_context(|| self.context("contract_bytecode_matches"))
	}
	async fn implementation(&self, proxy: Address32) -> Result<Address32> {
		self.0
			.implementation(proxy)
			.await
			.with_context(|| self.context("implementation"))
	}
	async fn admin(&self, gateway: Address32) -> Result<Address32> {
		self.0.admin(gateway).await.with_context(|| self.context("admin"))
	}
	async fn set_admin(&self, gateway: Address32, admin: Address32) -> Result<()> {
		self.0
			.set_admin(gateway, admin)
			.await
			.with_context(|| self.context("set_admin"))
	}
	async fn shards(&self, gateway: Address32) -> Result<Vec<TssPublicKey>> {
		self.0.shards(gateway).await.with_context(|| self.context("shards"))
	}
	async fn set_shards(
		&self,
		gateway: Address32,
		register: &[(TssPublicKey, u16)],
		revoke: &[(TssPublicKey, u16)],
	) -> Result<()> {
		self.0
			.set_shards(gateway, register, revoke)
			.await
			.with_context(|| self.context("set_shards"))
	}
	async fn routes(&self, gateway: Address32) -> Result<Vec<Route>> {
		self.0.routes(gateway).await.with_context(|| self.context("routes"))
	}
	async fn set_route(&self, gateway: Address32, route: Route) -> Result<()> {
		self.0
			.set_route(gateway, route)
			.await
			.with_context(|| self.context("set_route"))
	}
	async fn set_prices(&self, gateway: Address32, prices: &[f64]) -> Result<()> {
		self.0
			.set_prices(gateway, prices)
			.await
			.with_context(|| self.context("set_prices"))
	}
	async fn deploy_tester(&self, gateway: Address32, tester: &[u8]) -> Result<(Address32, u64)> {
		self.0
			.deploy_tester(gateway, tester)
			.await
			.with_context(|| self.context("deploy_tester"))
	}
	async fn estimate_message_gas_limit(
		&self,
		contract: Address32,
		src_network: NetworkId,
		src: Address32,
		payload: Vec<u8>,
	) -> Result<u64> {
		self.0
			.estimate_message_gas_limit(contract, src_network, src, payload)
			.await
			.with_context(|| self.context("estimate_message_gas_limit"))
	}
	async fn estimate_message_cost(
		&self,
		gateway: Address32,
		dest_network: NetworkId,
		msg_size: u16,
		gas_limit: u64,
	) -> Result<u128> {
		self.0
			.estimate_message_cost(gateway, dest_network, msg_size, gas_limit)
			.await
			.with_context(|| self.context("estimate_message_cost"))
	}
	async fn send_messages(
		&self,
		src: Address32,
		dest_network: NetworkId,
		dest: Address32,
		gas_limit: u64,
		msg_cost: u128,
		payload: Vec<u8>,
		amplification: u16,
	) -> Result<Vec<MessageId>> {
		self.0
			.send_messages(src, dest_network, dest, gas_limit, msg_cost, payload, amplification)
			.await
			.with_context(|| self.context("send_messages"))
	}
	async fn recv_messages(
		&self,
		contract: Address32,
		blocks: Range<u64>,
	) -> Result<Vec<GmpMessage>> {
		self.0
			.recv_messages(contract, blocks)
			.await
			.with_context(|| self.context("recv_messages"))
	}
	async fn block_gas_limit(&self) -> Result<u64> {
		self.0.block_gas_limit().await.with_context(|| self.context("block_gas_limit"))
	}
	async fn withdraw_funds(
		&self,
		gateway: Address32,
		amount: u128,
		address: Address32,
	) -> Result<()> {
		self.0
			.withdraw_funds(gateway, amount, address)
			.await
			.with_context(|| self.context("withdraw_funds"))
	}
	async fn debug_transaction(&self, tx: Hash) -> Result<String> {
		self.0
			.debug_transaction(tx)
			.await
			.with_context(|| self.context("debug_transaction"))
	}
}

#[cfg(test)]
mod tests {
	use super::*;

	#[test]
	fn boxed() {
		std::collections::HashMap::<NetworkId, Box<dyn IConnectorAdmin>>::default();
	}
}