BibliothecaDAO / realms-contracts

Realms Monorepo for Ethereum contracts and Starknet contracts.
https://bibliothecadao.xyz/
MIT License
87 stars 33 forks source link

Initializing `ModuleController` via `Arbiter::batch_set_controller_addresses` module address missing #219

Closed d-s-i closed 2 years ago

d-s-i commented 2 years ago

When initializing the game you need to deploy everything and then set module addresses to the controller (via the arbiter). There is a mismatch between the Arbiter batch_set_controller_addresses (which call IModuleController.set_initial_module_addresses). and the real set_initial_module_addresses function in the ModuleController.

Here is the function call in Arbiter.cairo:

@external
func batch_set_controller_addresses{
    syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr
}(
    module_01_addr: felt,
    module_02_addr: felt,
    module_03_addr: felt,
    module_04_addr: felt,
    module_06_addr: felt,
) {
    Ownable.assert_only_owner();
    let (controller) = controller_address.read();
    IModuleController.set_initial_module_addresses(
        controller, module_01_addr, module_02_addr, module_03_addr, module_04_addr, module_06_addr
    );
    return ();
}

It gives module addresses from 1 to 6 omitting the 5th.

In the ModuleController however, it is expecting this 5th module

@external
func set_initial_module_addresses{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
    settling_module_addr: felt,
    resources_module_addr: felt,
    buildings_module_addr: felt,
    calculator_module_addr: felt,
    module_05_addr: felt,
    module_06_addr: felt,
) {
    only_arbiter();

    // Settling Logic
    address_of_module_id.write(ModuleIds.Settling, settling_module_addr);
    module_id_of_address.write(settling_module_addr, ModuleIds.Settling);

    // Resources Logic
    address_of_module_id.write(ModuleIds.Resources, resources_module_addr);
    module_id_of_address.write(resources_module_addr, ModuleIds.Resources);

    // Buildings Logic
    address_of_module_id.write(ModuleIds.Buildings, buildings_module_addr);
    module_id_of_address.write(buildings_module_addr, ModuleIds.Buildings);

    // Calculator Logic
    address_of_module_id.write(ModuleIds.Calculator, calculator_module_addr);
    module_id_of_address.write(calculator_module_addr, ModuleIds.Calculator);

    // Combat Logic
    address_of_module_id.write(ModuleIds.L06_Combat, module_06_addr);
    module_id_of_address.write(module_06_addr, ModuleIds.L06_Combat);

    // # Crypts Logic
    // address_of_module_id.write(ModuleIds.L07_Crypts, module_07_addr)
    // module_id_of_address.write(module_07_addr, ModuleIds.L07_Crypts)

    // # Crypts Resources Logic
    // address_of_module_id.write(ModuleIds.L08_Crypts_Resources, module_08_addr)
    // module_id_of_address.write(module_08_addr, ModuleIds.L08_Crypts_Resources)

    return ();
}

So we should either remove the 5th module in ModuleController.cairo or add it in Arbiter.cairo. Not sure how to make the pull request to solve this.

ponderingdemocritus commented 2 years ago

closing as is being actioned in another PR