-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: deployUpgradable() utility and proxy tests
- Loading branch information
Showing
12 changed files
with
111 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,70 @@ | ||
import { DeployResult, DeployOptions, DeploymentsExtension } from "hardhat-deploy/types"; | ||
import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
import { | ||
DeployResult, | ||
DeployOptions, | ||
DeploymentsExtension, | ||
DeployOptionsBase, | ||
ProxyOptions, | ||
} from "hardhat-deploy/types"; | ||
|
||
export const deployUpgradable = async ( | ||
hre: HardhatRuntimeEnvironment, | ||
contract: string, | ||
options: DeployOptions | ||
): Promise<DeployResult> => { | ||
const { deploy } = hre.deployments; | ||
const { args, ...otherOptions } = options; | ||
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629 | ||
return deploy(contract, { | ||
proxy: { | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, // Not relevant for UUPSProxy | ||
checkABIConflict: false, // Not relevant for UUPSProxy | ||
upgradeFunction: { | ||
methodName: "upgradeToAndCall", | ||
upgradeArgs: ["{implementation}", "{data}"], | ||
}, | ||
execute: { | ||
init: { | ||
methodName: "initialize", | ||
args: args ?? [], | ||
}, | ||
onUpgrade: { | ||
methodName: "initialize", | ||
args: args ?? [], | ||
}, | ||
}, | ||
}, | ||
...otherOptions, | ||
}); | ||
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629 | ||
const PROXY_OPTIONS: ProxyOptions = { | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, // Not relevant for UUPSProxy | ||
checkABIConflict: false, // Not relevant for UUPSProxy | ||
upgradeFunction: { | ||
methodName: "upgradeToAndCall", | ||
upgradeArgs: ["{implementation}", "{data}"], | ||
}, | ||
}; | ||
|
||
export const deployUpgradableEXPERIMENTAL = async ( | ||
deployments: DeploymentsExtension, | ||
contract: string, | ||
options: DeployOptions | ||
): Promise<DeployResult> => { | ||
const { deploy } = deployments; | ||
const { args, ...otherOptions } = options; | ||
// Rationale: https://github.com/kleros/kleros-v2/pull/1214#issue-1879116629 | ||
return deploy(contract, { | ||
proxy: { | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, // Not relevant for UUPSProxy | ||
checkABIConflict: false, // Not relevant for UUPSProxy | ||
upgradeFunction: { | ||
methodName: "upgradeToAndCall", | ||
upgradeArgs: ["{implementation}", "{data}"], | ||
}, | ||
execute: { | ||
init: { | ||
methodName: "initialize", | ||
args: args ?? [], | ||
}, | ||
onUpgrade: { | ||
methodName: "initialize", | ||
args: args ?? [], | ||
}, | ||
}, | ||
}, | ||
...otherOptions, | ||
}); | ||
}; | ||
type DeployUpgradableOptions = { | ||
newImplementation?: string; | ||
initializer?: string; | ||
} & DeployOptionsBase; | ||
|
||
export const deployUpgradableEXPERIMENTAL2 = async ( | ||
export const deployUpgradable = async ( | ||
deployments: DeploymentsExtension, | ||
proxy: string, | ||
newImplementation: string, | ||
initializer = "initialize", | ||
options: DeployOptions | ||
options: DeployUpgradableOptions | ||
): Promise<DeployResult> => { | ||
const { deploy } = deployments; | ||
const { args, ...otherOptions } = options; | ||
return await deploy(proxy, { | ||
contract: newImplementation, | ||
const { newImplementation, initializer, args: initializerArgs, ...otherOptions } = options; | ||
|
||
const methodName = initializer ?? "initialize"; | ||
const args = initializerArgs ?? []; | ||
|
||
const contract: Partial<DeployOptions> = newImplementation | ||
? { | ||
contract: newImplementation, | ||
} | ||
: {}; | ||
|
||
const implementationName: Partial<ProxyOptions> = newImplementation | ||
? { | ||
implementationName: newImplementation + "_Implementation", | ||
} | ||
: {}; | ||
|
||
let fullOptions: DeployOptions = { | ||
...otherOptions, | ||
...contract, | ||
proxy: { | ||
implementationName: newImplementation + "_Implementation", | ||
proxyContract: "UUPSProxy", | ||
proxyArgs: ["{implementation}", "{data}"], | ||
checkProxyAdmin: false, // Not relevant for UUPSProxy | ||
checkABIConflict: false, // Not relevant for UUPSProxy | ||
upgradeFunction: { | ||
methodName: "upgradeToAndCall", | ||
upgradeArgs: ["{implementation}", "{data}"], | ||
}, | ||
...PROXY_OPTIONS, | ||
...implementationName, | ||
execute: { | ||
init: { | ||
methodName: initializer, | ||
args: args ?? [], | ||
methodName, | ||
args, | ||
}, | ||
onUpgrade: { | ||
methodName: initializer, | ||
args: args ?? [], | ||
methodName, | ||
args, | ||
}, | ||
}, | ||
}, | ||
...otherOptions, | ||
}); | ||
}; | ||
|
||
// console.debug("fullOptions: ", JSON.stringify(fullOptions)); | ||
return await deploy(proxy, fullOptions); | ||
}; |
Oops, something went wrong.