o2-tools 0.4.8-rc2

Reusable tooling for trade account and order book contract interactions on Fuel
Documentation
//! eval-minter bindings and initialization behind the generic SRC-14 proxy.
pub use crate::generic_proxy::GenericProxyDeployConfig as EvalMinterDeployConfig;
use crate::generic_proxy::{
    GenericProxyContract,
    GenericProxyDeployment,
};
use anyhow::{
    Context,
    Result,
};
use fuels::prelude::*;

abigen!(Contract(
    name = "EvalMinterContract",
    abi = "artifacts/eval-minter/eval-minter-abi.json"
));
pub const DEFAULT_ADMIN_ROLE: u64 = 0;
pub const PAUSER_ROLE: u64 = 3;
pub const MINTER_ROLE: u64 = 1;
pub const EVAL_MINTER_BYTECODE: &[u8] =
    include_bytes!("../artifacts/eval-minter/eval-minter.bin");
pub const EVAL_MINTER_STORAGE: &[u8] =
    include_bytes!("../artifacts/eval-minter/eval-minter-storage_slots.json");

pub struct EvalMinterDeployment<W: Account> {
    pub minter: EvalMinterContract<W>,
    pub proxy: GenericProxyContract<W>,
    pub contract_id: ContractId,
    pub blob_id: ContractId,
}
impl<W: Account + Clone> EvalMinterDeployment<W> {
    /// Reuse pinned IDs and upgrade only when explicitly requested. Operational roles are explicit.
    pub async fn deploy(wallet: &W, config: &EvalMinterDeployConfig) -> Result<Self> {
        let deployed = GenericProxyDeployment::deploy(
            wallet,
            config,
            EVAL_MINTER_BYTECODE,
            EVAL_MINTER_STORAGE,
        )
        .await?;
        let minter = EvalMinterContract::new(deployed.contract_id, wallet.clone());
        if !minter
            .methods()
            .initialized()
            .simulate(Execution::state_read_only())
            .await?
            .value
        {
            minter
                .methods()
                .initialize()
                .call()
                .await
                .context("initialize EvalMinter as its proxy owner")?;
        }
        Ok(Self {
            minter,
            proxy: deployed.proxy,
            contract_id: deployed.contract_id,
            blob_id: deployed.blob_id,
        })
    }
}
#[cfg(test)]
#[path = "eval_minter_tests.rs"]
mod tests;