Skip to content

Commit

Permalink
feat: Add currentBid function to PCOBaseFacet
Browse files Browse the repository at this point in the history
  • Loading branch information
codynhat committed Aug 18, 2022
1 parent d2be20b commit f6edbe8
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "currentBid",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "bidder",
"type": "address"
},
{
"internalType": "int96",
"name": "contributionRate",
"type": "int96"
},
{
"internalType": "uint256",
"name": "perSecondFeeNumerator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "perSecondFeeDenominator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "forSalePrice",
"type": "uint256"
}
],
"internalType": "struct LibCFABasePCO.Bid",
"name": "",
"type": "tuple"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "forSalePrice",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,51 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "currentBid",
"outputs": [
{
"components": [
{
"internalType": "uint256",
"name": "timestamp",
"type": "uint256"
},
{
"internalType": "address",
"name": "bidder",
"type": "address"
},
{
"internalType": "int96",
"name": "contributionRate",
"type": "int96"
},
{
"internalType": "uint256",
"name": "perSecondFeeNumerator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "perSecondFeeDenominator",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "forSalePrice",
"type": "uint256"
}
],
"internalType": "struct LibCFABasePCO.Bid",
"name": "",
"type": "tuple"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [],
"name": "forSalePrice",
Expand Down
35 changes: 22 additions & 13 deletions contracts/pco-license/facets/CFABasePCOFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

contract CFABasePCOFacetModifiers {
modifier onlyPayer() {
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
require(
msg.sender == currentBid.bidder,
msg.sender == _currentBid.bidder,
"CFABasePCOFacet: Only payer is allowed to perform this action"
);
_;
Expand Down Expand Up @@ -110,13 +110,13 @@ contract CFABasePCOFacet is IBasePCO, CFABasePCOFacetModifiers {
// Create flow (license -> beneficiary)
cs.cfaV1.createFlow(beneficiary, paymentToken, newContributionRate);

LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
currentBid.timestamp = block.timestamp;
currentBid.bidder = bidder;
currentBid.contributionRate = newContributionRate;
currentBid.perSecondFeeNumerator = perSecondFeeNumerator;
currentBid.perSecondFeeDenominator = perSecondFeeDenominator;
currentBid.forSalePrice = newForSalePrice;
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
_currentBid.timestamp = block.timestamp;
_currentBid.bidder = bidder;
_currentBid.contributionRate = newContributionRate;
_currentBid.perSecondFeeNumerator = perSecondFeeNumerator;
_currentBid.perSecondFeeDenominator = perSecondFeeDenominator;
_currentBid.forSalePrice = newForSalePrice;

emit PayerForSalePriceUpdated(bidder, newForSalePrice);
emit PayerContributionRateUpdated(bidder, newContributionRate);
Expand All @@ -126,8 +126,8 @@ contract CFABasePCOFacet is IBasePCO, CFABasePCOFacetModifiers {
* @notice Current payer of license
*/
function payer() public view returns (address) {
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
return currentBid.bidder;
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
return _currentBid.bidder;
}

/**
Expand All @@ -142,8 +142,8 @@ contract CFABasePCOFacet is IBasePCO, CFABasePCOFacetModifiers {
*/
function forSalePrice() external view returns (uint256) {
if (LibCFABasePCO._isPayerBidActive()) {
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
return currentBid.forSalePrice;
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
return _currentBid.forSalePrice;
} else {
return 0;
}
Expand Down Expand Up @@ -173,4 +173,13 @@ contract CFABasePCOFacet is IBasePCO, CFABasePCOFacetModifiers {
function isPayerBidActive() external view returns (bool) {
return LibCFABasePCO._isPayerBidActive();
}

/**
* @notice Get current bid
*/
function currentBid() external pure returns (LibCFABasePCO.Bid memory) {
LibCFABasePCO.Bid storage bid = LibCFABasePCO._currentBid();

return bid;
}
}
24 changes: 12 additions & 12 deletions contracts/pco-license/facets/CFAPenaltyBidFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
modifier onlyDuringBidPeriod() {
LibCFAPenaltyBid.Bid storage _pendingBid = LibCFAPenaltyBid
.pendingBid();
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();

LibCFABasePCO.DiamondStorage storage ds = LibCFABasePCO
.diamondStorage();
Expand Down Expand Up @@ -168,7 +168,7 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
.getPerSecondFeeDenominator();

// Check for sale price
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();

require(
LibCFABasePCO._checkForSalePrice(
Expand All @@ -181,7 +181,7 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
);

require(
newContributionRate >= currentBid.contributionRate,
newContributionRate >= _currentBid.contributionRate,
"CFAPenaltyBidFacet: New contribution rate is not high enough"
);

Expand Down Expand Up @@ -246,12 +246,12 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
{
LibCFAPenaltyBid.Bid storage _pendingBid = LibCFAPenaltyBid
.pendingBid();
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();

emit BidAccepted(
currentBid.bidder,
_currentBid.bidder,
_pendingBid.bidder,
currentBid.forSalePrice
_currentBid.forSalePrice
);

LibCFAPenaltyBid._triggerTransfer();
Expand All @@ -272,12 +272,12 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
{
LibCFAPenaltyBid.Bid storage _pendingBid = LibCFAPenaltyBid
.pendingBid();
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();

emit BidRejected(
currentBid.bidder,
_currentBid.bidder,
_pendingBid.bidder,
currentBid.forSalePrice
_currentBid.forSalePrice
);

LibCFAPenaltyBid._rejectBid();
Expand All @@ -291,13 +291,13 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
function triggerTransfer() external onlyIfPendingBid onlyAfterBidPeriod {
LibCFAPenaltyBid.Bid storage _pendingBid = LibCFAPenaltyBid
.pendingBid();
LibCFABasePCO.Bid storage currentBid = LibCFABasePCO.currentBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();

emit TransferTriggered(
msg.sender,
currentBid.bidder,
_currentBid.bidder,
_pendingBid.bidder,
currentBid.forSalePrice
_currentBid.forSalePrice
);

LibCFAPenaltyBid._triggerTransfer();
Expand Down
31 changes: 14 additions & 17 deletions contracts/pco-license/libraries/LibCFABasePCO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ library LibCFABasePCO {
}

/// @dev Store currentBid in separate position so struct is upgradeable
function currentBid() internal pure returns (Bid storage bid) {
function _currentBid() internal pure returns (Bid storage bid) {
bytes32 position = STORAGE_POSITION_CUR_BID;
assembly {
bid.slot := position
Expand Down Expand Up @@ -110,7 +110,7 @@ library LibCFABasePCO {
{
DiamondStorage storage ds = diamondStorage();
DiamondCFAStorage storage cs = cfaStorage();
Bid storage _currentBid = currentBid();
Bid storage bid = _currentBid();

uint256 perSecondFeeNumerator = ds
.paramsStore
Expand All @@ -133,21 +133,21 @@ library LibCFABasePCO {

(, int96 flowRate, , ) = cs.cfaV1.cfa.getFlow(
paymentToken,
_currentBid.bidder,
bid.bidder,
address(this)
);
if (flowRate > 0) {
// Update flow (payer -> license)
cs.cfaV1.updateFlowByOperator(
_currentBid.bidder,
bid.bidder,
address(this),
paymentToken,
newContributionRate
);
} else {
// Recreate flow (payer -> license)
cs.cfaV1.createFlowByOperator(
_currentBid.bidder,
bid.bidder,
address(this),
paymentToken,
newContributionRate
Expand All @@ -168,17 +168,14 @@ library LibCFABasePCO {
cs.cfaV1.createFlow(beneficiary, paymentToken, newContributionRate);
}

_currentBid.timestamp = block.timestamp;
_currentBid.bidder = _currentBid.bidder;
_currentBid.contributionRate = newContributionRate;
_currentBid.perSecondFeeNumerator = perSecondFeeNumerator;
_currentBid.perSecondFeeDenominator = perSecondFeeDenominator;
_currentBid.forSalePrice = newForSalePrice;

emit PayerForSalePriceUpdated(_currentBid.bidder, newForSalePrice);
emit PayerContributionRateUpdated(
_currentBid.bidder,
newContributionRate
);
bid.timestamp = block.timestamp;
bid.bidder = bid.bidder;
bid.contributionRate = newContributionRate;
bid.perSecondFeeNumerator = perSecondFeeNumerator;
bid.perSecondFeeDenominator = perSecondFeeDenominator;
bid.forSalePrice = newForSalePrice;

emit PayerForSalePriceUpdated(bid.bidder, newForSalePrice);
emit PayerContributionRateUpdated(bid.bidder, newContributionRate);
}
}
Loading

0 comments on commit f6edbe8

Please sign in to comment.