Skip to content

Commit

Permalink
finished testing and added coverage report for BorrowPositionProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey committed Aug 19, 2022
1 parent 1f2b8a0 commit 9aa63d2
Show file tree
Hide file tree
Showing 26 changed files with 479 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .temp_contracts/external/amm/DolomiteAmmPair.sol
Expand Up @@ -410,7 +410,7 @@ contract DolomiteAmmPair is IDolomiteAmmPair, DolomiteAmmERC20, IAutoTrader {
amount0OutWei = 0;
amount1OutWei = amountOutWei;
} else {
assert(inputMarketId == cache.marketId1);
/*assert(inputMarketId == cache.marketId1);*/

cache.balance1Wei = cache.balance1Wei.add(inputWei.value);
cache.balance0Wei = cache.balance0Wei.sub(amountOutWei);
Expand Down
80 changes: 80 additions & 0 deletions .temp_contracts/external/interfaces/IBorrowPositionProxy.sol
@@ -0,0 +1,80 @@
/*
Copyright 2022 Dolomite.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.7;


interface IBorrowPositionProxy {

// ========================= Events =========================

event BorrowPositionOpen(address indexed _borrower, uint indexed _borrowAccountIndex);

// ========================= Functions =========================

/**
* @param _fromAccountIndex The index from which `msg.sender` will be sourcing the deposit
* @param _toAccountIndex The index into which `msg.sender` will be depositing
* @param _collateralMarketId The ID of the market being deposited
* @param _amountWei The amount, in Wei, to deposit
*/
function openBorrowPosition(
uint _fromAccountIndex,
uint _toAccountIndex,
uint _collateralMarketId,
uint _amountWei
) external;

/**
* @notice This method can only be called once the user's debt has been reduced to zero. Sends funds from account
* index
*
* @param _borrowAccountIndex The index from which `msg.sender` collateral will be withdrawn
* @param _toAccountIndex The index into which `msg.sender` will be depositing leftover collateral
* @param _collateralMarketIds The IDs of the markets being withdrawn, to close the position
*/
function closeBorrowPosition(
uint _borrowAccountIndex,
uint _toAccountIndex,
uint[] calldata _collateralMarketIds
) external;

/**
* @param _fromAccountIndex The index from which `msg.sender` will be withdrawing assets
* @param _toAccountIndex The index into which `msg.sender` will be depositing assets
* @param _marketId The ID of the market being transferred
* @param _amountWei The amount, in Wei, to transfer
*/
function transferBetweenAccounts(
uint _fromAccountIndex,
uint _toAccountIndex,
uint _marketId,
uint _amountWei
) external;

/**
* @param _fromAccountIndex The index from which `msg.sender` will be depositing assets
* @param _borrowAccountIndex The index of the borrow position for that will receive the deposited assets
* @param _marketId The ID of the market being transferred
*/
function repayAllForBorrowPosition(
uint _fromAccountIndex,
uint _borrowAccountIndex,
uint _marketId
) external;
}
Expand Up @@ -30,4 +30,4 @@ contract IChainlinkAggregator {

function latestAnswer() public view returns (int256);

}
}
2 changes: 1 addition & 1 deletion .temp_contracts/external/lib/TypedSignature.sol
Expand Up @@ -106,7 +106,7 @@ library TypedSignature {
} else if (sigType == SignatureType.Decimal) {
signedHash = keccak256(abi.encodePacked(PREPEND_DEC, hash));
} else {
assert(sigType == SignatureType.Hexadecimal);
/*assert(sigType == SignatureType.Hexadecimal);*/
signedHash = keccak256(abi.encodePacked(PREPEND_HEX, hash));
}

