From 9b6be0f3d4aac18b5073a4508c66ac3d9f640669 Mon Sep 17 00:00:00 2001 From: Foivos Date: Fri, 7 Jun 2024 15:36:07 +0300 Subject: [PATCH] added some structs, adding squid structs next --- .../squid/types/deepbook_v2_swap_data.move | 26 ++++++ scripts/bcs.js | 85 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 move/squid/sources/squid/types/deepbook_v2_swap_data.move create mode 100644 scripts/bcs.js diff --git a/move/squid/sources/squid/types/deepbook_v2_swap_data.move b/move/squid/sources/squid/types/deepbook_v2_swap_data.move new file mode 100644 index 00000000..7e069c4a --- /dev/null +++ b/move/squid/sources/squid/types/deepbook_v2_swap_data.move @@ -0,0 +1,26 @@ +module squid::deepbook_v2_swap_data { + public struct DeepbookV2SwapData { + swap_type: u8, + pool_id: address, + has_base: bool, + min_output: u64, + base_type: String, + quote_type: String, + lot_size: u64, + should_sweep: bool, + } + + entry fun new(data: vector): DeepbookV2SwapData { + let bcs = bcs::new(data); + DeepbookV2SwapData { + swap_type: bcs.peel_u8(), + pool_id: address(), + has_base: bcs.peel_bool(), + min_output: bcs.peel_u64(), + base_type: ascii::string(bcs.peel_vec_u8()), + quote_type: ascii::string(bcs.peel_vec_u8()), + lot_size: bcs.peel_u64(), + should_sweep: bcs.peel_bool(), + } + } +} \ No newline at end of file diff --git a/scripts/bcs.js b/scripts/bcs.js new file mode 100644 index 00000000..0dd290ae --- /dev/null +++ b/scripts/bcs.js @@ -0,0 +1,85 @@ +const { bcs } = require('@mysten/sui.js/bcs'); + + +function getAxelarStructs() { + const Bytes32 = bcs.struct('Bytes32', { + bytes: bcs.Address, + }); + + const Message = bcs.struct('Message', { + source_chain: bcs.String, + message_id: bcs.String, + source_address: bcs.String, + destination_id: Address, + payload_hash: Bytes32, + }); + + const WeightedSigner = bcs.struct('WeightedSigner', { + pubkey: bcs.vector(bcs.U8), + weight: bcs.U128, + }); + + const WeightedSigners = bcs.struct('WeightedSigners', { + signers: bcs.vector(WeightedSigner), + threshold: bcs.U128, + nonce: Bytes32, + }); + + const Signature = bcs.struct('Signature', { + bytes: bcs.vector(bcs.U8), + }) + + const Proof = bcs.struct('Proof', { + signers: WeightedSigners, + signatures: bcs.vector(Signature), + }) + + const MessageToSign = bcs.struct('MessageToSign', { + domain_separator: Bytes32, + signers_hash: Bytes32, + data_hash: Bytes32, + }); + + const Function = bcs.struct('Function', { + package_id: bcs.Address, + module_name: bcs.String, + name: bcs.String, + }); + + /// Arguments are prefixed with: + /// - 0 for objects followed by exactly 32 bytes that cointain the object id + /// - 1 for pures followed by the bcs encoded form of the pure + /// - 2 for the call contract object, followed by nothing (to be passed into the target function) + /// - 3 for the payload of the contract call (to be passed into the intermediate function) + /// - 4 for an argument returned from a previous move call, followed by a u8 specified which call to get the return of (0 for the first transaction AFTER the one that gets ApprovedMessage out), and then another u8 specifying which argument to input. + const MoveCall = bcs.struct('MoveCall', { + function: Function, + arguments: bcs.vector(bcs.vector(bcs.U8)), + type_arguments: bcs.vector(bcs.String), + }); + + const Transaction = bcs.struct('Transaction', { + is_final: bcs.Bool, + move_calls: bcs.vector(MoveCall), + }); + + const EncodedMessage = bcs.struct('EncodedMessage', { + message_type: bcs.U8, + data: bcs.vector(bcs.U8), + }); + return { + Bytes32, + Message, + WeightedSigner, + WeightedSigners, + Signature, + Proof, + MessageToSign, + Function, + MoveCall, + Transaction, + EncodedMessage, + } +}; + +