fix broken tests from instadapp PR

This commit is contained in:
Edward Mulraney 2021-06-30 17:16:05 +01:00
parent d45f08b743
commit 7ef923929c
4 changed files with 157 additions and 135 deletions

View File

@ -8,8 +8,8 @@ contract Events {
uint maxFeePercentage, uint maxFeePercentage,
uint depositAmount, uint depositAmount,
uint borrowAmount, uint borrowAmount,
uint[] getIds, uint256[] getIds,
uint[] setIds uint256[] setIds
); );
event LogClose(address indexed borrower, uint setId); event LogClose(address indexed borrower, uint setId);
event LogDeposit(address indexed borrower, uint amount, uint getId, uint setId); event LogDeposit(address indexed borrower, uint amount, uint getId, uint setId);
@ -23,8 +23,8 @@ contract Events {
uint withdrawAmount, uint withdrawAmount,
uint borrowAmount, uint borrowAmount,
uint repayAmount, uint repayAmount,
uint[] getIds, uint256[] getIds,
uint[] setIds uint256[] setIds
); );
event LogClaimCollateralFromRedemption(address indexed borrower, uint amount, uint setId); event LogClaimCollateralFromRedemption(address indexed borrower, uint amount, uint setId);
@ -52,7 +52,7 @@ contract Events {
event LogStabilityMoveEthGainToTrove(address indexed borrower, uint amount); event LogStabilityMoveEthGainToTrove(address indexed borrower, uint amount);
/* Staking */ /* Staking */
event LogStake(address indexed borrower, uint amount, uint setStakeId, uint getStakeId, uint setEthGainId, uint setLusdGainId); event LogStake(address indexed borrower, uint amount, uint getStakeId, uint setStakeId, uint setEthGainId, uint setLusdGainId);
event LogUnstake(address indexed borrower, uint amount, uint getUnstakeId, uint setUnstakeId, uint setEthGainId, uint setLusdGainId); event LogUnstake(address indexed borrower, uint amount, uint getUnstakeId, uint setUnstakeId, uint setEthGainId, uint setLusdGainId);
event LogClaimStakingGains(address indexed borrower, uint ethGain, uint lusdGain, uint setEthGainId, uint setLusdGainId); event LogClaimStakingGains(address indexed borrower, uint ethGain, uint lusdGain, uint setEthGainId, uint setLusdGainId);
} }

View File

