├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── move-binding-derive ├── Cargo.toml ├── src │ └── lib.rs └── tests │ └── test.rs ├── move-binding ├── Cargo.toml ├── src │ ├── lib.rs │ ├── move_codegen.rs │ ├── package_id_resolver.rs │ ├── package_provider.rs │ └── types.rs └── tests │ ├── snapshot_tests.rs │ └── snapshots │ ├── snapshot_tests__0x1.snap │ ├── snapshot_tests__0x2.snap │ ├── snapshot_tests__0x3.snap │ ├── snapshot_tests__0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a.snap │ ├── snapshot_tests__0xb.snap │ └── snapshot_tests__0xd84704c17fc870b8764832c535aa6b11f21a95cd6f5bb38a9b07d2cf42220c66.snap └── move-types ├── Cargo.toml └── src ├── functions.rs └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | 4 | members = [ 5 | "move-types", 6 | "move-binding", 7 | "move-binding-derive" 8 | ] 9 | 10 | [workspace.dependencies] 11 | serde = "1.0.217" 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Move Binding 2 | 3 | Move Binding is a Rust library that provides a way to interact with Sui Move packages on-chain. It reads Move packages from the Sui blockchain and generates corresponding Rust structs and function entry points, allowing for seamless integration between Move and Rust. 4 | 5 | > ⚠️ **Disclaimer** 6 | > This library is experimental and may not be actively maintained or fully supported by Mysten Labs. 7 | > Developers should be aware that features may change without notice, and community or official support could be limited. 8 | > **Use at your own risk**, and thoroughly test any integration in your own development environment before relying on it in production systems. 9 | 10 | ## Features 11 | - Reads Sui Move packages directly from the Sui blockchain. 12 | - Generates Rust representations of Move objects. 13 | - Provides Rust function entry points for Move contract interactions. 14 | - Facilitates seamless integration between Move smart contracts and Rust applications. 15 | 16 | ## Installation 17 | To use Move Binding in your project, add the following dependency to your `Cargo.toml`: 18 | 19 | ```toml 20 | [dependencies] 21 | move-binding-derive = { git = "https://github.com/MystenLabs/move-binding" } 22 | move-types = { git = "https://github.com/MystenLabs/move-binding" } 23 | ``` 24 | 25 | ## Usage 26 | 27 | ### Import a Move Package from Sui 28 | ```rust 29 | use std::str::FromStr; 30 | use sui_client::Client; 31 | use sui_sdk_types::{Address, ObjectData}; 32 | 33 | use crate::bridge::bridge::BridgeInner; 34 | use crate::sui::dynamic_field::Field; 35 | use move_binding_derive::move_contract; 36 | 37 | move_contract! {alias = "sui", package = "0x2"} 38 | move_contract! {alias = "bridge", package = "0xb"} 39 | 40 | // Example for move package import where base module path is not "crate" 41 | pub mod models { 42 | use move_binding_derive::move_contract; 43 | move_contract! {alias = "sui_system", package = "0x3", base_path = crate::models } 44 | } 45 | 46 | #[tokio::main] 47 | async fn main() { 48 | let client = Client::new("https://sui-mainnet.mystenlabs.com/graphql").unwrap(); 49 | let bridge_obj = client 50 | .object( 51 | Address::from_str( 52 | "0x00ba8458097a879607d609817a05599dc3e9e73ce942f97d4f1262605a8bf0fc".into(), 53 | ) 54 | .unwrap(), 55 | None, 56 | ) 57 | .await 58 | .unwrap() 59 | .unwrap(); 60 | 61 | if let ObjectData::Struct(o) = bridge_obj.data() { 62 | let bridge: Field = bcs::from_bytes(o.contents()).unwrap(); 63 | println!("Deserialized Bridge object: {:?}", bridge); 64 | } 65 | } 66 | ``` 67 | 68 | ### Call move functions using sui-client and sui-transaction-builder 69 | ```rust 70 | use std::str::FromStr; 71 | use sui_client::Client; 72 | use sui_sdk_types::{Address, ObjectId}; 73 | use sui_transaction_builder::TransactionBuilder; 74 | use sui_transaction_builder::unresolved::Input; 75 | use move_binding_derive::move_contract; 76 | 77 | move_contract! {alias = "sui", package = "0x2"} 78 | 79 | #[tokio::main] 80 | async fn main() { 81 | let client = Client::new("https://sui-mainnet.mystenlabs.com/graphql").unwrap(); 82 | let owner = Address::from_str("0x2").unwrap(); 83 | let gas = ObjectId::from_str("0x726b714a3c4c681d8a9b1ff1833ad368585579a273362e1cbd738c0c8f70dabd").unwrap(); 84 | let gas = client.object(gas.into(), None).await.unwrap().unwrap(); 85 | 86 | let mut builder = TransactionBuilder::new(); 87 | builder.set_sender(owner); 88 | builder.add_gas_objects(vec![Input::owned(gas.object_id(), gas.version(), gas.digest())]); 89 | builder.set_gas_budget(10000000); 90 | builder.set_gas_price(1000); 91 | 92 | let mut new_bag = sui::bag::new(&mut builder); 93 | sui::bag::add(&mut builder, new_bag.borrow_mut(), "Test".into(), "Test_value".into()); 94 | sui::bag::add(&mut builder, new_bag.borrow_mut(), "Test2".into(), "Test_value2".into()); 95 | sui::transfer::public_transfer(&mut builder, new_bag, owner.into()); 96 | 97 | let tx = builder.finish().unwrap(); 98 | let result = client.dry_run_tx(&tx, None).await.unwrap(); 99 | 100 | println!("{:?}", result); 101 | } 102 | ``` 103 | 104 | 105 | ## Development 106 | Clone the repository and build the project: 107 | 108 | ```sh 109 | git clone https://github.com/MystenLabs/move-binding.git 110 | cd move-binding 111 | cargo build 112 | ``` 113 | 114 | To run tests: 115 | ```sh 116 | cargo test 117 | ``` 118 | 119 | ## Contributing 120 | Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes. 121 | 122 | ## License 123 | This project is licensed under the Apache 2.0 License. 124 | 125 | --- 126 | -------------------------------------------------------------------------------- /move-binding-derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "move-binding-derive" 3 | version = "0.1.0" 4 | authors = ["Mysten Labs "] 5 | license = "Apache-2.0" 6 | publish = false 7 | edition = "2021" 8 | 9 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 10 | [lib] 11 | proc-macro = true 12 | 13 | [dependencies] 14 | syn = "^2.0.46" 15 | quote = "^1.0.35" 16 | proc-macro2 = "^1.0.74" 17 | serde = { workspace = true, features = ["derive"] } 18 | sui-sdk-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", features = ["serde"], rev="f0c8068"} 19 | sui-transaction-builder = { git = "https://github.com/mystenlabs/sui-rust-sdk", rev="f0c8068"} 20 | move-binding = { path = "../move-binding" } 21 | move-types = { path = "../move-types" } 22 | bcs = "0.1.6" 23 | 24 | [dev-dependencies] 25 | tokio = { version = "1.43.0", features = ["full"] } 26 | sui-client = { git = "https://github.com/mystenlabs/sui-rust-sdk", package = "sui-graphql-client", rev="f0c8068"} -------------------------------------------------------------------------------- /move-binding-derive/src/lib.rs: -------------------------------------------------------------------------------- 1 | use move_binding::move_codegen::MoveCodegen; 2 | use move_binding::SuiNetwork; 3 | use proc_macro::TokenStream; 4 | use proc_macro2::Ident; 5 | use quote::quote; 6 | use syn::parse::{Parse, ParseStream}; 7 | use syn::{parse_macro_input, DeriveInput, ExprPath, GenericParam, Generics, LitStr, Token}; 8 | 9 | #[proc_macro_derive(Key)] 10 | pub fn key_derive(input: TokenStream) -> TokenStream { 11 | let ast: DeriveInput = syn::parse(input).unwrap(); 12 | let name = &ast.ident; 13 | 14 | let types = extract_type_ident(&ast.generics); 15 | 16 | let (types_with_trait, types) = if types.is_empty() { 17 | (quote! {}, quote! {}) 18 | } else { 19 | ( 20 | quote! {<#(#types:move_types::MoveType),*>}, 21 | quote! {<#(#types),*>}, 22 | ) 23 | }; 24 | 25 | let gen = quote! { 26 | impl #types_with_trait move_types::Key for #name #types { 27 | fn id(&self) -> &move_types::ObjectId { 28 | &self.id 29 | } 30 | } 31 | }; 32 | gen.into() 33 | } 34 | 35 | fn extract_type_ident(generics: &Generics) -> Vec { 36 | generics 37 | .params 38 | .iter() 39 | .flat_map(|p| { 40 | if let GenericParam::Type(t) = p { 41 | Some(t.ident.clone()) 42 | } else { 43 | None 44 | } 45 | }) 46 | .collect() 47 | } 48 | 49 | #[proc_macro_derive(MoveStruct)] 50 | pub fn move_struct_derive(input: TokenStream) -> TokenStream { 51 | let ast: DeriveInput = syn::parse(input).unwrap(); 52 | let name = &ast.ident; 53 | 54 | let types = extract_type_ident(&ast.generics); 55 | let name_str = name.to_string(); 56 | 57 | let gen = if types.is_empty() { 58 | quote! { 59 | impl move_types::MoveStruct for #name { 60 | fn struct_type() -> move_types::StructTag { 61 | move_types::StructTag { 62 | address: Self::TYPE_ORIGIN_ID, 63 | module: move_types::Identifier::from_str(MODULE_NAME).unwrap(), 64 | name: move_types::Identifier::from_str(#name_str).unwrap(), 65 | type_params: vec![], 66 | } 67 | } 68 | } 69 | } 70 | } else { 71 | quote! { 72 | impl <#(#types:move_types::MoveType), *> move_types::MoveStruct for #name<#(#types),*> { 73 | fn struct_type() -> move_types::StructTag { 74 | move_types::StructTag { 75 | address: Self::TYPE_ORIGIN_ID, 76 | module: move_types::Identifier::from_str(MODULE_NAME).unwrap(), 77 | name: move_types::Identifier::from_str(#name_str).unwrap(), 78 | type_params: vec![#(#types::type_()),*], 79 | } 80 | } 81 | } 82 | } 83 | }; 84 | gen.into() 85 | } 86 | 87 | struct MoveContractArgs { 88 | network: SuiNetwork, 89 | package_alias: String, 90 | package: String, 91 | path: Option, 92 | } 93 | 94 | impl Parse for MoveContractArgs { 95 | fn parse(input: ParseStream) -> Result { 96 | let mut alias = None; 97 | let mut package = None; 98 | let mut path = None; 99 | let mut network = SuiNetwork::Mainnet; 100 | 101 | while !input.is_empty() { 102 | let key: Ident = input.parse()?; // Parse the key (e.g., alias, package, deps) 103 | input.parse::()?; // Expect '=' token 104 | 105 | if key == "alias" { 106 | alias = Some(input.parse::()?.value()); // Parse string literal 107 | } else if key == "package" { 108 | package = Some(input.parse::()?.value()); // Parse string literal 109 | } else if key == "base_path" { 110 | let p = input.parse::()?.path; 111 | path = Some(quote!(#p).to_string()); // Parse string literal 112 | } else if key == "network" { 113 | if let Ok(lit) = input.parse::() { 114 | network = match lit.value().to_lowercase().as_str() { 115 | "mainnet" => SuiNetwork::Mainnet, 116 | "testnet" => SuiNetwork::Testnet, 117 | _ => { 118 | return Err(syn::Error::new( 119 | key.span(), 120 | "Unknown network, only ['mainnet', 'testnet'] are supported.", 121 | )) 122 | } 123 | }; 124 | } 125 | } else { 126 | return Err(syn::Error::new(key.span(), "Unknown key")); 127 | } 128 | 129 | if input.peek(Token![,]) { 130 | input.parse::()?; // Consume optional comma 131 | } 132 | } 133 | 134 | Ok(MoveContractArgs { 135 | network, 136 | package_alias: alias.ok_or_else(|| syn::Error::new(input.span(), "Missing alias"))?, 137 | package: package.ok_or_else(|| syn::Error::new(input.span(), "Missing package"))?, 138 | path, 139 | }) 140 | } 141 | } 142 | 143 | #[proc_macro] 144 | pub fn move_contract(input: TokenStream) -> TokenStream { 145 | let MoveContractArgs { 146 | network, 147 | package_alias, 148 | package, 149 | path, 150 | } = parse_macro_input!(input as MoveContractArgs); 151 | MoveCodegen::expand( 152 | network, 153 | &package, 154 | &package_alias, 155 | &path.unwrap_or("crate".to_string()), 156 | ) 157 | .unwrap() 158 | .into() 159 | } 160 | -------------------------------------------------------------------------------- /move-binding-derive/tests/test.rs: -------------------------------------------------------------------------------- 1 | use crate::bridge::bridge::BridgeInner; 2 | use crate::sui::dynamic_field::Field; 3 | use move_binding_derive::move_contract; 4 | use move_types::Key; 5 | use std::str::FromStr; 6 | use sui_client::Client; 7 | use sui_sdk_types::{Address, ObjectData, ObjectId}; 8 | use sui_transaction_builder::unresolved::Input; 9 | use sui_transaction_builder::TransactionBuilder; 10 | 11 | move_contract! {alias = "move_lib", package = "0x1"} 12 | move_contract! {alias = "sui", package = "0x2"} 13 | move_contract! {alias = "sui_system", package = "0x3"} 14 | move_contract! {alias = "bridge", package = "0xb"} 15 | 16 | move_contract! {alias = "mvr_metadata", package = "@mvr/metadata"} 17 | move_contract! {alias = "suins", package = "0xd22b24490e0bae52676651b4f56660a5ff8022a2576e0089f79b3c88d44e08f0"} 18 | move_contract! {alias = "mvr_core", package = "@mvr/core"} 19 | 20 | move_contract! {alias = "token", package = "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270"} 21 | 22 | move_contract! {alias = "deepbook", package = "@deepbook/core"} 23 | 24 | move_contract! {alias = "tokenv2", package = "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8", network="testnet"} 25 | move_contract! {alias = "deepbookv2", package = "@deepbook/core", network = "testnet"} 26 | 27 | //move_contract! {alias = "mvr_metadata_testnet", package = "@mvr/metadata", network = "testnet", deps = [crate::sui]} 28 | 29 | move_contract! {alias = "commander", package = "0xdc931e30acc15dbc7fcbd39cd385a03894a7236761490ff4d5b9dbf51af3ce26", network="testnet"} 30 | 31 | move_contract! {alias = "wal", package = "0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a", network="testnet"} 32 | move_contract! {alias = "walrus", package = "0xd84704c17fc870b8764832c535aa6b11f21a95cd6f5bb38a9b07d2cf42220c66", network="testnet"} 33 | 34 | #[tokio::test] 35 | pub async fn test_deserialize_object() { 36 | let client = Client::new("https://sui-mainnet.mystenlabs.com/graphql").unwrap(); 37 | let bridge_obj = client 38 | .object( 39 | Address::from_str( 40 | "0x00ba8458097a879607d609817a05599dc3e9e73ce942f97d4f1262605a8bf0fc".into(), 41 | ) 42 | .unwrap(), 43 | None, 44 | ) 45 | .await 46 | .unwrap() 47 | .unwrap(); 48 | 49 | if let ObjectData::Struct(o) = bridge_obj.data() { 50 | let bridge: Field = bcs::from_bytes(o.contents()).unwrap(); 51 | println!("{:?}", bridge); 52 | println!("{:?}", bridge.id()); 53 | } 54 | } 55 | 56 | #[tokio::test] 57 | pub async fn test_function_call() { 58 | let client = Client::new("https://sui-mainnet.mystenlabs.com/graphql").unwrap(); 59 | 60 | let owner = Address::from_str("0x2").unwrap(); 61 | let gas = 62 | ObjectId::from_str("0x726b714a3c4c681d8a9b1ff1833ad368585579a273362e1cbd738c0c8f70dabd") 63 | .unwrap(); 64 | let gas = client.object(gas.into(), None).await.unwrap().unwrap(); 65 | 66 | let mut builder = TransactionBuilder::new(); 67 | builder.set_sender(owner); 68 | builder.add_gas_objects(vec![Input::owned( 69 | gas.object_id(), 70 | gas.version(), 71 | gas.digest(), 72 | )]); 73 | builder.set_gas_budget(10000000); 74 | builder.set_gas_price(1000); 75 | 76 | let mut new_bag = sui::bag::new(&mut builder); 77 | 78 | let option = move_lib::option::some(&mut builder, "Test".into()); 79 | 80 | sui::bag::add(&mut builder, new_bag.borrow_mut(), "Test".into(), option); 81 | sui::bag::add( 82 | &mut builder, 83 | new_bag.borrow_mut(), 84 | "Test2".into(), 85 | "Test_value2".into(), 86 | ); 87 | sui::transfer::public_transfer(&mut builder, new_bag, owner.into()); 88 | 89 | let tx = builder.finish().unwrap(); 90 | let result = client.dry_run_tx(&tx, None).await.unwrap(); 91 | 92 | println!("{:?}", result); 93 | } 94 | 95 | #[tokio::test] 96 | async fn test_deserialize_enum() { 97 | use commander::history; 98 | 99 | // Struct Variant 100 | let attack = history::Record::Attack { 101 | origin: vec![1, 1], 102 | target: vec![2, 7], 103 | }; 104 | let bytes = bcs::to_bytes(&attack).unwrap(); 105 | let deserialized: history::Record = bcs::from_bytes(&bytes).unwrap(); 106 | println!("Deserialized: {:?}", deserialized); 107 | 108 | // Tuple variant 109 | let reload = history::Record::Reload(vec![4, 7, 8, 22]); 110 | let bytes = bcs::to_bytes(&reload).unwrap(); 111 | let deserialized: history::Record = bcs::from_bytes(&bytes).unwrap(); 112 | println!("Deserialized: {:?}", deserialized); 113 | 114 | // Unit variant 115 | let miss = history::Record::Miss; 116 | let bytes = bcs::to_bytes(&miss).unwrap(); 117 | let deserialized: history::Record = bcs::from_bytes(&bytes).unwrap(); 118 | println!("Deserialized: {:?}", deserialized); 119 | } 120 | -------------------------------------------------------------------------------- /move-binding/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "move-binding" 3 | version = "0.1.0" 4 | authors = ["Mysten Labs "] 5 | license = "Apache-2.0" 6 | publish = false 7 | edition = "2021" 8 | 9 | [dependencies] 10 | syn = "^2.0.46" 11 | quote = "^1.0.35" 12 | proc-macro2 = "^1.0.74" 13 | itertools = "0.14.0" 14 | reqwest = { version = "^0.12", features = ["blocking", "json"] } 15 | serde_json = "^1.0.138" 16 | anyhow = "1.0.98" 17 | sui-sdk-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", features = ["serde"], rev = "f0c8068" } 18 | fastcrypto = "0.1.9" 19 | bcs = "0.1.6" 20 | move-binary-format = { git = "https://github.com/MystenLabs/sui.git", rev = "42ba6c0" } 21 | move-core-types = { git = "https://github.com/MystenLabs/sui.git", rev = "42ba6c0" } 22 | prettyplease = "0.2.32" 23 | once_cell = "1.20.3" 24 | 25 | [dev-dependencies] 26 | insta = "1.43.1" 27 | prettyplease = "0.2.32" -------------------------------------------------------------------------------- /move-binding/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod move_codegen; 2 | mod package_id_resolver; 3 | mod package_provider; 4 | mod types; 5 | 6 | #[derive(Copy, Clone)] 7 | pub enum SuiNetwork { 8 | Mainnet, 9 | Testnet, 10 | } 11 | 12 | impl SuiNetwork { 13 | pub fn mvr_endpoint(&self) -> &str { 14 | match self { 15 | SuiNetwork::Mainnet => "https://mainnet.mvr.mystenlabs.com", 16 | SuiNetwork::Testnet => "https://testnet.mvr.mystenlabs.com", 17 | } 18 | } 19 | pub fn gql(&self) -> &str { 20 | match self { 21 | SuiNetwork::Mainnet => "https://sui-mainnet.mystenlabs.com/graphql", 22 | SuiNetwork::Testnet => "https://sui-testnet.mystenlabs.com/graphql", 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /move-binding/src/move_codegen.rs: -------------------------------------------------------------------------------- 1 | use crate::package_provider::{ModuleProvider, MoveModuleProvider}; 2 | use crate::types::ToRustType; 3 | use crate::SuiNetwork; 4 | use anyhow::anyhow; 5 | use itertools::Itertools; 6 | use move_binary_format::normalized::{Enum, Function, Struct, Type}; 7 | use move_core_types::account_address::AccountAddress; 8 | use move_core_types::identifier::Identifier; 9 | use once_cell::sync::Lazy; 10 | use proc_macro2::{Ident, TokenStream}; 11 | use quote::quote; 12 | use std::collections::{BTreeMap, HashMap}; 13 | use std::sync::RwLock; 14 | 15 | pub static BINDING_REGISTRY: Lazy>> = 16 | Lazy::new(|| RwLock::new(HashMap::new())); 17 | 18 | pub struct MoveCodegen; 19 | 20 | impl MoveCodegen { 21 | pub fn expand( 22 | network: SuiNetwork, 23 | package: &str, 24 | package_alias: &str, 25 | base_path: &str, 26 | ) -> Result { 27 | let module_provider = MoveModuleProvider::new(network); 28 | let package = module_provider.get_package(package)?; 29 | 30 | // register package path 31 | let mut cache = BINDING_REGISTRY 32 | .write() 33 | .map_err(|e| anyhow!("Failed to acquire write lock: {}", e))?; 34 | package 35 | .type_origin_table 36 | .iter() 37 | .flat_map(|(_, m)| m.values()) 38 | .dedup() 39 | .for_each(|addr| { 40 | cache.insert(addr.clone(), format!("{base_path}::{package_alias}")); 41 | }); 42 | drop(cache); 43 | 44 | let module_tokens = package 45 | .module_map 46 | .iter() 47 | .map(|(module_name, module)| { 48 | let module_ident = Ident::new(module_name, proc_macro2::Span::call_site()); 49 | let type_origin_table = package 50 | .type_origin_table 51 | .get(module_name) 52 | .cloned() 53 | .unwrap_or_default(); 54 | 55 | let mut struct_fun_tokens = 56 | Self::create_structs(&module.structs, &type_origin_table)?; 57 | struct_fun_tokens.extend(Self::create_enums(&module.enums, &type_origin_table)); 58 | struct_fun_tokens.extend(Self::create_funs(&module.functions)); 59 | 60 | Ok::<_, anyhow::Error>(if struct_fun_tokens.is_empty() { 61 | quote! {} 62 | } else { 63 | let addr_byte_ident = module.address.to_vec(); 64 | quote! { 65 | pub mod #module_ident{ 66 | use std::str::FromStr; 67 | use move_binding_derive::{MoveStruct, Key}; 68 | use move_types::{MoveType, Address, Identifier, ObjectId}; 69 | use move_types::functions::{Arg, Ref, MutRef}; 70 | pub const PACKAGE_ID: Address = Address::new([#(#addr_byte_ident),*]); 71 | pub const MODULE_NAME: &str = #module_name; 72 | #(#struct_fun_tokens)* 73 | } 74 | } 75 | }) 76 | }) 77 | .collect::, _>>()?; 78 | 79 | let package_ident = Ident::new(&package_alias, proc_macro2::Span::call_site()); 80 | let version = package.version; 81 | 82 | Ok(quote! { 83 | pub mod #package_ident{ 84 | pub const PACKAGE_VERSION:u64 = #version; 85 | #(#module_tokens)* 86 | } 87 | }) 88 | } 89 | 90 | fn create_structs( 91 | structs: &BTreeMap, 92 | type_origin_ids: &HashMap, 93 | ) -> Result, anyhow::Error> { 94 | structs 95 | .iter() 96 | .map(|(name, move_struct)| { 97 | Self::create_struct(name.as_str(), move_struct, type_origin_ids) 98 | }) 99 | .collect() 100 | } 101 | 102 | fn create_struct( 103 | struct_name: &str, 104 | move_struct: &Struct, 105 | type_origin_id: &HashMap, 106 | ) -> Result { 107 | let (type_parameters, phantoms) = move_struct.type_parameters.iter().enumerate().fold( 108 | (vec![], vec![]), 109 | |(mut type_parameters, mut phantoms), (i, v)| { 110 | let ident = Ident::new(&format!("T{i}"), proc_macro2::Span::call_site()); 111 | type_parameters.push(quote! {#ident}); 112 | 113 | if v.is_phantom { 114 | let name = 115 | Ident::new(&format!("phantom_data_{i}"), proc_macro2::Span::call_site()); 116 | let type_: syn::Type = 117 | syn::parse_str(&format!("std::marker::PhantomData")).unwrap(); 118 | phantoms.push(quote! {#name: #type_,}) 119 | } 120 | (type_parameters, phantoms) 121 | }, 122 | ); 123 | 124 | let struct_ident = Ident::new(&struct_name.to_string(), proc_macro2::Span::call_site()); 125 | let field_tokens = move_struct 126 | .fields 127 | .iter() 128 | .map(|field| { 129 | let field_ident = Ident::new( 130 | &escape_keyword(field.name.as_str()), 131 | proc_macro2::Span::call_site(), 132 | ); 133 | let field_type: syn::Type = syn::parse_str(&field.type_.to_rust_type())?; 134 | Ok(quote! {pub #field_ident: #field_type,}) 135 | }) 136 | .collect::, anyhow::Error>>()?; 137 | 138 | let mut derives = vec![ 139 | quote! {serde::Deserialize}, 140 | quote! {serde::Serialize}, 141 | quote! {Debug}, 142 | quote! {MoveStruct}, 143 | ]; 144 | 145 | if move_struct.abilities.has_key() { 146 | derives.push(quote! {Key}); 147 | } 148 | 149 | let addr_byte_ident = type_origin_id[struct_name].to_vec(); 150 | Ok(if type_parameters.is_empty() { 151 | quote! { 152 | #[derive(#(#derives),*)] 153 | pub struct #struct_ident { 154 | #(#field_tokens)* 155 | } 156 | impl #struct_ident{ 157 | pub const TYPE_ORIGIN_ID: Address = Address::new([#(#addr_byte_ident),*]); 158 | } 159 | } 160 | } else { 161 | quote! { 162 | #[derive(#(#derives),*)] 163 | pub struct #struct_ident<#(#type_parameters),*> { 164 | #(#field_tokens)* 165 | #(#phantoms)* 166 | } 167 | impl <#(#type_parameters),*> #struct_ident<#(#type_parameters),*>{ 168 | pub const TYPE_ORIGIN_ID: Address = Address::new([#(#addr_byte_ident),*]); 169 | } 170 | } 171 | }) 172 | } 173 | 174 | fn create_enums( 175 | enums: &BTreeMap, 176 | type_origin_ids: &HashMap, 177 | ) -> Vec { 178 | enums 179 | .iter() 180 | .map(|(name, move_enum)| Self::create_enum(name.as_str(), move_enum, type_origin_ids)) 181 | .collect() 182 | } 183 | 184 | fn create_enum( 185 | enum_name: &str, 186 | move_enum: &Enum, 187 | type_origin_id: &HashMap, 188 | ) -> TokenStream { 189 | let enum_ident = Ident::new(&enum_name.to_string(), proc_macro2::Span::call_site()); 190 | let variant_tokens = move_enum.variants.iter().map(|variant| { 191 | let variant_ident = Ident::new( 192 | &escape_keyword(variant.name.as_str()), 193 | proc_macro2::Span::call_site(), 194 | ); 195 | 196 | if variant.fields.is_empty() { 197 | return quote! {#variant_ident,}; 198 | } 199 | 200 | if variant 201 | .fields 202 | .iter() 203 | .enumerate() 204 | .all(|(i, field)| field.name.to_string() == format!("pos{}", i)) 205 | { 206 | let field_types = variant.fields.iter().map(|field| { 207 | let field_type: syn::Type = 208 | syn::parse_str(&field.type_.to_rust_type()).unwrap(); 209 | quote! {#field_type,} 210 | }); 211 | 212 | return quote! { 213 | #variant_ident(#(#field_types)*), 214 | }; 215 | } 216 | 217 | let field_tokens = variant.fields.iter().map(|field| { 218 | let field_ident = Ident::new( 219 | &escape_keyword(field.name.as_str()), 220 | proc_macro2::Span::call_site(), 221 | ); 222 | let field_type: syn::Type = syn::parse_str(&field.type_.to_rust_type()).unwrap(); 223 | quote! {#field_ident: #field_type,} 224 | }); 225 | quote! { #variant_ident {#(#field_tokens)*},} 226 | }); 227 | 228 | let derives = vec![ 229 | quote! {serde::Deserialize}, 230 | quote! {serde::Serialize}, 231 | quote! {Debug}, 232 | quote! {MoveStruct}, 233 | ]; 234 | 235 | let addr_byte_ident = type_origin_id[enum_name].to_vec(); 236 | 237 | quote! { 238 | #[derive(#(#derives),*)] 239 | pub enum #enum_ident{ 240 | #(#variant_tokens)* 241 | } 242 | 243 | impl #enum_ident{ 244 | pub const TYPE_ORIGIN_ID: Address = Address::new([#(#addr_byte_ident),*]); 245 | } 246 | } 247 | } 248 | 249 | fn create_funs(funs: &BTreeMap) -> Vec { 250 | funs.iter() 251 | .flat_map(|(name, fun)| Self::create_fun(name.as_str(), fun)) 252 | .collect() 253 | } 254 | 255 | fn create_fun(fun_name: &str, fun: &Function) -> Option { 256 | let (param_names, mut params, need_lifetime) = fun.parameters 257 | .iter() 258 | .enumerate() 259 | .fold((vec![], vec![], false), |(mut param_names, mut params, mut lifetime), (i, move_type)| { 260 | let field_ident = Ident::new(&format!("p{i}"), proc_macro2::Span::call_site()); 261 | lifetime = lifetime || move_type.is_ref(); 262 | match &move_type { 263 | Type::Reference(r) | 264 | Type::MutableReference(r) => { 265 | // filter out TxContext 266 | if matches!(&**r, Type::Struct{address, name, ..} if address == &AccountAddress::TWO && name.as_str() == "TxContext") { 267 | return (param_names, params, lifetime); 268 | } 269 | } 270 | _ => {} 271 | } 272 | param_names.push(quote! {#field_ident}); 273 | let field_type: syn::Type = syn::parse_str(&move_type.to_arg_type()).unwrap(); 274 | params.push(quote! {#field_ident: #field_type}); 275 | (param_names, params, lifetime) 276 | }); 277 | params.insert( 278 | 0, 279 | quote! {builder: &mut sui_transaction_builder::TransactionBuilder}, 280 | ); 281 | 282 | let returns = fun 283 | .return_ 284 | .iter() 285 | .flat_map(|move_type| syn::parse_str::(&move_type.to_arg_type()).ok()) 286 | .collect::>(); 287 | 288 | let (types, mut types_with_ability) = fun.type_parameters.iter().enumerate().fold( 289 | (vec![], vec![]), 290 | |(mut types, mut types_with_ability), (i, v)| { 291 | let ident = Ident::new(&format!("T{i}"), proc_macro2::Span::call_site()); 292 | types.push(ident.clone()); 293 | let mut abilities = vec![]; 294 | if v.has_key() { 295 | abilities.push(quote! {move_types::Key}); 296 | } else { 297 | abilities.push(quote! {MoveType}); 298 | } 299 | types_with_ability.push(quote! {#ident: #(#abilities)+*}); 300 | (types, types_with_ability) 301 | }, 302 | ); 303 | 304 | if need_lifetime || fun.return_.iter().any(|t| t.is_ref()) { 305 | types_with_ability.insert(0, quote! {'a}) 306 | } 307 | 308 | let fun_ident = Ident::new(fun_name, proc_macro2::Span::call_site()); 309 | 310 | let (maybe_returns, maybe_into) = if let Some(t) = returns.first() { 311 | (quote! { -> #t}, quote! {.into()}) 312 | } else { 313 | (quote! {}, quote! {;}) 314 | }; 315 | 316 | let sig = if types_with_ability.is_empty() { 317 | quote! { 318 | pub fn #fun_ident(#(#params),*) #maybe_returns 319 | } 320 | } else { 321 | quote! { 322 | pub fn #fun_ident <#(#types_with_ability),*>(#(#params),*) #maybe_returns 323 | } 324 | }; 325 | 326 | let fun_impl = quote! { 327 | #sig { 328 | #(let #param_names = #param_names.resolve_arg(builder);)* 329 | builder.move_call( 330 | sui_transaction_builder::Function::new( 331 | PACKAGE_ID, 332 | Identifier::from_str(MODULE_NAME).unwrap(), 333 | Identifier::from_str(#fun_name).unwrap(), 334 | vec![#(#types::type_()),*], 335 | ), 336 | vec![#(#param_names.into()),*], 337 | ) 338 | #maybe_into 339 | } 340 | }; 341 | Some(fun_impl) 342 | } 343 | } 344 | 345 | fn escape_keyword(name: &str) -> String { 346 | match name { 347 | "for" | "ref" => { 348 | format!("{name}_") 349 | } 350 | _ => name.to_string(), 351 | } 352 | } 353 | -------------------------------------------------------------------------------- /move-binding/src/package_id_resolver.rs: -------------------------------------------------------------------------------- 1 | use crate::SuiNetwork; 2 | use serde_json::Value; 3 | use std::str::FromStr; 4 | use sui_sdk_types::Address; 5 | 6 | pub struct PackageIdResolver; 7 | 8 | impl PackageIdResolver { 9 | pub fn resolve_package_id( 10 | network: SuiNetwork, 11 | package: &str, 12 | ) -> Result { 13 | Ok(if package.contains("@") || package.contains(".sui") { 14 | Self::resolve_mvr_name(package, network.mvr_endpoint())? 15 | } else { 16 | Address::from_str(&package)? 17 | }) 18 | } 19 | 20 | fn resolve_mvr_name(package: &str, url: &str) -> Result { 21 | let client = reqwest::blocking::Client::new(); 22 | let name = client 23 | .get(format!("{url}/v1/resolution/{package}")) 24 | .send()?; 25 | Ok(serde_json::from_value( 26 | name.json::()?["package_id"].clone(), 27 | )?) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /move-binding/src/package_provider.rs: -------------------------------------------------------------------------------- 1 | use crate::package_id_resolver::PackageIdResolver; 2 | use crate::SuiNetwork; 3 | use fastcrypto::encoding::{Base64, Encoding}; 4 | use move_binary_format::normalized::Module; 5 | use move_binary_format::CompiledModule; 6 | use move_core_types::account_address::AccountAddress; 7 | use reqwest::header::CONTENT_TYPE; 8 | use serde_json::{json, Value}; 9 | use std::collections::{BTreeMap, HashMap}; 10 | use std::str::FromStr; 11 | 12 | pub trait ModuleProvider { 13 | fn get_package(&self, package_id: &str) -> Result; 14 | } 15 | 16 | pub struct MoveModuleProvider { 17 | network: SuiNetwork, 18 | } 19 | 20 | impl MoveModuleProvider { 21 | pub fn new(network: SuiNetwork) -> Self { 22 | Self { network } 23 | } 24 | } 25 | 26 | impl ModuleProvider for MoveModuleProvider { 27 | fn get_package(&self, package: &str) -> Result { 28 | let package_id = PackageIdResolver::resolve_package_id(self.network, package)?; 29 | let client = reqwest::blocking::Client::new(); 30 | let request = format!( 31 | r#"{{package(address: "{package_id}") {{moduleBcs, typeOrigins{{module, struct, definingId}}, version}}}}"# 32 | ); 33 | let res = client 34 | .post(self.network.gql()) 35 | .header(CONTENT_TYPE, "application/json") 36 | .json(&json!({ 37 | "query": request, 38 | "variables": Value::Null 39 | })) 40 | .send() 41 | .ok() 42 | .expect("Error fetching package from Sui GQL."); 43 | 44 | let value = res.json::().unwrap(); 45 | let module_bcs: String = 46 | serde_json::from_value(value["data"]["package"]["moduleBcs"].clone()).unwrap(); 47 | let module_bytes = Base64::decode(&module_bcs).unwrap(); 48 | let module_map: BTreeMap> = bcs::from_bytes(&module_bytes).unwrap(); 49 | 50 | let module_map = module_map 51 | .iter() 52 | .map(|(name, bytes)| { 53 | let module = CompiledModule::deserialize_with_defaults(bytes)?; 54 | let normalized = Module::new(&module); 55 | Ok::<_, anyhow::Error>((name.clone(), normalized)) 56 | }) 57 | .collect::>()?; 58 | 59 | let type_origin_table: Vec = 60 | serde_json::from_value(value["data"]["package"]["typeOrigins"].clone())?; 61 | 62 | let type_origin_table = type_origin_table.iter().fold( 63 | HashMap::new(), 64 | |mut results: HashMap>, v| { 65 | let module = v["module"].as_str().unwrap(); 66 | let struct_ = v["struct"].as_str().unwrap(); 67 | let defining_id = v["definingId"].as_str().unwrap(); 68 | results.entry(module.to_string()).or_default().insert( 69 | struct_.to_string(), 70 | AccountAddress::from_str(defining_id).unwrap(), 71 | ); 72 | results 73 | }, 74 | ); 75 | 76 | let version = serde_json::from_value(value["data"]["package"]["version"].clone())?; 77 | 78 | Ok(Package { 79 | module_map, 80 | type_origin_table, 81 | version, 82 | }) 83 | } 84 | } 85 | 86 | pub struct Package { 87 | pub module_map: BTreeMap, 88 | pub type_origin_table: HashMap>, 89 | pub version: u64, 90 | } 91 | -------------------------------------------------------------------------------- /move-binding/src/types.rs: -------------------------------------------------------------------------------- 1 | use crate::move_codegen::BINDING_REGISTRY; 2 | use itertools::Itertools; 3 | use move_binary_format::normalized::Type; 4 | use move_core_types::account_address::AccountAddress; 5 | 6 | pub trait ToRustType { 7 | fn to_rust_type(&self) -> String; 8 | fn is_ref(&self) -> bool; 9 | fn to_arg_type(&self) -> String; 10 | } 11 | 12 | impl ToRustType for Type { 13 | fn to_rust_type(&self) -> String { 14 | match self { 15 | Self::Bool => "bool".to_string(), 16 | Self::U8 => "u8".to_string(), 17 | Self::U16 => "u16".to_string(), 18 | Self::U32 => "u32".to_string(), 19 | Self::U64 => "u64".to_string(), 20 | Self::U128 => "u128".to_string(), 21 | Self::U256 => "move_types::U256".to_string(), 22 | Self::Address => "Address".to_string(), 23 | Self::Signer => "Address".to_string(), 24 | t @ Self::Struct { .. } => try_resolve_known_types(t), 25 | Self::Vector(t) => { 26 | format!("Vec<{}>", t.to_rust_type()) 27 | } 28 | Self::Reference(t) => { 29 | format!("&'static {}", t.to_rust_type()) 30 | } 31 | Self::MutableReference(t) => { 32 | format!("&'static mut {}", t.to_rust_type()) 33 | } 34 | Self::TypeParameter(index) => format!("T{index}"), 35 | } 36 | } 37 | 38 | fn is_ref(&self) -> bool { 39 | match self { 40 | Self::Reference(_) | Self::MutableReference(_) => true, 41 | _ => false, 42 | } 43 | } 44 | 45 | fn to_arg_type(&self) -> String { 46 | match self { 47 | Self::Reference(t) => { 48 | format!("Ref<'a, {}>", t.to_rust_type()) 49 | } 50 | Self::MutableReference(t) => { 51 | format!("MutRef<'a, {}>", t.to_rust_type()) 52 | } 53 | _ => format!("Arg<{}>", self.to_rust_type()), 54 | } 55 | } 56 | } 57 | 58 | fn try_resolve_known_types(_type: &Type) -> String { 59 | if let Type::Struct { 60 | address, 61 | module, 62 | name, 63 | type_arguments, 64 | } = _type 65 | { 66 | match (address, module.as_str(), name.as_str()) { 67 | (&AccountAddress::ONE, "type_name", "TypeName") => "String".to_string(), 68 | (&AccountAddress::ONE, "string", "String") => "String".to_string(), 69 | (&AccountAddress::ONE, "ascii", "String") => "String".to_string(), 70 | (&AccountAddress::ONE, "option", "Option") => { 71 | format!("Option<{}>", type_arguments[0].to_rust_type()) 72 | } 73 | 74 | (&AccountAddress::TWO, "object", "UID") => "ObjectId".to_string(), 75 | (&AccountAddress::TWO, "object", "ID") => "ObjectId".to_string(), 76 | _ => { 77 | let cache = BINDING_REGISTRY.read().unwrap(); 78 | 79 | let package_path = cache.get(address).cloned(); 80 | drop(cache); // Release read lock 81 | 82 | let type_ = if let Some(package_path) = package_path{ 83 | format!("{package_path}::{module}::{name}") 84 | }else{ 85 | format!("{module}::{name}") 86 | }; 87 | 88 | if type_arguments.is_empty() { 89 | type_ 90 | } else { 91 | format!( 92 | "{type_}<{}>", 93 | type_arguments.iter().map(|ty| ty.to_rust_type()).join(", ") 94 | ) 95 | } 96 | } 97 | } 98 | } else { 99 | unreachable!() 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /move-binding/tests/snapshot_tests.rs: -------------------------------------------------------------------------------- 1 | use insta::assert_snapshot; 2 | use move_binding::move_codegen::MoveCodegen; 3 | use move_binding::SuiNetwork; 4 | use syn::parse2; 5 | 6 | #[test] 7 | fn test_generate_sui_packages() { 8 | test_package(SuiNetwork::Mainnet, "0x1", "move_lib"); 9 | test_package(SuiNetwork::Mainnet, "0x2", "sui"); 10 | test_package(SuiNetwork::Mainnet, "0x3", "sui_system"); 11 | test_package(SuiNetwork::Mainnet, "0xb", "bridge"); 12 | test_package( 13 | SuiNetwork::Testnet, 14 | "0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a", 15 | "wal", 16 | ); 17 | test_package( 18 | SuiNetwork::Testnet, 19 | "0xd84704c17fc870b8764832c535aa6b11f21a95cd6f5bb38a9b07d2cf42220c66", 20 | "walrus", 21 | ); 22 | } 23 | 24 | fn test_package(network: SuiNetwork, package: &str, alias: &str) { 25 | let ts = MoveCodegen::expand(network, package, alias, "crate").unwrap(); 26 | let file = parse2::(ts.clone()).expect("Failed to parse TokenStream"); 27 | let pretty = prettyplease::unparse(&file); 28 | assert_snapshot!(package, pretty) 29 | } 30 | -------------------------------------------------------------------------------- /move-binding/tests/snapshots/snapshot_tests__0x8270feb7375eee355e64fdb69c50abb6b5f9393a722883c1cf45f8e26048810a.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: move-binding/tests/snapshot_tests.rs 3 | expression: pretty 4 | --- 5 | pub mod wal { 6 | pub const PACKAGE_VERSION: u64 = 1u64; 7 | pub mod wal { 8 | use std::str::FromStr; 9 | use move_binding_derive::{MoveStruct, Key}; 10 | use move_types::{MoveType, Address, Identifier, ObjectId}; 11 | use move_types::functions::{Arg, Ref, MutRef}; 12 | pub const PACKAGE_ID: Address = Address::new([ 13 | 130u8, 112u8, 254u8, 183u8, 55u8, 94u8, 238u8, 53u8, 94u8, 100u8, 253u8, 14 | 182u8, 156u8, 80u8, 171u8, 182u8, 181u8, 249u8, 57u8, 58u8, 114u8, 40u8, 15 | 131u8, 193u8, 207u8, 69u8, 248u8, 226u8, 96u8, 72u8, 129u8, 10u8, 16 | ]); 17 | pub const MODULE_NAME: &str = "wal"; 18 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct, Key)] 19 | pub struct ProtectedTreasury { 20 | pub id: ObjectId, 21 | } 22 | impl ProtectedTreasury { 23 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 24 | 130u8, 112u8, 254u8, 183u8, 55u8, 94u8, 238u8, 53u8, 94u8, 100u8, 253u8, 25 | 182u8, 156u8, 80u8, 171u8, 182u8, 181u8, 249u8, 57u8, 58u8, 114u8, 40u8, 26 | 131u8, 193u8, 207u8, 69u8, 248u8, 226u8, 96u8, 72u8, 129u8, 10u8, 27 | ]); 28 | } 29 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 30 | pub struct TreasuryCapKey { 31 | pub dummy_field: bool, 32 | } 33 | impl TreasuryCapKey { 34 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 35 | 130u8, 112u8, 254u8, 183u8, 55u8, 94u8, 238u8, 53u8, 94u8, 100u8, 253u8, 36 | 182u8, 156u8, 80u8, 171u8, 182u8, 181u8, 249u8, 57u8, 58u8, 114u8, 40u8, 37 | 131u8, 193u8, 207u8, 69u8, 248u8, 226u8, 96u8, 72u8, 129u8, 10u8, 38 | ]); 39 | } 40 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 41 | pub struct WAL { 42 | pub dummy_field: bool, 43 | } 44 | impl WAL { 45 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 46 | 130u8, 112u8, 254u8, 183u8, 55u8, 94u8, 238u8, 53u8, 94u8, 100u8, 253u8, 47 | 182u8, 156u8, 80u8, 171u8, 182u8, 181u8, 249u8, 57u8, 58u8, 114u8, 40u8, 48 | 131u8, 193u8, 207u8, 69u8, 248u8, 226u8, 96u8, 72u8, 129u8, 10u8, 49 | ]); 50 | } 51 | pub fn borrow_cap<'a>( 52 | builder: &mut sui_transaction_builder::TransactionBuilder, 53 | p0: Ref<'a, crate::wal::wal::ProtectedTreasury>, 54 | ) -> Ref<'a, crate::sui::coin::TreasuryCap> { 55 | let p0 = p0.resolve_arg(builder); 56 | builder 57 | .move_call( 58 | sui_transaction_builder::Function::new( 59 | PACKAGE_ID, 60 | Identifier::from_str(MODULE_NAME).unwrap(), 61 | Identifier::from_str("borrow_cap").unwrap(), 62 | vec![], 63 | ), 64 | vec![p0.into()], 65 | ) 66 | .into() 67 | } 68 | pub fn borrow_cap_mut<'a>( 69 | builder: &mut sui_transaction_builder::TransactionBuilder, 70 | p0: MutRef<'a, crate::wal::wal::ProtectedTreasury>, 71 | ) -> MutRef<'a, crate::sui::coin::TreasuryCap> { 72 | let p0 = p0.resolve_arg(builder); 73 | builder 74 | .move_call( 75 | sui_transaction_builder::Function::new( 76 | PACKAGE_ID, 77 | Identifier::from_str(MODULE_NAME).unwrap(), 78 | Identifier::from_str("borrow_cap_mut").unwrap(), 79 | vec![], 80 | ), 81 | vec![p0.into()], 82 | ) 83 | .into() 84 | } 85 | pub fn burn<'a>( 86 | builder: &mut sui_transaction_builder::TransactionBuilder, 87 | p0: MutRef<'a, crate::wal::wal::ProtectedTreasury>, 88 | p1: Arg>, 89 | ) { 90 | let p0 = p0.resolve_arg(builder); 91 | let p1 = p1.resolve_arg(builder); 92 | builder 93 | .move_call( 94 | sui_transaction_builder::Function::new( 95 | PACKAGE_ID, 96 | Identifier::from_str(MODULE_NAME).unwrap(), 97 | Identifier::from_str("burn").unwrap(), 98 | vec![], 99 | ), 100 | vec![p0.into(), p1.into()], 101 | ); 102 | } 103 | pub fn init<'a>( 104 | builder: &mut sui_transaction_builder::TransactionBuilder, 105 | p0: Arg, 106 | ) { 107 | let p0 = p0.resolve_arg(builder); 108 | builder 109 | .move_call( 110 | sui_transaction_builder::Function::new( 111 | PACKAGE_ID, 112 | Identifier::from_str(MODULE_NAME).unwrap(), 113 | Identifier::from_str("init").unwrap(), 114 | vec![], 115 | ), 116 | vec![p0.into()], 117 | ); 118 | } 119 | pub fn total_supply<'a>( 120 | builder: &mut sui_transaction_builder::TransactionBuilder, 121 | p0: Ref<'a, crate::wal::wal::ProtectedTreasury>, 122 | ) -> Arg { 123 | let p0 = p0.resolve_arg(builder); 124 | builder 125 | .move_call( 126 | sui_transaction_builder::Function::new( 127 | PACKAGE_ID, 128 | Identifier::from_str(MODULE_NAME).unwrap(), 129 | Identifier::from_str("total_supply").unwrap(), 130 | vec![], 131 | ), 132 | vec![p0.into()], 133 | ) 134 | .into() 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /move-binding/tests/snapshots/snapshot_tests__0xb.snap: -------------------------------------------------------------------------------- 1 | --- 2 | source: move-binding/tests/snapshot_tests.rs 3 | expression: pretty 4 | --- 5 | pub mod bridge { 6 | pub const PACKAGE_VERSION: u64 = 5u64; 7 | pub mod bridge { 8 | use std::str::FromStr; 9 | use move_binding_derive::{MoveStruct, Key}; 10 | use move_types::{MoveType, Address, Identifier, ObjectId}; 11 | use move_types::functions::{Arg, Ref, MutRef}; 12 | pub const PACKAGE_ID: Address = Address::new([ 13 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 14 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 15 | 0u8, 11u8, 16 | ]); 17 | pub const MODULE_NAME: &str = "bridge"; 18 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct, Key)] 19 | pub struct Bridge { 20 | pub id: ObjectId, 21 | pub inner: crate::sui::versioned::Versioned, 22 | } 23 | impl Bridge { 24 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 25 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 26 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 27 | 0u8, 0u8, 0u8, 11u8, 28 | ]); 29 | } 30 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 31 | pub struct BridgeInner { 32 | pub bridge_version: u64, 33 | pub message_version: u8, 34 | pub chain_id: u8, 35 | pub sequence_nums: crate::sui::vec_map::VecMap, 36 | pub committee: crate::bridge::committee::BridgeCommittee, 37 | pub treasury: crate::bridge::treasury::BridgeTreasury, 38 | pub token_transfer_records: crate::sui::linked_table::LinkedTable< 39 | crate::bridge::message::BridgeMessageKey, 40 | crate::bridge::bridge::BridgeRecord, 41 | >, 42 | pub limiter: crate::bridge::limiter::TransferLimiter, 43 | pub paused: bool, 44 | } 45 | impl BridgeInner { 46 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 47 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 48 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 49 | 0u8, 0u8, 0u8, 11u8, 50 | ]); 51 | } 52 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 53 | pub struct BridgeRecord { 54 | pub message: crate::bridge::message::BridgeMessage, 55 | pub verified_signatures: Option>>, 56 | pub claimed: bool, 57 | } 58 | impl BridgeRecord { 59 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 60 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 61 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 62 | 0u8, 0u8, 0u8, 11u8, 63 | ]); 64 | } 65 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 66 | pub struct EmergencyOpEvent { 67 | pub frozen: bool, 68 | } 69 | impl EmergencyOpEvent { 70 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 71 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 72 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 73 | 0u8, 0u8, 0u8, 11u8, 74 | ]); 75 | } 76 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 77 | pub struct TokenDepositedEvent { 78 | pub seq_num: u64, 79 | pub source_chain: u8, 80 | pub sender_address: Vec, 81 | pub target_chain: u8, 82 | pub target_address: Vec, 83 | pub token_type: u8, 84 | pub amount: u64, 85 | } 86 | impl TokenDepositedEvent { 87 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 88 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 89 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 90 | 0u8, 0u8, 0u8, 11u8, 91 | ]); 92 | } 93 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 94 | pub struct TokenTransferAlreadyApproved { 95 | pub message_key: crate::bridge::message::BridgeMessageKey, 96 | } 97 | impl TokenTransferAlreadyApproved { 98 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 99 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 100 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 101 | 0u8, 0u8, 0u8, 11u8, 102 | ]); 103 | } 104 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 105 | pub struct TokenTransferAlreadyClaimed { 106 | pub message_key: crate::bridge::message::BridgeMessageKey, 107 | } 108 | impl TokenTransferAlreadyClaimed { 109 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 110 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 111 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 112 | 0u8, 0u8, 0u8, 11u8, 113 | ]); 114 | } 115 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 116 | pub struct TokenTransferApproved { 117 | pub message_key: crate::bridge::message::BridgeMessageKey, 118 | } 119 | impl TokenTransferApproved { 120 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 121 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 122 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 123 | 0u8, 0u8, 0u8, 11u8, 124 | ]); 125 | } 126 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 127 | pub struct TokenTransferClaimed { 128 | pub message_key: crate::bridge::message::BridgeMessageKey, 129 | } 130 | impl TokenTransferClaimed { 131 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 132 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 133 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 134 | 0u8, 0u8, 0u8, 11u8, 135 | ]); 136 | } 137 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 138 | pub struct TokenTransferLimitExceed { 139 | pub message_key: crate::bridge::message::BridgeMessageKey, 140 | } 141 | impl TokenTransferLimitExceed { 142 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 143 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 144 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 145 | 0u8, 0u8, 0u8, 11u8, 146 | ]); 147 | } 148 | pub fn approve_token_transfer<'a>( 149 | builder: &mut sui_transaction_builder::TransactionBuilder, 150 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 151 | p1: Arg, 152 | p2: Arg>>, 153 | ) { 154 | let p0 = p0.resolve_arg(builder); 155 | let p1 = p1.resolve_arg(builder); 156 | let p2 = p2.resolve_arg(builder); 157 | builder 158 | .move_call( 159 | sui_transaction_builder::Function::new( 160 | PACKAGE_ID, 161 | Identifier::from_str(MODULE_NAME).unwrap(), 162 | Identifier::from_str("approve_token_transfer").unwrap(), 163 | vec![], 164 | ), 165 | vec![p0.into(), p1.into(), p2.into()], 166 | ); 167 | } 168 | pub fn claim_and_transfer_token<'a, T0: MoveType>( 169 | builder: &mut sui_transaction_builder::TransactionBuilder, 170 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 171 | p1: Ref<'a, crate::sui::clock::Clock>, 172 | p2: Arg, 173 | p3: Arg, 174 | ) { 175 | let p0 = p0.resolve_arg(builder); 176 | let p1 = p1.resolve_arg(builder); 177 | let p2 = p2.resolve_arg(builder); 178 | let p3 = p3.resolve_arg(builder); 179 | builder 180 | .move_call( 181 | sui_transaction_builder::Function::new( 182 | PACKAGE_ID, 183 | Identifier::from_str(MODULE_NAME).unwrap(), 184 | Identifier::from_str("claim_and_transfer_token").unwrap(), 185 | vec![T0::type_()], 186 | ), 187 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 188 | ); 189 | } 190 | pub fn claim_token<'a, T0: MoveType>( 191 | builder: &mut sui_transaction_builder::TransactionBuilder, 192 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 193 | p1: Ref<'a, crate::sui::clock::Clock>, 194 | p2: Arg, 195 | p3: Arg, 196 | ) -> Arg> { 197 | let p0 = p0.resolve_arg(builder); 198 | let p1 = p1.resolve_arg(builder); 199 | let p2 = p2.resolve_arg(builder); 200 | let p3 = p3.resolve_arg(builder); 201 | builder 202 | .move_call( 203 | sui_transaction_builder::Function::new( 204 | PACKAGE_ID, 205 | Identifier::from_str(MODULE_NAME).unwrap(), 206 | Identifier::from_str("claim_token").unwrap(), 207 | vec![T0::type_()], 208 | ), 209 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 210 | ) 211 | .into() 212 | } 213 | pub fn claim_token_internal<'a, T0: MoveType>( 214 | builder: &mut sui_transaction_builder::TransactionBuilder, 215 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 216 | p1: Ref<'a, crate::sui::clock::Clock>, 217 | p2: Arg, 218 | p3: Arg, 219 | ) -> Arg>> { 220 | let p0 = p0.resolve_arg(builder); 221 | let p1 = p1.resolve_arg(builder); 222 | let p2 = p2.resolve_arg(builder); 223 | let p3 = p3.resolve_arg(builder); 224 | builder 225 | .move_call( 226 | sui_transaction_builder::Function::new( 227 | PACKAGE_ID, 228 | Identifier::from_str(MODULE_NAME).unwrap(), 229 | Identifier::from_str("claim_token_internal").unwrap(), 230 | vec![T0::type_()], 231 | ), 232 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 233 | ) 234 | .into() 235 | } 236 | pub fn committee_registration<'a>( 237 | builder: &mut sui_transaction_builder::TransactionBuilder, 238 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 239 | p1: MutRef<'a, crate::sui_system::sui_system::SuiSystemState>, 240 | p2: Arg>, 241 | p3: Arg>, 242 | ) { 243 | let p0 = p0.resolve_arg(builder); 244 | let p1 = p1.resolve_arg(builder); 245 | let p2 = p2.resolve_arg(builder); 246 | let p3 = p3.resolve_arg(builder); 247 | builder 248 | .move_call( 249 | sui_transaction_builder::Function::new( 250 | PACKAGE_ID, 251 | Identifier::from_str(MODULE_NAME).unwrap(), 252 | Identifier::from_str("committee_registration").unwrap(), 253 | vec![], 254 | ), 255 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 256 | ); 257 | } 258 | pub fn create<'a>( 259 | builder: &mut sui_transaction_builder::TransactionBuilder, 260 | p0: Arg, 261 | p1: Arg, 262 | ) { 263 | let p0 = p0.resolve_arg(builder); 264 | let p1 = p1.resolve_arg(builder); 265 | builder 266 | .move_call( 267 | sui_transaction_builder::Function::new( 268 | PACKAGE_ID, 269 | Identifier::from_str(MODULE_NAME).unwrap(), 270 | Identifier::from_str("create").unwrap(), 271 | vec![], 272 | ), 273 | vec![p0.into(), p1.into()], 274 | ); 275 | } 276 | pub fn execute_add_tokens_on_sui<'a>( 277 | builder: &mut sui_transaction_builder::TransactionBuilder, 278 | p0: MutRef<'a, crate::bridge::bridge::BridgeInner>, 279 | p1: Arg, 280 | ) { 281 | let p0 = p0.resolve_arg(builder); 282 | let p1 = p1.resolve_arg(builder); 283 | builder 284 | .move_call( 285 | sui_transaction_builder::Function::new( 286 | PACKAGE_ID, 287 | Identifier::from_str(MODULE_NAME).unwrap(), 288 | Identifier::from_str("execute_add_tokens_on_sui").unwrap(), 289 | vec![], 290 | ), 291 | vec![p0.into(), p1.into()], 292 | ); 293 | } 294 | pub fn execute_emergency_op<'a>( 295 | builder: &mut sui_transaction_builder::TransactionBuilder, 296 | p0: MutRef<'a, crate::bridge::bridge::BridgeInner>, 297 | p1: Arg, 298 | ) { 299 | let p0 = p0.resolve_arg(builder); 300 | let p1 = p1.resolve_arg(builder); 301 | builder 302 | .move_call( 303 | sui_transaction_builder::Function::new( 304 | PACKAGE_ID, 305 | Identifier::from_str(MODULE_NAME).unwrap(), 306 | Identifier::from_str("execute_emergency_op").unwrap(), 307 | vec![], 308 | ), 309 | vec![p0.into(), p1.into()], 310 | ); 311 | } 312 | pub fn execute_system_message<'a>( 313 | builder: &mut sui_transaction_builder::TransactionBuilder, 314 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 315 | p1: Arg, 316 | p2: Arg>>, 317 | ) { 318 | let p0 = p0.resolve_arg(builder); 319 | let p1 = p1.resolve_arg(builder); 320 | let p2 = p2.resolve_arg(builder); 321 | builder 322 | .move_call( 323 | sui_transaction_builder::Function::new( 324 | PACKAGE_ID, 325 | Identifier::from_str(MODULE_NAME).unwrap(), 326 | Identifier::from_str("execute_system_message").unwrap(), 327 | vec![], 328 | ), 329 | vec![p0.into(), p1.into(), p2.into()], 330 | ); 331 | } 332 | pub fn execute_update_asset_price<'a>( 333 | builder: &mut sui_transaction_builder::TransactionBuilder, 334 | p0: MutRef<'a, crate::bridge::bridge::BridgeInner>, 335 | p1: Arg, 336 | ) { 337 | let p0 = p0.resolve_arg(builder); 338 | let p1 = p1.resolve_arg(builder); 339 | builder 340 | .move_call( 341 | sui_transaction_builder::Function::new( 342 | PACKAGE_ID, 343 | Identifier::from_str(MODULE_NAME).unwrap(), 344 | Identifier::from_str("execute_update_asset_price").unwrap(), 345 | vec![], 346 | ), 347 | vec![p0.into(), p1.into()], 348 | ); 349 | } 350 | pub fn execute_update_bridge_limit<'a>( 351 | builder: &mut sui_transaction_builder::TransactionBuilder, 352 | p0: MutRef<'a, crate::bridge::bridge::BridgeInner>, 353 | p1: Arg, 354 | ) { 355 | let p0 = p0.resolve_arg(builder); 356 | let p1 = p1.resolve_arg(builder); 357 | builder 358 | .move_call( 359 | sui_transaction_builder::Function::new( 360 | PACKAGE_ID, 361 | Identifier::from_str(MODULE_NAME).unwrap(), 362 | Identifier::from_str("execute_update_bridge_limit").unwrap(), 363 | vec![], 364 | ), 365 | vec![p0.into(), p1.into()], 366 | ); 367 | } 368 | pub fn get_current_seq_num_and_increment<'a>( 369 | builder: &mut sui_transaction_builder::TransactionBuilder, 370 | p0: MutRef<'a, crate::bridge::bridge::BridgeInner>, 371 | p1: Arg, 372 | ) -> Arg { 373 | let p0 = p0.resolve_arg(builder); 374 | let p1 = p1.resolve_arg(builder); 375 | builder 376 | .move_call( 377 | sui_transaction_builder::Function::new( 378 | PACKAGE_ID, 379 | Identifier::from_str(MODULE_NAME).unwrap(), 380 | Identifier::from_str("get_current_seq_num_and_increment") 381 | .unwrap(), 382 | vec![], 383 | ), 384 | vec![p0.into(), p1.into()], 385 | ) 386 | .into() 387 | } 388 | pub fn get_parsed_token_transfer_message<'a>( 389 | builder: &mut sui_transaction_builder::TransactionBuilder, 390 | p0: Ref<'a, crate::bridge::bridge::Bridge>, 391 | p1: Arg, 392 | p2: Arg, 393 | ) -> Arg> { 394 | let p0 = p0.resolve_arg(builder); 395 | let p1 = p1.resolve_arg(builder); 396 | let p2 = p2.resolve_arg(builder); 397 | builder 398 | .move_call( 399 | sui_transaction_builder::Function::new( 400 | PACKAGE_ID, 401 | Identifier::from_str(MODULE_NAME).unwrap(), 402 | Identifier::from_str("get_parsed_token_transfer_message") 403 | .unwrap(), 404 | vec![], 405 | ), 406 | vec![p0.into(), p1.into(), p2.into()], 407 | ) 408 | .into() 409 | } 410 | pub fn get_token_transfer_action_signatures<'a>( 411 | builder: &mut sui_transaction_builder::TransactionBuilder, 412 | p0: Ref<'a, crate::bridge::bridge::Bridge>, 413 | p1: Arg, 414 | p2: Arg, 415 | ) -> Arg>>> { 416 | let p0 = p0.resolve_arg(builder); 417 | let p1 = p1.resolve_arg(builder); 418 | let p2 = p2.resolve_arg(builder); 419 | builder 420 | .move_call( 421 | sui_transaction_builder::Function::new( 422 | PACKAGE_ID, 423 | Identifier::from_str(MODULE_NAME).unwrap(), 424 | Identifier::from_str("get_token_transfer_action_signatures") 425 | .unwrap(), 426 | vec![], 427 | ), 428 | vec![p0.into(), p1.into(), p2.into()], 429 | ) 430 | .into() 431 | } 432 | pub fn get_token_transfer_action_status<'a>( 433 | builder: &mut sui_transaction_builder::TransactionBuilder, 434 | p0: Ref<'a, crate::bridge::bridge::Bridge>, 435 | p1: Arg, 436 | p2: Arg, 437 | ) -> Arg { 438 | let p0 = p0.resolve_arg(builder); 439 | let p1 = p1.resolve_arg(builder); 440 | let p2 = p2.resolve_arg(builder); 441 | builder 442 | .move_call( 443 | sui_transaction_builder::Function::new( 444 | PACKAGE_ID, 445 | Identifier::from_str(MODULE_NAME).unwrap(), 446 | Identifier::from_str("get_token_transfer_action_status") 447 | .unwrap(), 448 | vec![], 449 | ), 450 | vec![p0.into(), p1.into(), p2.into()], 451 | ) 452 | .into() 453 | } 454 | pub fn init_bridge_committee<'a>( 455 | builder: &mut sui_transaction_builder::TransactionBuilder, 456 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 457 | p1: Arg>, 458 | p2: Arg, 459 | ) { 460 | let p0 = p0.resolve_arg(builder); 461 | let p1 = p1.resolve_arg(builder); 462 | let p2 = p2.resolve_arg(builder); 463 | builder 464 | .move_call( 465 | sui_transaction_builder::Function::new( 466 | PACKAGE_ID, 467 | Identifier::from_str(MODULE_NAME).unwrap(), 468 | Identifier::from_str("init_bridge_committee").unwrap(), 469 | vec![], 470 | ), 471 | vec![p0.into(), p1.into(), p2.into()], 472 | ); 473 | } 474 | pub fn load_inner<'a>( 475 | builder: &mut sui_transaction_builder::TransactionBuilder, 476 | p0: Ref<'a, crate::bridge::bridge::Bridge>, 477 | ) -> Ref<'a, crate::bridge::bridge::BridgeInner> { 478 | let p0 = p0.resolve_arg(builder); 479 | builder 480 | .move_call( 481 | sui_transaction_builder::Function::new( 482 | PACKAGE_ID, 483 | Identifier::from_str(MODULE_NAME).unwrap(), 484 | Identifier::from_str("load_inner").unwrap(), 485 | vec![], 486 | ), 487 | vec![p0.into()], 488 | ) 489 | .into() 490 | } 491 | pub fn load_inner_mut<'a>( 492 | builder: &mut sui_transaction_builder::TransactionBuilder, 493 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 494 | ) -> MutRef<'a, crate::bridge::bridge::BridgeInner> { 495 | let p0 = p0.resolve_arg(builder); 496 | builder 497 | .move_call( 498 | sui_transaction_builder::Function::new( 499 | PACKAGE_ID, 500 | Identifier::from_str(MODULE_NAME).unwrap(), 501 | Identifier::from_str("load_inner_mut").unwrap(), 502 | vec![], 503 | ), 504 | vec![p0.into()], 505 | ) 506 | .into() 507 | } 508 | pub fn register_foreign_token<'a, T0: MoveType>( 509 | builder: &mut sui_transaction_builder::TransactionBuilder, 510 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 511 | p1: Arg>, 512 | p2: Arg, 513 | p3: Ref<'a, crate::sui::coin::CoinMetadata>, 514 | ) { 515 | let p0 = p0.resolve_arg(builder); 516 | let p1 = p1.resolve_arg(builder); 517 | let p2 = p2.resolve_arg(builder); 518 | let p3 = p3.resolve_arg(builder); 519 | builder 520 | .move_call( 521 | sui_transaction_builder::Function::new( 522 | PACKAGE_ID, 523 | Identifier::from_str(MODULE_NAME).unwrap(), 524 | Identifier::from_str("register_foreign_token").unwrap(), 525 | vec![T0::type_()], 526 | ), 527 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 528 | ); 529 | } 530 | pub fn send_token<'a, T0: MoveType>( 531 | builder: &mut sui_transaction_builder::TransactionBuilder, 532 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 533 | p1: Arg, 534 | p2: Arg>, 535 | p3: Arg>, 536 | ) { 537 | let p0 = p0.resolve_arg(builder); 538 | let p1 = p1.resolve_arg(builder); 539 | let p2 = p2.resolve_arg(builder); 540 | let p3 = p3.resolve_arg(builder); 541 | builder 542 | .move_call( 543 | sui_transaction_builder::Function::new( 544 | PACKAGE_ID, 545 | Identifier::from_str(MODULE_NAME).unwrap(), 546 | Identifier::from_str("send_token").unwrap(), 547 | vec![T0::type_()], 548 | ), 549 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 550 | ); 551 | } 552 | pub fn update_node_url<'a>( 553 | builder: &mut sui_transaction_builder::TransactionBuilder, 554 | p0: MutRef<'a, crate::bridge::bridge::Bridge>, 555 | p1: Arg>, 556 | ) { 557 | let p0 = p0.resolve_arg(builder); 558 | let p1 = p1.resolve_arg(builder); 559 | builder 560 | .move_call( 561 | sui_transaction_builder::Function::new( 562 | PACKAGE_ID, 563 | Identifier::from_str(MODULE_NAME).unwrap(), 564 | Identifier::from_str("update_node_url").unwrap(), 565 | vec![], 566 | ), 567 | vec![p0.into(), p1.into()], 568 | ); 569 | } 570 | } 571 | pub mod chain_ids { 572 | use std::str::FromStr; 573 | use move_binding_derive::{MoveStruct, Key}; 574 | use move_types::{MoveType, Address, Identifier, ObjectId}; 575 | use move_types::functions::{Arg, Ref, MutRef}; 576 | pub const PACKAGE_ID: Address = Address::new([ 577 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 578 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 579 | 0u8, 11u8, 580 | ]); 581 | pub const MODULE_NAME: &str = "chain_ids"; 582 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 583 | pub struct BridgeRoute { 584 | pub source: u8, 585 | pub destination: u8, 586 | } 587 | impl BridgeRoute { 588 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 589 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 590 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 591 | 0u8, 0u8, 0u8, 11u8, 592 | ]); 593 | } 594 | pub fn assert_valid_chain_id( 595 | builder: &mut sui_transaction_builder::TransactionBuilder, 596 | p0: Arg, 597 | ) { 598 | let p0 = p0.resolve_arg(builder); 599 | builder 600 | .move_call( 601 | sui_transaction_builder::Function::new( 602 | PACKAGE_ID, 603 | Identifier::from_str(MODULE_NAME).unwrap(), 604 | Identifier::from_str("assert_valid_chain_id").unwrap(), 605 | vec![], 606 | ), 607 | vec![p0.into()], 608 | ); 609 | } 610 | pub fn eth_custom( 611 | builder: &mut sui_transaction_builder::TransactionBuilder, 612 | ) -> Arg { 613 | builder 614 | .move_call( 615 | sui_transaction_builder::Function::new( 616 | PACKAGE_ID, 617 | Identifier::from_str(MODULE_NAME).unwrap(), 618 | Identifier::from_str("eth_custom").unwrap(), 619 | vec![], 620 | ), 621 | vec![], 622 | ) 623 | .into() 624 | } 625 | pub fn eth_mainnet( 626 | builder: &mut sui_transaction_builder::TransactionBuilder, 627 | ) -> Arg { 628 | builder 629 | .move_call( 630 | sui_transaction_builder::Function::new( 631 | PACKAGE_ID, 632 | Identifier::from_str(MODULE_NAME).unwrap(), 633 | Identifier::from_str("eth_mainnet").unwrap(), 634 | vec![], 635 | ), 636 | vec![], 637 | ) 638 | .into() 639 | } 640 | pub fn eth_sepolia( 641 | builder: &mut sui_transaction_builder::TransactionBuilder, 642 | ) -> Arg { 643 | builder 644 | .move_call( 645 | sui_transaction_builder::Function::new( 646 | PACKAGE_ID, 647 | Identifier::from_str(MODULE_NAME).unwrap(), 648 | Identifier::from_str("eth_sepolia").unwrap(), 649 | vec![], 650 | ), 651 | vec![], 652 | ) 653 | .into() 654 | } 655 | pub fn get_route( 656 | builder: &mut sui_transaction_builder::TransactionBuilder, 657 | p0: Arg, 658 | p1: Arg, 659 | ) -> Arg { 660 | let p0 = p0.resolve_arg(builder); 661 | let p1 = p1.resolve_arg(builder); 662 | builder 663 | .move_call( 664 | sui_transaction_builder::Function::new( 665 | PACKAGE_ID, 666 | Identifier::from_str(MODULE_NAME).unwrap(), 667 | Identifier::from_str("get_route").unwrap(), 668 | vec![], 669 | ), 670 | vec![p0.into(), p1.into()], 671 | ) 672 | .into() 673 | } 674 | pub fn is_valid_route( 675 | builder: &mut sui_transaction_builder::TransactionBuilder, 676 | p0: Arg, 677 | p1: Arg, 678 | ) -> Arg { 679 | let p0 = p0.resolve_arg(builder); 680 | let p1 = p1.resolve_arg(builder); 681 | builder 682 | .move_call( 683 | sui_transaction_builder::Function::new( 684 | PACKAGE_ID, 685 | Identifier::from_str(MODULE_NAME).unwrap(), 686 | Identifier::from_str("is_valid_route").unwrap(), 687 | vec![], 688 | ), 689 | vec![p0.into(), p1.into()], 690 | ) 691 | .into() 692 | } 693 | pub fn route_destination<'a>( 694 | builder: &mut sui_transaction_builder::TransactionBuilder, 695 | p0: Ref<'a, crate::bridge::chain_ids::BridgeRoute>, 696 | ) -> Ref<'a, u8> { 697 | let p0 = p0.resolve_arg(builder); 698 | builder 699 | .move_call( 700 | sui_transaction_builder::Function::new( 701 | PACKAGE_ID, 702 | Identifier::from_str(MODULE_NAME).unwrap(), 703 | Identifier::from_str("route_destination").unwrap(), 704 | vec![], 705 | ), 706 | vec![p0.into()], 707 | ) 708 | .into() 709 | } 710 | pub fn route_source<'a>( 711 | builder: &mut sui_transaction_builder::TransactionBuilder, 712 | p0: Ref<'a, crate::bridge::chain_ids::BridgeRoute>, 713 | ) -> Ref<'a, u8> { 714 | let p0 = p0.resolve_arg(builder); 715 | builder 716 | .move_call( 717 | sui_transaction_builder::Function::new( 718 | PACKAGE_ID, 719 | Identifier::from_str(MODULE_NAME).unwrap(), 720 | Identifier::from_str("route_source").unwrap(), 721 | vec![], 722 | ), 723 | vec![p0.into()], 724 | ) 725 | .into() 726 | } 727 | pub fn sui_custom( 728 | builder: &mut sui_transaction_builder::TransactionBuilder, 729 | ) -> Arg { 730 | builder 731 | .move_call( 732 | sui_transaction_builder::Function::new( 733 | PACKAGE_ID, 734 | Identifier::from_str(MODULE_NAME).unwrap(), 735 | Identifier::from_str("sui_custom").unwrap(), 736 | vec![], 737 | ), 738 | vec![], 739 | ) 740 | .into() 741 | } 742 | pub fn sui_mainnet( 743 | builder: &mut sui_transaction_builder::TransactionBuilder, 744 | ) -> Arg { 745 | builder 746 | .move_call( 747 | sui_transaction_builder::Function::new( 748 | PACKAGE_ID, 749 | Identifier::from_str(MODULE_NAME).unwrap(), 750 | Identifier::from_str("sui_mainnet").unwrap(), 751 | vec![], 752 | ), 753 | vec![], 754 | ) 755 | .into() 756 | } 757 | pub fn sui_testnet( 758 | builder: &mut sui_transaction_builder::TransactionBuilder, 759 | ) -> Arg { 760 | builder 761 | .move_call( 762 | sui_transaction_builder::Function::new( 763 | PACKAGE_ID, 764 | Identifier::from_str(MODULE_NAME).unwrap(), 765 | Identifier::from_str("sui_testnet").unwrap(), 766 | vec![], 767 | ), 768 | vec![], 769 | ) 770 | .into() 771 | } 772 | pub fn valid_routes( 773 | builder: &mut sui_transaction_builder::TransactionBuilder, 774 | ) -> Arg> { 775 | builder 776 | .move_call( 777 | sui_transaction_builder::Function::new( 778 | PACKAGE_ID, 779 | Identifier::from_str(MODULE_NAME).unwrap(), 780 | Identifier::from_str("valid_routes").unwrap(), 781 | vec![], 782 | ), 783 | vec![], 784 | ) 785 | .into() 786 | } 787 | } 788 | pub mod committee { 789 | use std::str::FromStr; 790 | use move_binding_derive::{MoveStruct, Key}; 791 | use move_types::{MoveType, Address, Identifier, ObjectId}; 792 | use move_types::functions::{Arg, Ref, MutRef}; 793 | pub const PACKAGE_ID: Address = Address::new([ 794 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 795 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 796 | 0u8, 11u8, 797 | ]); 798 | pub const MODULE_NAME: &str = "committee"; 799 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 800 | pub struct BlocklistValidatorEvent { 801 | pub blocklisted: bool, 802 | pub public_keys: Vec>, 803 | } 804 | impl BlocklistValidatorEvent { 805 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 806 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 807 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 808 | 0u8, 0u8, 0u8, 11u8, 809 | ]); 810 | } 811 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 812 | pub struct BridgeCommittee { 813 | pub members: crate::sui::vec_map::VecMap< 814 | Vec, 815 | crate::bridge::committee::CommitteeMember, 816 | >, 817 | pub member_registrations: crate::sui::vec_map::VecMap< 818 | Address, 819 | crate::bridge::committee::CommitteeMemberRegistration, 820 | >, 821 | pub last_committee_update_epoch: u64, 822 | } 823 | impl BridgeCommittee { 824 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 825 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 826 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 827 | 0u8, 0u8, 0u8, 11u8, 828 | ]); 829 | } 830 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 831 | pub struct CommitteeMember { 832 | pub sui_address: Address, 833 | pub bridge_pubkey_bytes: Vec, 834 | pub voting_power: u64, 835 | pub http_rest_url: Vec, 836 | pub blocklisted: bool, 837 | } 838 | impl CommitteeMember { 839 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 840 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 841 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 842 | 0u8, 0u8, 0u8, 11u8, 843 | ]); 844 | } 845 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 846 | pub struct CommitteeMemberRegistration { 847 | pub sui_address: Address, 848 | pub bridge_pubkey_bytes: Vec, 849 | pub http_rest_url: Vec, 850 | } 851 | impl CommitteeMemberRegistration { 852 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 853 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 854 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 855 | 0u8, 0u8, 0u8, 11u8, 856 | ]); 857 | } 858 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 859 | pub struct CommitteeMemberUrlUpdateEvent { 860 | pub member: Vec, 861 | pub new_url: Vec, 862 | } 863 | impl CommitteeMemberUrlUpdateEvent { 864 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 865 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 866 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 867 | 0u8, 0u8, 0u8, 11u8, 868 | ]); 869 | } 870 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 871 | pub struct CommitteeUpdateEvent { 872 | pub members: crate::sui::vec_map::VecMap< 873 | Vec, 874 | crate::bridge::committee::CommitteeMember, 875 | >, 876 | pub stake_participation_percentage: u64, 877 | } 878 | impl CommitteeUpdateEvent { 879 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 880 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 881 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 882 | 0u8, 0u8, 0u8, 11u8, 883 | ]); 884 | } 885 | pub fn check_uniqueness_bridge_keys<'a>( 886 | builder: &mut sui_transaction_builder::TransactionBuilder, 887 | p0: Ref<'a, crate::bridge::committee::BridgeCommittee>, 888 | p1: Arg>, 889 | ) { 890 | let p0 = p0.resolve_arg(builder); 891 | let p1 = p1.resolve_arg(builder); 892 | builder 893 | .move_call( 894 | sui_transaction_builder::Function::new( 895 | PACKAGE_ID, 896 | Identifier::from_str(MODULE_NAME).unwrap(), 897 | Identifier::from_str("check_uniqueness_bridge_keys").unwrap(), 898 | vec![], 899 | ), 900 | vec![p0.into(), p1.into()], 901 | ); 902 | } 903 | pub fn committee_members<'a>( 904 | builder: &mut sui_transaction_builder::TransactionBuilder, 905 | p0: Ref<'a, crate::bridge::committee::BridgeCommittee>, 906 | ) -> Ref< 907 | 'a, 908 | crate::sui::vec_map::VecMap< 909 | Vec, 910 | crate::bridge::committee::CommitteeMember, 911 | >, 912 | > { 913 | let p0 = p0.resolve_arg(builder); 914 | builder 915 | .move_call( 916 | sui_transaction_builder::Function::new( 917 | PACKAGE_ID, 918 | Identifier::from_str(MODULE_NAME).unwrap(), 919 | Identifier::from_str("committee_members").unwrap(), 920 | vec![], 921 | ), 922 | vec![p0.into()], 923 | ) 924 | .into() 925 | } 926 | pub fn create<'a>( 927 | builder: &mut sui_transaction_builder::TransactionBuilder, 928 | ) -> Arg { 929 | builder 930 | .move_call( 931 | sui_transaction_builder::Function::new( 932 | PACKAGE_ID, 933 | Identifier::from_str(MODULE_NAME).unwrap(), 934 | Identifier::from_str("create").unwrap(), 935 | vec![], 936 | ), 937 | vec![], 938 | ) 939 | .into() 940 | } 941 | pub fn execute_blocklist<'a>( 942 | builder: &mut sui_transaction_builder::TransactionBuilder, 943 | p0: MutRef<'a, crate::bridge::committee::BridgeCommittee>, 944 | p1: Arg, 945 | ) { 946 | let p0 = p0.resolve_arg(builder); 947 | let p1 = p1.resolve_arg(builder); 948 | builder 949 | .move_call( 950 | sui_transaction_builder::Function::new( 951 | PACKAGE_ID, 952 | Identifier::from_str(MODULE_NAME).unwrap(), 953 | Identifier::from_str("execute_blocklist").unwrap(), 954 | vec![], 955 | ), 956 | vec![p0.into(), p1.into()], 957 | ); 958 | } 959 | pub fn register<'a>( 960 | builder: &mut sui_transaction_builder::TransactionBuilder, 961 | p0: MutRef<'a, crate::bridge::committee::BridgeCommittee>, 962 | p1: MutRef<'a, crate::sui_system::sui_system::SuiSystemState>, 963 | p2: Arg>, 964 | p3: Arg>, 965 | ) { 966 | let p0 = p0.resolve_arg(builder); 967 | let p1 = p1.resolve_arg(builder); 968 | let p2 = p2.resolve_arg(builder); 969 | let p3 = p3.resolve_arg(builder); 970 | builder 971 | .move_call( 972 | sui_transaction_builder::Function::new( 973 | PACKAGE_ID, 974 | Identifier::from_str(MODULE_NAME).unwrap(), 975 | Identifier::from_str("register").unwrap(), 976 | vec![], 977 | ), 978 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 979 | ); 980 | } 981 | pub fn try_create_next_committee<'a>( 982 | builder: &mut sui_transaction_builder::TransactionBuilder, 983 | p0: MutRef<'a, crate::bridge::committee::BridgeCommittee>, 984 | p1: Arg>, 985 | p2: Arg, 986 | ) { 987 | let p0 = p0.resolve_arg(builder); 988 | let p1 = p1.resolve_arg(builder); 989 | let p2 = p2.resolve_arg(builder); 990 | builder 991 | .move_call( 992 | sui_transaction_builder::Function::new( 993 | PACKAGE_ID, 994 | Identifier::from_str(MODULE_NAME).unwrap(), 995 | Identifier::from_str("try_create_next_committee").unwrap(), 996 | vec![], 997 | ), 998 | vec![p0.into(), p1.into(), p2.into()], 999 | ); 1000 | } 1001 | pub fn update_node_url<'a>( 1002 | builder: &mut sui_transaction_builder::TransactionBuilder, 1003 | p0: MutRef<'a, crate::bridge::committee::BridgeCommittee>, 1004 | p1: Arg>, 1005 | ) { 1006 | let p0 = p0.resolve_arg(builder); 1007 | let p1 = p1.resolve_arg(builder); 1008 | builder 1009 | .move_call( 1010 | sui_transaction_builder::Function::new( 1011 | PACKAGE_ID, 1012 | Identifier::from_str(MODULE_NAME).unwrap(), 1013 | Identifier::from_str("update_node_url").unwrap(), 1014 | vec![], 1015 | ), 1016 | vec![p0.into(), p1.into()], 1017 | ); 1018 | } 1019 | pub fn verify_signatures<'a>( 1020 | builder: &mut sui_transaction_builder::TransactionBuilder, 1021 | p0: Ref<'a, crate::bridge::committee::BridgeCommittee>, 1022 | p1: Arg, 1023 | p2: Arg>>, 1024 | ) { 1025 | let p0 = p0.resolve_arg(builder); 1026 | let p1 = p1.resolve_arg(builder); 1027 | let p2 = p2.resolve_arg(builder); 1028 | builder 1029 | .move_call( 1030 | sui_transaction_builder::Function::new( 1031 | PACKAGE_ID, 1032 | Identifier::from_str(MODULE_NAME).unwrap(), 1033 | Identifier::from_str("verify_signatures").unwrap(), 1034 | vec![], 1035 | ), 1036 | vec![p0.into(), p1.into(), p2.into()], 1037 | ); 1038 | } 1039 | } 1040 | pub mod crypto { 1041 | use std::str::FromStr; 1042 | use move_binding_derive::{MoveStruct, Key}; 1043 | use move_types::{MoveType, Address, Identifier, ObjectId}; 1044 | use move_types::functions::{Arg, Ref, MutRef}; 1045 | pub const PACKAGE_ID: Address = Address::new([ 1046 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1047 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1048 | 0u8, 11u8, 1049 | ]); 1050 | pub const MODULE_NAME: &str = "crypto"; 1051 | pub fn ecdsa_pub_key_to_eth_address<'a>( 1052 | builder: &mut sui_transaction_builder::TransactionBuilder, 1053 | p0: Ref<'a, Vec>, 1054 | ) -> Arg> { 1055 | let p0 = p0.resolve_arg(builder); 1056 | builder 1057 | .move_call( 1058 | sui_transaction_builder::Function::new( 1059 | PACKAGE_ID, 1060 | Identifier::from_str(MODULE_NAME).unwrap(), 1061 | Identifier::from_str("ecdsa_pub_key_to_eth_address").unwrap(), 1062 | vec![], 1063 | ), 1064 | vec![p0.into()], 1065 | ) 1066 | .into() 1067 | } 1068 | } 1069 | pub mod limiter { 1070 | use std::str::FromStr; 1071 | use move_binding_derive::{MoveStruct, Key}; 1072 | use move_types::{MoveType, Address, Identifier, ObjectId}; 1073 | use move_types::functions::{Arg, Ref, MutRef}; 1074 | pub const PACKAGE_ID: Address = Address::new([ 1075 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1076 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1077 | 0u8, 11u8, 1078 | ]); 1079 | pub const MODULE_NAME: &str = "limiter"; 1080 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1081 | pub struct TransferLimiter { 1082 | pub transfer_limits: crate::sui::vec_map::VecMap< 1083 | crate::bridge::chain_ids::BridgeRoute, 1084 | u64, 1085 | >, 1086 | pub transfer_records: crate::sui::vec_map::VecMap< 1087 | crate::bridge::chain_ids::BridgeRoute, 1088 | crate::bridge::limiter::TransferRecord, 1089 | >, 1090 | } 1091 | impl TransferLimiter { 1092 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1093 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1094 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1095 | 0u8, 0u8, 0u8, 11u8, 1096 | ]); 1097 | } 1098 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1099 | pub struct TransferRecord { 1100 | pub hour_head: u64, 1101 | pub hour_tail: u64, 1102 | pub per_hour_amounts: Vec, 1103 | pub total_amount: u64, 1104 | } 1105 | impl TransferRecord { 1106 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1107 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1108 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1109 | 0u8, 0u8, 0u8, 11u8, 1110 | ]); 1111 | } 1112 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1113 | pub struct UpdateRouteLimitEvent { 1114 | pub sending_chain: u8, 1115 | pub receiving_chain: u8, 1116 | pub new_limit: u64, 1117 | } 1118 | impl UpdateRouteLimitEvent { 1119 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1120 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1121 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1122 | 0u8, 0u8, 0u8, 11u8, 1123 | ]); 1124 | } 1125 | pub fn adjust_transfer_records<'a>( 1126 | builder: &mut sui_transaction_builder::TransactionBuilder, 1127 | p0: MutRef<'a, crate::bridge::limiter::TransferRecord>, 1128 | p1: Arg, 1129 | ) { 1130 | let p0 = p0.resolve_arg(builder); 1131 | let p1 = p1.resolve_arg(builder); 1132 | builder 1133 | .move_call( 1134 | sui_transaction_builder::Function::new( 1135 | PACKAGE_ID, 1136 | Identifier::from_str(MODULE_NAME).unwrap(), 1137 | Identifier::from_str("adjust_transfer_records").unwrap(), 1138 | vec![], 1139 | ), 1140 | vec![p0.into(), p1.into()], 1141 | ); 1142 | } 1143 | pub fn check_and_record_sending_transfer<'a, T0: MoveType>( 1144 | builder: &mut sui_transaction_builder::TransactionBuilder, 1145 | p0: MutRef<'a, crate::bridge::limiter::TransferLimiter>, 1146 | p1: Ref<'a, crate::bridge::treasury::BridgeTreasury>, 1147 | p2: Ref<'a, crate::sui::clock::Clock>, 1148 | p3: Arg, 1149 | p4: Arg, 1150 | ) -> Arg { 1151 | let p0 = p0.resolve_arg(builder); 1152 | let p1 = p1.resolve_arg(builder); 1153 | let p2 = p2.resolve_arg(builder); 1154 | let p3 = p3.resolve_arg(builder); 1155 | let p4 = p4.resolve_arg(builder); 1156 | builder 1157 | .move_call( 1158 | sui_transaction_builder::Function::new( 1159 | PACKAGE_ID, 1160 | Identifier::from_str(MODULE_NAME).unwrap(), 1161 | Identifier::from_str("check_and_record_sending_transfer") 1162 | .unwrap(), 1163 | vec![T0::type_()], 1164 | ), 1165 | vec![p0.into(), p1.into(), p2.into(), p3.into(), p4.into()], 1166 | ) 1167 | .into() 1168 | } 1169 | pub fn current_hour_since_epoch<'a>( 1170 | builder: &mut sui_transaction_builder::TransactionBuilder, 1171 | p0: Ref<'a, crate::sui::clock::Clock>, 1172 | ) -> Arg { 1173 | let p0 = p0.resolve_arg(builder); 1174 | builder 1175 | .move_call( 1176 | sui_transaction_builder::Function::new( 1177 | PACKAGE_ID, 1178 | Identifier::from_str(MODULE_NAME).unwrap(), 1179 | Identifier::from_str("current_hour_since_epoch").unwrap(), 1180 | vec![], 1181 | ), 1182 | vec![p0.into()], 1183 | ) 1184 | .into() 1185 | } 1186 | pub fn get_route_limit<'a>( 1187 | builder: &mut sui_transaction_builder::TransactionBuilder, 1188 | p0: Ref<'a, crate::bridge::limiter::TransferLimiter>, 1189 | p1: Ref<'a, crate::bridge::chain_ids::BridgeRoute>, 1190 | ) -> Arg { 1191 | let p0 = p0.resolve_arg(builder); 1192 | let p1 = p1.resolve_arg(builder); 1193 | builder 1194 | .move_call( 1195 | sui_transaction_builder::Function::new( 1196 | PACKAGE_ID, 1197 | Identifier::from_str(MODULE_NAME).unwrap(), 1198 | Identifier::from_str("get_route_limit").unwrap(), 1199 | vec![], 1200 | ), 1201 | vec![p0.into(), p1.into()], 1202 | ) 1203 | .into() 1204 | } 1205 | pub fn initial_transfer_limits( 1206 | builder: &mut sui_transaction_builder::TransactionBuilder, 1207 | ) -> Arg< 1208 | crate::sui::vec_map::VecMap, 1209 | > { 1210 | builder 1211 | .move_call( 1212 | sui_transaction_builder::Function::new( 1213 | PACKAGE_ID, 1214 | Identifier::from_str(MODULE_NAME).unwrap(), 1215 | Identifier::from_str("initial_transfer_limits").unwrap(), 1216 | vec![], 1217 | ), 1218 | vec![], 1219 | ) 1220 | .into() 1221 | } 1222 | pub fn new( 1223 | builder: &mut sui_transaction_builder::TransactionBuilder, 1224 | ) -> Arg { 1225 | builder 1226 | .move_call( 1227 | sui_transaction_builder::Function::new( 1228 | PACKAGE_ID, 1229 | Identifier::from_str(MODULE_NAME).unwrap(), 1230 | Identifier::from_str("new").unwrap(), 1231 | vec![], 1232 | ), 1233 | vec![], 1234 | ) 1235 | .into() 1236 | } 1237 | pub fn update_route_limit<'a>( 1238 | builder: &mut sui_transaction_builder::TransactionBuilder, 1239 | p0: MutRef<'a, crate::bridge::limiter::TransferLimiter>, 1240 | p1: Ref<'a, crate::bridge::chain_ids::BridgeRoute>, 1241 | p2: Arg, 1242 | ) { 1243 | let p0 = p0.resolve_arg(builder); 1244 | let p1 = p1.resolve_arg(builder); 1245 | let p2 = p2.resolve_arg(builder); 1246 | builder 1247 | .move_call( 1248 | sui_transaction_builder::Function::new( 1249 | PACKAGE_ID, 1250 | Identifier::from_str(MODULE_NAME).unwrap(), 1251 | Identifier::from_str("update_route_limit").unwrap(), 1252 | vec![], 1253 | ), 1254 | vec![p0.into(), p1.into(), p2.into()], 1255 | ); 1256 | } 1257 | } 1258 | pub mod message { 1259 | use std::str::FromStr; 1260 | use move_binding_derive::{MoveStruct, Key}; 1261 | use move_types::{MoveType, Address, Identifier, ObjectId}; 1262 | use move_types::functions::{Arg, Ref, MutRef}; 1263 | pub const PACKAGE_ID: Address = Address::new([ 1264 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1265 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1266 | 0u8, 11u8, 1267 | ]); 1268 | pub const MODULE_NAME: &str = "message"; 1269 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1270 | pub struct AddTokenOnSui { 1271 | pub native_token: bool, 1272 | pub token_ids: Vec, 1273 | pub token_type_names: Vec, 1274 | pub token_prices: Vec, 1275 | } 1276 | impl AddTokenOnSui { 1277 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1278 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1279 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1280 | 0u8, 0u8, 0u8, 11u8, 1281 | ]); 1282 | } 1283 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1284 | pub struct Blocklist { 1285 | pub blocklist_type: u8, 1286 | pub validator_eth_addresses: Vec>, 1287 | } 1288 | impl Blocklist { 1289 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1290 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1291 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1292 | 0u8, 0u8, 0u8, 11u8, 1293 | ]); 1294 | } 1295 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1296 | pub struct BridgeMessage { 1297 | pub message_type: u8, 1298 | pub message_version: u8, 1299 | pub seq_num: u64, 1300 | pub source_chain: u8, 1301 | pub payload: Vec, 1302 | } 1303 | impl BridgeMessage { 1304 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1305 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1306 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1307 | 0u8, 0u8, 0u8, 11u8, 1308 | ]); 1309 | } 1310 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1311 | pub struct BridgeMessageKey { 1312 | pub source_chain: u8, 1313 | pub message_type: u8, 1314 | pub bridge_seq_num: u64, 1315 | } 1316 | impl BridgeMessageKey { 1317 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1318 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1319 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1320 | 0u8, 0u8, 0u8, 11u8, 1321 | ]); 1322 | } 1323 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1324 | pub struct EmergencyOp { 1325 | pub op_type: u8, 1326 | } 1327 | impl EmergencyOp { 1328 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1329 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1330 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1331 | 0u8, 0u8, 0u8, 11u8, 1332 | ]); 1333 | } 1334 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1335 | pub struct ParsedTokenTransferMessage { 1336 | pub message_version: u8, 1337 | pub seq_num: u64, 1338 | pub source_chain: u8, 1339 | pub payload: Vec, 1340 | pub parsed_payload: crate::bridge::message::TokenTransferPayload, 1341 | } 1342 | impl ParsedTokenTransferMessage { 1343 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1344 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1345 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1346 | 0u8, 0u8, 0u8, 11u8, 1347 | ]); 1348 | } 1349 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1350 | pub struct TokenTransferPayload { 1351 | pub sender_address: Vec, 1352 | pub target_chain: u8, 1353 | pub target_address: Vec, 1354 | pub token_type: u8, 1355 | pub amount: u64, 1356 | } 1357 | impl TokenTransferPayload { 1358 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1359 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1360 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1361 | 0u8, 0u8, 0u8, 11u8, 1362 | ]); 1363 | } 1364 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1365 | pub struct UpdateAssetPrice { 1366 | pub token_id: u8, 1367 | pub new_price: u64, 1368 | } 1369 | impl UpdateAssetPrice { 1370 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1371 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1372 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1373 | 0u8, 0u8, 0u8, 11u8, 1374 | ]); 1375 | } 1376 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 1377 | pub struct UpdateBridgeLimit { 1378 | pub receiving_chain: u8, 1379 | pub sending_chain: u8, 1380 | pub limit: u64, 1381 | } 1382 | impl UpdateBridgeLimit { 1383 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 1384 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1385 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1386 | 0u8, 0u8, 0u8, 11u8, 1387 | ]); 1388 | } 1389 | pub fn blocklist_type<'a>( 1390 | builder: &mut sui_transaction_builder::TransactionBuilder, 1391 | p0: Ref<'a, crate::bridge::message::Blocklist>, 1392 | ) -> Arg { 1393 | let p0 = p0.resolve_arg(builder); 1394 | builder 1395 | .move_call( 1396 | sui_transaction_builder::Function::new( 1397 | PACKAGE_ID, 1398 | Identifier::from_str(MODULE_NAME).unwrap(), 1399 | Identifier::from_str("blocklist_type").unwrap(), 1400 | vec![], 1401 | ), 1402 | vec![p0.into()], 1403 | ) 1404 | .into() 1405 | } 1406 | pub fn blocklist_validator_addresses<'a>( 1407 | builder: &mut sui_transaction_builder::TransactionBuilder, 1408 | p0: Ref<'a, crate::bridge::message::Blocklist>, 1409 | ) -> Ref<'a, Vec>> { 1410 | let p0 = p0.resolve_arg(builder); 1411 | builder 1412 | .move_call( 1413 | sui_transaction_builder::Function::new( 1414 | PACKAGE_ID, 1415 | Identifier::from_str(MODULE_NAME).unwrap(), 1416 | Identifier::from_str("blocklist_validator_addresses").unwrap(), 1417 | vec![], 1418 | ), 1419 | vec![p0.into()], 1420 | ) 1421 | .into() 1422 | } 1423 | pub fn create_add_tokens_on_sui_message( 1424 | builder: &mut sui_transaction_builder::TransactionBuilder, 1425 | p0: Arg, 1426 | p1: Arg, 1427 | p2: Arg, 1428 | p3: Arg>, 1429 | p4: Arg>, 1430 | p5: Arg>, 1431 | ) -> Arg { 1432 | let p0 = p0.resolve_arg(builder); 1433 | let p1 = p1.resolve_arg(builder); 1434 | let p2 = p2.resolve_arg(builder); 1435 | let p3 = p3.resolve_arg(builder); 1436 | let p4 = p4.resolve_arg(builder); 1437 | let p5 = p5.resolve_arg(builder); 1438 | builder 1439 | .move_call( 1440 | sui_transaction_builder::Function::new( 1441 | PACKAGE_ID, 1442 | Identifier::from_str(MODULE_NAME).unwrap(), 1443 | Identifier::from_str("create_add_tokens_on_sui_message") 1444 | .unwrap(), 1445 | vec![], 1446 | ), 1447 | vec![ 1448 | p0.into(), p1.into(), p2.into(), p3.into(), p4.into(), p5.into() 1449 | ], 1450 | ) 1451 | .into() 1452 | } 1453 | pub fn create_blocklist_message( 1454 | builder: &mut sui_transaction_builder::TransactionBuilder, 1455 | p0: Arg, 1456 | p1: Arg, 1457 | p2: Arg, 1458 | p3: Arg>>, 1459 | ) -> Arg { 1460 | let p0 = p0.resolve_arg(builder); 1461 | let p1 = p1.resolve_arg(builder); 1462 | let p2 = p2.resolve_arg(builder); 1463 | let p3 = p3.resolve_arg(builder); 1464 | builder 1465 | .move_call( 1466 | sui_transaction_builder::Function::new( 1467 | PACKAGE_ID, 1468 | Identifier::from_str(MODULE_NAME).unwrap(), 1469 | Identifier::from_str("create_blocklist_message").unwrap(), 1470 | vec![], 1471 | ), 1472 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 1473 | ) 1474 | .into() 1475 | } 1476 | pub fn create_emergency_op_message( 1477 | builder: &mut sui_transaction_builder::TransactionBuilder, 1478 | p0: Arg, 1479 | p1: Arg, 1480 | p2: Arg, 1481 | ) -> Arg { 1482 | let p0 = p0.resolve_arg(builder); 1483 | let p1 = p1.resolve_arg(builder); 1484 | let p2 = p2.resolve_arg(builder); 1485 | builder 1486 | .move_call( 1487 | sui_transaction_builder::Function::new( 1488 | PACKAGE_ID, 1489 | Identifier::from_str(MODULE_NAME).unwrap(), 1490 | Identifier::from_str("create_emergency_op_message").unwrap(), 1491 | vec![], 1492 | ), 1493 | vec![p0.into(), p1.into(), p2.into()], 1494 | ) 1495 | .into() 1496 | } 1497 | pub fn create_key( 1498 | builder: &mut sui_transaction_builder::TransactionBuilder, 1499 | p0: Arg, 1500 | p1: Arg, 1501 | p2: Arg, 1502 | ) -> Arg { 1503 | let p0 = p0.resolve_arg(builder); 1504 | let p1 = p1.resolve_arg(builder); 1505 | let p2 = p2.resolve_arg(builder); 1506 | builder 1507 | .move_call( 1508 | sui_transaction_builder::Function::new( 1509 | PACKAGE_ID, 1510 | Identifier::from_str(MODULE_NAME).unwrap(), 1511 | Identifier::from_str("create_key").unwrap(), 1512 | vec![], 1513 | ), 1514 | vec![p0.into(), p1.into(), p2.into()], 1515 | ) 1516 | .into() 1517 | } 1518 | pub fn create_token_bridge_message( 1519 | builder: &mut sui_transaction_builder::TransactionBuilder, 1520 | p0: Arg, 1521 | p1: Arg, 1522 | p2: Arg>, 1523 | p3: Arg, 1524 | p4: Arg>, 1525 | p5: Arg, 1526 | p6: Arg, 1527 | ) -> Arg { 1528 | let p0 = p0.resolve_arg(builder); 1529 | let p1 = p1.resolve_arg(builder); 1530 | let p2 = p2.resolve_arg(builder); 1531 | let p3 = p3.resolve_arg(builder); 1532 | let p4 = p4.resolve_arg(builder); 1533 | let p5 = p5.resolve_arg(builder); 1534 | let p6 = p6.resolve_arg(builder); 1535 | builder 1536 | .move_call( 1537 | sui_transaction_builder::Function::new( 1538 | PACKAGE_ID, 1539 | Identifier::from_str(MODULE_NAME).unwrap(), 1540 | Identifier::from_str("create_token_bridge_message").unwrap(), 1541 | vec![], 1542 | ), 1543 | vec![ 1544 | p0.into(), p1.into(), p2.into(), p3.into(), p4.into(), p5.into(), 1545 | p6.into() 1546 | ], 1547 | ) 1548 | .into() 1549 | } 1550 | pub fn create_update_asset_price_message( 1551 | builder: &mut sui_transaction_builder::TransactionBuilder, 1552 | p0: Arg, 1553 | p1: Arg, 1554 | p2: Arg, 1555 | p3: Arg, 1556 | ) -> Arg { 1557 | let p0 = p0.resolve_arg(builder); 1558 | let p1 = p1.resolve_arg(builder); 1559 | let p2 = p2.resolve_arg(builder); 1560 | let p3 = p3.resolve_arg(builder); 1561 | builder 1562 | .move_call( 1563 | sui_transaction_builder::Function::new( 1564 | PACKAGE_ID, 1565 | Identifier::from_str(MODULE_NAME).unwrap(), 1566 | Identifier::from_str("create_update_asset_price_message") 1567 | .unwrap(), 1568 | vec![], 1569 | ), 1570 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 1571 | ) 1572 | .into() 1573 | } 1574 | pub fn create_update_bridge_limit_message( 1575 | builder: &mut sui_transaction_builder::TransactionBuilder, 1576 | p0: Arg, 1577 | p1: Arg, 1578 | p2: Arg, 1579 | p3: Arg, 1580 | ) -> Arg { 1581 | let p0 = p0.resolve_arg(builder); 1582 | let p1 = p1.resolve_arg(builder); 1583 | let p2 = p2.resolve_arg(builder); 1584 | let p3 = p3.resolve_arg(builder); 1585 | builder 1586 | .move_call( 1587 | sui_transaction_builder::Function::new( 1588 | PACKAGE_ID, 1589 | Identifier::from_str(MODULE_NAME).unwrap(), 1590 | Identifier::from_str("create_update_bridge_limit_message") 1591 | .unwrap(), 1592 | vec![], 1593 | ), 1594 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 1595 | ) 1596 | .into() 1597 | } 1598 | pub fn emergency_op_pause( 1599 | builder: &mut sui_transaction_builder::TransactionBuilder, 1600 | ) -> Arg { 1601 | builder 1602 | .move_call( 1603 | sui_transaction_builder::Function::new( 1604 | PACKAGE_ID, 1605 | Identifier::from_str(MODULE_NAME).unwrap(), 1606 | Identifier::from_str("emergency_op_pause").unwrap(), 1607 | vec![], 1608 | ), 1609 | vec![], 1610 | ) 1611 | .into() 1612 | } 1613 | pub fn emergency_op_type<'a>( 1614 | builder: &mut sui_transaction_builder::TransactionBuilder, 1615 | p0: Ref<'a, crate::bridge::message::EmergencyOp>, 1616 | ) -> Arg { 1617 | let p0 = p0.resolve_arg(builder); 1618 | builder 1619 | .move_call( 1620 | sui_transaction_builder::Function::new( 1621 | PACKAGE_ID, 1622 | Identifier::from_str(MODULE_NAME).unwrap(), 1623 | Identifier::from_str("emergency_op_type").unwrap(), 1624 | vec![], 1625 | ), 1626 | vec![p0.into()], 1627 | ) 1628 | .into() 1629 | } 1630 | pub fn emergency_op_unpause( 1631 | builder: &mut sui_transaction_builder::TransactionBuilder, 1632 | ) -> Arg { 1633 | builder 1634 | .move_call( 1635 | sui_transaction_builder::Function::new( 1636 | PACKAGE_ID, 1637 | Identifier::from_str(MODULE_NAME).unwrap(), 1638 | Identifier::from_str("emergency_op_unpause").unwrap(), 1639 | vec![], 1640 | ), 1641 | vec![], 1642 | ) 1643 | .into() 1644 | } 1645 | pub fn extract_add_tokens_on_sui<'a>( 1646 | builder: &mut sui_transaction_builder::TransactionBuilder, 1647 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1648 | ) -> Arg { 1649 | let p0 = p0.resolve_arg(builder); 1650 | builder 1651 | .move_call( 1652 | sui_transaction_builder::Function::new( 1653 | PACKAGE_ID, 1654 | Identifier::from_str(MODULE_NAME).unwrap(), 1655 | Identifier::from_str("extract_add_tokens_on_sui").unwrap(), 1656 | vec![], 1657 | ), 1658 | vec![p0.into()], 1659 | ) 1660 | .into() 1661 | } 1662 | pub fn extract_blocklist_payload<'a>( 1663 | builder: &mut sui_transaction_builder::TransactionBuilder, 1664 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1665 | ) -> Arg { 1666 | let p0 = p0.resolve_arg(builder); 1667 | builder 1668 | .move_call( 1669 | sui_transaction_builder::Function::new( 1670 | PACKAGE_ID, 1671 | Identifier::from_str(MODULE_NAME).unwrap(), 1672 | Identifier::from_str("extract_blocklist_payload").unwrap(), 1673 | vec![], 1674 | ), 1675 | vec![p0.into()], 1676 | ) 1677 | .into() 1678 | } 1679 | pub fn extract_emergency_op_payload<'a>( 1680 | builder: &mut sui_transaction_builder::TransactionBuilder, 1681 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1682 | ) -> Arg { 1683 | let p0 = p0.resolve_arg(builder); 1684 | builder 1685 | .move_call( 1686 | sui_transaction_builder::Function::new( 1687 | PACKAGE_ID, 1688 | Identifier::from_str(MODULE_NAME).unwrap(), 1689 | Identifier::from_str("extract_emergency_op_payload").unwrap(), 1690 | vec![], 1691 | ), 1692 | vec![p0.into()], 1693 | ) 1694 | .into() 1695 | } 1696 | pub fn extract_token_bridge_payload<'a>( 1697 | builder: &mut sui_transaction_builder::TransactionBuilder, 1698 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1699 | ) -> Arg { 1700 | let p0 = p0.resolve_arg(builder); 1701 | builder 1702 | .move_call( 1703 | sui_transaction_builder::Function::new( 1704 | PACKAGE_ID, 1705 | Identifier::from_str(MODULE_NAME).unwrap(), 1706 | Identifier::from_str("extract_token_bridge_payload").unwrap(), 1707 | vec![], 1708 | ), 1709 | vec![p0.into()], 1710 | ) 1711 | .into() 1712 | } 1713 | pub fn extract_update_asset_price<'a>( 1714 | builder: &mut sui_transaction_builder::TransactionBuilder, 1715 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1716 | ) -> Arg { 1717 | let p0 = p0.resolve_arg(builder); 1718 | builder 1719 | .move_call( 1720 | sui_transaction_builder::Function::new( 1721 | PACKAGE_ID, 1722 | Identifier::from_str(MODULE_NAME).unwrap(), 1723 | Identifier::from_str("extract_update_asset_price").unwrap(), 1724 | vec![], 1725 | ), 1726 | vec![p0.into()], 1727 | ) 1728 | .into() 1729 | } 1730 | pub fn extract_update_bridge_limit<'a>( 1731 | builder: &mut sui_transaction_builder::TransactionBuilder, 1732 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1733 | ) -> Arg { 1734 | let p0 = p0.resolve_arg(builder); 1735 | builder 1736 | .move_call( 1737 | sui_transaction_builder::Function::new( 1738 | PACKAGE_ID, 1739 | Identifier::from_str(MODULE_NAME).unwrap(), 1740 | Identifier::from_str("extract_update_bridge_limit").unwrap(), 1741 | vec![], 1742 | ), 1743 | vec![p0.into()], 1744 | ) 1745 | .into() 1746 | } 1747 | pub fn is_native<'a>( 1748 | builder: &mut sui_transaction_builder::TransactionBuilder, 1749 | p0: Ref<'a, crate::bridge::message::AddTokenOnSui>, 1750 | ) -> Arg { 1751 | let p0 = p0.resolve_arg(builder); 1752 | builder 1753 | .move_call( 1754 | sui_transaction_builder::Function::new( 1755 | PACKAGE_ID, 1756 | Identifier::from_str(MODULE_NAME).unwrap(), 1757 | Identifier::from_str("is_native").unwrap(), 1758 | vec![], 1759 | ), 1760 | vec![p0.into()], 1761 | ) 1762 | .into() 1763 | } 1764 | pub fn key<'a>( 1765 | builder: &mut sui_transaction_builder::TransactionBuilder, 1766 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1767 | ) -> Arg { 1768 | let p0 = p0.resolve_arg(builder); 1769 | builder 1770 | .move_call( 1771 | sui_transaction_builder::Function::new( 1772 | PACKAGE_ID, 1773 | Identifier::from_str(MODULE_NAME).unwrap(), 1774 | Identifier::from_str("key").unwrap(), 1775 | vec![], 1776 | ), 1777 | vec![p0.into()], 1778 | ) 1779 | .into() 1780 | } 1781 | pub fn message_type<'a>( 1782 | builder: &mut sui_transaction_builder::TransactionBuilder, 1783 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1784 | ) -> Arg { 1785 | let p0 = p0.resolve_arg(builder); 1786 | builder 1787 | .move_call( 1788 | sui_transaction_builder::Function::new( 1789 | PACKAGE_ID, 1790 | Identifier::from_str(MODULE_NAME).unwrap(), 1791 | Identifier::from_str("message_type").unwrap(), 1792 | vec![], 1793 | ), 1794 | vec![p0.into()], 1795 | ) 1796 | .into() 1797 | } 1798 | pub fn message_version<'a>( 1799 | builder: &mut sui_transaction_builder::TransactionBuilder, 1800 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1801 | ) -> Arg { 1802 | let p0 = p0.resolve_arg(builder); 1803 | builder 1804 | .move_call( 1805 | sui_transaction_builder::Function::new( 1806 | PACKAGE_ID, 1807 | Identifier::from_str(MODULE_NAME).unwrap(), 1808 | Identifier::from_str("message_version").unwrap(), 1809 | vec![], 1810 | ), 1811 | vec![p0.into()], 1812 | ) 1813 | .into() 1814 | } 1815 | pub fn payload<'a>( 1816 | builder: &mut sui_transaction_builder::TransactionBuilder, 1817 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1818 | ) -> Arg> { 1819 | let p0 = p0.resolve_arg(builder); 1820 | builder 1821 | .move_call( 1822 | sui_transaction_builder::Function::new( 1823 | PACKAGE_ID, 1824 | Identifier::from_str(MODULE_NAME).unwrap(), 1825 | Identifier::from_str("payload").unwrap(), 1826 | vec![], 1827 | ), 1828 | vec![p0.into()], 1829 | ) 1830 | .into() 1831 | } 1832 | pub fn peel_u64_be<'a>( 1833 | builder: &mut sui_transaction_builder::TransactionBuilder, 1834 | p0: MutRef<'a, crate::sui::bcs::BCS>, 1835 | ) -> Arg { 1836 | let p0 = p0.resolve_arg(builder); 1837 | builder 1838 | .move_call( 1839 | sui_transaction_builder::Function::new( 1840 | PACKAGE_ID, 1841 | Identifier::from_str(MODULE_NAME).unwrap(), 1842 | Identifier::from_str("peel_u64_be").unwrap(), 1843 | vec![], 1844 | ), 1845 | vec![p0.into()], 1846 | ) 1847 | .into() 1848 | } 1849 | pub fn required_voting_power<'a>( 1850 | builder: &mut sui_transaction_builder::TransactionBuilder, 1851 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1852 | ) -> Arg { 1853 | let p0 = p0.resolve_arg(builder); 1854 | builder 1855 | .move_call( 1856 | sui_transaction_builder::Function::new( 1857 | PACKAGE_ID, 1858 | Identifier::from_str(MODULE_NAME).unwrap(), 1859 | Identifier::from_str("required_voting_power").unwrap(), 1860 | vec![], 1861 | ), 1862 | vec![p0.into()], 1863 | ) 1864 | .into() 1865 | } 1866 | pub fn reverse_bytes( 1867 | builder: &mut sui_transaction_builder::TransactionBuilder, 1868 | p0: Arg>, 1869 | ) -> Arg> { 1870 | let p0 = p0.resolve_arg(builder); 1871 | builder 1872 | .move_call( 1873 | sui_transaction_builder::Function::new( 1874 | PACKAGE_ID, 1875 | Identifier::from_str(MODULE_NAME).unwrap(), 1876 | Identifier::from_str("reverse_bytes").unwrap(), 1877 | vec![], 1878 | ), 1879 | vec![p0.into()], 1880 | ) 1881 | .into() 1882 | } 1883 | pub fn seq_num<'a>( 1884 | builder: &mut sui_transaction_builder::TransactionBuilder, 1885 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1886 | ) -> Arg { 1887 | let p0 = p0.resolve_arg(builder); 1888 | builder 1889 | .move_call( 1890 | sui_transaction_builder::Function::new( 1891 | PACKAGE_ID, 1892 | Identifier::from_str(MODULE_NAME).unwrap(), 1893 | Identifier::from_str("seq_num").unwrap(), 1894 | vec![], 1895 | ), 1896 | vec![p0.into()], 1897 | ) 1898 | .into() 1899 | } 1900 | pub fn serialize_message( 1901 | builder: &mut sui_transaction_builder::TransactionBuilder, 1902 | p0: Arg, 1903 | ) -> Arg> { 1904 | let p0 = p0.resolve_arg(builder); 1905 | builder 1906 | .move_call( 1907 | sui_transaction_builder::Function::new( 1908 | PACKAGE_ID, 1909 | Identifier::from_str(MODULE_NAME).unwrap(), 1910 | Identifier::from_str("serialize_message").unwrap(), 1911 | vec![], 1912 | ), 1913 | vec![p0.into()], 1914 | ) 1915 | .into() 1916 | } 1917 | pub fn source_chain<'a>( 1918 | builder: &mut sui_transaction_builder::TransactionBuilder, 1919 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1920 | ) -> Arg { 1921 | let p0 = p0.resolve_arg(builder); 1922 | builder 1923 | .move_call( 1924 | sui_transaction_builder::Function::new( 1925 | PACKAGE_ID, 1926 | Identifier::from_str(MODULE_NAME).unwrap(), 1927 | Identifier::from_str("source_chain").unwrap(), 1928 | vec![], 1929 | ), 1930 | vec![p0.into()], 1931 | ) 1932 | .into() 1933 | } 1934 | pub fn to_parsed_token_transfer_message<'a>( 1935 | builder: &mut sui_transaction_builder::TransactionBuilder, 1936 | p0: Ref<'a, crate::bridge::message::BridgeMessage>, 1937 | ) -> Arg { 1938 | let p0 = p0.resolve_arg(builder); 1939 | builder 1940 | .move_call( 1941 | sui_transaction_builder::Function::new( 1942 | PACKAGE_ID, 1943 | Identifier::from_str(MODULE_NAME).unwrap(), 1944 | Identifier::from_str("to_parsed_token_transfer_message") 1945 | .unwrap(), 1946 | vec![], 1947 | ), 1948 | vec![p0.into()], 1949 | ) 1950 | .into() 1951 | } 1952 | pub fn token_amount<'a>( 1953 | builder: &mut sui_transaction_builder::TransactionBuilder, 1954 | p0: Ref<'a, crate::bridge::message::TokenTransferPayload>, 1955 | ) -> Arg { 1956 | let p0 = p0.resolve_arg(builder); 1957 | builder 1958 | .move_call( 1959 | sui_transaction_builder::Function::new( 1960 | PACKAGE_ID, 1961 | Identifier::from_str(MODULE_NAME).unwrap(), 1962 | Identifier::from_str("token_amount").unwrap(), 1963 | vec![], 1964 | ), 1965 | vec![p0.into()], 1966 | ) 1967 | .into() 1968 | } 1969 | pub fn token_ids<'a>( 1970 | builder: &mut sui_transaction_builder::TransactionBuilder, 1971 | p0: Ref<'a, crate::bridge::message::AddTokenOnSui>, 1972 | ) -> Arg> { 1973 | let p0 = p0.resolve_arg(builder); 1974 | builder 1975 | .move_call( 1976 | sui_transaction_builder::Function::new( 1977 | PACKAGE_ID, 1978 | Identifier::from_str(MODULE_NAME).unwrap(), 1979 | Identifier::from_str("token_ids").unwrap(), 1980 | vec![], 1981 | ), 1982 | vec![p0.into()], 1983 | ) 1984 | .into() 1985 | } 1986 | pub fn token_prices<'a>( 1987 | builder: &mut sui_transaction_builder::TransactionBuilder, 1988 | p0: Ref<'a, crate::bridge::message::AddTokenOnSui>, 1989 | ) -> Arg> { 1990 | let p0 = p0.resolve_arg(builder); 1991 | builder 1992 | .move_call( 1993 | sui_transaction_builder::Function::new( 1994 | PACKAGE_ID, 1995 | Identifier::from_str(MODULE_NAME).unwrap(), 1996 | Identifier::from_str("token_prices").unwrap(), 1997 | vec![], 1998 | ), 1999 | vec![p0.into()], 2000 | ) 2001 | .into() 2002 | } 2003 | pub fn token_target_address<'a>( 2004 | builder: &mut sui_transaction_builder::TransactionBuilder, 2005 | p0: Ref<'a, crate::bridge::message::TokenTransferPayload>, 2006 | ) -> Arg> { 2007 | let p0 = p0.resolve_arg(builder); 2008 | builder 2009 | .move_call( 2010 | sui_transaction_builder::Function::new( 2011 | PACKAGE_ID, 2012 | Identifier::from_str(MODULE_NAME).unwrap(), 2013 | Identifier::from_str("token_target_address").unwrap(), 2014 | vec![], 2015 | ), 2016 | vec![p0.into()], 2017 | ) 2018 | .into() 2019 | } 2020 | pub fn token_target_chain<'a>( 2021 | builder: &mut sui_transaction_builder::TransactionBuilder, 2022 | p0: Ref<'a, crate::bridge::message::TokenTransferPayload>, 2023 | ) -> Arg { 2024 | let p0 = p0.resolve_arg(builder); 2025 | builder 2026 | .move_call( 2027 | sui_transaction_builder::Function::new( 2028 | PACKAGE_ID, 2029 | Identifier::from_str(MODULE_NAME).unwrap(), 2030 | Identifier::from_str("token_target_chain").unwrap(), 2031 | vec![], 2032 | ), 2033 | vec![p0.into()], 2034 | ) 2035 | .into() 2036 | } 2037 | pub fn token_type<'a>( 2038 | builder: &mut sui_transaction_builder::TransactionBuilder, 2039 | p0: Ref<'a, crate::bridge::message::TokenTransferPayload>, 2040 | ) -> Arg { 2041 | let p0 = p0.resolve_arg(builder); 2042 | builder 2043 | .move_call( 2044 | sui_transaction_builder::Function::new( 2045 | PACKAGE_ID, 2046 | Identifier::from_str(MODULE_NAME).unwrap(), 2047 | Identifier::from_str("token_type").unwrap(), 2048 | vec![], 2049 | ), 2050 | vec![p0.into()], 2051 | ) 2052 | .into() 2053 | } 2054 | pub fn token_type_names<'a>( 2055 | builder: &mut sui_transaction_builder::TransactionBuilder, 2056 | p0: Ref<'a, crate::bridge::message::AddTokenOnSui>, 2057 | ) -> Arg> { 2058 | let p0 = p0.resolve_arg(builder); 2059 | builder 2060 | .move_call( 2061 | sui_transaction_builder::Function::new( 2062 | PACKAGE_ID, 2063 | Identifier::from_str(MODULE_NAME).unwrap(), 2064 | Identifier::from_str("token_type_names").unwrap(), 2065 | vec![], 2066 | ), 2067 | vec![p0.into()], 2068 | ) 2069 | .into() 2070 | } 2071 | pub fn update_asset_price_payload_new_price<'a>( 2072 | builder: &mut sui_transaction_builder::TransactionBuilder, 2073 | p0: Ref<'a, crate::bridge::message::UpdateAssetPrice>, 2074 | ) -> Arg { 2075 | let p0 = p0.resolve_arg(builder); 2076 | builder 2077 | .move_call( 2078 | sui_transaction_builder::Function::new( 2079 | PACKAGE_ID, 2080 | Identifier::from_str(MODULE_NAME).unwrap(), 2081 | Identifier::from_str("update_asset_price_payload_new_price") 2082 | .unwrap(), 2083 | vec![], 2084 | ), 2085 | vec![p0.into()], 2086 | ) 2087 | .into() 2088 | } 2089 | pub fn update_asset_price_payload_token_id<'a>( 2090 | builder: &mut sui_transaction_builder::TransactionBuilder, 2091 | p0: Ref<'a, crate::bridge::message::UpdateAssetPrice>, 2092 | ) -> Arg { 2093 | let p0 = p0.resolve_arg(builder); 2094 | builder 2095 | .move_call( 2096 | sui_transaction_builder::Function::new( 2097 | PACKAGE_ID, 2098 | Identifier::from_str(MODULE_NAME).unwrap(), 2099 | Identifier::from_str("update_asset_price_payload_token_id") 2100 | .unwrap(), 2101 | vec![], 2102 | ), 2103 | vec![p0.into()], 2104 | ) 2105 | .into() 2106 | } 2107 | pub fn update_bridge_limit_payload_limit<'a>( 2108 | builder: &mut sui_transaction_builder::TransactionBuilder, 2109 | p0: Ref<'a, crate::bridge::message::UpdateBridgeLimit>, 2110 | ) -> Arg { 2111 | let p0 = p0.resolve_arg(builder); 2112 | builder 2113 | .move_call( 2114 | sui_transaction_builder::Function::new( 2115 | PACKAGE_ID, 2116 | Identifier::from_str(MODULE_NAME).unwrap(), 2117 | Identifier::from_str("update_bridge_limit_payload_limit") 2118 | .unwrap(), 2119 | vec![], 2120 | ), 2121 | vec![p0.into()], 2122 | ) 2123 | .into() 2124 | } 2125 | pub fn update_bridge_limit_payload_receiving_chain<'a>( 2126 | builder: &mut sui_transaction_builder::TransactionBuilder, 2127 | p0: Ref<'a, crate::bridge::message::UpdateBridgeLimit>, 2128 | ) -> Arg { 2129 | let p0 = p0.resolve_arg(builder); 2130 | builder 2131 | .move_call( 2132 | sui_transaction_builder::Function::new( 2133 | PACKAGE_ID, 2134 | Identifier::from_str(MODULE_NAME).unwrap(), 2135 | Identifier::from_str( 2136 | "update_bridge_limit_payload_receiving_chain", 2137 | ) 2138 | .unwrap(), 2139 | vec![], 2140 | ), 2141 | vec![p0.into()], 2142 | ) 2143 | .into() 2144 | } 2145 | pub fn update_bridge_limit_payload_sending_chain<'a>( 2146 | builder: &mut sui_transaction_builder::TransactionBuilder, 2147 | p0: Ref<'a, crate::bridge::message::UpdateBridgeLimit>, 2148 | ) -> Arg { 2149 | let p0 = p0.resolve_arg(builder); 2150 | builder 2151 | .move_call( 2152 | sui_transaction_builder::Function::new( 2153 | PACKAGE_ID, 2154 | Identifier::from_str(MODULE_NAME).unwrap(), 2155 | Identifier::from_str("update_bridge_limit_payload_sending_chain") 2156 | .unwrap(), 2157 | vec![], 2158 | ), 2159 | vec![p0.into()], 2160 | ) 2161 | .into() 2162 | } 2163 | } 2164 | pub mod message_types { 2165 | use std::str::FromStr; 2166 | use move_binding_derive::{MoveStruct, Key}; 2167 | use move_types::{MoveType, Address, Identifier, ObjectId}; 2168 | use move_types::functions::{Arg, Ref, MutRef}; 2169 | pub const PACKAGE_ID: Address = Address::new([ 2170 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2171 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2172 | 0u8, 11u8, 2173 | ]); 2174 | pub const MODULE_NAME: &str = "message_types"; 2175 | pub fn add_tokens_on_sui( 2176 | builder: &mut sui_transaction_builder::TransactionBuilder, 2177 | ) -> Arg { 2178 | builder 2179 | .move_call( 2180 | sui_transaction_builder::Function::new( 2181 | PACKAGE_ID, 2182 | Identifier::from_str(MODULE_NAME).unwrap(), 2183 | Identifier::from_str("add_tokens_on_sui").unwrap(), 2184 | vec![], 2185 | ), 2186 | vec![], 2187 | ) 2188 | .into() 2189 | } 2190 | pub fn committee_blocklist( 2191 | builder: &mut sui_transaction_builder::TransactionBuilder, 2192 | ) -> Arg { 2193 | builder 2194 | .move_call( 2195 | sui_transaction_builder::Function::new( 2196 | PACKAGE_ID, 2197 | Identifier::from_str(MODULE_NAME).unwrap(), 2198 | Identifier::from_str("committee_blocklist").unwrap(), 2199 | vec![], 2200 | ), 2201 | vec![], 2202 | ) 2203 | .into() 2204 | } 2205 | pub fn emergency_op( 2206 | builder: &mut sui_transaction_builder::TransactionBuilder, 2207 | ) -> Arg { 2208 | builder 2209 | .move_call( 2210 | sui_transaction_builder::Function::new( 2211 | PACKAGE_ID, 2212 | Identifier::from_str(MODULE_NAME).unwrap(), 2213 | Identifier::from_str("emergency_op").unwrap(), 2214 | vec![], 2215 | ), 2216 | vec![], 2217 | ) 2218 | .into() 2219 | } 2220 | pub fn token( 2221 | builder: &mut sui_transaction_builder::TransactionBuilder, 2222 | ) -> Arg { 2223 | builder 2224 | .move_call( 2225 | sui_transaction_builder::Function::new( 2226 | PACKAGE_ID, 2227 | Identifier::from_str(MODULE_NAME).unwrap(), 2228 | Identifier::from_str("token").unwrap(), 2229 | vec![], 2230 | ), 2231 | vec![], 2232 | ) 2233 | .into() 2234 | } 2235 | pub fn update_asset_price( 2236 | builder: &mut sui_transaction_builder::TransactionBuilder, 2237 | ) -> Arg { 2238 | builder 2239 | .move_call( 2240 | sui_transaction_builder::Function::new( 2241 | PACKAGE_ID, 2242 | Identifier::from_str(MODULE_NAME).unwrap(), 2243 | Identifier::from_str("update_asset_price").unwrap(), 2244 | vec![], 2245 | ), 2246 | vec![], 2247 | ) 2248 | .into() 2249 | } 2250 | pub fn update_bridge_limit( 2251 | builder: &mut sui_transaction_builder::TransactionBuilder, 2252 | ) -> Arg { 2253 | builder 2254 | .move_call( 2255 | sui_transaction_builder::Function::new( 2256 | PACKAGE_ID, 2257 | Identifier::from_str(MODULE_NAME).unwrap(), 2258 | Identifier::from_str("update_bridge_limit").unwrap(), 2259 | vec![], 2260 | ), 2261 | vec![], 2262 | ) 2263 | .into() 2264 | } 2265 | } 2266 | pub mod treasury { 2267 | use std::str::FromStr; 2268 | use move_binding_derive::{MoveStruct, Key}; 2269 | use move_types::{MoveType, Address, Identifier, ObjectId}; 2270 | use move_types::functions::{Arg, Ref, MutRef}; 2271 | pub const PACKAGE_ID: Address = Address::new([ 2272 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2273 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2274 | 0u8, 11u8, 2275 | ]); 2276 | pub const MODULE_NAME: &str = "treasury"; 2277 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2278 | pub struct BridgeTokenMetadata { 2279 | pub id: u8, 2280 | pub decimal_multiplier: u64, 2281 | pub notional_value: u64, 2282 | pub native_token: bool, 2283 | } 2284 | impl BridgeTokenMetadata { 2285 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2286 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2287 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2288 | 0u8, 0u8, 0u8, 11u8, 2289 | ]); 2290 | } 2291 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2292 | pub struct BridgeTreasury { 2293 | pub treasuries: crate::sui::object_bag::ObjectBag, 2294 | pub supported_tokens: crate::sui::vec_map::VecMap< 2295 | String, 2296 | crate::bridge::treasury::BridgeTokenMetadata, 2297 | >, 2298 | pub id_token_type_map: crate::sui::vec_map::VecMap, 2299 | pub waiting_room: crate::sui::bag::Bag, 2300 | } 2301 | impl BridgeTreasury { 2302 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2303 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2304 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2305 | 0u8, 0u8, 0u8, 11u8, 2306 | ]); 2307 | } 2308 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2309 | pub struct ForeignTokenRegistration { 2310 | pub type_name: String, 2311 | pub uc: crate::sui::package::UpgradeCap, 2312 | pub decimal: u8, 2313 | } 2314 | impl ForeignTokenRegistration { 2315 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2316 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2317 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2318 | 0u8, 0u8, 0u8, 11u8, 2319 | ]); 2320 | } 2321 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2322 | pub struct NewTokenEvent { 2323 | pub token_id: u8, 2324 | pub type_name: String, 2325 | pub native_token: bool, 2326 | pub decimal_multiplier: u64, 2327 | pub notional_value: u64, 2328 | } 2329 | impl NewTokenEvent { 2330 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2331 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2332 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2333 | 0u8, 0u8, 0u8, 11u8, 2334 | ]); 2335 | } 2336 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2337 | pub struct TokenRegistrationEvent { 2338 | pub type_name: String, 2339 | pub decimal: u8, 2340 | pub native_token: bool, 2341 | } 2342 | impl TokenRegistrationEvent { 2343 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2344 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2345 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2346 | 0u8, 0u8, 0u8, 11u8, 2347 | ]); 2348 | } 2349 | #[derive(serde::Deserialize, serde::Serialize, Debug, MoveStruct)] 2350 | pub struct UpdateTokenPriceEvent { 2351 | pub token_id: u8, 2352 | pub new_price: u64, 2353 | } 2354 | impl UpdateTokenPriceEvent { 2355 | pub const TYPE_ORIGIN_ID: Address = Address::new([ 2356 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2357 | 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 2358 | 0u8, 0u8, 0u8, 11u8, 2359 | ]); 2360 | } 2361 | pub fn add_new_token<'a>( 2362 | builder: &mut sui_transaction_builder::TransactionBuilder, 2363 | p0: MutRef<'a, crate::bridge::treasury::BridgeTreasury>, 2364 | p1: Arg, 2365 | p2: Arg, 2366 | p3: Arg, 2367 | p4: Arg, 2368 | ) { 2369 | let p0 = p0.resolve_arg(builder); 2370 | let p1 = p1.resolve_arg(builder); 2371 | let p2 = p2.resolve_arg(builder); 2372 | let p3 = p3.resolve_arg(builder); 2373 | let p4 = p4.resolve_arg(builder); 2374 | builder 2375 | .move_call( 2376 | sui_transaction_builder::Function::new( 2377 | PACKAGE_ID, 2378 | Identifier::from_str(MODULE_NAME).unwrap(), 2379 | Identifier::from_str("add_new_token").unwrap(), 2380 | vec![], 2381 | ), 2382 | vec![p0.into(), p1.into(), p2.into(), p3.into(), p4.into()], 2383 | ); 2384 | } 2385 | pub fn burn<'a, T0: MoveType>( 2386 | builder: &mut sui_transaction_builder::TransactionBuilder, 2387 | p0: MutRef<'a, crate::bridge::treasury::BridgeTreasury>, 2388 | p1: Arg>, 2389 | ) { 2390 | let p0 = p0.resolve_arg(builder); 2391 | let p1 = p1.resolve_arg(builder); 2392 | builder 2393 | .move_call( 2394 | sui_transaction_builder::Function::new( 2395 | PACKAGE_ID, 2396 | Identifier::from_str(MODULE_NAME).unwrap(), 2397 | Identifier::from_str("burn").unwrap(), 2398 | vec![T0::type_()], 2399 | ), 2400 | vec![p0.into(), p1.into()], 2401 | ); 2402 | } 2403 | pub fn create<'a>( 2404 | builder: &mut sui_transaction_builder::TransactionBuilder, 2405 | ) -> Arg { 2406 | builder 2407 | .move_call( 2408 | sui_transaction_builder::Function::new( 2409 | PACKAGE_ID, 2410 | Identifier::from_str(MODULE_NAME).unwrap(), 2411 | Identifier::from_str("create").unwrap(), 2412 | vec![], 2413 | ), 2414 | vec![], 2415 | ) 2416 | .into() 2417 | } 2418 | pub fn decimal_multiplier<'a, T0: MoveType>( 2419 | builder: &mut sui_transaction_builder::TransactionBuilder, 2420 | p0: Ref<'a, crate::bridge::treasury::BridgeTreasury>, 2421 | ) -> Arg { 2422 | let p0 = p0.resolve_arg(builder); 2423 | builder 2424 | .move_call( 2425 | sui_transaction_builder::Function::new( 2426 | PACKAGE_ID, 2427 | Identifier::from_str(MODULE_NAME).unwrap(), 2428 | Identifier::from_str("decimal_multiplier").unwrap(), 2429 | vec![T0::type_()], 2430 | ), 2431 | vec![p0.into()], 2432 | ) 2433 | .into() 2434 | } 2435 | pub fn get_token_metadata<'a, T0: MoveType>( 2436 | builder: &mut sui_transaction_builder::TransactionBuilder, 2437 | p0: Ref<'a, crate::bridge::treasury::BridgeTreasury>, 2438 | ) -> Arg { 2439 | let p0 = p0.resolve_arg(builder); 2440 | builder 2441 | .move_call( 2442 | sui_transaction_builder::Function::new( 2443 | PACKAGE_ID, 2444 | Identifier::from_str(MODULE_NAME).unwrap(), 2445 | Identifier::from_str("get_token_metadata").unwrap(), 2446 | vec![T0::type_()], 2447 | ), 2448 | vec![p0.into()], 2449 | ) 2450 | .into() 2451 | } 2452 | pub fn mint<'a, T0: MoveType>( 2453 | builder: &mut sui_transaction_builder::TransactionBuilder, 2454 | p0: MutRef<'a, crate::bridge::treasury::BridgeTreasury>, 2455 | p1: Arg, 2456 | ) -> Arg> { 2457 | let p0 = p0.resolve_arg(builder); 2458 | let p1 = p1.resolve_arg(builder); 2459 | builder 2460 | .move_call( 2461 | sui_transaction_builder::Function::new( 2462 | PACKAGE_ID, 2463 | Identifier::from_str(MODULE_NAME).unwrap(), 2464 | Identifier::from_str("mint").unwrap(), 2465 | vec![T0::type_()], 2466 | ), 2467 | vec![p0.into(), p1.into()], 2468 | ) 2469 | .into() 2470 | } 2471 | pub fn notional_value<'a, T0: MoveType>( 2472 | builder: &mut sui_transaction_builder::TransactionBuilder, 2473 | p0: Ref<'a, crate::bridge::treasury::BridgeTreasury>, 2474 | ) -> Arg { 2475 | let p0 = p0.resolve_arg(builder); 2476 | builder 2477 | .move_call( 2478 | sui_transaction_builder::Function::new( 2479 | PACKAGE_ID, 2480 | Identifier::from_str(MODULE_NAME).unwrap(), 2481 | Identifier::from_str("notional_value").unwrap(), 2482 | vec![T0::type_()], 2483 | ), 2484 | vec![p0.into()], 2485 | ) 2486 | .into() 2487 | } 2488 | pub fn register_foreign_token<'a, T0: MoveType>( 2489 | builder: &mut sui_transaction_builder::TransactionBuilder, 2490 | p0: MutRef<'a, crate::bridge::treasury::BridgeTreasury>, 2491 | p1: Arg>, 2492 | p2: Arg, 2493 | p3: Ref<'a, crate::sui::coin::CoinMetadata>, 2494 | ) { 2495 | let p0 = p0.resolve_arg(builder); 2496 | let p1 = p1.resolve_arg(builder); 2497 | let p2 = p2.resolve_arg(builder); 2498 | let p3 = p3.resolve_arg(builder); 2499 | builder 2500 | .move_call( 2501 | sui_transaction_builder::Function::new( 2502 | PACKAGE_ID, 2503 | Identifier::from_str(MODULE_NAME).unwrap(), 2504 | Identifier::from_str("register_foreign_token").unwrap(), 2505 | vec![T0::type_()], 2506 | ), 2507 | vec![p0.into(), p1.into(), p2.into(), p3.into()], 2508 | ); 2509 | } 2510 | pub fn token_id<'a, T0: MoveType>( 2511 | builder: &mut sui_transaction_builder::TransactionBuilder, 2512 | p0: Ref<'a, crate::bridge::treasury::BridgeTreasury>, 2513 | ) -> Arg { 2514 | let p0 = p0.resolve_arg(builder); 2515 | builder 2516 | .move_call( 2517 | sui_transaction_builder::Function::new( 2518 | PACKAGE_ID, 2519 | Identifier::from_str(MODULE_NAME).unwrap(), 2520 | Identifier::from_str("token_id").unwrap(), 2521 | vec![T0::type_()], 2522 | ), 2523 | vec![p0.into()], 2524 | ) 2525 | .into() 2526 | } 2527 | pub fn update_asset_notional_price<'a>( 2528 | builder: &mut sui_transaction_builder::TransactionBuilder, 2529 | p0: MutRef<'a, crate::bridge::treasury::BridgeTreasury>, 2530 | p1: Arg, 2531 | p2: Arg, 2532 | ) { 2533 | let p0 = p0.resolve_arg(builder); 2534 | let p1 = p1.resolve_arg(builder); 2535 | let p2 = p2.resolve_arg(builder); 2536 | builder 2537 | .move_call( 2538 | sui_transaction_builder::Function::new( 2539 | PACKAGE_ID, 2540 | Identifier::from_str(MODULE_NAME).unwrap(), 2541 | Identifier::from_str("update_asset_notional_price").unwrap(), 2542 | vec![], 2543 | ), 2544 | vec![p0.into(), p1.into(), p2.into()], 2545 | ); 2546 | } 2547 | } 2548 | } 2549 | -------------------------------------------------------------------------------- /move-types/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "move-types" 3 | version = "0.1.0" 4 | authors = ["Mysten Labs "] 5 | license = "Apache-2.0" 6 | publish = false 7 | edition = "2021" 8 | 9 | [dependencies] 10 | serde.workspace = true 11 | sui-sdk-types = { git = "https://github.com/mystenlabs/sui-rust-sdk", features = ["serde"], rev="f0c8068" } 12 | sui-transaction-builder = { git = "https://github.com/mystenlabs/sui-rust-sdk", rev="f0c8068" } 13 | move-core-types = { git = "https://github.com/MystenLabs/sui.git", rev = "42ba6c0" } -------------------------------------------------------------------------------- /move-types/src/functions.rs: -------------------------------------------------------------------------------- 1 | use crate::MoveType; 2 | use serde::Serialize; 3 | use sui_sdk_types::Argument; 4 | use sui_transaction_builder::unresolved::Input; 5 | use sui_transaction_builder::{Serialized, TransactionBuilder}; 6 | 7 | pub enum Arg { 8 | Resolved(Argument), 9 | Raw(T), 10 | } 11 | 12 | pub enum Ref<'a, T> { 13 | Resolved(Argument), 14 | Raw(&'a T), 15 | } 16 | 17 | pub enum MutRef<'a, T> { 18 | Resolved(Argument), 19 | Raw(&'a mut T), 20 | } 21 | 22 | impl From for MutRef<'_, T> { 23 | fn from(value: Argument) -> Self { 24 | Self::Resolved(value) 25 | } 26 | } 27 | 28 | impl From for Ref<'_, T> { 29 | fn from(value: Argument) -> Self { 30 | Self::Resolved(value) 31 | } 32 | } 33 | 34 | impl From for Arg { 35 | fn from(value: Argument) -> Self { 36 | Self::Resolved(value) 37 | } 38 | } 39 | 40 | impl From for Arg { 41 | fn from(value: T) -> Self { 42 | Self::Raw(value) 43 | } 44 | } 45 | 46 | impl Arg { 47 | pub fn resolve_arg(self, builder: &mut TransactionBuilder) -> Self 48 | where 49 | T: ToInput, 50 | { 51 | match self { 52 | Arg::Raw(value) => Self::Resolved(builder.input(value.to_input())), 53 | _ => self, 54 | } 55 | } 56 | pub fn borrow(&self) -> Ref { 57 | match self { 58 | Arg::Resolved(a) => Ref::Resolved(a.clone()), 59 | Arg::Raw(p) => Ref::Raw(p), 60 | } 61 | } 62 | 63 | pub fn borrow_mut(&mut self) -> MutRef { 64 | match self { 65 | Arg::Resolved(a) => MutRef::Resolved(a.clone()), 66 | Arg::Raw(p) => MutRef::Raw(p), 67 | } 68 | } 69 | } 70 | 71 | impl Ref<'_, T> { 72 | pub fn resolve_arg(self, builder: &mut TransactionBuilder) -> Self 73 | where 74 | T: ToInput, 75 | { 76 | match self { 77 | Ref::Raw(value) => Self::Resolved(builder.input(value.to_input())), 78 | _ => self, 79 | } 80 | } 81 | } 82 | 83 | impl MutRef<'_, T> { 84 | pub fn resolve_arg(self, builder: &mut TransactionBuilder) -> Self 85 | where 86 | T: ToInput, 87 | { 88 | match self { 89 | MutRef::Raw(value) => Self::Resolved(builder.input(value.to_input())), 90 | _ => self, 91 | } 92 | } 93 | } 94 | impl From> for Argument { 95 | fn from(value: Arg) -> Self { 96 | match value { 97 | Arg::Resolved(arg) => arg, 98 | Arg::Raw(_) => panic!("Cannot use unresolved arg"), 99 | } 100 | } 101 | } 102 | impl From> for Argument { 103 | fn from(value: MutRef<'_, T>) -> Self { 104 | match value { 105 | MutRef::Resolved(arg) => arg, 106 | MutRef::Raw(_) => panic!("Cannot use unresolved arg"), 107 | } 108 | } 109 | } 110 | impl From> for Argument { 111 | fn from(value: Ref<'_, T>) -> Self { 112 | match value { 113 | Ref::Resolved(arg) => arg, 114 | Ref::Raw(_) => panic!("Cannot use unresolved arg"), 115 | } 116 | } 117 | } 118 | 119 | pub trait ToInput { 120 | fn to_input(&self) -> Input; 121 | } 122 | 123 | impl ToInput for T { 124 | fn to_input(&self) -> Input { 125 | Serialized(self).into() 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /move-types/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod functions; 2 | 3 | pub use move_core_types::u256::U256; 4 | use serde::Serialize; 5 | use std::str::FromStr; 6 | pub use sui_sdk_types::Address; 7 | pub use sui_sdk_types::Identifier; 8 | pub use sui_sdk_types::ObjectId; 9 | pub use sui_sdk_types::StructTag; 10 | pub use sui_sdk_types::TypeTag; 11 | 12 | pub const MOVE_STDLIB: Address = { 13 | let mut address = [0u8; 32]; 14 | address[31] = 1; 15 | Address::new(address) 16 | }; 17 | 18 | pub trait MoveType: Serialize { 19 | fn type_() -> TypeTag; 20 | } 21 | 22 | pub trait MoveStruct: Serialize { 23 | fn struct_type() -> StructTag; 24 | } 25 | 26 | impl MoveType for T { 27 | fn type_() -> TypeTag { 28 | TypeTag::Struct(Self::struct_type().into()) 29 | } 30 | } 31 | 32 | // todo: simplify with macros 33 | impl MoveType for u8 { 34 | fn type_() -> TypeTag { 35 | TypeTag::U8 36 | } 37 | } 38 | impl MoveType for u16 { 39 | fn type_() -> TypeTag { 40 | TypeTag::U16 41 | } 42 | } 43 | impl MoveType for u32 { 44 | fn type_() -> TypeTag { 45 | TypeTag::U32 46 | } 47 | } 48 | impl MoveType for u64 { 49 | fn type_() -> TypeTag { 50 | TypeTag::U64 51 | } 52 | } 53 | impl MoveType for u128 { 54 | fn type_() -> TypeTag { 55 | TypeTag::U128 56 | } 57 | } 58 | 59 | impl MoveType for U256 { 60 | fn type_() -> TypeTag { 61 | TypeTag::U256 62 | } 63 | } 64 | 65 | impl MoveType for Address { 66 | fn type_() -> TypeTag { 67 | TypeTag::Address 68 | } 69 | } 70 | 71 | impl MoveType for bool { 72 | fn type_() -> TypeTag { 73 | TypeTag::Bool 74 | } 75 | } 76 | impl MoveType for ObjectId { 77 | fn type_() -> TypeTag { 78 | TypeTag::Struct(Box::new(StructTag { 79 | address: Address::TWO, 80 | module: Identifier::from_str("object").unwrap(), 81 | name: Identifier::from_str("UID").unwrap(), 82 | type_params: vec![], 83 | })) 84 | } 85 | } 86 | 87 | impl MoveType for String { 88 | fn type_() -> TypeTag { 89 | TypeTag::Struct(Box::new(StructTag { 90 | address: MOVE_STDLIB, 91 | module: Identifier::from_str("string").unwrap(), 92 | name: Identifier::from_str("String").unwrap(), 93 | type_params: vec![], 94 | })) 95 | } 96 | } 97 | 98 | impl MoveType for &str { 99 | fn type_() -> TypeTag { 100 | String::type_() 101 | } 102 | } 103 | 104 | impl MoveType for Option { 105 | fn type_() -> TypeTag { 106 | TypeTag::Struct(Box::new(StructTag { 107 | address: MOVE_STDLIB, 108 | module: Identifier::from_str("option").unwrap(), 109 | name: Identifier::from_str("Option").unwrap(), 110 | type_params: vec![T::type_()], 111 | })) 112 | } 113 | } 114 | 115 | impl MoveType for Vec { 116 | fn type_() -> TypeTag { 117 | TypeTag::Vector(Box::new(T::type_())) 118 | } 119 | } 120 | 121 | pub trait Key: MoveStruct { 122 | fn id(&self) -> &ObjectId; 123 | } 124 | --------------------------------------------------------------------------------