mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
wip: reward claim tests
This commit is contained in:
parent
5e58eda2ed
commit
14008b3bf9
|
@ -2,9 +2,20 @@ import hre, { ethers } from "hardhat";
|
||||||
import { IERC20Minimal__factory } from "../../../typechain";
|
import { IERC20Minimal__factory } from "../../../typechain";
|
||||||
import { BigNumber as BN } from "ethers";
|
import { BigNumber as BN } from "ethers";
|
||||||
|
|
||||||
const DEAD_ADDRESS = "0x0000000000000000000000000000000000000001";
|
export const DEAD_ADDRESS = "0x0000000000000000000000000000000000000001";
|
||||||
const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
export const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
||||||
const DEFAULT_DECIMALS = 18;
|
|
||||||
|
export const DEFAULT_DECIMALS = 18;
|
||||||
|
|
||||||
|
export const ZERO = BN.from(0);
|
||||||
|
export const ONE_MIN = BN.from(60);
|
||||||
|
export const TEN_MINS = BN.from(60 * 10);
|
||||||
|
export const ONE_HOUR = BN.from(60 * 60);
|
||||||
|
export const ONE_DAY = BN.from(60 * 60 * 24);
|
||||||
|
export const FIVE_DAYS = BN.from(60 * 60 * 24 * 5);
|
||||||
|
export const TEN_DAYS = BN.from(60 * 60 * 24 * 10);
|
||||||
|
export const ONE_WEEK = BN.from(60 * 60 * 24 * 7);
|
||||||
|
export const ONE_YEAR = BN.from(60 * 60 * 24 * 365);
|
||||||
|
|
||||||
interface TokenData {
|
interface TokenData {
|
||||||
tokenAddress: string;
|
tokenAddress: string;
|
||||||
|
@ -12,7 +23,7 @@ interface TokenData {
|
||||||
feederPool?: string;
|
feederPool?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getToken = (tokenSymbol: string): TokenData => {
|
export const getToken = (tokenSymbol: string): TokenData => {
|
||||||
switch (tokenSymbol) {
|
switch (tokenSymbol) {
|
||||||
case "MTA":
|
case "MTA":
|
||||||
return {
|
return {
|
||||||
|
@ -51,7 +62,7 @@ const getToken = (tokenSymbol: string): TokenData => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendToken = async (token: string, amount: any, from: string, to: string): Promise<any> => {
|
export const sendToken = async (token: string, amount: any, from: string, to: string): Promise<any> => {
|
||||||
await hre.network.provider.request({
|
await hre.network.provider.request({
|
||||||
method: "hardhat_impersonateAccount",
|
method: "hardhat_impersonateAccount",
|
||||||
params: [from]
|
params: [from]
|
||||||
|
@ -67,20 +78,18 @@ const sendToken = async (token: string, amount: any, from: string, to: string):
|
||||||
return await IERC20Minimal__factory.connect(token, sender).transfer(to, amount);
|
return await IERC20Minimal__factory.connect(token, sender).transfer(to, amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
const fundWallet = async (token: string, amount: any, to: string) => {
|
export const fundWallet = async (token: string, amount: any, to: string) => {
|
||||||
const { tokenAddress, tokenWhaleAddress } = getToken(token);
|
const { tokenAddress, tokenWhaleAddress } = getToken(token);
|
||||||
await sendToken(tokenAddress, amount, tokenWhaleAddress!, to);
|
await sendToken(tokenAddress, amount, tokenWhaleAddress!, to);
|
||||||
};
|
};
|
||||||
|
|
||||||
const calcMinOut = (amount: BN, slippage: number): BN => {
|
export const calcMinOut = (amount: BN, slippage: number): BN => {
|
||||||
const value = simpleToExactAmount(1 - slippage);
|
const value = simpleToExactAmount(1 - slippage);
|
||||||
const minOut = amount.mul(value).div(ethers.BigNumber.from(10).pow(DEFAULT_DECIMALS));
|
const minOut = amount.mul(value).div(ethers.BigNumber.from(10).pow(DEFAULT_DECIMALS));
|
||||||
return minOut;
|
return minOut;
|
||||||
};
|
};
|
||||||
|
|
||||||
const simpleToExactAmount = (amount: number | string | BN, decimals: number | BN = DEFAULT_DECIMALS): BN => {
|
export const simpleToExactAmount = (amount: number | string | BN, decimals: number | BN = DEFAULT_DECIMALS): BN => {
|
||||||
// Code is largely lifted from the guts of web3 toWei here:
|
|
||||||
// https://github.com/ethjs/ethjs-unit/blob/master/src/index.js
|
|
||||||
let amountString = amount.toString();
|
let amountString = amount.toString();
|
||||||
const decimalsBN = BN.from(decimals);
|
const decimalsBN = BN.from(decimals);
|
||||||
|
|
||||||
|
@ -134,4 +143,9 @@ const simpleToExactAmount = (amount: number | string | BN, decimals: number | BN
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
export { fundWallet, getToken, simpleToExactAmount, DEAD_ADDRESS, ZERO_ADDRESS, calcMinOut };
|
export const advanceBlock = async (): Promise<void> => ethers.provider.send("evm_mine", []);
|
||||||
|
|
||||||
|
export const increaseTime = async (length: BN | number): Promise<void> => {
|
||||||
|
await ethers.provider.send("evm_increaseTime", [BN.from(length).toNumber()]);
|
||||||
|
await advanceBlock();
|
||||||
|
};
|
||||||
|
|
|
@ -16,7 +16,15 @@ import type { Signer, Contract, BigNumber } from "ethers";
|
||||||
|
|
||||||
import { ConnectV2mStable__factory, IERC20Minimal__factory, IERC20Minimal } from "../../../typechain";
|
import { ConnectV2mStable__factory, IERC20Minimal__factory, IERC20Minimal } from "../../../typechain";
|
||||||
|
|
||||||
import { fundWallet, getToken, simpleToExactAmount, DEAD_ADDRESS, calcMinOut } from "./mstable.helpers";
|
import {
|
||||||
|
fundWallet,
|
||||||
|
getToken,
|
||||||
|
simpleToExactAmount,
|
||||||
|
DEAD_ADDRESS,
|
||||||
|
calcMinOut,
|
||||||
|
ONE_DAY,
|
||||||
|
increaseTime
|
||||||
|
} from "./mstable.helpers";
|
||||||
|
|
||||||
describe("MStable", async () => {
|
describe("MStable", async () => {
|
||||||
const connectorName = "MStable";
|
const connectorName = "MStable";
|
||||||
|
@ -278,13 +286,14 @@ describe("MStable", async () => {
|
||||||
const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address);
|
const mtaBalanceBefore = await mtaToken.balanceOf(dsaWallet0.address);
|
||||||
console.log("MTA balance before: ", toEther(mtaBalanceBefore));
|
console.log("MTA balance before: ", toEther(mtaBalanceBefore));
|
||||||
|
|
||||||
// Wait a day and let the rewards accumulate
|
// Wait a bit and let the rewards accumulate
|
||||||
await provider.send("evm_increaseTime", [600]);
|
await increaseTime(ONE_DAY);
|
||||||
|
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
connector: connectorName,
|
connector: connectorName,
|
||||||
method: "claimRewards"
|
method: "claimRewards",
|
||||||
|
args: []
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user