Skip to content

Commit

Permalink
fix: send to treasury only assets that were minted
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Sep 26, 2024
1 parent b5e1722 commit 0ff1968
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions deploy/011-initial-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BigNumber } from "ethers";
import { getNetworkName } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

Expand All @@ -20,9 +21,9 @@ const sumAmounts = async (tokens: { symbol: string; amount: BigNumber }[]) => {
return amounts;
};

const faucetTokens = async (deploymentConfig: DeploymentConfig, hre: HardhatRuntimeEnvironment) => {
const faucetTokens = async (deploymentConfig: DeploymentConfig) => {
const { poolConfig, tokensConfig } = deploymentConfig;
const unregisteredVTokens = await getUnregisteredVTokens(poolConfig, hre);
const unregisteredVTokens = await getUnregisteredVTokens(poolConfig);
const vTokenConfigs = unregisteredVTokens.map((p: PoolConfig) => p.vtokens).flat();
const assetsToFaucet = vTokenConfigs
.map((v: { asset: string }) => getTokenConfig(v.asset, tokensConfig))
Expand All @@ -42,28 +43,25 @@ const faucetTokens = async (deploymentConfig: DeploymentConfig, hre: HardhatRunt
const tx = await tokenContract.faucet(amount, { gasLimit: 5000000 });
await tx.wait(1);
}
return vTokensToFaucet
};

const sendInitialLiquidityToTreasury = async (deploymentConfig: DeploymentConfig, hre: HardhatRuntimeEnvironment) => {
if (hre.getNetworkName() == "bscmainnet" || hre.getNetworkName() == "ethereum") {
const sendInitialLiquidityToTreasury = async (deploymentConfig: DeploymentConfig, tokensToFaucet: VTokenConfig[]) => {
if (getNetworkName() == "bscmainnet" || getNetworkName() == "ethereum") {
return;
}
const { poolConfig, tokensConfig, preconfiguredAddresses } = deploymentConfig;
const unregisteredVTokens = await getUnregisteredVTokens(poolConfig, hre);
const vTokenConfigs = unregisteredVTokens.map((p: PoolConfig) => p.vtokens).flat();

const { tokensConfig, preconfiguredAddresses } = deploymentConfig;

const amounts = vTokenConfigs.map((token: VTokenConfig) => ({
const amounts = tokensToFaucet.map((token: VTokenConfig) => ({
symbol: token.asset,
amount: BigNumber.from(token.initialSupply),
}));
const totalAmounts = await sumAmounts(amounts);
for (const [symbol, amount] of Object.entries(totalAmounts)) {
const tokenContract = await getUnderlyingToken(symbol, tokensConfig);
console.log(`Sending ${amount} ${symbol} to VTreasury`);
console.log(`Token Contract: ${tokenContract.address}`);
console.log(`Token Contract: ${amount.toString()}`);
const treasuryAddress = await toAddress(preconfiguredAddresses.VTreasury || "VTreasury");
console.log(`Token Contract: ${treasuryAddress}`);

const tx = await tokenContract.transfer(treasuryAddress, amount, { gasLimit: 5000000 });
await tx.wait(1);
Expand All @@ -72,8 +70,8 @@ const sendInitialLiquidityToTreasury = async (deploymentConfig: DeploymentConfig

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const deploymentConfig = await getConfig(hre.getNetworkName());
await faucetTokens(deploymentConfig, hre);
await sendInitialLiquidityToTreasury(deploymentConfig, hre);
const assetsToFaucet = await faucetTokens(deploymentConfig);
await sendInitialLiquidityToTreasury(deploymentConfig, assetsToFaucet);
};

func.tags = ["InitialLiquidity", "il"];
Expand Down

0 comments on commit 0ff1968

Please sign in to comment.