From b12bf5de408c5a2b52f8a0e4516edf7e89b523f7 Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Tue, 6 Dec 2022 13:21:41 -0300 Subject: [PATCH 1/7] feat: arbitrator calculation --- contracts/Unicrow.sol | 20 ++++++++----- contracts/UnicrowArbitrator.sol | 34 +++++++++++---------- contracts/UnicrowClaim.sol | 52 ++++++++++++++++----------------- 3 files changed, 55 insertions(+), 51 deletions(-) diff --git a/contracts/Unicrow.sol b/contracts/Unicrow.sol index 436fe0e..03e753c 100644 --- a/contracts/Unicrow.sol +++ b/contracts/Unicrow.sol @@ -363,9 +363,9 @@ contract Unicrow is ReentrancyGuard, IUnicrow, Context { // Discount the protocol fee based on seller's share if (currentSplit[WHO_PROTOCOL] > 0) { - split[WHO_PROTOCOL] = uint16( + (split[WHO_PROTOCOL] = uint16( uint256(currentSplit[WHO_PROTOCOL]) * - currentSplit[WHO_SELLER] / + currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS ); } @@ -373,16 +373,20 @@ contract Unicrow is ReentrancyGuard, IUnicrow, Context { // Discount the marketplace fee based on the seller's share if (currentSplit[WHO_MARKETPLACE] > 0) { split[WHO_MARKETPLACE] = uint16( - uint256(currentSplit[WHO_MARKETPLACE]) * - currentSplit[WHO_SELLER] / + (uint256(currentSplit[WHO_MARKETPLACE]) * + currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS ); } - // Discount the arbitrator's fee based on the seller's share - calculatedArbitratorFee = uint16( - uint256(currentSplit[WHO_ARBITRATOR]) * currentSplit[WHO_SELLER] / _100_PCT_IN_BIPS - ); + // Calculate the arbitrator fee based on the seller's share + if (currentSplit[WHO_ARBITRATOR] > 0) { + calculatedArbitratorFee = uint16( + (uint256(currentSplit[WHO_ARBITRATOR]) * + currentSplit[WHO_SELLER]) / + _100_PCT_IN_BIPS + ); + } // Calculate seller's final share by substracting all the fees unchecked { diff --git a/contracts/UnicrowArbitrator.sol b/contracts/UnicrowArbitrator.sol index b6a38dc..9760a1e 100644 --- a/contracts/UnicrowArbitrator.sol +++ b/contracts/UnicrowArbitrator.sol @@ -238,25 +238,27 @@ contract UnicrowArbitrator is IUnicrowArbitrator, Context, ReentrancyGuard { uint16 calculatedSellerArbitratorFee; uint16 calculatedBuyerArbitratorFee; - // Calculate buyer's portion of the arbitrator fee - calculatedBuyerArbitratorFee = uint16( - uint256(currentSplit[WHO_ARBITRATOR]) - * currentSplit[WHO_BUYER] + if(currentSplit[WHO_ARBITRATOR] > 0) { + // Calculate buyer's portion of the arbitrator fee + calculatedBuyerArbitratorFee = uint16( + (uint256(currentSplit[WHO_ARBITRATOR]) + * currentSplit[WHO_BUYER]) + / _100_PCT_IN_BIPS + ); + + // Seller's portion of the arbitrator fee + calculatedSellerArbitratorFee = uint16( + (uint256(currentSplit[WHO_ARBITRATOR]) + * currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS - ); - - // Seller's portion of the arbitrator fee - calculatedSellerArbitratorFee = uint16( - uint256(currentSplit[WHO_ARBITRATOR]) - * currentSplit[WHO_SELLER] - / _100_PCT_IN_BIPS - ); + ); + } // Protocol fee if (currentSplit[WHO_PROTOCOL] > 0) { split[WHO_PROTOCOL] = uint16( - uint256(currentSplit[WHO_PROTOCOL]) - * currentSplit[WHO_SELLER] + (uint256(currentSplit[WHO_PROTOCOL]) + * currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS ); } @@ -264,8 +266,8 @@ contract UnicrowArbitrator is IUnicrowArbitrator, Context, ReentrancyGuard { // Marketplace fee if (currentSplit[WHO_MARKETPLACE] > 0) { split[WHO_MARKETPLACE] = uint16( - uint256(currentSplit[WHO_MARKETPLACE]) - * currentSplit[WHO_SELLER] + (uint256(currentSplit[WHO_MARKETPLACE]) + * currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS ); } diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index b2ece91..7c508be 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -12,6 +12,7 @@ import "./interfaces/IUnicrowClaimRewards.sol"; import "./UnicrowArbitrator.sol"; import "./Unicrow.sol"; import "./UnicrowTypes.sol"; +import "hardhat/console.sol"; /** * @title Contract for managing claims from Unicrow's escrow @@ -107,9 +108,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { uint256[5] memory payments = calculatePayments( escrow.amount, calculatedSplits, - escrow.split[WHO_SELLER], - arbitratorData.arbitratorFee, - arbitratorData.arbitrated + arbitratorData.arbitratorFee ); address[5] memory addresses = [ @@ -165,9 +164,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { uint256[5] memory payments = calculatePayments( escrow.amount, calculatedSplits, - escrow.split[WHO_SELLER], - arbitratorData.arbitratorFee, - arbitratorData.arbitrated + arbitratorData.arbitratorFee ); // Prepare list of addresses for the withdrawals @@ -246,36 +243,37 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { * @dev Calculates actual amounts that should be sent to the parties * @param amount payment amount in escrow (in token) * @param split final splits - * @param fullSellerSplit seller split - * @param arbitratorFee Arbitrator fee - * @param arbitrated whether the payment was arbitrated (it impacts final arbitrator's fee for refunds) */ function calculatePayments( uint amount, uint16[4] memory split, - uint16 fullSellerSplit, - uint16 arbitratorFee, - bool arbitrated - ) internal pure returns(uint256[5] memory) { + uint16 arbitratorFee + ) internal returns(uint256[5] memory) { uint256[5] memory payments; // Multiply all the splits by the total amount - payments[WHO_BUYER] = uint256(split[WHO_BUYER]) * amount / _100_PCT_IN_BIPS; - payments[WHO_SELLER] = uint256(split[WHO_SELLER]) * amount / _100_PCT_IN_BIPS; - payments[WHO_MARKETPLACE] = uint256(split[WHO_MARKETPLACE]) * amount / _100_PCT_IN_BIPS; - payments[WHO_PROTOCOL] = uint256(split[WHO_PROTOCOL]) * amount / _100_PCT_IN_BIPS; - - if(!arbitrated) { - // If the payment wasn't arbitrated, the arbitrator fee is calculated from seller's share - // (normally 100%, but could be 0 for refund) - uint16 arbitratorFee_ = uint16(uint256(arbitratorFee) * fullSellerSplit / _100_PCT_IN_BIPS); - payments[WHO_ARBITRATOR] = uint256(arbitratorFee_) * amount / _100_PCT_IN_BIPS; - } else { - // If the arbitrator decided the payment, they get their full fee - // (in such case, buyer's split was reduced in the calling function) - payments[WHO_ARBITRATOR] = uint256(arbitratorFee)* amount / _100_PCT_IN_BIPS; + payments[WHO_BUYER] = (uint256(split[WHO_BUYER]) * amount) / _100_PCT_IN_BIPS; + payments[WHO_SELLER] = (uint256(split[WHO_SELLER]) * amount) / _100_PCT_IN_BIPS; + payments[WHO_MARKETPLACE] = (uint256(split[WHO_MARKETPLACE]) * amount) / _100_PCT_IN_BIPS; + + // If the arbitrator decided the payment, they get their full fee + // in such case, buyer's or seller split was reduced in the calling function) + payments[WHO_ARBITRATOR] = (uint256(arbitratorFee) * amount) / _100_PCT_IN_BIPS; + + unchecked { + payments[WHO_PROTOCOL] = amount - payments[WHO_BUYER] - payments[WHO_SELLER] - payments[WHO_MARKETPLACE] - payments[WHO_ARBITRATOR]; } + // console all the payments + console.log("amount", amount); + console.log("payments[WHO_BUYER]", payments[WHO_BUYER]); + console.log("payments[WHO_SELLER]", payments[WHO_SELLER]); + console.log("payments[WHO_MARKETPLACE]", payments[WHO_MARKETPLACE]); + console.log("payments[WHO_ARBITRATOR]", payments[WHO_ARBITRATOR]); + console.log("payments[WHO_ARBITRATOR]", payments[WHO_ARBITRATOR]); + + console.log("PAYMENTS[WHO_PROTOCOL]", payments[WHO_PROTOCOL]); + return payments; } From 0f6bf5c8a94371deda99c69bacc55690e4774839 Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Tue, 6 Dec 2022 15:26:17 -0300 Subject: [PATCH 2/7] fix: split calculation --- contracts/Unicrow.sol | 5 +++-- contracts/UnicrowArbitrator.sol | 6 ++++-- contracts/UnicrowClaim.sol | 35 +++++++++---------------------- contracts/interfaces/IUnicrow.sol | 2 +- test/UnicrowArbitrator.ts | 4 ++-- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/contracts/Unicrow.sol b/contracts/Unicrow.sol index 03e753c..6ea7f1a 100644 --- a/contracts/Unicrow.sol +++ b/contracts/Unicrow.sol @@ -356,8 +356,8 @@ contract Unicrow is ReentrancyGuard, IUnicrow, Context { /// @inheritdoc IUnicrow function splitCalculation( uint16[5] calldata currentSplit - ) external pure override returns (uint16[4] memory) { - uint16[4] memory split; + ) external pure override returns (uint16[5] memory) { + uint16[5] memory split; uint16 calculatedArbitratorFee; @@ -392,6 +392,7 @@ contract Unicrow is ReentrancyGuard, IUnicrow, Context { unchecked { split[WHO_SELLER] = currentSplit[WHO_SELLER] - split[WHO_PROTOCOL] - split[WHO_MARKETPLACE] - calculatedArbitratorFee; split[WHO_BUYER] = currentSplit[WHO_BUYER]; + split[WHO_ARBITRATOR] = calculatedArbitratorFee; } return split; diff --git a/contracts/UnicrowArbitrator.sol b/contracts/UnicrowArbitrator.sol index 9760a1e..b74a032 100644 --- a/contracts/UnicrowArbitrator.sol +++ b/contracts/UnicrowArbitrator.sol @@ -232,8 +232,8 @@ contract UnicrowArbitrator is IUnicrowArbitrator, Context, ReentrancyGuard { */ function arbitrationCalculation( uint16[5] calldata currentSplit - ) public pure returns (uint16[4] memory) { - uint16[4] memory split; + ) public pure returns (uint16[5] memory) { + uint16[5] memory split; uint16 calculatedSellerArbitratorFee; uint16 calculatedBuyerArbitratorFee; @@ -252,6 +252,8 @@ contract UnicrowArbitrator is IUnicrowArbitrator, Context, ReentrancyGuard { * currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS ); + + split[WHO_ARBITRATOR] = calculatedBuyerArbitratorFee + calculatedSellerArbitratorFee; } // Protocol fee diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index 7c508be..8cfe75c 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -99,7 +99,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { "0-006" ); - uint16[4] memory calculatedSplits = calculateSplits( + uint16[5] memory calculatedSplits = calculateSplits( arbitratorData.arbitratorFee, arbitratorData.arbitrated, escrow @@ -107,8 +107,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { uint256[5] memory payments = calculatePayments( escrow.amount, - calculatedSplits, - arbitratorData.arbitratorFee + calculatedSplits ); address[5] memory addresses = [ @@ -154,7 +153,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { ); // Calculate final splits (in bips) from gross splits - uint16[4] memory calculatedSplits = calculateSplits( + uint16[5] memory calculatedSplits = calculateSplits( arbitratorData.arbitratorFee, arbitratorData.arbitrated, escrow @@ -163,8 +162,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { // Calculate amounts to be sent in the token uint256[5] memory payments = calculatePayments( escrow.amount, - calculatedSplits, - arbitratorData.arbitratorFee + calculatedSplits ); // Prepare list of addresses for the withdrawals @@ -210,8 +208,8 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { uint16 arbitratorFee, bool arbitrated, Escrow memory escrow - ) internal view returns(uint16[4] memory) { - uint16[4] memory split; + ) internal view returns(uint16[5] memory) { + uint16[5] memory split; // The calculation will differ slightly based on whether the payment was decided by an arbitrator or not if(arbitrated) { @@ -246,9 +244,8 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { */ function calculatePayments( uint amount, - uint16[4] memory split, - uint16 arbitratorFee - ) internal returns(uint256[5] memory) { + uint16[5] memory split + ) internal pure returns(uint256[5] memory) { uint256[5] memory payments; // Multiply all the splits by the total amount @@ -258,21 +255,9 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { // If the arbitrator decided the payment, they get their full fee // in such case, buyer's or seller split was reduced in the calling function) - payments[WHO_ARBITRATOR] = (uint256(arbitratorFee) * amount) / _100_PCT_IN_BIPS; + payments[WHO_ARBITRATOR] = (uint256(split[WHO_ARBITRATOR]) * amount) / _100_PCT_IN_BIPS; - unchecked { - payments[WHO_PROTOCOL] = amount - payments[WHO_BUYER] - payments[WHO_SELLER] - payments[WHO_MARKETPLACE] - payments[WHO_ARBITRATOR]; - } - - // console all the payments - console.log("amount", amount); - console.log("payments[WHO_BUYER]", payments[WHO_BUYER]); - console.log("payments[WHO_SELLER]", payments[WHO_SELLER]); - console.log("payments[WHO_MARKETPLACE]", payments[WHO_MARKETPLACE]); - console.log("payments[WHO_ARBITRATOR]", payments[WHO_ARBITRATOR]); - console.log("payments[WHO_ARBITRATOR]", payments[WHO_ARBITRATOR]); - - console.log("PAYMENTS[WHO_PROTOCOL]", payments[WHO_PROTOCOL]); + payments[WHO_PROTOCOL] = amount - payments[WHO_BUYER] - payments[WHO_SELLER] - payments[WHO_MARKETPLACE] - payments[WHO_ARBITRATOR]; return payments; } diff --git a/contracts/interfaces/IUnicrow.sol b/contracts/interfaces/IUnicrow.sol index d55f134..1f46d01 100644 --- a/contracts/interfaces/IUnicrow.sol +++ b/contracts/interfaces/IUnicrow.sol @@ -69,7 +69,7 @@ interface IUnicrow { */ function splitCalculation( uint16[5] calldata currentSplit - ) external returns(uint16[4] memory); + ) external returns(uint16[5] memory); /** * @dev Get the escrow data (without arbitrator or settlement information) diff --git a/test/UnicrowArbitrator.ts b/test/UnicrowArbitrator.ts index fe5e2d3..bfe7c2e 100644 --- a/test/UnicrowArbitrator.ts +++ b/test/UnicrowArbitrator.ts @@ -351,7 +351,7 @@ describe("UnicrowArbitrator", function () { const escrowFee = await unicrowContract.protocolFee(); - const expectedResult = [0, 10000 - 100 - escrowFee, 0, escrowFee]; + const expectedResult = [0, 10000 - 100 - escrowFee, 0, escrowFee, 100]; expect( await unicrowArbitratorContract.arbitrationCalculation( @@ -379,7 +379,7 @@ describe("UnicrowArbitrator", function () { const [b, s, m, c ] = split; - const expectedResult = [4950, 4950, 0, 0]; + const expectedResult = [4950, 4950, 0, 0, 100]; expect( await unicrowArbitratorContract.arbitrationCalculation( From 73676d9fa20f0f544ffe288a35a1fa2f330d34eb Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Tue, 6 Dec 2022 15:27:23 -0300 Subject: [PATCH 3/7] chore: remove hardhat/console.sol --- contracts/UnicrowClaim.sol | 1 - 1 file changed, 1 deletion(-) diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index 8cfe75c..9a25a19 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -12,7 +12,6 @@ import "./interfaces/IUnicrowClaimRewards.sol"; import "./UnicrowArbitrator.sol"; import "./Unicrow.sol"; import "./UnicrowTypes.sol"; -import "hardhat/console.sol"; /** * @title Contract for managing claims from Unicrow's escrow From 5c30bf4ccc0e914771745f91184b6ebf114e55b8 Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Tue, 6 Dec 2022 15:54:27 -0300 Subject: [PATCH 4/7] fix: protocol fee calculation --- contracts/Unicrow.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Unicrow.sol b/contracts/Unicrow.sol index 6ea7f1a..1ea09a4 100644 --- a/contracts/Unicrow.sol +++ b/contracts/Unicrow.sol @@ -363,7 +363,7 @@ contract Unicrow is ReentrancyGuard, IUnicrow, Context { // Discount the protocol fee based on seller's share if (currentSplit[WHO_PROTOCOL] > 0) { - (split[WHO_PROTOCOL] = uint16( + split[WHO_PROTOCOL] = uint16(( uint256(currentSplit[WHO_PROTOCOL]) * currentSplit[WHO_SELLER]) / _100_PCT_IN_BIPS From 6f79589a185fa17bce448a3a0faca2d5c49df8ce Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Tue, 6 Dec 2022 15:56:29 -0300 Subject: [PATCH 5/7] chore: added comments --- contracts/UnicrowArbitrator.sol | 1 + contracts/UnicrowClaim.sol | 1 + 2 files changed, 2 insertions(+) diff --git a/contracts/UnicrowArbitrator.sol b/contracts/UnicrowArbitrator.sol index b74a032..fbc13e3 100644 --- a/contracts/UnicrowArbitrator.sol +++ b/contracts/UnicrowArbitrator.sol @@ -253,6 +253,7 @@ contract UnicrowArbitrator is IUnicrowArbitrator, Context, ReentrancyGuard { / _100_PCT_IN_BIPS ); + // Store how much the arbitrator will get from each party split[WHO_ARBITRATOR] = calculatedBuyerArbitratorFee + calculatedSellerArbitratorFee; } diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index 9a25a19..e9be7fe 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -256,6 +256,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { // in such case, buyer's or seller split was reduced in the calling function) payments[WHO_ARBITRATOR] = (uint256(split[WHO_ARBITRATOR]) * amount) / _100_PCT_IN_BIPS; + // The rest of the amount goes to the protocol payments[WHO_PROTOCOL] = amount - payments[WHO_BUYER] - payments[WHO_SELLER] - payments[WHO_MARKETPLACE] - payments[WHO_ARBITRATOR]; return payments; From 1b489ff4aef067b8289c647f82ace6d565515b55 Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Wed, 7 Dec 2022 11:49:51 -0300 Subject: [PATCH 6/7] fix: calculate arbitrator fee on calculateSplit --- contracts/UnicrowClaim.sol | 20 +++++++++----------- test/UnicrowClaim.ts | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index b2ece91..0795f62 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -99,8 +99,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { ); uint16[4] memory calculatedSplits = calculateSplits( - arbitratorData.arbitratorFee, - arbitratorData.arbitrated, + arbitratorData, escrow ); @@ -156,8 +155,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { // Calculate final splits (in bips) from gross splits uint16[4] memory calculatedSplits = calculateSplits( - arbitratorData.arbitratorFee, - arbitratorData.arbitrated, + arbitratorData, escrow ); @@ -205,26 +203,26 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { /** * @dev Calculates how the balance in the escrow should be split between all the relevant parties - * @param arbitratorFee Arbitrator information is not part of core escrow data, so fee is provided separately here - * @param arbitrated Whether the escrow was decided by an arbitrator + * @param arbitrator Arbitrator information is not part of core escrow data, so data is provided separately here * @param escrow Escrow information */ function calculateSplits( - uint16 arbitratorFee, - bool arbitrated, + Arbitrator memory arbitrator, Escrow memory escrow ) internal view returns(uint16[4] memory) { uint16[4] memory split; + bool arbitratorConsensus = arbitrator.buyerConsensus && arbitrator.sellerConsensus; + // The calculation will differ slightly based on whether the payment was decided by an arbitrator or not - if(arbitrated) { + if(arbitrator.arbitrated) { split = unicrowArbitrator.arbitrationCalculation( [ escrow.split[WHO_BUYER], escrow.split[WHO_SELLER], escrow.split[WHO_MARKETPLACE], escrow.split[WHO_PROTOCOL], - arbitratorFee + arbitratorConsensus ? arbitrator.arbitratorFee : 0 ] ); } else { @@ -234,7 +232,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { escrow.split[WHO_SELLER], escrow.split[WHO_MARKETPLACE], escrow.split[WHO_PROTOCOL], - arbitratorFee + arbitratorConsensus ? arbitrator.arbitratorFee : 0 ] ); } diff --git a/test/UnicrowClaim.ts b/test/UnicrowClaim.ts index 4bbebaf..1e9613c 100644 --- a/test/UnicrowClaim.ts +++ b/test/UnicrowClaim.ts @@ -374,6 +374,31 @@ describe("UnicrowClaim", function () { ).to.be.revertedWith("0-005"); }); + it("should not update arbitrator fee after challenge", async function () { + await crowToken.connect(buyer).approve(unicrowContract.address, escrowValue); + await unicrowContract.connect(buyer).pay( + { + //@ts-ignore + ...payCommon, + }, + ZERO_ADDRESS, + 0 + ); + + await network.provider.send("evm_increaseTime", [300]); + await network.provider.send("evm_mine"); + + await unicrowArbitratorContract.connect(seller).proposeArbitrator(escrowId, bob.address, 1000); + + await expect(() => + unicrowClaimContract.connect(seller).claim([escrowId]) + ).to.changeTokenBalance( + crowToken, + bob, + ethers.utils.parseUnits("1", 18) + ); + }); + it("should be able to claim marketplace fee", async function () { await crowToken.connect(buyer).approve(unicrowContract.address, escrowValue); await unicrowContract.connect(buyer).pay( From 8ccdad56ed2fd53a4c117e6b7eb8d85a1d2feb62 Mon Sep 17 00:00:00 2001 From: Emanuel Ferreira Date: Wed, 7 Dec 2022 12:05:11 -0300 Subject: [PATCH 7/7] chore: refactor to a variable --- contracts/UnicrowClaim.sol | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contracts/UnicrowClaim.sol b/contracts/UnicrowClaim.sol index 16e0a09..734e22f 100644 --- a/contracts/UnicrowClaim.sol +++ b/contracts/UnicrowClaim.sol @@ -207,6 +207,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { uint16[5] memory split; bool arbitratorConsensus = arbitrator.buyerConsensus && arbitrator.sellerConsensus; + uint16 arbitratorFee = arbitratorConsensus ? arbitrator.arbitratorFee : 0; // The calculation will differ slightly based on whether the payment was decided by an arbitrator or not if(arbitrator.arbitrated) { @@ -216,7 +217,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { escrow.split[WHO_SELLER], escrow.split[WHO_MARKETPLACE], escrow.split[WHO_PROTOCOL], - arbitratorConsensus ? arbitrator.arbitratorFee : 0 + arbitratorFee ] ); } else { @@ -226,7 +227,7 @@ contract UnicrowClaim is IUnicrowClaim, Context, ReentrancyGuard { escrow.split[WHO_SELLER], escrow.split[WHO_MARKETPLACE], escrow.split[WHO_PROTOCOL], - arbitratorConsensus ? arbitrator.arbitratorFee : 0 + arbitratorFee ] ); }