Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Fix maxPotentialDebt check in lien buyout (Spearbit #110) (#211)
Browse files Browse the repository at this point in the history
* moved potentialDebt buyout check to after new lien is added to stack

* check the junior positions maxPotentialDebt's are being upheld on buyout

* cleanup

Co-authored-by: Andrew Redden <opensource@andrewredden.com>
Co-authored-by: Andrew Redden <=>
  • Loading branch information
2 people authored and dangerousfood committed Dec 21, 2022
1 parent b399531 commit 4a0ebb4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/seaport
Submodule seaport updated 70 files
+20 −1 .github/workflows/test.yml
+8 −1 .gitignore
+1 −1 .prettierrc.js
+3 −0 config/.solcover-reference.js
+3 −0 config/.solcover.js
+8 −0 contracts/interfaces/AbridgedTokenInterfaces.sol
+5 −0 contracts/interfaces/ConsiderationInterface.sol
+43 −0 contracts/interfaces/ContractOffererInterface.sol
+5 −0 contracts/interfaces/SeaportInterface.sol
+4 −2 contracts/lib/AmountDeriver.sol
+10 −6 contracts/lib/Assertions.sol
+22 −20 contracts/lib/BasicOrderFulfiller.sol
+11 −2 contracts/lib/Consideration.sol
+23 −5 contracts/lib/ConsiderationBase.sol
+483 −59 contracts/lib/ConsiderationConstants.sol
+4 −1 contracts/lib/ConsiderationEnums.sol
+299 −0 contracts/lib/ConsiderationErrors.sol
+8 −8 contracts/lib/CriteriaResolution.sol
+18 −7 contracts/lib/Executor.sol
+28 −35 contracts/lib/FulfillmentApplier.sol
+14 −13 contracts/lib/GettersAndDerivers.sol
+42 −0 contracts/lib/LowLevelHelpers.sol
+121 −66 contracts/lib/OrderCombiner.sol
+16 −9 contracts/lib/OrderFulfiller.sol
+355 −40 contracts/lib/OrderValidator.sol
+2 −2 contracts/lib/ReentrancyGuard.sol
+22 −12 contracts/lib/SignatureVerification.sol
+52 −38 contracts/lib/TokenTransferrer.sol
+48 −37 contracts/lib/TokenTransferrerConstants.sol
+96 −15 contracts/lib/Verifiers.sol
+68 −20 contracts/lib/ZoneInteraction.sol
+250 −0 contracts/test/TestContractOfferer.sol
+68 −0 contracts/test/TestPostExecution.sol
+35 −0 eip-712-types/bulkOrder.js
+27 −9 foundry.toml
+1 −1 hardhat-coverage.config.ts
+10 −2 hardhat.config.ts
+1 −1 lib/forge-std
+46 −0 offerers/TestPoolFactory.sol
+340 −0 offerers/TestPoolOfferer.sol
+560 −0 offerers/test/TestPoolOfferer.t.sol
+45,910 −0 package-lock.json
+14 −3 package.json
+9 −0 reference/ReferenceConsideration.sol
+24 −23 reference/lib/ReferenceBasicOrderFulfiller.sol
+17 −0 reference/lib/ReferenceConsiderationBase.sol
+105 −69 reference/lib/ReferenceOrderCombiner.sol
+13 −6 reference/lib/ReferenceOrderFulfiller.sol
+298 −34 reference/lib/ReferenceOrderValidator.sol
+59 −0 reference/lib/ReferenceVerifiers.sol
+4 −2 reference/lib/ReferenceZoneInteraction.sol
+2 −0 reference/shim/Shim.sol
+7 −5 remappings.txt
+1,736 −0 test/advanced.spec.ts
+151 −1 test/basic.spec.ts
+1 −1 test/foundry/GetterTests.t.sol
+535 −0 test/foundry/offerers/TestPoolOfferrer.t.sol
+1 −1 test/foundry/utils/BaseConsiderationTest.sol
+2 −2 test/utils/contracts.ts
+128 −0 test/utils/eip712/Eip712MerkleTree.ts
+45 −0 test/utils/eip712/bulk-orders.ts
+46 −0 test/utils/eip712/code-gen.ts
+113 −0 test/utils/eip712/defaults.ts
+239 −0 test/utils/eip712/eip712-merkle.ts
+54 −0 test/utils/eip712/utils.ts
+4 −0 test/utils/fixtures/index.ts
+60 −2 test/utils/fixtures/marketplace.ts
+4 −0 test/utils/types.ts
+6 −10 test/zone.spec.ts
+816 −1,893 yarn.lock
47 changes: 29 additions & 18 deletions src/LienToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,6 @@ contract LienToken is ERC721, ILienToken, Auth {
params.encumber.stack[params.position]
);

if (
_getMaxPotentialDebtForCollateral(params.encumber.stack) >
params.encumber.lien.details.maxPotentialDebt
) {
revert InvalidState(InvalidStates.DEBT_LIMIT);
}

if (params.encumber.lien.details.maxAmount < owed) {
revert InvalidBuyoutDetails(params.encumber.lien.details.maxAmount, owed);
}
Expand Down Expand Up @@ -171,10 +164,31 @@ contract LienToken is ERC721, ILienToken, Auth {
params.encumber.stack,
params.position,
newLien,
params.encumber.stack[params.position].point.lienId,
newLien.point.lienId
params.encumber.stack[params.position].point.lienId
);

uint256 maxPotentialDebt;
uint256 n = newStack.length;
uint256 i;
for (i; i < n; ) {
maxPotentialDebt += _getOwed(newStack[i], newStack[i].point.end);
//no need to check validity before the position we're buying
if (i == params.position) {
if (maxPotentialDebt > params.encumber.lien.details.maxPotentialDebt) {
revert InvalidState(InvalidStates.DEBT_LIMIT);
}
}
if (
i > params.position &&
(maxPotentialDebt > newStack[i].lien.details.maxPotentialDebt)
) {
revert InvalidState(InvalidStates.DEBT_LIMIT);
}
unchecked {
++i;
}
}

s.collateralStateHash[params.encumber.collateralId] = keccak256(
abi.encode(newStack)
);
Expand All @@ -185,8 +199,7 @@ contract LienToken is ERC721, ILienToken, Auth {
ILienToken.Stack[] calldata stack,
uint256 position,
Stack memory newLien,
uint256 oldLienId,
uint256 newLienId
uint256 oldLienId
) internal returns (ILienToken.Stack[] memory newStack) {
newStack = stack;
newStack[position] = newLien;
Expand Down Expand Up @@ -646,15 +659,13 @@ contract LienToken is ERC721, ILienToken, Auth {
validateStack(stack[0].lien.collateralId, stack)
returns (uint256 maxPotentialDebt)
{
return _getMaxPotentialDebtForCollateral(stack);
return _getMaxPotentialDebtForCollateralUpToNPositions(stack, stack.length);
}

function _getMaxPotentialDebtForCollateral(Stack[] memory stack)
internal
pure
returns (uint256 maxPotentialDebt)
{
uint256 n = stack.length;
function _getMaxPotentialDebtForCollateralUpToNPositions(
Stack[] memory stack,
uint256 n
) internal pure returns (uint256 maxPotentialDebt) {
for (uint256 i; i < n; ) {
maxPotentialDebt += _getOwed(stack[i], stack[i].point.end);
unchecked {
Expand Down

0 comments on commit 4a0ebb4

Please sign in to comment.