Skip to content

Commit 706a82f

Browse files
committed
Ensure beneficiary is emitted on initial contribution
For external tools tracking the state of the contract, the initial contribution to the contract was not emitting the beneficiary which meant they were unable to rederive the state of the contract from the events alone.
1 parent a57e511 commit 706a82f

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

contracts/ServiceNodeContribution.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ contract ServiceNodeContribution is Shared, IServiceNodeContribution {
155155
stakingRewardsContract.validateProofOfPossession(newBLSPubkey, newBLSSig, operator, ed25519Pubkey);
156156

157157
// NOTE: Update BLS keys
158-
blsPubkey = newBLSPubkey;
158+
blsPubkey = newBLSPubkey;
159159
_blsSignature = newBLSSig;
160160

161161
// NOTE: Update Ed25519 keys
@@ -302,11 +302,11 @@ contract ServiceNodeContribution is Shared, IServiceNodeContribution {
302302
}
303303

304304
// NOTE: Add the contributor to the contract
305+
address desiredBeneficiary = deriveBeneficiary(caller, beneficiary);
305306
if (contributions[caller] == 0) {
306-
address desiredBeneficiary = deriveBeneficiary(caller, beneficiary);
307307
_contributorAddresses.push(IServiceNodeRewards.Staker(caller, desiredBeneficiary));
308308
} else {
309-
_updateBeneficiary(caller, beneficiary);
309+
_updateBeneficiary(caller, desiredBeneficiary);
310310
}
311311

312312
// NOTE: Update the amount contributed and transfer the tokens
@@ -333,7 +333,7 @@ contract ServiceNodeContribution is Shared, IServiceNodeContribution {
333333
}
334334

335335
// NOTE: Transfer funds from sender to contract
336-
emit NewContribution(caller, amount);
336+
emit NewContribution(caller, desiredBeneficiary, amount);
337337
SESH.safeTransferFrom(caller, address(this), amount);
338338

339339
// NOTE: Auto finalize the node if valid

contracts/interfaces/IServiceNodeContribution.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IServiceNodeContribution {
4141
//////////////////////////////////////////////////////////////
4242

4343
event Finalized ();
44-
event NewContribution (address indexed contributor, uint256 amount);
44+
event NewContribution (address indexed contributor, address beneficiary, uint256 amount);
4545
event OpenForPublicContribution ();
4646
event Filled ();
4747
event WithdrawContribution (address indexed contributor, uint256 amount);

contracts/interfaces/IServiceNodeContributionFactory.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: GPL-3.0
22
pragma solidity ^0.8.26;
33

4-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
54
import "./IServiceNodeRewards.sol";
65

76
interface IServiceNodeContributionFactory {

test/unit-js/ServiceNodeContributionTest.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
330330
await seshToken.connect(snOperator).approve(snContributionAddress, minContribution);
331331
await expect(snContribution.connect(snOperator).contributeFunds(minContribution, beneficiaryData))
332332
.to.emit(snContribution, "NewContribution")
333-
.withArgs(await snOperator.getAddress(), minContribution);
333+
.withArgs(await snOperator.getAddress(), await snOperator.getAddress(), minContribution);
334334

335335
await expect(await snContribution.operatorContribution())
336336
.to.equal(minContribution);
@@ -384,7 +384,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
384384
await expect(snContribution.connect(snOperator)
385385
.contributeFunds(minContribution, beneficiaryData)).to
386386
.emit(snContribution, "NewContribution")
387-
.withArgs(await snOperator.getAddress(), minContribution);
387+
.withArgs(await snOperator.getAddress(), await snOperator.getAddress(), minContribution);
388388
});
389389

390390
it("Should be able to contribute funds as a contributor", async function () {
@@ -395,7 +395,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
395395
await seshToken.connect(contributor).approve(snContribution, minContribution);
396396
await expect(snContribution.connect(contributor).contributeFunds(minContribution, beneficiaryData))
397397
.to.emit(snContribution, "NewContribution")
398-
.withArgs(await contributor.getAddress(), minContribution);
398+
.withArgs(await contributor.getAddress(), await contributor.getAddress(), minContribution);
399399
await expect(await snContribution.operatorContribution())
400400
.to.equal(previousContribution);
401401
await expect(await snContribution.totalContribution())
@@ -412,7 +412,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
412412
await seshToken.connect(snOperator).approve(snContribution, topup);
413413
await expect(snContribution.connect(snOperator).contributeFunds(topup, beneficiaryData))
414414
.to.emit(snContribution, "NewContribution")
415-
.withArgs(await snOperator.getAddress(), topup);
415+
.withArgs(await snOperator.getAddress(), await snOperator.getAddress(), topup);
416416
await expect(await snContribution.operatorContribution())
417417
.to.equal(currTotal + topup);
418418
await expect(await snContribution.totalContribution())
@@ -439,7 +439,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
439439
await expect(snContribution.connect(contributor1)
440440
.contributeFunds(minContribution1, beneficiaryData)).to
441441
.emit(snContribution, "NewContribution")
442-
.withArgs(await contributor1.getAddress(), minContribution1);
442+
.withArgs(await contributor1.getAddress(), await contributor1.getAddress(), minContribution1);
443443

444444
// NOTE: Contributor 2 w/ minContribution()
445445
const minContribution2 = await snContribution.minimumContribution();
@@ -450,7 +450,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
450450
await expect(snContribution.connect(contributor2)
451451
.contributeFunds(minContribution2, beneficiaryData)).to
452452
.emit(snContribution, "NewContribution")
453-
.withArgs(await contributor2.getAddress(), minContribution2);
453+
.withArgs(await contributor2.getAddress(), await contributor2.getAddress(), minContribution2);
454454

455455
// NOTE: Check contribution values
456456
expect(await snContribution.operatorContribution()).to
@@ -473,7 +473,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
473473
await seshToken.connect(contributor1).approve(snContribution, topup1);
474474
await expect(snContribution.connect(contributor1).contributeFunds(topup1, beneficiaryData))
475475
.to.emit(snContribution, "NewContribution")
476-
.withArgs(await contributor1.getAddress(), topup1);
476+
.withArgs(await contributor1.getAddress(), await contributor1.getAddress(), topup1);
477477

478478
const minContribution2 = await snContribution.minimumContribution();
479479
const topup2 = BigInt(13_000000000);
@@ -482,7 +482,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
482482
await seshToken.connect(contributor2).approve(snContribution, topup2);
483483
await expect(snContribution.connect(contributor2).contributeFunds(topup2, beneficiaryData))
484484
.to.emit(snContribution, "NewContribution")
485-
.withArgs(await contributor2.getAddress(), topup2);
485+
.withArgs(await contributor2.getAddress(), await contributor2.getAddress(), topup2);
486486

487487
await expect(await snContribution.operatorContribution())
488488
.to.equal(initialOperatorContrib);
@@ -534,7 +534,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
534534
await expect(snContribution.connect(contributor1)
535535
.contributeFunds(minContribution1, beneficiaryData)).to
536536
.emit(snContribution, "NewContribution")
537-
.withArgs(await contributor1.getAddress(), minContribution1);
537+
.withArgs(await contributor1.getAddress(), await contributor1.getAddress(), minContribution1);
538538

539539
// NOTE: Contributor 2 w/ minContribution()
540540
const minContribution2 = await snContribution.minimumContribution();
@@ -545,7 +545,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
545545
await expect(snContribution.connect(contributor2)
546546
.contributeFunds(minContribution2, beneficiaryData)).to
547547
.emit(snContribution, "NewContribution")
548-
.withArgs(await contributor2.getAddress(), minContribution2);
548+
.withArgs(await contributor2.getAddress(), await contributor2.getAddress(), minContribution2);
549549

550550
// NOTE: Check contribution values
551551
expect(await snContribution.operatorContribution()).to
@@ -620,12 +620,12 @@ describe("ServiceNodeContribution Contract Tests", function () {
620620
.contributeFunds(minContribution, beneficiaryData)).to
621621
.emit(snContribution, "NewContribution")
622622
.emit(snContribution, "Finalized")
623-
.withArgs(await signer.getAddress(), minContribution);
623+
.withArgs(await signer.getAddress(), await signer.getAddress(), minContribution);
624624
} else {
625625
await expect(snContribution.connect(signer)
626626
.contributeFunds(minContribution, beneficiaryData)).to
627627
.emit(snContribution, "NewContribution")
628-
.withArgs(await signer.getAddress(), minContribution);
628+
.withArgs(await signer.getAddress(), await signer.getAddress(), minContribution);
629629
}
630630
}
631631
}
@@ -644,7 +644,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
644644

645645
await expect(await snContribution.connect(contributor).contributeFunds(minContribution, beneficiaryData))
646646
.to.emit(snContribution, "NewContribution")
647-
.withArgs(await contributor.getAddress(), minContribution);
647+
.withArgs(await contributor.getAddress(), await contributor.getAddress(), minContribution);
648648

649649
await expect(snContribution.finalize()).to.be.reverted;
650650

@@ -1128,7 +1128,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
11281128
await seshToken.connect(reservedContributor1).approve(snContribution.getAddress(), contribution1);
11291129
await expect(snContribution.connect(reservedContributor1).contributeFunds(contribution1, beneficiaryData))
11301130
.to.emit(snContribution, "NewContribution")
1131-
.withArgs(reservedContributor1.address, contribution1);
1131+
.withArgs(reservedContributor1.address, reservedContributor1.address, contribution1);
11321132

11331133
// NOTE: Check contribution is registered
11341134
const contribution = await snContribution.contributions(reservedContributor1.address);
@@ -1176,7 +1176,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
11761176

11771177
await expect(snContribution.connect(reservedContributor1).contributeFunds(contribution1 + 1, beneficiaryData))
11781178
.to.emit(snContribution, "NewContribution")
1179-
.withArgs(reservedContributor1.address, contribution1 + 1);
1179+
.withArgs(reservedContributor1.address, reservedContributor1.address, contribution1 + 1);
11801180

11811181
const contribution = await snContribution.contributions(reservedContributor1.address);
11821182
expect(contribution).to.equal(contribution1 + 1);
@@ -1219,7 +1219,7 @@ describe("ServiceNodeContribution Contract Tests", function () {
12191219
await seshToken.connect(reservedContributor2).approve(snContribution.getAddress(), contribution2);
12201220
await expect(snContribution.connect(reservedContributor2).contributeFunds(contribution2, beneficiaryData))
12211221
.to.emit(snContribution, "NewContribution")
1222-
.withArgs(reservedContributor2.address, contribution2);
1222+
.withArgs(reservedContributor2.address, reservedContributor2.address, contribution2);
12231223

12241224
// NOTE: Check contract reservation data before we withdraw
12251225
await expect(await snContribution.getReserved()).to.deep.equal(

test/unit-js/TokenVestingStaking.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe("TokenVestingStaking Contract Tests", function () {
269269
contribAmount,
270270
/*snContribBenficiary*/ beneficiary))
271271
.to.emit(snContribContract, "NewContribution")
272-
.withArgs(await vestingContract.getAddress(), contribAmount);
272+
.withArgs(await vestingContract.getAddress(), beneficiary.address, contribAmount);
273273

274274
const contractBalance = await mockERC20.balanceOf(snContribContract.getAddress());
275275
expect(contractBalance).to.equal(revokerContribAmount + contribAmount);

0 commit comments

Comments
 (0)