Skip to content

conductiveai/playmanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

24 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

banner

 _______  __                   __       __                                                       
|       \|  \                 |  \     /  \                                                      
| โ–“โ–“โ–“โ–“โ–“โ–“โ–“\ โ–“โ–“ ______  __    __| โ–“โ–“\   /  โ–“โ–“ ______  _______   ______   ______   ______   ______  
| โ–“โ–“__/ โ–“โ–“ โ–“โ–“|      \|  \  |  \ โ–“โ–“โ–“\ /  โ–“โ–“โ–“|      \|       \ |      \ /      \ /      \ /      \ 
| โ–“โ–“    โ–“โ–“ โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“\ โ–“โ–“  | โ–“โ–“ โ–“โ–“โ–“โ–“\  โ–“โ–“โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“\ โ–“โ–“โ–“โ–“โ–“โ–“โ–“\ \โ–“โ–“โ–“โ–“โ–“โ–“\  โ–“โ–“โ–“โ–“โ–“โ–“\  โ–“โ–“โ–“โ–“โ–“โ–“\  โ–“โ–“โ–“โ–“โ–“โ–“\
| โ–“โ–“โ–“โ–“โ–“โ–“โ–“| โ–“โ–“/      โ–“โ–“ โ–“โ–“  | โ–“โ–“ โ–“โ–“\โ–“โ–“ โ–“โ–“ โ–“โ–“/      โ–“โ–“ โ–“โ–“  | โ–“โ–“/      โ–“โ–“ โ–“โ–“  | โ–“โ–“ โ–“โ–“    โ–“โ–“ โ–“โ–“   \โ–“โ–“
| โ–“โ–“     | โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“ โ–“โ–“__/ โ–“โ–“ โ–“โ–“ \โ–“โ–“โ–“| โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“ โ–“โ–“  | โ–“โ–“  โ–“โ–“โ–“โ–“โ–“โ–“โ–“ โ–“โ–“__| โ–“โ–“ โ–“โ–“โ–“โ–“โ–“โ–“โ–“โ–“ โ–“โ–“      
| โ–“โ–“     | โ–“โ–“\โ–“โ–“    โ–“โ–“\โ–“โ–“    โ–“โ–“ โ–“โ–“  \โ–“ | โ–“โ–“\โ–“โ–“    โ–“โ–“ โ–“โ–“  | โ–“โ–“\โ–“โ–“    โ–“โ–“\โ–“โ–“    โ–“โ–“\โ–“โ–“     \ โ–“โ–“      
 \โ–“โ–“      \โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“โ–“_\โ–“โ–“โ–“โ–“โ–“โ–“โ–“\โ–“โ–“      \โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“โ–“\โ–“โ–“   \โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“โ–“_\โ–“โ–“โ–“โ–“โ–“โ–“โ–“ \โ–“โ–“โ–“โ–“โ–“โ–“โ–“\โ–“โ–“      
                     |  \__| โ–“โ–“                                      |  \__| โ–“โ–“                  
                      \โ–“โ–“    โ–“โ–“                                       \โ–“โ–“    โ–“โ–“                  
                       \โ–“โ–“โ–“โ–“โ–“โ–“                                         \โ–“โ–“โ–“โ–“โ–“โ–“                   

๐ŸŽฎ PlayManager v1.0.0

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.

๐Ÿ“ Directory structure

    .
    โ”œโ”€โ”€ ๐Ÿ“ 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)

๐Ÿ“ Contract

Functionality is straight-forward for v1.0.0:

  • ๐ŸŽฎ Basic game event logging
    • createAccount(uint256 accountType) - create a new account
    • startSession(uint256 sessionType) - start a new session
    • dailyLogin(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

๐Ÿ Getting started

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

๐Ÿงช Run tests

To run tests in the tests directory, run:

forge test

Should see 5 tests pass: image

๐Ÿ—๏ธ Building and deploying

Compiling

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.

Flattening the contract

forge flatten --output src/PlayManager.flattened.sol src/PlayManager.sol

Output:

image

The flatten command will concatenate all the imports into a single file. This is useful for running static analysis tools like Slither.

Generating the ABI

forge inspect src/PlayManager.sol:PlayManager abi > PlayManager.abi.json

Constructor

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

Deploying via RPC node

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

Deploying via REMIX

๐Ÿ“บ Walkthrough video coming soon

โ›“๏ธ Create dev testnet with Anvil

Anvil is a local testnet the comes with Foundry CLI.

Start Anvil

forge anvil start

image

Your local RPC node will be running on http://127.0.0.1:8545

๐Ÿง Verification on Block Explorer

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>

๐ŸŒŸ Upgrading the Proxy Contract

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.

Example: image

๐Ÿ” Security

  • 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:

Install Slither

pip3 install slither-analyzer
pip3 install solc-select
solc-select install 0.8.13
solc-select use 0.8.13

Running slither

slither src/PlayManager.flattened.sol

Output running Slither on the PlayManager contract:

  • image

โ˜‘๏ธ TODO

  • Multi-party auth (client, master wallet, etc.)
  • Client contract inheritance for ERC20, ERC721, and ERC1155
  • SDK CRUD primitives for ERC20, ERC721, and ERC1155

๐Ÿ—ƒ๏ธ References