Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script to add liquidity to Vault #156

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const stableLPMakerV2Address = "0x2DF95Be842cd68062Ecdb7a30cA8dD400a8ab86
export const stableLPMakerV3Address = "0x84c1b1986766fD32cfAC340f947217bd1fB8ADed";
export const stableLPMakerV4Address = "0x5174F1F043A9C66C58f62C3b81a24fb0F31DE94A";
export const usdcMakerAddress = "0x5EBd5e963A00500B6a1234c621811c52AF0aAade";
export const gUniRouterAddress = "0x49eb1F160e167aa7bA96BdD88B6C1f2ffda5212A"

export const wethAddress = "0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB";
export const wnearAddress = "0xC42C30aC6Cc15faC9bD938618BcaA1a1FaE8501d";
Expand Down
79 changes: 79 additions & 0 deletions scripts/vaults/addLiquidityVault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
import { ethers } from "hardhat";
import { GUniRouter__factory, WETH9__factory } from "../../typechain";
import { gUniRouterAddress } from "../constants";

async function main(): Promise<void> {
// Hardhat always runs the compile task when running scripts through it.
// If this runs in a standalone fashion you may want to call compile manually
// to make sure everything is compiled
// await run("compile");

const [deployer] = await ethers.getSigners();
console.log(`Calling contracts with ${deployer.address}`);

const balance = await deployer.getBalance();
console.log(`Account balance: ${balance.toString()}`);

const gUniRouter: GUniRouter__factory = await ethers.getContractFactory("GUniRouter");
const router = gUniRouter.attach(gUniRouterAddress);

console.log(`gUniRouter address: ${router.address}`);

//Set Vault and Token Addresses (Manual for now until vaults finalized)
const vaultAddress = "0xC7b83e5CC0E997e9D230AFBFC268Fec3b00a9F61"; // OP-WETH Vault

const token0Address = "0x4200000000000000000000000000000000000006"; // WETH
const wethFactory: WETH9__factory = await ethers.getContractFactory("WETH9");
const token0 = wethFactory.attach(token0Address);
const token0BalanceDeployer = await token0.balanceOf(deployer.address);
console.log(`Token0 Balance of Deployer: ${token0BalanceDeployer}`);

const token1Address = "0x4200000000000000000000000000000000000042"; // OP
const erc20Factory = await ethers.getContractFactory("ERC20Mock");
const token1 = erc20Factory.attach(token1Address);
const token1BalanceDeployer = await token1.balanceOf(deployer.address);
console.log(`Token1 Balance of Deployer: ${token1BalanceDeployer}`);

// Approve token0 to be used by gUNI Router
console.log(`Approving token0 ${token0.address} for spend by gUniRouter: ${router.address}`);
const approveTx0 = await token0.connect(deployer).approve(router.address, token0BalanceDeployer);
const approveReceipt0 = await approveTx0.wait();
console.log(approveReceipt0.logs);

const allowance0 = await token0.connect(deployer).allowance(deployer.address, router.address);
console.log(`Allowance of gUniRouter to spend Token0: ${allowance0}`);

// Approve token1 to be used by gUNI Router
console.log(`Approving token1 ${token1.address} for spend by gUniRouter: ${router.address}`);
const approveTx1 = await token1.connect(deployer).approve(router.address, token1BalanceDeployer);
const approveReceipt1 = await approveTx1.wait();
console.log(approveReceipt1.logs);

const allowance1 = await token1.connect(deployer).allowance(deployer.address, router.address);
console.log(`Allowance of gUniRouter to spend Token1: ${allowance1}`);

// Add Liquidity via gUNI Router
const amount0Max = "3000000000000000"; // WETH to add
const amount1Max = "1404916453317048553"; // OP to add
const amount0Min = 0;
const amount1Min = 0;
console.log(`Calling addLiquidity function on gUNIRouter`);
const addLiqTxn = await router
.connect(deployer)
.addLiquidity(vaultAddress, amount0Max, amount1Max, amount0Min, amount1Min, deployer.address);
const initReceipt = await addLiqTxn.wait();
console.log(initReceipt.logs);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error: Error) => {
console.error(error);
process.exit(1);
});