mirror of
https://github.com/Instadapp/dsa-connectors-old.git
synced 2024-07-29 22:47:46 +00:00
Update mapping
This commit is contained in:
parent
579b081d79
commit
5c460884b7
|
@ -40,7 +40,7 @@ interface ComptrollerInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstaMappingV2 {
|
interface InstaMappingV2 {
|
||||||
function cTokenMapping(string calldata) external view returns (address);
|
function getMapping(string calldata tokenId) external view returns (address, address);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MemoryInterface {
|
interface MemoryInterface {
|
||||||
|
@ -172,14 +172,14 @@ contract BasicResolver is CompoundHelpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deposit ETH/ERC20_Token.
|
* @dev Deposit ETH/ERC20_Token.
|
||||||
* @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to deposit.(For eg: ETH-A)
|
||||||
* @param amt token amount to deposit.
|
* @param amt token amount to deposit.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function deposit(address token, string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
function deposit(string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
enterMarket(cToken);
|
enterMarket(cToken);
|
||||||
if (token == getAddressETH()) {
|
if (token == getAddressETH()) {
|
||||||
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
_amt = _amt == uint(-1) ? address(this).balance : _amt;
|
||||||
|
@ -197,14 +197,14 @@ contract BasicResolver is CompoundHelpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw ETH/ERC20_Token.
|
* @dev Withdraw ETH/ERC20_Token.
|
||||||
* @param token token address to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to withdraw.(For eg: ETH-A)
|
||||||
* @param amt token amount to withdraw.
|
* @param amt token amount to withdraw.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function withdraw(address token, string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
function withdraw(string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||||
if (_amt == uint(-1)) {
|
if (_amt == uint(-1)) {
|
||||||
TokenInterface tokenContract = TokenInterface(token);
|
TokenInterface tokenContract = TokenInterface(token);
|
||||||
|
@ -222,14 +222,14 @@ contract BasicResolver is CompoundHelpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Borrow ETH/ERC20_Token.
|
* @dev Borrow ETH/ERC20_Token.
|
||||||
* @param token token address to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to borrow.(For eg: DAI-A)
|
||||||
* @param amt token amount to borrow.
|
* @param amt token amount to borrow.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function borrow(address token, string calldata tokenId, uint amt, uint getId, uint setId) external payable {
|
function borrow(string calldata tokenId, uint amt, uint getId, uint setId) external payable {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
enterMarket(cToken);
|
enterMarket(cToken);
|
||||||
require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed");
|
require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed");
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
@ -239,14 +239,14 @@ contract BasicResolver is CompoundHelpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Payback borrowed ETH/ERC20_Token.
|
* @dev Payback borrowed ETH/ERC20_Token.
|
||||||
* @param token token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to payback.(For eg: COMP-A)
|
||||||
* @param amt token amount to payback.
|
* @param amt token amount to payback.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function payback(address token, string calldata tokenId, uint amt, uint getId, uint setId) external payable {
|
function payback(string calldata tokenId, uint amt, uint getId, uint setId) external payable {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||||
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(address(this)) : _amt;
|
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(address(this)) : _amt;
|
||||||
|
|
||||||
|
@ -295,24 +295,22 @@ contract ExtraResolver is BasicResolver {
|
||||||
);
|
);
|
||||||
|
|
||||||
struct LiquidateData {
|
struct LiquidateData {
|
||||||
address borrower;
|
|
||||||
address tokenToPay;
|
address tokenToPay;
|
||||||
string tokenPayId;
|
|
||||||
address tokenInReturn;
|
address tokenInReturn;
|
||||||
string tokenReturnId;
|
address cTokenPay;
|
||||||
uint amt;
|
address cTokenColl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deposit ETH/ERC20_Token.
|
* @dev Deposit ETH/ERC20_Token.
|
||||||
* @param token token address to depositCToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to depositCToken.(For eg: DAI-A)
|
||||||
* @param amt token amount to depositCToken.
|
* @param amt token amount to depositCToken.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
* @param setId Set ctoken amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function depositCToken(address token, string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
function depositCToken(string calldata tokenId, uint amt, uint getId, uint setId) external payable{
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
enterMarket(cToken);
|
enterMarket(cToken);
|
||||||
|
|
||||||
CTokenInterface ctokenContract = CTokenInterface(cToken);
|
CTokenInterface ctokenContract = CTokenInterface(cToken);
|
||||||
|
@ -337,23 +335,28 @@ contract ExtraResolver is BasicResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Withdraw CETH/CERC20_Token using cToken Amt.
|
* @dev Withdraw CETH/CERC20_Token using cToken Amt.
|
||||||
* @param token token address to withdraw CToken.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param tokenId token id of the token to withdraw CToken.(For eg: ETH-A)
|
||||||
* @param cTokenAmt ctoken amount to withdrawCToken.
|
* @param cTokenAmt ctoken amount to withdrawCToken.
|
||||||
* @param getId Get ctoken amount at this ID from `InstaMemory` Contract.
|
* @param getId Get ctoken amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function withdrawCToken(address token, string calldata tokenId, uint cTokenAmt, uint getId, uint setId) external payable {
|
function withdrawCToken(string calldata tokenId, uint cTokenAmt, uint getId, uint setId) external payable {
|
||||||
uint _cAmt = getUint(getId, cTokenAmt);
|
uint _cAmt = getUint(getId, cTokenAmt);
|
||||||
address cToken = InstaMappingV2(getMappingAddr()).cTokenMapping(tokenId);
|
(address token, address cToken) = InstaMappingV2(getMappingAddr()).getMapping(tokenId);
|
||||||
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
CTokenInterface cTokenContract = CTokenInterface(cToken);
|
||||||
TokenInterface tokenContract = TokenInterface(token);
|
TokenInterface tokenContract = TokenInterface(token);
|
||||||
_cAmt = _cAmt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _cAmt;
|
_cAmt = _cAmt == uint(-1) ? cTokenContract.balanceOf(address(this)) : _cAmt;
|
||||||
|
|
||||||
uint initialBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
uint withdrawAmt;
|
||||||
require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
|
|
||||||
uint finalBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
{
|
||||||
|
uint initialBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||||
|
require(cTokenContract.redeem(_cAmt) == 0, "redeem-failed");
|
||||||
|
uint finalBal = token != getAddressETH() ? tokenContract.balanceOf(address(this)) : address(this).balance;
|
||||||
|
|
||||||
|
withdrawAmt = sub(finalBal, initialBal);
|
||||||
|
}
|
||||||
|
|
||||||
uint withdrawAmt = sub(finalBal, initialBal);
|
|
||||||
setUint(setId, withdrawAmt);
|
setUint(setId, withdrawAmt);
|
||||||
|
|
||||||
emit LogWithdrawCToken(token, tokenId, cToken, withdrawAmt, _cAmt, getId, setId);
|
emit LogWithdrawCToken(token, tokenId, cToken, withdrawAmt, _cAmt, getId, setId);
|
||||||
|
@ -361,34 +364,44 @@ contract ExtraResolver is BasicResolver {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Liquidate a position.
|
* @dev Liquidate a position.
|
||||||
* @param data Liquidation data.
|
* @param borrower Borrower's Address.
|
||||||
|
* @param tokenIdToPay token id of the token to pay for liquidation.(For eg: ETH-A)
|
||||||
|
* @param tokenIdInReturn token id of the token to return for liquidation.(For eg: USDC-A)
|
||||||
|
* @param amt token amount to pay for liquidation.
|
||||||
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
*/
|
*/
|
||||||
function liquidate(
|
function liquidate(
|
||||||
LiquidateData calldata data,
|
address borrower,
|
||||||
|
string calldata tokenIdToPay,
|
||||||
|
string calldata tokenIdInReturn,
|
||||||
|
uint amt,
|
||||||
uint getId,
|
uint getId,
|
||||||
uint setId
|
uint setId
|
||||||
) external payable {
|
) external payable
|
||||||
uint _amt = getUint(getId, data.amt);
|
{
|
||||||
address cTokenPay = InstaMappingV2(getMappingAddr()).cTokenMapping(data.tokenPayId);
|
uint _amt = getUint(getId, amt);
|
||||||
address cTokenColl = InstaMappingV2(getMappingAddr()).cTokenMapping(data.tokenReturnId);
|
|
||||||
CTokenInterface cTokenContract = CTokenInterface(cTokenPay);
|
LiquidateData memory data;
|
||||||
|
|
||||||
|
(data.tokenToPay, data.cTokenPay) = InstaMappingV2(getMappingAddr()).getMapping(tokenIdToPay);
|
||||||
|
(data.tokenInReturn, data.cTokenColl) = InstaMappingV2(getMappingAddr()).getMapping(tokenIdInReturn);
|
||||||
|
CTokenInterface cTokenContract = CTokenInterface(data.cTokenPay);
|
||||||
|
|
||||||
{
|
{
|
||||||
(,, uint shortfal) = ComptrollerInterface(getComptrollerAddress()).getAccountLiquidity(data.borrower);
|
(,, uint shortfal) = ComptrollerInterface(getComptrollerAddress()).getAccountLiquidity(borrower);
|
||||||
require(shortfal != 0, "account-cannot-be-liquidated");
|
require(shortfal != 0, "account-cannot-be-liquidated");
|
||||||
}
|
}
|
||||||
|
|
||||||
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(data.borrower) : _amt;
|
_amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(borrower) : _amt;
|
||||||
if (data.tokenToPay == getAddressETH()) {
|
if (data.tokenToPay == getAddressETH()) {
|
||||||
require(address(this).balance >= _amt, "not-enought-eth");
|
require(address(this).balance >= _amt, "not-enought-eth");
|
||||||
CETHInterface(cTokenPay).liquidateBorrow.value(_amt)(data.borrower, cTokenColl);
|
CETHInterface(data.cTokenPay).liquidateBorrow.value(_amt)(borrower, data.cTokenColl);
|
||||||
} else {
|
} else {
|
||||||
TokenInterface tokenContract = TokenInterface(data.tokenToPay);
|
TokenInterface tokenContract = TokenInterface(data.tokenToPay);
|
||||||
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token");
|
||||||
tokenContract.approve(cTokenPay, _amt);
|
tokenContract.approve(data.cTokenPay, _amt);
|
||||||
require(cTokenContract.liquidateBorrow(data.borrower, _amt, cTokenColl) == 0, "liquidate-failed");
|
require(cTokenContract.liquidateBorrow(borrower, _amt, data.cTokenColl) == 0, "liquidate-failed");
|
||||||
}
|
}
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user