Skip to content

Commit

Permalink
chore: keeper fulfill request with ETH
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoujia6139 committed May 30, 2023
1 parent 300172c commit 533c103
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion contracts/interfaces/IPoolMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ interface IPoolMarketplace {
*/
function fulfillAcceptBlurBidsRequest(
DataTypes.AcceptBlurBidsRequest[] calldata requests
) external;
) external payable;

/**
* @notice Reject accept blur bids for underlying request if the blur selling transaction is failed.
Expand Down
10 changes: 6 additions & 4 deletions contracts/protocol/libraries/logic/PoolExtendedLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ library PoolExtendedLogic {
require(msg.sender == keeper, Errors.CALLER_NOT_KEEPER);

uint256 requestLength = requests.length;
uint256 totalWETH = 0;
uint256 totalETH = 0;
address currentOwner;
for (uint256 index = 0; index < requestLength; index++) {
DataTypes.AcceptBlurBidsRequest calldata request = requests[index];
Expand Down Expand Up @@ -533,7 +533,7 @@ library PoolExtendedLogic {
}

// calculate and accumulate weth
totalWETH += (request.bidingPrice - request.marketPlaceFee);
totalETH += (request.bidingPrice - request.marketPlaceFee);

// update request status
delete ps._blurExchangeRequestStatus[requestHash];
Expand Down Expand Up @@ -561,11 +561,13 @@ library PoolExtendedLogic {
request.bidOrderHash
);
}
require(msg.value == totalETH, Errors.INVALID_ETH_VALUE);

//supply eth for current ntoken owner
if (totalWETH > 0) {
if (totalETH > 0) {
address weth = poolAddressProvider.getWETH();
supplyForUser(ps, weth, keeper, currentOwner, totalWETH);
IWETH(weth).deposit{value: msg.value}();
supplyForUser(ps, weth, address(this), currentOwner, totalETH);
}

// update ongoing request amount
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/pool/PoolMarketplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ contract PoolMarketplace is
/// @inheritdoc IPoolMarketplace
function fulfillAcceptBlurBidsRequest(
DataTypes.AcceptBlurBidsRequest[] calldata requests
) external virtual override {
) external payable override {
DataTypes.PoolStorage storage ps = poolStorage();
PoolExtendedLogic.executeFulfillAcceptBlurBidsRequest(
ps,
Expand Down
41 changes: 36 additions & 5 deletions test/_blur_sell_integraion_marketplace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ describe("BLUR Sell Integration Tests", () => {
await waitForTx(
await pool
.connect(user2.signer)
.fulfillAcceptBlurBidsRequest([
AcceptBaycBidsRequest,
AcceptMaycBidsRequest,
])
.fulfillAcceptBlurBidsRequest(
[AcceptBaycBidsRequest, AcceptMaycBidsRequest],
{
value: parseEther("168"),
}
)
);

almostEqual(await pWETH.balanceOf(user1.address), parseEther("168"));
Expand Down Expand Up @@ -698,7 +700,9 @@ describe("BLUR Sell Integration Tests", () => {
await waitForTx(
await pool
.connect(user2.signer)
.fulfillAcceptBlurBidsRequest([AcceptBaycBidsRequest])
.fulfillAcceptBlurBidsRequest([AcceptBaycBidsRequest], {
value: parseEther("109"),
})
);

expect(await nBAYC.balanceOf(user1.address)).to.be.eq(0);
Expand Down Expand Up @@ -786,4 +790,31 @@ describe("BLUR Sell Integration Tests", () => {
.initiateAcceptBlurBidsRequest([InvalidAcceptBaycBidsRequest])
).to.be.revertedWith(ProtocolErrors.NOT_THE_OWNER);
});

it("fulfill requests failed if transaction value is wrong", async () => {
const {
pool,
users: [user1, user2],
} = await loadFixture(fixture);

await waitForTx(
await pool
.connect(user1.signer)
.initiateAcceptBlurBidsRequest([
AcceptBaycBidsRequest,
AcceptMaycBidsRequest,
])
);

await expect(
pool
.connect(user2.signer)
.fulfillAcceptBlurBidsRequest(
[AcceptBaycBidsRequest, AcceptMaycBidsRequest],
{
value: parseEther("100"),
}
)
).to.be.revertedWith(ProtocolErrors.INVALID_ETH_VALUE);
});
});

0 comments on commit 533c103

Please sign in to comment.