Skip to content

Commit

Permalink
Oz upgrade to v5 (#13874)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed May 21, 2024
1 parent 35fa808 commit b71c9cf
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 27 deletions.
3 changes: 1 addition & 2 deletions smart-contracts/contracts/CardPurchaser.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ contract CardPurchaser is Ownable, EIP712 {
address _owner,
address _unlockAddress,
address _usdc
) EIP712("Card Purchaser", "1") Ownable() {
) EIP712("Card Purchaser", "1") Ownable(_owner) {
name = "Card Purchaser";
version = "1";
unlockAddress = _unlockAddress;
usdc = _usdc;
transferOwnership(_owner);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions smart-contracts/contracts/hooks/CaptchaHook.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV12.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract CaptchaHook is Ownable {
mapping(address => bool) public signers;

constructor() {}
constructor() Ownable(msg.sender) {}

function addSigner(address signer) public onlyOwner {
signers[signer] = true;
Expand Down Expand Up @@ -44,7 +45,7 @@ contract CaptchaHook is Ownable {
) public view returns (bool isSigner) {
bytes memory encoded = abi.encodePacked(message);
bytes32 messageHash = keccak256(encoded);
bytes32 hash = ECDSA.toEthSignedMessageHash(messageHash);
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(messageHash);
address recoveredAddress = ECDSA.recover(hash, signature);
return signers[recoveredAddress];
}
Expand Down
3 changes: 2 additions & 1 deletion smart-contracts/contracts/hooks/DiscountCodeHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV12.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

error TOO_BIG();
error NOT_AUTHORIZED();
Expand Down Expand Up @@ -86,7 +87,7 @@ contract DiscountHook {
bytes calldata signature
) public pure returns (address recoveredAddress) {
bytes32 hash = keccak256(abi.encodePacked(message));
bytes32 signedMessageHash = ECDSA.toEthSignedMessageHash(hash);
bytes32 signedMessageHash = MessageHashUtils.toEthSignedMessageHash(hash);
return ECDSA.recover(signedMessageHash, signature);
}

Expand Down
5 changes: 3 additions & 2 deletions smart-contracts/contracts/hooks/GitcoinHook.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV13.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract GitcoinHook is Ownable {
mapping(address => bool) public signers;

constructor() {}
constructor() Ownable(msg.sender) {}

function addSigner(address signer) public onlyOwner {
signers[signer] = true;
Expand Down Expand Up @@ -43,7 +44,7 @@ contract GitcoinHook is Ownable {
) private view returns (bool isSigner) {
bytes memory encoded = abi.encodePacked(message);
bytes32 messageHash = keccak256(encoded);
bytes32 hash = ECDSA.toEthSignedMessageHash(messageHash);
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(messageHash);
address recoveredAddress = ECDSA.recover(hash, signature);
return signers[recoveredAddress];
}
Expand Down
5 changes: 3 additions & 2 deletions smart-contracts/contracts/hooks/GuildHook.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV13.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract GuildHook is Ownable {
mapping(address => bool) public signers;

constructor() {}
constructor() Ownable(msg.sender) {}

function addSigner(address signer) public onlyOwner {
signers[signer] = true;
Expand Down Expand Up @@ -44,7 +45,7 @@ contract GuildHook is Ownable {
) private view returns (bool isSigner) {
bytes memory encoded = abi.encodePacked(message);
bytes32 messageHash = keccak256(encoded);
bytes32 hash = ECDSA.toEthSignedMessageHash(messageHash);
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(messageHash);
address recoveredAddress = ECDSA.recover(hash, signature);
return signers[recoveredAddress];
}
Expand Down
3 changes: 2 additions & 1 deletion smart-contracts/contracts/hooks/PasswordRequiredHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity ^0.8.21;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@unlock-protocol/contracts/dist/PublicLock/IPublicLockV12.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

error WRONG_PASSWORD();
error NOT_AUTHORIZED();
Expand Down Expand Up @@ -52,7 +53,7 @@ contract PasswordRequiredHook {
bytes calldata signature
) public pure returns (address recoveredAddress) {
bytes32 hash = keccak256(abi.encodePacked(message));
bytes32 signedMessageHash = ECDSA.toEthSignedMessageHash(hash);
bytes32 signedMessageHash = MessageHashUtils.toEthSignedMessageHash(hash);
return ECDSA.recover(signedMessageHash, signature);
}

Expand Down
1 change: 0 additions & 1 deletion smart-contracts/contracts/test-artifacts/TestERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract TestERC1155 is ERC1155 {
constructor() ERC1155("tokenURIExample") {}
Expand Down
8 changes: 3 additions & 5 deletions smart-contracts/contracts/test-artifacts/TestERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
pragma solidity ^0.8.21;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract TestERC721 is ERC721 {
using Counters for Counters.Counter;
Counters.Counter private _tokenIds;
uint private _lastTokenId = 1;

constructor() ERC721("BasicToken", "BASIC") {}

function mint(address holder) public returns (uint256) {
_tokenIds.increment();
_lastTokenId++;

uint256 newItemId = _tokenIds.current();
uint256 newItemId = _lastTokenId;
_mint(holder, newItemId);

return newItemId;
Expand Down
4 changes: 3 additions & 1 deletion smart-contracts/contracts/test-artifacts/TestProxyAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

contract TestProxyAdmin is ProxyAdmin {}
contract TestProxyAdmin is ProxyAdmin {
constructor() ProxyAdmin(msg.sender) {}
}
4 changes: 3 additions & 1 deletion smart-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"@nomicfoundation/hardhat-ethers": "3.0.5",
"@nomicfoundation/hardhat-network-helpers": "1.0.10",
"@nomicfoundation/hardhat-verify": "2.0.6",
"@openzeppelin/contracts": "4.9.6",
"@openzeppelin/contracts": "5.0.2",
"@openzeppelin/contracts-upgradeable": "4.9.6",
"@openzeppelin/contracts-upgradeable5": "npm:@openzeppelin/contracts-upgradeable@5.0.2",
"@openzeppelin/contracts5": "npm:@openzeppelin/contracts@5.0.2",
"@openzeppelin/hardhat-upgrades": "3.1.0",
"@openzeppelin/upgrades-core": "1.33.1",
"@safe-global/safe-core-sdk": "3.3.5",
Expand Down
2 changes: 1 addition & 1 deletion smart-contracts/test/Lock/hooks/CaptchaHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('CaptchaHook', function () {
[await aThird.getAddress()],
['0x']
),
'ECDSA: invalid signature length'
'ECDSAInvalidSignatureLength'
)
})
})
5 changes: 3 additions & 2 deletions smart-contracts/test/Lock/hooks/GitcoinHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('GitcoinHook', function () {
[await aThird.getAddress()],
['0x']
),
'ECDSA: invalid signature length'
'ECDSAInvalidSignatureLength'
)
})

Expand All @@ -96,6 +96,7 @@ describe('GitcoinHook', function () {
await hook.addSigner(await signer.getAddress())
expect(await hook.signers(await signer.getAddress())).to.equal(true)
expect(await hook.owner()).to.equal(await user.getAddress())
const previousOwner = await hook.owner()

// Transfer ownership
await hook.transferOwnership(await anotherUser.getAddress())
Expand All @@ -105,7 +106,7 @@ describe('GitcoinHook', function () {
const anotherSigner = ethers.Wallet.createRandom()
await reverts(
hook.addSigner(await anotherSigner.getAddress()),
'Ownable: caller is not the owner'
`OwnableUnauthorizedAccount("${previousOwner}")`
)
expect(await hook.signers(await anotherSigner.getAddress())).to.equal(false)

Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/test/Lock/hooks/GuildHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('GuildHook', function () {
[await aThird.getAddress()],
['0x']
),
'ECDSA: invalid signature length'
'ECDSAInvalidSignatureLength'
)
})

Expand All @@ -105,7 +105,7 @@ describe('GuildHook', function () {
const anotherSigner = ethers.Wallet.createRandom()
await reverts(
hook.addSigner(await anotherSigner.getAddress()),
'Ownable: caller is not the owner'
'OwnableUnauthorizedAccount'
)
expect(await hook.signers(await anotherSigner.getAddress())).to.equal(false)

Expand Down
4 changes: 2 additions & 2 deletions smart-contracts/test/Lock/renewMembershipFor.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('Lock / Recurring memberships', () => {
// now reverts
await reverts(
lock.renewMembershipFor(tokenId, ADDRESS_ZERO),
'ERC20: insufficient allowance'
'ERC20InsufficientAllowance'
)
})

Expand Down Expand Up @@ -250,7 +250,7 @@ describe('Lock / Recurring memberships', () => {
// now funds are not enough
await reverts(
lock.renewMembershipFor(tokenId, ADDRESS_ZERO),
'ERC20: transfer amount exceeds balance'
'ERC20InsufficientBalance'
)
})
})
Expand Down
22 changes: 20 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12684,6 +12684,15 @@ __metadata:
languageName: node
linkType: hard

"@openzeppelin/contracts-upgradeable5@npm:@openzeppelin/contracts-upgradeable@5.0.2":
version: 5.0.2
resolution: "@openzeppelin/contracts-upgradeable@npm:5.0.2"
peerDependencies:
"@openzeppelin/contracts": 5.0.2
checksum: 10/71847c6bbd7a859a2f02f496215b9664e41375589010e66da32f080d9af9215accf558da63134926e0eb3eb87ee7ab952462bc877ec5c5e1ac077b44cac9c363
languageName: node
linkType: hard

"@openzeppelin/contracts-upgradeable@npm:4.5.2":
version: 4.5.2
resolution: "@openzeppelin/contracts-upgradeable@npm:4.5.2"
Expand All @@ -12705,6 +12714,13 @@ __metadata:
languageName: node
linkType: hard

"@openzeppelin/contracts5@npm:@openzeppelin/contracts@5.0.2, @openzeppelin/contracts@npm:5.0.2":
version: 5.0.2
resolution: "@openzeppelin/contracts@npm:5.0.2"
checksum: 10/938ebffbdade7dc59ea3df5b562c0e457bbefde9d82be8fa2acfd11da887df11653ac07922f41746b80cdbc106430e1e6978ce244fe99b00a7d9dc1418fc7670
languageName: node
linkType: hard

"@openzeppelin/contracts@npm:3.4.1-solc-0.7-2":
version: 3.4.1-solc-0.7-2
resolution: "@openzeppelin/contracts@npm:3.4.1-solc-0.7-2"
Expand Down Expand Up @@ -12740,7 +12756,7 @@ __metadata:
languageName: node
linkType: hard

"@openzeppelin/contracts@npm:4.9.6, @openzeppelin/contracts@npm:^4.9.2":
"@openzeppelin/contracts@npm:^4.9.2":
version: 4.9.6
resolution: "@openzeppelin/contracts@npm:4.9.6"
checksum: 10/71f45ad42e68c0559be4ba502115462a01c76fc805c08d3005c10b5550a093f1a2b00b2d7e9d6d1f331e147c50fd4ad832f71c4470ec5b34f5a2d0751cd19a47
Expand Down Expand Up @@ -19838,8 +19854,10 @@ __metadata:
"@nomicfoundation/hardhat-ethers": "npm:3.0.5"
"@nomicfoundation/hardhat-network-helpers": "npm:1.0.10"
"@nomicfoundation/hardhat-verify": "npm:2.0.6"
"@openzeppelin/contracts": "npm:4.9.6"
"@openzeppelin/contracts": "npm:5.0.2"
"@openzeppelin/contracts-upgradeable": "npm:4.9.6"
"@openzeppelin/contracts-upgradeable5": "npm:@openzeppelin/contracts-upgradeable@5.0.2"
"@openzeppelin/contracts5": "npm:@openzeppelin/contracts@5.0.2"
"@openzeppelin/hardhat-upgrades": "npm:3.1.0"
"@openzeppelin/upgrades-core": "npm:1.33.1"
"@safe-global/safe-core-sdk": "npm:3.3.5"
Expand Down

0 comments on commit b71c9cf

Please sign in to comment.