Skip to content

Commit 347d58e

Browse files
authored
fix upgradeable (#125)
closes #124
1 parent 40b22f6 commit 347d58e

14 files changed

Lines changed: 791 additions & 121 deletions

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
"hardhat": "^2.11.1"
3838
},
3939
"devDependencies": {
40-
"@nomiclabs/hardhat-ethers": "^2.1.1",
40+
"@nomiclabs/hardhat-ethers": "^2.2.3",
4141
"@nomiclabs/hardhat-etherscan": "^3.1.0",
4242
"@nomiclabs/hardhat-waffle": "^2.0.3",
43+
"@openzeppelin/hardhat-upgrades": "^1.28.0",
4344
"@typechain/ethers-v5": "^10.1.0",
4445
"@typechain/hardhat": "^6.1.2",
4546
"@types/chai": "^4.3.3",
@@ -74,7 +75,7 @@
7475
"async": ">=2.6.4",
7576
"cross-fetch": ">=3.1.5",
7677
"lodash": ">=4.17.21",
77-
"node-fetch": ">=2.6.7",
78+
"node-fetch": "^2.6.7",
7879
"underscore": ">=1.12.1",
7980
"yargs-parser": ">=5.0.1",
8081
"web3": ">=1.8.0",

src-upgradeable/README.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,13 @@ Constructors are replaced by internal initializer functions following the naming
1313

1414
These functions are internal, and you must define your own public initializer function that calls the parent class' initializer.
1515

16-
If using with another upgradeable library, please do use their respective initializer modifier on the `initialize()` function, in addition to the `initializerERC721A` modifier.
16+
If using with another upgradeable library, please do use their respective initializer modifier on the `initialize()` function, in addition to the `onlyInitializing` modifier.
1717

1818
## Deployment
1919

2020
If you are using hardhat, you can deploy it using
2121
[OpenZeppelin Upgrade Plugins](https://docs.openzeppelin.com/upgrades-plugins/1.x/).
2222

23-
```
24-
npm install --save-dev @openzeppelin/hardhat-upgrades
25-
```
26-
2723
**Deploy Script**
2824

2925
Located at [`scripts/deploy.ts`](./scripts/deploy.ts)
@@ -34,14 +30,14 @@ Located at [`scripts/upgrade.ts`](./scripts/upgrade.ts)
3430

3531
### Testnet / Mainnet
3632

37-
We will use the Goerli testnet as an example.
33+
We will use the Sepolia testnet as an example.
3834

3935
Add the following to your environment file `.env`:
4036

4137
```
42-
export ETHERSCAN_KEY="Your Etherscan API Key"
4338
export PRIVATE_KEY="Your Wallet Private Key"
44-
export RPC_URL_GOERLI="https://Infura Or Alchemy URL With API Key"
39+
export SEPOLIA_RPC_URL="https://Infura Or Alchemy URL With API Key"
40+
export ETHERSCAN_API_KEY="Your Etherscan API Key"
4541
```
4642

4743
Hardhat config located at [`hardhat.config.ts`](./hardhat.config.ts)
@@ -51,13 +47,13 @@ Hardhat config located at [`hardhat.config.ts`](./hardhat.config.ts)
5147
In this directory (`src-upgradeable`) run:
5248

5349
```
54-
npx hardhat run --config hardhat.config.ts --network goerli scripts/deploy.ts
50+
npx hardhat run --config hardhat.config.ts --network sepolia scripts/deploy.ts
5551
```
5652

5753
**Upgrade**
5854

5955
In this directory (`src-upgradeable`) run:
6056

6157
```
62-
npx hardhat run --config hardhat.config.ts --network goerli scripts/upgrade.ts
58+
npx hardhat run --config hardhat.config.ts --network sepolia scripts/upgrade.ts
6359
```

src-upgradeable/hardhat.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ module.exports = {
1111
viaIR: true,
1212
optimizer: {
1313
enabled: true,
14-
runs: 200,
14+
runs: 1000,
1515
},
1616
},
1717
},
1818
],
1919
},
2020
networks: {
21-
goerli: {
22-
url: process.env.RPC_URL_GOERLI,
21+
sepolia: {
22+
url: process.env.SEPOLIA_RPC_URL,
2323
accounts: [process.env.PRIVATE_KEY],
2424
},
2525
},
2626
etherscan: {
2727
// Your API key for Etherscan
2828
// Obtain one at https://etherscan.io/
29-
apiKey: process.env.ETHERSCAN_KEY,
29+
apiKey: process.env.ETHERSCAN_API_KEY,
3030
},
3131
paths: { sources: "./src" },
3232
};

