From ad1126d59bd76e015688f98275d43dd34252bd13 Mon Sep 17 00:00:00 2001 From: owen05 Date: Wed, 28 Apr 2021 00:04:40 +0800 Subject: [PATCH] audit fix --- contracts/DODOFee/FeeDistributer.sol | 5 +++-- .../Factory/Registries/DODONFTRegistry.sol | 22 +++++++++++++++---- .../GeneralizedFragment/impl/Fragment.sol | 16 +++++++------- migrations/5_deploy_nft.js | 2 +- test/utils/NFTContext.ts | 2 +- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/contracts/DODOFee/FeeDistributer.sol b/contracts/DODOFee/FeeDistributer.sol index ac6558a..7a75c73 100644 --- a/contracts/DODOFee/FeeDistributer.sol +++ b/contracts/DODOFee/FeeDistributer.sol @@ -124,13 +124,14 @@ contract FeeDistributor { function _claim(address sender, address to) internal { uint256 allBase = _USER_BASE_REWARDS_[sender]; uint256 allQuote = _USER_QUOTE_REWARDS_[sender]; - IERC20(_BASE_TOKEN_).safeTransfer(to, allBase); - IERC20(_QUOTE_TOKEN_).safeTransfer(to, allQuote); _BASE_RESERVE_ = _BASE_RESERVE_.sub(allBase); _QUOTE_RESERVE_ = _QUOTE_RESERVE_.sub(allQuote); _USER_BASE_REWARDS_[sender] = 0; _USER_QUOTE_REWARDS_[sender] = 0; + + IERC20(_BASE_TOKEN_).safeTransfer(to, allBase); + IERC20(_QUOTE_TOKEN_).safeTransfer(to, allQuote); emit Claim(sender, allBase, allQuote); } diff --git a/contracts/Factory/Registries/DODONFTRegistry.sol b/contracts/Factory/Registries/DODONFTRegistry.sol index 3bade5b..b9b36fb 100644 --- a/contracts/Factory/Registries/DODONFTRegistry.sol +++ b/contracts/Factory/Registries/DODONFTRegistry.sol @@ -9,6 +9,7 @@ pragma solidity 0.6.9; pragma experimental ABIEncoderV2; import {InitializableOwnable} from "../../lib/InitializableOwnable.sol"; +import {IDVM} from "../../DODOVendingMachine/intf/IDVM.sol"; interface IDODONFTRegistry { function addRegistry( @@ -26,7 +27,7 @@ interface IDODONFTRegistry { * * @notice Register DODONFT Pools */ -contract DODONFTRegistry is InitializableOwnable { +contract DODONFTRegistry is InitializableOwnable, IDODONFTRegistry { mapping (address => bool) public isAdminListed; @@ -62,7 +63,7 @@ contract DODONFTRegistry is InitializableOwnable { address quoteToken, address feeDistributor, address dvm - ) external { + ) override external { require(isAdminListed[msg.sender], "ACCESS_DENIED"); _FRAG_FEE_REGISTRY_[fragment] = feeDistributor; _DVM_FEE_REGISTRY_[dvm] = feeDistributor; @@ -79,14 +80,27 @@ contract DODONFTRegistry is InitializableOwnable { _FRAG_FEE_REGISTRY_[fragment] = address(0); _DVM_FEE_REGISTRY_[dvm] = address(0); _VAULT_FRAG_REGISTRY_[vault] = address(0); + + address quoteToken = IDVM(dvm)._QUOTE_TOKEN_(); + address[] memory registryList = _REGISTRY_[fragment][quoteToken]; + for (uint256 i = 0; i < registryList.length; i++) { + if (registryList[i] == dvm) { + if(i != registryList.length - 1) { + _REGISTRY_[fragment][quoteToken][i] = _REGISTRY_[fragment][quoteToken][registryList.length - 1]; + } + _REGISTRY_[fragment][quoteToken].pop(); + break; + } + } + emit RemoveRegistry(fragment); } - function addAmindList (address contractAddr) public onlyOwner { + function addAdminList (address contractAddr) external onlyOwner { isAdminListed[contractAddr] = true; } - function removeWhiteList (address contractAddr) public onlyOwner { + function removeAdminList (address contractAddr) external onlyOwner { isAdminListed[contractAddr] = false; } diff --git a/contracts/GeneralizedFragment/impl/Fragment.sol b/contracts/GeneralizedFragment/impl/Fragment.sol index a24b074..6fb629c 100644 --- a/contracts/GeneralizedFragment/impl/Fragment.sol +++ b/contracts/GeneralizedFragment/impl/Fragment.sol @@ -47,7 +47,7 @@ contract Fragment is InitializableERC20 { address dvm, address vaultPreOwner, address collateralVault, - uint256 totalSupply, + uint256 _totalSupply, uint256 ownerRatio, uint256 buyoutTimestamp ) external { @@ -66,12 +66,12 @@ contract Fragment is InitializableERC20 { name = string(abi.encodePacked(prefix, IDVM(_DVM_).addressToShortString(_COLLATERAL_VAULT_))); symbol = "FRAG"; decimals = 18; - super.init(address(this), totalSupply, name, symbol, decimals); + super.init(address(this), _totalSupply, name, symbol, decimals); // init FRAG distribution - uint256 vaultPreOwnerBalance = DecimalMath.mulFloor(totalSupply, ownerRatio); + uint256 vaultPreOwnerBalance = DecimalMath.mulFloor(_totalSupply, ownerRatio); _transfer(address(this), _VAULT_PRE_OWNER_, vaultPreOwnerBalance); - _transfer(address(this), _DVM_, totalSupply.sub(vaultPreOwnerBalance)); + _transfer(address(this), _DVM_, _totalSupply.sub(vaultPreOwnerBalance)); // init DVM liquidity IDVM(_DVM_).buyShares(address(this)); @@ -100,12 +100,12 @@ contract Fragment is InitializableERC20 { _clearBalance(address(this)); uint256 preOwnerQuote = DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[_VAULT_PRE_OWNER_]); - IERC20(_QUOTE_).safeTransfer(_VAULT_PRE_OWNER_, preOwnerQuote); _clearBalance(_VAULT_PRE_OWNER_); + IERC20(_QUOTE_).safeTransfer(_VAULT_PRE_OWNER_, preOwnerQuote); uint256 newOwnerQuote = DecimalMath.mulFloor(_BUYOUT_PRICE_, balances[newVaultOwner]); - IERC20(_QUOTE_).safeTransfer(newVaultOwner, newOwnerQuote); _clearBalance(newVaultOwner); + IERC20(_QUOTE_).safeTransfer(newVaultOwner, newOwnerQuote); ICollateralVault(_COLLATERAL_VAULT_).directTransferOwnership(newVaultOwner); @@ -118,8 +118,8 @@ contract Fragment is InitializableERC20 { uint256 baseAmount = balances[msg.sender]; uint256 quoteAmount = DecimalMath.mulFloor(_BUYOUT_PRICE_, baseAmount); - IERC20(_QUOTE_).safeTransfer(to, quoteAmount); _clearBalance(msg.sender); + IERC20(_QUOTE_).safeTransfer(to, quoteAmount); if (data.length > 0) { IDODOCallee(to).NFTRedeemCall( @@ -142,7 +142,7 @@ contract Fragment is InitializableERC20 { function _clearBalance(address account) internal { uint256 clearBalance = balances[account]; balances[account] = 0; - balances[address(0)] = clearBalance; + balances[address(0)] = balances[address(0)].add(clearBalance); emit Transfer(account, address(0), clearBalance); } } diff --git a/migrations/5_deploy_nft.js b/migrations/5_deploy_nft.js index 40b4d38..8384bc5 100644 --- a/migrations/5_deploy_nft.js +++ b/migrations/5_deploy_nft.js @@ -198,7 +198,7 @@ module.exports = async (deployer, network, accounts) => { logger.log("DODOApproveProxy addDODOProxy tx: ", tx.tx); const DODONFTRegistrynstance = await DODONFTRegistry.at(DODONFTRegistryAddress); - var tx = await DODONFTRegistrynstance.addAmindList(DODONFTProxyAddress); + var tx = await DODONFTRegistrynstance.addAdminList(DODONFTProxyAddress); logger.log("Add AdminList on DODONFTRegistry Tx:", tx.tx); } } diff --git a/test/utils/NFTContext.ts b/test/utils/NFTContext.ts index 514026c..a1b6170 100644 --- a/test/utils/NFTContext.ts +++ b/test/utils/NFTContext.ts @@ -122,7 +122,7 @@ export class NFTContext { await this.NFTProxy.methods.initOwner(this.Deployer).send(this.sendParam(this.Deployer)); - await this.NFTRegister.methods.addAmindList(this.NFTProxy.options.address).send(this.sendParam(this.Deployer)); + await this.NFTRegister.methods.addAdminList(this.NFTProxy.options.address).send(this.sendParam(this.Deployer)); await this.DODOApprove.methods.init(this.Deployer, this.DODOApproveProxy.options.address).send(this.sendParam(this.Deployer));