$PACK Protocol lets anyone create and sell packs filled with rewards. A pack can be opened only once. On opening a pack, a reward from the pack is distributed to the pack opener.
The contracts in this branch create-in-one-tx
have a different flow for creating packs.
Creating packs was a 3 step process:
- Create rewards with
Rewards.sol
by calling e.g.createNativeRewards
- Approve
Pack.sol
to transfer the created rewards, by callingsetApprovalForAll
. - Create packs with
Pack.sol
by callingcreatePack
.
Creating packs is now a one step process:
- Call
createPackAtomic
inRewards.sol
with the relevant arguments.
On calling createPackAtomic
, the contracts first mints rewards to the creator, and then transfers the rewards from the caller to Pack.sol
. On receiving the rewards, Pack.sol
mints packs to the creator with the sent underlying rewards.
The data
argument in safeTransferFrom
allows sending whatever information to Pack.sol
that is required to create the relevant packs.
Note: Creating packs with wrapped rewards is a two step process:
-
First create your rewards by calling the relevant reward creation function e.g.
wrapERC721
. -
Call
createPack
inRewards.sol
with the relevant arguments.
The entire create flow is a now one step (just one frontend call):
- Create packs with rewards: Call
createPackAtomic
onRewards.sol
. The interface is:
/// @dev Creates packs with rewards.
function createPackAtomic(
string[] calldata _rewardURIs,
uint[] calldata _rewardSupplies,
string calldata _packURI,
uint _secondsUntilOpenStart,
uint _secondsUntilOpenEnd
) external {}
The list-for-sale flow is a two step process (two frontend calls)
- Approve market to transfer tokens being listed for sale: This approval needs to be given only once ever (unless the user has removed the approval at a later time).
// First check if approval already exists
await packContract.isApprovedForAll(userAddress, marketAddress);
// If no approval, ask user for approval
await packContract.connect(useSigner).setApprovalForAll(marketAddress, true)
- List packs on market: Call
list
onMarket.sol
. The interface is:
/// @notice List a given amount of pack or reward tokens for sale.
function list(
address _assetContract,
uint _tokenId,
address _currency,
uint _pricePerToken,
uint _quantity,
uint _secondsUntilStart,
uint _secondsUntilEnd
) external onlyUnpausedProtocol {}
The contracts in the /contracts
directory are deployed on the following networks.
-
ProtocolControl.sol
: 0x35d9fD7AA4b49028a5EB83F0E48c3ea99bE23124 -
Market.sol
: 0x63025410F6463Bf87c36565D843b7FCdDF16d753 -
Rewards.sol
: 0x32AE8E62494951c0c758131F28220B3d30a90258
-
ProtocolControl.sol
: 0x3d86dD9846c0a15B0f40037AAf51CC68A4236add -
Market.sol
: 0xF1089C7a0Ae7d0729d94ff6806d7BeA0A02C3bF2 -
Rewards.sol
: 0x7c6c7048Cd447BA200bde9A89A2ECc83435b7E51
-
ProtocolControl.sol
: 0xAFe8f8EDad3Fd7b0108997b51CCd24286FbF000B -
Market.sol
: 0xE0C0158A9d498EF4D0b02a8256A6957718Af8B5B -
Rewards.sol
: 0xebC0b11f62A416634fe400bbB750f0E40833a4d0
Clone the project
git clone https://github.com/nftlabs/pack-protocol.git
Install dependencies
yarn install
Add a .env
file to the project's root directory. Update the .env
file with the values mentioned in the provided .env.example
file.
Run tests
npx hardhat test
To use scripts, update the transaction parameters in the particular script and run
npx hardhat run scripts/.../${testFileName}.ts --network {name of network}
To deploy this project on a given network (e.g. mumbai) update the hardhat.config.ts
file with the following
// ...
if (testPrivateKey) {
config.networks = {
mumbai: createTestnetConfig("mumbai"),
};
}
Finally, run
npx hardhat run scripts/deploy/mumbai/protocol.js --network mumbai
If you have any feedback, please reach out to us at [email protected].