Skip to content

Commit

Permalink
debartify
Browse files Browse the repository at this point in the history
  • Loading branch information
Barry Lyndon committed Sep 8, 2022
1 parent 128baf3 commit 8fe3ac2
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module.exports = {
{
files: "*.ts",
options: {
printWidth: 145,
printWidth: 80,
semi: true,
trailingComma: "es5",
},
},
{
files: "*.sol",
options: {
printWidth: 140,
printWidth: 80,
tabWidth: 4,
useTabs: false,
singleQuote: false,
Expand Down
57 changes: 48 additions & 9 deletions contracts/LendingClub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {
address private immutable ops;
address payable private immutable gelato;
IERC20 private immutable WETH;
ISeaport private constant seaport = ISeaport(0x00000000006c3852cbEf3e08E8dF289169EdE581);
ISeaport private constant seaport =
ISeaport(0x00000000006c3852cbEf3e08E8dF289169EdE581);

constructor(address _ops, IERC20 _WETH) public {
ops = _ops;
Expand All @@ -49,7 +50,15 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {
}

function init(bytes calldata data) public payable {
(nftPair, owner, oracle, annualInterestBPS, ltvBPS, relistBPS, maxDuration) = abi.decode(
(
nftPair,
owner,
oracle,
annualInterestBPS,
ltvBPS,
relistBPS,
maxDuration
) = abi.decode(
data,
(INFTPair, address, INFTOracle, uint16, uint16, uint16, uint32)
);
Expand All @@ -61,7 +70,14 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {
// TODO: check whether this is exploitable (i think not)
nftPair.collateral().setApprovalForAll(address(seaport), true);

nftPair.bentoBox().setMasterContractApproval(address(this), address(nftPair.masterContract()), true, 0, bytes32(0), bytes32(0));
nftPair.bentoBox().setMasterContractApproval(
address(this),
address(nftPair.masterContract()),
true,
0,
bytes32(0),
bytes32(0)
);
}

function willLend(
Expand All @@ -84,16 +100,27 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {

// valuation can be smaller than what is to be expected, same for duration

return oracle == _oracle && valuation <= _valuation && duration <= maxDuration && _annualInterestBPS >= annualInterestBPS;
return
oracle == _oracle &&
valuation <= _valuation &&
duration <= maxDuration &&
_annualInterestBPS >= annualInterestBPS;
}

function lendingConditions(address _nftPair, uint256 tokenId) external view returns (TokenLoanParamsWithOracle[] memory) {
function lendingConditions(address _nftPair, uint256 tokenId)
external
view
returns (TokenLoanParamsWithOracle[] memory)
{
if (_nftPair != address(nftPair)) {
TokenLoanParamsWithOracle[] memory empty;
return empty;
} else {
TokenLoanParamsWithOracle[] memory conditions = new TokenLoanParamsWithOracle[](4);
uint128 valuation = uint128((oracle.peekSpot(_nftPair, tokenId) * uint256(ltvBPS)) / BPS);
TokenLoanParamsWithOracle[]
memory conditions = new TokenLoanParamsWithOracle[](4);
uint128 valuation = uint128(
(oracle.peekSpot(_nftPair, tokenId) * uint256(ltvBPS)) / BPS
);
for (uint256 i; i < 4; i++) {
conditions[i].valuation = valuation;
conditions[i].duration = uint64((maxDuration * i) / 4);
Expand All @@ -115,7 +142,13 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {
nftPair.removeCollateral(tokenId, address(this));
}

nftPair.bentoBox().withdraw(IERC20(address(0)), address(this), gelato, fee, 0);
nftPair.bentoBox().withdraw(
IERC20(address(0)),
address(this),
gelato,
fee,
0
);

seaport.validate(orders);
}
Expand All @@ -125,6 +158,12 @@ contract LendingClubWETH is BoringOwnable, ILendingClub {
}

function withdrawFunds(uint256 bentoShares, address to) external onlyOwner {
nftPair.bentoBox().withdraw(nftPair.asset(), address(this), to, 0, bentoShares);
nftPair.bentoBox().withdraw(
nftPair.asset(),
address(this),
to,
0,
bentoShares
);
}
}
40 changes: 33 additions & 7 deletions contracts/mocks/LendingClubMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ contract LendingClubMock {
}

function init() public {
nftPair.bentoBox().setMasterContractApproval(address(this), address(nftPair.masterContract()), true, 0, bytes32(0), bytes32(0));
nftPair.bentoBox().setMasterContractApproval(
address(this),
address(nftPair.masterContract()),
true,
0,
bytes32(0),
bytes32(0)
);
}

function willLend(
Expand All @@ -31,18 +38,28 @@ contract LendingClubMock {
if (msg.sender != address(nftPair)) {
return false;
}
TokenLoanParamsWithOracle memory accepted = _lendingConditions(tokenId)[0];
TokenLoanParamsWithOracle memory accepted = _lendingConditions(tokenId)[
0
];
// Valuation has to be an exact match, everything else must be at least
// as good for the lender as `accepted`.

return valuation == accepted.valuation && duration <= accepted.duration && annualInterestBPS >= accepted.annualInterestBPS;
return
valuation == accepted.valuation &&
duration <= accepted.duration &&
annualInterestBPS >= accepted.annualInterestBPS;
}

function _lendingConditions(uint256 tokenId) private pure returns (TokenLoanParamsWithOracle[] memory) {
function _lendingConditions(uint256 tokenId)
private
pure
returns (TokenLoanParamsWithOracle[] memory)
{
// No specific conditions given, but we'll take all even-numbered
// ones at 100% APY:
if (tokenId % 2 == 0) {
TokenLoanParamsWithOracle[] memory conditions = new TokenLoanParamsWithOracle[](1);
TokenLoanParamsWithOracle[]
memory conditions = new TokenLoanParamsWithOracle[](1);
// 256-bit addition fits by the above check.
// Cast is.. relatively safe: this is a mock implementation,
// production use is unlikely to follow this pattern for valuing
Expand All @@ -58,7 +75,11 @@ contract LendingClubMock {
}
}

function lendingConditions(address _nftPair, uint256 tokenId) external view returns (TokenLoanParamsWithOracle[] memory) {
function lendingConditions(address _nftPair, uint256 tokenId)
external
view
returns (TokenLoanParamsWithOracle[] memory)
{
if (_nftPair != address(nftPair)) {
TokenLoanParamsWithOracle[] memory empty;
return empty;
Expand All @@ -72,6 +93,11 @@ contract LendingClubMock {
}

function withdrawFunds(uint256 bentoShares) external {
nftPair.bentoBox().transfer(nftPair.asset(), address(this), investor, bentoShares);
nftPair.bentoBox().transfer(
nftPair.asset(),
address(this),
investor,
bentoShares
);
}
}

4 comments on commit 8fe3ac2

@boringcrypto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ROFL :P

@wenakita
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont get it :(

@boringcrypto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not you, you can't know ;)

@wenakita
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not you, you can't know ;)

Nooooooooooooooooooooo :(

Please sign in to comment.