@ -38,8 +38,8 @@ abstract contract LiquityResolver is Events, Helpers {
uint borrowAmount, uint borrowAmount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint[] getIds, uint[] memory getIds,
uint[] setIds uint[] memory setIds
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
depositAmount = getUint(getIds[0], depositAmount); depositAmount = getUint(getIds[0], depositAmount);
@ -139,7 +139,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @param amount Amount of LUSD to borrow * @param amount Amount of LUSD to borrow
* @param upperHint Address of the Trove near the upper bound of where the user's Trove should now sit in the ordered Trove list * @param upperHint Address of the Trove near the upper bound of where the user's Trove should now sit in the ordered Trove list
* @param lowerHint Address of the Trove near the lower bound of where the user's Trove should now sit in the ordered Trove list * @param lowerHint Address of the Trove near the lower bound of where the user's Trove should now sit in the ordered Trove list
* @param setId Optional storage slot to store the borrowed LUSD in * @param getId Optional storage slot to retrieve the amount of LUSD to borrow
* @param setId Optional storage slot to store the final amount of LUSD borrowed
*/ */
function borrow( function borrow(
uint maxFeePercentage, uint maxFeePercentage,
@ -165,7 +166,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @param amount Amount of LUSD to repay * @param amount Amount of LUSD to repay
* @param upperHint Address of the Trove near the upper bound of where the user's Trove should now sit in the ordered Trove list * @param upperHint Address of the Trove near the upper bound of where the user's Trove should now sit in the ordered Trove list
* @param lowerHint Address of the Trove near the lower bound of where the user's Trove should now sit in the ordered Trove list * @param lowerHint Address of the Trove near the lower bound of where the user's Trove should now sit in the ordered Trove list
* @param getId Optional storage slot to retrieve the LUSD from * @param getId Optional storage slot to retrieve the amount of LUSD from
* @param setId Optional storage slot to store the final amount of LUSD repaid
*/ */
function repay( function repay(
uint amount, uint amount,
@ -211,8 +213,8 @@ abstract contract LiquityResolver is Events, Helpers {
uint repayAmount, uint repayAmount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint[] getIds, uint[] memory getIds,
uint[] setIds uint[] memory setIds
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
AdjustTrove memory adjustTrove; AdjustTrove memory adjustTrove;
@ -276,7 +278,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @notice Deposit LUSD into Stability Pool * @notice Deposit LUSD into Stability Pool
* @param amount Amount of LUSD to deposit into Stability Pool * @param amount Amount of LUSD to deposit into Stability Pool
* @param frontendTag Address of the frontend to make this deposit against (determines the kickback rate of rewards) * @param frontendTag Address of the frontend to make this deposit against (determines the kickback rate of rewards)
* @param getDepositId Optional storage slot to retrieve the LUSD from * @param getDepositId Optional storage slot to retrieve the amount of LUSD from
* @param setDepositId Optional storage slot to store the final amount of LUSD deposited
* @param setEthGainId Optional storage slot to store any ETH gains in * @param setEthGainId Optional storage slot to store any ETH gains in
* @param setLqtyGainId Optional storage slot to store any LQTY gains in * @param setLqtyGainId Optional storage slot to store any LQTY gains in
*/ */
@ -312,6 +315,7 @@ abstract contract LiquityResolver is Events, Helpers {
* @dev Withdraw user deposited LUSD from Stability Pool * @dev Withdraw user deposited LUSD from Stability Pool
* @notice Withdraw LUSD from Stability Pool * @notice Withdraw LUSD from Stability Pool
* @param amount Amount of LUSD to withdraw from Stability Pool * @param amount Amount of LUSD to withdraw from Stability Pool
* @param getWithdrawId Optional storage slot to retrieve the amount of LUSD to withdraw from
* @param setWithdrawId Optional storage slot to store the withdrawn LUSD * @param setWithdrawId Optional storage slot to store the withdrawn LUSD
* @param setEthGainId Optional storage slot to store any ETH gains in * @param setEthGainId Optional storage slot to store any ETH gains in
* @param setLqtyGainId Optional storage slot to store any LQTY gains in * @param setLqtyGainId Optional storage slot to store any LQTY gains in
@ -325,7 +329,7 @@ abstract contract LiquityResolver is Events, Helpers {
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
amount = getUint(getWithdrawId, amount); amount = getUint(getWithdrawId, amount);
amount = amount == uint(-1) ? StabilityPoolLike.getCompoundedLUSDDeposit(address(this)) : amount; amount = amount == uint(-1) ? stabilityPool.getCompoundedLUSDDeposit(address(this)) : amount;
uint ethGain = stabilityPool.getDepositorETHGain(address(this)); uint ethGain = stabilityPool.getDepositorETHGain(address(this));
uint lqtyBalanceBefore = lqtyToken.balanceOf(address(this)); uint lqtyBalanceBefore = lqtyToken.balanceOf(address(this));
@ -366,7 +370,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @dev Sends LQTY tokens from user to Staking Pool * @dev Sends LQTY tokens from user to Staking Pool
* @notice Stake LQTY in Staking Pool * @notice Stake LQTY in Staking Pool
* @param amount Amount of LQTY to stake * @param amount Amount of LQTY to stake
* @param getStakeId Optional storage slot to retrieve the LQTY from * @param getStakeId Optional storage slot to retrieve the amount of LQTY to stake
* @param setStakeId Optional storage slot to store the final staked amount (can differ if requested with max balance: uint(-1))
* @param setEthGainId Optional storage slot to store any ETH gains * @param setEthGainId Optional storage slot to store any ETH gains
* @param setLusdGainId Optional storage slot to store any LUSD gains * @param setLusdGainId Optional storage slot to store any LUSD gains
*/ */
@ -396,7 +401,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @dev Sends LQTY tokens from Staking Pool to user * @dev Sends LQTY tokens from Staking Pool to user
* @notice Unstake LQTY in Staking Pool * @notice Unstake LQTY in Staking Pool
* @param amount Amount of LQTY to unstake * @param amount Amount of LQTY to unstake
* @param setStakeId Optional storage slot to store the unstaked LQTY * @param getUnstakeId Optional storage slot to retrieve the amount of LQTY to unstake
* @param setUnstakeId Optional storage slot to store the unstaked LQTY
* @param setEthGainId Optional storage slot to store any ETH gains * @param setEthGainId Optional storage slot to store any ETH gains
* @param setLusdGainId Optional storage slot to store any LUSD gains * @param setLusdGainId Optional storage slot to store any LUSD gains
*/ */

View File

@ -50,10 +50,11 @@ const openTroveSpell = async (
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0],
0, [0, 0],
], ],
}; };
return await dsa return await dsa
.connect(signer) .connect(signer)
.cast(...encodeSpells([openTroveSpell]), address, { .cast(...encodeSpells([openTroveSpell]), address, {

View File

@ -65,8 +65,8 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0],
0, [0, 0],
], ],
}; };
@ -144,8 +144,8 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
depositId, [depositId, 0],
0, [0, 0],
], ],
}; };
@ -218,8 +218,8 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0],
borrowId, [borrowId, 0],
], ],
}; };
@ -297,8 +297,8 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0],
0, [0, 0],
], ],
}; };
@ -313,17 +313,24 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogOpen(address,uint256,uint256,uint256,uint256,uint256)" "LogOpen(address,uint256,uint256,uint256,uint256[],uint256[])"
); );
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256", "uint256"],
[ [
userWallet.address, "address",
"uint256",
"uint256",
"uint256",
"uint256[]",
"uint256[]",
],
[
dsa.address,
maxFeePercentage, maxFeePercentage,
depositAmount, depositAmount,
borrowAmount, borrowAmount,
0, [0, 0],
0, [0, 0],
] ]
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
@ -598,7 +605,7 @@ describe("Liquity", () => {
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256"], ["address", "uint256"],
[userWallet.address, 0] [dsa.address, 0]
); );
expect(castLogEvent.eventNames[0]).eq("LogClose(address,uint256)"); expect(castLogEvent.eventNames[0]).eq("LogClose(address,uint256)");
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
@ -620,7 +627,7 @@ describe("Liquity", () => {
const depositEthSpell = { const depositEthSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "deposit", method: "deposit",
args: [topupAmount, upperHint, lowerHint, 0], args: [topupAmount, upperHint, lowerHint, 0, 0],
}; };
await dsa await dsa
@ -663,7 +670,7 @@ describe("Liquity", () => {
const depositEthToTroveSpell = { const depositEthToTroveSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "deposit", method: "deposit",
args: [0, upperHint, lowerHint, depositId], args: [0, upperHint, lowerHint, depositId, 0],
}; };
const spells = [depositEthSpell, depositEthToTroveSpell]; const spells = [depositEthSpell, depositEthToTroveSpell];
@ -697,7 +704,7 @@ describe("Liquity", () => {
const depositEthSpell = { const depositEthSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "deposit", method: "deposit",
args: [topupAmount, upperHint, lowerHint, 0], args: [topupAmount, upperHint, lowerHint, 0, 0],
}; };
const depositTx = await dsa const depositTx = await dsa
@ -710,11 +717,11 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256"],
[userWallet.address, topupAmount, 0] [dsa.address, topupAmount, 0, 0]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogDeposit(address,uint256,uint256)" "LogDeposit(address,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -734,7 +741,7 @@ describe("Liquity", () => {
const withdrawEthSpell = { const withdrawEthSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "withdraw", method: "withdraw",
args: [withdrawAmount, upperHint, lowerHint, 0], args: [withdrawAmount, upperHint, lowerHint, 0, 0],
}; };
await dsa await dsa
@ -772,7 +779,7 @@ describe("Liquity", () => {
const withdrawEthFromTroveSpell = { const withdrawEthFromTroveSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "withdraw", method: "withdraw",
args: [withdrawAmount, upperHint, lowerHint, withdrawId], args: [withdrawAmount, upperHint, lowerHint, 0, withdrawId],
}; };
const withdrawEthSpell = { const withdrawEthSpell = {
@ -815,11 +822,10 @@ describe("Liquity", () => {
const withdrawAmount = ethers.utils.parseEther("1"); const withdrawAmount = ethers.utils.parseEther("1");
const upperHint = ethers.constants.AddressZero; const upperHint = ethers.constants.AddressZero;
const lowerHint = ethers.constants.AddressZero; const lowerHint = ethers.constants.AddressZero;
const setId = 0;
const withdrawEthSpell = { const withdrawEthSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "withdraw", method: "withdraw",
args: [withdrawAmount, upperHint, lowerHint, setId], args: [withdrawAmount, upperHint, lowerHint, 0, 0],
}; };
const withdrawTx = await dsa const withdrawTx = await dsa
@ -830,11 +836,11 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256"],
[userWallet.address, withdrawAmount, setId] [dsa.address, withdrawAmount, 0, 0]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogWithdraw(address,uint256,uint256)" "LogWithdraw(address,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -856,7 +862,7 @@ describe("Liquity", () => {
const borrowSpell = { const borrowSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "borrow", method: "borrow",
args: [maxFeePercentage, borrowAmount, upperHint, lowerHint, 0], args: [maxFeePercentage, borrowAmount, upperHint, lowerHint, 0, 0],
}; };
// Borrow more LUSD from the Trove // Borrow more LUSD from the Trove
@ -896,6 +902,7 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0,
borrowId, borrowId,
], ],
}; };
@ -944,11 +951,10 @@ describe("Liquity", () => {
const upperHint = ethers.constants.AddressZero; const upperHint = ethers.constants.AddressZero;
const lowerHint = ethers.constants.AddressZero; const lowerHint = ethers.constants.AddressZero;
const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee
const setId = 0;
const borrowSpell = { const borrowSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "borrow", method: "borrow",
args: [maxFeePercentage, borrowAmount, upperHint, lowerHint, setId], args: [maxFeePercentage, borrowAmount, upperHint, lowerHint, 0, 0],
}; };
const borrowTx = await dsa const borrowTx = await dsa
@ -959,11 +965,11 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256"],
[userWallet.address, borrowAmount, setId] [dsa.address, borrowAmount, 0, 0]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogBorrow(address,uint256,uint256)" "LogBorrow(address,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -997,7 +1003,7 @@ describe("Liquity", () => {
const repaySpell = { const repaySpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "repay", method: "repay",
args: [repayAmount, upperHint, lowerHint, 0], args: [repayAmount, upperHint, lowerHint, 0, 0],
}; };
await dsa await dsa
@ -1061,7 +1067,7 @@ describe("Liquity", () => {
const borrowSpell = { const borrowSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "repay", method: "repay",
args: [0, upperHint, lowerHint, lusdDepositId], args: [0, upperHint, lowerHint, lusdDepositId, 0],
}; };
const spells = [depositSpell, borrowSpell]; const spells = [depositSpell, borrowSpell];
@ -1099,12 +1105,11 @@ describe("Liquity", () => {
borrowAmount, borrowAmount,
liquity liquity
); );
const getId = 0;
const borrowSpell = { const borrowSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "repay", method: "repay",
args: [repayAmount, upperHint, lowerHint, getId], args: [repayAmount, upperHint, lowerHint, 0, 0],
}; };
const repayTx = await dsa const repayTx = await dsa
@ -1117,11 +1122,11 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256"],
[userWallet.address, repayAmount, getId] [dsa.address, repayAmount, 0, 0]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogRepay(address,uint256,uint256)" "LogRepay(address,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -1151,16 +1156,14 @@ describe("Liquity", () => {
method: "adjust", method: "adjust",
args: [ args: [
maxFeePercentage, maxFeePercentage,
withdrawAmount,
depositAmount, depositAmount,
withdrawAmount,
borrowAmount, borrowAmount,
repayAmount, repayAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0, 0, 0],
0, [0, 0, 0, 0],
0,
0,
], ],
}; };
@ -1218,16 +1221,14 @@ describe("Liquity", () => {
method: "adjust", method: "adjust",
args: [ args: [
maxFeePercentage, maxFeePercentage,
withdrawAmount,
depositAmount, depositAmount,
withdrawAmount,
borrowAmount, borrowAmount,
repayAmount, repayAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0, 0, 0],
0, [0, 0, 0, 0],
0,
0,
], ],
}; };
@ -1297,16 +1298,14 @@ describe("Liquity", () => {
method: "adjust", method: "adjust",
args: [ args: [
maxFeePercentage, maxFeePercentage,
withdrawAmount,
0, // Deposit amount comes from a previous spell's storage slot 0, // Deposit amount comes from a previous spell's storage slot
withdrawAmount,
borrowAmount, borrowAmount,
0, // Repay amount comes from a previous spell's storage slot 0, // Repay amount comes from a previous spell's storage slot
upperHint, upperHint,
lowerHint, lowerHint,
ethDepositId, [ethDepositId, 0, 0, 0],
0, [0, 0, 0, 0],
lusdRepayId,
0,
], ],
}; };
const spells = [depositEthSpell, depositLusdSpell, adjustSpell]; const spells = [depositEthSpell, depositLusdSpell, adjustSpell];
@ -1379,16 +1378,14 @@ describe("Liquity", () => {
method: "adjust", method: "adjust",
args: [ args: [
maxFeePercentage, maxFeePercentage,
withdrawAmount,
depositAmount, depositAmount,
withdrawAmount,
borrowAmount, borrowAmount,
repayAmount, repayAmount,
upperHint, upperHint,
lowerHint, lowerHint,
0, [0, 0, 0, 0],
ethWithdrawId, [0, ethWithdrawId, lusdBorrowId, 0],
0,
lusdBorrowId,
], ],
}; };
@ -1432,7 +1429,6 @@ describe("Liquity", () => {
const userLusdBalanceAfter = await liquity.lusdToken.balanceOf( const userLusdBalanceAfter = await liquity.lusdToken.balanceOf(
userWallet.address userWallet.address
); );
expect(userEthBalanceAfter).eq( expect(userEthBalanceAfter).eq(
userEthBalanceBefore.add(withdrawAmount) userEthBalanceBefore.add(withdrawAmount)
); );
@ -1452,26 +1448,20 @@ describe("Liquity", () => {
const upperHint = ethers.constants.AddressZero; const upperHint = ethers.constants.AddressZero;
const lowerHint = ethers.constants.AddressZero; const lowerHint = ethers.constants.AddressZero;
const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee const maxFeePercentage = ethers.utils.parseUnits("0.5", 18); // 0.5% max fee
const getDepositId = 0;
const setWithdrawId = 0;
const getRepayId = 0;
const setBorrowId = 0;
const adjustSpell = { const adjustSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "adjust", method: "adjust",
args: [ args: [
maxFeePercentage, maxFeePercentage,
withdrawAmount,
depositAmount, depositAmount,
withdrawAmount,
borrowAmount, borrowAmount,
repayAmount, repayAmount,
upperHint, upperHint,
lowerHint, lowerHint,
getDepositId, [0, 0, 0, 0],
setWithdrawId, [0, 0, 0, 0],
getRepayId,
setBorrowId,
], ],
}; };
@ -1493,26 +1483,22 @@ describe("Liquity", () => {
"uint256", "uint256",
"uint256", "uint256",
"uint256", "uint256",
"uint256", "uint256[]",
"uint256", "uint256[]",
"uint256",
"uint256",
], ],
[ [
userWallet.address, dsa.address,
maxFeePercentage, maxFeePercentage,
depositAmount, depositAmount,
withdrawAmount, withdrawAmount,
borrowAmount, borrowAmount,
repayAmount, repayAmount,
getDepositId, [0, 0, 0, 0],
setWithdrawId, [0, 0, 0, 0],
getRepayId,
setBorrowId,
] ]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)" "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -1652,7 +1638,7 @@ describe("Liquity", () => {
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256"], ["address", "uint256", "uint256"],
[userWallet.address, claimAmount, setId] [dsa.address, claimAmount, setId]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogClaimCollateralFromRedemption(address,uint256,uint256)" "LogClaimCollateralFromRedemption(address,uint256,uint256)"
@ -1678,7 +1664,7 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -1711,7 +1697,7 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [0, frontendTag, lusdDepositId, 0, 0], args: [0, frontendTag, lusdDepositId, 0, 0, 0],
}; };
const spells = [depositLusdSpell, stabilityDepositSpell]; const spells = [depositLusdSpell, stabilityDepositSpell];
@ -1735,6 +1721,7 @@ describe("Liquity", () => {
const halfAmount = amount.div(2); const halfAmount = amount.div(2);
const frontendTag = ethers.constants.AddressZero; const frontendTag = ethers.constants.AddressZero;
const getDepositId = 0; const getDepositId = 0;
const setDepositId = 0;
const setEthGainId = 0; const setEthGainId = 0;
const setLqtyGainId = 0; const setLqtyGainId = 0;
@ -1748,7 +1735,14 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [halfAmount, frontendTag, getDepositId, 0, 0], args: [
halfAmount,
frontendTag,
getDepositId,
setDepositId,
setEthGainId,
setLqtyGainId,
],
}; };
// Create a Stability deposit for this DSA // Create a Stability deposit for this DSA
@ -1803,20 +1797,22 @@ describe("Liquity", () => {
"uint256", "uint256",
"uint256", "uint256",
"uint256", "uint256",
"uint256",
], ],
[ [
userWallet.address, dsa.address,
halfAmount, halfAmount,
ethGain, ethGain,
lqtyGain, lqtyGain,
frontendTag, frontendTag,
getDepositId, getDepositId,
setDepositId,
setEthGainId, setEthGainId,
setLqtyGainId, setLqtyGainId,
] ]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogStabilityDeposit(address,uint256,uint256,uint256,address,uint256,uint256,uint256)" "LogStabilityDeposit(address,uint256,uint256,uint256,address,uint256,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -1849,14 +1845,14 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
// Withdraw half of the deposit // Withdraw half of the deposit
const stabilityWithdrawSpell = { const stabilityWithdrawSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityWithdraw", method: "stabilityWithdraw",
args: [amount.div(2), 0, 0, 0], args: [amount.div(2), 0, 0, 0, 0],
}; };
const spells = [stabilityDepositSpell, stabilityWithdrawSpell]; const spells = [stabilityDepositSpell, stabilityWithdrawSpell];
@ -1899,14 +1895,14 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
// Withdraw half of the deposit // Withdraw half of the deposit
const stabilityWithdrawSpell = { const stabilityWithdrawSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityWithdraw", method: "stabilityWithdraw",
args: [amount.div(2), 0, 0, withdrawId], args: [amount.div(2), 0, 0, 0, withdrawId],
}; };
const withdrawLusdSpell = { const withdrawLusdSpell = {
@ -1962,11 +1958,12 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
// Withdraw half of the deposit // Withdraw half of the deposit
const withdrawAmount = amount.div(2); const withdrawAmount = amount.div(2);
const getWithdrawId = 0;
const setWithdrawId = 0; const setWithdrawId = 0;
const setEthGainId = 0; const setEthGainId = 0;
const setLqtyGainId = 0; const setLqtyGainId = 0;
@ -2009,7 +2006,13 @@ describe("Liquity", () => {
const stabilityWithdrawSpell = { const stabilityWithdrawSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityWithdraw", method: "stabilityWithdraw",
args: [withdrawAmount, setWithdrawId, setEthGainId, setLqtyGainId], args: [
withdrawAmount,
getWithdrawId,
setWithdrawId,
setEthGainId,
setLqtyGainId,
],
}; };
const withdrawTx = await dsa const withdrawTx = await dsa
@ -2031,19 +2034,21 @@ describe("Liquity", () => {
"uint256", "uint256",
"uint256", "uint256",
"uint256", "uint256",
"uint256",
], ],
[ [
userWallet.address, dsa.address,
withdrawAmount, withdrawAmount,
ethGain, ethGain,
lqtyGain, lqtyGain,
getWithdrawId,
setWithdrawId, setWithdrawId,
setEthGainId, setEthGainId,
setLqtyGainId, setLqtyGainId,
] ]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogStabilityWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256)" "LogStabilityWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -2072,7 +2077,7 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2125,7 +2130,7 @@ describe("Liquity", () => {
const stabilityDepositSpell = { const stabilityDepositSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stabilityDeposit", method: "stabilityDeposit",
args: [amount, frontendTag, 0, 0, 0], args: [amount, frontendTag, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2160,7 +2165,7 @@ describe("Liquity", () => {
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256"], ["address", "uint256"],
[userWallet.address, ethGainFromLiquidation] [dsa.address, ethGainFromLiquidation]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogStabilityMoveEthGainToTrove(address,uint256)" "LogStabilityMoveEthGainToTrove(address,uint256)"
@ -2188,7 +2193,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2228,7 +2233,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [0, lqtyDepositId, lqtyDepositId, 0], args: [0, lqtyDepositId, 0, 0, 0],
}; };
const spells = [depositSpell, stakeSpell]; const spells = [depositSpell, stakeSpell];
@ -2262,12 +2267,13 @@ describe("Liquity", () => {
); );
const getStakeId = 0; const getStakeId = 0;
const setStakeId = 0;
const setEthGainId = 0; const setEthGainId = 0;
const setLusdGainId = 0; const setLusdGainId = 0;
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, getStakeId, setEthGainId, setLusdGainId], args: [amount, getStakeId, setStakeId, setEthGainId, setLusdGainId],
}; };
const stakeTx = await dsa const stakeTx = await dsa
@ -2279,17 +2285,18 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256", "uint256", "uint256"],
[ [
userWallet.address, dsa.address,
amount, amount,
getStakeId, getStakeId,
setStakeId,
setEthGainId, setEthGainId,
setLusdGainId, setLusdGainId,
] ]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogStake(address,uint256,uint256,uint256,uint256)" "LogStake(address,uint256,uint256,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
@ -2308,7 +2315,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2321,7 +2328,7 @@ describe("Liquity", () => {
const unstakeSpell = { const unstakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "unstake", method: "unstake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2351,7 +2358,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await dsa await dsa
@ -2365,7 +2372,7 @@ describe("Liquity", () => {
const unstakeSpell = { const unstakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "unstake", method: "unstake",
args: [amount, withdrawId, 0, 0], args: [amount, 0, withdrawId, 0, 0],
}; };
const withdrawLqtySpell = { const withdrawLqtySpell = {
@ -2410,20 +2417,27 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await dsa await dsa
.connect(userWallet) .connect(userWallet)
.cast(...encodeSpells([stakeSpell]), userWallet.address); .cast(...encodeSpells([stakeSpell]), userWallet.address);
const getUnstakeId = 0;
const setUnstakeId = 0; const setUnstakeId = 0;
const setEthGainId = 0; const setEthGainId = 0;
const setLusdGainId = 0; const setLusdGainId = 0;
const unstakeSpell = { const unstakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "unstake", method: "unstake",
args: [amount, setUnstakeId, setEthGainId, setLusdGainId], args: [
amount,
getUnstakeId,
setUnstakeId,
setEthGainId,
setLusdGainId,
],
}; };
const unstakeTx = await dsa const unstakeTx = await dsa
@ -2435,24 +2449,25 @@ describe("Liquity", () => {
const castLogEvent = receipt.events.find((e) => e.event === "LogCast") const castLogEvent = receipt.events.find((e) => e.event === "LogCast")
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256", "uint256", "uint256"],
[ [
userWallet.address, dsa.address,
amount, amount,
getUnstakeId,
setUnstakeId, setUnstakeId,
setEthGainId, setEthGainId,
setLusdGainId, setLusdGainId,
] ]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogUnstake(address,uint256,uint256,uint256,uint256)" "LogUnstake(address,uint256,uint256,uint256,uint256,uint256)"
); );
expect(castLogEvent.eventParams[0]).eq(expectedEventParams); expect(castLogEvent.eventParams[0]).eq(expectedEventParams);
}); });
}); });
describe("claimStakingGains()", () => { describe("claimStakingGains()", () => {
it("Claims gains from staking", async () => { it("claims gains from staking", async () => {
const stakerDsa = await buildDSAv2(userWallet.address); const stakerDsa = await buildDSAv2(userWallet.address);
const amount = ethers.utils.parseUnits("1000", 18); // 1000 LQTY const amount = ethers.utils.parseUnits("1000", 18); // 1000 LQTY
@ -2466,7 +2481,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await stakerDsa await stakerDsa
.connect(userWallet) .connect(userWallet)
@ -2520,7 +2535,7 @@ describe("Liquity", () => {
expect(lusdBalanceAfter).to.eq(lusdGain); expect(lusdBalanceAfter).to.eq(lusdGain);
}); });
it("Claims gains from staking and stores them for other spells", async () => { it("claims gains from staking and stores them for other spells", async () => {
const stakerDsa = await buildDSAv2(userWallet.address); const stakerDsa = await buildDSAv2(userWallet.address);
const amount = ethers.utils.parseUnits("1000", 18); // 1000 LQTY const amount = ethers.utils.parseUnits("1000", 18); // 1000 LQTY
@ -2534,7 +2549,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await stakerDsa await stakerDsa
.connect(userWallet) .connect(userWallet)
@ -2634,7 +2649,7 @@ describe("Liquity", () => {
const stakeSpell = { const stakeSpell = {
connector: helpers.LIQUITY_CONNECTOR, connector: helpers.LIQUITY_CONNECTOR,
method: "stake", method: "stake",
args: [amount, 0, 0, 0], args: [amount, 0, 0, 0, 0],
}; };
await stakerDsa await stakerDsa
.connect(userWallet) .connect(userWallet)
@ -2680,7 +2695,7 @@ describe("Liquity", () => {
.args; .args;
const expectedEventParams = ethers.utils.defaultAbiCoder.encode( const expectedEventParams = ethers.utils.defaultAbiCoder.encode(
["address", "uint256", "uint256", "uint256", "uint256"], ["address", "uint256", "uint256", "uint256", "uint256"],
[userWallet.address, ethGain, lusdGain, setEthGainId, setLusdGainId] [stakerDsa.address, ethGain, lusdGain, setEthGainId, setLusdGainId]
); );
expect(castLogEvent.eventNames[0]).eq( expect(castLogEvent.eventNames[0]).eq(
"LogClaimStakingGains(address,uint256,uint256,uint256,uint256)" "LogClaimStakingGains(address,uint256,uint256,uint256,uint256)"