Skip to content

Commit

Permalink
docs: NatSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Nov 7, 2024
1 parent af186d7 commit 3bcb0d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
10 changes: 5 additions & 5 deletions contracts/governance/Comp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ abstract contract Comp is IComp, EncryptedERC20, Ownable2Step {
* @param owner Owner address
*/
constructor(address owner) EncryptedERC20("Compound", "COMP") Ownable(owner) {
_unsafeMint(owner, TFHE.asEuint64(10000000e6)); // 10 million Comp
_unsafeMint(owner, TFHE.asEuint64(10000000e6)); /// 10 million Comp
_totalSupply = 10000000e6;

// @dev Define the constant in the storage.
/// @dev Define the constant in the storage.
_EUINT64_ZERO = TFHE.asEuint64(0);
TFHE.allowThis(_EUINT64_ZERO);
}
Expand Down Expand Up @@ -201,7 +201,7 @@ abstract contract Comp is IComp, EncryptedERC20, Ownable2Step {
uint32 lower = 0;
uint32 upper = nCheckpoints - 1;
while (upper > lower) {
// Ceil to avoid overflow.
/// Ceil to avoid overflow.
uint32 center = upper - (upper - lower) / 2;
Checkpoint memory cp = _checkpoints[account][center];

Expand All @@ -222,14 +222,14 @@ abstract contract Comp is IComp, EncryptedERC20, Ownable2Step {
if (srcRep != address(0)) {
uint32 srcRepNum = numCheckpoints[srcRep];
euint64 srcRepOld = srcRepNum > 0 ? _checkpoints[srcRep][srcRepNum - 1].votes : _EUINT64_ZERO;
euint64 srcRepNew = TFHE.sub(srcRepOld, amount); // srcRepOld - amount;
euint64 srcRepNew = TFHE.sub(srcRepOld, amount); /// srcRepOld - amount;
_writeCheckpoint(srcRep, srcRepNum, srcRepNew);
}

if (dstRep != address(0)) {
uint32 dstRepNum = numCheckpoints[dstRep];
euint64 dstRepOld = dstRepNum > 0 ? _checkpoints[dstRep][dstRepNum - 1].votes : _EUINT64_ZERO;
euint64 dstRepNew = TFHE.add(dstRepOld, amount); // dstRepOld + amount;
euint64 dstRepNew = TFHE.add(dstRepOld, amount); /// dstRepOld + amount;
_writeCheckpoint(dstRep, dstRepNum, dstRepNew);
}
}
Expand Down
9 changes: 5 additions & 4 deletions contracts/governance/GovernorAlphaZama.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
COMP = IComp(comp_);
VOTING_PERIOD = votingPeriod_;

// @dev Store these constant-like variables in the storage.
/// @dev Store these constant-like variables in the storage.
_EUINT64_ZERO = TFHE.asEuint64(0);
_EUINT64_PROPOSAL_THRESHOLD = TFHE.asEuint64(PROPOSAL_THRESHOLD);

Expand Down Expand Up @@ -330,7 +330,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
revert ProposalStateInvalid();
}

// proposal.executed = true;
/// proposal.executed = true;
for (uint256 i = 0; i < proposal.targets.length; i++) {
TIMELOCK.executeTransaction{ value: proposal.values[i] }(
proposal.targets[i],
Expand Down Expand Up @@ -590,7 +590,7 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
proposalInfo.forVotes = proposal.forVotesDecrypted;
proposalInfo.againstVotes = proposal.againstVotesDecrypted;

// The state is adjusted but not closed.
/// The state is adjusted but not closed.
if (
(proposalInfo.state == ProposalState.Queued) &&
(block.timestamp > proposalInfo.eta + TIMELOCK.GRACE_PERIOD())
Expand Down Expand Up @@ -658,7 +658,8 @@ abstract contract GovernorAlphaZama is Ownable2Step, GatewayCaller {
TFHE.allow(receipt.support, msg.sender);
TFHE.allow(receipt.votes, msg.sender);

// `support` and `votes` are encrypted values, no need to include them in the event.
/// @dev `support` and `votes` are encrypted values.
/// There is no need to include them in the event.
emit VoteCast(voter, proposalId);
}
}
8 changes: 4 additions & 4 deletions contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
function transfer(address to, euint64 amount) public virtual returns (bool) {
_isSenderAllowedForAmount(amount);

// Make sure the owner has enough tokens
/// Make sure the owner has enough tokens.
ebool canTransfer = TFHE.le(amount, _balances[msg.sender]);
_transfer(msg.sender, to, amount, canTransfer);
return true;
Expand Down Expand Up @@ -179,7 +179,7 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
revert ReceiverAddressNull();
}

// Add to the balance of `to` and subract from the balance of `from`.
/// Add to the balance of `to` and subract from the balance of `from`.
euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
euint64 newBalanceTo = TFHE.add(_balances[to], transferValue);
_balances[to] = newBalanceTo;
Expand All @@ -193,9 +193,9 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {

function _updateAllowance(address owner, address spender, euint64 amount) internal virtual returns (ebool) {
euint64 currentAllowance = _allowance(owner, spender);
// Make sure sure the allowance suffices
/// Make sure sure the allowance suffices.
ebool allowedTransfer = TFHE.le(amount, currentAllowance);
// Make sure the owner has enough tokens
/// Make sure the owner has enough tokens.
ebool canTransfer = TFHE.le(amount, _balances[owner]);
ebool isTransferable = TFHE.and(canTransfer, allowedTransfer);
_approve(owner, spender, TFHE.select(isTransferable, TFHE.sub(currentAllowance, amount), currentAllowance));
Expand Down
8 changes: 4 additions & 4 deletions contracts/token/ERC20/extensions/EncryptedERC20WithErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors {
function transfer(address to, euint64 amount) public virtual override returns (bool) {
_isSenderAllowedForAmount(amount);

// Make sure the owner has enough tokens
/// Check whether the owner has enough tokens.
ebool canTransfer = TFHE.le(amount, _balances[msg.sender]);

euint8 errorCode = TFHE.select(
Expand Down Expand Up @@ -98,7 +98,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors {
_transferNoEvent(from, to, amount, isTransferable);
emit TransferWithErrorHandling(from, to, _transferIdCounter);

// Set error code in the storage and increment
/// Set the error code in the storage and increment.
_errorCodeForTransferId[_transferIdCounter++] = errorCode;

TFHE.allowThis(errorCode);
Expand All @@ -113,7 +113,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors {
) internal virtual returns (ebool isTransferable, euint8 errorCode) {
euint64 currentAllowance = _allowance(owner, spender);

// Make sure sure the allowance suffices
/// Make sure sure the allowance suffices.
ebool allowedTransfer = TFHE.le(amount, currentAllowance);

errorCode = TFHE.select(
Expand All @@ -122,7 +122,7 @@ abstract contract EncryptedERC20WithErrors is EncryptedERC20, EncryptedErrors {
_errorCodes[uint8(ErrorCodes.NO_ERROR)]
);

// Make sure the owner has enough tokens
/// Make sure the owner has enough tokens.
ebool canTransfer = TFHE.le(amount, _balances[owner]);

errorCode = TFHE.select(
Expand Down

0 comments on commit 3bcb0d6

Please sign in to comment.