Skip to content

Commit

Permalink
Merge pull request #94 from VenusProtocol/VEN-2638
Browse files Browse the repository at this point in the history
[VEN-2638]: Deployment of SingleTokenConverters on Ethereum And Sepolia
  • Loading branch information
Debugger022 authored Jun 20, 2024
2 parents 7451d11 + 2331045 commit d4a3b14
Show file tree
Hide file tree
Showing 40 changed files with 24,455 additions and 1,814 deletions.
2 changes: 1 addition & 1 deletion contracts/TokenConverter/AbstractTokenConverter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ abstract contract AbstractTokenConverter is AccessControlledV8, IAbstractTokenCo

uint256 balanceBefore = IERC20Upgradeable(tokenAddressIn).balanceOf(_destinationAddress);

IERC20Upgradeable(tokenAddressOut).approve(converterAddresses[i], amountIn);
IERC20Upgradeable(tokenAddressOut).forceApprove(converterAddresses[i], amountIn);
IAbstractTokenConverter(converterAddresses[i]).convertExactTokens(
amountIn,
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const func = async ({ network: { live, name }, getNamedAccounts, deployments }:

const xvsAddress = (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || ADDRESS_ONE || multisigs[name];
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[name] || ADDRESS_ONE;
const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const xvsVaultAddress = (await ethers.getContractOrNull("XVSVaultProxy"))?.address || ADDRESS_ONE;

Expand Down
62 changes: 51 additions & 11 deletions deploy/004-single-token-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,61 @@ import { DeployResult } from "hardhat-deploy/dist/types";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { ADDRESS_ONE, ADDRESS_TWO } from "../helpers/utils";
import { ADDRESS_ONE, ADDRESS_TWO, multisigs } from "../helpers/utils";

interface BaseAssets {
[key: string]: string;
}

async function getBaseAssets(network: string): Promise<BaseAssets> {
const networkBaseAssets: { [key: string]: BaseAssets } = {
bsctestnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
bscmainnet: {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
sepolia: {
USDTPrimeConverter: (await ethers.getContractOrNull("MockUSDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("MockUSDC"))?.address || ADDRESS_ONE,
WBTCPrimeConverter: (await ethers.getContractOrNull("MockWBTC"))?.address || ADDRESS_ONE,
WETHPrimeConverter: "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9", // WETH on Sepolia
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
ethereum: {
USDTPrimeConverter: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT on Ethereum
USDCPrimeConverter: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC on Ethereum
WBTCPrimeConverter: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", // WBTC on Ethereum
WETHPrimeConverter: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", // WETH on Ethereum
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
},
// add more networks
};
return networkBaseAssets[network];
}

const MIN_AMOUNT_TO_CONVERT = parseUnits("10", 18).toString();

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deployments, getNamedAccounts, network } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const baseAssets: BaseAssets = {
USDTPrimeConverter: (await ethers.getContractOrNull("USDT"))?.address || ADDRESS_ONE,
USDCPrimeConverter: (await ethers.getContractOrNull("USDC"))?.address || ADDRESS_ONE,
BTCBPrimeConverter: (await ethers.getContractOrNull("BTCB"))?.address || ADDRESS_ONE,
ETHPrimeConverter: (await ethers.getContractOrNull("ETH"))?.address || ADDRESS_ONE,
XVSVaultConverter: (await ethers.getContractOrNull("XVS"))?.address || ADDRESS_TWO,
};
const networkName = network.name;
const baseAssets: BaseAssets = await getBaseAssets(networkName);

const acmAddress = (await ethers.getContractOrNull("AccessControlManager"))?.address || ADDRESS_ONE;
const oracleAddress = (await ethers.getContractOrNull("ResilientOracle"))?.address || ADDRESS_ONE;
const proxyOwnerAddress =
(await ethers.getContractOrNull("NormalTimelock"))?.address || multisigs[networkName] || ADDRESS_ONE;

const singleTokenConverterImp: DeployResult = await deploy("SingleTokenConverterImp", {
contract: "SingleTokenConverter",
Expand Down Expand Up @@ -57,16 +89,24 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

const args: string[] = [acmAddress, oracleAddress, destinationAddress, baseAsset, MIN_AMOUNT_TO_CONVERT];

await deploy(singleTokenConverterName, {
const converterProxy: DeployResult = await deploy(singleTokenConverterName, {
from: deployer,
contract: "BeaconProxy",
args: [SingleTokenConverterBeacon.address, SingleTokenConverter.interface.encodeFunctionData("initialize", args)],
log: true,
autoMine: true,
});

if (network.live) {
const converter = await ethers.getContractAt("SingleTokenConverter", converterProxy.address);

const tx = await converter.transferOwnership(proxyOwnerAddress);
await tx.wait();
console.log(`Transferred ownership of ${singleTokenConverterName} to Timelock: ` + proxyOwnerAddress);
}
}
};

func.tags = ["SingleTokenConverter"];
func.tags = ["SingleTokenConverter", "Converters"];

export default func;
2 changes: 1 addition & 1 deletion deploy/005-converter-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ const func = async ({ network: { live, name }, getNamedAccounts, deployments }:
}
};

func.tags = ["ConverterNetwork"];
func.tags = ["ConverterNetwork", "Converters"];

export default func;
Loading

0 comments on commit d4a3b14

Please sign in to comment.