diff --git a/contracts/DODOToken/DODOCirculationHelper.sol b/contracts/DODOToken/DODOCirculationHelper.sol index 0c66fb1..f048713 100644 --- a/contracts/DODOToken/DODOCirculationHelper.sol +++ b/contracts/DODOToken/DODOCirculationHelper.sol @@ -40,6 +40,7 @@ contract DODOCirculationHelper is Ownable { function getCirculation() public view returns (uint256 circulation) { circulation = 10**9; + //TODO circulation 需要乘以decimals吗? for (uint256 i = 0; i < _LOCKED_CONTRACT_ADDRESS_.length; i++) { circulation -= IERC20(_DODO_TOKEN_).balanceOf(_LOCKED_CONTRACT_ADDRESS_[i]); } @@ -54,7 +55,7 @@ contract DODOCirculationHelper is Ownable { uint256 x = DecimalMath.divCeil( dodoCirculationAmout, - IERC20(_DODO_TOKEN_).balanceOf(address(this)) + IERC20(_DODO_TOKEN_).balanceOf(address(this))// TODO 这里应该是vdodo的值吧? ); if (x <= 10**18) { diff --git a/contracts/DODOToken/Governance.sol b/contracts/DODOToken/Governance.sol new file mode 100644 index 0000000..4f2371d --- /dev/null +++ b/contracts/DODOToken/Governance.sol @@ -0,0 +1,24 @@ +/* + + Copyright 2020 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ +pragma solidity 0.6.9; +pragma experimental ABIEncoderV2; + +import {InitializableOwnable} from "../lib/InitializableOwnable.sol"; + +contract Governance is InitializableOwnable { + + // ============ Storage ============ + + address immutable _DODO_TOKEN_; + + constructor(address dodoToken) public { + _DODO_TOKEN_ = dodoToken; + } + function getLockedvDODO(address account) external pure returns (uint256 lockedvDODO) { + lockedvDODO = 0;//DOTO,0 for test + } +} diff --git a/contracts/DODOToken/vDODOToken.sol b/contracts/DODOToken/vDODOToken.sol index 6c018d2..6ae3e84 100644 --- a/contracts/DODOToken/vDODOToken.sol +++ b/contracts/DODOToken/vDODOToken.sol @@ -90,18 +90,19 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { // ============ Constructor ============ constructor( - address _dodoGov, + // address _dodoGov, address _dodoToken, address _dodoCirculationHelper, address _dodoApproveProxy, string memory _name, string memory _symbol ) public { + initOwner(msg.sender); name = _name; symbol = _symbol; decimals = 18; _DODO_APPROVE_PROXY_ = _dodoApproveProxy; - _DOOD_GOV_ = _dodoGov; + // _DOOD_GOV_ = _dodoGov; _DODO_CIRCULATION_HELPER_ = _dodoCirculationHelper; _DODO_TOKEN_ = _dodoToken; lastRewardBlock = block.number; @@ -128,6 +129,9 @@ contract vDODOToken is InitializableOwnable, ReentrancyGuard { function updateDODOCirculationHelper(address _helper) public onlyOwner { _DODO_CIRCULATION_HELPER_ = _helper; } + function updateGovernance(address _governance) public onlyOwner { + _DOOD_GOV_ = _governance; + } // ============ Functions ============ diff --git a/test/Token/vdodo.test.ts b/test/Token/vdodo.test.ts new file mode 100644 index 0000000..9538008 --- /dev/null +++ b/test/Token/vdodo.test.ts @@ -0,0 +1,75 @@ +/* + + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +// import * as assert from 'assert'; + +import { decimalStr, MAX_UINT256 } from '../utils/Converter'; +import { logGas } from '../utils/Log'; +import { VDODOContext, getVDODOContext } from '../utils/VDODOContext'; +import { assert } from 'chai'; +import BigNumber from 'bignumber.js'; +const truffleAssert = require('truffle-assertions'); + +let account0: string; +let account1: string; +let account2: string; + +async function init(ctx: VDODOContext): Promise { + account0 = ctx.SpareAccounts[0]; + account1 = ctx.SpareAccounts[1]; + account2 = ctx.SpareAccounts[2]; + + await ctx.mintTestToken(account0, decimalStr("1000")); + await ctx.mintTestToken(account1, decimalStr("1000")); + +} + +describe("VDODO", () => { + let snapshotId: string; + let ctx: VDODOContext; + + before(async () => { + ctx = await getVDODOContext(); + await init(ctx); + }); + + beforeEach(async () => { + snapshotId = await ctx.EVM.snapshot(); + }); + + afterEach(async () => { + await ctx.EVM.reset(snapshotId); + }); + + describe("vdodo", () => { + + it("vdodo init", async () => { + + assert.equal( + await ctx.DODO.methods.balanceOf(account0).call(), + decimalStr("1000") + ); + assert.equal( + await ctx.VDODO.methods.balanceOf(account0).call(), + decimalStr("0") + ); + assert.equal( + await ctx.VDODO.methods.alpha().call(), + ctx.alpha + ); + assert.equal( + await ctx.VDODO.methods.lastRewardBlock().call(), + ctx.lastRewardBlock + ); + assert.equal( + await ctx.VDODO.methods.totalSupply().call(), + decimalStr("0") + ); + + }); + }) +}); diff --git a/test/utils/Contracts.ts b/test/utils/Contracts.ts index 5842d33..7bc7c90 100644 --- a/test/utils/Contracts.ts +++ b/test/utils/Contracts.ts @@ -47,6 +47,9 @@ export const DODO_CALLEE_HELPER_NAME = "DODOCalleeHelper" export const CROWD_POOLING_NAME = "CP" export const CROWD_POOLING_FACTORY = "CrowdPoolingFactory" export const DODO_INCENTIVE = "DODOIncentive" +export const VDODO_NAME = "vDODOToken" +export const DODO_CULATION_HELPER = "DODOCirculationHelper" +export const DODO_GOVERNANCE = "Governance" interface ContractJson { abi: any; diff --git a/test/utils/VDODOContext.ts b/test/utils/VDODOContext.ts new file mode 100644 index 0000000..3827889 --- /dev/null +++ b/test/utils/VDODOContext.ts @@ -0,0 +1,120 @@ +/* + + Copyright 2021 DODO ZOO. + SPDX-License-Identifier: Apache-2.0 + +*/ + +import BigNumber from 'bignumber.js'; +import Web3 from 'web3'; +import { Contract } from 'web3-eth-contract'; + +import * as contracts from './Contracts'; +import { decimalStr, MAX_UINT256 } from './Converter'; +import { EVM, getDefaultWeb3 } from './EVM'; +import * as log from './Log'; + +BigNumber.config({ + EXPONENTIAL_AT: 1000, + DECIMAL_PLACES: 80, +}); + +export class VDODOContext { + EVM: EVM; + Web3: Web3; + Deployer: string; + Maintainer: string; + SpareAccounts: string[]; + + //token + DODO: Contract; + VDODO: Contract; + + DODOApprove: Contract; + DODOApproveProxy: Contract; + + DODOCirculationHelper: Contract; + Governance: Contract; + + lastRewardBlock:number; + alpha:number; + + + + constructor() { } + + async init() { + this.EVM = new EVM(); + this.Web3 = getDefaultWeb3(); + + this.DODO = await contracts.newContract( + contracts.MINTABLE_ERC20_CONTRACT_NAME, + ["DODO Token", "DODO", 18] + ); + + this.DODOCirculationHelper = await contracts.newContract( + contracts.DODO_CULATION_HELPER, + [ + this.DODO.options.address + ] + ); + this.DODOApprove = await contracts.newContract( + contracts.SMART_APPROVE + ); + + this.DODOApproveProxy = await contracts.newContract( + contracts.SMART_APPROVE_PROXY, + [this.DODOApprove.options.address] + ) + + this.VDODO = await contracts.newContract( + contracts.VDODO_NAME, + [ + this.DODO.options.address, + this.DODOCirculationHelper.options.address, + this.DODOApproveProxy.options.address, + "VDODO Token", "VDODO" + ] + ) + + this.Governance = await contracts.newContract( + contracts.DODO_GOVERNANCE, + [this.VDODO.options.address] + ) + + const allAccounts = await this.Web3.eth.getAccounts(); + this.Deployer = allAccounts[0]; + this.Maintainer = allAccounts[1]; + this.SpareAccounts = allAccounts.slice(2, 10); + + await this.VDODO.methods.updateGovernance( + this.Governance.options.address + ).send(this.sendParam(this.Deployer)) + + this.alpha = await this.VDODO.methods.alpha().call(); + this.lastRewardBlock = await this.VDODO.methods.lastRewardBlock().call(); + + console.log("alpha = "+ this.alpha); + console.log("lastRewardBlock = " + this.lastRewardBlock); + console.log(log.blueText("[Init VDODO context]")); + } + + sendParam(sender, value = "0") { + return { + from: sender, + gas: process.env["COVERAGE"] ? 10000000000 : 7000000, + gasPrice: process.env.GAS_PRICE, + value: decimalStr(value), + }; + } + + async mintTestToken(to: string, amount: string) { + await this.DODO.methods.mint(to, amount).send(this.sendParam(this.Deployer)); + } +} + +export async function getVDODOContext(): Promise { + var context = new VDODOContext(); + await context.init(); + return context; +}