Skip to content

Commit

Permalink
refactor: use OZ upgrades plugin for proxy deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jparklev committed May 8, 2024
1 parent 9a6015c commit a5d145e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions contracts/PointTokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ contract PointTokenVault is UUPSUpgradeable, AccessControlUpgradeable, Multicall
error PTokenNotDeployed();
error AmountTooSmall();

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
Expand Down
20 changes: 9 additions & 11 deletions contracts/script/PointTokenVault.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {ERC20} from "solmate/tokens/ERC20.sol";
import {CREATE3} from "solmate/utils/CREATE3.sol";
import {LibString} from "solady/utils/LibString.sol";

import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";

import {console} from "forge-std/console.sol";

contract PointTokenVaultScripts is BatchScript {
Expand Down Expand Up @@ -55,15 +57,10 @@ contract PointTokenVaultScripts is BatchScript {
}

function run(string memory version) public returns (PointTokenVault) {
PointTokenVault pointTokenVaultImplementation = new PointTokenVault{salt: keccak256(abi.encode(version))}();

PointTokenVault pointTokenVault = PointTokenVault(
payable(
address(
new ERC1967Proxy{salt: keccak256(abi.encode(version))}(
address(pointTokenVaultImplementation),
abi.encodeCall(PointTokenVault.initialize, (msg.sender)) // msg.sender is admin
)
Upgrades.deployUUPSProxy(
"PointTokenVault.sol", abi.encodeCall(PointTokenVault.initialize, (msg.sender))
)
)
);
Expand All @@ -89,11 +86,12 @@ contract PointTokenVaultScripts is BatchScript {
function upgrade() public {
vm.startBroadcast();

PointTokenVault currentPointTokenVault = PointTokenVault(payable(0xbff7Fb79efC49504afc97e74F83EE618768e63E9));

PointTokenVault PointTokenVaultImplementation = new PointTokenVault();
// address currentPointTokenVaultAddress = 0xbff7Fb79efC49504afc97e74F83EE618768e63E9;

currentPointTokenVault.upgradeToAndCall(address(PointTokenVaultImplementation), bytes(""));
// Once there is a v2, upgrade referencing v1 for automatic OZ safety checks
// Options memory opts;
// opts.referenceContract = "PointTokenVaultV1.sol";
// Upgrades.upgradeProxy(currentPointTokenVaultAddress, "PointTokenVaultV2.sol", "");

vm.stopBroadcast();
}
Expand Down
7 changes: 5 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
src = "contracts"
script = 'contracts/script'
test = 'contracts/test'
out = "contracts/out"
out = "out"
libs = ["lib"]
ffi = true
evm_version = "cancun"
ffi = true
ast = true
build_info = true
extra_output = ["storageLayout"]

[rpc_endpoints]
sepolia = "${SEPOLIA_RPC_URL}"
Expand Down

0 comments on commit a5d145e

Please sign in to comment.