Skip to content

Commit 0a220ed

Browse files
committed
Keep upgrade compatible
1 parent 322ed88 commit 0a220ed

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

contracts/public_data_storage.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
8484
mapping(bytes32 => CycleDataInfo) dataInfos;
8585

8686
SortedScoreList.List scoreList;
87-
uint256 totalReward; // 记录这个cycle的总奖励
87+
uint256 totalAward; // 记录这个cycle的总奖励
8888
}
8989

9090
struct CycleOutputInfo {
@@ -96,6 +96,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
9696
uint256 _currectCycle;
9797
mapping(uint256 => CycleInfo) _cycleInfos;
9898
uint256 _startBlock;
99+
uint64 _minRankingScore;
99100

100101
struct SysConfig {
101102
uint32 minDepositRatio;
@@ -222,19 +223,19 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
222223
CycleInfo storage cycleInfo = _cycleInfos[cycleNumber];
223224
// 如果cycle的reward为0,说明这个周期还没有开始
224225
// 开始一个周期:从上个周期的奖励中拿20%
225-
if (cycleInfo.totalReward == 0) {
226-
uint256 lastCycleReward = _cycleInfos[_currectCycle].totalReward;
226+
if (cycleInfo.totalAward == 0) {
227+
uint256 lastCycleReward = _cycleInfos[_currectCycle].totalAward;
227228
// 5%作为基金会收入
228229
uint256 fundationIncome = lastCycleReward * 5 / 100;
229230
gwtToken.transfer(foundationAddress, fundationIncome);
230231
// 如果上一轮的获奖数据不足32个,剩余的奖金也滚动进此轮奖池
231232
uint16 remainScore = _getRemainScore(_cycleInfos[_currectCycle].scoreList.length());
232233
uint256 remainReward = lastCycleReward * 4 * remainScore / totalRewardScore / 5;
233234

234-
cycleInfo.totalReward = lastCycleReward - (lastCycleReward * 4 / 5) - fundationIncome + remainReward;
235+
cycleInfo.totalAward = lastCycleReward - (lastCycleReward * 4 / 5) - fundationIncome + remainReward;
235236
_currectCycle = cycleNumber;
236237

237-
emit CycleStart(cycleNumber, cycleInfo.totalReward);
238+
emit CycleStart(cycleNumber, cycleInfo.totalAward);
238239
}
239240

240241
return cycleInfo;
@@ -243,7 +244,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
243244

244245
function _addCycleReward(uint256 amount) private {
245246
CycleInfo storage cycleInfo = _ensureCurrentCycleStart();
246-
cycleInfo.totalReward += amount;
247+
cycleInfo.totalAward += amount;
247248
}
248249

249250
// 计算这些空间对应多少GWT,单位是wei
@@ -307,7 +308,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
307308
}
308309

309310
function getCycleInfo(uint256 cycleNumber) public view returns(CycleOutputInfo memory) {
310-
return CycleOutputInfo(_cycleInfos[cycleNumber].totalReward, _cycleInfos[cycleNumber].scoreList.getSortedList());
311+
return CycleOutputInfo(_cycleInfos[cycleNumber].totalAward, _cycleInfos[cycleNumber].scoreList.getSortedList());
311312
}
312313

313314
function getPledgeInfo(address supplier) public view returns(SupplierInfo memory) {
@@ -585,7 +586,7 @@ contract PublicDataStorage is Initializable, UUPSUpgradeable, OwnableUpgradeable
585586
require(dataInfo.score > 0, "already withdraw");
586587

587588
// 计算该得到多少奖励
588-
uint256 totalReward = cycleInfo.totalReward * 8 / 10;
589+
uint256 totalReward = cycleInfo.totalAward * 8 / 10;
589590

590591
uint8 score = _getRewardScore(scoreListRanking);
591592
// 如果数据总量不足32,那么多余的奖励沉淀在合约账户中

test/test_public_data.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe("PublicDataStorage", function () {
7070
await (await gwtToken.enableTransfer([await contract.getAddress()])).wait();
7171

7272
nftBridge = await (await ethers.getContractFactory("OwnedNFTBridge")).deploy();
73-
await (await contract.allowPublicDataContract(await nftBridge.getAddress())).wait();
73+
await (await contract.allowPublicDataContract([await nftBridge.getAddress()])).wait();
7474
}
7575

7676
before(async () => {
@@ -325,7 +325,7 @@ describe("PublicDataStorage", function () {
325325
// data[0]可分到67,621.76 * 240 / 1600 = 10,143.264
326326
// owner获得10143.264*0.2=2028.6528
327327
//let cycleInfo = await contract.getCycleInfo(1);
328-
let tx = contract.connect(signers[0]).withdrawAward(1, TestDatas[0].hash);
328+
let tx = contract.connect(signers[0]).withdrawReward(1, TestDatas[0].hash);
329329
await expect(tx)
330330
.changeTokenBalance(gwtToken, signers[0], ethers.parseEther("2028.6528"));
331331
// sponser获得10143.264*0.5 = 5071.632
@@ -338,4 +338,16 @@ describe("PublicDataStorage", function () {
338338
.changeTokenBalance(gwtToken, signers[index], ethers.parseEther("608.59584"));
339339
}
340340
});
341+
342+
it("next cycle reward", async () => {
343+
//进行一次create来激活下个Cycle
344+
await expect(contract.createPublicData(TestDatas[1].hash, 64, ethers.parseEther("768"), await nftBridge.getAddress()))
345+
.emit(contract, "PublicDataCreated").withArgs(TestDatas[1].hash)
346+
.emit(contract, "SponsorChanged").withArgs(TestDatas[1].hash, ethers.ZeroAddress, signers[0].address)
347+
.emit(contract, "DepositData").withArgs(signers[0].address, TestDatas[1].hash, ethers.parseEther("614.4"), ethers.parseEther("153.6"))
348+
.emit(contract, "CycleStart").withArgs(2, ethers.parseEther("70157.576"));
349+
350+
// 上期奖池数量:84527.2
351+
// 本期奖池数量:84527.2 - 67,621.76 - 4,226.36 + 67,621.76 * (1600-240) / 1600 = 12,679.08 + 57,478.496 = 70,157.576
352+
})
341353
});

0 commit comments

Comments
 (0)