Skip to content

Commit

Permalink
adjusted deploy script to use existing ztokens
Browse files Browse the repository at this point in the history
  • Loading branch information
David405 committed Apr 29, 2024
1 parent 5711bff commit ab3f11d
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 17 deletions.
20 changes: 3 additions & 17 deletions contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -182,30 +182,27 @@ contract Vault is
globalResetState = true;
}

function resetUserState(address _user, uint256 _collateral, uint256 _netMint, uint256 _zusd, uint256 _zngn, uint256 _zxaf, uint256 _zzar) external onlyOwner {
function resetUserState(address _user, uint256 _collateral, uint256 _netMint) external onlyOwner {
require( userResetState[_user] == false, "User state already reset" );

uint256 amountInUSDC = _collateral / USDC_DIVISOR;

userCollateralBalance[_user] = _collateral;
netMintUser[_user] = _netMint;
grossMintUser[_user] = _netMint;

mintersAddresses.push(_user);
isMinter[_user] = true;

userResetState[_user] = true;

_mint(zUSD, _user, _zusd);
_mint(zNGN, _user, _zngn);
_mint(zXAF, _user, _zxaf);
_mint(zZAR, _user, _zzar);
lastUserCollateralRatio[_user] = getUserCollateralRatio(_user);

bool success = collateral.transfer(
_user,
amountInUSDC
);
if (!success) revert();

}

/**
Expand Down Expand Up @@ -862,17 +859,6 @@ contract Vault is
return zUSD = BakiOracleInterface(Oracle).getZToken("zusd");
}

function getzNGNAddress() external returns(address) {
return zNGN = BakiOracleInterface(Oracle).getZToken("zngn");
}

function getzXAFAddress() external returns(address) {
return zXAF = BakiOracleInterface(Oracle).getZToken("zxaf");
}

function getzZARAddress() external returns(address) {
return zZAR = BakiOracleInterface(Oracle).getZToken("zzar");
}
/**
* Helper function for global debt
*/
Expand Down
107 changes: 107 additions & 0 deletions scripts/reset_mainnet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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: 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');

const datafeed = MAINNET_DATAFEED;

const MULTISIG = MAINNET_MULTISIG;

const collateral = "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E";
const Oracle = "0x3dbC7F6b6AB5178C7e0eefbCf361dba1968DbF58";
const zUSD = "0x9626B9583519E9dAa1C3a7B2E374518743C91ed2";

async function deployToken(_name, _symbol) {
const ZToken = await ethers.getContractFactory("ZToken");
console.log(`deploying ${_name}`);

const ztoken = await ZToken.deploy(_name, _symbol, MULTISIG);

await ztoken.waitForDeployment();
tokens[_name] = ztoken.address;
console.log(`${_name} token is deployed at ${ztoken.target}`);

return ztoken.target;
}

async function deployOracle(_admin, _datafeed, _zusd, _zngn, _zzar ,_zxaf) {
const Oracle = await ethers.getContractFactory("BakiOracle");
console.log("deploying oracle");

const oracle = await Oracle.deploy(_admin, _datafeed, _zusd, _zngn, _zzar ,_zxaf);

await oracle.waitForDeployment();

console.log(`oracle is deployed is ${oracle.target}`);
return oracle.target;
}

async function addContract(_address, _name, _abi) {
const success = await client.addContract({
network: 'fuji',
address: _address,
name: _name,
abi: _abi,
natSpec: '{devdoc:{...}, userdoc: {...}}',
});
console.log('success');
return success;
}

async function main() {

console.log("deploying mainnet");

const Vault = await ethers.getContractFactory("Vault");

// deploy ztokens contracts
// const zUSD = await deployToken("zUSD", "zUSD");
// const zNGN = await deployToken("zNGN", "zNGN");
// const zZAR = await deployToken("zZAR", "zZAR");
// const zXAF = await deployToken("zXAF", "zXAF");

// Oracle = await deployOracle(MULTISIG, datafeed, zUSD, zNGN, zZAR, zXAF);

// console.log(Oracle);

const vault = await upgrades.deployProxy(
Vault,
[MULTISIG, Oracle, collateral, zUSD],
{
initializer: "vault_init",
}
);

await vault.waitForDeployment();
console.log("Vault deployed to:", vault);

console.log('Transferring ownership of ProxyAdmin...');

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));

const filePath = 'keystore.json';

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

main()

0 comments on commit ab3f11d

Please sign in to comment.