Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Jun 4, 2023
1 parent 1ebbb32 commit 4f1a069
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
14 changes: 7 additions & 7 deletions darc-protocol/contracts/protocol/MachineStateManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ contract MachineStateManager {
));

// set dividend permyriad per transaction as 500
currentMachineState.machineStateParameters.dividendPermyriadPerTransaction = 500;
currentMachineState.machineStateParameters.dividendPermyriadPerTransaction = 5000;

// set the dividend cycle of transactions as 1
currentMachineState.machineStateParameters.dividendCycleOfTransactions = 1;
Expand Down Expand Up @@ -339,10 +339,10 @@ contract MachineStateManager {
* @param bIsSandbox The flag to indicate whether is the sandbox
*/

function currentDividendPerUnit(bool bIsSandbox) public view returns(uint256) {
function currentDividendPerUnit(bool bIsSandbox) internal view returns(uint256) {
if (bIsSandbox) {
// make sure that the dividend per myriad per transaction is less than 1000
require(sandboxMachineState.machineStateParameters.dividendPermyriadPerTransaction < 1000,
// make sure that the dividend per myriad per transaction is less than 10000
require(sandboxMachineState.machineStateParameters.dividendPermyriadPerTransaction < 10000,
ErrorMsg.By(15));

// make sure that cycle counter is less than the threashold
Expand All @@ -359,7 +359,7 @@ contract MachineStateManager {

(bIsValid, totalDividends) = SafeMathUpgradeable.tryDiv(
totalDividends,
1000);
10000);
require (bIsValid, ErrorMsg.By(12));

// 2. calculate the total dividends weight of all dividendable tokens
Expand All @@ -386,7 +386,7 @@ contract MachineStateManager {
return (cashPerUnit);
} else {
// make sure that the dividend per myriad per transaction is less than 1000
require(currentMachineState.machineStateParameters.dividendPermyriadPerTransaction < 1000,
require(currentMachineState.machineStateParameters.dividendPermyriadPerTransaction < 10000,
ErrorMsg.By(15));

// make sure that cycle counter is less than the threashold
Expand All @@ -403,7 +403,7 @@ contract MachineStateManager {

(bIsValid, totalDividends) = SafeMathUpgradeable.tryDiv(
totalDividends,
1000);
10000);
require (bIsValid, ErrorMsg.By(12));

// 2. calculate the total dividends weight of all dividendable tokens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ contract OfferDividendsInstructions 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,
// make sure that the dividend per myriad per transaction is less than 10000
require(sandboxMachineState.machineStateParameters.dividendPermyriadPerTransaction < 10000,
ErrorMsg.By(15));

// make sure that cycle counter is less than the threashold
Expand All @@ -28,6 +27,37 @@ contract OfferDividendsInstructions is MachineStateManager {

// 1. calculate the total amount of dividends to be offered
bool bIsValid = true;
uint256 totalDividends = 0;

(bIsValid, totalDividends) = SafeMathUpgradeable.tryMul(
sandboxMachineState.machineStateParameters.currentCashBalanceForDividends,
sandboxMachineState.machineStateParameters.dividendPermyriadPerTransaction);

(bIsValid, totalDividends) = SafeMathUpgradeable.tryDiv(
totalDividends,
10000);
require (bIsValid, ErrorMsg.By(12));



// 2. calculate the total dividends weight of all dividendable tokens
uint256 totalDividendsWeight = 0;
uint256 ithTotalWeights = 0;
for (uint256 index=0; index < sandboxMachineState.tokenList.length; index++) {
ithTotalWeights = 0;
if (sandboxMachineState.tokenList[index].bIsInitialized == false) {
break;
}
(bIsValid, ithTotalWeights) = SafeMathUpgradeable.tryMul(
sumDividendWeightForTokenClass(bIsSandbox, index),
sandboxMachineState.tokenList[index].dividendWeight);
require(bIsValid, ErrorMsg.By(12));

(bIsValid, totalDividendsWeight) = SafeMathUpgradeable.tryAdd(
totalDividendsWeight,
ithTotalWeights);
require(bIsValid, ErrorMsg.By(12));
}

// 3. calculate the cash dividend per unit
uint256 cashPerUnit = currentDividendPerUnit(bIsSandbox);
Expand All @@ -52,6 +82,8 @@ contract OfferDividendsInstructions is MachineStateManager {
// get total amount of current level of tokens by current token owner
// and get the total dividends
address owner = sandboxMachineState.tokenList[index].ownerList[tokenOwnerId];


(bIsValid, dividends) = SafeMathUpgradeable.tryMul(
sandboxMachineState.tokenList[index].tokenBalance[owner],
cashPerUnit);
Expand All @@ -61,6 +93,7 @@ contract OfferDividendsInstructions is MachineStateManager {
dividends,
sandboxMachineState.tokenList[index].dividendWeight
);
require(bIsValid, ErrorMsg.By(12));

// add the dividends to the withdrawable balance of the address
(bIsValid, sandboxMachineState.withdrawableDividendMap[owner]) = SafeMathUpgradeable.tryAdd(
Expand Down Expand Up @@ -142,8 +175,8 @@ contract OfferDividendsInstructions 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,
// make sure that the dividend per myriad per transaction is less than 10000
require(currentMachineState.machineStateParameters.dividendPermyriadPerTransaction < 10000,
ErrorMsg.By(15));

// make sure that cycle counter is less than the threashold
Expand All @@ -160,7 +193,7 @@ contract OfferDividendsInstructions is MachineStateManager {

(bIsValid, totalDividends) = SafeMathUpgradeable.tryDiv(
totalDividends,
1000);
10000);
require (bIsValid, ErrorMsg.By(12));


Expand Down

0 comments on commit 4f1a069

Please sign in to comment.