diff --git a/contracts/DBIT.sol b/contracts/DBIT.sol index a9df514..1fa70e2 100644 --- a/contracts/DBIT.sol +++ b/contracts/DBIT.sol @@ -20,14 +20,18 @@ import "./interfaces/IDBIT.sol"; contract DBIT is IDBIT, DebondToken { constructor( - string memory name, - string memory symbol, - address airdropAddress, - address bankAddress, address governanceAddress, - uint256 maxAirdropSupply, - uint256 maxAllocpercentage - ) DebondToken(name, symbol, airdropAddress, bankAddress, governanceAddress, maxAirdropSupply, maxAllocpercentage) {} + address bankAddress, + address airdropAddress + ) DebondToken( + "DBIT", + "DBIT", + airdropAddress, + bankAddress, + governanceAddress, + 500_000 ether, + 1000 // rate on 10000 (10%) + ) {} function mintCollateralisedSupply(address _to, uint256 _amount) external onlyBank { _mintCollateralisedSupply(_to, _amount); diff --git a/contracts/DGOV.sol b/contracts/DGOV.sol index e74dcdc..abbf303 100644 --- a/contracts/DGOV.sol +++ b/contracts/DGOV.sol @@ -21,16 +21,19 @@ contract DGOV is IDGOV, DebondToken { uint256 internal _maximumSupply; constructor( - string memory name, - string memory symbol, - address airdropAddress, - address bankAddress, - address governanceAddress, - uint256 maxSupply, - uint256 maxAirdropSupply, - uint256 maxAllocpercentage - ) DebondToken(name, symbol, airdropAddress, bankAddress, governanceAddress, maxAirdropSupply, maxAllocpercentage) { - _maximumSupply = maxSupply; + address governanceAddress, + address bankAddress, + address airdropAddress + ) DebondToken( + "DGOV", + "DGOV", + airdropAddress, + bankAddress, + governanceAddress, + 250_000 ether, + 1000 // rate on 10000 (10%) + ) { + _maximumSupply = 1_000_000 ether; } function getMaxSupply() external view returns (uint256) { @@ -43,8 +46,8 @@ contract DGOV is IDGOV, DebondToken { function getMaxCollateralisedSupply() external view returns (uint256) { return (_maximumSupply - - (_maxAirdropSupply + - ((_maximumSupply * _maxAllocationPercentage) / 10000))); + (_maxAirdropSupply + + ((_maximumSupply * _maxAllocationPercentage) / 10000))); } function setMaxSupply(uint256 max_supply) external onlyGovernance returns (bool) { diff --git a/contracts/DebondToken.sol b/contracts/DebondToken.sol index 7dc0e8a..07b4562 100644 --- a/contracts/DebondToken.sol +++ b/contracts/DebondToken.sol @@ -187,6 +187,16 @@ abstract contract DebondToken is IDebondToken, ERC20, GovernanceOwnable { _mint(_to, _amount); } + function setBankAddress(address _bankAddress) external onlyGovernance { + require(_bankAddress != address(0), "DebondToken Error: address 0 given"); + bankAddress = _bankAddress; + } + + function setAirdropAddress(address _airdropAddress) external onlyGovernance { + require(_airdropAddress != address(0), "DebondToken Error: address 0 given"); + airdropAddress = _airdropAddress; + } + diff --git a/contracts/interfaces/IDebondToken.sol b/contracts/interfaces/IDebondToken.sol index 41bbdbe..b288480 100644 --- a/contracts/interfaces/IDebondToken.sol +++ b/contracts/interfaces/IDebondToken.sol @@ -53,4 +53,8 @@ interface IDebondToken { function setMaxAllocationPercentage(uint256 newPercentage) external returns (bool); + + function setBankAddress(address _bankAddress) external; + + function setAirdropAddress(address _airdropAddress) external; } diff --git a/migrations/2_deploy_tokens.js b/migrations/2_deploy_tokens.js index 57f52ee..017614b 100644 --- a/migrations/2_deploy_tokens.js +++ b/migrations/2_deploy_tokens.js @@ -1,13 +1,8 @@ const DBIT = artifacts.require("DBIT"); const DGOV = artifacts.require("DGOV"); -//const Governance = artifacts.require("Governance"); module.exports = async function (deployer, network, accounts) { - await deployer.deploy(DBIT, accounts[0] ); - await deployer.deploy(DGOV, accounts[0] ); - let DBITInstance = DBIT.deployed(); - let DGOVInstance = DGOV.deployed(); - - await DBITInstance.grantRole(DEFAULT_ADMIN_ROLE,accounts[0]); - await DGOVInstance.grantRole(DEFAULT_ADMIN_ROLE,accounts[0]); + const [governanceAddress, bankAddress, airdropAddress] = accounts; + + await deployer.deploy(DBIT, governanceAddress, bankAddress, airdropAddress ); + await deployer.deploy(DGOV, governanceAddress, bankAddress, airdropAddress ); }; - \ No newline at end of file diff --git a/test/DBIT.ts b/test/DBIT.ts index f9a2d9b..1e0e387 100644 --- a/test/DBIT.ts +++ b/test/DBIT.ts @@ -2,36 +2,18 @@ import {expect} from "chai"; import Web3 from "web3"; import { DBITInstance, - BankInstance, - DBITAirdropInstance, - ExchangeInstance, - GovernanceInstance } from "../types/truffle-contracts"; const DBIT = artifacts.require("DBIT"); -const DBITAirdrop = artifacts.require("DBITAirdrop"); const web3 = require('web3'); contract("DBIT token", async (accounts: any) => { - let dbitObj: DBITInstance; -// TODO: just taken as the demo for replicating the ng the other contracts , to be removed - let Bank: BankInstance; - let Governance: GovernanceInstance - let DBITAirdrop: DBITAirdropInstance; - let Exchange: ExchangeInstance; - - let [deployer, User1, User2, bank, exchange] = accounts; - - before('instantiation', async () => { + let dbitObj: DBITInstance; + const [governance, bank, airdrop, user1, user2] = accounts; + it('instantiation', async () => { dbitObj = await DBIT.deployed(); - DBITAirdrop = await DBITAirdrop.deployed(); - Governance = await governance.deployed(); - Exchange = await exchange.deployed(); - Bank = await bank.deployed(); - await dbitObj.setBankContract(bank, {from: deployer}); - await dbitObj.setExchangeContract(exchange, {from: deployer}); }); @@ -43,63 +25,57 @@ contract("DBIT token", async (accounts: any) => { }); - it('DBIT is able to set contract address', async () => { - expect(await dbitObj.setAirdropContract(DBITAirdrop.address)).not.to.equal(false); - expect(await dbitObj.setExchangeContract(Exchange.address)).not.to.equal(false); - expect(await dbitObj.setBankContract(Bank.address)).not.to.equal(false); - }) - it('is able to mint the collateralised supply via bank', async () => { - await dbitObj.mintCollateralisedSupply(User2, 100, {from: Bank.address}); - expect(web3.eth.Balance(User2)).to.be('100'); + await dbitObj.mintCollateralisedSupply(user2, 100, {from: bank}); + expect(web3.eth.Balance(user2)).to.be('100'); }); it('able to mint the allocated supply', async () => { - await dbitObj.mintAllocatedSupply(User2, 100, {from: Governance.address}); - expect(web3.eth.Balance(User2)).to.be('100'); + await dbitObj.mintAllocatedSupply(user2, 100, {from: governance}); + expect(web3.eth.Balance(user2)).to.be('100'); }); it('able to mint the airdroped supply', async () => { - await dbitObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address}); - expect(dbitObj.LockedBalance(User2, {from: User2})).to.be('100'); + await dbitObj.mintAirdropSupply(user2, '100', {from: airdrop}); + expect(dbitObj.getLockedBalance(user2, {from: user2})).to.be('100'); }); it('total supply is sum of the airdrop + collateral + allocated supply ', async () => { - await dbitObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address}); - await dbitObj.mintCollateralisedSupply(User2, '200', {from: User2}); - await dbitObj.mintAllocatedSupply(User2, 300, {from: User2}); - expect(dbitObj.totalSupply({from: User2})).to.equal('600'); + await dbitObj.mintAirdropSupply(user2, '100', {from: airdrop}); + await dbitObj.mintCollateralisedSupply(user2, '200', {from: user2}); + await dbitObj.mintAllocatedSupply(user2, 300, {from: user2}); + expect(dbitObj.totalSupply({from: user2})).to.equal('600'); }); it('gets the locked supply initially as full supply ', async () => { // setting only the airdropped supply for the 2 users and no collateralised supply - await dbitObj.setAirdroppedSupply('200', {from: deployer}); - await dbitObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address}); - await dbitObj.mintAirdroppedSupply(User1, '100', {from: DBITAirdrop.address}); + await dbitObj.setMaxAirdropSupply('200', {from: governance}); + await dbitObj.mintAirdropSupply(user2, '100', {from: airdrop}); + await dbitObj.mintAirdropSupply(user1, '100', {from: airdrop}); // it should be total max supply (1 million DBIT). - await dbitObj.LockedBalance(User2).to.be(Web3.utils.toWei('1000000000', 'ether')); + (await dbitObj.getLockedBalance(user2)).to.be(Web3.utils.toWei('1000000000', 'ether')); }) it('if the collateralised supply gets bigger than airdropped supply , there is no locked balance', async () => { - await dbitObj.setAirdroppedSupply('200', {from: deployer}); - await dbitObj.mintAirdroppedSupply(User2, '100', {from: DBITAirdrop.address}); - await dbitObj.mintAirdroppedSupply(User1, '100', {from: DBITAirdrop.address}); + await dbitObj.setAirdroppedSupply('200', {from: governance}); + await dbitObj.mintAirdroppedSupply(user2, '100', {from: DBITAirdrop.address}); + await dbitObj.mintAirdroppedSupply(user1, '100', {from: DBITAirdrop.address}); - await dbitObj.mintCollateralisedSupply(User2, '10000000000000000000', {from: DBITAirdrop.address}); + await dbitObj.mintCollateralisedSupply(user2, '10000000000000000000', {from: DBITAirdrop.address}); - await dbitObj.LockedBalance(User2).to.equal('0'); + await dbitObj.LockedBalance(user2).to.equal('0'); }); @@ -108,7 +84,7 @@ contract("DBIT token", async (accounts: any) => { await dbitObj.mintCollateralisedSupply(bank, 300, {from: bank}); - await dbitObj.mintCollateralisedSupply(exchange, 300, {from: exchange}); + await dbitObj.mintCollateralisedSupply(airdrop, 300, {from: airdrop}); await dbitObj.mintAirdroppedSupply(Bank, 1000, {from: Bank}); await dbitObj.directTransfer(Bank, Exchange, 600, {from: Bank}); @@ -116,12 +92,12 @@ contract("DBIT token", async (accounts: any) => { it('transfer is working between any general address', async () => { - await dbitObj.mintCollateralisedSupply(User1, 300, {from: bank}); - await dbitObj.mintCollateralisedSupply(User2, 900, {from: bank}) - await dbitObj.mintAllocatedSupply(User1, 300, {from: deployer}); - await dbitObj.mintAllocatedSupply(User2, 800, {from: deployer}) + await dbitObj.mintCollateralisedSupply(user1, 300, {from: bank}); + await dbitObj.mintCollateralisedSupply(user2, 900, {from: bank}) + await dbitObj.mintAllocatedSupply(user1, 300, {from: governance}); + await dbitObj.mintAllocatedSupply(user2, 800, {from: governance}) - await dbitObj.directTransfer(User1, User2, {from: deployer}); + await dbitObj.directTransfer(user1, user2, {from: governance}); });