From 804435cf0c85ec7c61a32fc9f171844adf8fe485 Mon Sep 17 00:00:00 2001 From: zhoujia6139 Date: Thu, 31 Aug 2023 09:02:37 +0800 Subject: [PATCH] CApe Migration (#407) chore: helper contract add cApe migration --- contracts/misc/HelperContract.sol | 9 +++++ helpers/contracts-deployments.ts | 7 ++-- .../deployments/steps/21_helperContract.ts | 5 ++- test/helper_contract.spec.ts | 33 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/contracts/misc/HelperContract.sol b/contracts/misc/HelperContract.sol index 5cff9d808..1c3dea9d5 100644 --- a/contracts/misc/HelperContract.sol +++ b/contracts/misc/HelperContract.sol @@ -13,17 +13,20 @@ contract HelperContract is Initializable, OwnableUpgradeable { using SafeERC20 for IERC20; address internal immutable apeCoin; + address internal immutable cApeV1; address internal immutable cApe; address internal immutable pcApe; address internal immutable lendingPool; constructor( address _apeCoin, + address _cApeV1, address _cApe, address _pcApe, address _lendingPool ) { apeCoin = _apeCoin; + cApeV1 = _cApeV1; cApe = _cApe; pcApe = _pcApe; lendingPool = _lendingPool; @@ -57,4 +60,10 @@ contract HelperContract is Initializable, OwnableUpgradeable { IAutoCompoundApe(cApe).withdraw(amount); IERC20(apeCoin).safeTransfer(msg.sender, amount); } + + function cApeMigration(uint256 amount) external { + IERC20(cApeV1).safeTransferFrom(msg.sender, address(this), amount); + IAutoCompoundApe(cApeV1).withdraw(amount); + IAutoCompoundApe(cApe).deposit(msg.sender, amount); + } } diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 0d43355a0..2977f0f1b 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -2763,7 +2763,7 @@ export const deployAutoYieldApeImplAndAssignItToProxy = async ( ); }; -export const deployHelperContractImpl = async (verify?: boolean) => { +export const deployHelperContractImpl = async (cApeV1: tEthereumAddress, verify?: boolean) => { const allTokens = await getAllTokens(); const protocolDataProvider = await getProtocolDataProvider(); const pCApe = ( @@ -2772,6 +2772,7 @@ export const deployHelperContractImpl = async (verify?: boolean) => { const pool = await getPoolProxy(); const args = [ allTokens.APE.address, + cApeV1, allTokens.cAPE.address, pCApe, pool.address, @@ -2785,8 +2786,8 @@ export const deployHelperContractImpl = async (verify?: boolean) => { ) as Promise; }; -export const deployHelperContract = async (verify?: boolean) => { - const helperImplementation = await deployHelperContractImpl(verify); +export const deployHelperContract = async (cApeV1: tEthereumAddress, verify?: boolean) => { + const helperImplementation = await deployHelperContractImpl(cApeV1, verify); const deployer = await getFirstSigner(); const deployerAddress = await deployer.getAddress(); diff --git a/scripts/deployments/steps/21_helperContract.ts b/scripts/deployments/steps/21_helperContract.ts index 22fcc79f2..2ad31a73f 100644 --- a/scripts/deployments/steps/21_helperContract.ts +++ b/scripts/deployments/steps/21_helperContract.ts @@ -1,6 +1,7 @@ import {deployHelperContract} from "../../../helpers/contracts-deployments"; import {getParaSpaceConfig} from "../../../helpers/misc-utils"; import {ERC20TokenContractId} from "../../../helpers/types"; +import {getAllTokens} from "../../../helpers/contracts-getters"; export const step_21 = async (verify = false) => { const paraSpaceConfig = getParaSpaceConfig(); try { @@ -8,7 +9,9 @@ export const step_21 = async (verify = false) => { return; } - await deployHelperContract(verify); + const allTokens = await getAllTokens(); + //for test env, we use same address for cApeV1 and cApeV2 + await deployHelperContract(allTokens.cAPE.address, verify); } catch (error) { console.error(error); process.exit(1); diff --git a/test/helper_contract.spec.ts b/test/helper_contract.spec.ts index 42300a25a..0bfd055d6 100644 --- a/test/helper_contract.spec.ts +++ b/test/helper_contract.spec.ts @@ -12,6 +12,8 @@ import {MAX_UINT_AMOUNT} from "../helpers/constants"; import {parseEther} from "ethers/lib/utils"; import {almostEqual} from "./helpers/uniswapv3-helper"; import {waitForTx} from "../helpers/misc-utils"; +import {deployAutoCompoundApeImplAndAssignItToProxy} from "../helpers/contracts-deployments"; +import {expect} from "chai"; describe("Helper contract Test", () => { let testEnv: TestEnv; @@ -90,4 +92,35 @@ describe("Helper contract Test", () => { const apeBalance = await ape.balanceOf(user1.address); almostEqual(apeBalance, parseEther("10000")); }); + + it("cApeMigration", async () => { + const { + users: [user1], + ape, + } = await loadFixture(fixture); + + await mintAndValidate(ape, "10000", user1); + await waitForTx( + await ape + .connect(user1.signer) + .approve(cApe.address, MAX_UINT_AMOUNT) + ); + + await waitForTx( + await cApe.connect(user1.signer).deposit(user1.address, parseEther("10000")) + ); + expect(await cApe.balanceOf(user1.address)).to.be.eq(parseEther("10000")) + + await waitForTx( + await cApe + .connect(user1.signer) + .approve(helperContract.address, MAX_UINT_AMOUNT) + ); + await waitForTx( + await helperContract + .connect(user1.signer) + .cApeMigration(parseEther("10000")) + ); + expect(await cApe.balanceOf(user1.address)).to.be.eq(parseEther("10000")) + }); });