update feeratemodel & test case
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
pragma solidity 0.6.9;
|
pragma solidity 0.6.9;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||||
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||||
|
|
||||||
interface IFeeRateModel {
|
interface IFeeRateModel {
|
||||||
@@ -16,23 +17,28 @@ interface IFeeRateModel {
|
|||||||
function setFeeRate(uint256 newFeeRate) external;
|
function setFeeRate(uint256 newFeeRate) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
contract FeeRateModel is InitializableOwnable {
|
contract FeeRateModel is ReentrancyGuard,InitializableOwnable {
|
||||||
//DEFAULT
|
//DEFAULT
|
||||||
uint256 public _FEE_RATE_;
|
uint256 public _FEE_RATE_;
|
||||||
mapping(address => uint256) feeMapping;
|
mapping(address => uint256) feeMapping;
|
||||||
|
event Log(string str, bool result);
|
||||||
|
|
||||||
function init(address owner, uint256 feeRate) external {
|
function init(address owner, uint256 feeRate) external {
|
||||||
initOwner(owner);
|
initOwner(owner);
|
||||||
_FEE_RATE_ = feeRate;
|
_FEE_RATE_ = feeRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
function setSpecificFeeRate(address trader, uint256 feeRate, address logicContractAddr) external onlyOwner {
|
||||||
require(trader != address(0), "INVALID ADDRESS!");
|
bool r;
|
||||||
feeMapping[trader] = feeRate;
|
(r, ) = logicContractAddr.delegatecall(abi.encodeWithSignature("setSpecificFeeRate(address,uint256)", trader,feeRate));
|
||||||
|
emit Log("delegatecall return ", r);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
function setFeeRate(uint256 newFeeRate, address logicContractAddr) external onlyOwner {
|
||||||
_FEE_RATE_ = newFeeRate;
|
bool r;
|
||||||
|
(r, ) = logicContractAddr.delegatecall(abi.encodeWithSignature("setFeeRate(uint256)", newFeeRate));
|
||||||
|
emit Log("delegatecall return ", r);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFeeRate(address trader) external view returns (uint256) {
|
function getFeeRate(address trader) external view returns (uint256) {
|
||||||
|
|||||||
30
contracts/lib/FeeRateModelLogic.sol
Normal file
30
contracts/lib/FeeRateModelLogic.sol
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2020 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity 0.6.9;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||||
|
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||||
|
|
||||||
|
contract FeeRateModelLogic is ReentrancyGuard,InitializableOwnable {
|
||||||
|
//DEFAULT
|
||||||
|
uint256 public _FEE_RATE_;
|
||||||
|
mapping(address => uint256) feeMapping;
|
||||||
|
|
||||||
|
|
||||||
|
event Log(string str, bool result);
|
||||||
|
|
||||||
|
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
||||||
|
require(trader != address(0), "INVALID ADDRESS!");
|
||||||
|
feeMapping[trader] = feeRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||||
|
_FEE_RATE_ = newFeeRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
contracts/lib/FeeRateModelLogicUpdate.sol
Normal file
31
contracts/lib/FeeRateModelLogicUpdate.sol
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2020 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
pragma solidity 0.6.9;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import {ReentrancyGuard} from "../lib/ReentrancyGuard.sol";
|
||||||
|
import {InitializableOwnable} from "../lib/InitializableOwnable.sol";
|
||||||
|
|
||||||
|
//for test update
|
||||||
|
contract FeeRateModelLogicUpdate is ReentrancyGuard ,InitializableOwnable{
|
||||||
|
//DEFAULT
|
||||||
|
uint256 public _FEE_RATE_;
|
||||||
|
mapping(address => uint256) feeMapping;
|
||||||
|
|
||||||
|
|
||||||
|
event Log(string str, bool result);
|
||||||
|
|
||||||
|
function setSpecificFeeRate(address trader, uint256 feeRate) external onlyOwner {
|
||||||
|
require(trader != address(0), "INVALID ADDRESS!");
|
||||||
|
feeMapping[trader] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setFeeRate(uint256 newFeeRate) external onlyOwner {
|
||||||
|
_FEE_RATE_ = _FEE_RATE_+ newFeeRate;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
migrations/5_deploy_feerate.js
Normal file
22
migrations/5_deploy_feerate.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const fs = require("fs");
|
||||||
|
const Web3 = require('web3');
|
||||||
|
const { deploySwitch } = require('../truffle-config.js')
|
||||||
|
// const file = fs.createWriteStream("../deploy-detail-v2.0.txt", { 'flags': 'a' });
|
||||||
|
// let logger = new console.Console(file, file);
|
||||||
|
|
||||||
|
|
||||||
|
const FeeRateModelLogic = artifacts.require("FeeRateModelLogic");
|
||||||
|
const FeeRateModelLogicUpdate = artifacts.require("FeeRateModelLogicUpdate");
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = async (deployer, network, accounts) => {
|
||||||
|
let FeeRateModelLogicAddress;
|
||||||
|
let FeeRateModelLogicUpdateAddress;
|
||||||
|
await deployer.deploy(FeeRateModelLogic);
|
||||||
|
FeeRateModelLogicAddress = FeeRateModelLogic.address;
|
||||||
|
// logger.log("FeeRateModelLogicAddress: ", FeeRateModelLogicAddress);
|
||||||
|
|
||||||
|
await deployer.deploy(FeeRateModelLogicUpdate);
|
||||||
|
FeeRateModelLogicUpdateAddress = FeeRateModelLogicUpdate.address;
|
||||||
|
// logger.log("FeeRateModelLogicUpdateAddress: ", FeeRateModelLogicUpdateAddress);
|
||||||
|
};
|
||||||
90
test/DVM/FeeRateModelUpdate.test.ts
Normal file
90
test/DVM/FeeRateModelUpdate.test.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Copyright 2020 DODO ZOO.
|
||||||
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// import * as assert from 'assert';
|
||||||
|
|
||||||
|
import { decimalStr, gweiStr } from '../utils/Converter';
|
||||||
|
import { logGas } from '../utils/Log';
|
||||||
|
import { DVMContext, getDVMContext } from '../utils/DVMContext';
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import { EXTERNAL_VALUE_NAME, getContractWithAddress } from '../utils/Contracts';
|
||||||
|
const truffleAssert = require('truffle-assertions');
|
||||||
|
|
||||||
|
let lp: string;
|
||||||
|
let trader: string;
|
||||||
|
|
||||||
|
async function init(ctx: DVMContext): Promise<void> {
|
||||||
|
lp = ctx.SpareAccounts[0];
|
||||||
|
trader = ctx.SpareAccounts[1];
|
||||||
|
|
||||||
|
// await ctx.mintTestToken(lp, decimalStr("10"), decimalStr("1000"));
|
||||||
|
// await ctx.mintTestToken(trader, decimalStr("10"), decimalStr("1000"));
|
||||||
|
|
||||||
|
// await ctx.transferBaseToDVM(lp, decimalStr("10"))
|
||||||
|
// await ctx.DVM.methods.buyShares(lp).send(ctx.sendParam(lp))
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("FeeratemodelUpdate", () => {
|
||||||
|
let snapshotId: string;
|
||||||
|
let ctx: DVMContext;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
ctx = await getDVMContext();
|
||||||
|
await init(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
snapshotId = await ctx.EVM.snapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await ctx.EVM.reset(snapshotId);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Feeratemodel", () => {
|
||||||
|
|
||||||
|
it("feeRateUpdate", async () => {
|
||||||
|
var feeRate = await ctx.DVM.methods.getUserFeeRate(lp).call()
|
||||||
|
console.log(feeRate[1])//1000000000000000
|
||||||
|
assert.equal(
|
||||||
|
feeRate[1],
|
||||||
|
"1000000000000000"
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log('~~~~~~~~~~~~~~~~~start set new feerate~~~~~~~~~~~~~~~~~')
|
||||||
|
var feerateLogicAddress = ctx.MtFeeRateModelLogic.options.address;
|
||||||
|
|
||||||
|
await ctx.mtFeeRateModel.methods.setFeeRate(decimalStr("0.003"),feerateLogicAddress).send(ctx.sendParam(ctx.Deployer))
|
||||||
|
var feeRateSet = await ctx.DVM.methods.getUserFeeRate(lp).call()
|
||||||
|
console.log(feeRateSet[1])
|
||||||
|
assert.equal(
|
||||||
|
feeRateSet[1],
|
||||||
|
"3000000000000000"
|
||||||
|
);
|
||||||
|
console.log('~~~~~~~~~~~~~~~~~start update feerateModel~~~~~~~~~~~~~~~~~')
|
||||||
|
|
||||||
|
var feerateLogicUpdateAddress = ctx.MtFeeRateModelLogicUpdate.options.address;
|
||||||
|
await ctx.mtFeeRateModel.methods.setFeeRate(decimalStr("0.001"),feerateLogicUpdateAddress).send(ctx.sendParam(ctx.Deployer))
|
||||||
|
var feeRateUpdate = await ctx.DVM.methods.getUserFeeRate(lp).call()
|
||||||
|
console.log(feeRateUpdate[1])
|
||||||
|
assert.equal(
|
||||||
|
feeRateUpdate[1],
|
||||||
|
"4000000000000000"
|
||||||
|
);
|
||||||
|
console.log('~~~~~~~~~~~~~~~~~set feeMapping[trader] ==0 ~~~~~~~~~~~~~~~~~')
|
||||||
|
await ctx.mtFeeRateModel.methods.setSpecificFeeRate(trader,decimalStr("0.001"),feerateLogicUpdateAddress).send(ctx.sendParam(ctx.Deployer))
|
||||||
|
var feeRateTrader = await ctx.DVM.methods.getUserFeeRate(trader).call()
|
||||||
|
console.log(feeRateTrader[1])
|
||||||
|
assert.equal(// if(feeMapping[trader] == 0) return _FEE_RATE_;
|
||||||
|
feeRateUpdate[1],
|
||||||
|
"4000000000000000"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -37,6 +37,8 @@ export const PERMISSION_MANAGER_NAME = "PermissionManager"
|
|||||||
export const EXTERNAL_VALUE_NAME = "ExternalValue"
|
export const EXTERNAL_VALUE_NAME = "ExternalValue"
|
||||||
export const DODO_PROXY_NAME = "DODOV2Proxy01"
|
export const DODO_PROXY_NAME = "DODOV2Proxy01"
|
||||||
export const FEE_RATE_MODEL_NAME = "FeeRateModel"
|
export const FEE_RATE_MODEL_NAME = "FeeRateModel"
|
||||||
|
export const FEE_RATE_MODEL_LOGIC_NAME = "FeeRateModelLogic"
|
||||||
|
export const FEE_RATE_MODEL_LOGIC_UPDATE_NAME = "FeeRateModelLogicUpdate"
|
||||||
export const DPP_NAME = "DPP"
|
export const DPP_NAME = "DPP"
|
||||||
export const DPP_FACTORY_NAME = "DPPFactory"
|
export const DPP_FACTORY_NAME = "DPPFactory"
|
||||||
export const SMART_APPROVE = "DODOApprove"
|
export const SMART_APPROVE = "DODOApprove"
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ export class DVMContext {
|
|||||||
MtFeeRate: string;
|
MtFeeRate: string;
|
||||||
SpareAccounts: string[];
|
SpareAccounts: string[];
|
||||||
|
|
||||||
|
mtFeeRateModel: Contract;
|
||||||
|
|
||||||
|
MtFeeRateModelLogic: Contract;
|
||||||
|
MtFeeRateModelLogicUpdate: Contract;
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
async init(config: DVMContextInitConfig) {
|
async init(config: DVMContextInitConfig) {
|
||||||
@@ -64,8 +69,9 @@ export class DVMContext {
|
|||||||
this.Web3 = getDefaultWeb3();
|
this.Web3 = getDefaultWeb3();
|
||||||
|
|
||||||
this.DVM = await contracts.newContract(contracts.DVM_NAME)
|
this.DVM = await contracts.newContract(contracts.DVM_NAME)
|
||||||
var lpFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME)
|
var lpFeeRateModel = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
|
||||||
var mtFeeRateModel = await contracts.newContract(contracts.CONST_FEE_RATE_MODEL_NAME)
|
var mtFeeRateModel = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
|
||||||
|
this.mtFeeRateModel = mtFeeRateModel;
|
||||||
this.MtFeeRate = mtFeeRateModel.options.address
|
this.MtFeeRate = mtFeeRateModel.options.address
|
||||||
var permissionManager = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
var permissionManager = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
||||||
var gasPriceSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
|
var gasPriceSource = await contracts.newContract(contracts.EXTERNAL_VALUE_NAME)
|
||||||
@@ -103,6 +109,10 @@ export class DVMContext {
|
|||||||
await lpFeeRateModel.methods.init(this.Deployer, config.lpFeeRate).send(this.sendParam(this.Deployer))
|
await lpFeeRateModel.methods.init(this.Deployer, config.lpFeeRate).send(this.sendParam(this.Deployer))
|
||||||
await mtFeeRateModel.methods.init(this.Deployer, config.mtFeeRate).send(this.sendParam(this.Deployer))
|
await mtFeeRateModel.methods.init(this.Deployer, config.mtFeeRate).send(this.sendParam(this.Deployer))
|
||||||
|
|
||||||
|
|
||||||
|
this.MtFeeRateModelLogic = await contracts.newContract(contracts.FEE_RATE_MODEL_LOGIC_NAME)
|
||||||
|
this.MtFeeRateModelLogicUpdate = await contracts.newContract(contracts.FEE_RATE_MODEL_LOGIC_UPDATE_NAME)
|
||||||
|
|
||||||
console.log(log.blueText("[Init DVM context]"));
|
console.log(log.blueText("[Init DVM context]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ export class ProxyContext {
|
|||||||
|
|
||||||
//Functions
|
//Functions
|
||||||
DODOIncentive: Contract;
|
DODOIncentive: Contract;
|
||||||
|
MtFeeRateModelLogic: Contract;
|
||||||
|
MtFeeRateModelLogicUpdate: Contract;
|
||||||
|
|
||||||
Deployer: string;
|
Deployer: string;
|
||||||
Maintainer: string;
|
Maintainer: string;
|
||||||
@@ -78,8 +80,8 @@ export class ProxyContext {
|
|||||||
var dppAdminTemplate = await contracts.newContract(contracts.DPP_ADMIN_NAME)
|
var dppAdminTemplate = await contracts.newContract(contracts.DPP_ADMIN_NAME)
|
||||||
var permissionManagerTemplate = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
var permissionManagerTemplate = await contracts.newContract(contracts.PERMISSION_MANAGER_NAME)
|
||||||
var mtFeeRateModelTemplate = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
|
var mtFeeRateModelTemplate = await contracts.newContract(contracts.FEE_RATE_MODEL_NAME)
|
||||||
// await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0.01")).send(this.sendParam(this.Deployer));
|
await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0.01")).send(this.sendParam(this.Deployer));
|
||||||
await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0")).send(this.sendParam(this.Deployer));
|
// await mtFeeRateModelTemplate.methods.init(this.Deployer,decimalStr("0")).send(this.sendParam(this.Deployer));
|
||||||
|
|
||||||
this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME,
|
this.DVMFactory = await contracts.newContract(contracts.DVM_FACTORY_NAME,
|
||||||
[
|
[
|
||||||
@@ -150,6 +152,11 @@ export class ProxyContext {
|
|||||||
[this.WETH.options.address]
|
[this.WETH.options.address]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
this.MtFeeRateModelLogic = await contracts.newContract(contracts.FEE_RATE_MODEL_LOGIC_NAME)
|
||||||
|
this.MtFeeRateModelLogicUpdate = await contracts.newContract(contracts.FEE_RATE_MODEL_LOGIC_UPDATE_NAME)
|
||||||
|
|
||||||
|
|
||||||
console.log(log.blueText("[Init DVM context]"));
|
console.log(log.blueText("[Init DVM context]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ module.exports = {
|
|||||||
host: "127.0.0.1",
|
host: "127.0.0.1",
|
||||||
port: 8545,
|
port: 8545,
|
||||||
network_id: 5777,
|
network_id: 5777,
|
||||||
gas: 0xfffffffffff,
|
gas: 1000000000,
|
||||||
gasPrice: 1,
|
gasPrice: 1,
|
||||||
},
|
},
|
||||||
kovan: {
|
kovan: {
|
||||||
|
|||||||
Reference in New Issue
Block a user