Skip to content

Commit

Permalink
Add fundation address to contract, add some view interface
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiushi committed Dec 29, 2023
1 parent c8434b6 commit 7b61785
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
21 changes: 19 additions & 2 deletions contracts/public_data_storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down
39 changes: 19 additions & 20 deletions doc/user-story.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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名,需要后台做一些计算。
Expand Down

0 comments on commit 7b61785

Please sign in to comment.