mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
logic updated
This commit is contained in:
parent
921af2f626
commit
80bc284919
|
@ -178,4 +178,22 @@ contract Events {
|
|||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogAllow(
|
||||
address indexed market,
|
||||
address indexed manager,
|
||||
bool allow
|
||||
);
|
||||
|
||||
event LogAllowWithPermit(
|
||||
address indexed market,
|
||||
address indexed owner,
|
||||
address indexed manager,
|
||||
uint256 expiry,
|
||||
uint256 nonce,
|
||||
uint256 v,
|
||||
uint256 r,
|
||||
uint256 s,
|
||||
bool allow
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,73 +29,22 @@ abstract contract Helpers is DSMath, Basic {
|
|||
baseToken = CometInterface(market).baseToken();
|
||||
}
|
||||
|
||||
function _supply(
|
||||
address market,
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amt
|
||||
) public payable returns (bool success) {
|
||||
bytes memory data;
|
||||
|
||||
if (from == address(0) && to == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"supply(address, uint256)",
|
||||
token,
|
||||
amt
|
||||
);
|
||||
} else if (from == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"supplyTo(address, address, uint256)",
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
} else if (from != address(0) && to != address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"supplyFrom(address, address, address, uint256)",
|
||||
from,
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
}
|
||||
|
||||
(success, ) = market.delegatecall(data);
|
||||
}
|
||||
|
||||
function _withdraw(
|
||||
address market,
|
||||
address token,
|
||||
address from,
|
||||
address to,
|
||||
uint256 amt
|
||||
) internal returns (bool success) {
|
||||
) internal {
|
||||
bytes memory data;
|
||||
|
||||
if (from == address(0) && to == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"withdraw(address, uint256)",
|
||||
token,
|
||||
amt
|
||||
);
|
||||
CometInterface(market).withdraw(token, amt);
|
||||
} else if (from == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"withdrawTo(address, address, uint256)",
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
CometInterface(market).withdrawTo(to, token, amt);
|
||||
} else if (from != address(0) && to != address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"withdrawFrom(address, address, address, uint256)",
|
||||
from,
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
CometInterface(market).withdrawFrom(from, to, token, amt);
|
||||
}
|
||||
(success, ) = market.delegatecall(data);
|
||||
}
|
||||
|
||||
function _transfer(
|
||||
|
@ -104,27 +53,14 @@ abstract contract Helpers is DSMath, Basic {
|
|||
address from,
|
||||
address to,
|
||||
uint256 amt
|
||||
) public payable returns (bool success) {
|
||||
) public payable {
|
||||
bytes memory data;
|
||||
|
||||
if (from == address(0)) {
|
||||
data = abi.encodeWithSignature(
|
||||
"transferAsset(address, address, uint256)",
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
CometInterface(market).transferAsset(to, token, amt);
|
||||
} else {
|
||||
data = abi.encodeWithSignature(
|
||||
"transferAssetFrom(address, address, address, uint256)",
|
||||
from,
|
||||
to,
|
||||
token,
|
||||
amt
|
||||
);
|
||||
CometInterface(market).transferAssetFrom(from, to, token, amt);
|
||||
}
|
||||
|
||||
(success, ) = market.delegatecall(data);
|
||||
}
|
||||
|
||||
function _borrowOrWithdraw(BorrowWithdrawParams memory params)
|
||||
|
@ -147,14 +83,7 @@ abstract contract Helpers is DSMath, Basic {
|
|||
params.market,
|
||||
_token
|
||||
);
|
||||
bool success = _withdraw(
|
||||
params.market,
|
||||
_token,
|
||||
params.from,
|
||||
params.to,
|
||||
_amt
|
||||
);
|
||||
require(success, "borrow-or-withdraw-failed");
|
||||
_withdraw(params.market, _token, params.from, params.to, _amt);
|
||||
|
||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||
address(this),
|
||||
|
|
|
@ -95,6 +95,19 @@ interface CometInterface {
|
|||
function balanceOf(address account) external view returns (uint256);
|
||||
|
||||
function borrowBalanceOf(address account) external view returns (uint256);
|
||||
|
||||
function allow(address manager, bool isAllowed_) external;
|
||||
|
||||
function allowBySig(
|
||||
address owner,
|
||||
address manager,
|
||||
bool isAllowed_,
|
||||
uint256 nonce,
|
||||
uint256 expiry,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) external;
|
||||
}
|
||||
|
||||
interface CometRewards {
|
||||
|
|
|
@ -12,6 +12,7 @@ import { Stores } from "../../common/stores.sol";
|
|||
import { Helpers } from "./helpers.sol";
|
||||
import { Events } from "./events.sol";
|
||||
import { CometInterface } from "./interface.sol";
|
||||
import "hardhat/console.sol";
|
||||
|
||||
abstract contract CompoundIIIResolver is Events, Helpers {
|
||||
/**
|
||||
|
@ -51,8 +52,11 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
|
||||
approve(tokenContract, market, _amt);
|
||||
|
||||
bool success = _supply(market, _token, address(0), address(0), _amt);
|
||||
require(success, "supply-failed");
|
||||
CometInterface(market).supply(_token, _amt);
|
||||
console.log(
|
||||
CometInterface(market).userCollateral(address(this), _token).balance
|
||||
);
|
||||
console.log(address(this));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -99,8 +103,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
|
||||
approve(tokenContract, market, _amt);
|
||||
|
||||
bool success = _supply(market, _token, address(0), to, _amt);
|
||||
require(success, "supply-failed");
|
||||
CometInterface(market).supplyTo(to, _token, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -149,8 +152,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
|
||||
approve(tokenContract, market, _amt);
|
||||
|
||||
bool success = _supply(market, _token, from, to, _amt);
|
||||
require(success, "supply-failed");
|
||||
CometInterface(market).supplyFrom(from, to, _token, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -195,8 +197,8 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
market,
|
||||
token
|
||||
);
|
||||
bool success = _withdraw(market, token, address(0), address(0), _amt);
|
||||
require(success, "withdraw-failed");
|
||||
|
||||
CometInterface(market).withdraw(_token, _amt);
|
||||
|
||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||
address(this),
|
||||
|
@ -325,8 +327,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
market,
|
||||
token
|
||||
);
|
||||
bool success = _withdraw(market, token, address(0), address(0), _amt);
|
||||
require(success, "borrow-failed");
|
||||
CometInterface(market).withdraw(_token, _amt);
|
||||
|
||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||
address(this),
|
||||
|
@ -422,7 +423,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
* @param market The address of the market from where to withdraw.
|
||||
* @param setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function payBack(address market, uint256 setId)
|
||||
function payback(address market, uint256 setId)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
|
@ -437,14 +438,7 @@ 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)
|
||||
);
|
||||
require(success, "payback-failed");
|
||||
CometInterface(market).supply(_token, uint256(-1));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -459,7 +453,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
* @param to The address on behalf of which the borrow is to be repaid.
|
||||
* @param setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function payBackOnBehalf(
|
||||
function paybackOnBehalf(
|
||||
address market,
|
||||
address to,
|
||||
uint256 setId
|
||||
|
@ -478,8 +472,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
approve(tokenContract, market, uint256(-1));
|
||||
uint256 _amt = CometInterface(market).borrowBalanceOf(to);
|
||||
|
||||
bool success = _supply(market, _token, address(0), to, uint256(-1));
|
||||
require(success, "paybackOnBehalf-failed");
|
||||
CometInterface(market).supplyTo(to, _token, uint256(-1));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -495,7 +488,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
* @param to The address on behalf of which the borrow is to be repaid.
|
||||
* @param setId ID stores the amount of tokens withdrawn.
|
||||
*/
|
||||
function payFrom(
|
||||
function paybackFrom(
|
||||
address market,
|
||||
address from,
|
||||
address to,
|
||||
|
@ -515,8 +508,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
approve(tokenContract, market, uint256(-1));
|
||||
uint256 _amt = CometInterface(market).borrowBalanceOf(to);
|
||||
|
||||
bool success = _supply(market, _token, from, to, uint256(-1));
|
||||
require(success, "paybackFrom-failed");
|
||||
CometInterface(market).supplyFrom(from, to, _token, uint256(-1));
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -708,8 +700,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, address(0), dest, _amt);
|
||||
require(success, "transfer-base-failed");
|
||||
_transfer(market, _token, address(0), dest, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -751,8 +742,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, src, dest, _amt);
|
||||
require(success, "transfer-base-from-failed");
|
||||
_transfer(market, _token, src, dest, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -796,8 +786,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, address(0), dest, _amt);
|
||||
require(success, "transfer-asset-failed");
|
||||
_transfer(market, _token, address(0), dest, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
|
@ -841,14 +830,78 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
|||
convertEthToWeth(isEth, tokenContract, _amt);
|
||||
}
|
||||
|
||||
bool success = _transfer(market, _token, src, dest, _amt);
|
||||
require(success, "transfer-asset-from-failed");
|
||||
_transfer(market, _token, src, dest, _amt);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogTransferAssetFrom(address,address,address,address,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(market, _token, src, dest, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allow/Disallow managers to handle position.
|
||||
* @notice Authorize/Remove managers to perform write operations for the position.
|
||||
* @param market The address of the market where to supply.
|
||||
* @param manager The address to be authorized.
|
||||
* @param isAllowed Whether to allow or disallow the manager.
|
||||
*/
|
||||
function allow(
|
||||
address market,
|
||||
address manager,
|
||||
bool isAllowed
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
CometInterface(market).allow(manager, isAllowed);
|
||||
_eventName = "LogAllow(address,address,bool)";
|
||||
_eventParam = abi.encode(market, manager, isAllowed);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Allow/Disallow managers to handle owner's position.
|
||||
* @notice Authorize/Remove managers to perform write operations for owner's position.
|
||||
* @param market The address of the market where to supply.
|
||||
* @param owner The authorizind owner account.
|
||||
* @param manager The address to be authorized.
|
||||
* @param isAllowed Whether to allow or disallow the manager.
|
||||
* @param nonce Signer's nonce.
|
||||
* @param expiry The duration for which to permit the manager.
|
||||
* @param v Recovery byte of the signature.
|
||||
* @param r Half of the ECDSA signature pair.
|
||||
* @param s Half of the ECDSA signature pair.
|
||||
*/
|
||||
function allowWithPermit(
|
||||
address market,
|
||||
address owner,
|
||||
address manager,
|
||||
bool isAllowed,
|
||||
uint256 nonce,
|
||||
uint256 expiry,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
) external returns (string memory _eventName, bytes memory _eventParam) {
|
||||
CometInterface(market).allowBySig(
|
||||
owner,
|
||||
manager,
|
||||
isAllowed,
|
||||
nonce,
|
||||
expiry,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
);
|
||||
_eventName = "LogAllowWithPermit(address,address,address,uint256,uint256,uint256,uint256,uint256,bool)";
|
||||
_eventParam = abi.encode(
|
||||
market,
|
||||
owner,
|
||||
manager,
|
||||
isAllowed,
|
||||
nonce,
|
||||
expiry,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV3Compound is CompoundIIIResolver {
|
||||
|
|
|
@ -41,6 +41,27 @@ export const tokens = {
|
|||
name: "Etherem Name Services",
|
||||
address: "0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72",
|
||||
decimals: 18
|
||||
},
|
||||
comp: {
|
||||
type: "token",
|
||||
symbol: "COMP",
|
||||
name: "Compound",
|
||||
address: "0xc00e94Cb662C3520282E6f5717214004A7f26888",
|
||||
decimals: 18
|
||||
},
|
||||
link: {
|
||||
type: "token",
|
||||
symbol: "LINK",
|
||||
name: "ChainLink Token",
|
||||
address: "0x514910771AF9Ca656af840dff83E8264EcF986CA",
|
||||
decimals: 18
|
||||
},
|
||||
uni: {
|
||||
type: "token",
|
||||
symbol: "UNI",
|
||||
name: "Uniswap",
|
||||
address: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
|
||||
decimals: 18
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -48,7 +69,10 @@ export const tokenMapping: Record<string, any> = {
|
|||
usdc: {
|
||||
impersonateSigner: "0xfcb19e6a322b27c06842a71e8c725399f049ae3a",
|
||||
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
||||
abi: ["function mint(address _to, uint256 _amount) external returns (bool);"],
|
||||
abi: [
|
||||
"function mint(address _to, uint256 _amount) external returns (bool)",
|
||||
"function balanceOf(address user) external returns (uint256)"
|
||||
],
|
||||
process: async function (owner: Signer | Provider, to: any, amt: any) {
|
||||
const contract = new ethers.Contract(this.address, this.abi, owner);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user