_______ __ __ __
| \| \ | \ / \
| โโโโโโโ\ โโ ______ __ __| โโ\ / โโ ______ _______ ______ ______ ______ ______
| โโ__/ โโ โโ| \| \ | \ โโโ\ / โโโ| \| \ | \ / \ / \ / \
| โโ โโ โโ \โโโโโโ\ โโ | โโ โโโโ\ โโโโ \โโโโโโ\ โโโโโโโ\ \โโโโโโ\ โโโโโโ\ โโโโโโ\ โโโโโโ\
| โโโโโโโ| โโ/ โโ โโ | โโ โโ\โโ โโ โโ/ โโ โโ | โโ/ โโ โโ | โโ โโ โโ โโ \โโ
| โโ | โโ โโโโโโโ โโ__/ โโ โโ \โโโ| โโ โโโโโโโ โโ | โโ โโโโโโโ โโ__| โโ โโโโโโโโ โโ
| โโ | โโ\โโ โโ\โโ โโ โโ \โ | โโ\โโ โโ โโ | โโ\โโ โโ\โโ โโ\โโ \ โโ
\โโ \โโ \โโโโโโโ_\โโโโโโโ\โโ \โโ \โโโโโโโ\โโ \โโ \โโโโโโโ_\โโโโโโโ \โโโโโโโ\โโ
| \__| โโ | \__| โโ
\โโ โโ \โโ โโ
\โโโโโโ \โโโโโโ
Play Manager is the smart contract companion to Conductive Instant Play. Conductive Instant Play is an SDK that enables games to intuitively persist in-game events to multiple blockchains without the overhead, integration and budget required in web3. No gas, no wallets, no contracts -- it just works.
.
โโโ ๐ lib (library imports)
โ โโโ ๐ forge-std (forge standard library)
โ โโโ ๐ openzeppelin-contracts (openzeppelin contract libs)
โ โโโ ๐ openzeppelin-upgrades (openzeppelin upgrade libs)
โโโ ๐ out (output directory)
โโโ ๐ src
โ โโโ ๐ค PlayManager.sol (smart contract)
โโโ ๐ test
โ โโโ ๐งช PlayManager.t.sol (smart contract test file)
โโโ โ๏ธ foundry.toml (foundry config)
โโโ โฝ gas-profile.txt (gas used per test function)
โโโ ๐ remappings.txt (remappings for solc)
โโโ โ๏ธ slither.config.json (remappings for slither)
Functionality is straight-forward for v1.0.0:
- ๐ฎ Basic game event logging
createAccount(uint256 accountType)
- create a new accountstartSession(uint256 sessionType)
- start a new sessiondailyLogin(uint256 sessionType, string calldata sessionId, string calldata userId)
- log a daily login- ... a LOT more to come
- ๐ฐ๏ธ Events directly monitored by Instant Play Service backend / client API
- โจ Upgradeable via UUPS proxy method
- โฝ Optimized for minimal wallet gas usage
- ๐ Secured via OpenZeppelin libraries
- โ๏ธ Configurable, upgradeable and pauseable via master wallet
This repository is setup to use Foundry for development, testing and deployment. Foundry is a fast and lightweight toolchain vs. Hardhat / Brownie / etc. created by the gigachads at Paradigm.
1. Download Foundry install script:
$ curl -L https://foundry.paradigm.xyz | bash
2. Install Foundry CLI
$ foundryup
If you have issues with the install script (like I did with libusb
), you can install and build Foundry manually:
1. Install Rust
$ curl https://sh.rustup.rs -sSf | sh
2. Use crates (Rust package manager) to build and install foundry
$ cargo install --git https://github.com/foundry-rs/foundry foundry-cli anvil chisel --bins --locked
Next clone the repo
git clone https://github.com/conductiveai/playmanager.git
cd playmanager
To run tests in the tests
directory, run:
forge test
forge build
The build command will compile the contract and output the compiled contract to the out
directory. The build command will also generate a remappings.txt
file which is used by the forge test
command to run tests.
forge flatten --output src/PlayManager.flattened.sol src/PlayManager.sol
Output:
The flatten command will concatenate all the imports into a single file. This is useful for running static analysis tools like Slither.
forge inspect src/PlayManager.sol:PlayManager abi > PlayManager.abi.json
The constructors are position based, in our case it is app name and app ID. The constructor is called when the contract is deployed. The constructor is only called once, when the contract is first deployed. The constructor is not called when the contract is upgraded
function initialize(string memory _appName, string memory _appID) initializer public {}
_appName
- name of the game_appID
- project UUID of the game
Deployment is done via forge create
:
$ forge create PlayManager --rpc-url https://rpc.ankr.com/polygon_mumbai --private-key 0xd34db33fd00d src/PlayManager.flattened.sol --constructor-args "SuperGigaChad" "3411297c-57d8-4704-8ca1-39935ebc92c9"
[โ ข] Compiling...
[โ ] Compiling 30 files with 0.8.19
[โ ] Solc 0.8.19 finished in 1.69s
Compiler run successful
Deployer: 0x1876004e862243c696806497dc05066b
Deployed to: 0x48917efa3f514b2b988c07d09aa2f505
Transaction hash: 0x1876004e862243c696806497dc05066b48917efa3f51
(Remember the constructor above, argument 1 is app name, argument 2 is app ID)
You can also set the deploying account private key via
export privateKey=0xd34db33fd00d
๐บ Walkthrough video coming soon
Anvil is a local testnet the comes with Foundry CLI.
forge anvil start
Your local RPC node will be running on http://127.0.0.1:8545
You can also easily verify your contract via CLI by running:
forge verify-contract --chain-id 1 --num-of-optimizations 200 --constructor-args (cast abi-encode "constructor(string,string)" "SuperGigaChad" "3411297c-57d8-4704-8ca1-39935ebc92c9" --compiler-version v0.8.0+commit.c7dfd78e 0xContractAddressHere src/PlayManager.flattened.sol:PlayManager <your-blockexplorer-key>
PlayManager implements the UUPSUpgradeable library from OpenZeppelin. This allows the contract to be upgraded via the function _upgradeToAndCall(newImplementation, data);
which is called by the upgradeToAndCall
function in the proxy contract.
You can find an implementation of this here.
- Slither is an open-source contract security framework written in Python. It runs a suite of vulnerability detectors and prints visual information about contract detail. This is the output of running Slither on the PlayManager contract:
pip3 install slither-analyzer
pip3 install solc-select
solc-select install 0.8.13
solc-select use 0.8.13
slither src/PlayManager.flattened.sol
Output running Slither on the PlayManager contract:
- Multi-party auth (client, master wallet, etc.)
- Client contract inheritance for ERC20, ERC721, and ERC1155
- SDK CRUD primitives for ERC20, ERC721, and ERC1155