Skip to content

Commit 053b9e6

Browse files
committed
feat: update initialize version for settlement
1 parent bbec69f commit 053b9e6

28 files changed

+111
-123
lines changed

lib/surl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 034c912ae9b5e707a5afd21f145b452ad8e800df

script/Deploy.s.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import {Settlement} from "../src/Settlement.sol";
88
import {Staking} from "../src/Staking.sol";
99
import {DeployConfig} from "./DeployConfig.s.sol";
1010
import {Deployer} from "./Deployer.sol";
11-
import {TransparentUpgradeableProxy} from
12-
"@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
11+
import {
12+
TransparentUpgradeableProxy
13+
} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
1314
import {console2 as console} from "forge-std/console2.sol";
1415

1516
contract Deploy is Deployer {
@@ -86,9 +87,7 @@ contract Deploy is Deployer {
8687
function deployProxy(string memory _name) public broadcast returns (address addr_) {
8788
address logic = mustGetAddress(_stripSemver(_name));
8889
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy({
89-
_logic: logic,
90-
initialOwner: cfg.proxyAdminOwner(),
91-
_data: ""
90+
_logic: logic, initialOwner: cfg.proxyAdminOwner(), _data: ""
9291
});
9392

9493
// check states

script/Deployer.sol

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,7 @@ abstract contract Deployer is Script {
499499
/// @notice Reads the artifact from the filesystem by name and returns the Deployment.
500500
/// @param _name The name of the artifact to read.
501501
/// @return The deployment corresponding to the name.
502-
function _getExistingDeployment(string memory _name)
503-
internal
504-
view
505-
returns (Deployment memory)
506-
{
502+
function _getExistingDeployment(string memory _name) internal view returns (Deployment memory) {
507503
string memory path = string.concat(deploymentsDir, "/", _name, ".json");
508504
try vm.readFile(path) returns (string memory json) {
509505
bytes memory addr = stdJson.parseRaw(json, "$.address");

src/Chips.sol

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ contract Chips is IChips, Initializable, ERC721 {
120120
"]}"
121121
);
122122

123-
return string.concat(
124-
"data:application/json;base64,", Base64.encode(bytes(string.concat(json)))
125-
);
123+
return
124+
string.concat(
125+
"data:application/json;base64,", Base64.encode(bytes(string.concat(json)))
126+
);
126127
}
127128

128129
function tokenURI(uint256 id) public view override returns (string memory) {
@@ -151,9 +152,10 @@ contract Chips is IChips, Initializable, ERC721 {
151152
"]}"
152153
);
153154

154-
return string.concat(
155-
"data:application/json;base64,", Base64.encode(bytes(string.concat(json)))
156-
);
155+
return
156+
string.concat(
157+
"data:application/json;base64,", Base64.encode(bytes(string.concat(json)))
158+
);
157159
}
158160

159161
function _generateChipImage(uint256 tokenId)
@@ -191,13 +193,14 @@ contract Chips is IChips, Initializable, ERC721 {
191193
{
192194
Node memory node = IStaking(_staking).getNode(nodeAddr);
193195

194-
(uint8 colorCount, uint8 frameCount, uint8 chipCornerCount, uint8 chipDetailCount) =
195-
chipVersion == ChipVersion.V1
196+
(uint8 colorCount, uint8 frameCount, uint8 chipCornerCount, uint8 chipDetailCount) = chipVersion
197+
== ChipVersion.V1
196198
? SVGGenerator.getNodeTraitsCount()
197199
: SVGGeneratorV2.getNodeTraitsCount();
198200

199-
uint256 nodeTraitCount = uint256(frameCount) * uint256(colorCount)
200-
* uint256(chipDetailCount) * uint256(colorCount) * uint256(chipCornerCount);
201+
uint256 nodeTraitCount =
202+
uint256(frameCount) * uint256(colorCount) * uint256(chipDetailCount)
203+
* uint256(colorCount) * uint256(chipCornerCount);
201204

202205
// Chips from the same node will have the same traits
203206
uint256 nodeTraitId = uint256(keccak256(abi.encodePacked(nodeAddr))) % nodeTraitCount;
@@ -263,8 +266,9 @@ contract Chips is IChips, Initializable, ERC721 {
263266
(colorCount,,,) = SVGGeneratorV2.getNodeTraitsCount();
264267
}
265268

266-
uint256 chipTraitCount = uint256(eyeCount) * (mouthCount) * (headShapeCount) * (colorCount)
267-
* (headDetailCount) * (colorCount) * (nftCardCount);
269+
uint256 chipTraitCount =
270+
uint256(eyeCount) * (mouthCount) * (headShapeCount) * (colorCount) * (headDetailCount)
271+
* (colorCount) * (nftCardCount);
268272

269273
uint256 chipTraitId = seed % chipTraitCount;
270274

@@ -291,11 +295,11 @@ contract Chips is IChips, Initializable, ERC721 {
291295
uint8 colorCount,
292296
uint8 nftCardCount
293297
) internal pure returns (ChipTraits memory) {
294-
uint256 factor = uint256(mouthCount) * uint256(headShapeCount) * uint256(colorCount)
298+
uint256 factor =
299+
uint256(mouthCount) * uint256(headShapeCount) * uint256(colorCount)
295300
* uint256(headDetailCount) * uint256(colorCount) * uint256(nftCardCount);
296301

297-
return (
298-
ChipTraits({
302+
return (ChipTraits({
299303
eyesId: _calTraitId(chipTraitId, eyeCount, factor),
300304
mouthId: _calTraitId(chipTraitId, mouthCount, factor / uint256(mouthCount)),
301305
headShapeId: _calTraitId(
@@ -320,8 +324,7 @@ contract Chips is IChips, Initializable, ERC721 {
320324
(factor / uint256(mouthCount)) / uint256(headShapeCount) / uint256(colorCount)
321325
/ uint256(headDetailCount) / uint256(colorCount)
322326
)
323-
})
324-
);
327+
}));
325328
}
326329

327330
function _calTraitId(uint256 traitId, uint8 traitCount, uint256 divisionFactor)

src/NetworkParams.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
// solhint-disable comprehensive-interface
33
pragma solidity 0.8.24;
44

5-
import {AccessControlEnumerable} from
6-
"@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
5+
import {
6+
AccessControlEnumerable
7+
} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
78
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
89
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
910
import {LibZip} from "@solady/utils/LibZip.sol";

src/Settlement.sol

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import {
1313
RewardsAlreadyDistributed,
1414
SubmissionIntervalNotElapsed
1515
} from "./libraries/Errors.sol";
16-
import {AccessControlEnumerable} from
17-
"@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
16+
import {
17+
AccessControlEnumerable
18+
} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
1819
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
1920
import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol";
2021

2122
contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnumerable {
22-
string public constant version = "2.1.0";
23+
string public constant version = "2.2.0";
2324

2425
/// @dev Duration of an epoch.
2526
uint256 public constant EPOCH_DURATION = 18 hours;
@@ -49,7 +50,8 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
4950
// distributed operation rewards for each epoch
5051
mapping(uint256 epoch => uint256 operationRewards) internal _distributedOperationRewards;
5152
// rewarded node addresses
52-
mapping(uint256 epoch => mapping(address nodeAddr => bool rewarded)) internal _rewardedAddresses;
53+
mapping(uint256 epoch => mapping(address nodeAddr => bool rewarded)) internal
54+
_rewardedAddresses;
5355

5456
modifier validEpoch(uint256 epoch) {
5557
if (epoch < _currentEpoch || epoch > _currentEpoch + 1) {
@@ -75,7 +77,7 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
7577
address oracleAccount,
7678
uint256 startTime,
7779
uint256 operationRewardsPercent
78-
) external override reinitializer(4) {
80+
) external override reinitializer(5) {
7981
if (staking != address(0)) {
8082
_staking = staking;
8183
}
@@ -89,7 +91,9 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
8991
_startTimestamp = startTime;
9092
}
9193

92-
_updateRewardsRatio(operationRewardsPercent);
94+
if (operationRewardsPercent > 0) {
95+
_updateRewardsRatio(operationRewardsPercent);
96+
}
9397
}
9498

9599
/// @inheritdoc ISettlement
@@ -112,7 +116,10 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
112116
IStaking(_staking).setSettlementPhase(!isFinal);
113117

114118
// distribute rewards
115-
IStaking(_staking).distributeRewards{value: data.rewardsToSend}(
119+
IStaking(_staking)
120+
.distributeRewards{
121+
value: data.rewardsToSend
122+
}(
116123
data.epochInfo,
117124
nodeAddrs,
118125
operationRewards,
@@ -195,9 +202,8 @@ contract Settlement is ISettlement, Multicall, Initializable, AccessControlEnume
195202
function _updateRewardsRatio(uint256 operationRewardsPercent) internal {
196203
_totalOperationRewardsPerEpoch =
197204
(TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION * operationRewardsPercent) / (100 * 365 days);
198-
_totalStakingRewardsPerEpoch = (
199-
(TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION) * (100 - operationRewardsPercent)
200-
) / (100 * 365 days);
205+
_totalStakingRewardsPerEpoch = ((TOTAL_REWARDS_PER_YEAR * EPOCH_DURATION)
206+
* (100 - operationRewardsPercent)) / (100 * 365 days);
201207
}
202208

203209
/// @dev check distributed operationRewards not exceeds the max rewards per

src/Staking.sol

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import {NodeSettingsLib} from "./libraries/NodeSettingsLib.sol";
1818
import {RewardsAndSlashingLib} from "./libraries/RewardsAndSlashingLib.sol";
1919
import {StakingLib} from "./libraries/StakingLib.sol";
2020
import {StorageLib} from "./libraries/StorageLib.sol";
21-
import {AccessControlEnumerable} from
22-
"@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
21+
import {
22+
AccessControlEnumerable
23+
} from "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol";
2324
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
2425
import {Multicall} from "@openzeppelin/contracts/utils/Multicall.sol";
2526
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
@@ -85,7 +86,7 @@ contract Staking is
8586

8687
/// @dev total operation pool tokens
8788
uint256 internal _totalOperationPoolTokens; // deprecated in next version
88-
/// @dev total staking pool tokens
89+
// / @dev total staking pool tokens
8990
uint256 internal _totalStakingPoolTokens; // deprecated in next version
9091

9192
/// @dev the issuers of chips
@@ -281,11 +282,7 @@ contract Staking is
281282
}
282283

283284
/// @inheritdoc IStaking
284-
function setTaxRateBasisPoints4Node(uint64 taxRateBasisPoints)
285-
external
286-
override
287-
whenNotPaused
288-
{
285+
function setTaxRateBasisPoints4Node(uint64 taxRateBasisPoints) external override whenNotPaused {
289286
NodeSettingsLib.setTaxRateBasisPoints4Node(taxRateBasisPoints, msg.sender);
290287
}
291288

@@ -313,11 +310,7 @@ contract Staking is
313310
}
314311

315312
/// @inheritdoc IStaking
316-
function mergeChips(uint256[] calldata chipIds)
317-
external
318-
override
319-
returns (uint256 newTokenId)
320-
{
313+
function mergeChips(uint256[] calldata chipIds) external override returns (uint256 newTokenId) {
321314
return StakingLib.mergeChips(chipIds);
322315
}
323316

@@ -455,9 +448,12 @@ contract Staking is
455448
)
456449
{
457450
PoolStatData storage pool = StorageLib.poolStatStorage();
458-
return (
459-
pool.totalOperationPoolTokens, pool.totalStakingPoolTokens, pool.totalSlashingPoolTokens
460-
);
451+
return
452+
(
453+
pool.totalOperationPoolTokens,
454+
pool.totalStakingPoolTokens,
455+
pool.totalSlashingPoolTokens
456+
);
461457
}
462458

463459
/// @inheritdoc IStaking

src/base/ERC721.sol

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
5555
returns (bool)
5656
{
5757
return interfaceId == type(IERC721).interfaceId
58-
|| interfaceId == type(IERC721Metadata).interfaceId || super.supportsInterface(interfaceId);
58+
|| interfaceId == type(IERC721Metadata).interfaceId
59+
|| super.supportsInterface(interfaceId);
5960
}
6061

6162
/**
@@ -195,9 +196,9 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
195196
returns (bool)
196197
{
197198
return spender != address(0)
198-
&& (
199-
owner == spender || isApprovedForAll(owner, spender) || _getApproved(tokenId) == spender
200-
);
199+
&& (owner == spender
200+
|| isApprovedForAll(owner, spender)
201+
|| _getApproved(tokenId) == spender);
201202
}
202203

203204
/**
@@ -238,11 +239,7 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
238239
*
239240
* NOTE: If overriding this function in a way that tracks balances, see also {_increaseBalance}.
240241
*/
241-
function _update(address to, uint256 tokenId, address auth)
242-
internal
243-
virtual
244-
returns (address)
245-
{
242+
function _update(address to, uint256 tokenId, address auth) internal virtual returns (address) {
246243
address from = _ownerOf(tokenId);
247244

248245
// Perform (optional) operator check
@@ -415,9 +412,8 @@ abstract contract ERC721 is Context, ERC165, IERC721, IERC721Metadata, IERC721Er
415412
private
416413
{
417414
if (to.code.length > 0) {
418-
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (
419-
bytes4 retval
420-
) {
415+
try IERC721Receiver(to)
416+
.onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
421417
if (retval != IERC721Receiver.onERC721Received.selector) {
422418
revert ERC721InvalidReceiver(to);
423419
}

src/interfaces/IChips.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IChips {
4141
function totalSupply() external view returns (uint256);
4242

4343
/**
44-
* @notice Returns the address of the Staking contract.
44+
* @notice Returns the address of the Staking contract.
4545
* @return Address of the Staking contract.
4646
*/
4747
function stakingContract() external view returns (address);

src/interfaces/ISettlement.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ interface ISettlement {
9393
function setNodeStatus(address[] calldata nodeAddrs, NodeStatus[] calldata status) external;
9494

9595
/**
96-
* @notice Returns the address of the Staking contract.
96+
* @notice Returns the address of the Staking contract.
9797
* @return Address of the Staking contract.
9898
*/
9999
function stakingContract() external view returns (address);
@@ -105,7 +105,7 @@ interface ISettlement {
105105
function currentEpoch() external view returns (uint256);
106106

107107
/**
108-
* @notice Returns the bonus info.
108+
* @notice Returns the bonus info.
109109
* @return (operationRewardsPerEpoch, stakingRewardsPerEpoch) The amount of request bonus per
110110
* epoch.
111111
*/

0 commit comments

Comments
 (0)