mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
withdraw and borrow update
This commit is contained in:
parent
91bb5ea57c
commit
b88d9d887a
|
@ -47,6 +47,15 @@ contract Events {
|
|||
);
|
||||
|
||||
event LogWithdrawOnBehalf(
|
||||
address indexed market,
|
||||
address indexed token,
|
||||
address from,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogWithdrawOnBehalfAndTransfer(
|
||||
address indexed market,
|
||||
address indexed token,
|
||||
address from,
|
||||
|
@ -72,6 +81,14 @@ contract Events {
|
|||
);
|
||||
|
||||
event LogBorrowOnBehalf(
|
||||
address indexed market,
|
||||
address from,
|
||||
uint256 tokenAmt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogBorrowOnBehalfAndTransfer(
|
||||
address indexed market,
|
||||
address from,
|
||||
address to,
|
||||
|
@ -127,7 +144,11 @@ contract Events {
|
|||
uint256 setId
|
||||
);
|
||||
|
||||
event LogToggleAccountManager(address indexed market, address indexed manager, bool allow);
|
||||
event LogToggleAccountManager(
|
||||
address indexed market,
|
||||
address indexed manager,
|
||||
bool allow
|
||||
);
|
||||
|
||||
event LogToggleAccountManagerWithPermit(
|
||||
address indexed market,
|
||||
|
|
|
@ -293,6 +293,44 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
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'.
|
||||
* @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 setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function withdrawOnBehalf(
|
||||
function withdrawOnBehalfAndTransfer(
|
||||
address market,
|
||||
address token,
|
||||
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 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 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 token,
|
||||
address from,
|
||||
|
@ -468,7 +547,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
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_);
|
||||
}
|
||||
|
||||
|
|
|
@ -390,7 +390,7 @@ describe("Compound III", function () {
|
|||
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({
|
||||
to: tokens.weth.address,
|
||||
value: ethers.utils.parseEther("10")
|
||||
|
@ -399,7 +399,7 @@ describe("Compound III", function () {
|
|||
const spells = [
|
||||
{
|
||||
connector: connectorName,
|
||||
method: "withdrawOnBehalf",
|
||||
method: "withdrawOnBehalfAndTransfer",
|
||||
args: [market, tokens.eth.address, dsaWallet0.address, dsaWallet1.address, amount, 0, 0]
|
||||
}
|
||||
];
|
||||
|
@ -607,7 +607,7 @@ describe("Compound III", function () {
|
|||
const spells = [
|
||||
{
|
||||
connector: connectorName,
|
||||
method: "borrowOnBehalf",
|
||||
method: "borrowOnBehalfAndTransfer",
|
||||
args: [market, base, dsaWallet3.address, dsaWallet0.address, amount, 0, 0]
|
||||
}
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue
Block a user