Skip to content

Commit

Permalink
refactoring + migrations ok
Browse files Browse the repository at this point in the history
  • Loading branch information
drikssy committed Jun 21, 2022
1 parent ef51d4a commit 2736df9
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 80 deletions.
18 changes: 11 additions & 7 deletions contracts/DBIT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 15 additions & 12 deletions contracts/DGOV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions contracts/DebondToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}




Expand Down
4 changes: 4 additions & 0 deletions contracts/interfaces/IDebondToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ interface IDebondToken {
function setMaxAllocationPercentage(uint256 newPercentage)
external
returns (bool);

function setBankAddress(address _bankAddress) external;

function setAirdropAddress(address _airdropAddress) external;
}
13 changes: 4 additions & 9 deletions migrations/2_deploy_tokens.js
Original file line number Diff line number Diff line change
@@ -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 );
};

80 changes: 28 additions & 52 deletions test/DBIT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});

});

Expand All @@ -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');


});
Expand All @@ -108,20 +84,20 @@ 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});

});


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});


});
Expand Down

0 comments on commit 2736df9

Please sign in to comment.