From f1bd306a40839dcec0bdcdb6b7362de28c709014 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Mon, 12 Feb 2024 14:10:01 +0100 Subject: [PATCH] Added reward to the ProofSubmitted events --- abi/ProofManagerV1.json | 6 ++++++ abi/ProofManagerV1U1.json | 6 ++++++ abi/StakingV2.json | 6 ++++++ contracts/v1/ProofManagerV1.sol | 18 ++++++++++-------- contracts/v1/ProofManagerV1U1.sol | 18 ++++++++++-------- contracts/v2/Staking.sol | 10 +++++++++- test/v1/unit/ProofManagerV1.test.ts | 4 ++-- test/v1/unit/ProofManagerV1U1.test.ts | 4 ++-- 8 files changed, 51 insertions(+), 21 deletions(-) diff --git a/abi/ProofManagerV1.json b/abi/ProofManagerV1.json index 81c3e38c..13e8a649 100644 --- a/abi/ProofManagerV1.json +++ b/abi/ProofManagerV1.json @@ -219,6 +219,12 @@ "internalType": "uint72", "name": "identityId", "type": "uint72" + }, + { + "indexed": false, + "internalType": "uint96", + "name": "reward", + "type": "uint96" } ], "name": "ProofSubmitted", diff --git a/abi/ProofManagerV1U1.json b/abi/ProofManagerV1U1.json index 0642bad4..e70f4097 100644 --- a/abi/ProofManagerV1U1.json +++ b/abi/ProofManagerV1U1.json @@ -245,6 +245,12 @@ "internalType": "uint72", "name": "identityId", "type": "uint72" + }, + { + "indexed": false, + "internalType": "uint96", + "name": "reward", + "type": "uint96" } ], "name": "ProofSubmitted", diff --git a/abi/StakingV2.json b/abi/StakingV2.json index d6b68a35..4883965a 100644 --- a/abi/StakingV2.json +++ b/abi/StakingV2.json @@ -217,6 +217,12 @@ { "anonymous": false, "inputs": [ + { + "indexed": true, + "internalType": "bytes32", + "name": "agreementId", + "type": "bytes32" + }, { "indexed": true, "internalType": "uint72", diff --git a/contracts/v1/ProofManagerV1.sol b/contracts/v1/ProofManagerV1.sol index 67da1bf6..811f1c07 100644 --- a/contracts/v1/ProofManagerV1.sol +++ b/contracts/v1/ProofManagerV1.sol @@ -27,11 +27,12 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable { bytes keyword, uint8 hashFunctionId, uint16 epoch, - uint72 indexed identityId + uint72 indexed identityId, + uint96 reward ); string private constant _NAME = "ProofManagerV1"; - string private constant _VERSION = "1.0.2"; + string private constant _VERSION = "1.0.3"; bool[4] public reqs = [false, false, false, false]; @@ -191,20 +192,21 @@ contract ProofManagerV1 is Named, Versioned, ContractStatus, Initializable { challenge ); + uint96 reward = sasProxy.getAgreementTokenAmount(agreementId) / + ((r0 - sasProxy.getAgreementRewardedNodesNumber(agreementId, args.epoch)) + + (sasProxy.getAgreementEpochsNumber(agreementId) - (args.epoch + 1)) * + r0); + emit ProofSubmitted( args.assetContract, args.tokenId, args.keyword, args.hashFunctionId, args.epoch, - identityId + identityId, + reward ); - uint96 reward = sasProxy.getAgreementTokenAmount(agreementId) / - ((r0 - sasProxy.getAgreementRewardedNodesNumber(agreementId, args.epoch)) + - (sasProxy.getAgreementEpochsNumber(agreementId) - (args.epoch + 1)) * - r0); - stakingContract.addReward(agreementId, identityId, reward); sasProxy.setAgreementTokenAmount(agreementId, sasProxy.getAgreementTokenAmount(agreementId) - reward); sasProxy.incrementAgreementRewardedNodesNumber(agreementId, args.epoch); diff --git a/contracts/v1/ProofManagerV1U1.sol b/contracts/v1/ProofManagerV1U1.sol index d6b5afd4..e3586ad6 100644 --- a/contracts/v1/ProofManagerV1U1.sol +++ b/contracts/v1/ProofManagerV1U1.sol @@ -29,11 +29,12 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable { uint8 hashFunctionId, uint16 epoch, uint256 stateIndex, - uint72 indexed identityId + uint72 indexed identityId, + uint96 reward ); string private constant _NAME = "ProofManagerV1U1"; - string private constant _VERSION = "1.0.2"; + string private constant _VERSION = "1.0.3"; bool[4] public reqs = [false, false, false, false]; @@ -200,6 +201,11 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable { challenge ); + uint96 reward = sasProxy.getAgreementTokenAmount(agreementId) / + ((r0 - sasProxy.getAgreementRewardedNodesNumber(agreementId, args.epoch)) + + (sasProxy.getAgreementEpochsNumber(agreementId) - (args.epoch + 1)) * + r0); + emit ProofSubmitted( args.assetContract, args.tokenId, @@ -207,14 +213,10 @@ contract ProofManagerV1U1 is Named, Versioned, ContractStatus, Initializable { args.hashFunctionId, args.epoch, latestFinalizedStateIndex, - identityId + identityId, + reward ); - uint96 reward = sasProxy.getAgreementTokenAmount(agreementId) / - ((r0 - sasProxy.getAgreementRewardedNodesNumber(agreementId, args.epoch)) + - (sasProxy.getAgreementEpochsNumber(agreementId) - (args.epoch + 1)) * - r0); - stakingContract.addReward(agreementId, identityId, reward); sasProxy.setAgreementTokenAmount(agreementId, sasProxy.getAgreementTokenAmount(agreementId) - reward); sasProxy.incrementAgreementRewardedNodesNumber(agreementId, args.epoch); diff --git a/contracts/v2/Staking.sol b/contracts/v2/Staking.sol index 2973c5ed..191b836c 100644 --- a/contracts/v2/Staking.sol +++ b/contracts/v2/Staking.sol @@ -39,6 +39,7 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable { uint256 newTotalSupply ); event RewardCollected( + bytes32 indexed agreementId, uint72 indexed identityId, bytes nodeId, address serviceAgreementAddress, @@ -225,7 +226,14 @@ contract StakingV2 is Named, Versioned, ContractStatus, Initializable { else sasAddress = sasProxy.agreementV1U1StorageAddress(); emit StakeIncreased(identityId, ps.getNodeId(identityId), sasAddress, oldStake, oldStake + delegatorsReward); - emit RewardCollected(identityId, ps.getNodeId(identityId), sasAddress, operatorFee, delegatorsReward); + emit RewardCollected( + agreementId, + identityId, + ps.getNodeId(identityId), + sasAddress, + operatorFee, + delegatorsReward + ); } // solhint-disable-next-line no-empty-blocks diff --git a/test/v1/unit/ProofManagerV1.test.ts b/test/v1/unit/ProofManagerV1.test.ts index 34ed69ca..27de5446 100644 --- a/test/v1/unit/ProofManagerV1.test.ts +++ b/test/v1/unit/ProofManagerV1.test.ts @@ -173,8 +173,8 @@ describe('@v1 @unit ProofManagerV1 contract', function () { expect(await ProofManagerV1.name()).to.equal('ProofManagerV1'); }); - it('The contract is version "1.0.2"', async () => { - expect(await ProofManagerV1.version()).to.equal('1.0.2'); + it('The contract is version "1.0.3"', async () => { + expect(await ProofManagerV1.version()).to.equal('1.0.3'); }); it('Create a new asset, teleport to the proof phase and check if window is open, expect true', async () => { diff --git a/test/v1/unit/ProofManagerV1U1.test.ts b/test/v1/unit/ProofManagerV1U1.test.ts index ec6e8272..47344d04 100644 --- a/test/v1/unit/ProofManagerV1U1.test.ts +++ b/test/v1/unit/ProofManagerV1U1.test.ts @@ -258,8 +258,8 @@ describe('@v1 @unit ProofManagerV1U1 contract', function () { expect(await ProofManagerV1U1.name()).to.equal('ProofManagerV1U1'); }); - it('The contract is version "1.0.2"', async () => { - expect(await ProofManagerV1U1.version()).to.equal('1.0.2'); + it('The contract is version "1.0.3"', async () => { + expect(await ProofManagerV1U1.version()).to.equal('1.0.3'); }); it('Create a new asset, update and finalize update, teleport to the proof phase and check if window is open, expect true', async () => {