Skip to content

Commit

Permalink
feat: add editContentHash function
Browse files Browse the repository at this point in the history
  • Loading branch information
codynhat committed Jun 27, 2023
1 parent deda5c9 commit 6cc6307
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 27 deletions.
38 changes: 22 additions & 16 deletions contracts/pco-license/facets/CFAPenaltyBidFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ contract CFAPenaltyBidFacet is ICFAPenaltyBid, CFABasePCOFacetModifiers {
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function editBid(int96 newContributionRate, uint256 newForSalePrice)
external
onlyPayer
onlyIfNotPendingBid
{
function editBid(
int96 newContributionRate,
uint256 newForSalePrice
) external onlyPayer onlyIfNotPendingBid {
LibCFABasePCO._editBid(newContributionRate, newForSalePrice);
}

Expand All @@ -142,18 +141,27 @@ contract CFAPenaltyBidFacet is ICFAPenaltyBid, CFABasePCOFacetModifiers {
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function placeBid(int96 newContributionRate, uint256 newForSalePrice)
external
onlyIfPayerBidActive
onlyNotPayer
{
function placeBid(
int96 newContributionRate,
uint256 newForSalePrice
) external onlyIfPayerBidActive onlyNotPayer {
LibCFAPenaltyBid._placeBid(
newContributionRate,
newForSalePrice,
new bytes(0)
);
}

/**
* @notice Edit content hash
* - Must be the current payer
* - Must have permissions to update flow for payer
* @param contentHash Content hash for parcel content
*/
function editContentHash(bytes calldata contentHash) external onlyPayer {
LibCFABasePCO._editContentHash(contentHash);
}

/**
* @notice Edit bid with content hash
* - Must be the current payer
Expand Down Expand Up @@ -230,12 +238,10 @@ contract CFAPenaltyBidFacet is ICFAPenaltyBid, CFABasePCOFacetModifiers {
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function rejectBid(int96 newContributionRate, uint256 newForSalePrice)
external
onlyPayer
onlyIfPendingBid
onlyDuringBidPeriod
{
function rejectBid(
int96 newContributionRate,
uint256 newForSalePrice
) external onlyPayer onlyIfPendingBid onlyDuringBidPeriod {
LibCFAPenaltyBid.Bid storage _pendingBid = LibCFAPenaltyBid
.pendingBid();
LibCFABasePCO.Bid storage _currentBid = LibCFABasePCO._currentBid();
Expand Down
26 changes: 20 additions & 6 deletions contracts/pco-license/interfaces/ICFAPenaltyBid.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ interface ICFAPenaltyBid {
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function editBid(int96 newContributionRate, uint256 newForSalePrice)
external;
function editBid(
int96 newContributionRate,
uint256 newForSalePrice
) external;

/**
* @notice Place a bid to purchase license as msg.sender
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function placeBid(int96 newContributionRate, uint256 newForSalePrice)
external;
function placeBid(
int96 newContributionRate,
uint256 newForSalePrice
) external;

/**
* @notice Accept a pending bid as the current payer
Expand All @@ -79,8 +83,10 @@ interface ICFAPenaltyBid {
* @param newContributionRate New contribution rate for bid
* @param newForSalePrice Intented new for sale price. Must be within rounding bounds of newContributionRate
*/
function rejectBid(int96 newContributionRate, uint256 newForSalePrice)
external;
function rejectBid(
int96 newContributionRate,
uint256 newForSalePrice
) external;

/**
* @notice Trigger a transfer after bidding period has elapsed
Expand Down Expand Up @@ -110,4 +116,12 @@ interface ICFAPenaltyBid {
uint256 newForSalePrice,
bytes calldata contentHash
) external;

/**
* @notice Edit content hash
* - Must be the current payer
* - Must have permissions to update flow for payer
* @param contentHash Content hash for parcel content
*/
function editContentHash(bytes calldata contentHash) external;
}
8 changes: 8 additions & 0 deletions contracts/pco-license/libraries/LibCFABasePCO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ library LibCFABasePCO {
_editBid(newContributionRate, newForSalePrice, bid.contentHash);
}

function _editContentHash(bytes memory contentHash) internal {
Bid storage bid = _currentBid();

bid.contentHash = contentHash;

emit PayerContentHashUpdated(bid.bidder, contentHash);
}

function _editBid(
int96 newContributionRate,
uint256 newForSalePrice,
Expand Down
34 changes: 34 additions & 0 deletions test/pco-license/CFAPenaltyBidFacet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,40 @@ describe("CFAPenaltyBidFacet", async function () {
});
});

describe("editContentHash", async () => {
it("should edit", async () => {
const { basePCOFacet } = await BaseFixtures.initialized();
const { user } = await getNamedAccounts();

const txn = await basePCOFacet
.connect(await ethers.getSigner(user))
["editContentHash(bytes)"]("0x13");
await txn.wait();

expect(await basePCOFacet.contentHash()).to.equal("0x13");
});

it("should edit if has pending bid", async () => {
const { basePCOFacet } = await CFAPenaltyBidFixtures.afterPlaceBid();
const { user } = await getNamedAccounts();

const txn = await basePCOFacet
.connect(await ethers.getSigner(user))
["editContentHash(bytes)"]("0x13");
await txn.wait();
});

it("should fail if not payer", async () => {
const { basePCOFacet } = await BaseFixtures.initialized();

const txn = basePCOFacet["editContentHash(bytes)"]("0x13");

await expect(txn).to.be.revertedWith(
"CFABasePCOFacet: Only payer is allowed to perform this action"
);
});
});

describe("placeBid with content hash", async () => {
it("should place bid with create permissions", async () => {
const {
Expand Down
2 changes: 1 addition & 1 deletion typechain-types/factories/CFABasePCOFacet__factory.ts

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion typechain-types/factories/CFAPenaltyBidFacet__factory.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typechain-types/factories/PCOLicenseDiamond__factory.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion typechain-types/factories/RegistryDiamond__factory.ts

Large diffs are not rendered by default.

0 comments on commit 6cc6307

Please sign in to comment.