/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Dhedge, Pool } from ".."; import { routerAddress } from "../config"; import { Dapp, Network } from "../types"; import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants"; import { TestingRunParams, fixOracleAggregatorStaleness, runWithImpersonateAccount, setChainlinkTimeout, testingHelper } from "./utils/testingHelper"; import { allowanceDelta, balanceDelta } from "./utils/token"; const USDC_SUSD_Lp = "0xd16232ad60188b68076a235c65d692090caba155"; const USDC_SUSD_Gauge = "0xb03f52d2db3e758dd49982defd6aeefea9454e80"; const testVelodrome = ({ wallet, network, provider }: TestingRunParams) => { const SUSD = CONTRACT_ADDRESS[network].SUSD; const USDC = CONTRACT_ADDRESS[network].USDC; let dhedge: Dhedge; let pool: Pool; jest.setTimeout(100000); describe(`pool on ${network}`, () => { beforeAll(async () => { await provider.send("hardhat_setBalance", [ wallet.address, "0x10000000000000000" ]); dhedge = new Dhedge(wallet, network); pool = await dhedge.loadPool(TEST_POOL[network]); await setChainlinkTimeout({ pool, provider }, 86400 * 365); await fixOracleAggregatorStaleness({ pool, provider }); await runWithImpersonateAccount( { provider, account: await pool.managerLogic.manager() }, async ({ signer }) => { await pool.managerLogic.connect(signer).setTrader(wallet.address); await pool.managerLogic.connect(signer).changeAssets( [ [USDC, true], [SUSD, true], [USDC_SUSD_Lp, false] ], [] ); } ); }); it("approves unlimited sUSD and USDC on for Velodrome", async () => { await pool.approve(Dapp.VELODROME, SUSD, MAX_AMOUNT); await pool.approve(Dapp.VELODROME, USDC, MAX_AMOUNT); const UsdcAllowanceDelta = await allowanceDelta( pool.address, USDC, routerAddress[network].velodrome!, pool.signer ); expect(UsdcAllowanceDelta.gt(0)).toBe(true); }); it("adds USDC and SUSD to a Velodrome stable pool", async () => { await pool.addLiquidityVelodrome( USDC, SUSD, (5 * 1e6).toString(), (5 * 1e18).toString(), true ); const lpTokenDelta = await balanceDelta( pool.address, USDC_SUSD_Lp, pool.signer ); expect(lpTokenDelta.gt(0)).toBe(true); }); it("should stake USDC-sUSD LP in a gauge", async () => { const balance = await dhedge.utils.getBalance(USDC_SUSD_Lp, pool.address); await pool.approveSpender(USDC_SUSD_Gauge, USDC_SUSD_Lp, MAX_AMOUNT); await pool.stakeInGauge(Dapp.VELODROME, USDC_SUSD_Gauge, balance); const gaugeBalance = await balanceDelta( pool.address, USDC_SUSD_Lp, pool.signer ); expect(gaugeBalance.gt(0)).toBe(true); }); it("should claim rewards from Gauge", async () => { const tx = await pool.claimFees(Dapp.VELODROME, USDC_SUSD_Gauge); expect(tx).not.toBe(null); }); it("should unStake USDC-sUSD LP from a gauge", async () => { const gaugeBalance = await dhedge.utils.getBalance( USDC_SUSD_Gauge, pool.address ); await pool.unstakeFromGauge(USDC_SUSD_Gauge, gaugeBalance); const lpTokenDelta = await balanceDelta( pool.address, USDC_SUSD_Lp, pool.signer ); expect(lpTokenDelta.gt(0)).toBe(true); }); it("approves unlimited USDC-sUSD LP for Velodrome", async () => { await pool.approve(Dapp.VELODROME, USDC_SUSD_Lp, MAX_AMOUNT); const lpAllowanceDelta = await allowanceDelta( pool.address, USDC_SUSD_Lp, routerAddress[network].velodrome!, pool.signer ); expect(lpAllowanceDelta.gt(0)).toBe(true); }); it("should remove all liquidity from an existing pool ", async () => { const balance = await dhedge.utils.getBalance(USDC_SUSD_Lp, pool.address); await pool.removeLiquidityVelodrome(USDC, SUSD, balance, true); const usdcBalanceDelta = await balanceDelta( pool.address, USDC, pool.signer ); const susdBalanceDelta = await balanceDelta( pool.address, SUSD, pool.signer ); expect(usdcBalanceDelta.gt(0)).toBe(true); expect(susdBalanceDelta.gt(0)).toBe(true); }); }); }; testingHelper({ network: Network.OPTIMISM, testingRun: testVelodrome });