withdraw and borrow update

This commit is contained in:
Richa-iitr 2022-09-02 23:13:39 +05:30
parent 91bb5ea57c
commit b88d9d887a
3 changed files with 107 additions and 7 deletions

View File

@ -47,6 +47,15 @@ contract Events {
); );
event LogWithdrawOnBehalf( event LogWithdrawOnBehalf(
address indexed market,
address indexed token,
address from,
uint256 tokenAmt,
uint256 getId,
uint256 setId
);
event LogWithdrawOnBehalfAndTransfer(
address indexed market, address indexed market,
address indexed token, address indexed token,
address from, address from,
@ -72,6 +81,14 @@ contract Events {
); );
event LogBorrowOnBehalf( event LogBorrowOnBehalf(
address indexed market,
address from,
uint256 tokenAmt,
uint256 getId,
uint256 setId
);
event LogBorrowOnBehalfAndTransfer(
address indexed market, address indexed market,
address from, address from,
address to, address to,
@ -127,7 +144,11 @@ contract Events {
uint256 setId uint256 setId
); );
event LogToggleAccountManager(address indexed market, address indexed manager, bool allow); event LogToggleAccountManager(
address indexed market,
address indexed manager,
bool allow
);
event LogToggleAccountManagerWithPermit( event LogToggleAccountManagerWithPermit(
address indexed market, address indexed market,

View File

@ -293,6 +293,44 @@ abstract contract CompoundV3Resolver is Events, Helpers {
eventParam_ = abi.encode(market, token, to, amt_, getId, setId_); eventParam_ = abi.encode(market, token, to, amt_, getId, setId_);
} }
/**
* @dev Withdraw base/collateral asset from an account and transfer to DSA.
* @notice Withdraw base token or deposited token from Compound from an address and transfer to DSA.
* @param market The address of the market.
* @param token The address of the token to be withdrawn. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param from The address from where asset is to be withdrawed.
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens withdrawn.
*/
function withdrawOnBehalf(
address market,
address token,
address from,
uint256 amt,
uint256 getId,
uint256 setId
)
public
payable
returns (string memory eventName_, bytes memory eventParam_)
{
(uint256 amt_, uint256 setId_) = _withdraw(
BorrowWithdrawParams({
market: market,
token: token,
from: from,
to: address(this),
amt: amt,
getId: getId,
setId: setId
})
);
eventName_ = "LogWithdrawOnBehalf(address,address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, token, from, amt_, getId, setId_);
}
/** /**
* @dev Withdraw base/collateral asset from an account and transfer to 'to'. * @dev Withdraw base/collateral asset from an account and transfer to 'to'.
* @notice Withdraw base token or deposited token from Compound from an address and transfer to 'to'. * @notice Withdraw base token or deposited token from Compound from an address and transfer to 'to'.
@ -304,7 +342,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens withdrawn. * @param setId ID stores the amount of tokens withdrawn.
*/ */
function withdrawOnBehalf( function withdrawOnBehalfAndTransfer(
address market, address market,
address token, address token,
address from, address from,
@ -436,11 +474,52 @@ abstract contract CompoundV3Resolver is Events, Helpers {
* @param token The address of the token to be borrowed. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to be borrowed. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`) * @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
* @param from The address from where asset is to be withdrawed. * @param from The address from where asset is to be withdrawed.
* @param to The address to which the borrowed assets are to be transferred.
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens borrowed. * @param setId ID stores the amount of tokens borrowed.
*/ */
function borrowOnBehalf( function borrowOnBehalf(
address market,
address token,
address from,
uint256 amt,
uint256 getId,
uint256 setId
)
external
payable
returns (string memory eventName_, bytes memory eventParam_)
{
require(
token == ethAddr || token == getBaseToken(market),
"invalid-token"
);
(uint256 amt_, uint256 setId_) = _borrow(
BorrowWithdrawParams({
market: market,
token: token,
from: from,
to: address(this),
amt: amt,
getId: getId,
setId: setId
})
);
eventName_ = "LogBorrowOnBehalf(address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, from, amt_, getId, setId_);
}
/**
* @dev Borrow base asset from 'from' and transfer to 'to'.
* @notice Borrow base token or deposited token from Compound.
* @param market The address of the market.
* @param token The address of the token to be borrowed. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
* @param from The address from where asset is to be withdrawed.
* @param to The address to which the borrowed assets are to be transferred.
* @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens borrowed.
*/
function borrowOnBehalfAndTransfer(
address market, address market,
address token, address token,
address from, address from,
@ -468,7 +547,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
setId: setId setId: setId
}) })
); );
eventName_ = "LogBorrowOnBehalf(address,address,address,uint256,uint256,uint256)"; eventName_ = "LogBorrowOnBehalfAndTransfer(address,address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, from, to, amt_, getId, setId_); eventParam_ = abi.encode(market, from, to, amt_, getId, setId_);
} }

View File

@ -390,7 +390,7 @@ describe("Compound III", function () {
expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(initialBal.add(amount_).toString()); expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.gte(initialBal.add(amount_).toString());
}); });
it("manager should be able to withdraw collateral from the position", async function () { it("manager should be able to withdraw collateral from the position and transfer", async function () {
await wallet1.sendTransaction({ await wallet1.sendTransaction({
to: tokens.weth.address, to: tokens.weth.address,
value: ethers.utils.parseEther("10") value: ethers.utils.parseEther("10")
@ -399,7 +399,7 @@ describe("Compound III", function () {
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "withdrawOnBehalf", method: "withdrawOnBehalfAndTransfer",
args: [market, tokens.eth.address, dsaWallet0.address, dsaWallet1.address, amount, 0, 0] args: [market, tokens.eth.address, dsaWallet0.address, dsaWallet1.address, amount, 0, 0]
} }
]; ];
@ -607,7 +607,7 @@ describe("Compound III", function () {
const spells = [ const spells = [
{ {
connector: connectorName, connector: connectorName,
method: "borrowOnBehalf", method: "borrowOnBehalfAndTransfer",
args: [market, base, dsaWallet3.address, dsaWallet0.address, amount, 0, 0] args: [market, base, dsaWallet3.address, dsaWallet0.address, amount, 0, 0]
} }
]; ];