2022-03-09 12:03:47 +00:00
|
|
|
import { ethers, network } from "hardhat";
|
2022-01-28 22:13:16 +00:00
|
|
|
|
2021-11-28 19:04:32 +00:00
|
|
|
import { impersonateAccounts } from "./impersonate";
|
2021-12-15 07:43:41 +00:00
|
|
|
import { tokenMapping as mainnetMapping } from "./mainnet/tokens";
|
|
|
|
import { tokenMapping as polygonMapping } from "./polygon/tokens";
|
|
|
|
import { tokenMapping as avalancheMapping } from "./avalanche/tokens";
|
2021-06-04 10:47:16 +00:00
|
|
|
|
2021-11-28 19:04:32 +00:00
|
|
|
const mineTx = async (tx: any) => {
|
2021-06-04 10:47:16 +00:00
|
|
|
await (await tx).wait();
|
|
|
|
};
|
|
|
|
|
2021-12-15 07:43:41 +00:00
|
|
|
const tokenMapping: Record<string, Record<string, any>> = {
|
|
|
|
mainnet: mainnetMapping,
|
|
|
|
polygon: polygonMapping,
|
2022-03-09 12:03:47 +00:00
|
|
|
avalanche: avalancheMapping
|
2021-06-04 10:47:16 +00:00
|
|
|
};
|
|
|
|
|
2021-11-29 17:21:11 +00:00
|
|
|
export async function addLiquidity(tokenName: string, address: any, amt: any) {
|
2021-06-04 10:47:16 +00:00
|
|
|
const [signer] = await ethers.getSigners();
|
|
|
|
tokenName = tokenName.toLowerCase();
|
2021-12-15 07:43:41 +00:00
|
|
|
const chain = String(process.env.networkType);
|
|
|
|
if (!tokenMapping[chain][tokenName]) {
|
2022-03-09 12:03:47 +00:00
|
|
|
throw new Error(`Add liquidity doesn't support the following token: ${tokenName}`);
|
2021-06-04 10:47:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-15 07:43:41 +00:00
|
|
|
const token = tokenMapping[chain][tokenName];
|
2022-03-09 12:03:47 +00:00
|
|
|
const [impersonatedSigner] = await impersonateAccounts([token.impersonateSigner]);
|
2021-06-04 10:47:16 +00:00
|
|
|
|
2022-01-14 14:08:35 +00:00
|
|
|
// send 2 eth to cover any tx costs.
|
|
|
|
await network.provider.send("hardhat_setBalance", [
|
|
|
|
impersonatedSigner.address,
|
2022-03-09 12:03:47 +00:00
|
|
|
ethers.utils.parseEther("2").toHexString()
|
2022-01-14 14:08:35 +00:00
|
|
|
]);
|
2021-06-04 10:47:16 +00:00
|
|
|
|
|
|
|
await token.process(impersonatedSigner, address, amt);
|
2021-11-29 17:21:11 +00:00
|
|
|
}
|