Skip to content

Commit

Permalink
Fix contracts with coucilsafe transfer, Adapt UI with new contract, l…
Browse files Browse the repository at this point in the history
…isten to event in subgraph
  • Loading branch information
Corantin committed Nov 2, 2024
1 parent 862400a commit c69d5dd
Show file tree
Hide file tree
Showing 51 changed files with 33,691 additions and 1,219 deletions.
2 changes: 1 addition & 1 deletion apps/web/configs/subgraph.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"VERSION_TESTNET": "0.1.15",
"VERSION_TESTNET": "0.1.17",
"VERSION_PROD": "0.1.4"
}
2,535 changes: 2,535 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/421614/run-1730500346.json

Large diffs are not rendered by default.

2,535 changes: 2,535 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/421614/run-1730504448.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion broadcast/DeployCVMultiChain.s.sol/421614/run-latest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2529,7 +2529,7 @@
"libraries": [],
"pending": [],
"returns": {},
"timestamp": 1729404896,
"timestamp": 1730504448,
"chain": 421614,
"commit": "aaf9065d"
}
1,023 changes: 1,023 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/42161/run-1730505325.json

Large diffs are not rendered by default.

461 changes: 461 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/42161/run-1730505675.json

Large diffs are not rendered by default.

1,023 changes: 1,023 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/42161/run-1730505859.json

Large diffs are not rendered by default.

1,023 changes: 1,023 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/42161/run-1730505976.json

Large diffs are not rendered by default.

815 changes: 589 additions & 226 deletions broadcast/UpgradeCVMultichain.s.sol/42161/run-latest.json

Large diffs are not rendered by default.

2,450 changes: 2,450 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730493498.json

Large diffs are not rendered by default.

1,185 changes: 1,185 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730499454.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730499663.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730501475.json

Large diffs are not rendered by default.

1,185 changes: 1,185 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730501627.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730501843.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730504507.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730505668.json

Large diffs are not rendered by default.

3,007 changes: 3,007 additions & 0 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-1730506324.json

Large diffs are not rendered by default.

2,305 changes: 1,405 additions & 900 deletions broadcast/UpgradeCVMultichain.s.sol/421614/run-latest.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pkg/contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ upgrade-arbsep:
-vvv

verify-blockscout-arbsep:
-forge script script/DeployCVMultiChain.s.sol:DeployCVMultiChain \
-forge script script/UpgradeCVMultichain.s.sol:UpgradeCVMultichain \
--rpc-url $(RPC_URL_ARB_TESTNET) \
--account pkGarden \
--etherscan-api-key $(ARBISCAN_API_KEY) \
--verifier blockscout \
--verifier-url https://arbitrum.blockscout.com/api/ \
--verify \
--via-ir \
--slow
Expand Down Expand Up @@ -256,7 +257,7 @@ deploy-new-collateral-vault-template-arbitrum-sepolia:
--verify \
-vvv

upgrade-and-verify-arbsep: upgrade-arbsep verify-blockscout-arb
upgrade-and-verify-arbsep: upgrade-arbsep verify-blockscout-arbsep


# Arbitrum
Expand Down

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.

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.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

1 change: 0 additions & 1 deletion pkg/contracts/out/TERC20.sol/TERC20.json

