o2-tools 0.1.23

Reusable tooling for trade account and order book contract interactions on Fuel
Documentation
use fuels::{
    accounts::{
        signers::private_key::PrivateKeySigner,
        wallet::{
            Unlocked,
            Wallet,
        },
    },
    macros::abigen,
    programs::contract::Contract,
    tx::StorageSlot,
    types::{
        ContractId,
        Salt,
        transaction::TxPolicies,
    },
};

abigen!(Contract(
    name = "Src20Mock",
    abi = "artifacts/test_artifacts/src20-mock-abi.json"
));

pub const SRC20_MOCK_BYTECODE: &[u8] =
    include_bytes!("../artifacts/test_artifacts/src20-mock.bin");

pub const SRC20_MOCK_STORAGE_SLOTS: &str =
    include_str!("../artifacts/test_artifacts/src20-mock-storage_slots.json");

pub async fn setup_src20_mock(
    wallet: &Wallet<Unlocked<PrivateKeySigner>>,
) -> (Src20Mock<Wallet<Unlocked<PrivateKeySigner>>>, ContractId) {
    let storage_slots: Vec<StorageSlot> = serde_json::from_str(SRC20_MOCK_STORAGE_SLOTS)
        .expect("failed to parse storage slots");

    let id =
        Contract::regular(SRC20_MOCK_BYTECODE.to_vec(), Salt::default(), storage_slots)
            .deploy(wallet, TxPolicies::default())
            .await
            .unwrap()
            .contract_id;

    let instance = Src20Mock::new(id, wallet.clone());

    (instance, id)
}