From e57228b42cab8c7dd3704981adcb7006f1706899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=8B=E5=85=9A=20Lidang?= Date: Wed, 24 May 2023 16:01:54 -0500 Subject: [PATCH] update --- .../Executable/Instructions/MoneyInstructions.sol | 10 ++++++++++ darc-protocol/contracts/Utilities/ErrorMsg.sol | 3 +++ .../test/operationUnitTest/offer_dividends_test.ts | 6 +++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/darc-protocol/contracts/Runtime/Executable/Instructions/MoneyInstructions.sol b/darc-protocol/contracts/Runtime/Executable/Instructions/MoneyInstructions.sol index f114fa2..d9e8601 100644 --- a/darc-protocol/contracts/Runtime/Executable/Instructions/MoneyInstructions.sol +++ b/darc-protocol/contracts/Runtime/Executable/Instructions/MoneyInstructions.sol @@ -92,9 +92,14 @@ contract MoneyInstructions is MachineStateManager { function op_OFFER_DIVIDENDS(Operation memory operation, bool bIsSandbox) internal { if (bIsSandbox) { + // make sure that the dividend per myriad per transaction is less than 1000 require(sandboxMachineState.machineStateParameters.dividendPermyriadPerTransaction < 1000, ErrorMsg.By(15)); + // make sure that cycle counter is less than the threashold + require(sandboxMachineState.machineStateParameters.dividendCycleCounter < + sandboxMachineState.machineStateParameters.dividendCycleOfTransactions, ErrorMsg.By(16)); + // 1. calculate the total amount of dividends to be offered bool bIsValid = true; uint256 totalDividends = 0; @@ -238,9 +243,14 @@ contract MoneyInstructions is MachineStateManager { sandboxMachineState.machineStateParameters.dividendCycleCounter = 0; } else { + // make sure that the dividend per myriad per transaction is less than 1000 require(currentMachineState.machineStateParameters.dividendPermyriadPerTransaction < 1000, ErrorMsg.By(15)); + // make sure that cycle counter is less than the threashold + require(currentMachineState.machineStateParameters.dividendCycleCounter < + currentMachineState.machineStateParameters.dividendCycleOfTransactions, ErrorMsg.By(16)); + // 1. calculate the total amount of dividends to be offered bool bIsValid = true; uint256 totalDividends = 0; diff --git a/darc-protocol/contracts/Utilities/ErrorMsg.sol b/darc-protocol/contracts/Utilities/ErrorMsg.sol index 8bcc764..915ea23 100644 --- a/darc-protocol/contracts/Utilities/ErrorMsg.sol +++ b/darc-protocol/contracts/Utilities/ErrorMsg.sol @@ -43,6 +43,9 @@ library ErrorMsg{ else if (val == 15) { return "Invalid dividend permyriad per transaction. Should be less than 1000"; } + else if (val == 16) { + return "No enough number of transactions for dividends yet"; + } return "Unknown Error"; } } \ No newline at end of file diff --git a/darc-protocol/test/operationUnitTest/offer_dividends_test.ts b/darc-protocol/test/operationUnitTest/offer_dividends_test.ts index 7ed6584..bf6c6e9 100644 --- a/darc-protocol/test/operationUnitTest/offer_dividends_test.ts +++ b/darc-protocol/test/operationUnitTest/offer_dividends_test.ts @@ -34,7 +34,7 @@ describe("offer_dividends_test", function () { await darc.initialize(); - // create a token class first + // create 3 token class first await darc.entrance({ programOperatorAddress: programOperatorAddress, operations: [{ @@ -49,8 +49,8 @@ describe("offer_dividends_test", function () { PARAMETER_ARRAY: [], PLUGIN_ARRAY: [], UINT256_2DARRAY: [ - [BigNumber.from(0), BigNumber.from(1)], - [BigNumber.from(10), BigNumber.from(1)], + [BigNumber.from(1), BigNumber.from(1)], + [BigNumber.from(1), BigNumber.from(10)], [BigNumber.from(10), BigNumber.from(1)], ], ADDRESS_2DARRAY: []