diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be7bcede..f6bd3ca12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog ## vNEXT + +### Updated contracts +- [x] `IexecPoco2Delegate.sol` + +### Features +- Remove unnecessary back and forth transfers in `IexecPoco2Delegate` happening during `claim(..)`. (#167) - Remove references to blockscout v5. (#161) - Migrate integration test files to Typescript & Hardhat: - 000_fullchain.js (#156, #157) diff --git a/contracts/modules/delegates/IexecPoco2Delegate.sol b/contracts/modules/delegates/IexecPoco2Delegate.sol index 33aeecec4..893efcc1d 100644 --- a/contracts/modules/delegates/IexecPoco2Delegate.sol +++ b/contracts/modules/delegates/IexecPoco2Delegate.sol @@ -61,8 +61,15 @@ contract IexecPoco2Delegate is IexecPoco2, DelegateBase, IexecEscrow, SignatureV unlock(deal.sponsor, taskPrice); // Refund the payer of the task seize(deal.workerpool.owner, poolstake, _taskid); - reward(KITTY_ADDRESS, poolstake, _taskid); // → Kitty / Burn - lock(KITTY_ADDRESS, poolstake); // → Kitty / Burn + /** + * Reward kitty and lock value on it. + * Next lines optimize simple `reward(kitty, ..)` and `lock(kitty, ..)` calls + * where functions would together uselessly transfer value from main PoCo + * proxy to kitty, then would transfer value back from kitty to main PoCo proxy. + */ + m_frozens[KITTY_ADDRESS] += poolstake; // → Kitty / Burn + emit Reward(KITTY_ADDRESS, poolstake, _taskid); + emit Lock(KITTY_ADDRESS, poolstake); } /*************************************************************************** diff --git a/test/byContract/IexecPoco/04_finalize.test.ts b/test/byContract/IexecPoco/04_finalize.test.ts index dcc9fc708..e4fcded5b 100644 --- a/test/byContract/IexecPoco/04_finalize.test.ts +++ b/test/byContract/IexecPoco/04_finalize.test.ts @@ -338,7 +338,6 @@ describe('IexecPoco2#finalize', async () => { const sponsorFrozenBefore = await iexecPoco.frozenOf(sponsor.address); await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x')) - .to.emit(iexecPoco, 'TaskFinalize') .to.changeTokenBalances( iexecPoco, [requester, sponsor, appProvider, datasetProvider], @@ -348,7 +347,8 @@ describe('IexecPoco2#finalize', async () => { appPrice, // app provider is rewarded 0, // but dataset provider is not rewarded ], - ); + ) + .to.emit(iexecPoco, 'TaskFinalize'); expect(await iexecPoco.frozenOf(requester.address)).to.be.equal( requesterFrozenBefore - taskPrice, ); @@ -517,14 +517,6 @@ describe('IexecPoco2#finalize', async () => { (await iexecPoco.viewTask(kittyFillingDeal.taskId)).finalDeadline, ); await expect(iexecPoco.claim(kittyFillingDeal.taskId)) - .to.emit(iexecPoco, 'Transfer') - .withArgs(iexecPoco.address, kittyAddress, kittyFillingSchedulerTaskStake) - .to.emit(iexecPoco, 'Reward') - .withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId) - .to.emit(iexecPoco, 'Transfer') - .withArgs(kittyAddress, iexecPoco.address, kittyFillingSchedulerTaskStake) - .to.emit(iexecPoco, 'Lock') - .withArgs(kittyAddress, kittyFillingSchedulerTaskStake) .to.changeTokenBalances( iexecPoco, [iexecPoco, kittyAddress], @@ -532,7 +524,11 @@ describe('IexecPoco2#finalize', async () => { -workerpoolPriceToFillKitty, // deal payer is refunded 0, ], - ); + ) + .to.emit(iexecPoco, 'Reward') + .withArgs(kittyAddress, kittyFillingSchedulerTaskStake, kittyFillingDeal.taskId) + .to.emit(iexecPoco, 'Lock') + .withArgs(kittyAddress, kittyFillingSchedulerTaskStake); const kittyFrozenAfterClaim = (await iexecPoco.frozenOf(kittyAddress)).toNumber(); expect(kittyFrozenAfterClaim).to.equal( kittyFrozenBeforeClaim + kittyFillingSchedulerTaskStake, @@ -579,6 +575,11 @@ describe('IexecPoco2#finalize', async () => { .reveal(taskId, resultDigest) .then((tx) => tx.wait()); await expect(iexecPocoAsScheduler.finalize(taskId, results, '0x')) + .to.changeTokenBalances( + iexecPoco, + [iexecPoco, scheduler, kittyAddress], + [-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0], + ) .to.emit(iexecPoco, 'TaskFinalize') .to.emit(iexecPoco, 'Seize') .withArgs(kittyAddress, expectedSchedulerKittyPartReward, taskId) @@ -589,12 +590,7 @@ describe('IexecPoco2#finalize', async () => { expectedSchedulerKittyPartReward, ) .to.emit(iexecPoco, 'Reward') - .withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId) - .to.changeTokenBalances( - iexecPoco, - [iexecPoco, scheduler, kittyAddress], - [-expectedSchedulerKittyPartReward, expectedSchedulerKittyPartReward, 0], - ); + .withArgs(scheduler.address, expectedSchedulerKittyPartReward, taskId); expect(await iexecPoco.frozenOf(kittyAddress)).to.equal( kittyFrozenAfterClaim - expectedSchedulerKittyPartReward, ); diff --git a/test/byContract/IexecPoco/06_claim.test.ts b/test/byContract/IexecPoco/06_claim.test.ts index 707dcb7fe..e93a166d8 100644 --- a/test/byContract/IexecPoco/06_claim.test.ts +++ b/test/byContract/IexecPoco/06_claim.test.ts @@ -144,12 +144,8 @@ describe('IexecPoco2#claim', async () => { .withArgs(sponsor.address, taskPrice) .to.emit(iexecPoco, 'Seize') .withArgs(scheduler.address, schedulerTaskStake, taskId) - .to.emit(iexecPoco, 'Transfer') - .withArgs(iexecPoco.address, kittyAddress, schedulerTaskStake) .to.emit(iexecPoco, 'Reward') .withArgs(kittyAddress, schedulerTaskStake, taskId) - .to.emit(iexecPoco, 'Transfer') - .withArgs(kittyAddress, iexecPoco.address, schedulerTaskStake) .to.emit(iexecPoco, 'Lock') .withArgs(kittyAddress, schedulerTaskStake); for (const worker of workers) {