Skip to content

Commit

Permalink
Test replacing PAL by hPAL for Controller rewards + Kovan tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kogaroshi committed May 9, 2022
1 parent a834e04 commit 8e3106c
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 9 deletions.
56 changes: 56 additions & 0 deletions contracts/interfaces/IhPAL.sol
@@ -0,0 +1,56 @@
pragma solidity ^0.7.6;
pragma abicoder v2;
//SPDX-License-Identifier: MIT

interface IhPAL {

struct UserLock {
uint128 amount;
uint48 startTimestamp;
uint48 duration;
uint32 fromBlock;
}

// solhint-disable-next-line
function MIN_LOCK_DURATION() external view returns(uint256);
// solhint-disable-next-line
function MAX_LOCK_DURATION() external view returns(uint256);

function getUserLock(address user) external view returns(UserLock memory);

function getUserLockCount(address user) external view returns(uint256);

function getUserPastLock(address user, uint256 blockNumber) external view returns(UserLock memory);

function estimateClaimableRewards(address user) external view returns(uint256);


function stake(uint256 amount) external returns(uint256);

function cooldown() external;

function unstake(uint256 amount, address receiver) external returns(uint256);

function lock(uint256 amount, uint256 duration) external;

function increaseLockDuration(uint256 duration) external;

function increaseLock(uint256 amount) external;

function unlock() external;

function kick(address user) external;

function stakeAndLock(uint256 amount, uint256 duration) external returns(uint256);

function stakeAndIncreaseLock(uint256 amount, uint256 duration) external returns(uint256);

function delegate(address delegatee) external;

function claim(uint256 amount) external;

function updateRewardState() external;

function updateUserRewardState(address user) external;

}
5 changes: 4 additions & 1 deletion hardhat.config.ts
Expand Up @@ -67,7 +67,7 @@ const config: HardhatUserConfig = {
hardhat: {
forking: {
url: "https://eth-mainnet.alchemyapi.io/v2/" + (process.env.ALCHEMY_API_KEY || ''),
blockNumber: 12908431
blockNumber: 14741400
}
},
kovan: {
Expand All @@ -92,6 +92,9 @@ const config: HardhatUserConfig = {
},*/
},
},
mocha: {
timeout: 0
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
Expand Down
43 changes: 35 additions & 8 deletions test/controller/rewards.test.ts
Expand Up @@ -8,11 +8,17 @@ import { PalPool } from "../../typechain/PalPool";
import { PalLoanToken } from "../../typechain/PalLoanToken";
import { InterestCalculator } from "../../typechain/InterestCalculator";
import { BasicDelegator } from "../../typechain/BasicDelegator";
import { IERC20 } from "../../typechain/IERC20";
import { IERC20__factory } from "../../typechain/factories/IERC20__factory";
import { IhPAL } from "../../typechain/IhPAL";
import { IhPAL__factory } from "../../typechain/factories/IhPAL__factory";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { ContractFactory } from "@ethersproject/contracts";
import { getERC20 } from "../utils/getERC20";

chai.use(solidity);
const { expect } = chai;
const { provider } = ethers;

const mantissa = ethers.utils.parseEther('1')
const doubleMantissa = ethers.utils.parseEther('1000000000000000000')
Expand All @@ -26,6 +32,11 @@ let delegatorFactory: ContractFactory
let interestFactory: ContractFactory
let palLoanTokenFactory: ContractFactory

const hPAL_address = "0x624D822934e87D3534E435b83ff5C19769Efd9f6"

const PAL_address = "0xAB846Fb6C81370327e784Ae7CbB6d6a6af6Ff4BF"
const PAL_holder = "0x0792dcb7080466e4bbc678bdb873fe7d969832b8"


describe('Paladin Controller - Rewards System tests', () => {
let admin: SignerWithAddress
Expand All @@ -43,7 +54,8 @@ describe('Paladin Controller - Rewards System tests', () => {
let delegator: BasicDelegator
let interest: InterestCalculator
let underlying: Comp
let rewardToken: Comp

let rewardToken: IERC20

let fakeLoan: SignerWithAddress

Expand All @@ -62,23 +74,38 @@ describe('Paladin Controller - Rewards System tests', () => {
}

before( async () => {
[
admin,
user1,
user2,
user3,
fakeLoan
] = await ethers.getSigners();

controllerFactory = await ethers.getContractFactory("PaladinController");
erc20Factory = await ethers.getContractFactory("Comp");
tokenFactory = await ethers.getContractFactory("PalToken");
palLoanTokenFactory = await ethers.getContractFactory("PalLoanToken");
poolFactory = await ethers.getContractFactory("PalPool");
delegatorFactory = await ethers.getContractFactory("BasicDelegator");
interestFactory = await ethers.getContractFactory("InterestCalculator");

const rewards_amount = ethers.utils.parseEther('1000000')

const PAL = IERC20__factory.connect(PAL_address, provider);

const hPAL = IhPAL__factory.connect(hPAL_address, provider);
rewardToken = IERC20__factory.connect(hPAL_address, provider);

await getERC20(admin, PAL_holder, PAL, admin.address, rewards_amount)

await PAL.connect(admin).approve(hPAL.address, rewards_amount)

await hPAL.connect(admin).stake(rewards_amount)

})

beforeEach( async () => {
[
admin,
user1,
user2,
user3,
fakeLoan
] = await ethers.getSigners();

controller = (await controllerFactory.deploy()) as PaladinController;

Expand Down
28 changes: 28 additions & 0 deletions test/utils/getERC20.ts
Expand Up @@ -30,4 +30,32 @@ export async function getAAVE(
method: "hardhat_stopImpersonatingAccount",
params: [AAVE_holder],
});
}

export async function getERC20(
admin: SignerWithAddress,
holder: string,
erc20_contract: Contract,
recipient: string,
amount: BigNumber
) {

await hre.network.provider.request({
method: "hardhat_impersonateAccount",
params: [holder],
});

await admin.sendTransaction({
to: holder,
value: ethers.utils.parseEther("10"),
});

const signer = await ethers.getSigner(holder)

await erc20_contract.connect(signer).transfer(recipient, amount);

await hre.network.provider.request({
method: "hardhat_stopImpersonatingAccount",
params: [holder],
});
}

0 comments on commit 8e3106c

Please sign in to comment.