Skip to content

Commit

Permalink
Merge pull request #202 from OpenZeppelin/plat-3609-defender-deploy-s…
Browse files Browse the repository at this point in the history
…upport-constructor-input-as-an-abi-encoded

Defender deploy support constructor input as an abi encoded
  • Loading branch information
tirumerla authored Jan 10, 2024
2 parents 83af4d6 + b4dffd1 commit ab47885
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 104 deletions.
433 changes: 359 additions & 74 deletions examples/deploy-contract/artifacts/Box.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions examples/deploy-contract/contracts/Box.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ contract Box {
// Emitted when the stored value changes
event ValueChanged(uint256 value);

constructor(uint value) {
_value = value;
}

// Stores a new value in the contract
function store(uint256 value) public {
_value = value;
Expand Down
8 changes: 5 additions & 3 deletions examples/deploy-contract/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require('dotenv').config();

const { Defender } = require('@openzeppelin/defender-sdk');
const { AbiCoder } = require('ethers');

const artifactFile = require('./artifacts/Box.json');

Expand All @@ -9,24 +10,25 @@ async function main() {
const client = new Defender(creds);

// await client.deploy.createBlockExplorerApiKey({
// network: 'goerli',
// network: 'sepolia',
// key: process.env.BLOCKEXPLORER_API_KEY,
// });

const keys = await client.deploy.listBlockExplorerApiKeys();
console.log(keys);

// Get approval process for deployment on sepolia
const config = await client.deploy.getDeployApprovalProcess('goerli');
const config = await client.deploy.getDeployApprovalProcess('sepolia');
console.log(config);

const deployment = await client.deploy.deployContract({
contractName: 'Box',
contractPath: 'contracts/Box.sol',
network: 'goerli',
network: 'sepolia',
artifactPayload: JSON.stringify(artifactFile),
licenseType: 'MIT',
verifySourceCode: true,
constructorBytecode: AbiCoder.defaultAbiCoder().encode(['uint'], ['5']), // or constructorInputs: [5],
});

const deploymentStatus = await client.deploy.getDeployedContract(deployment.deploymentId);
Expand Down
3 changes: 2 additions & 1 deletion examples/deploy-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@openzeppelin/defender-sdk": "1.8.0",
"dotenv": "^16.3.1"
"dotenv": "^16.3.1",
"ethers": "^6.9.0"
}
}
41 changes: 18 additions & 23 deletions packages/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ Additionally you must provide your compilation artifact from hardhat. The compil

There are a number of optional fields depending on what you are deploying, these include:

- `constructorInputs` - The inputs to your contract constructor,
- `constructorInputs` - The inputs to your contract constructor.
- `constructorBytecode` - Alternative to `constructorInputs`.
- `value` - ETH to be sent with the deployment.
- `salt` - deployments are done using the CREATE2 opcode, you can provide a salt or we can generate one for you if none is supplied.
- `licenseType` - This will be displayed on Etherscan e.g MIT.
Expand All @@ -37,14 +38,13 @@ Below is an example of a contract deployment request which responds with a `Depl

```js
await client.deploy.deployContract({
contract: {
contractName: 'Greeter',
contractPath: 'contracts/Greeter.sol',
network: 'sepolia',
artifactPayload: JSON.stringify(artifactFile),
licenseType: 'MIT',
constructorInputs: ['Hello World!'],
},
contractName: 'Box',
contractPath: 'contracts/Box.sol',
network: 'sepolia',
artifactPayload: JSON.stringify(artifactFile),
licenseType: 'MIT',
verifySourceCode: true,
constructorBytecode: AbiCoder.defaultAbiCoder().encode(['uint'], ['5']), // or constructorInputs: [5],
});
```

Expand All @@ -58,13 +58,13 @@ As well as fetching a deployment via it's ID

```js
const deploymentId = '8181d9e0-88ce-4db0-802a-2b56e2e6a7b1';
await client.deploy.getDeployedContract({ deploymentId });
await client.deploy.getDeployedContract(deploymentId);
```

You can also retrieve the deploy approval process for a given network, which will return a `ApprovalProcessResponse` object

```js
await client.deploy.getDeployApprovalProcess({ network: 'sepolia' });
await client.deploy.getDeployApprovalProcess('sepolia');
```

### Upgrade
Expand All @@ -86,13 +86,11 @@ Below is an example of a contract upgrade request which responds with a `Upgrade

```js
await client.deploy.upgradeContract({
upgradeParams: {
proxyAddress: '0xABC1234...',
proxyAdminAddress: '0xDEF1234...',
newImplementationABI: JSON.stringify(boxABIFile),
newImplementationAddress: '0xABCDEF1....',
network: 'sepolia',
},
proxyAddress: '0xABC1234...',
proxyAdminAddress: '0xDEF1234...',
newImplementationABI: JSON.stringify(boxABIFile),
newImplementationAddress: '0xABCDEF1....',
network: 'sepolia',
});
```

Expand Down Expand Up @@ -123,15 +121,12 @@ As well as fetching a your Api Key via it's ID

```js
const apiKeyId = '8181d9e0-88ce-4db0-802a-2b56e2e6a7b1';
await client.deploy.getBlockExplorerApiKey({ apiKeyId });
await client.deploy.getBlockExplorerApiKey(apiKeyId);
```

And updating the Api Key for a given network

```js
const apiKeyId = '8181d9e0-88ce-4db0-802a-2b56e2e6a7b1';
await client.deploy.updateBlockExplorerApiKey({
apiKeyId,
{ key: 'LDNWOWFNEJ2WEL4WLKNWEF8F2MNWKEF' },
});
await client.deploy.updateBlockExplorerApiKey(apiKeyId, { key: 'LDNWOWFNEJ2WEL4WLKNWEF8F2MNWKEF' });
```
1 change: 1 addition & 0 deletions packages/deploy/src/models/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface DeployContractRequest {
licenseType?: SourceCodeLicense;
libraries?: DeployRequestLibraries;
constructorInputs?: (string | boolean | number)[];
constructorBytecode?: string;
relayerId?: string;
approvalProcessId?: string;
createFactoryAddress?: string;
Expand Down
8 changes: 5 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab47885

Please sign in to comment.