mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
transfer method
This commit is contained in:
parent
40d3b6e67a
commit
d5747bd903
|
@ -105,10 +105,10 @@ contract Events {
|
|||
bool accrued
|
||||
);
|
||||
|
||||
event LogRewardsClaimedTo(
|
||||
event LogRewardsClaimedTo(
|
||||
address indexed market,
|
||||
address indexed account,
|
||||
address to,
|
||||
address to,
|
||||
uint256 indexed totalClaimedInWei,
|
||||
uint256 getId,
|
||||
bool accrued
|
||||
|
@ -141,4 +141,41 @@ contract Events {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogTransferBase(
|
||||
address indexed market,
|
||||
address indexed dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogTransferBaseFrom(
|
||||
address indexed market,
|
||||
address indexed from,
|
||||
address indexed dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogTransferAsset(
|
||||
address indexed market,
|
||||
address token,
|
||||
address indexed from,
|
||||
address indexed dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogTransferAssetFrom(
|
||||
address indexed market,
|
||||
address token,
|
||||
address indexed from,
|
||||
address indexed dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ import { Basic } from "../../common/basic.sol";
|
|||
import { CometInterface, CometRewards } from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
|
||||
CometRewards internal constant cometRewards = CometRewards(0x1B0e765F6224C21223AeA2af16c1C46E38885a40);
|
||||
CometRewards internal constant cometRewards =
|
||||
CometRewards(0x1B0e765F6224C21223AeA2af16c1C46E38885a40);
|
||||
|
||||
function getBaseToken(address market)
|
||||
internal
|
||||
|
@ -87,6 +87,35 @@ abstract contract Helpers is DSMath, Basic {
|
|||
(success, ) = market.delegatecall(data);
|
||||
}
|
||||
|
||||
function _transfer(
|
||||
address market,
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amt
|
||||
) public payable returns (bool success) {
|
||||
bytes memory data;
|
||||
|
||||
if (from == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"transferAsset(address, address, uint256)",
|
||||
dest,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
} else {
|
||||
data = abi.encodeWithSignature(
|
||||
"transferAssetFrom(address, address, address, uint256)",
|
||||
from,
|
||||
dest,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
}
|
||||
|
||||
(success, ) = market.delegatecall(data);
|
||||
}
|
||||
|
||||
function getAccountSupplyBalanceOfAsset(
|
||||
address account,
|
||||
address market,
|
||||
|
|
|
@ -463,7 +463,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
uint256 _amt = getUint(getId, amt);
|
||||
|
||||
require(market != address(0), "invalid market address");
|
||||
bool isEth = (getBaseToken(market) == ethAddr);
|
||||
bool isEth = (getBaseToken(market) == ethAddr);
|
||||
address _token = isEth ? wethAddr : getBaseToken(market);
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
@ -513,7 +513,13 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
approve(tokenContract, market, uint256(-1));
|
||||
uint256 _amt = CometInterface(market).borrowBalanceOf(address(this));
|
||||
|
||||
bool success = _supply(market, _token, address(0), address(0), uint256(-1));
|
||||
bool success = _supply(
|
||||
market,
|
||||
_token,
|
||||
address(0),
|
||||
address(0),
|
||||
uint256(-1)
|
||||
);
|
||||
require(success, "payback-failed");
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
@ -708,6 +714,140 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
accrue
|
||||
);
|
||||
}
|
||||
|
||||
function transferBase(
|
||||
address market,
|
||||
address dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amount);
|
||||
require(market != address(0), "invalid market address");
|
||||
|
||||
address token = getBaseToken(market);
|
||||
bool isEth = token == ethAddr;
|
||||
address _token = isEth ? wethAddr : token;
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, address(0), dest, _amt);
|
||||
require(success, "transfer-base-failed");
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogTransferBase(address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(market, dest, _amt, getId, setId);
|
||||
}
|
||||
|
||||
function transferBaseFrom(
|
||||
address market,
|
||||
address src,
|
||||
address dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amount);
|
||||
require(market != address(0), "invalid market address");
|
||||
|
||||
address token = getBaseToken(market);
|
||||
bool isEth = token == ethAddr;
|
||||
address _token = isEth ? wethAddr : token;
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, src, dest, _amt);
|
||||
require(success, "transfer-base-from-failed");
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogTransferBaseFrom(address,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(market, src, dest, _amt, getId, setId);
|
||||
}
|
||||
|
||||
function transferAsset(
|
||||
address market,
|
||||
address token,
|
||||
address dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amount);
|
||||
require(
|
||||
market != address(0) && token != address(0),
|
||||
"invalid market address"
|
||||
);
|
||||
|
||||
bool isEth = token == ethAddr;
|
||||
address _token = isEth ? wethAddr : token;
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, address(0), dest, _amt);
|
||||
require(success, "transfer-asset-failed");
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogTransferAsset(address,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(market, _token, dest, _amt, getId, setId);
|
||||
}
|
||||
|
||||
function transferAssetFrom(
|
||||
address market,
|
||||
address token,
|
||||
address src,
|
||||
address dest,
|
||||
uint256 amount,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amount);
|
||||
require(market != address(0), "invalid market address");
|
||||
|
||||
address token = getBaseToken(market);
|
||||
bool isEth = token == ethAddr;
|
||||
address _token = isEth ? wethAddr : token;
|
||||
TokenInterface tokenContract = TokenInterface(_token);
|
||||
|
||||
if (isEth) {
|
||||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, src, dest, _amt);
|
||||
require(success, "transfer-asset-from-failed");
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogTransferAssetFrom(address,address,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(market, _token, src, dest, _amt, getId, setId);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV3Compound is CompoundIIIResolver {
|
||||
|
|
Loading…
Reference in New Issue
Block a user