This file was deleted.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pkg/contracts/script/UpgradeCVMultichain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ contract UpgradeCVMultichain is BaseMultiChain {

// Upgrades.upgradeProxy(address(registryFactoryProxy), "RegistryFactoryV0_0.sol:RegistryFactoryV0_0", "");
// abi.encodeWithSelector(RegistryFactoryV0_1.initializeV2.selector)
// registryFactory.upgradeTo(registryFactoryImplementation); // DOESNT VALIDATE SAFE UPGRADING
// registryFactory.setRegistryCommunityTemplate(registryImplementation);
registryFactory.upgradeTo(registryFactoryImplementation); // DOESNT VALIDATE SAFE UPGRADING
registryFactory.setRegistryCommunityTemplate(registryImplementation);
registryFactory.setStrategyTemplate(strategyImplementation);

// REGISTRY COMMUNITIES UPGRADES
Expand All @@ -41,7 +41,7 @@ contract UpgradeCVMultichain is BaseMultiChain {
// address(registryCommunityProxies[i]), "RegistryCommunityV0_0.sol:RegistryCommunityV0_0", ""
// );
// abi.encodeWithSelector(RegistryCommunityV0_0.initializeV2.selector)
// registryCommunity.upgradeTo(registryImplementation); // DOESNT VALIDATE SAFE UPGRADING
registryCommunity.upgradeTo(registryImplementation); // DOESNT VALIDATE SAFE UPGRADING
registryCommunity.setStrategyTemplate(strategyImplementation);
}

Expand Down
64 changes: 26 additions & 38 deletions pkg/contracts/src/RegistryCommunity/RegistryCommunityV0_0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ struct Member {
}

struct CommunityParams {
uint256 registerStakeAmount;
bool isKickEnabled;
string covenantIpfsHash;
address councilSafe;
address feeReceiver;
uint256 communityFee;
string communityName;
// Empty community only params
uint256 registerStakeAmount;
bool isKickEnabled;
string covenantIpfsHash;
}

struct Strategies {
Expand All @@ -85,7 +86,6 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
/*| EVENTS |*/
/*|--------------------------------------------|*/

event AlloSet(address _allo);
event CouncilSafeUpdated(address _safe);
event CouncilSafeChangeStarted(address _safeOwner, address _newSafeOwner);
event MemberRegistered(address _member, uint256 _amountStaked);
Expand All @@ -97,7 +97,7 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
event StrategyRemoved(address _strategy);
event MemberActivatedStrategy(address _member, address _strategy, uint256 _pointsToIncrease);
event MemberDeactivatedStrategy(address _member, address _strategy);
event BasisStakedAmountSet(uint256 _newAmount);
event BasisStakedAmountUpdated(uint256 _newAmount);
event MemberPowerIncreased(address _member, uint256 _stakedAmount);
event MemberPowerDecreased(address _member, uint256 _unstakedAmount);
event CommunityNameUpdated(string _communityName);
Expand All @@ -113,11 +113,8 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
error AllowlistTooBig(uint256 size);
error AddressCannotBeZero();
error OnlyEmptyCommunity(uint256 totalMembers);
error RegistryCannotBeZero();
error UserNotInCouncil(address _user);
error UserNotInRegistry();
error UserAlreadyRegistered();
error UserNotGardenOwner();
error UserAlreadyActivated();
error UserAlreadyDeactivated();
error StrategyExists();
Expand Down Expand Up @@ -178,7 +175,7 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
/// @notice The covenant IPFS hash of community
string public covenantIpfsHash;

/// @notice The total number of members in the community
/// @notice The total number of members in the community
uint256 public totalMembers;

// mapping(address => bool) public tribunalMembers;
Expand Down Expand Up @@ -236,6 +233,7 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
revert OnlyEmptyCommunity(totalMembers);
}
}

