Skip to content

Commit

Permalink
CApe Migration (#407)
Browse files Browse the repository at this point in the history
chore: helper contract add cApe migration
  • Loading branch information
zhoujia6139 authored Aug 31, 2023
1 parent 73cbb39 commit 804435c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
9 changes: 9 additions & 0 deletions contracts/misc/HelperContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
7 changes: 4 additions & 3 deletions helpers/contracts-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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,
Expand All @@ -2785,8 +2786,8 @@ export const deployHelperContractImpl = async (verify?: boolean) => {
) as Promise<HelperContract>;
};

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();
Expand Down
5 changes: 4 additions & 1 deletion scripts/deployments/steps/21_helperContract.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
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 {
if (!paraSpaceConfig.ReservesConfig[ERC20TokenContractId.APE]) {
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);
Expand Down
33 changes: 33 additions & 0 deletions test/helper_contract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))
});
});

0 comments on commit 804435c

Please sign in to comment.