From f951880fcc173bd1c33584fb03697ea18ec999a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20James=20Toussaint?= <33313130+jeremyjams@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:13:04 +0100 Subject: [PATCH] Remove unnecessary back and forth transfers in `IexecPoco2Delegate` --- CHANGELOG.md | 6 ++++++ contracts/modules/delegates/IexecPoco2Delegate.sol | 11 +++++++++-- test/byContract/IexecPoco/06_claim.test.ts | 4 ---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7be7bced..f6bd3ca1 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 33aeecec..893efcc1 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/06_claim.test.ts b/test/byContract/IexecPoco/06_claim.test.ts index 707dcb7f..e93a166d 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) {