Skip to content

Commit

Permalink
make poco less complicated
Browse files Browse the repository at this point in the history
  • Loading branch information
gfournieriExec committed May 29, 2024
1 parent cb9cb95 commit 568f574
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
31 changes: 2 additions & 29 deletions contracts/mocks/IexecPocoMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
*/
contract IexecPocoMock is ERC20 {
using Math for uint256;
using IexecLibOrders_v5 for IexecLibOrders_v5.AppOrder;
using IexecLibOrders_v5 for IexecLibOrders_v5.DatasetOrder;
using IexecLibOrders_v5 for IexecLibOrders_v5.WorkerpoolOrder;
using IexecLibOrders_v5 for IexecLibOrders_v5.RequestOrder;
bool public shouldRevertOnSponsorMatchOrders = false;
bool public shouldRevertOnSponsorMatchOrdersBoost = false;
bytes32 public EIP712DOMAIN_SEPARATOR = "EIP712DOMAIN_SEPARATOR";
mapping(bytes32 => uint256) public m_consumed;

constructor() ERC20("Staked RLC", "SRLC") {
_mint(msg.sender, 1000000);
Expand All @@ -35,10 +29,6 @@ contract IexecPocoMock is ERC20 {
if (shouldRevertOnSponsorMatchOrders) {
revert("IexecPocoMock: Failed to sponsorMatchOrders");
}
bytes32 requestOrderTypedDataHash = _toTypedDataHash(requestOrder.hash());
bytes32 appOrderTypedDataHash = _toTypedDataHash(appOrder.hash());
bytes32 workerpoolOrderTypedDataHash = _toTypedDataHash(workerpoolOrder.hash());
bytes32 datasetOrderTypedDataHash = _toTypedDataHash(datasetOrder.hash());
uint256 volume = computeDealVolume(appOrder, datasetOrder, workerpoolOrder, requestOrder);

uint256 dealPrice = (appOrder.appprice +
Expand All @@ -58,7 +48,6 @@ contract IexecPocoMock is ERC20 {
revert("IexecPocoMock: Failed to sponsorMatchOrdersBoost");
}
uint256 volume = computeDealVolume(appOrder, datasetOrder, workerpoolOrder, requestOrder);

uint256 dealPrice = (appOrder.appprice +
datasetOrder.datasetprice +
workerpoolOrder.workerpoolprice) * volume;
Expand All @@ -79,26 +68,10 @@ contract IexecPocoMock is ERC20 {
IexecLibOrders_v5.WorkerpoolOrder calldata workerpoolOrder,
IexecLibOrders_v5.RequestOrder calldata requestOrder
) public view returns (uint256) {
bytes32 requestOrderTypedDataHash = _toTypedDataHash(requestOrder.hash());
bytes32 appOrderTypedDataHash = _toTypedDataHash(appOrder.hash());
bytes32 workerpoolOrderTypedDataHash = _toTypedDataHash(workerpoolOrder.hash());
bytes32 datasetOrderTypedDataHash = _toTypedDataHash(datasetOrder.hash());
return
Math.min(
Math.min(
Math.min(
appOrder.volume - m_consumed[appOrderTypedDataHash],
datasetOrder.dataset != address(0)
? datasetOrder.volume - m_consumed[datasetOrderTypedDataHash]
: type(uint256).max
),
workerpoolOrder.volume - m_consumed[workerpoolOrderTypedDataHash]
),
requestOrder.volume - m_consumed[requestOrderTypedDataHash]
datasetOrder.dataset != address(0) ? datasetOrder.volume : type(uint256).max,
requestOrder.volume
);
}

function _toTypedDataHash(bytes32 structHash) internal view returns (bytes32) {
return MessageHashUtils.toTypedDataHash(EIP712DOMAIN_SEPARATOR, structHash);
}
}
10 changes: 2 additions & 8 deletions test/VoucherHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@ describe('VoucherHub', function () {
anyone,
] = await ethers.getSigners();
const beacon = await voucherUtils.deployBeaconAndImplementation(admin.address);
const iexecLibOrders = await ethers.getContractFactory('IexecLibOrders_v5');
const iexecLibOrdersInstance = await iexecLibOrders.deploy();
const iexecLibOrdersInstanceAddress = await iexecLibOrdersInstance.getAddress();

iexecPocoInstance = await new IexecPocoMock__factory({
['@iexec/poco/contracts/libs/IexecLibOrders_v5.sol:IexecLibOrders_v5']:
iexecLibOrdersInstanceAddress,
})

iexecPocoInstance = await new IexecPocoMock__factory()
.connect(admin)
.deploy()
.then((x) => x.waitForDeployment());
Expand Down

0 comments on commit 568f574

Please sign in to comment.