|
|
@ -5,40 +5,51 @@ pragma solidity ^0.8.0; |
|
|
|
import {TokenMessage} from "../libs/TokenMessage.sol"; |
|
|
|
import {TokenMessage} from "../libs/TokenMessage.sol"; |
|
|
|
|
|
|
|
|
|
|
|
struct ThresholdValidatorsSet { |
|
|
|
struct ThresholdValidatorsSet { |
|
|
|
uint startAmount; |
|
|
|
uint startAmount; |
|
|
|
address[] validatorsSet; |
|
|
|
address[] validatorsSet; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using TokenMessage for bytes; |
|
|
|
using TokenMessage for bytes; |
|
|
|
|
|
|
|
|
|
|
|
contract rateLimitedMultisigIsm { |
|
|
|
contract rateLimitedMultisigIsm { |
|
|
|
address[] defaultSet; |
|
|
|
address[] defaultSet; |
|
|
|
ThresholdValidatorsSet[] rules; |
|
|
|
ThresholdValidatorsSet[] rules; |
|
|
|
|
|
|
|
|
|
|
|
constructor ( |
|
|
|
constructor( |
|
|
|
address[] memory _default, |
|
|
|
address[] memory _default, |
|
|
|
// must be strictly ordered in this example: from small to high |
|
|
|
// must be strictly ordered in this example: from small to high |
|
|
|
ThresholdValidatorsSet[] memory _rules |
|
|
|
ThresholdValidatorsSet[] memory _rules |
|
|
|
) { |
|
|
|
) { |
|
|
|
for (uint256 rule = 0; rule < _rules.length; rule++) { |
|
|
|
for (uint256 rule = 0; rule < _rules.length; rule++) { |
|
|
|
if (rule > 0) {require(_rules[rule].startAmount > _rules[rule-1].startAmount);} |
|
|
|
if (rule > 0) { |
|
|
|
rules.push(_rules[rule]); |
|
|
|
require( |
|
|
|
} |
|
|
|
_rules[rule].startAmount > _rules[rule - 1].startAmount |
|
|
|
defaultSet = _default; |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
rules.push(_rules[rule]); |
|
|
|
function validatorsAndThreshold( |
|
|
|
} |
|
|
|
bytes calldata _message // this is for a better example, probably you will parse this already and bring `amount` as a number |
|
|
|
defaultSet = _default; |
|
|
|
) public view returns (address[] memory, uint) { |
|
|
|
} |
|
|
|
uint256 tokenAmount = _message.amount(); |
|
|
|
|
|
|
|
|
|
|
|
function validatorsAndThreshold( |
|
|
|
// mind that for the sake of example sets aren't united and you should repeat addresses when setting up if they to appear on different thresholds |
|
|
|
bytes calldata _message // this is for a better example, probably you will parse this already and bring `amount` as a number |
|
|
|
for (uint256 thresholdInd = rules.length-1; thresholdInd == 0; thresholdInd--) { |
|
|
|
) public view returns (address[] memory, uint) { |
|
|
|
if (tokenAmount >= rules[thresholdInd].startAmount) { |
|
|
|
uint256 tokenAmount = _message.amount(); |
|
|
|
return (rules[thresholdInd].validatorsSet, rules[thresholdInd].validatorsSet.length); |
|
|
|
|
|
|
|
} |
|
|
|
// mind that for the sake of example sets aren't united and you should repeat addresses when setting up if they to appear on different thresholds |
|
|
|
} |
|
|
|
for ( |
|
|
|
|
|
|
|
uint256 thresholdInd = rules.length - 1; |
|
|
|
return (defaultSet, defaultSet.length); |
|
|
|
thresholdInd == 0; |
|
|
|
} |
|
|
|
thresholdInd-- |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if (tokenAmount >= rules[thresholdInd].startAmount) { |
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
|
|
rules[thresholdInd].validatorsSet, |
|
|
|
|
|
|
|
rules[thresholdInd].validatorsSet.length |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (defaultSet, defaultSet.length); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|