mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
edited dydx proxy logic
This commit is contained in:
parent
ae823a659d
commit
41ff721da3
|
@ -36,6 +36,7 @@ contract SoloMarginContract {
|
||||||
Par // the amount is denominated in par
|
Par // the amount is denominated in par
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enum AssetReference {
|
enum AssetReference {
|
||||||
Delta, // the amount is given as a delta from the current value
|
Delta, // the amount is given as a delta from the current value
|
||||||
Target // the amount is given as an exact number to end up at
|
Target // the amount is given as an exact number to end up at
|
||||||
|
@ -74,7 +75,7 @@ contract PayableProxySoloMarginContract {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract DSMath {
|
contract DSMath{
|
||||||
|
|
||||||
function add(uint x, uint y) internal pure returns (uint z) {
|
function add(uint x, uint y) internal pure returns (uint z) {
|
||||||
require((z = x + y) >= x, "math-not-safe");
|
require((z = x + y) >= x, "math-not-safe");
|
||||||
|
@ -164,23 +165,49 @@ contract DydxResolver is Helpers {
|
||||||
/**
|
/**
|
||||||
* @dev Deposit ETH/ERC20 or Payback borrowed ETH/ERC20
|
* @dev Deposit ETH/ERC20 or Payback borrowed ETH/ERC20
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function deposit(
|
function deposit(
|
||||||
SoloMarginContract.Info[] memory accounts,
|
uint256 marketId,
|
||||||
SoloMarginContract.ActionArgs[] memory actions,
|
|
||||||
address erc20Addr,
|
address erc20Addr,
|
||||||
uint256 tokenAmt
|
uint256 tokenAmt
|
||||||
) public payable
|
) public payable
|
||||||
{
|
{
|
||||||
if (erc20Addr == getAddressETH()) {
|
SoloMarginContract.Info[] memory accounts = new SoloMarginContract.Info[](1);
|
||||||
PayableProxySoloMarginContract soloPayable = PayableProxySoloMarginContract(getSoloPayableAddress());
|
accounts[0] = (SoloMarginContract.Info(address(this), 0));
|
||||||
soloPayable.operate.value(msg.value)(accounts, actions, msg.sender);
|
|
||||||
} else {
|
SoloMarginContract.ActionArgs[] memory actions = new SoloMarginContract.ActionArgs[](1);
|
||||||
|
|
||||||
|
SoloMarginContract.AssetAmount memory amount = SoloMarginContract.AssetAmount(
|
||||||
|
true,
|
||||||
|
SoloMarginContract.AssetDenomination.Wei,
|
||||||
|
SoloMarginContract.AssetReference.Delta,
|
||||||
|
tokenAmt
|
||||||
|
);
|
||||||
|
|
||||||
|
bytes[] memory data = new bytes[](0);
|
||||||
|
actions[0] = SoloMarginContract.ActionArgs(
|
||||||
|
SoloMarginContract.ActionType.Deposit,
|
||||||
|
0,
|
||||||
|
amount,
|
||||||
|
marketId,
|
||||||
|
0,
|
||||||
|
address(this),
|
||||||
|
0,
|
||||||
|
data[0]
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// if (erc20Addr == getAddressETH()) {
|
||||||
|
// // PayableProxySoloMarginContract soloPayable = PayableProxySoloMarginContract(getSoloPayableAddress());
|
||||||
|
// // soloPayable.operate.value(msg.value)(accounts, actions, msg.sender);
|
||||||
|
// } else {
|
||||||
SoloMarginContract solo = SoloMarginContract(getSoloAddress());
|
SoloMarginContract solo = SoloMarginContract(getSoloAddress());
|
||||||
ERC20Interface token = ERC20Interface(erc20Addr);
|
ERC20Interface token = ERC20Interface(erc20Addr);
|
||||||
token.transferFrom(msg.sender, address(this), tokenAmt);
|
token.transferFrom(msg.sender, address(this), tokenAmt);
|
||||||
setApproval(erc20Addr, 2**255, getSoloAddress());
|
setApproval(erc20Addr, 2**255, getSoloAddress());
|
||||||
solo.operate(accounts, actions);
|
solo.operate(accounts, actions);
|
||||||
}
|
// }
|
||||||
emit LogDeposit(erc20Addr, tokenAmt, msg.sender);
|
emit LogDeposit(erc20Addr, tokenAmt, msg.sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user