Skip to content

wouterlenaerts/DEDACS

Repository files navigation

DEDACS

Framework for decentralized and dynamic access control for smart contracts

README under construction

Installation

Installation for core deployment

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-ethers

Now you can run the following command to startup a hardhat network

npx hardhat node --no-deploy

To be able to compile all necessary core solidity contracts you need to install the following libraries:

npm install @openzeppelin/contracts
npm install web3

Now you can run the following script to deploy the core contracts of DEDACS (without the demo contracts)

npx hardhat --network localhost deploy --reset --tags DeployCore

Unfortunately, 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?

Installation for demo

To install the DEDACS smart contracts and run its deploy and demoscripts on a hardhat blockchain, run the following commands:

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-ethers
npm install @openzeppelin/contracts
npm install @uniswap/v3-core
npm install @uniswap/v3-periphery
npm install @uniswap/v3-core

Deployment

This 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-deploy

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

Deploy Core Contracts

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 DeployCore

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

Deploy Demo Contracts

If you want to setup the Demo, run the following command:

npx hardhat --network localhost deploy --reset --tags DeployDemo

or this one if you need to work with an elaborated config file:

npx hardhat --config hardhat.config_demo.js --network localhost deploy --reset --tags DeployDemo

Demo

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

Example

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 false

Other demo commands

npx 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 upgradeGamer1

npx 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

About

Framework for decentralized and dynamic access control for smart contracts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published