src-upgradeable/scripts/deploy.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@ import fs from "fs";
22
import { ethers, upgrades } from "hardhat";
33

44
async function mainDeploy() {
5-
const ExampleToken = await ethers.getContractFactory("ExampleToken");
5+
const ERC721SeaDropUpgradeable = await ethers.getContractFactory("ERC721SeaDropUpgradeable");
6+
67
console.log("Deploying...");
7-
const exampleToken = await upgrades.deployProxy(
8-
ExampleToken,
8+
9+
const tokenName = "ERC721SeaDropUpgradeable"
10+
const tokenSymbol = "SD"
11+
const allowedSeaDrop = ["0x00005EA00Ac477B1030CE78506496e8C2dE24bf5"]
12+
13+
const token = await upgrades.deployProxy(
14+
ERC721SeaDropUpgradeable,
915
[
10-
"ExampleToken",
11-
"ExTkn",
12-
"0x4468A5B725E2C63056131121cD33b66848E1dd87",
13-
["0x00005EA00Ac477B1030CE78506496e8C2dE24bf5"],
16+
tokenName,
17+
tokenSymbol,
18+
allowedSeaDrop,
1419
],
1520
{ initializer: "initialize" }
1621
);
17-
await exampleToken.deployed();
22+
23+
await token.deployed();
24+
1825
const addresses = {
19-
proxy: exampleToken.address,
20-
admin: await upgrades.erc1967.getAdminAddress(exampleToken.address),
26+
proxy: token.address,
27+
admin: await upgrades.erc1967.getAdminAddress(token.address),
2128
implementation: await upgrades.erc1967.getImplementationAddress(
22-
exampleToken.address
29+
token.address
2330
),
2431
};
2532
console.log("Addresses: ", addresses);

src-upgradeable/scripts/upgrade.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ import fs from "fs";
22
import { ethers, upgrades } from "hardhat";
33

44
async function main() {
5-
const ExampleToken = await ethers.getContractFactory("ExampleToken");
5+
const ERC721SeaDropUpgradeable = await ethers.getContractFactory("ERC721SeaDropUpgradeable");
6+
67
console.log("Upgrading...");
8+
79
let addresses = JSON.parse(
810
fs.readFileSync("deployment-addresses.json").toString()
911
);
10-
const result = await upgrades.upgradeProxy(addresses.proxy, ExampleToken);
12+
13+
const result = await upgrades.upgradeProxy(addresses.proxy, ERC721SeaDropUpgradeable);
1114
await result.deployTransaction.wait();
15+
1216
console.log("Upgraded");
1317

1418
addresses = {

src-upgradeable/src/ERC721ContractMetadataUpgradeable.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
*/
5151
contract ERC721ContractMetadataUpgradeable is
5252
ERC721AConduitPreapprovedUpgradeable,
53+
ERC721TransferValidatorUpgradeable,
5354
TwoStepOwnableUpgradeable,
5455
ISeaDropTokenContractMetadataUpgradeable
5556
{
@@ -77,7 +78,6 @@ contract ERC721ContractMetadataUpgradeable is
7778
string memory symbol
7879
) internal onlyInitializing {
7980
__ERC721AConduitPreapprovedUpgradeable_init_unchained(name, symbol);
80-
__ConstructorInitializable_init_unchained();
8181
__TwoStepOwnable_init_unchained();
8282
}
8383

src-upgradeable/src/ERC721SeaDropUpgradeable.sol

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,29 @@ contract ERC721SeaDropUpgradeable is
7171
}
7272

7373
/**
74-
* @notice Deploy the token contract with its name, symbol,
74+
* @notice Initialize the token contract with its name, symbol,
7575
* and allowed SeaDrop addresses.
7676
*/
77+
function initialize(
78+
string memory name,
79+
string memory symbol,
80+
address[] memory allowedSeaDrop
81+
) external initializer initializerERC721A {
82+
__ERC721SeaDrop_init(
83+
name,
84+
symbol,
85+
allowedSeaDrop
86+
);
87+
}
88+
7789
function __ERC721SeaDrop_init(
7890
string memory name,
7991
string memory symbol,
8092
address[] memory allowedSeaDrop
8193
) internal onlyInitializing {
82-
__ERC721A_init_unchained(name, symbol);
83-
__ConstructorInitializable_init_unchained();
84-
__TwoStepOwnable_init_unchained();
85-
__ERC721ContractMetadata_init_unchained(name, symbol);
86-
__ReentrancyGuard_init_unchained();
94+
__ERC721ContractMetadata_init(name, symbol);
8795
__ERC721SeaDrop_init_unchained(name, symbol, allowedSeaDrop);
96+
__ReentrancyGuard_init_unchained();
8897
}
8998

9099
function __ERC721SeaDrop_init_unchained(
@@ -182,7 +191,7 @@ contract ERC721SeaDropUpgradeable is
182191
* @param tokenId The token id to burn.
183192
*/
184193
// solhint-disable-next-line comprehensive-interface
185-
function burn(uint256 tokenId) external {
194+
function burn(uint256 tokenId) external virtual {
186195
_burn(tokenId, true);
187196
}
188197

src-upgradeable/src/ExampleToken.sol

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,6 @@ contract ExampleToken is ERC721SeaDropUpgradeable {
3333
*/
3434
error BurnIncorrectSender();
3535

36-
/**
37-
* @notice Initialize the token contract with its name, symbol,
38-
* and allowed SeaDrop addresses.
39-
*/
40-
function initialize(
41-
string memory name,
42-
string memory symbol,
43-
address[] memory allowedSeaDrop
44-
) external initializer initializerERC721A {
45-
ERC721SeaDropUpgradeable.__ERC721SeaDrop_init(
46-
name,
47-
symbol,
48-
allowedSeaDrop
49-
);
50-
}
51-
5236
function setBurnAddress(address newBurnAddress) external onlyOwner {
5337
ExampleTokenStorage.layout().burnAddress = newBurnAddress;
5438
}
@@ -62,7 +46,7 @@ contract ExampleToken is ERC721SeaDropUpgradeable {
6246
*
6347
* @param tokenId The token id to burn.
6448
*/
65-
function burn(uint256 tokenId) external {
49+
function burn(uint256 tokenId) external override {
6650
if (msg.sender != ExampleTokenStorage.layout().burnAddress) {
6751
revert BurnIncorrectSender();
6852
}

src-upgradeable/src/extensions/ERC721SeaDropRandomOffsetUpgradeable.sol

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,9 @@ contract ERC721SeaDropRandomOffsetUpgradeable is ERC721SeaDropUpgradeable {
3838
string memory symbol,
3939
address[] memory allowedSeaDrop
4040
) internal onlyInitializing {
41-
__ERC721A_init_unchained(name, symbol);
42-
__ConstructorInitializable_init_unchained();
43-
__TwoStepOwnable_init_unchained();
44-
__ERC721ContractMetadata_init_unchained(name, symbol);
45-
__ReentrancyGuard_init_unchained();
4641
__ERC721SeaDrop_init_unchained(name, symbol, allowedSeaDrop);
47-
__ERC721SeaDrop_init_unchained(name, symbol, allowedSeaDrop);
48-
__ERC721SeaDropRandomOffset_init_unchained(
49-
name,
50-
symbol,
51-
allowedSeaDrop
52-
);
5342
}
5443

55-
function __ERC721SeaDropRandomOffset_init_unchained(
56-
string memory,
57-
string memory,
58-
address,
59-
address[] memory
60-
) internal onlyInitializing {}
61-
6244
/**
6345
* @notice Set the random offset, for a fair metadata reveal. Only callable
6446
* by the owner one time when the total number of minted tokens

src-upgradeable/src/lib/ERC721AConduitPreapprovedUpgradeable.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract contract ERC721AConduitPreapprovedUpgradeable is ERC721AUpgradeable {
1616
*/
1717
function __ERC721AConduitPreapprovedUpgradeable_init_unchained(
1818
string memory name, string memory symbol
19-
) internal onlyInitializing {
19+
) internal onlyInitializingERC721A {
2020
__ERC721A_init_unchained(name, symbol);
2121
}
2222

@@ -28,6 +28,6 @@ abstract contract ERC721AConduitPreapprovedUpgradeable is ERC721AUpgradeable {
2828
if (operator == _CONDUIT) {
2929
return true;
3030
}
31-
return ERC721A.isApprovedForAll(owner, operator);
31+
return ERC721AUpgradeable.isApprovedForAll(owner, operator);
3232
}
3333
}

0 commit comments

Comments
 (0)