Skip to content

Commit 49d8dbd

Browse files
committed
(feat) (openai/gpt-5.5, reviewed T, tested T) make RIK deploy through upgradeable proxy
1 parent 7f133f3 commit 49d8dbd

12 files changed

Lines changed: 107 additions & 24 deletions

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "contracts/lib/forge-std"]
55
path = contracts/lib/forge-std
66
url = https://github.com/foundry-rs/forge-std
7+
[submodule "contracts/lib/openzeppelin-contracts-upgradeable"]
8+
path = contracts/lib/openzeppelin-contracts-upgradeable
9+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
10+
[submodule "contracts/lib/openzeppelin-foundry-upgrades"]
11+
path = contracts/lib/openzeppelin-foundry-upgrades
12+
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades

cli/src/abi/RIK.json

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
[
22
{
33
"type": "constructor",
4-
"inputs": [
5-
{
6-
"name": "initialOwner",
7-
"type": "address",
8-
"internalType": "address"
9-
}
10-
],
4+
"inputs": [],
115
"stateMutability": "nonpayable"
126
},
137
{
@@ -102,6 +96,19 @@
10296
],
10397
"stateMutability": "view"
10498
},
99+
{
100+
"type": "function",
101+
"name": "initialize",
102+
"inputs": [
103+
{
104+
"name": "initialOwner",
105+
"type": "address",
106+
"internalType": "address"
107+
}
108+
],
109+
"outputs": [],
110+
"stateMutability": "nonpayable"
111+
},
105112
{
106113
"type": "function",
107114
"name": "isApprovedForAll",
@@ -495,6 +502,19 @@
495502
],
496503
"anonymous": false
497504
},
505+
{
506+
"type": "event",
507+
"name": "Initialized",
508+
"inputs": [
509+
{
510+
"name": "version",
511+
"type": "uint64",
512+
"indexed": false,
513+
"internalType": "uint64"
514+
}
515+
],
516+
"anonymous": false
517+
},
498518
{
499519
"type": "event",
500520
"name": "KeyAdded",
@@ -737,6 +757,16 @@
737757
}
738758
]
739759
},
760+
{
761+
"type": "error",
762+
"name": "InvalidInitialization",
763+
"inputs": []
764+
},
765+
{
766+
"type": "error",
767+
"name": "NotInitializing",
768+
"inputs": []
769+
},
740770
{
741771
"type": "error",
742772
"name": "OwnableInvalidOwner",

contracts/deploy-sepolia.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ARGS=(
1313
script/Deploy.s.sol
1414
--rpc-url "$SEPOLIA_RPC_URL"
1515
--broadcast
16+
--force
1617
)
1718

1819
if [[ "$VERIFY" == "true" ]]; then

contracts/foundry.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,17 @@
1010
"name": "v5.6.1",
1111
"rev": "5fd1781b1454fd1ef8e722282f86f9293cacf256"
1212
}
13+
},
14+
"lib/openzeppelin-contracts-upgradeable": {
15+
"tag": {
16+
"name": "v5.6.1",
17+
"rev": "7bf4727aacdbfaa0f36cbd664654d0c9e1dc52bf"
18+
}
19+
},
20+
"lib/openzeppelin-foundry-upgrades": {
21+
"tag": {
22+
"name": "v0.4.1",
23+
"rev": "258e12e727bfe7f0ec30c51995d01ec88b82efc1"
24+
}
1325
}
1426
}

contracts/foundry.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ src = "src"
33
out = "out"
44
libs = ["lib"]
55
ffi = true
6+
ast = true
7+
build_info = true
8+
extra_output = ["storageLayout"]
69

710
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

contracts/remappings.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
@openzeppelin/=lib/openzeppelin-contracts/
1+
@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
2+
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
3+
openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/
24
forge-std/=lib/forge-std/src/

contracts/script/Deploy.s.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pragma solidity ^0.8.24;
55

66
import {Script} from "forge-std/Script.sol";
7+
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
78
import {RIK} from "../src/RIK.sol";
89

910
contract Deploy is Script {
@@ -12,7 +13,8 @@ contract Deploy is Script {
1213
address owner = vm.addr(deployerPrivateKey);
1314

1415
vm.startBroadcast(deployerPrivateKey);
15-
rik = new RIK(owner);
16+
address proxy = Upgrades.deployTransparentProxy("RIK.sol", owner, abi.encodeCall(RIK.initialize, (owner)));
17+
rik = RIK(proxy);
1618
vm.stopBroadcast();
1719
}
1820
}

contracts/src/RIK.sol

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
// SPDX-License-Identifier: Apache-2.0
33
pragma solidity ^0.8.24;
44

5-
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
6-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
5+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
6+
import {ERC721Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol";
7+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
78
import {RSA} from "@openzeppelin/contracts/utils/cryptography/RSA.sol";
89
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";
910
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
1011
import {JsonClaim} from "./JsonClaim.sol";
1112

12-
contract RIK is ERC721, Ownable {
13+
contract RIK is Initializable, ERC721Upgradeable, OwnableUpgradeable {
1314
using RSA for bytes32;
1415

1516
struct RSAKey {
@@ -45,7 +46,15 @@ contract RIK is ERC721, Ownable {
4546
// NOTE: make it so contract owner can update this
4647
string public constant EXPECTED_ISS = "https://token.actions.githubusercontent.com";
4748

48-
constructor(address initialOwner) ERC721("Repository Identity Key", "RIK") Ownable(initialOwner) {}
49+
/// @custom:oz-upgrades-unsafe-allow constructor
50+
constructor() {
51+
_disableInitializers();
52+
}
53+
54+
function initialize(address initialOwner) public initializer {
55+
__ERC721_init("Repository Identity Key", "RIK");
56+
__Ownable_init(initialOwner);
57+
}
4958

5059
function register(
5160
bytes32 kid,

0 commit comments

Comments
 (0)