Skip to content

$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.

License

Notifications You must be signed in to change notification settings

eabdelmoneim/pack-protocol

 
 

Repository files navigation

$Pack Protocol

$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.

Difference from main

The contracts in this branch create-in-one-tx have a different flow for creating packs.

Creating Packs: Before (in main)

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 calling setApprovalForAll.
  • Create packs with Pack.sol by calling createPack.

Creating Packs: Now (in create-in-one-tx)

Creating packs is now a one step process:

  • Call createPackAtomic in Rewards.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 in Rewards.sol with the relevant arguments.

Notes for AccessPacks frontend integration

Creating packs with rewards

The entire create flow is a now one step (just one frontend call):

  • Create packs with rewards: Call createPackAtomic on Rewards.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 {}

Listing packs for sale

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 on Market.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 {}

Deployments

The contracts in the /contracts directory are deployed on the following networks.

Polygon

Mumbai

Rinkeby

Run Locally

Clone the project

  git clone https://github.com/nftlabs/pack-protocol.git

Install dependencies

  yarn install

Run tests and scripts

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}

Deploying contracts

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

Feedback

If you have any feedback, please reach out to us at [email protected].

Authors

License

GPL v3.0

About

$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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 55.6%
  • Solidity 43.8%
  • Other 0.6%