基于区块链的毕业设计oct-token-eth – 华侨城代币eth

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计oct-token-eth – 华侨城代币eth 是一篇很好的国外资料

oct-token-eth

This repository contains contracts for OCT token on Ethereum network.

Function specification

Contract ‘OctToken’

This is a contract based on standard openzeppelin-contracts ERC20 and Ownable, with following functions added:

  • The token has name OctToken and symbol OCT.
  • The token has fixed total supply – 100 million (100,000,000).
  • All of the OCT tokens will be minted to the owner (deployer) of the contract at construction time. After this, there is NO WAY to mint or burn OCT tokens.
  • Only the owner of the contract can transfer OCT tokens to other accounts until the function unlockTransfer() is called.
  • The function unlockTransfer() can ONLY be called by the owner of the contract.
  • After the owner of the contract call function unlockTransfer() the contract will act as a standard ERC20 contract, and there is NO WAY to lock the contract again.

Contract ‘OctFoundationTimelock’

This is a contract based on standard openzeppelin-contracts Ownable, with the following functions added:

  • This contract has the following constants:
    // Seconds of a day     uint256 private constant SECONDS_OF_A_DAY = 86400;      // The earliest timestamp of token release period (2021/09/01 00:00:00 GMT).     //     // Before this time NO ONE can withdraw any token from this contract.     uint256 private constant EARLIEST_RELEASE_START_TIME = 1630454400;      // The end timestamp of token release period (2024/09/01 00:00:00 GMT).     //     // After this time, ANY ONE can withdraw any amount of tokens they held.     uint256 private constant RELEASE_END_TIME = 1725148800;
  • The beneficiary of this contract is defined as follow:
