From bcb6699b637bdcf0a34c89934edd5477f4bb2b9d Mon Sep 17 00:00:00 2001 From: axiongsupra Date: Mon, 21 Oct 2024 19:48:14 -0700 Subject: [PATCH 1/5] Draft for supra container --- .../supra-framework/sources/Container.move | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 aptos-move/framework/supra-framework/sources/Container.move diff --git a/aptos-move/framework/supra-framework/sources/Container.move b/aptos-move/framework/supra-framework/sources/Container.move new file mode 100644 index 0000000000000..317a98b9e3e1d --- /dev/null +++ b/aptos-move/framework/supra-framework/sources/Container.move @@ -0,0 +1,50 @@ +module supra_framework::Container { + + use aptos_std::simple_map; + use aptos_std::simple_map::SimpleMap; + use supra_framework::system_addresses; + + struct AddressToContainerMap has key, store { + address_container_map: SimpleMap, + } + + //TODO: Add more fields for container metadata if needed + struct ContainerMetadata has copy, drop, store { + /// The unique identifier of the supra container + container_indentifier: u64, + /// The addresses of modules in the container + Module_adresses: vector
, + /// The address of the customer asset reciver + customer_asset_reciver: address, + /// The address of the supra coin reciver + supra_coin_reciver: address + } + + /// Initialize the container metadata storage + public fun initialize(supra_framework: &signer) { + system_addresses::assert_supra_framework(supra_framework); + if (!exists(@supra_framework)) { + move_to( + supra_framework, + AddressToContainerMap { + address_container_map: simple_map::new(), + } + ); + } + } + + #[view] + public fun GetContainerMetadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap { + system_addresses::assert_supra_framework(supra_framework); + assert(exists(address), 1); + let container = borrow_global(@supra_framework); + *simple_map::borrow(&container.address_container_map, &address) + } + + public fun UpdateContainerMetadata(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires ContainerMetadata { + system_addresses::assert_supra_framework(supra_framework); + let container_metadata = borrow_global_mut(address); + //DO IT in a nicer way + *container_metadata = container_metadata; + } +} From 5721866426cd4776f64ab18c5e058f4092685c7d Mon Sep 17 00:00:00 2001 From: axiongsupra Date: Mon, 21 Oct 2024 20:26:30 -0700 Subject: [PATCH 2/5] More helper functions --- .../supra-framework/sources/Container.move | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aptos-move/framework/supra-framework/sources/Container.move b/aptos-move/framework/supra-framework/sources/Container.move index 317a98b9e3e1d..4e80cb43600b8 100644 --- a/aptos-move/framework/supra-framework/sources/Container.move +++ b/aptos-move/framework/supra-framework/sources/Container.move @@ -1,5 +1,6 @@ module supra_framework::Container { + use std::vector; use aptos_std::simple_map; use aptos_std::simple_map::SimpleMap; use supra_framework::system_addresses; @@ -33,6 +34,22 @@ module supra_framework::Container { } } + /// Add a new container metadata to the storage + public fun AddContainerMetadata(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { + system_addresses::assert_supra_framework(supra_framework); + let container = borrow_global_mut(@supra_framework); + simple_map::upsert(&mut container.address_container_map, address, container_metadata); + } + + /// Add one module address to the container metadata + public fun AddModuleToContainer(supra_framework: &signer, address: address, module_address: address) acquires AddressToContainerMap { + system_addresses::assert_supra_framework(supra_framework); + assert(exists(@supra_framework), 1); + let container = borrow_global_mut(@supra_framework); + let container_metadata = simple_map::borrow_mut(&mut container.address_container_map, &address); + vector::insert(container_metadata.Module_adresses, module_address); + } + #[view] public fun GetContainerMetadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap { system_addresses::assert_supra_framework(supra_framework); From 477095e4a39b4f4705197856471814fd01547bd8 Mon Sep 17 00:00:00 2001 From: axiongsupra Date: Mon, 21 Oct 2024 20:27:00 -0700 Subject: [PATCH 3/5] Lower case for move file name --- .../supra-framework/sources/{Container.move => container.move} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename aptos-move/framework/supra-framework/sources/{Container.move => container.move} (98%) diff --git a/aptos-move/framework/supra-framework/sources/Container.move b/aptos-move/framework/supra-framework/sources/container.move similarity index 98% rename from aptos-move/framework/supra-framework/sources/Container.move rename to aptos-move/framework/supra-framework/sources/container.move index 4e80cb43600b8..692d2c0a6d66e 100644 --- a/aptos-move/framework/supra-framework/sources/Container.move +++ b/aptos-move/framework/supra-framework/sources/container.move @@ -1,4 +1,4 @@ -module supra_framework::Container { +module supra_framework::container { use std::vector; use aptos_std::simple_map; From 3ed4e457851b3dfb097895a3f1b9b7b9ee7a54d5 Mon Sep 17 00:00:00 2001 From: axiongsupra Date: Mon, 21 Oct 2024 21:11:16 -0700 Subject: [PATCH 4/5] Add a few todo for discussion --- .../supra-framework/sources/container.move | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/supra-framework/sources/container.move b/aptos-move/framework/supra-framework/sources/container.move index 692d2c0a6d66e..196def1e12aaf 100644 --- a/aptos-move/framework/supra-framework/sources/container.move +++ b/aptos-move/framework/supra-framework/sources/container.move @@ -3,18 +3,26 @@ module supra_framework::container { use std::vector; use aptos_std::simple_map; use aptos_std::simple_map::SimpleMap; + use aptos_std::table::Table; use supra_framework::system_addresses; struct AddressToContainerMap has key, store { - address_container_map: SimpleMap, + address_container_map: SimpleMap>, + id_containerMetaData_map: Table } //TODO: Add more fields for container metadata if needed + //TODO: Group discussion: charging metrics struct ContainerMetadata has copy, drop, store { + container_owner: address, + //TODO enforce uniqueness of container_indentifier /// The unique identifier of the supra container container_indentifier: u64, /// The addresses of modules in the container Module_adresses: vector
, + /// Pending proposal module address, + pending_proposal: SimpleMap>, + //TODO type information for the coin /// The address of the customer asset reciver customer_asset_reciver: address, /// The address of the supra coin reciver @@ -34,15 +42,22 @@ module supra_framework::container { } } - /// Add a new container metadata to the storage - public fun AddContainerMetadata(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { + /// Create a new container + public fun creat_container(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { system_addresses::assert_supra_framework(supra_framework); let container = borrow_global_mut(@supra_framework); simple_map::upsert(&mut container.address_container_map, address, container_metadata); } - /// Add one module address to the container metadata - public fun AddModuleToContainer(supra_framework: &signer, address: address, module_address: address) acquires AddressToContainerMap { + //TODO design choice: 1) Supraframework create container 2) every one can create container, there would be a charge + // the charge would go to some beneficiary address, the beneficiary address would be set and change by the supraframework + + //TODO API to view and modify the metadata and requires the container owner's signer + + //TODO Task for Aosen: how this will be published and how can we get the address back + + /// Add one module address to the container + public fun add_module_to_container(supra_framework: &signer, address: address, module_address: address) acquires AddressToContainerMap { system_addresses::assert_supra_framework(supra_framework); assert(exists(@supra_framework), 1); let container = borrow_global_mut(@supra_framework); @@ -51,7 +66,7 @@ module supra_framework::container { } #[view] - public fun GetContainerMetadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap { + public fun get_container_metadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap { system_addresses::assert_supra_framework(supra_framework); assert(exists(address), 1); let container = borrow_global(@supra_framework); From 7ddbd898185cf5f2931df613fa8f972e78b2334a Mon Sep 17 00:00:00 2001 From: Aric <158555905+axiongsupra@users.noreply.github.com> Date: Mon, 18 Nov 2024 19:22:23 -0800 Subject: [PATCH 5/5] Naming Co-authored-by: Saurabh Joshi <106232965+sjoshisupra@users.noreply.github.com> --- aptos-move/framework/supra-framework/sources/container.move | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aptos-move/framework/supra-framework/sources/container.move b/aptos-move/framework/supra-framework/sources/container.move index 196def1e12aaf..9745a0cd65fe8 100644 --- a/aptos-move/framework/supra-framework/sources/container.move +++ b/aptos-move/framework/supra-framework/sources/container.move @@ -24,9 +24,9 @@ module supra_framework::container { pending_proposal: SimpleMap>, //TODO type information for the coin /// The address of the customer asset reciver - customer_asset_reciver: address, + customer_asset_receiver: address, /// The address of the supra coin reciver - supra_coin_reciver: address + supra_coin_receiver: address } /// Initialize the container metadata storage @@ -43,7 +43,7 @@ module supra_framework::container { } /// Create a new container - public fun creat_container(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { + public fun create_container(supra_framework: &signer, address: address, container_metadata: ContainerMetadata) acquires AddressToContainerMap { system_addresses::assert_supra_framework(supra_framework); let container = borrow_global_mut(@supra_framework); simple_map::upsert(&mut container.address_container_map, address, container_metadata);