1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
//! Precompile to receive GMP callbacks and forward to XCM
18

            
19
use parity_scale_codec::{Decode, Encode};
20
use precompile_utils::prelude::*;
21
use sp_core::{H256, U256};
22
use sp_std::vec::Vec;
23
use xcm::VersionedLocation;
24

            
25
// A user action which will attempt to route the transferred assets to the account/chain specified
26
// by the given Location. Recall that a Location can contain both a chain and an account
27
// on that chain, as this one should.
28
#[derive(Encode, Decode, Debug)]
29
pub struct XcmRoutingUserAction {
30
	pub destination: VersionedLocation,
31
}
32

            
33
// A user action which is the same as XcmRoutingUserAction but also allows a fee to be paid. The
34
// fee is paid in the same asset being transferred, and must be <= the amount being sent.
35
#[derive(Encode, Decode, Debug)]
36
pub struct XcmRoutingUserActionWithFee {
37
	pub destination: VersionedLocation,
38
	pub fee: U256,
39
}
40

            
41
// A simple versioning wrapper around the initial XcmRoutingUserAction use-case. This should make
42
// future breaking changes easy to add in a backwards-compatible way.
43
#[derive(Encode, Decode, Debug)]
44
#[non_exhaustive]
45
pub enum VersionedUserAction {
46
	V1(XcmRoutingUserAction),
47
	V2(XcmRoutingUserActionWithFee),
48
}
49

            
50
// Struct representing a Wormhole VM
51
// The main purpose of this struct is to decode the ABI encoded struct returned from certain calls
52
// in the Wormhole Ethereum contracts.
53
//
54
// https://github.com/wormhole-foundation/wormhole/blob/main/ethereum/contracts/Structs.sol
55
#[derive(Debug, solidity::Codec)]
56
pub struct WormholeVM {
57
	pub version: u8,
58
	pub timestamp: u32,
59
	pub nonce: u32,
60
	pub emitter_chain_id: u16,
61
	pub emitter_address: H256,
62
	pub sequence: u64,
63
	pub consistency_level: u8,
64
	pub payload: BoundedBytes<crate::GetCallDataLimit>,
65

            
66
	pub guardian_set_index: u32,
67
	pub signatures: Vec<WormholeSignature>, // TODO: review: can this allow unbounded allocations?
68
	pub hash: H256,
69
}
70

            
71
// Struct representing a Wormhole Signature struct
72
#[derive(Debug, solidity::Codec)]
73
pub struct WormholeSignature {
74
	pub r: U256,
75
	pub s: U256,
76
	pub v: u8,
77
	pub guardian_index: u8,
78
}
79

            
80
// Struct representing a wormhole "BridgeStructs.TransferWithPayload" struct
81
// As with WormholeVM, the main purpose of this struct is to decode the ABI encoded struct when it
82
// returned from calls to Wormhole Ethereum contracts.
83
#[derive(Debug, solidity::Codec)]
84
pub struct WormholeTransferWithPayloadData {
85
	pub payload_id: u8,
86
	pub amount: U256,
87
	pub token_address: H256,
88
	pub token_chain: u16,
89
	pub to: H256,
90
	pub to_chain: u16,
91
	pub from_address: H256,
92
	pub payload: BoundedBytes<crate::GetCallDataLimit>,
93
}