// The storage data of a beneficiary // // Because the smart contract can NOT automatically execute over time, // the value of 'unreleasedBalance', 'unreleasedSupervisedBalance' and 'releasedBalance' // will be updated ONLY when 'unreleasedBalance' or 'unreleasedSupervisedBalance' // need to be modified during release period (from EARLIEST_RELEASE_START_TIME to RELEASE_END_TIME) // by calling function '_benefit(address, amount, supervised)' or 'decreaseBenefitOf(address, amount)' struct Beneficiary {     // The amount of unreleased balance of the beneficiary.     //     // This value may NOT be equal to the actual unreleased balance,     // call function 'unreleasedBalanceOf(address)' to get actual value.     uint256 unreleasedBalance;        // The amount of unreleased supervised balance of the beneficiary.     //     // This value may NOT be equal to the actual unreleased supervised balance,     // call function 'unreleasedSupervisedBalanceOf(address)' to get actual value.     uint256 unreleasedSupervisedBalance;        // The amount of released balance of the beneficiary.     //     // This value may NOT be equal to the actual total released balance,     // call function 'releasedBalanceOf(address)' to get actual value.     uint256 releasedBalance;      // The amount of withdrawed balance of the beneficiary.     //     // This value will be updated on each withdraw operation.     uint256 withdrawedBalance;      // The start time when the beneficiary can withdraw held tokens.     //     // This value will be updated ONLY when 'unreleasedBalance' or 'unreleasedSupervisedBalance'     // is changed during release period (from EARLIEST_RELEASE_START_TIME to RELEASE_END_TIME)     // for recalculating the time lock amount of held balance of beneficiary.     uint256 releaseStartTime; }
  • This contract will accept an address of contract OctToken at construction time, and the address will be immutable after construction.
  • Anyone can call function token() to get the address of contract OctToken bonded to this contract.
  • This contract has a private function _balanceToReleaseTo(address, supervised) which implements the following logic:
    • Get beneficiary corresponding to param address.
    • If block.timestamp is smaller than releaseStartTime, return 0
    • If block.timestamp is larger than RELEASE_END_TIME :
      • If param supervised is true, return unreleasedSupervisedBalance
      • If param supervised is false, return unreleasedBalance
    • Calculate passedDays : (block.timestampreleaseStartTime) / SECONDS_OF_A_DAY
    • Calculate totalDays : (RELEASE_END_TIMEreleaseStartTime) / SECONDS_OF_A_DAY
    • If param supervised is true, return unreleasedSupervisedBalance * passedDays / totalDays
    • If param supervised is false, return unreleasedBalance * passedDays / totalDays
  • Anyone can call function unreleasedBalanceOf(address) to get the total unreleased balance of a certain beneficiary corresponding to param address.
    • Get beneficiary corresponding to param address.
    • The result of this function is calculated by: unreleasedBalance_balanceToReleaseTo(address, false)
  • Anyone can call function withdrawedBalanceOf(address) to get the withdrawedBalance of a certain beneficiary corresponding to param address.
  • Anyone can call function unreleasedSupervisedBalanceOf(address) to get the total unreleased supervised balance of a certain beneficiary corresponding to param address.
    • Get beneficiary corresponding to param address.
    • The result of this function is calculated by: unreleasedSupervisedBalance_balanceToReleaseTo(address, true)
  • Anyone can call function releasedBalanceOf(address) to get the total released balance of a certain beneficiary corresponding to param address.
    • Get beneficiary corresponding to param address.
    • The result of this function is calculated by: releasedBalance + _balanceToReleaseTo(address, true) + _balanceToReleaseTo(address, false)
  • This contract has a private function _benefit(address, amount, supervised) which implements the following logic:
    • If block.timestamp is smaller than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to param address as follow:
      • unreleasedBalance :
        • If param supervised is true : NO change
        • If param supervised is false : unreleasedBalance + amount
      • releaseStartTime : EARLIEST_RELEASE_START_TIME
      • releasedBalance : NO change
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance :
        • If param supervised is true : unreleasedSupervisedBalance + amount
        • If param supervised is false : NO change
    • If block.timestamp is larger than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to param address as follow:
      • releasedBalance : releasedBalanceOf(address)
      • unreleasedBalance :
        • If param supervised is true : unreleasedBalanceOf(address)
        • If param supervised is false : unreleasedBalanceOf(address) + amount
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance :
        • If param supervised is true : unreleasedSupervisedBalanceOf(address) + amount
        • If param supervised is false : unreleasedSupervisedBalanceOf(address)
      • releaseStartTime : block.timestamp – (block.timestamp % SECONDS_OF_A_DAY)
  • Only the owner (deployer) of this contract can call function benefit(address, amount, supervised) to increase benefit of a certain beneficiary corresponding to param address.
    • This function is a simple wraper of private function _benefit(address, amount, supervised).
    • The param address MUST be an EOA address. (This will be verified by the owner of this contract rather than by contract code.)
  • Anyone can call function withdraw(amount) to withdraw a certain amount tokens to the address of himself.
    • Get beneficiary corresponding to _msgSender().
    • The param amount must be less or equal to avaialable balance, which is calculated by: releasedBalanceOf(_msgSender())withdrawedBalance
    • The param amount must be less or equal to token().balanceOf(address(this)).
    • Increase withdrawedBalance by amount.
    • Transfer amount of OCT tokens to _msgSender().
  • Anyone can call function transferUnreleasedBalance(address, amount, msgHash, v, r, s) to transfer a part or whole of his unreleased balance to another account (address).
    • Get beneficiary corresponding to _msgSender().
    • The param amount must be less or equal to unreleasedBalanceOf(_msgSender())
    • The param address MUST be an EOA. (The param address should be equal to the address recovered by solidity global function ecrecover using param msgHash, v, r and s).
    • If block.timestamp is smaller than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to _msgSender() as follow:
      • unreleasedBalance : unreleasedBalanceamount
      • releaseStartTime : EARLIEST_RELEASE_START_TIME
      • releasedBalance : NO change
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : NO change
    • If block.timestamp is larger than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to _msgSender() as follow:
      • releasedBalance : releasedBalanceOf(_msgSender())
      • unreleasedBalance : unreleasedBalanceOf(_msgSender())amount
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceOf(_msgSender())
      • releaseStartTime : block.timestamp – (block.timestamp % SECONDS_OF_A_DAY)
    • Call private function _benefit(address, amount, false).
  • Only the owner (deployer) of this contract can call function decreaseBenefitOf(address, amount) to decrease the benefit of a certain beneficiary corresponding to param address.
    • Get beneficiary corresponding to param address.
    • The param amount must be less or equal to unreleasedSupervisedBalanceOf(address)
    • If block.timestamp is smaller than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to address as follow:
      • unreleasedBalance : NO change
      • releaseStartTime : EARLIEST_RELEASE_START_TIME
      • releasedBalance : NO change
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceamount
    • If block.timestamp is larger than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to address as follow:
      • releasedBalance : releasedBalanceOf(address)
      • unreleasedBalance : unreleasedBalanceOf(address)
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceOf(address)amount
      • releaseStartTime : block.timestamp – (block.timestamp % SECONDS_OF_A_DAY)

Installation

Install dependencies

Install openzeppelin/contracts.

npm install @openzeppelin/contracts

Install dependencies for development

Install hardhat for testing.