Expand Down
16 changes: 8 additions & 8 deletions .temp_contracts/external/oracles/ChainlinkPriceOracleV1.sol
Expand Up @@ -86,22 +86,22 @@ contract ChainlinkPriceOracleV1 is IPriceOracle, Ownable {
uint8[] memory aggregatorDecimals,
address chainlinkFlagsOrNull
) public {
require( // coverage-disable-line
/*require( // coverage-disable-line
tokens.length == chainlinkAggregators.length,
"invalid aggregators"
);
require( // coverage-disable-line
);*/
/*require( // coverage-disable-line
chainlinkAggregators.length == tokenDecimals.length,
"invalid token decimals"
);
require( // coverage-disable-line
);*/
/*require( // coverage-disable-line
tokenDecimals.length == tokenPairs.length,
"invalid token pairs"
);
require( // coverage-disable-line
);*/
/*require( // coverage-disable-line
tokenPairs.length == aggregatorDecimals.length,
"invalid aggregator decimals"
);
);*/

for (uint i = 0; i < tokens.length; i++) {
_insertOrUpdateOracleToken(
Expand Down
182 changes: 182 additions & 0 deletions .temp_contracts/external/proxies/BorrowPositionProxy.sol
@@ -0,0 +1,182 @@
/*
Copyright 2022 Dolomite.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

pragma solidity ^0.5.7;
pragma experimental ABIEncoderV2;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import { IDolomiteMargin } from "../../protocol/interfaces/IDolomiteMargin.sol";

import { Account } from "../../protocol/lib/Account.sol";
import { Actions } from "../../protocol/lib/Actions.sol";
import { Require } from "../../protocol/lib/Require.sol";
import { Types } from "../../protocol/lib/Types.sol";

import { OnlyDolomiteMargin } from "../helpers/OnlyDolomiteMargin.sol";

import { IBorrowPositionProxy } from "../interfaces/IBorrowPositionProxy.sol";


/**
* @title BorrowPositionProxy
* @author Dolomite
*
* @dev Contract for opening borrow positions to make indexing easier. This lowers gas costs on Arbitrum by minimizing
* call data, too.
*/
contract BorrowPositionProxy is IBorrowPositionProxy, OnlyDolomiteMargin, ReentrancyGuard {

constructor (
address dolomiteMargin
)
public
OnlyDolomiteMargin(dolomiteMargin)
{}

function openBorrowPosition(
uint _fromAccountIndex,
uint _toAccountIndex,
uint _marketId,
uint _amountWei
) external {
Account.Info[] memory accounts = new Account.Info[](2);
accounts[0] = Account.Info(msg.sender, _fromAccountIndex);
accounts[1] = Account.Info(msg.sender, _toAccountIndex);

Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);
Types.AssetAmount memory assetAmount = Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: _amountWei
});
actions[0] = Actions.ActionArgs({
actionType : Actions.ActionType.Transfer,
accountId : 0,
amount : assetAmount,
primaryMarketId : _marketId,
secondaryMarketId : 0,
otherAddress : address(0),
otherAccountId : 1,
data : bytes("")
});

// Emit this before the call to DolomiteMargin so indexers get it before the Transfer events are emitted
emit BorrowPositionOpen(msg.sender, _toAccountIndex);

IDolomiteMargin(DOLOMITE_MARGIN).operate(accounts, actions);
}

function closeBorrowPosition(
uint _borrowAccountIndex,
uint _toAccountIndex,
uint[] calldata _collateralMarketIds
) external {
Account.Info[] memory accounts = new Account.Info[](2);
accounts[0] = Account.Info(msg.sender, _borrowAccountIndex);
accounts[1] = Account.Info(msg.sender, _toAccountIndex);

Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](_collateralMarketIds.length);
Types.AssetAmount memory assetAmount = Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Target,
value: 0
});

for (uint i = 0; i < _collateralMarketIds.length; i++) {
actions[i] = Actions.ActionArgs({
actionType : Actions.ActionType.Transfer,
accountId : 0,
amount : assetAmount,
primaryMarketId : _collateralMarketIds[i],
secondaryMarketId : 0,
otherAddress : address(0),
otherAccountId : 1,
data : bytes("")
});
}

IDolomiteMargin(DOLOMITE_MARGIN).operate(accounts, actions);
}

function transferBetweenAccounts(
uint _fromAccountIndex,
uint _toAccountIndex,
uint _marketId,
uint _amountWei
) external {
Account.Info[] memory accounts = new Account.Info[](2);
accounts[0] = Account.Info(msg.sender, _fromAccountIndex);
accounts[1] = Account.Info(msg.sender, _toAccountIndex);

Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);
Types.AssetAmount memory assetAmount = Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Delta,
value: _amountWei
});
actions[0] = Actions.ActionArgs({
actionType : Actions.ActionType.Transfer,
accountId : 0,
amount : assetAmount,
primaryMarketId : _marketId,
secondaryMarketId : 0,
otherAddress : address(0),
otherAccountId : 1,
data : bytes("")
});

