Merge pull request #3 from liquity/liquity-updates

Fix tests after Instadapp team changes
This commit is contained in:
Edward Mulraney 2021-06-30 17:30:30 +01:00 committed by GitHub
commit 6ce7fca82f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 317 additions and 239 deletions

View File

@ -8,14 +8,14 @@ contract Events {
uint maxFeePercentage, uint maxFeePercentage,
uint depositAmount, uint depositAmount,
uint borrowAmount, uint borrowAmount,
uint getId, uint256[] getIds,
uint setId 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); event LogDeposit(address indexed borrower, uint amount, uint getId, uint setId);
event LogWithdraw(address indexed borrower, uint amount, uint setId); event LogWithdraw(address indexed borrower, uint amount, uint getId, uint setId);
event LogBorrow(address indexed borrower, uint amount, uint setId); event LogBorrow(address indexed borrower, uint amount, uint getId, uint setId);
event LogRepay(address indexed borrower, uint amount, uint getId); event LogRepay(address indexed borrower, uint amount, uint getId, uint setId);
event LogAdjust( event LogAdjust(
address indexed borrower, address indexed borrower,
uint maxFeePercentage, uint maxFeePercentage,
@ -23,10 +23,8 @@ contract Events {
uint withdrawAmount, uint withdrawAmount,
uint borrowAmount, uint borrowAmount,
uint repayAmount, uint repayAmount,
uint getDepositId, uint256[] getIds,
uint setWithdrawId, uint256[] setIds
uint getRepayId,
uint setBorrowId
); );
event LogClaimCollateralFromRedemption(address indexed borrower, uint amount, uint setId); event LogClaimCollateralFromRedemption(address indexed borrower, uint amount, uint setId);
@ -38,6 +36,7 @@ contract Events {
uint lqtyGain, uint lqtyGain,
address frontendTag, address frontendTag,
uint getDepositId, uint getDepositId,
uint setDepositId,
uint setEthGainId, uint setEthGainId,
uint setLqtyGainId uint setLqtyGainId
); );
@ -45,6 +44,7 @@ contract Events {
uint amount, uint amount,
uint ethGain, uint ethGain,
uint lqtyGain, uint lqtyGain,
uint getWithdrawId,
uint setWithdrawId, uint setWithdrawId,
uint setEthGainId, uint setEthGainId,
uint setLqtyGainId uint setLqtyGainId
@ -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 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 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

@ -3,4 +3,35 @@ pragma solidity ^0.7.6;
import { DSMath } from "../../common/math.sol"; import { DSMath } from "../../common/math.sol";
import { Basic } from "../../common/basic.sol"; import { Basic } from "../../common/basic.sol";
abstract contract Helpers is DSMath, Basic {} import { TokenInterface } from "../../common/interfaces.sol";
import {
BorrowerOperationsLike,
TroveManagerLike,
StabilityPoolLike,
StakingLike,
CollateralSurplusLike,
LqtyTokenLike
} from "./interface.sol";
abstract contract Helpers is DSMath, Basic {
BorrowerOperationsLike internal constant borrowerOperations = BorrowerOperationsLike(0x24179CD81c9e782A4096035f7eC97fB8B783e007);
TroveManagerLike internal constant troveManager = TroveManagerLike(0xA39739EF8b0231DbFA0DcdA07d7e29faAbCf4bb2);
StabilityPoolLike internal constant stabilityPool = StabilityPoolLike(0x66017D22b0f8556afDd19FC67041899Eb65a21bb);
StakingLike internal constant staking = StakingLike(0x4f9Fbb3f1E99B56e0Fe2892e623Ed36A76Fc605d);
CollateralSurplusLike internal constant collateralSurplus = CollateralSurplusLike(0x3D32e8b97Ed5881324241Cf03b2DA5E2EBcE5521);
LqtyTokenLike internal constant lqtyToken = LqtyTokenLike(0x6DEA81C8171D0bA574754EF6F8b412F2Ed88c54D);
TokenInterface internal constant lusdToken = TokenInterface(0x5f98805A4E8be255a32880FDeC7F6728C6568bA0);
// Prevents stack-too-deep error
struct AdjustTrove {
uint maxFeePercentage;
uint withdrawAmount;
uint depositAmount;
uint borrowAmount;
uint repayAmount;
bool isBorrow;
}
}

View File

@ -54,6 +54,7 @@ interface StabilityPoolLike {
function withdrawETHGainToTrove(address _upperHint, address _lowerHint) external; function withdrawETHGainToTrove(address _upperHint, address _lowerHint) external;
function getDepositorETHGain(address _depositor) external view returns (uint); function getDepositorETHGain(address _depositor) external view returns (uint);
function getDepositorLQTYGain(address _depositor) external view returns (uint); function getDepositorLQTYGain(address _depositor) external view returns (uint);
function getCompoundedLUSDDeposit(address _depositor) external view returns (uint);
} }
interface StakingLike { interface StakingLike {
@ -61,6 +62,7 @@ interface StakingLike {
function unstake(uint _LQTYamount) external; function unstake(uint _LQTYamount) external;
function getPendingETHGain(address _user) external view returns (uint); function getPendingETHGain(address _user) external view returns (uint);
function getPendingLUSDGain(address _user) external view returns (uint); function getPendingLUSDGain(address _user) external view returns (uint);
function stakes(address owner) external view returns (uint);
} }
interface CollateralSurplusLike { interface CollateralSurplusLike {

View File

@ -17,28 +17,7 @@ import { Helpers } from "./helpers.sol";
import { Events } from "./events.sol"; import { Events } from "./events.sol";
abstract contract LiquityResolver is Events, Helpers { abstract contract LiquityResolver is Events, Helpers {
BorrowerOperationsLike internal constant borrowerOperations =
BorrowerOperationsLike(0x24179CD81c9e782A4096035f7eC97fB8B783e007);
TroveManagerLike internal constant troveManager =
TroveManagerLike(0xA39739EF8b0231DbFA0DcdA07d7e29faAbCf4bb2);
StabilityPoolLike internal constant stabilityPool =
StabilityPoolLike(0x66017D22b0f8556afDd19FC67041899Eb65a21bb);
StakingLike internal constant staking =
StakingLike(0x4f9Fbb3f1E99B56e0Fe2892e623Ed36A76Fc605d);
CollateralSurplusLike internal constant collateralSurplus =
CollateralSurplusLike(0x3D32e8b97Ed5881324241Cf03b2DA5E2EBcE5521);
LqtyTokenLike internal constant lqtyToken =
LqtyTokenLike(0x6DEA81C8171D0bA574754EF6F8b412F2Ed88c54D);
// Prevents stack-too-deep error
struct AdjustTrove {
uint maxFeePercentage;
uint withdrawAmount;
uint depositAmount;
uint borrowAmount;
uint repayAmount;
bool isBorrow;
}
/* Begin: Trove */ /* Begin: Trove */
@ -50,8 +29,8 @@ abstract contract LiquityResolver is Events, Helpers {
* @param borrowAmount The amount of LUSD to borrow * @param borrowAmount The 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 getId Optional storage slot to retrieve ETH from * @param getIds Optional (default: 0) Optional storage slot to get deposit & borrow amounts stored using other spells
* @param setId Optional storage slot to store the LUSD borrowed against * @param setIds Optional (default: 0) Optional storage slot to set deposit & borrow amounts to be used in future spells
*/ */
function open( function open(
uint depositAmount, uint depositAmount,
@ -59,14 +38,14 @@ abstract contract LiquityResolver is Events, Helpers {
uint borrowAmount, uint borrowAmount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getId, uint[] memory getIds,
uint setId uint[] memory setIds
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
if (getId != 0 && depositAmount != 0) {
revert("open(): Cannot supply a depositAmount if a non-zero getId is supplied");
}
depositAmount = getUint(getId, depositAmount); depositAmount = getUint(getIds[0], depositAmount);
borrowAmount = getUint(getIds[1], borrowAmount);
depositAmount = depositAmount == uint(-1) ? address(this).balance : depositAmount;
borrowerOperations.openTrove{value: depositAmount}( borrowerOperations.openTrove{value: depositAmount}(
maxFeePercentage, maxFeePercentage,
@ -75,10 +54,11 @@ abstract contract LiquityResolver is Events, Helpers {
lowerHint lowerHint
); );
// Allow other spells to use the borrowed amount setUint(setIds[0], depositAmount);
setUint(setId, borrowAmount); setUint(setIds[1], borrowAmount);
_eventName = "LogOpen(address,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, maxFeePercentage, depositAmount, borrowAmount, getId, setId); _eventName = "LogOpen(address,uint256,uint256,uint256,uint256[],uint256[])";
_eventParam = abi.encode(address(this), maxFeePercentage, depositAmount, borrowAmount, getIds, setIds);
} }
/** /**
@ -86,14 +66,14 @@ abstract contract LiquityResolver is Events, Helpers {
* @notice Closes a Trove by repaying LUSD debt * @notice Closes a Trove by repaying LUSD debt
* @param setId Optional storage slot to store the ETH withdrawn from the Trove * @param setId Optional storage slot to store the ETH withdrawn from the Trove
*/ */
function close(uint setId) external returns (string memory _eventName, bytes memory _eventParam) { function close(uint setId) external payable returns (string memory _eventName, bytes memory _eventParam) {
uint collateral = troveManager.getTroveColl(address(this)); uint collateral = troveManager.getTroveColl(address(this));
borrowerOperations.closeTrove(); borrowerOperations.closeTrove();
// Allow other spells to use the collateral released from the Trove // Allow other spells to use the collateral released from the Trove
setUint(setId, collateral); setUint(setId, collateral);
_eventName = "LogClose(address,uint256)"; _eventName = "LogClose(address,uint256)";
_eventParam = abi.encode(msg.sender, setId); _eventParam = abi.encode(address(this), setId);
} }
/** /**
@ -103,20 +83,26 @@ abstract contract LiquityResolver is Events, Helpers {
* @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 ETH from * @param getId Optional storage slot to retrieve the ETH from
* @param setId Optional storage slot to set the ETH deposited
*/ */
function deposit( function deposit(
uint amount, uint amount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getId uint getId,
uint setId
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
if (getId != 0 && amount != 0) {
revert("deposit(): Cannot supply an amount if a non-zero getId is supplied"); uint _amount = getUint(getId, amount);
}
amount = getUint(getId, amount); _amount = _amount == uint(-1) ? address(this).balance : _amount;
borrowerOperations.addColl{value: amount}(upperHint, lowerHint);
_eventName = "LogDeposit(address,uint256,uint256)"; borrowerOperations.addColl{value: _amount}(upperHint, lowerHint);
_eventParam = abi.encode(msg.sender, amount, getId);
setUint(setId, _amount);
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
_eventParam = abi.encode(address(this), _amount, getId, setId);
} }
/** /**
@ -125,19 +111,25 @@ abstract contract LiquityResolver is Events, Helpers {
* @param amount Amount of ETH to move from Trove to DSA * @param amount Amount of ETH to move from Trove to DSA
* @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 get the amount of ETH to withdraw
* @param setId Optional storage slot to store the withdrawn ETH in * @param setId Optional storage slot to store the withdrawn ETH in
*/ */
function withdraw( function withdraw(
uint amount, uint amount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getId,
uint setId uint setId
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
borrowerOperations.withdrawColl(amount, upperHint, lowerHint); uint _amount = getUint(getId, amount);
setUint(setId, amount); _amount = _amount == uint(-1) ? troveManager.getTroveColl(address(this)) : _amount;
_eventName = "LogWithdraw(address,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, setId); borrowerOperations.withdrawColl(_amount, upperHint, lowerHint);
setUint(setId, _amount);
_eventName = "LogWithdraw(address,uint256,uint256,uint256)";
_eventParam = abi.encode(address(this), _amount, getId, setId);
} }
/** /**
@ -147,20 +139,25 @@ 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,
uint amount, uint amount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getId,
uint setId uint setId
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
borrowerOperations.withdrawLUSD(maxFeePercentage, amount, upperHint, lowerHint); uint _amount = getUint(getId, amount);
setUint(setId, amount); borrowerOperations.withdrawLUSD(maxFeePercentage, _amount, upperHint, lowerHint);
_eventName = "LogBorrow(address,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, setId); setUint(setId, _amount);
_eventName = "LogBorrow(address,uint256,uint256,uint256)";
_eventParam = abi.encode(address(this), _amount, getId, setId);
} }
/** /**
@ -169,21 +166,30 @@ 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,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getId uint getId,
uint setId
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
if (getId != 0 && amount != 0) { uint _amount = getUint(getId, amount);
revert("repay(): Cannot supply an amount if a non-zero getId is supplied");
if (_amount == uint(-1)) {
uint _lusdBal = lusdToken.balanceOf(address(this));
uint _totalDebt = troveManager.getTroveDebt(address(this));
_amount = _lusdBal > _totalDebt ? _totalDebt : _lusdBal;
} }
amount = getUint(getId, amount);
borrowerOperations.repayLUSD(amount, upperHint, lowerHint); borrowerOperations.repayLUSD(_amount, upperHint, lowerHint);
_eventName = "LogRepay(address,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, getId); setUint(setId, _amount);
_eventName = "LogRepay(address,uint256,uint256,uint256)";
_eventParam = abi.encode(address(this), _amount, getId, setId);
} }
/** /**
@ -196,37 +202,40 @@ abstract contract LiquityResolver is Events, Helpers {
* @param repayAmount Amount of LUSD to repay * @param repayAmount 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 getDepositId Optional storage slot to retrieve the ETH to deposit * @param getIds Optional Get Ids for deposit, withdraw, borrow & repay
* @param setWithdrawId Optional storage slot to store the withdrawn ETH to * @param setIds Optional Set Ids for deposit, withdraw, borrow & repay
* @param getRepayId Optional storage slot to retrieve the LUSD to repay
* @param setBorrowId Optional storage slot to store the LUSD borrowed
*/ */
function adjust( function adjust(
uint maxFeePercentage, uint maxFeePercentage,
uint withdrawAmount,
uint depositAmount, uint depositAmount,
uint withdrawAmount,
uint borrowAmount, uint borrowAmount,
uint repayAmount, uint repayAmount,
address upperHint, address upperHint,
address lowerHint, address lowerHint,
uint getDepositId, uint[] memory getIds,
uint setWithdrawId, uint[] memory setIds
uint getRepayId,
uint setBorrowId
) external payable returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
if (getDepositId != 0 && depositAmount != 0) {
revert("adjust(): Cannot supply a depositAmount if a non-zero getDepositId is supplied");
}
if (getRepayId != 0 && repayAmount != 0) {
revert("adjust(): Cannot supply a repayAmount if a non-zero getRepayId is supplied");
}
AdjustTrove memory adjustTrove; AdjustTrove memory adjustTrove;
adjustTrove.maxFeePercentage = maxFeePercentage; adjustTrove.maxFeePercentage = maxFeePercentage;
adjustTrove.withdrawAmount = withdrawAmount;
adjustTrove.depositAmount = getUint(getDepositId, depositAmount); depositAmount = getUint(getIds[0], depositAmount);
adjustTrove.borrowAmount = borrowAmount; adjustTrove.depositAmount = depositAmount == uint(-1) ? address(this).balance : depositAmount;
adjustTrove.repayAmount = getUint(getRepayId, repayAmount);
withdrawAmount = getUint(getIds[1], withdrawAmount);
adjustTrove.withdrawAmount = withdrawAmount == uint(-1) ? troveManager.getTroveColl(address(this)) : withdrawAmount;
adjustTrove.borrowAmount = getUint(getIds[2], borrowAmount);
repayAmount = getUint(getIds[3], repayAmount);
if (repayAmount == uint(-1)) {
uint _lusdBal = lusdToken.balanceOf(address(this));
uint _totalDebt = troveManager.getTroveDebt(address(this));
repayAmount = _lusdBal > _totalDebt ? _totalDebt : _lusdBal;
}
adjustTrove.repayAmount = repayAmount;
adjustTrove.isBorrow = borrowAmount > 0; adjustTrove.isBorrow = borrowAmount > 0;
borrowerOperations.adjustTrove{value: adjustTrove.depositAmount}( borrowerOperations.adjustTrove{value: adjustTrove.depositAmount}(
@ -238,14 +247,13 @@ abstract contract LiquityResolver is Events, Helpers {
lowerHint lowerHint
); );
// Allow other spells to use the withdrawn collateral setUint(setIds[0], adjustTrove.depositAmount);
setUint(setWithdrawId, withdrawAmount); setUint(setIds[1], adjustTrove.withdrawAmount);
setUint(setIds[2], adjustTrove.borrowAmount);
setUint(setIds[3], adjustTrove.repayAmount);
// Allow other spells to use the borrowed amount _eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256[])";
setUint(setBorrowId, borrowAmount); _eventParam = abi.encode(address(this), maxFeePercentage, adjustTrove.depositAmount, adjustTrove.withdrawAmount, adjustTrove.borrowAmount, adjustTrove.repayAmount, getIds, setIds);
_eventName = "LogAdjust(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, maxFeePercentage, depositAmount, withdrawAmount, borrowAmount, repayAmount, getDepositId, setWithdrawId, getRepayId, setBorrowId);
} }
/** /**
@ -253,13 +261,13 @@ abstract contract LiquityResolver is Events, Helpers {
* @param setId Optional storage slot to store the ETH claimed * @param setId Optional storage slot to store the ETH claimed
* @notice Claim remaining collateral from Trove * @notice Claim remaining collateral from Trove
*/ */
function claimCollateralFromRedemption(uint setId) external returns(string memory _eventName, bytes memory _eventParam) { function claimCollateralFromRedemption(uint setId) external payable returns(string memory _eventName, bytes memory _eventParam) {
uint amount = collateralSurplus.getCollateral(address(this)); uint amount = collateralSurplus.getCollateral(address(this));
borrowerOperations.claimCollateral(); borrowerOperations.claimCollateral();
setUint(setId, amount); setUint(setId, amount);
_eventName = "LogClaimCollateralFromRedemption(address,uint256,uint256)"; _eventName = "LogClaimCollateralFromRedemption(address,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, setId); _eventParam = abi.encode(address(this), amount, setId);
} }
/* End: Trove */ /* End: Trove */
@ -270,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
*/ */
@ -278,11 +287,14 @@ abstract contract LiquityResolver is Events, Helpers {
uint amount, uint amount,
address frontendTag, address frontendTag,
uint getDepositId, uint getDepositId,
uint setDepositId,
uint setEthGainId, uint setEthGainId,
uint setLqtyGainId uint setLqtyGainId
) external returns (string memory _eventName, bytes memory _eventParam) { ) external payable returns (string memory _eventName, bytes memory _eventParam) {
amount = getUint(getDepositId, amount); amount = getUint(getDepositId, amount);
amount = amount == uint(-1) ? lusdToken.balanceOf(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));
@ -291,27 +303,34 @@ abstract contract LiquityResolver is Events, Helpers {
uint lqtyBalanceAfter = lqtyToken.balanceOf(address(this)); uint lqtyBalanceAfter = lqtyToken.balanceOf(address(this));
uint lqtyGain = sub(lqtyBalanceAfter, lqtyBalanceBefore); uint lqtyGain = sub(lqtyBalanceAfter, lqtyBalanceBefore);
setUint(setDepositId, amount);
setUint(setEthGainId, ethGain); setUint(setEthGainId, ethGain);
setUint(setLqtyGainId, lqtyGain); setUint(setLqtyGainId, lqtyGain);
_eventName = "LogStabilityDeposit(address,uint256,uint256,uint256,address,uint256,uint256,uint256)"; _eventName = "LogStabilityDeposit(address,uint256,uint256,uint256,address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, ethGain, lqtyGain, frontendTag, getDepositId, setEthGainId, setLqtyGainId); _eventParam = abi.encode(address(this), amount, ethGain, lqtyGain, frontendTag, getDepositId, setDepositId, setEthGainId, setLqtyGainId);
} }
/** /**
* @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
*/ */
function stabilityWithdraw( function stabilityWithdraw(
uint amount, uint amount,
uint getWithdrawId,
uint setWithdrawId, uint setWithdrawId,
uint setEthGainId, uint setEthGainId,
uint setLqtyGainId uint setLqtyGainId
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
amount = getUint(getWithdrawId, 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));
@ -324,8 +343,8 @@ abstract contract LiquityResolver is Events, Helpers {
setUint(setEthGainId, ethGain); setUint(setEthGainId, ethGain);
setUint(setLqtyGainId, lqtyGain); setUint(setLqtyGainId, lqtyGain);
_eventName = "LogStabilityWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256)"; _eventName = "LogStabilityWithdraw(address,uint256,uint256,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, ethGain, lqtyGain, setWithdrawId, setEthGainId, setLqtyGainId); _eventParam = abi.encode(address(this), amount, ethGain, lqtyGain, getWithdrawId, setWithdrawId, setEthGainId, setLqtyGainId);
} }
/** /**
@ -341,7 +360,7 @@ abstract contract LiquityResolver is Events, Helpers {
uint amount = stabilityPool.getDepositorETHGain(address(this)); uint amount = stabilityPool.getDepositorETHGain(address(this));
stabilityPool.withdrawETHGainToTrove(upperHint, lowerHint); stabilityPool.withdrawETHGainToTrove(upperHint, lowerHint);
_eventName = "LogStabilityMoveEthGainToTrove(address,uint256)"; _eventName = "LogStabilityMoveEthGainToTrove(address,uint256)";
_eventParam = abi.encode(msg.sender, amount); _eventParam = abi.encode(address(this), amount);
} }
/* End: Stability Pool */ /* End: Stability Pool */
@ -351,52 +370,62 @@ 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
*/ */
function stake( function stake(
uint amount, uint amount,
uint getStakeId, uint getStakeId,
uint setStakeId,
uint setEthGainId, uint setEthGainId,
uint setLusdGainId uint setLusdGainId
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
amount = getUint(getStakeId, amount);
amount = amount == uint(-1) ? lqtyToken.balanceOf(address(this)) : amount;
uint ethGain = staking.getPendingETHGain(address(this)); uint ethGain = staking.getPendingETHGain(address(this));
uint lusdGain = staking.getPendingLUSDGain(address(this)); uint lusdGain = staking.getPendingLUSDGain(address(this));
amount = getUint(getStakeId, amount);
staking.stake(amount); staking.stake(amount);
setUint(setStakeId, amount);
setUint(setEthGainId, ethGain); setUint(setEthGainId, ethGain);
setUint(setLusdGainId, lusdGain); setUint(setLusdGainId, lusdGain);
_eventName = "LogStake(address,uint256,uint256,uint256,uint256)"; _eventName = "LogStake(address,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, getStakeId, setEthGainId, setLusdGainId); _eventParam = abi.encode(address(this), amount, getStakeId, setStakeId, setEthGainId, setLusdGainId);
} }
/** /**
* @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
*/ */
function unstake( function unstake(
uint amount, uint amount,
uint setStakeId, uint getUnstakeId,
uint setUnstakeId,
uint setEthGainId, uint setEthGainId,
uint setLusdGainId uint setLusdGainId
) external returns (string memory _eventName, bytes memory _eventParam) { ) external returns (string memory _eventName, bytes memory _eventParam) {
amount = getUint(getUnstakeId, amount);
amount = amount == uint(-1) ? staking.stakes(address(this)) : amount;
uint ethGain = staking.getPendingETHGain(address(this)); uint ethGain = staking.getPendingETHGain(address(this));
uint lusdGain = staking.getPendingLUSDGain(address(this)); uint lusdGain = staking.getPendingLUSDGain(address(this));
staking.unstake(amount); staking.unstake(amount);
setUint(setStakeId, amount); setUint(setUnstakeId, amount);
setUint(setEthGainId, ethGain); setUint(setEthGainId, ethGain);
setUint(setLusdGainId, lusdGain); setUint(setLusdGainId, lusdGain);
_eventName = "LogUnstake(address,uint256,uint256,uint256,uint256)"; _eventName = "LogUnstake(address,uint256,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, amount, setStakeId, setEthGainId, setLusdGainId); _eventParam = abi.encode(address(this), amount, getUnstakeId, setUnstakeId, setEthGainId, setLusdGainId);
} }
/** /**
@ -418,7 +447,7 @@ abstract contract LiquityResolver is Events, Helpers {
setUint(setLusdGainId, lusdGain); setUint(setLusdGainId, lusdGain);
_eventName = "LogClaimStakingGains(address,uint256,uint256,uint256,uint256)"; _eventName = "LogClaimStakingGains(address,uint256,uint256,uint256,uint256)";
_eventParam = abi.encode(msg.sender, ethGain, lusdGain, setEthGainId, setLusdGainId); _eventParam = abi.encode(address(this), ethGain, lusdGain, setEthGainId, setLusdGainId);
} }
/* End: Staking */ /* End: Staking */

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)"