npm install --save-dev hardhat

Install modules for running testing scripts compatible with Waffle.

npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

Test

You can run the tests by:

npx hardhat test

or

npm run test

oct令牌eth

此存储库包含以太坊eth网络上OCT令牌的合同

功能规范

合同“OctToken”

这是基于标准openzeppelin contracts ERC20和Ownable的合同,添加了以下功能:

  • 代币的固定总供应量为1亿(100000000)
  • 只有合同的所有者才能将OCT令牌转移到其他帐户,直到调用函数unlockTransfer()
  • 函数unlockTransfer()只能由合同所有者调用
  • 在契约的所有者调用函数unlockTransfer()后,契约将作为标准ERC20契约,无法再次锁定契约
  • 本合同具有以下常量:
  • 本合同的受益人定义如下:

安装开发依赖项

这是基于标准openzeppelin contracts Ownable的合同,添加了以下功能:

  • 本合同将在施工时接受合同地址,且该地址在施工后不可更改
    // Seconds of a day     uint256 private constant SECONDS_OF_A_DAY = 86400;      // The earliest timestamp of token release period (2021/09/01 00:00:00 GMT).     //     // Before this time NO ONE can withdraw any token from this contract.     uint256 private constant EARLIEST_RELEASE_START_TIME = 1630454400;      // The end timestamp of token release period (2024/09/01 00:00:00 GMT).     //     // After this time, ANY ONE can withdraw any amount of tokens they held.     uint256 private constant RELEASE_END_TIME = 1725148800;
  • 任何人都可以调用函数token()来获取绑定到此合同的合同token的地址
