Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage #496

Draft
wants to merge 9 commits into
base: dev
Choose a base branch
from
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@ export default function Page({
(strategy) =>
PoolTypes[strategy.config?.proposalType] === "signaling" &&
strategy.isEnabled,
//&&
//strategy.isArchived,
);

const fundingPools = strategies.filter(
(strategy) =>
PoolTypes[strategy.config?.proposalType] === "funding" &&
strategy.isEnabled,
//&&
//strategy.isArchived,
);
const activePools = strategies?.filter((strategy) => strategy?.isEnabled);

Expand Down
1,592 changes: 796 additions & 796 deletions broadcast/DeployCVMultiChain.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731713495.json

Large diffs are not rendered by default.

468 changes: 468 additions & 0 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731713666.json

Large diffs are not rendered by default.

468 changes: 468 additions & 0 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731789065.json

Large diffs are not rendered by default.

474 changes: 474 additions & 0 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731797262.json

Large diffs are not rendered by default.

472 changes: 472 additions & 0 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731864508.json

Large diffs are not rendered by default.

334 changes: 167 additions & 167 deletions broadcast/UpgradeCVMultichainTest.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CVStrategyV0_0.sol/CVStrategyV0_0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CVStrategyV0_0.sol/IPointStrategy.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/CollateralVault.sol/CollateralVault.json

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/contracts/out/FAllo.sol/FAllo.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/IArbitrator.sol/IArbitrator.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/ISafe.sol/Enum.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/ISafe.sol/ISafe.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/ISafe.sol/SafeProxyFactory.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/PassportScorer.sol/PassportScorer.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/contracts/out/RegistrySetup.sol/RegistrySetup.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/contracts/out/RegistrySetup.sol/RegistrySetupFull.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/contracts/out/SafeArbitrator.sol/SafeArbitrator.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions pkg/contracts/script/DeploySafeArbitrator.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,14 @@ contract DeploySafeArbitrator is BaseMultiChain {
address proxyOwner = networkJson.readAddress(getKeyNetwork(".ENVS.PROXY_OWNER"));
address sender = 0xb05A948B5c1b057B88D381bDe3A375EfEA87EbAD;

address newSafeArbitrator = address(
new ERC1967Proxy(
address(new SafeArbitrator()),
abi.encodeWithSelector(SafeArbitrator.initialize.selector, 0.001 ether, address(proxyOwner))
)
);

// CV STRATEGIES
address[] memory cvStrategyProxies = networkJson.readAddressArray(getKeyNetwork(".PROXIES.CV_STRATEGIES"));
for (uint256 i = 0; i < cvStrategyProxies.length; i++) {
CVStrategyV0_0 strategy = CVStrategyV0_0(payable(address(cvStrategyProxies[i])));
if (address(strategy.registryCommunity().councilSafe()) != sender) {
continue;
}
address existingSybil = address(strategy.sybilScorer());
// address existingSybil = address(strategy.sybilScorer());
(
,
address tribunalSafe,
Expand All @@ -39,7 +32,16 @@ contract DeploySafeArbitrator is BaseMultiChain {
(uint256 maxRatio, uint256 weight, uint256 decay, uint256 minThresholdPoints) = strategy.cvParams();
strategy.setPoolParams(
ArbitrableConfig(
IArbitrator(newSafeArbitrator),
IArbitrator(
address(
new ERC1967Proxy(
address(new SafeArbitrator()),
abi.encodeWithSelector(
SafeArbitrator.initialize.selector, 0.001 ether, address(proxyOwner)
)
)
)
),
tribunalSafe,
submitterCollateralAmount,
challengerCollateralAmount,
Expand Down
4 changes: 2 additions & 2 deletions pkg/contracts/script/VerifyTest.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ contract VerifyTest is BaseMultiChain {
using stdJson for string;

function runCurrentNetwork(string memory networkJson) public virtual override {
allo_proxy = networkJson.readAddress(getKeyNetwork(".ENVS.ALLO_PROXY"));
address allo_proxy = networkJson.readAddress(getKeyNetwork(".ENVS.ALLO_PROXY"));

if (allo_proxy == address(0)) {
revert("ALLO_PROXY not set");
}

allo = Allo(allo_proxy);
IAllo allo = Allo(allo_proxy);

assertTrue(address(allo) != address(0));

Expand Down
131 changes: 76 additions & 55 deletions pkg/contracts/src/CVStrategy/CVStrategyV0_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
error UserNotInRegistry(); //0x6a5cfb6d
error UserIsInactive(); // 0x5fccb67f
error PoolIsEmpty(); // 0xed4421ad
error NotImplemented(); //0xd6234725
// error NotImplemented(); //0xd6234725
// error TokenCannotBeZero(); //0x596a094c
error TokenNotAllowed(); // 0xa29c4986
error AmountOverMaxRatio(); // 0x3bf5ca14
// error TokenNotAllowed(); // 0xa29c4986
// error AmountOverMaxRatio(); // 0x3bf5ca14
error AddressCannotBeZero(); //0xe622e040
// error RegistryCannotBeZero(); // 0x5df4b1ef
error SupportUnderflow(uint256 _support, int256 _delta, int256 _result); // 0x3bbc7142
// error SupportUnderflow(uint256 _support, int256 _delta, int256 _result); // 0x3bbc7142
error NotEnoughPointsToSupport(uint256 pointsSupport, uint256 pointsBalance); // 0xd64182fe

// error ProposalDataIsEmpty(); //0xc5f7c4c0
Expand All @@ -162,19 +162,19 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
error ProposalSupportDuplicated(uint256 _proposalId, uint256 index); //0xadebb154
error ConvictionUnderMinimumThreshold(); // 0xcce79308
error OnlyCommunityAllowed(); // 0xaf0916a2
error PoolAmountNotEnough(uint256 _proposalId, uint256 _requestedAmount, uint256 _poolAmount); //0x5863b0b6
// error PoolAmountNotEnough(uint256 _proposalId, uint256 _requestedAmount, uint256 _poolAmount); //0x5863b0b6
error OnlyCouncilSafe();
error UserCannotExecuteAction();
error InsufficientCollateral(uint256 sentAmount, uint256 requiredAmount);
// error InsufficientCollateral(uint256 sentAmount, uint256 requiredAmount);
error OnlyArbitrator();
error ProposalNotDisputed(uint256 _proposalId);
// error ArbitratorCannotBeZero();
error OnlySubmitter(address submitter, address sender);
// Goss: Support Collateral Zero
// error CollateralVaultCannotBeZero();
error DefaultRulingNotSet();
error DisputeCooldownNotPassed(uint256 _proposalId, uint256 _remainingSec);
error ProposalInvalidForAllocation(uint256 _proposalId, ProposalStatus _proposalStatus);
// error DisputeCooldownNotPassed(uint256 _proposalId, uint256 _remainingSec);
// error ProposalInvalidForAllocation(uint256 _proposalId, ProposalStatus _proposalStatus);
error AShouldBeUnderTwo_128();
error BShouldBeLessTwo_128();
error AShouldBeUnderOrEqTwo_128();
Expand Down Expand Up @@ -335,7 +335,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// revert RegistryCannotBeZero();
// }
if (!registryCommunity.isMember(_sender)) {
revert();
revert UserNotInRegistry();
}
// _;
}
Expand Down Expand Up @@ -377,7 +377,8 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
|| p.proposalStatus == ProposalStatus.Executed || p.proposalStatus == ProposalStatus.Rejected
)
) {
revert ProposalInvalidForAllocation(_proposalId, p.proposalStatus);
// revert ProposalInvalidForAllocation(_proposalId, p.proposalStatus);
revert(); // @todo take commented when contract size fixed with diamond
}
}

Expand All @@ -392,6 +393,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,

function _registerRecipient(bytes memory _data, address _sender) internal virtual override returns (address) {
checkSenderIsMember(_sender);
registryCommunity.onlyStrategyEnabled(address(this));
// surpressStateMutabilityWarning++;
_data;
CreateProposal memory proposal = abi.decode(_data, (CreateProposal));
Expand All @@ -404,24 +406,26 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// revert TokenCannotBeZero();
// }
IAllo _allo = this.getAllo();
IAllo.Pool memory pool = _allo.getPool(proposal.poolId);
if (proposal.requestedToken != pool.token) {
if (proposal.requestedToken != _allo.getPool(proposal.poolId).token) {
// console.log("::requestedToken", proposal.requestedToken);
// console.log("::PookToken", poolToken);
revert TokenNotAllowed();
// revert TokenNotAllowed();
revert(); // @todo take commented when contract size fixed with diamond
}
if (_isOverMaxRatio(proposal.amountRequested)) {
revert AmountOverMaxRatio();
// revert AmountOverMaxRatio();
revert(); // @todo take commented when contract size fixed with diamond
}
}

if (
address(arbitrableConfigs[currentArbitrableConfigVersion].arbitrator) != address(0)
&& msg.value < arbitrableConfigs[currentArbitrableConfigVersion].submitterCollateralAmount
) {
revert InsufficientCollateral(
msg.value, arbitrableConfigs[currentArbitrableConfigVersion].submitterCollateralAmount
);
// revert InsufficientCollateral(
// msg.value, arbitrableConfigs[currentArbitrableConfigVersion].submitterCollateralAmount
// );
revert(); // @todo take commented when contract size fixed with diamond
}

uint256 proposalId = ++proposalCounter;
Expand Down Expand Up @@ -450,12 +454,16 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// return cvParams.decay;
// }

function activatePoints() external virtual {
if (!_canExecuteAction(msg.sender)) {
function _activatePoints(address _sender) public virtual {
if (!_canExecuteAction(_sender)) {
revert UserCannotExecuteAction();
}
registryCommunity.activateMemberInStrategy(msg.sender, address(this));
totalPointsActivated += registryCommunity.getMemberPowerInStrategy(msg.sender, address(this));
registryCommunity.activateMemberInStrategy(_sender, address(this));
totalPointsActivated += registryCommunity.getMemberPowerInStrategy(_sender, address(this));
}

function activatePoints() external virtual {
_activatePoints(msg.sender);
}

function deactivatePoints() public virtual {
Expand Down Expand Up @@ -619,42 +627,42 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// if (proposalId == 0) {
// revert ProposalIdCannotBeZero();
// }
Proposal storage proposal = proposals[proposalId];

if (proposalType == ProposalType.Funding) {
if (proposal.proposalId != proposalId) {
if (proposals[proposalId].proposalId != proposalId) {
revert ProposalNotInList(proposalId);
}

if (proposal.requestedAmount > poolAmount) {
revert PoolAmountNotEnough(proposalId, proposal.requestedAmount, poolAmount);
if (proposals[proposalId].requestedAmount > poolAmount) {
// revert PoolAmountNotEnough(proposalId, proposals[proposalId].requestedAmount, poolAmount);
revert(); // @todo take commented when contract size fixed with diamond
}

if (proposal.proposalStatus != ProposalStatus.Active) {
if (proposals[proposalId].proposalStatus != ProposalStatus.Active) {
revert ProposalNotActive(proposalId);
}

uint256 convictionLast = updateProposalConviction(proposalId);
uint256 threshold = calculateThreshold(proposal.requestedAmount);
uint256 threshold = calculateThreshold(proposals[proposalId].requestedAmount);

if (convictionLast < threshold && proposal.requestedAmount > 0) {
if (convictionLast < threshold && proposals[proposalId].requestedAmount > 0) {
revert ConvictionUnderMinimumThreshold();
}

IAllo.Pool memory pool = allo.getPool(poolId);

poolAmount -= proposal.requestedAmount; // CEI
poolAmount -= proposals[proposalId].requestedAmount; // CEI

_transferAmount(pool.token, proposal.beneficiary, proposal.requestedAmount);
_transferAmount(
allo.getPool(poolId).token, proposals[proposalId].beneficiary, proposals[proposalId].requestedAmount
);

proposal.proposalStatus = ProposalStatus.Executed;
proposals[proposalId].proposalStatus = ProposalStatus.Executed;
collateralVault.withdrawCollateral(
proposalId,
proposal.submitter,
proposals[proposalId].submitter,
arbitrableConfigs[currentArbitrableConfigVersion].submitterCollateralAmount
);

emit Distributed(proposalId, proposal.beneficiary, proposal.requestedAmount);
emit Distributed(proposalId, proposals[proposalId].beneficiary, proposals[proposalId].requestedAmount);
} //signaling do nothing @todo write tests @todo add end date
}

Expand Down Expand Up @@ -689,7 +697,8 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// surpressStateMutabilityWarning
// PayoutSummary[] memory payouts = new PayoutSummary[](0);
// return payouts;
revert NotImplemented();
// revert NotImplemented();
revert();
}

function _getPayout(address _recipientId, bytes memory _data)
Expand Down Expand Up @@ -968,11 +977,22 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
int256 result = int256(_support) + _delta;

if (result < 0) {
revert SupportUnderflow(_support, _delta, result);
// revert SupportUnderflow(_support, _delta, result);
revert(); // @todo take commented when contract size fixed with diamond
}
return uint256(result);
}


function calculateProposalConviction(uint256 _proposalId) public view virtual returns (uint256) {
Proposal storage proposal = proposals[_proposalId];
return calculateConviction(
block.number - proposal.blockLast,
proposal.convictionLast,
proposal.stakedAmount
);
}

/**
* @dev Conviction formula: a^t * y(0) + x * (1 - a^t) / (1 - a)
* Solidity implementation: y = (2^128 * a^t * y0 + x * D * (2^128 - 2^128 * a^t) / (D - aD) + 2^127) / 2^128
Expand All @@ -996,6 +1016,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
>> 128;
}


/**
* @dev Formula: ρ * totalStaked / (1 - a) / (β - requestedAmount / total)**2
* For the Solidity implementation we amplify ρ and β and simplify the formula:
Expand All @@ -1015,7 +1036,8 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
}

if (_isOverMaxRatio(_requestedAmount)) {
revert AmountOverMaxRatio();
// revert AmountOverMaxRatio();
revert(); // @todo take commented when contract size fixed with diamond
}

uint256 denom = (cvParams.maxRatio * 2 ** 64) / D - (_requestedAmount * 2 ** 64) / poolAmount;
Expand All @@ -1028,7 +1050,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
uint256 thresholdOverride = (
((cvParams.minThresholdPoints / totalEffectiveActivePoints()) * D)
* (getMaxConviction(totalEffectiveActivePoints()))
) / 10 ** 18;
) / 10 ** 11;
_threshold = _threshold > thresholdOverride ? _threshold : thresholdOverride;
}
}
Expand Down Expand Up @@ -1086,16 +1108,13 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
* @param _proposal Proposal
* @param _oldStaked Amount of tokens staked on a proposal until now
*/
function _calculateAndSetConviction(Proposal storage _proposal, uint256 _oldStaked)
internal
virtual
returns (uint256 conviction, uint256 blockNumber)
{
(conviction, blockNumber) = _checkBlockAndCalculateConviction(_proposal, _oldStaked);
if (conviction != 0 || blockNumber != 0) {
_proposal.blockLast = blockNumber;
_proposal.convictionLast = conviction;
function _calculateAndSetConviction(Proposal storage _proposal, uint256 _oldStaked) internal virtual {
(uint256 conviction, uint256 blockNumber) = _checkBlockAndCalculateConviction(_proposal, _oldStaked);
if (conviction == 0 && blockNumber == 0) {
return;
}
_proposal.blockLast = blockNumber;
_proposal.convictionLast = conviction;
}

function _checkBlockAndCalculateConviction(Proposal storage _proposal, uint256 _oldStaked)
Expand All @@ -1112,7 +1131,6 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
}
// calculateConviction and store it
conviction = calculateConviction(
// TODO: Goss -> we should do this math inside the func so UI does not need to fetch latest block
blockNumber - _proposal.blockLast, // we assert it doesn't overflow above
_proposal.convictionLast,
_oldStaked
Expand Down Expand Up @@ -1167,7 +1185,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
emit CVParamsUpdated(_cvParams);
}

function updateProposalConviction(uint256 proposalId) public virtual returns (uint256 conviction) {
function updateProposalConviction(uint256 proposalId) public virtual returns (uint256) {
Proposal storage proposal = proposals[proposalId];

if (proposal.proposalId != proposalId) {
Expand All @@ -1179,7 +1197,8 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
// revert ProposalNotActive(proposalId);
// }

(conviction,) = _calculateAndSetConviction(proposal, proposal.stakedAmount);
_calculateAndSetConviction(proposal, proposal.stakedAmount);
return proposal.convictionLast;
}

function getMaxConviction(uint256 amount) public view virtual returns (uint256) {
Expand Down Expand Up @@ -1269,17 +1288,19 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
revert ProposalNotActive(proposalId);
}
if (msg.value < arbitrableConfig.challengerCollateralAmount) {
revert InsufficientCollateral(msg.value, arbitrableConfig.challengerCollateralAmount);
// revert InsufficientCollateral(msg.value, arbitrableConfig.challengerCollateralAmount);
revert(); // @todo take commented when contract size fixed with diamond
}

// if the lastDisputeCompletion is less than DISPUTE_COOLDOWN_SEC, we should revert
if (
proposal.lastDisputeCompletion != 0
&& proposal.lastDisputeCompletion + DISPUTE_COOLDOWN_SEC > block.timestamp
) {
revert DisputeCooldownNotPassed(
proposalId, proposal.lastDisputeCompletion + DISPUTE_COOLDOWN_SEC - block.timestamp
);
// revert DisputeCooldownNotPassed(
// proposalId, proposal.lastDisputeCompletion + DISPUTE_COOLDOWN_SEC - block.timestamp
// );
revert(); // @todo take commented when contract size fixed with diamond
}

uint256 arbitrationFee = msg.value - arbitrableConfig.challengerCollateralAmount;
Expand Down
Loading