@awar-dev/storage-manager
v0.2.4
Published
This package contains the smart contracts for the Storage System, built using Foundry and MUD (Mutable Universe Design).
Readme
Contracts Package
This package contains the smart contracts for the Storage System, built using Foundry and MUD (Mutable Universe Design).
Features
- Foundry: A fast, portable and modular toolkit for Ethereum application development.
- MUD: A framework for building decentralized, autonomous worlds.
- Solidity: The primary language for writing smart contracts on Ethereum.
Getting Started
Prerequisites
Installation
pnpm installRunning Tests
forge testTo Use
To use the StorageSystem in your MUD project, you need to import the package by installing it in your MUD project repo with the following command:
pnpm add @awar-dev/storage-managerThen you need to configure the Storage System on your Smart Storage Unit by importing the StorageSystemLib into a script with:
import { storageSystem } from "@awar-dev/storage-manager/codegen/systems/StorageSystemLib";and create a new bucket with the following function call:
storageSystem.createNestedBuckets(smartStorageId, bucketName);You can then use the Storage System to manage your storage needs in the game. By default - this created bucket will function like a tribal storage (where anyone in the deployer's tribe can both deposit and withdraw items from it). If you want to create a private bucket, you can will need to create a system that implements one or both of the following methods:
function canDeposit(uint256 smartObjectId, bytes32 bucketId, address sender) public returns (bool)function canWithdraw(uint256 smartObjectId, bytes32 bucketId, address sender) public returns (bool)After deploying the access control system with one or both of the above methods, you can set it to be used by the Storage System with the following fn call in a script run by the owner of the bucket:
storageSystem.setAccessSystemId(smartStorageId, bucketId, systemId);Project Structure
src/
├── codegen/ # Autogenerated code from MUD
├── systems/
│ ├── StorageSystem/
│ │ └── Constants.sol # Constants for the Storage System
│ │ └── StorageSystem.sol # Main system contract governing the usage of allocatable storage
│ │ └── Errors.sol # Outlines errors for the Storage System
│ ├── StoreProxySystem/
│ │ └── StoreProxySystem.sol # System contract acting as an immutable proxy on top of item inventory
│ └── StringPacker/
│ └── StringPacker.sol # System contract that packs and unpacks strings for use in creating buckets.
script/ # Deployment scripts
test/ # Test contracts
mud.config.ts # MUD configuration file
foundry.toml # Foundry configuration fileConfiguration
Environment Variables
The following environment variables are used to configure the contracts:
WORLD_ADDRESS: The address of the MUD World contract.CHAIN_ID: The ID of the Ethereum chain.PRIVATE_KEY: The private key of the deployer account.RPC_URL: The URL of the Ethereum RPC endpoint.
These variables can be set in the .env, .env.local, and .env.pyrope files.
Scripts
The following scripts are defined in package.json:
build: Builds the contracts usingmud build.clean: Cleans the build artifacts and autogenerated code.deploy:local: Deploys the contracts to a local development network.deploy:pyrope: Deploys the contracts to the Pyrope testnet.lint: Runs the code linters.prettier: Formats the Solidity code.solhint: Lints the Solidity code.test: Runs the tests using Forge.coverage: Generates code coverage reports.