// The storage data of a beneficiary // // Because the smart contract can NOT automatically execute over time, // the value of 'unreleasedBalance', 'unreleasedSupervisedBalance' and 'releasedBalance' // will be updated ONLY when 'unreleasedBalance' or 'unreleasedSupervisedBalance' // need to be modified during release period (from EARLIEST_RELEASE_START_TIME to RELEASE_END_TIME) // by calling function '_benefit(address, amount, supervised)' or 'decreaseBenefitOf(address, amount)' struct Beneficiary {     // The amount of unreleased balance of the beneficiary.     //     // This value may NOT be equal to the actual unreleased balance,     // call function 'unreleasedBalanceOf(address)' to get actual value.     uint256 unreleasedBalance;        // The amount of unreleased supervised balance of the beneficiary.     //     // This value may NOT be equal to the actual unreleased supervised balance,     // call function 'unreleasedSupervisedBalanceOf(address)' to get actual value.     uint256 unreleasedSupervisedBalance;        // The amount of released balance of the beneficiary.     //     // This value may NOT be equal to the actual total released balance,     // call function 'releasedBalanceOf(address)' to get actual value.     uint256 releasedBalance;      // The amount of withdrawed balance of the beneficiary.     //     // This value will be updated on each withdraw operation.     uint256 withdrawedBalance;      // The start time when the beneficiary can withdraw held tokens.     //     // This value will be updated ONLY when 'unreleasedBalance' or 'unreleasedSupervisedBalance'     // is changed during release period (from EARLIEST_RELEASE_START_TIME to RELEASE_END_TIME)     // for recalculating the time lock amount of held balance of beneficiary.     uint256 releaseStartTime; }
  • 本合同有一个私有函数“balanceToReleaseTo”(地址,受监管),该函数实现以下逻辑:获取与参数地址对应的受益人。如果block.timestamp小于releaseStartTime,如果block.timestamp大于RELEASE_END_TIME,则返回0:如果param supervised为true,如果param supervised为false,则返回unreleasedSupervisedBalance,返回unreleasedBalance Calculated passedDays:(block.timestamp-releaseStartTime)/SECONDS_OF A_DAY计算totalDays:(RELEASE_END_TIME-releaseStartTime)/SECONDS_OF A_DAY如果param supervised为true,则返回unreleasedSupervisedBalance*passedDays/totalDays如果param supervised为false,返回未释放余额*已过天数/总天数
  • 获取参数地址对应的受益人
  • 如果block.timestamp小于releaseStartTime,如果block.timestamp大于RELEASEu ENDu TIME,则返回0
  • 任何人都可以调用函数DrumedBalanceOf(address)来获取与param address相对应的某个受益人的提款余额
  • 此函数的结果通过以下公式计算:unreleasedSupervisedBalance-u balanceToReleaseTo(address,true)
  • 任何人都可以调用函数releasedBalanceOf(address),以获得与param address相对应的某个受益人的总已释放余额。获取对应于参数地址的受益人。此函数的结果通过以下方式计算:releasedBalance+u balanceToReleaseTo(地址,true)+u balanceToReleaseTo(地址,false)
  • 此合同有一个私有函数u benefit(地址,金额,监督),它实现以下逻辑:如果block.timestamp小于最早的u RELEASEu开始时间,更新参数地址对应的受益人的属性,如下所示:未释放余额:如果参数受监管为真:如果参数受监管为假,则无更改:未释放余额+金额释放开始时间:最早释放开始时间释放余额:无更改取款余额:无更改未释放受监管余额:如果param supervised为true:UnreleasedSupervised余额+金额(如果param supervised为false):如果block.timestamp大于最早发布开始时间,则无变化,更新参数地址对应的受益人的属性如下:releasedBalance:releasedBalanceOf(address)unreleasedBalanceOf(address)unreleasedBalanceOf(address):如果参数supervised为true:unreleasedBalanceOf(address)如果参数supervised为false:unreleasedBalanceOf(address)+金额取款余额:无更改unreleasedBalanceOf(address):如果监控参数为真:未释放的监控余额(地址)+金额(如果监控参数为假):未释放的监控余额(地址)释放开始时间:block.timestamp-(block.timestamp%秒/天)
  • 监管参数为假:未释放余额+金额
  • Only the owner (deployer) of this contract can call function benefit(address, amount, supervised) to increase benefit of a certain beneficiary corresponding to param address.
    • This function is a simple wraper of private function _benefit(address, amount, supervised).
    • The param address MUST be an EOA address. (This will be verified by the owner of this contract rather than by contract code.)
  • Anyone can call function withdraw(amount) to withdraw a certain amount tokens to the address of himself.
    • Get beneficiary corresponding to _msgSender().
    • The param amount must be less or equal to avaialable balance, which is calculated by: releasedBalanceOf(_msgSender())withdrawedBalance
    • The param amount must be less or equal to token().balanceOf(address(this)).
    • Increase withdrawedBalance by amount.
    • Transfer amount of OCT tokens to _msgSender().
  • Anyone can call function transferUnreleasedBalance(address, amount, msgHash, v, r, s) to transfer a part or whole of his unreleased balance to another account (address).
    • Get beneficiary corresponding to _msgSender().
    • The param amount must be less or equal to unreleasedBalanceOf(_msgSender())
    • The param address MUST be an EOA. (The param address should be equal to the address recovered by solidity global function ecrecover using param msgHash, v, r and s).
    • If block.timestamp is smaller than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to _msgSender() as follow:
      • unreleasedBalance : unreleasedBalanceamount
      • releaseStartTime : EARLIEST_RELEASE_START_TIME
      • releasedBalance : NO change
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : NO change
    • If block.timestamp is larger than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to _msgSender() as follow:
      • releasedBalance : releasedBalanceOf(_msgSender())
      • unreleasedBalance : unreleasedBalanceOf(_msgSender())amount
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceOf(_msgSender())
      • releaseStartTime : block.timestamp – (block.timestamp % SECONDS_OF_A_DAY)
    • Call private function _benefit(address, amount, false).
  • Only the owner (deployer) of this contract can call function decreaseBenefitOf(address, amount) to decrease the benefit of a certain beneficiary corresponding to param address.
    • Get beneficiary corresponding to param address.
    • The param amount must be less or equal to unreleasedSupervisedBalanceOf(address)
    • If block.timestamp is smaller than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to address as follow:
      • unreleasedBalance : NO change
      • releaseStartTime : EARLIEST_RELEASE_START_TIME
      • releasedBalance : NO change
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceamount
    • If block.timestamp is larger than EARLIEST_RELEASE_START_TIME, update the properties of the beneficiary corresponding to address as follow:
      • releasedBalance : releasedBalanceOf(address)
      • unreleasedBalance : unreleasedBalanceOf(address)
      • withdrawedBalance : NO change
      • unreleasedSupervisedBalance : unreleasedSupervisedBalanceOf(address)amount
      • releaseStartTime : block.timestamp – (block.timestamp % SECONDS_OF_A_DAY)

测试

Install dependencies

安装openzeppelin/contracts

npm install @openzeppelin/contracts

Install dependencies for development

安装安全帽进行测试

npm install --save-dev hardhat

安装模块以运行与华夫格兼容的测试脚本

npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers

Test

您可以通过以下方式运行测试:

npx hardhat test

npm run test

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/23490.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计oct-token-eth – 华侨城代币eth

提供最优质的资源集合

立即查看 了解详情