-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Upgrade] Add owner getter and setter to Asset and Catalyst #1345
base: feat/hardhat-updates-verification
Are you sure you want to change the base?
Changes from 4 commits
ab74f87
47abb75
302526c
41b929f
f9475b0
7356236
5b591fa
6692dd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,5 +384,21 @@ contract Asset is | |
return "ASSET"; | ||
} | ||
|
||
uint256[49] private __gap; | ||
address private _owner; | ||
|
||
/// @notice Returns the owner of the contract | ||
/// @return address of the owner | ||
function owner() external view returns (address) { | ||
return _owner; | ||
} | ||
|
||
/// @notice Sets the owner of the contract | ||
/// @param newOwner address of the new owner | ||
function transferOwnership(address newOwner) external { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the main reason is to be able to provide custom revert message. |
||
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Asset: Unauthorized"); | ||
_owner = newOwner; | ||
emit OwnershipTransferred(_owner, newOwner); | ||
} | ||
|
||
uint256[48] private __gap; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -324,5 +324,21 @@ contract Catalyst is | |
return "CATALYST"; | ||
} | ||
|
||
uint256[49] private __gap; | ||
address private _owner; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to line 52? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
/// @notice Returns the owner of the contract | ||
/// @return address of the owner | ||
function owner() external view returns (address) { | ||
return _owner; | ||
} | ||
|
||
/// @notice Sets the owner of the contract | ||
/// @param newOwner address of the new owner | ||
function transferOwnership(address newOwner) external { | ||
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Asset: Unauthorized"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
_owner = newOwner; | ||
emit OwnershipTransferred(_owner, newOwner); | ||
} | ||
|
||
uint256[48] private __gap; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ generated-markups | |
|
||
# editors | ||
.idea | ||
deployments/localhost |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
|
||
const func: DeployFunction = async function ( | ||
hre: HardhatRuntimeEnvironment | ||
): Promise<void> { | ||
const {deployments, getNamedAccounts, ethers} = hre; | ||
const {execute, read, catchUnknownSigner, deploy} = deployments; | ||
const {deployer, upgradeAdmin, catalystAdmin} = await getNamedAccounts(); | ||
|
||
await deploy('Catalyst', { | ||
from: deployer, | ||
log: true, | ||
contract: '@sandbox-smart-contracts/asset/contracts/Catalyst.sol:Catalyst', | ||
proxy: { | ||
owner: upgradeAdmin, | ||
proxyContract: 'OpenZeppelinTransparentProxy', | ||
upgradeIndex: 1, | ||
}, | ||
}); | ||
|
||
if ((await read('Catalyst', 'owner')) === ethers.constants.AddressZero) { | ||
await catchUnknownSigner( | ||
execute( | ||
'Catalyst', | ||
{from: catalystAdmin, log: true}, | ||
'transferOwnership', | ||
catalystAdmin | ||
) | ||
); | ||
} | ||
}; | ||
Comment on lines
+22
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is better to split this in a separated step, because if something goes wrong it is easier to re-run it separately |
||
export default func; | ||
func.tags = ['Catalyst_upgrade']; | ||
func.dependencies = ['Catalyst_deploy', 'Catalyst_setup']; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const {deployments, getNamedAccounts, ethers} = hre; | ||
const {read, catchUnknownSigner, execute, deploy} = deployments; | ||
const {deployer, upgradeAdmin, assetAdmin} = await getNamedAccounts(); | ||
|
||
await deploy('Asset', { | ||
from: deployer, | ||
contract: '@sandbox-smart-contracts/asset/contracts/Asset.sol:Asset', | ||
proxy: { | ||
owner: upgradeAdmin, | ||
proxyContract: 'OpenZeppelinTransparentProxy', | ||
upgradeIndex: 1, | ||
}, | ||
log: true, | ||
}); | ||
|
||
if ((await read('Asset', 'owner')) === ethers.constants.AddressZero) { | ||
await catchUnknownSigner( | ||
execute( | ||
'Asset', | ||
{from: assetAdmin, log: true}, | ||
'transferOwnership', | ||
assetAdmin | ||
) | ||
); | ||
} | ||
}; | ||
Comment on lines
+20
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is better to split this in a separated step, because if something goes wrong it is easier to re-run it separately There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the deployment of the upgrade fails this won't be called, and its a function that we likely call only once during the upgrade process. I feel like its integral to this upgrade. |
||
export default func; | ||
|
||
func.tags = ['Asset_upgrade']; | ||
func.dependencies = ['Asset_deploy', 'Asset_setup']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to line 59?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have declared it there so its all close together, but yeah will move it up