一、准备
本合约主要实现代币的定量和百分比模式的下发。用户根据需要选择定量或者百分比将合约地址中的代币下发到指定的钱包地址,每天固定时间调用合约,将合约地址中的代币下发给指定的用户。该合约适用于如下业务需求场景:
场景一:代币私募完成后,每个地址私募相同数量的代币,但是代币是线性释放模式,即每天定时定量将私募的代币下发到私募钱包地址,固定周期内释放完成。
场景二:锁仓指定数量的代币,每天定时线性释放代币到原来的锁定地址。
场景三:质押挖矿模式,用户质押指定数量的WETH到合约地址中,合约地址每天线下释放挖矿收益币种到质押来源地址。
该合约主要包括如下功能:
1、代币可以每天定时下发固定数量的代币到指定的下发地址中。
2、代币可以每天定时下发当前合约地址代币余额固定百分比数量的代币到指定的下发地址中。
3、下发地址预先配置到合约中,在后期可以排除下发地址。
4、合约具备合约所有权,只有合约所有权账号才可以配置合约的动态参数。
5、支持赎回BNB,和所有ERC20标准的代币
6、支持设置批量下发的gas费用上限,根据下发地址数量,动态调整gas费用上限。
7、合约中限定了批量下发的代币合约地址,必须是指定的代币才能实现批量下发,转入其他代币无法实现批量下发功能。
8、两次下发的冷却时间是200个块高度,避免误操作导致的短时间内重复下发。
二、合约部署
1、合约主要有以下几个sol文件组成
IERC20.sol SafeMath.sol IERC20Metadata.sol Context.sol Ownable.sol Address.sol Tools.sol
2、配置编译器相关的参数
3、按照以下顺序编译合约文件
4、部署合约
选择metamask钱包作为web3客户端,部署合约
要部署的目标合约名称为Tools
fundaddress: 赎回BNB时,目标接收地址
issuedToken:批量下发的代币合约地址
rationcounts:定量下发的次数
5、合约部署完成后,根据transaction hash确定合约地址,确认合约部署详情
6、核心部分功能源代码如下:
// SPDX-License-Identifier: MIT pragma solidity ^0.6.2; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-low-level-calls, avoid-call-value (bool success, ) = recipient.call{ value: amount }(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain`call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { return _functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); return _functionCallWithValue(target, data, value, errorMessage); } function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) { require(isContract(target), "Address: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.call{ value: weiValue }(data); if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly // solhint-disable-next-line no-inline-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
通过以上address类地址工具包处理相关地址定量或者百分比下发及线性释放代币的核心功
三、完整版本的合约源码
至此,完成代币锁定后定量或者百分比定期下发线性释放到指定钱包地址合约部署操作流程所有操作环节。
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载:
币安智能链BSC发币(合约部署、开源、锁仓、LP、参数配置、开发、故障处理、工具使用)教程下载:
多模式(燃烧、回流指定营销地址、分红本币及任意币种,邀请推广八代收益,LP加池分红、交易分红、复利分红、NFT分红、自动筑池、动态手续费、定时开盘、回购)组合合约源代码下载:
pdf+视频币安智能链BSC发币教程及多模式组合合约源代码下载地址:
此内容仅供注册用户可见,请登录!
添加VX或者telegram获取全程线上免费指导
评论前必须登录!
注册