Skip to content

Commit

Permalink
🐴 Upgrade to solidity 0.8.20
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Jun 14, 2023
1 parent 6b24681 commit e65aad3
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 140 deletions.
41 changes: 9 additions & 32 deletions contracts/KilitliTCKO.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// 🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "interfaces/Addresses.sol";
import "interfaces/DistroStage.sol";
Expand Down Expand Up @@ -47,12 +47,9 @@ contract KilitliTCKO is IERC20 {

uint256 private constant BALANCE0_MASK = type(uint256).max >> 128;

function balanceOf(address account)
external
view
override
returns (uint256)
{
function balanceOf(
address account
) external view override returns (uint256) {
unchecked {
uint256 balance = balances[account];
return (balance & BALANCE0_MASK) + (balance >> 128);
Expand All @@ -72,24 +69,18 @@ contract KilitliTCKO is IERC20 {
return false;
}

function allowance(address, address)
external
pure
override
returns (uint256)
{
function allowance(
address,
address
) external pure override returns (uint256) {
return 0;
}

function approve(address, uint256) external pure override returns (bool) {
return false;
}

function mint(
address account,
uint256 amount,
DistroStage stage
) external {
function mint(address account, uint256 amount, DistroStage stage) external {
require(msg.sender == TCKO_ADDR);
unchecked {
if (uint256(stage) & 1 == 0) {
Expand Down Expand Up @@ -180,20 +171,6 @@ contract KilitliTCKO is IERC20 {
}
}

/**
* Deletes the contract if all TCKO-k's have been unlocked.
*/
function selfDestruct() external {
// We restrict this method to `DEV_KASASI` as there may be ERC20 tokens
// sent to this contract by accident waiting to be rescued.
require(msg.sender == DEV_KASASI);
require(
HasDistroStage(TCKO_ADDR).distroStage() == DistroStage.FinalUnlock
);
require(totalSupply == 0);
selfdestruct(DAO_KASASI);
}

/**
* Moves ERC20 tokens sent to this address by accident to `DAO_KASASI`.
*/
Expand Down
105 changes: 42 additions & 63 deletions contracts/TCKO.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
// 🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿🧿

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "./KilitliTCKO.sol";
import {OYLAMA} from "interfaces/Addresses.sol";
Expand Down Expand Up @@ -172,12 +172,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function balanceOf(address account)
external
view
override
returns (uint256)
{
function balanceOf(
address account
) external view override returns (uint256) {
return balances[account] & BALANCE_MASK;
}

Expand All @@ -195,11 +192,10 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
* @param to the address of the recipient.
* @param amount amount of TCKOs * 1e6.
*/
function transfer(address to, uint256 amount)
external
override
returns (bool)
{
function transfer(
address to,
uint256 amount
) external override returns (bool) {
// Disallow sending to the 0 address, which is a common software / user
// error.
require(to != address(0));
Expand Down Expand Up @@ -266,31 +262,30 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
return true;
}

function approve(address spender, uint256 amount)
external
override
returns (bool)
{
function approve(
address spender,
uint256 amount
) external override returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}

function increaseAllowance(address spender, uint256 addedAmount)
external
returns (bool)
{
function increaseAllowance(
address spender,
uint256 addedAmount
) external returns (bool) {
// Checked addition
uint256 newAmount = allowance[msg.sender][spender] + addedAmount;
allowance[msg.sender][spender] = newAmount;
emit Approval(msg.sender, spender, newAmount);
return true;
}

function decreaseAllowance(address spender, uint256 subtractedAmount)
external
returns (bool)
{
function decreaseAllowance(
address spender,
uint256 subtractedAmount
) external returns (bool) {
// Checked subtraction
uint256 newAmount = allowance[msg.sender][spender] - subtractedAmount;
allowance[msg.sender][spender] = newAmount;
Expand Down Expand Up @@ -525,12 +520,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
// |-- 24 --|-- 20 --|-- 20 --|-- 48 --|-- 48 --|-- 48 --|-- 48 --|
uint256 private tick;

function snapshot0BalanceOf(address account)
external
view
override
returns (uint256)
{
function snapshot0BalanceOf(
address account
) external view override returns (uint256) {
uint256 balance = balances[account];
unchecked {
return
Expand All @@ -539,11 +531,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function consumeSnapshot0Balance(address account)
external
override
returns (uint256)
{
function consumeSnapshot0Balance(
address account
) external override returns (uint256) {
require(msg.sender == OYLAMA);
uint256 info = balances[account];
unchecked {
Expand All @@ -556,12 +546,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function snapshot1BalanceOf(address account)
external
view
override
returns (uint256)
{
function snapshot1BalanceOf(
address account
) external view override returns (uint256) {
uint256 info = balances[account];
unchecked {
return
Expand All @@ -570,11 +557,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function consumeSnapshot1Balance(address account)
external
override
returns (uint256)
{
function consumeSnapshot1Balance(
address account
) external override returns (uint256) {
require(msg.sender == OYLAMA);
uint256 info = balances[account];
unchecked {
Expand All @@ -587,12 +572,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function snapshot2BalanceOf(address account)
external
view
override
returns (uint256)
{
function snapshot2BalanceOf(
address account
) external view override returns (uint256) {
uint256 info = balances[account];
unchecked {
return
Expand All @@ -601,11 +583,9 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function consumeSnapshot2Balance(address account)
external
override
returns (uint256)
{
function consumeSnapshot2Balance(
address account
) external override returns (uint256) {
require(msg.sender == OYLAMA);
uint256 info = balances[account];
unchecked {
Expand Down Expand Up @@ -641,11 +621,10 @@ contract TCKO is IERC20Permit, IERC20Snapshot3, HasDistroStage {
}
}

function preserve(uint256 balance, uint256 t)
internal
pure
returns (uint256)
{
function preserve(
uint256 balance,
uint256 t
) internal pure returns (uint256) {
unchecked {
// tick.tick0 doesn't match balance.tick0; we need to preserve the
// current balance.
Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ds-test/=lib/interfaces/lib/forge-std/lib/ds-test/src/
ds-test/=lib/forge-std/lib/ds-test/src/
forge-std/=lib/forge-std/src/
interfaces/=lib/interfaces/contracts/
3 changes: 2 additions & 1 deletion test/ReentrancyAttackContracts.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;

pragma solidity 0.8.20;

import "forge-std/Test.sol";
import {DAO_KASASI, TCKO_ADDR} from "interfaces/Addresses.sol";
Expand Down
6 changes: 3 additions & 3 deletions test/ReentrancyTest.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "./ReentrancyAttackContracts.sol";
import "contracts/TCKO.sol";
import "forge-std/Test.sol";
import {MockDAOKasasi} from "interfaces/testing/MockDAOKasasi.sol";
import {MockDAOKasasiV1} from "interfaces/testing/MockDAOKasasiV1.sol";

contract ReentrancyTest is Test {
TCKO private tcko;
Expand All @@ -29,7 +29,7 @@ contract ReentrancyTest is Test {
vm.stopPrank();

vm.prank(DAO_KASASI_DEPLOYER);
daoKasasi = new MockDAOKasasi();
daoKasasi = new MockDAOKasasiV1();

vm.deal(DAO_KASASI, 80e18);

Expand Down
6 changes: 3 additions & 3 deletions test/TCKOGasTest.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "contracts/TCKO.sol";
import "forge-std/Test.sol";
import "interfaces/testing/MockDAOKasasi.sol";
import "interfaces/testing/MockDAOKasasiV1.sol";
import {MockERC20Permit} from "interfaces/testing/MockTokens.sol";

contract TCKOGasTest is Test {
Expand All @@ -21,7 +21,7 @@ contract TCKOGasTest is Test {
tckok = new KilitliTCKO();

vm.prank(DAO_KASASI_DEPLOYER);
daoKasasi = new MockDAOKasasi();
daoKasasi = new MockDAOKasasiV1();

mintAll(1e12);
vm.deal(DAO_KASASI, 80e18);
Expand Down
6 changes: 3 additions & 3 deletions test/TCKOMintTest.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "forge-std/Test.sol";
import "interfaces/Addresses.sol";
import {IDAOKasasi} from "interfaces/IDAOKasasi.sol";
import {MockDAOKasasi} from "interfaces/testing/MockDAOKasasi.sol";
import {MockDAOKasasiV1} from "interfaces/testing/MockDAOKasasiV1.sol";
import {TCKO, KilitliTCKO} from "contracts/TCKO.sol";

contract TCKOMintTest is Test {
Expand All @@ -21,7 +21,7 @@ contract TCKOMintTest is Test {
tcko = new TCKO(true);

vm.prank(DAO_KASASI_DEPLOYER);
daoKasasi = new MockDAOKasasi();
daoKasasi = new MockDAOKasasiV1();
}

function testBalances() external {
Expand Down
4 changes: 2 additions & 2 deletions test/TCKOSnapshotTest.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.18;
pragma solidity 0.8.20;

import "contracts/TCKO.sol";
import "forge-std/Test.sol";
Expand All @@ -26,7 +26,7 @@ contract TCKOSnapshotTest is Test {
tckok = new KilitliTCKO();

vm.prank(DAO_KASASI_DEPLOYER);
daoKasasi = new MockDAOKasasi();
daoKasasi = IDAOKasasi(address(new MockDAOKasasi()));

mintAll(1e12);
}
Expand Down
Loading

0 comments on commit e65aad3

Please sign in to comment.