IDolomiteMargin(DOLOMITE_MARGIN).operate(accounts, actions);
}

function repayAllForBorrowPosition(
uint _fromAccountIndex,
uint _borrowAccountIndex,
uint _marketId
) external {
Account.Info[] memory accounts = new Account.Info[](2);
accounts[0] = Account.Info(msg.sender, _borrowAccountIndex);
accounts[1] = Account.Info(msg.sender, _fromAccountIndex);

Actions.ActionArgs[] memory actions = new Actions.ActionArgs[](1);
// This works by transferring all debt from _borrowAccountIndex to _fromAccountIndex
Types.AssetAmount memory assetAmount = Types.AssetAmount({
sign: false,
denomination: Types.AssetDenomination.Wei,
ref: Types.AssetReference.Target,
value: 0
});
actions[0] = Actions.ActionArgs({
actionType : Actions.ActionType.Transfer,
accountId : 0,
amount : assetAmount,
primaryMarketId : _marketId,
secondaryMarketId : 0,
otherAddress : address(0),
otherAccountId : 1,
data : bytes("")
});

IDolomiteMargin(DOLOMITE_MARGIN).operate(accounts, actions);
}
}
Expand Up @@ -688,7 +688,7 @@ contract DolomiteAmmRouterProxy is ReentrancyGuard {
(amountAWei, amountBWei) = (amountADesiredWei, amountBOptimal);
} else {
uint amountAOptimal = DolomiteAmmLibrary.quote(amountBDesiredWei, reserveBWei, reserveAWei);
assert(amountAOptimal <= amountADesiredWei);
/*assert(amountAOptimal <= amountADesiredWei);*/
Require.that(
amountAOptimal >= amountAMinWei,
FILE,
Expand Down
6 changes: 3 additions & 3 deletions .temp_contracts/external/proxies/LiquidatorProxyV1.sol
Expand Up @@ -259,8 +259,8 @@ contract LiquidatorProxyV1 is OnlyDolomiteMargin, ReentrancyGuard, LiquidatorPro
private
pure
{
assert(!cache.heldWei.isNegative());
assert(!cache.owedWei.isPositive());
/*assert(!cache.heldWei.isNegative());*/
/*assert(!cache.owedWei.isPositive());*/

// if the liquidator account is already not above the collateralization requirement, return
bool liquidatorAboveCollateralization = isCollateralized(
Expand Down Expand Up @@ -390,7 +390,7 @@ contract LiquidatorProxyV1 is OnlyDolomiteMargin, ReentrancyGuard, LiquidatorPro

// update toLiquidate, heldWei, and owedWei
Types.Wei memory delta = cache.owedWei.sub(newOwedWei);
assert(!delta.isNegative());
/*assert(!delta.isNegative());*/
cache.toLiquidate = cache.toLiquidate.add(delta.value);
cache.heldWei = newHeldWei;
cache.owedWei = newOwedWei;
Expand Down
4 changes: 2 additions & 2 deletions .temp_contracts/external/proxies/LiquidatorProxyV1WithAmm.sol
Expand Up @@ -506,10 +506,10 @@ contract LiquidatorProxyV1WithAmm is ReentrancyGuard, LiquidatorProxyHelper {
for (uint i = 0; i < accountsForTrade.length; i++) {
accounts[i] = accountsForTrade[i];
}
assert(
/*assert(
accounts[0].owner == constants.solidAccount.owner &&
accounts[0].number == constants.solidAccount.number
);
);*/

accounts[accounts.length - 1] = constants.liquidAccount;
return accounts;
Expand Down
4 changes: 2 additions & 2 deletions .temp_contracts/external/proxies/PayableProxy.sol
Expand Up @@ -69,10 +69,10 @@ contract PayableProxy is OnlyDolomiteMargin, ReentrancyGuard {
external
payable
{
require( // coverage-disable-line
/*require( // coverage-disable-line
msg.sender == address(WETH),
"Cannot receive ETH"
);
);*/
}

function operate(
Expand Down

0 comments on commit 9aa63d2

Please sign in to comment.