Gelato-automations/test/helpers/services/maker/initializeMakerCdp.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-16 16:55:04 +00:00
const { expect } = require("chai");
2020-10-30 17:35:11 +00:00
const hre = require("hardhat");
2020-11-15 14:08:12 +00:00
module.exports = async function (
2020-10-30 17:35:11 +00:00
userAddress,
2020-11-02 10:51:49 +00:00
DAI,
2020-10-30 17:35:11 +00:00
dsa,
getCdps,
dssCdpManager,
makerInitialEth,
makerInitialDebt,
connectMakerABI
2020-10-30 17:35:11 +00:00
) {
//#region Step 8 User open a Vault, put some ether on it and borrow some dai
// User open a maker vault
// He deposit 10 Eth on it
// He borrow a 1000 DAI
const openVault = await hre.run("abi-encode-withselector", {
abi: connectMakerABI,
2020-10-30 17:35:11 +00:00
functionname: "open",
inputs: ["ETH-A"],
});
await dsa.cast([hre.network.config.ConnectMaker], [openVault], userAddress);
const cdps = await getCdps.getCdpsAsc(dssCdpManager.address, dsa.address);
let vaultId = String(cdps.ids[0]);
expect(cdps.ids[0].isZero()).to.be.false;
await dsa.cast(
[hre.network.config.ConnectMaker],
[
await hre.run("abi-encode-withselector", {
abi: connectMakerABI,
2020-10-30 17:35:11 +00:00
functionname: "deposit",
inputs: [vaultId, makerInitialEth, 0, 0],
}),
],
userAddress,
{
value: makerInitialEth,
}
);
await dsa.cast(
[hre.network.config.ConnectMaker],
[
await hre.run("abi-encode-withselector", {
abi: connectMakerABI,
2020-10-30 17:35:11 +00:00
functionname: "borrow",
inputs: [vaultId, makerInitialDebt, 0, 0],
}),
],
userAddress
);
2020-11-02 10:51:49 +00:00
expect(await DAI.balanceOf(dsa.address)).to.be.equal(makerInitialDebt);
2020-10-30 17:35:11 +00:00
//#endregion
return vaultId;
2020-11-15 14:08:12 +00:00
};