// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)pragmasolidity ^0.8.0;/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
}
Contract Source Code
File 2 of 6: DackieUSDFactory.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity ^0.8.20;import {Ownable} from"@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from"@openzeppelin/contracts/token/ERC20/IERC20.sol";
import"./interfaces/IDackieUSD.sol";
import"./interfaces/IDackieOracle.sol";
/**
* @title DackieUSDFactory
* @dev Factory contract for minting and burning Dackie USD (dckUSD) tokens.
* Inherits from Ownable to provide ownership control.
*/contractDackieUSDFactoryisOwnable{
IERC20 public dackie; // Dackie token contract
IDackieUSD public dckUSD; // Dackie USD token contract
IDackieOracle public dackieOracle; // Oracle contract for Dackie token priceeventMint(addressindexed user, uint256 dckUSDAmount, uint256 dackieAmount);
eventBurn(addressindexed user, uint256 dckUSDAmount, uint256 dackieAmount);
eventDackieOracleUpdated(addressindexed oldOracle, addressindexed newOracle);
eventOperationTransfer(addressindexed to, uint256 amount);
/**
* @dev Constructor to initialize the contract with token and oracle addresses.
* @param _dackie The address of the Dackie token contract.
* @param _dckUSD The address of the Dackie USD token contract.
* @param _dackieOracle The address of the Dackie Oracle contract.
*/constructor(address _dackie, address _dckUSD, address _dackieOracle) {
dackie = IERC20(_dackie);
dckUSD = IDackieUSD(_dckUSD);
dackieOracle = IDackieOracle(_dackieOracle);
}
/**
* @dev Mints dckUSD tokens by transferring Dackie tokens from the user to the contract.
* @param _dackieAmount The amount of Dackie tokens to use for minting.
*/functionmint(uint256 _dackieAmount) external{
require(_dackieAmount >0, "Amount must be greater than zero");
uint256 dckUSDAmount = (_dackieAmount * dackieOracle.getDackiePrice() *1e6) / (1e18*1e18);
dackie.transferFrom(msg.sender, address(this), _dackieAmount);
dckUSD.mint(msg.sender, dckUSDAmount);
emit Mint(msg.sender, dckUSDAmount, _dackieAmount);
}
/**
* @dev Burns dckUSD tokens by transferring them from the user to the contract and unlocking Dackie tokens.
* @param _dckUSDAmount The amount of dckUSD tokens to be burned.
*/functionburn(uint256 _dckUSDAmount) external{
require(_dckUSDAmount >0, "Amount must be greater than zero");
uint256 dackieAmount = ((_dckUSDAmount *1e18*1e18) / dackieOracle.getDackiePrice()) /1e6;
require(dackie.balanceOf(address(this)) >= dackieAmount, "Not enough Dackie tokens in the contract");
dckUSD.transferFrom(msg.sender, address(this), _dckUSDAmount);
dackie.transfer(msg.sender, dackieAmount);
dckUSD.burn(address(this), _dckUSDAmount);
emit Burn(msg.sender, _dckUSDAmount, dackieAmount);
}
/**
* @dev Updates the Dackie Oracle contract address. Can only be called by the owner.
* @param _dackieOracle The address of the new Oracle contract.
*/functionsetDackieOracle(address _dackieOracle) externalonlyOwner{
require(_dackieOracle !=address(0), "Invalid address");
address oldOracle =address(dackieOracle);
dackieOracle = IDackieOracle(_dackieOracle);
emit DackieOracleUpdated(oldOracle, _dackieOracle);
}
/**
* @dev Transfers Dackie tokens to a specific address by The DackieSwap DAO.
* @param _to The address to transfer Dackie tokens to.
* @param _amount The amount of Dackie tokens to transfer.
*/functionoperationTransfer(address _to, uint256 _amount) externalonlyOwner{
require(_to !=address(0), "Invalid address");
require(_amount >0, "Amount must be greater than zero");
require(dackie.balanceOf(address(this)) >= _amount, "Not enough Dackie tokens in the contract");
dackie.transfer(_to, _amount);
emit OperationTransfer(_to, _amount);
}
}
Contract Source Code
File 3 of 6: IDackieOracle.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.20;/**
* @title IDackieOracle
* @dev Interface for the DackieOracle contract.
*/interfaceIDackieOracle{
/**
* @dev Updates the operator address. Can only be called by the owner.
* @param _newOperator The address of the new operator.
*/functionupdateOperator(address _newOperator) external;
/**
* @dev Updates the price of Dackie token. Can only be called by the operator.
* @param _price The new price of Dackie token.
*/functionupdateDackiePrice(uint256 _price) external;
/**
* @dev Updates the price of Quack token. Can only be called by the operator.
* @param _price The new price of Quack token.
*/functionupdateQuackPrice(uint256 _price) external;
/**
* @dev Updates the price of dckUSD token. Can only be called by the operator.
* @param _price The new price of dckUSD token.
*/functionupdatedUSDPrice(uint256 _price) external;
/**
* @dev Returns the price of Dackie token.
* @return The current price of Dackie token.
*/functiongetDackiePrice() externalviewreturns (uint256);
/**
* @dev Returns the price of Quack token.
* @return The current price of Quack token.
*/functiongetQuackPrice() externalviewreturns (uint256);
/**
* @dev Returns the price of dckUSD token.
* @return The current price of dckUSD token.
*/functiongetDckUSDPrice() externalviewreturns (uint256);
}
Contract Source Code
File 4 of 6: IDackieUSD.sol
// SPDX-License-Identifier: UNLICENSEDpragmasolidity ^0.8.20;/**
* @title IDackieUSD
* @dev Interface for the DackieUSD token contract.
*/interfaceIDackieUSD{
/**
* @dev Updates the operator address. Can only be called by the owner.
* @param _newOperator The address of the new operator.
*/functionsetOperator(address _newOperator) external;
/**
* @dev Mints new tokens. Can only be called by the operator.
* @param _to The address to receive the minted tokens.
* @param _amount The amount of tokens to mint.
*/functionmint(address _to, uint256 _amount) external;
/**
* @dev Burns tokens from a specified address. Can only be called by the operator.
* @param _from The address from which tokens will be burned.
* @param _amount The amount of tokens to burn.
*/functionburn(address _from, uint256 _amount) external;
/**
* @dev Transfers tokens from one address to another.
* @param from The address to transfer tokens from.
* @param to The address to transfer tokens to.
* @param amount The amount of tokens to transfer.
*/functiontransferFrom(addressfrom, address to, uint256 amount) externalreturns (bool);
}
Contract Source Code
File 5 of 6: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner, address spender) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) externalreturns (bool);
}
Contract Source Code
File 6 of 6: Ownable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)pragmasolidity ^0.8.0;import"../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
require(newOwner !=address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/function_transferOwnership(address newOwner) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}