token_gateway_primitives/
lib.rs

1// Copyright (C) Polytope Labs Ltd.
2// SPDX-License-Identifier: Apache-2.0
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// 	http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16#![doc = include_str!("../README.md")]
17#![cfg_attr(not(feature = "std"), no_std)]
18
19use alloy_primitives::hex;
20use ismp::host::StateMachine;
21use polkadot_sdk::*;
22use sp_core::{ConstU32, H160, H256};
23use sp_runtime::BoundedVec;
24
25extern crate alloc;
26use alloc::vec::Vec;
27use codec::{Decode, DecodeWithMemTracking, Encode};
28
29/// Pallet Token Governor's module ID for ISMP requests
30pub const TOKEN_GOVERNOR_ID: [u8; 8] = *b"registry";
31
32/// Pallet Token Gateway's module ID for ISMP requests
33///
34/// Derived from `keccak_256(b"tokengty")[12..]`
35pub const PALLET_TOKEN_GATEWAY_ID: [u8; 20] = hex!("a09b1c60e8650245f92518c8a17314878c4043ed");
36
37/// Holds metadata relevant to a multi-chain native asset
38#[derive(
39	Debug,
40	Clone,
41	Encode,
42	Decode,
43	DecodeWithMemTracking,
44	scale_info::TypeInfo,
45	PartialEq,
46	Eq,
47	Default,
48)]
49pub struct AssetMetadata {
50	/// The asset name
51	pub name: BoundedVec<u8, ConstU32<50>>,
52	/// The asset symbol
53	pub symbol: BoundedVec<u8, ConstU32<20>>,
54}
55
56/// A struct for deregistering asset id on pallet-token-gateway
57#[derive(
58	Debug,
59	Clone,
60	Encode,
61	Decode,
62	DecodeWithMemTracking,
63	scale_info::TypeInfo,
64	PartialEq,
65	Eq,
66	Default,
67)]
68pub struct DeregisterAssets {
69	/// List of asset ids to deregister
70	pub asset_ids: Vec<H256>,
71}
72
73/// Holds data required for multi-chain native asset registration
74#[derive(
75	Debug, Clone, Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo, PartialEq, Eq,
76)]
77pub struct GatewayAssetRegistration {
78	/// The asset name
79	pub name: BoundedVec<u8, ConstU32<50>>,
80	/// The asset symbol
81	pub symbol: BoundedVec<u8, ConstU32<20>>,
82	/// The list of chains to create the asset on
83	pub chains: Vec<StateMachine>,
84	/// Minimum balance for the asset, for substrate chains,
85	pub minimum_balance: Option<u128>,
86}
87
88/// Allows a user to update their multi-chain native token potentially on multiple chains
89#[derive(
90	Debug,
91	Clone,
92	Encode,
93	Decode,
94	DecodeWithMemTracking,
95	scale_info::TypeInfo,
96	PartialEq,
97	Eq,
98	Default,
99)]
100pub struct GatewayAssetUpdate {
101	/// The asset identifier
102	pub asset_id: H256,
103	/// Chains to add support for the asset on
104	pub add_chains: BoundedVec<StateMachine, ConstU32<100>>,
105	/// Chains to delist the asset from
106	pub remove_chains: BoundedVec<StateMachine, ConstU32<100>>,
107	/// Chains to change the asset admin on
108	pub new_admins: BoundedVec<(StateMachine, H160), ConstU32<100>>,
109}
110
111/// Holds data required for multi-chain native asset registration
112#[derive(
113	Debug, Clone, Encode, Decode, DecodeWithMemTracking, scale_info::TypeInfo, PartialEq, Eq,
114)]
115pub enum RemoteERC6160AssetRegistration {
116	/// Asset creation message
117	CreateAsset(GatewayAssetRegistration),
118	/// Asset modification message
119	UpdateAsset(GatewayAssetUpdate),
120}