1
0
forked from mico/idle_moloch

Compare commits

...

4 Commits

Author SHA1 Message Date
san
5255856727 fix errors with upgradeable contracts 2024-10-29 00:28:30 +05:30
san
20b81db5e7 forge install: openzeppelin-contracts-upgradeable
v5.1.0
2024-10-27 22:30:01 +05:30
san
0477e3be1a forge install: openzeppelin-foundry-upgrades
v0.3.6
2024-10-27 22:29:16 +05:30
san
06cc9fa717 make contracts upgradeable 2024-10-27 22:25:19 +05:30
8 changed files with 49 additions and 9 deletions

6
.gitmodules vendored
View File

@ -4,3 +4,9 @@
[submodule "lib/openzeppelin-contracts"] [submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib\\openzeppelin-foundry-upgrades"]
path = lib\\openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
[submodule "lib\\openzeppelin-contracts-upgradeable"]
path = lib\\openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable

View File

@ -2,5 +2,9 @@
src = "src" src = "src"
out = "out" out = "out"
libs = ["lib"] libs = ["lib"]
ffi = true
ast = true
build_info = true
extra_output = ["storageLayout"]
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options # See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

@ -0,0 +1 @@
Subproject commit fa525310e45f91eb20a6d3baa2644be8e0adba31

@ -0,0 +1 @@
Subproject commit 16e0ae21e0e39049f619f2396fa28c57fad07368

View File

@ -1 +1,2 @@
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ @openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/

View File

@ -3,15 +3,26 @@ pragma solidity ^0.8.13;
import {Script, console} from "forge-std/Script.sol"; import {Script, console} from "forge-std/Script.sol";
import {RaidGeld} from "../src/RaidGeld.sol"; import {RaidGeld} from "../src/RaidGeld.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
contract RaidGeldScript is Script { contract RaidGeldScript is Script {
RaidGeld public raidgeld;
function setUp() public {} function setUp() public {}
function run() public { function run() public {
vm.startBroadcast(); vm.startBroadcast();
raidgeld = new RaidGeld();
// Deploy the upgradeable contract
address _proxyAddress = Upgrades.deployTransparentProxy(
"RaidGeld.sol",
msg.sender,
abi.encodeCall(RaidGeld.initialize, ())
);
// Get the implementation address
address implementationAddress = Upgrades.getImplementationAddress(
_proxyAddress
);
vm.stopBroadcast(); vm.stopBroadcast();
} }
} }

View File

@ -1,12 +1,13 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {RaidGeldUtils} from "../src/RaidGeldUtils.sol"; import {RaidGeldUtils} from "../src/RaidGeldUtils.sol";
import {Army, Player, Raider} from "../src/RaidGeldStructs.sol"; import {Army, Player, Raider} from "../src/RaidGeldStructs.sol";
contract RaidGeld is ERC20, Ownable { contract RaidGeld is Initializable, ERC20Upgradeable, OwnableUpgradeable {
uint256 public constant MANTISSA = 1e4; uint256 public constant MANTISSA = 1e4;
uint256 public constant BUY_IN_AMOUNT = 0.00005 ether; uint256 public constant BUY_IN_AMOUNT = 0.00005 ether;
@ -21,7 +22,10 @@ contract RaidGeld is ERC20, Ownable {
_; _;
} }
constructor() ERC20("Raid Geld", "GELD") Ownable(msg.sender) {} function initialize() public initializer {
__ERC20_init("Raid Geld", "GELD");
__Ownable_init(msg.sender);
}
// This effectively registers the user // This effectively registers the user
function register() external payable { function register() external payable {

View File

@ -2,11 +2,14 @@
pragma solidity ^0.8.13; pragma solidity ^0.8.13;
import {Test, console} from "forge-std/Test.sol"; import {Test, console} from "forge-std/Test.sol";
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
import {RaidGeld, Army, Player} from "../src/RaidGeld.sol"; import {RaidGeld, Army, Player} from "../src/RaidGeld.sol";
import "../src/RaidGeldUtils.sol"; import "../src/RaidGeldUtils.sol";
contract raid_geldTest is Test { contract raid_geldTest is Test {
RaidGeld public raid_geld; RaidGeld public raid_geld;
address implementationAddress;
address payable proxyAddress;
address public player1; address public player1;
address public player2; address public player2;
address public owner; address public owner;
@ -17,7 +20,16 @@ contract raid_geldTest is Test {
vm.deal(owner, 10 ether); vm.deal(owner, 10 ether);
vm.deal(player1, 10 ether); vm.deal(player1, 10 ether);
vm.prank(owner); vm.prank(owner);
raid_geld = new RaidGeld();
// Deploy the upgradeable contract
address _proxyAddress = Upgrades.deployTransparentProxy(
"RaidGeld.sol",
msg.sender,
abi.encodeCall(RaidGeld.initialize, ())
);
proxyAddress = payable(_proxyAddress);
raid_geld = RaidGeld(proxyAddress);
} }
function registerPlayer() private { function registerPlayer() private {