From 7b61785af25b1385f09125ea89a64af0af49d37e Mon Sep 17 00:00:00 2001 From: weiqiushi Date: Fri, 29 Dec 2023 18:34:43 +0800 Subject: [PATCH] Add fundation address to contract, add some view interface --- contracts/public_data_storage.sol | 21 +++++++++++++++-- doc/user-story.md | 39 +++++++++++++++---------------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/contracts/public_data_storage.sol b/contracts/public_data_storage.sol index 10b8196..44c783c 100644 --- a/contracts/public_data_storage.sol +++ b/contracts/public_data_storage.sol @@ -57,6 +57,8 @@ contract PublicDataStorage { GWTToken public gwtToken;// Gb per Week Token + address public foundationAddress; + mapping(address => SupplierInfo) supplier_infos; mapping(bytes32 => PublicData) public_datas; @@ -76,6 +78,11 @@ contract PublicDataStorage { uint256 total_award; // 记录这个cycle的总奖励 } + struct CycleOutputInfo { + uint256 total_reward; + bytes32[] data_ranking; + } + mapping(uint256 => CycleInfo) cycle_infos; uint256 startBlock; @@ -107,10 +114,11 @@ contract PublicDataStorage { event ShowDataProof(address supplier, bytes32 dataMixedHash, uint256 nonce_block_high, uint32 index_m, bytes32 proof_result); event WithdrawAward(bytes32 mixedHash, address user, uint256 amount); - constructor(address _gwtToken) { + constructor(address _gwtToken, address _Foundation) { gwtToken = GWTToken(_gwtToken); startBlock = block.number; currectCycle = 0; + foundationAddress = _Foundation; } function _getRewardScore(uint256 ranking) internal pure returns(uint256) { @@ -230,6 +238,14 @@ contract PublicDataStorage { return cycle_infos[_cycleNumber()].data_infos[dataMixedHash].last_showers; } + function getDataInCycle(uint256 cycleNumber, bytes32 dataMixedHash) public view returns(CycleDataInfo memory) { + return cycle_infos[cycleNumber].data_infos[dataMixedHash]; + } + + function getCycleInfo(uint256 cycleNumber) public view returns(CycleOutputInfo memory) { + return CycleOutputInfo(cycle_infos[cycleNumber].total_award, cycle_infos[cycleNumber].score_list.getSortedList()); + } + function getOwner(bytes32 dataMixedHash) public view returns(address) { PublicData memory info = public_datas[dataMixedHash]; if (info.owner != address(0)) { @@ -348,8 +364,9 @@ contract PublicDataStorage { // 当reward为0时,要不要增加积分? emit SupplierReward(publicDataInfo.prover, dataMixedHash, reward); if (reward > 0) { - // 奖励的80%给supplier,20%被基金会收走,这里实现成还是保存在合约自己的账户上先 + // 奖励的80%给supplier,20%被基金会收走 gwtToken.transfer(publicDataInfo.prover, reward * 8 / 10); + gwtToken.transfer(foundationAddress, reward - reward * 8 / 10); publicDataInfo.data_balance -= reward; } is_new_show = true; diff --git a/doc/user-story.md b/doc/user-story.md index 429e361..d77c5f0 100644 --- a/doc/user-story.md +++ b/doc/user-story.md @@ -84,7 +84,7 @@ DMC上DeFi ``` function createPublicData( bytes32 dataMixedHash, - uint64 depositRatio, //默认为 64,文件大小为1G,矿工需要锁定1*depositRatio*24的质押币 (SHOW相当于用户承诺保存24周) + uint64 depositRatio, //默认为 64,文件大小为1G,矿工需要锁定1*depositRatio*96的质押币 (SHOW相当于用户承诺保存96周) uint256 depositAmount, //希望打入的GWT余额 address publicDataContract, uint256 tokenId @@ -163,28 +163,27 @@ function showData(bytes32 dataMixedHash, uint256 nonce_block, uint32 index, byte ## Award计算 每个周期的奖励 = 上个周期的奖励 * 0.15 + 这个周期的所有赞助 * 0.2, 每个周期奖池的0.05会作为基金会的收入 -发放奖励的规则:每周期内奖池分配: 第一名记240分,依次递减,最后一名记13分。按照 总奖池* 0.8 * 自己的分数/总分数得到奖励 +发放奖励的规则:每周期内奖池分配: 第一名记240分,依次递减,最后一名记14分。按照 总奖池* 0.8 * 自己的分数/总分数得到奖励 完整的奖励积分分配如下: ``` - 1.240 - 2.180 - 3.150 - 4.120 - 5.100 - 6.80 - 7.60 - 8.50 - 9.40 - 10.35 - 11.34 - 12.33 - 13.32 - 14.31 - 15.30 - 16.29 - 17.28 + 1. 240 + 2. 180 + 3. 150 + 4. 120 + 5. 100 + 6. 80 + 7. 60 + 8. 53 + 9. 42 + 10.36 + 11.35 + 12.34 + 13.33 + 14.32 + 15.31 + 16.30 .... - 32.13 + 32.14 ``` 链上只保存前32名,按现在的需求需要展示前50名,需要后台做一些计算。