-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61a69e6
commit dc10cd5
Showing
5 changed files
with
50 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Unlock admin proposals | ||
|
||
To create Unlock admin proposals: | ||
1. Create a new proposal file (like in scripts/unlock-admin/example.yaml). | ||
2. At the project root, do `npm run unlock:propose -- <proposal-file-path>`. | ||
3. Follow the links in the output to verify that the proposals were created in Defender. |
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,47 +1,62 @@ | ||
const fs = require('fs'); | ||
require('dotenv').config(); | ||
const { AdminClient } = require('defender-admin-client'); | ||
const defenderAdmin = new AdminClient({ apiKey: process.env.DEFENDER_API_KEY, apiSecret: process.env.DEFENDER_API_SECRET }); | ||
const defenderAdmin = new AdminClient({ | ||
apiKey: process.env.DEFENDER_API_KEY, | ||
apiSecret: process.env.DEFENDER_SECRET_KEY, | ||
}); | ||
const jsyaml = require('js-yaml'); | ||
const { ethers } = require('ethers'); | ||
|
||
const call = require('./call'); | ||
|
||
async function main() { | ||
const proposalFile = jsyaml.load(process.argv[2]); | ||
const proposalFile = jsyaml.load(fs.readFileSync(process.argv[2], 'utf8')); | ||
for (let i = 0; i < proposalFile.proposals.length; i++) { | ||
const proposal = proposalFile.proposals[i]; | ||
await propose(proposalFile.config, proposal); | ||
} | ||
} | ||
|
||
async function propose(config, proposal) { | ||
const proposalCall = getCall(proposal); | ||
const result = await defenderAdmin.createProposal({ | ||
const { func, inputs } = getCall(proposal); | ||
const proposalParams = { | ||
contract: { | ||
address: config.contracts[proposal.contract], | ||
network: config.network, | ||
}, | ||
title: proposal.title, | ||
description: proposal.description, | ||
type: 'custom', | ||
functionInterface: proposalCall.function, | ||
functionInputs: proposalCall.inputs, | ||
functionInterface: func, | ||
functionInputs: inputs, | ||
via: config.signer.address, | ||
viaType: config.signer.type, | ||
}); | ||
console.log(result.url); | ||
}; | ||
const result = await defenderAdmin.createProposal(proposalParams); | ||
console.log(`${proposal.title}: ${result.url}`); | ||
} | ||
|
||
function getCall(proposal) { | ||
const { args } = proposal; | ||
switch (proposal.type) { | ||
case 'deploy': | ||
return call.createUpgradeableLockAtVersion(proposal.initArgs, proposal.version); | ||
if (!args.initArgs.maxNumberOfKeys) { | ||
args.initArgs.maxNumberOfKeys = ethers.constants.MaxUint256.toString(); | ||
} | ||
return call.createUpgradeableLockAtVersion(args.initArgs, args.version); | ||
|
||
case 'updateKeyPricing': | ||
return call.updateKeyPricing(proposal.keyPrice, proposal.tokenAddress); | ||
return call.updateKeyPricing(args.keyPrice, args.tokenAddress); | ||
|
||
case 'withdraw': | ||
return call.withdraw(proposal.tokenAddress, proposal.recipient, proposal.amount); | ||
return call.withdraw(args.tokenAddress, args.recipient, args.amount); | ||
|
||
default: | ||
throw `unknown proposal type ${proposal.type}`; | ||
} | ||
} | ||
|
||
main().then(() => { | ||
console.log('successfully created the proposal(s)!'); | ||
}); |