dsa-connectors/scripts/tests/addLiquidity.ts

43 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2022-03-09 12:03:47 +00:00
import { ethers, network } from "hardhat";
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";
2022-04-07 09:52:05 +00:00
import { tokenMapping as optimismMapping } from "./optimism/tokens";
2022-05-14 17:13:14 +00:00
import { tokenMapping as arbitrumMapping } from "./arbitrum/tokens";
2022-06-15 15:26:46 +00:00
import { tokenMapping as fantomMapping } from "./fantom/tokens";
2021-11-28 19:04:32 +00:00
const mineTx = async (tx: any) => {
await (await tx).wait();
};
2021-12-15 07:43:41 +00:00
const tokenMapping: Record<string, Record<string, any>> = {
mainnet: mainnetMapping,
polygon: polygonMapping,
2022-04-07 09:52:05 +00:00
avalanche: avalancheMapping,
2022-05-14 17:13:14 +00:00
optimism: optimismMapping,
2022-06-15 15:26:46 +00:00
arbitrum: arbitrumMapping,
fantom: fantomMapping
};
2021-11-29 17:21:11 +00:00
export async function addLiquidity(tokenName: string, address: any, amt: any) {
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-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]);
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
]);
await token.process(impersonatedSigner, address, amt);
2021-11-29 17:21:11 +00:00
}