function onlyStrategyAddress(address _sender, address _strategy) internal pure {
if (_sender != _strategy) {
revert SenderNotStrategy();
Expand All @@ -260,8 +258,6 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
collateralVaultTemplate = template;
}



// AUDIT: acknowledged upgradeable contract hat does not protect initialize functions,
// slither-disable-next-line unprotected-upgrade
function initialize(
Expand Down Expand Up @@ -562,9 +558,11 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
if (msg.sender != pendingCouncilSafe) {
revert SenderNotNewOwner();
}
_grantRole(COUNCIL_MEMBER, pendingCouncilSafe);
_revokeRole(COUNCIL_MEMBER, address(councilSafe));
councilSafe = ISafe(pendingCouncilSafe);
delete pendingCouncilSafe;
emit CouncilSafeUpdated(pendingCouncilSafe);
emit CouncilSafeUpdated(address(councilSafe));
}

function isMember(address _member) public view virtual returns (bool _isMember) {
Expand Down Expand Up @@ -622,22 +620,24 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
return registerStakeAmount;
}

function setBasisStakedAmount(uint256 _newAmount) external virtual {
function setBasisStakedAmount(uint256 _newAmount) public virtual {
onlyCouncilSafe();
onlyEmptyCommunity();
registerStakeAmount = _newAmount;
emit BasisStakedAmountSet(_newAmount);
emit BasisStakedAmountUpdated(_newAmount);
}

function setCommunityParams(CommunityParams memory _params) external {
function setCommunityParams(CommunityParams memory _params) external {
onlyCouncilSafe();
if(_params.registerStakeAmount != registerStakeAmount || _params.isKickEnabled != isKickEnabled || keccak256(bytes(_params.covenantIpfsHash)) != keccak256(bytes(covenantIpfsHash))) {
if (
_params.registerStakeAmount != registerStakeAmount || _params.isKickEnabled != isKickEnabled
|| keccak256(bytes(_params.covenantIpfsHash)) != keccak256(bytes(covenantIpfsHash))
) {
onlyEmptyCommunity();
if (_params.registerStakeAmount != registerStakeAmount){
registerStakeAmount = _params.registerStakeAmount;
emit BasisStakedAmountSet(_params.registerStakeAmount);
if (_params.registerStakeAmount != registerStakeAmount) {
setBasisStakedAmount(_params.registerStakeAmount);
}
if (_params.isKickEnabled != isKickEnabled){
if (_params.isKickEnabled != isKickEnabled) {
isKickEnabled = _params.isKickEnabled;
emit KickEnabledUpdated(_params.isKickEnabled);
}
Expand All @@ -646,28 +646,22 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
emit CovenantIpfsHashUpdated(_params.covenantIpfsHash);
}
}
if(keccak256(bytes(_params.communityName)) != keccak256(bytes(communityName))){
if (keccak256(bytes(_params.communityName)) != keccak256(bytes(communityName))) {
communityName = _params.communityName;
emit CommunityNameUpdated(_params.communityName);
}
if(_params.communityFee != communityFee){
communityFee = _params.communityFee;
emit CommunityFeeUpdated(_params.communityFee);
if (_params.communityFee != communityFee) {
setCommunityFee(_params.communityFee);
}
if(_params.feeReceiver != feeReceiver){
if (_params.feeReceiver != address(0)){
if (_params.feeReceiver != feeReceiver) {
feeReceiver = _params.feeReceiver;
emit FeeReceiverChanged(_params.feeReceiver);
}
}
if(_params.councilSafe != address(0)){
if (_params.councilSafe != address(0)) {
setCouncilSafe(payable(_params.councilSafe));
// event already emitted in setCouncilSafe
}
}



function setCommunityFee(uint256 _newCommunityFee) public virtual {
onlyCouncilSafe();
if (_newCommunityFee > MAX_FEE) {
Expand All @@ -677,8 +671,6 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
emit CommunityFeeUpdated(_newCommunityFee);
}

//function updateMinimumStake()

function isCouncilMember(address _member) public view virtual returns (bool) {
return hasRole(COUNCIL_MEMBER, _member);
}
Expand All @@ -704,11 +696,7 @@ contract RegistryCommunityV0_0 is ProxyOwnableUpgrader, ReentrancyGuardUpgradeab
IPointStrategy(memberStrategies[i]).deactivatePoints(_member);
}
}
function setKickEnabled() public virtual nonReentrant {
onlyCouncilSafe();
onlyEmptyCommunity();
isKickEnabled = !isKickEnabled;
}

function kickMember(address _member, address _transferAddress) public virtual nonReentrant {
onlyCouncilSafe();
if (!isKickEnabled) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"create-local": "graph create --node http://localhost:8020/ kamikazebr/gv2",
"remove-local": "graph remove --node http://localhost:8020/ kamikazebr/gv2",
"deploy:local": "pnpm manifest:local && graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 kamikazebr/gv2 -l v0.0.3",
"deploy:arbsep": "pnpm manifest:arbsep && graph deploy --studio gv2-arbsepolia",
"deploy:arbsep": "pnpm manifest:arbsep && graph deploy --studio gardens-v2---arbitrum-sepolia",
"deploy:ethsep": "pnpm manifest:ethsep && graph deploy --studio gv2-ethsepolia",
"deploy:arbitrum": "pnpm manifest:arbitrum && graph deploy --studio gardens-v2---arbitrum",
"deploy:optimism": "pnpm manifest:optimism && graph deploy --studio gardens-v2---optimism",
Expand Down
138 changes: 137 additions & 1 deletion pkg/subgraph/src/mappings/registry-community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import {
PoolCreated,
MemberKicked,
MemberPowerIncreased,
MemberPowerDecreased
MemberPowerDecreased,
CommunityNameUpdated,
CovenantIpfsHashUpdated,
KickEnabledUpdated,
CouncilSafeChangeStarted,
CouncilSafeUpdated,
BasisStakedAmountUpdated
} from "../../generated/templates/RegistryCommunityV0_0/RegistryCommunityV0_0";

import { RegistryFactoryV0_0 as RegistryFactoryContract } from "../../generated/RegistryFactoryV0_0/RegistryFactoryV0_0";
Expand Down Expand Up @@ -407,6 +413,136 @@ export function handleMemberPowerDecreased(event: MemberPowerDecreased): void {
newMemberCommunity.save();
}

/** Need to hanlde the following events:
* - handleFeeReceiverChanged
* - handleCommunityNameUpdated
* handleCovenantIpfsHashUpdated
* handleKickEnabledUpdated
* handleCouncilSafeChangeStarted
* handleCouncilSafeUpdated
* handleBasisStakedAmountUpdated
*/

// export function handleFeeReceiverChanged(event: MemberPowerDecreased): void {
// log.debug("RegistryCommunity: handleFeeReceiverChanged: {}", [
// event.params._member.toHexString()
// ]);

// }

export function handleCommunityNameUpdated(event: CommunityNameUpdated): void {
log.debug("RegistryCommunity: handleCommunityNameUpdated: {}", [
event.params._communityName
]);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.communityName = event.params._communityName;
community.save();
}

export function handleCovenantIpfsHashUpdated(
event: CovenantIpfsHashUpdated
): void {
log.debug("RegistryCommunity: handleCovenantIpfsHashUpdated: {}", [
event.params._covenantIpfsHash
]);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.covenantIpfsHash = event.params._covenantIpfsHash;
community.save();
}

export function handleKickEnabledUpdated(event: KickEnabledUpdated): void {
log.debug("RegistryCommunity: handleKickEnabledUpdated: {}", [
event.params._isKickEnabled.toString()
]);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.isKickEnabled = event.params._isKickEnabled;
community.save();
}

export function handleCouncilSafeChangeStarted(
event: CouncilSafeChangeStarted
): void {
log.debug(
"RegistryCommunity: handleCouncilSafeChangeStarted: from {} to {}",
[
event.params._safeOwner.toHexString(),
event.params._newSafeOwner.toHexString()
]
);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.pendingNewCouncilSafe = event.params._newSafeOwner.toHexString();
community.save();
}

export function handleCouncilSafeUpdated(event: CouncilSafeUpdated): void {
log.debug("RegistryCommunity: handleCouncilSafeUpdated: {}", [
event.params._safe.toHexString()
]);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.councilSafe = event.params._safe.toHexString();
community.pendingNewCouncilSafe = null;
community.save();
}

export function handleBasisStakedAmountUpdated(
event: BasisStakedAmountUpdated
): void {
log.debug("RegistryCommunity: handleBasisStakedAmountUpdated: {}", [
event.params._newAmount.toString()
]);

let community = RegistryCommunity.load(event.address.toHexString());
if (community == null) {
log.error("RegistryCommunity: Community not found: {}", [
event.address.toHexString()
]);
return;
}

community.registerStakeAmount = event.params._newAmount;
community.save();
}

// handler: handleMemberPowerDecreased
// export function handleMemberPowerDecreased(event: MemberPowerDecreased): void {
// log.debug("RegistryCommunity: handleMemberPowerDecreased: member:{} power:{} strategy:{} ", [
Expand Down
Loading

0 comments on commit c69d5dd

Please sign in to comment.