On-chain D.Quest is a set of smart contracts that allows Community admins to define Quests consisting of Missions and Rewards and Users to fulfill Missions and claim Rewards on-chain.
This project applies beacon proxy Factory upgradable pattern for creating & upgrading Quest contracts while the Dquest factory itself is upgraded following Transparent upgradable pattern.
- Install packages
npm install
- Make your own
.env
file and update it referring to.env.example
- Execute some test cases
npx hardhat test
For the details please refer: can-evm-dquest/contracts/interface/IDQuest.sol
Use Dquest factory contract, function createQuest(...)
to create and deploy quests contracts (proxy contract)
Quest proxy created on-chain via Dquest factory is outside of hardhat upgrades pluggin and we can not use the pluggin to verify our new Quest contract. To take the most out of hardhat upgrades pluggin, we can import our newly created proxy address in step 1 to the pluggin. First check & edit the proxy address in script/for-quest/force-import-proxy.js
and execute the following:
npx hardhat run --network localhost scripts/for-quest/force-import-proxy.js
Be sure to strictly follow contract upgrade rules in writing a new implementation contract or new upgrade will bring bugs and unexpected issues. Use prepare_upgrade_quest.js
to verify before upgrading with Dquest factory.
To verify new implementation's compatibility and return the current implementation contract address, check and adapt & edit the proxy address in script/for-quest/prepare_upgrade_quest.js
and execute the following:
npx hardhat run --network localhost scripts/for-quest/prepare_upgrade_quest.js
We might use truffle, hardhat or remix to deploy our new logic/implementation contract as normal.
Use Dquest factory contract, function upgradeQuest(address new_quest_impl_contract)
and give it new implementation/logic contract address in step4(prepare does automatically deploy a new implementation contract) Or in step5(where you deploy your implementation contract manually) to upgrade all quest proxy contracts
Check and adapt script/for-dquest/deploy_dquest_factory.js
for your deployment and execute the following:
npx hardhat run --network localhost script/for-dquest/deploy_dquest_factory.js
Check and adapt & edit the new owner address and execute the following script:
npx hardhat run --network localhost scripts/for-dquest/transfer_upgradeship_dquest_factory.js
To verify new implementation's compatibility and return the current implementation contract address, check and adapt & edit the proxy address in prepare_upgrade_dquest_factory.js
and execute the following:
npx hardhat run --network localhost scripts/for-dquest/prepare_upgrade_dquest_factory.js
Check and adapt & edit the proxy address in scripts/for-dquest/upgrade_dquest_factory.js
and execute the following script:
npx hardhat run --network localhost scripts/for-dquest/upgrade_dquest_factory.js
-
All network after option --network in this file is an example. Change accordingly to your network choice.
-
To verify contract(mostly implementation contracts):
npx hardhat verify <contract address> --network <network> <constructor param 1> <constructor param 2>
-
Network options(check hardhat.config.js):
- local
- goerli
- mumbai
- polygon
-
Follow strictly II. 2. to upgrade any contract (both quest or Dquest factory)