1
0
forked from mico/idle_moloch

make contracts upgradeable

This commit is contained in:
san 2024-10-27 22:25:19 +05:30
parent a45d74ebb2
commit 06cc9fa717
5 changed files with 33 additions and 8 deletions

3
.gitmodules vendored
View File

@ -4,3 +4,6 @@
[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-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

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,28 @@ 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, (msg.sender))
);
// Get the implementation address
address implementationAddress = Upgrades.getImplementationAddress(
_proxyAddress
);
vm.stopBroadcast(); vm.stopBroadcast();
return (implementationAddress, _proxyAddress);
} }
} }

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();
}
// This effectively registers the user // This effectively registers the user
function register() external payable { function register() external payable {