Skip to content

Commit

Permalink
added keystore management
Browse files Browse the repository at this point in the history
  • Loading branch information
David405 committed Apr 29, 2024
1 parent 3325aeb commit 5711bff
Show file tree
Hide file tree
Showing 10 changed files with 3,442 additions and 1,646 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ artifacts/
cache/
.openzeppelin/
.env
.DS_Store
.DS_Store
keystore.json
2 changes: 1 addition & 1 deletion contracts/Faucet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract Faucet is OwnableUpgradeable {
} else {
emit AvaxFinished(avax, address(this), IERC20(avax).balanceOf(msg.sender));
}
bool success = ZTokenInterface(assets[asset]).mint(receiver, 1000000 ether);
bool success = ZTokenInterface(assets[asset]).mint(receiver, 1000000 * 10**6);
if(!success) revert();
}

Expand Down
13 changes: 7 additions & 6 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type import('hardhat/config').HardhatUserConfig */
require("@nomicfoundation/hardhat-ethers");
require("@openzeppelin/hardhat-upgrades");
const {DEFENDER_API_KEY, DEFENDER_API_SECRET, MAINNET_PRIVATE_KEY, TESTNET_PRIVATE_KEY, ETHERSCAN_API_KEY } = require("./keystore.json");

const dotenv = require('dotenv');
dotenv.config();
Expand All @@ -16,32 +17,32 @@ module.exports = {
}
},
defender: {
"apiKey": `${process.env.DEFENDER_API_KEY}`,
"apiSecret": `${process.env.DEFENDER_API_SECRET}`,
"apiKey": `${DEFENDER_API_KEY}`,
"apiSecret": `${DEFENDER_API_SECRET}`,
},
networks: {
goerli: {
url: `https://eth-goerli.g.alchemy.com/v2/MIaPbNNNaHPp9qf5cDCOEJPVxJ_GwLVY`,
accounts: [
`${process.env.TESTNET_PRIVATE_KEY}`
`${TESTNET_PRIVATE_KEY}`
],
},
fuji: {
url: `https://omniscient-restless-thunder.avalanche-testnet.discover.quiknode.pro/933a2d24cf1a762fd73a569be25bdec21cb60a9f/ext/bc/C/rpc`,
accounts: [
`${process.env.TESTNET_PRIVATE_KEY}`
`${TESTNET_PRIVATE_KEY}`
],
chainId: 43113,
},
mainnet: {
url: `https://red-neat-putty.avalanche-mainnet.quiknode.pro/d54c9d0935c483e2f8e70b7a756d882e45cd9e3f/ext/bc/C/rpc/`,
accounts: [
`${process.env.MAINNET_PRIVATE_KEY}`
`${MAINNET_PRIVATE_KEY}`
],
chainId: 43114
},
// etherscan: {
// apiKey: `${process.env.ETHERSCAN_API_KEY}`,
// apiKey: `${ETHERSCAN_API_KEY}`,
// },
},
};
4,964 changes: 3,366 additions & 1,598 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"deploy-mainnet": "hardhat run --network mainnet scripts/deploy_mainnet_v1.js",
"upgrade-mainnet": "hardhat run --network mainnet scripts/upgrade_vault_mainnet.js ",
"transfer-ownership": "hardhat run --network fuji scripts/transfer-ownership.js",
"propose-upgrade": "hardhat run --network fuji scripts/propose_upgrade.js"
"propose-upgrade": "hardhat run --network fuji scripts/propose_upgrade.js",
"propose-upgrade-mainnet": "hardhat run --network mainnet scripts/propose_upgrade.js",
"bootstrap-deployment": "node scripts/aws_store.js"
},
"dependencies": {
"@aws-sdk/client-secrets-manager": "^3.556.0",
Expand Down
15 changes: 9 additions & 6 deletions scripts/test.js → scripts/aws_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ const {
SecretsManagerClient,
GetSecretValueCommand,
} = require("@aws-sdk/client-secrets-manager");
const fs = require('fs');

async function test() {
async function getStore() {

const secret_name = "KEYSTORE";

Expand All @@ -17,17 +18,19 @@ const {
response = await client.send(
new GetSecretValueCommand({
SecretId: secret_name,
VersionStage: "AWSCURRENT", // VersionStage defaults to AWSCURRENT if unspecified
VersionStage: "AWSCURRENT",
})
);
} catch (error) {
// For a list of exceptions thrown, see
// https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
throw error;
}

const secret = response.SecretString;
const keystore = JSON.parse(secret);

fs.writeFileSync('keystore.json', JSON.stringify(keystore, null, 2));

console.log(secret);
return keystore;
}
test();

getStore()
27 changes: 17 additions & 10 deletions scripts/deploy_mainnet_v1.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const { ethers, upgrades } = require("hardhat");
const fs = require('fs');
const { AdminClient } = require('@openzeppelin/defender-admin-client');
const {MAINNET_MULTISIG, DEFENDER_API_KEY, DEFENDER_API_SECRET, MAINNET_DATAFEED} = require('../keystore.json');

const client = new AdminClient({ apiKey: process.env.DEFENDER_API_KEY, apiSecret: process.env.DEFENDER_API_SECRET });
const client = new AdminClient({ apiKey: DEFENDER_API_KEY, apiSecret: DEFENDER_API_SECRET });

let ZTokenAbi = require('../contracts/abis/Ztoken.json');
let OracleAbi = require('../contracts/abis/Oracle.json');
let VaultAbi = require('../contracts/abis/Vault.json');
let USDCAbi = require('../contracts/abis/USDC.json');

const datafeed = process.env.MAINNET_DATAFEED;
const MULTISIG = process.env.MAINNET_MULTISIG;
const datafeed = MAINNET_DATAFEED;

const MULTISIG = MAINNET_MULTISIG;

let tokens = {
zUSD: null,
Expand Down Expand Up @@ -97,11 +99,16 @@ async function main() {
addContract(zXAF, 'zXAF', JSON.stringify(ZTokenAbi));
addContract(Oracle, 'Oracle', JSON.stringify(OracleAbi));
addContract(vault.target, 'Vault', JSON.stringify(VaultAbi));
addContract(collateral, 'USDC', JSON.stringify(USDCAbi));

const filePath = 'keystore.json';

fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file: ${err}`);
return;
}
console.log('File deleted successfully');
});
}

main().then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
})
main()
40 changes: 23 additions & 17 deletions scripts/deploy_vault_v1.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
const { ethers, upgrades, defender } = require("hardhat");
const { ethers, upgrades } = require("hardhat");
const fs = require('fs');
const { AdminClient } = require('@openzeppelin/defender-admin-client');
const {MAINNET_MULTISIG, DEFENDER_API_KEY, DEFENDER_API_SECRET, MAINNET_DATAFEED} = require('../keystore.json');

const dotenv = require('dotenv');
dotenv.config();

const client = new AdminClient({ apiKey: process.env.DEFENDER_API_KEY, apiSecret: process.env.DEFENDER_API_SECRET });
const client = new AdminClient({ apiKey: DEFENDER_API_KEY, apiSecret: DEFENDER_API_SECRET });

let ZTokenAbi = require('../contracts/abis/Ztoken.json');
let OracleAbi = require('../contracts/abis/Oracle.json');
let VaultAbi = require('../contracts/abis/Vault.json');
let USDCAbi = require('../contracts/abis/USDC.json');

const Datafeed = process.env.TESTNET_DATAFEED;
const Datafeed = MAINNET_DATAFEED;

const MULTISIG = process.env.TESTNET_MULTISIG;
const MULTISIG = MAINNET_MULTISIG;

let tokens = {
zUSD: null,
Expand Down Expand Up @@ -130,15 +129,22 @@ async function main() {
await upgrades.admin.transferProxyAdminOwnership(vault.target, MULTISIG);
console.log('Transferred ownership of ProxyAdmin to:', MULTISIG);

addContract(zUSD, 'zUSD', JSON.stringify(ZTokenAbi));
addContract(zNGN, 'zNGN', JSON.stringify(ZTokenAbi));
addContract(zZAR, 'zZAR', JSON.stringify(ZTokenAbi));
addContract(zXAF, 'zXAF', JSON.stringify(ZTokenAbi));
addContract(Oracle, 'Oracle', JSON.stringify(OracleAbi));
addContract(vault.target, 'Vault', JSON.stringify(VaultAbi));
addContract(collateral, 'USDC', JSON.stringify(USDCAbi));


// addContract(zUSD, 'zUSD', JSON.stringify(ZTokenAbi));
// addContract(zNGN, 'zNGN', JSON.stringify(ZTokenAbi));
// addContract(zZAR, 'zZAR', JSON.stringify(ZTokenAbi));
// addContract(zXAF, 'zXAF', JSON.stringify(ZTokenAbi));
// addContract(Oracle, 'Oracle', JSON.stringify(OracleAbi));
// addContract(vault.target, 'Vault', JSON.stringify(VaultAbi));
// addContract(collateral, 'USDC', JSON.stringify(USDCAbi));

const filePath = 'keystore.json';

fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file: ${err}`);
return;
}
console.log('File deleted successfully');
});
}

main()
16 changes: 14 additions & 2 deletions scripts/propose_upgrade.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@

const { ethers, upgrades, defender } = require("hardhat");
// const { defender } = require("hardhat");
const fs = require('fs');
const { MAINNET_VAULT } = require('../keystore.json');

async function main() {
const proxyAddress = process.env.MAINNET_VAULT;

const proxyAddress = MAINNET_VAULT;

const Vault = await ethers.getContractFactory("Vault");
console.log("Preparing proposal...");

const proposal = await defender.proposeUpgrade(proxyAddress, Vault);
console.log("Upgrade proposal created at:", proposal.url);

const filePath = 'keystore.json';

fs.unlink(filePath, (err) => {
if (err) {
console.error(`Error deleting file: ${err}`);
return;
}
console.log('File deleted successfully');
});
}

main();
Expand Down
4 changes: 0 additions & 4 deletions secret.json

This file was deleted.

0 comments on commit 5711bff

Please sign in to comment.