Architecture
The smart contract architecture of $PACK Protocol
Smart contracts
$PACK Protocol primarily consists of three smart contracts:
ProtocolControl.sol
acts as a control center for the protocol.
It stores the addresses of all modules of the protocol e.g. the protocol's ERC 1155 contract for packs.
It defines the
PROTOCOL_ADMIN
role, and contains functions to grant or revoke that role.It holds the protocol fees collected on every pack and reward sale / resale. This fees an be transferred by addresses having the
PROTOCOL_ADMIN
role.
Pack.sol
is the ERC 1155 smart contract for packs.
It contains all logic for creating packs, opening a pack, and distributing rewards to pack openers.
It inherits VRFConsumerBase and interacts with Chainlink VRF.
It is an IERC1155Receiver, and holds rewards that haven't been distributed to pack openers.
Market.sol
is the protocol's dedicated market contract for packs and rewards.
It enables buying and selling packs and rewards, and distributes a fixed percentage fee to the relevant pack creator, and the protocol, on every pack and reward sale/ resale.
Main Actions
The protocol has five main actions that can be performed by external actors e.g. pack creators.
Creating a set of packs.
Opening a pack.
Listing packs or rewards for sale.
Updating the parameters of a pack or reward listing.
Buying packs or rewards listed for sale.
The following gives a high level overview of how the protocol's smart contracts operate when an external actor performs one of these actions. For a detailed guide on how to perform these actions programmatically, join us at the NFT Labs discord so we can help you out! These docs are under construction. We plan to add a section on how to build on $PACK Protocol, soon.
Creating a set of packs
$PACK Protocol recognizes any ERC 1155 token as a reward. An actor creates a set of packs by batch transferring reward tokens to Pack.sol
, and receiving the relevant packs in return.
ERC 1155 standard's safeBatchTransferFrom
allows passing arbitrary bytes data in the function call. Pack.sol
expects the caller to encode relevant parameters for creating the set of packs, and pass them in the safeBatchTransferFrom
call. These parameters are decoded Pack.sol
to create the desired set of packs.
Opening a pack
An actor opens a pack by calling the openPack
function on Pack.sol
. Opening a pack burns the pack.
Upon openPack
being called, Pack.sol
requests a random number from Chainlink VRF, to be used in determining which reward to distribute to the pack opener. Chainlink VRF fulfills this request with a random number, upon which the relevant reward is distributed to the pack opener.
Listing packs or rewards for sale
An actor lists packs or rewards they own by calling the list
function on Market.sol
with the relevant parameters to set for the listing e.g. price per token listed.
Listing tokens (packs or rewards) for sale locks the tokens being listed in the Market.sol
contract.
Updating the parameters of a pack or reward listing
An actor can update the parameters of their token (pack or reward) listing, e.g. price per token or the currency accepted by the listing, by calling the updateListingParams
function on Market.sol
.
Updating the parameters of a token listing is a state changing transaction, which requires the caller to pay the requisite gas fees.
Buying packs or rewards listed for sale
An actor can buy tokens (packs or rewards) listed on sale by calling the buy
function on Market.sol
.
2.5% of the total price paid by the buyer is transferred to the creator of the tokens being sold (only if the seller associated with the token listing is not the creator of the tokens). An additional 2.5% of the total price is transferred to ProtocolControl.sol
as a fee. The remainder is transferred to the seller associated with the token listing.
Last updated