Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DON'T MERGE] Supra_container #113

Open
wants to merge 5 commits into
base: vm_upgrade_branch
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions aptos-move/framework/supra-framework/sources/container.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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, vector<u64>>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is a map from address to vector<u64>, it is supposed to be from module address to container id. Assuming container id to be a unique sequence number, this can be a map address -> u64, or rather it can be Table<address,u64>.

id_containerMetaData_map: Table<u64, ContainerMetadata>
}

//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<address>,
/// Pending proposal module address,
pending_proposal: SimpleMap<u64, vector<u8>>,
//TODO type information for the coin
/// The address of the customer asset reciver
customer_asset_receiver: address,
/// The address of the supra coin reciver
supra_coin_receiver: address
}

/// Initialize the container metadata storage
public fun initialize(supra_framework: &signer) {
system_addresses::assert_supra_framework(supra_framework);
if (!exists<AddressToContainerMap>(@supra_framework)) {
move_to<AddressToContainerMap>(
supra_framework,
AddressToContainerMap {
address_container_map: simple_map::new(),
}
);
}
}

/// Create a new container
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<AddressToContainerMap>(@supra_framework);
simple_map::upsert(&mut container.address_container_map, address, container_metadata);
}

//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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe creation of module should be up to container owner only. So add_module_to_container should not need supra_framework: &signer, it should need approval of owner, where owner could be single or multisig authority.

system_addresses::assert_supra_framework(supra_framework);
assert(exists<AddressToContainerMap>(@supra_framework), 1);
let container = borrow_global_mut<AddressToContainerMap>(@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 get_container_metadata(supra_framework: &signer, address: address): ContainerMetadata acquires AddressToContainerMap {
system_addresses::assert_supra_framework(supra_framework);
assert(exists<AddressToContainerMap>(address), 1);
let container = borrow_global<AddressToContainerMap>(@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<ContainerMetadata>(address);
//DO IT in a nicer way
*container_metadata = container_metadata;
}
}