Framework for decentralized and dynamic access control for smart contracts
npm install --save-dev hardhat
npm install @nomiclabs/hardhat-waffle
npm install --save-dev "@nomiclabs/hardhat-ethers@^2.0.0" "ethereum-waffle@^3.2.0" "ethers@^5.0.0"
npm install @nomiclabs/hardhat-web3
npm install hardhat-deploy
npm install hardhat-deploy-ethersNow you can run the following command to startup a hardhat network
npx hardhat node --no-deployTo be able to compile all necessary core solidity contracts you need to install the following libraries:
npm install @openzeppelin/contracts
npm install web3Now you can run the following script to deploy the core contracts of DEDACS (without the demo contracts)
npx hardhat --network localhost deploy --reset --tags DeployCoreUnfortunately, you have to change the pragma in the file node_modules@openzeppelin\contracts\token\ERC20\IERC20.sol from
pragma solidity ^0.8.0;to
pragma solidity >=0.7.0;=> Also for ERC20 and ownable?
To install the DEDACS smart contracts and run its deploy and demoscripts on a hardhat blockchain, run the following commands:
npm install --save-dev hardhatnpm install @nomiclabs/hardhat-wafflenpm install --save-dev "@nomiclabs/hardhat-ethers@^2.0.0" "ethereum-waffle@^3.2.0" "ethers@^5.0.0"npm install @nomiclabs/hardhat-web3npm install hardhat-deploynpm install hardhat-deploy-ethersnpm install @openzeppelin/contractsnpm install @uniswap/v3-corenpm install @uniswap/v3-peripherynpm install @uniswap/v3-coreThis scenario describes the steps to be performed to deploy DEDACS on a local hardhat blockchain.
Start a hardhat blockchain without deploying any scripts:
npx hardhat node --no-deployOpen a new terminal that you can use to interact with the hardhat blockchain and run the commands depending on what you want to deploy or run.
If you just want to deploy the Core contracts of DEDACS so you can interact with it from your own scripts run the following command:
npx hardhat --network localhost deploy --reset --tags DeployCoreYou can leave out the --reset tag is you don't want to reset your previous deployments on the blockchain. The DeployCore tag will run the script in deploy/DeployCore.js .
If you want to setup the Demo, run the following command:
npx hardhat --network localhost deploy --reset --tags DeployDemoor this one if you need to work with an elaborated config file:
npx hardhat --config hardhat.config_demo.js --network localhost deploy --reset --tags DeployDemoThe idea of this demo is that there are 2 resources (Common token and Rare token) that are protected by DEDACS. There are 2 gamers in this demo that can exchange the resources through a Uniswap pool. Depending on the level they have, DEDACS will allow or block a transaction they want to do with the resources.
Once the Demo is deployed, you can interact with it through 2 tasks: swap and upgradeGamer1.
The swap task takes 2 arguments: amount and commonforrare. amount is the amount of tokens you want to swap and commonforrare declares the swap direction. If commonforrare is true, Common tokens will be swapped for Rare tokens and vice versa if it is false.
The upgradeGamer1 task will upgrade the level of Gamer 1 to level 2 which will give him more rights.
The Common token can be swapped unlimited by everyone as declared in the CommonTokenPolicy. Gamers can swap at most 1000 Rare tokens at the same time or at most 2000 Rare tokens at the same time if they are in level 2.
The third transaction will be blocked by DEDACS because it violates the RareTokenPolicy. However if gamer1 has level 2, which will be the case after the fourth transaction, the third transaction does not violate the policy anymore so if you try it again, it will not be blocked anymore by DEDACS.
npx hardhat --config hardhat.config_demo.js --network localhost swap --amount 100000 --commonforrare true
npx hardhat --config hardhat.config_demo.js --network localhost swap --amount 200 --commonforrare false
npx hardhat --config hardhat.config_demo.js --network localhost swap --amount 1500 --commonforrare false
npx hardhat --config hardhat.config_demo.js --network localhost upgradeGamer1
npx hardhat --config hardhat.config_demo.js --network localhost swap --amount 1500 --commonforrare falsenpx hardhat --config hardhat.config_demo.js --network localhost swap --amount 100000 --commonforrare true
npx hardhat --config hardhat.config_demo.js --network localhost swapHardcoded --amount 100000 --commonforrare true
npx hardhat --config hardhat.config_demo.js --network localhost upgradeGamer1npx hardhat --network localhost deploy --reset --tags DeployScript npx hardhat --network localhost deploy --reset --tags DeployCore
To run the DEMO, you need to use the other config file which will compile more solidity contracts. npx hardhat --config hardhat.config_demo.js --network localhost deploy --reset --tags DeployScript