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

CApe Migration #407

Merged
merged 1 commit into from
Aug 31, 2023
Merged
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
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 @@ -2840,7 +2840,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 @@ -2849,6 +2849,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 @@ -2862,8 +2863,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"))
});
});