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

✨ Deploy script #7

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ pkg/contracts/broadcast/**/dry-run/
# subgraph
pkg/subgraph/generated
pkg/**/data

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"solidity.packageDefaultDependenciesContractsDirectory": "pkg/contracts/src",
"solidity.packageDefaultDependenciesDirectory": "lib",
"[solidity]": {
"editor.defaultFormatter": "JuanBlanco.solidity",
"editor.defaultFormatter": "NomicFoundation.hardhat-solidity",
"editor.formatOnSave": true
},
"solidity.formatter": "forge",
Expand Down
617 changes: 617 additions & 0 deletions broadcast/DeployCV.s.sol/1/run-1704393482.json

Large diffs are not rendered by default.

796 changes: 796 additions & 0 deletions broadcast/DeployCV.s.sol/1/run-1704401146.json

Large diffs are not rendered by default.

1,333 changes: 1,333 additions & 0 deletions broadcast/DeployCV.s.sol/1/run-1704401386.json

Large diffs are not rendered by default.

1,333 changes: 1,333 additions & 0 deletions broadcast/DeployCV.s.sol/1/run-latest.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#default-profile
[profile.default]
# solc-version = "0.8.19"
src = 'pkg/contracts/src'
src = 'pkg/contracts'
test = 'pkg/contracts/test'
out = 'pkg/contracts/out'
libs = ['lib']
Expand All @@ -10,7 +10,11 @@ optimizer = true
optimizer-runs = 1_000

# auto_detect_remappings = true # recursive auto-detection of remappings
# remappings = []
# remappings = ["ds-test/=lib/forge-std/lib/ds-test/src/",
# "forge-std/=lib/forge-std/src/",
# "allo-v2/=lib/allo-v2/"
# ,"allo-v2-contracts/=lib/allo-v2/contracts/"
# ,"allo-v2-test/=lib/allo-v2/test/","safe-contracts/=lib/safe-contracts/"]
# # list of libraries to link in the form of `<path to lib>:<lib name>:<address>`: `"src/MyLib.sol:MyLib:0x8De6DDbCd5053d32292AAA0D2105A32d108484a6"`
# # the <path to lib> supports remappings
# libraries = []
Expand Down
24 changes: 24 additions & 0 deletions pkg/contracts/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Lets creata commans to foundry
# forge script DeployCV.s.sol --account pk

# read RPC_URL from .env file
include .env

# create RPC_URL_LOCALHOST variable
RPC_URL_LOCALHOST = http://localhost:8545
# print RPC_URL
print :
@echo $(RPC_URL)

deploy :
forge script script/DeployCV.s.sol:DeployCV --account pk --rpc-url $(RPC_URL_LOCALHOST) --account pk --sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 --broadcast --unlocked -vv

fork:
anvil -f $(RPC_URL)

test1:
forge test --fork-url $(RPC_URL_LOCALHOST) --mc CVStrategyTest --sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 -vv


cast1:
cast send --account pk --rpc-url $(RPC_URL_LOCALHOST) "0xfEcFbe13c84595Ba47464CD4d8d3bb359372Fc6f" "nonce()"
4 changes: 4 additions & 0 deletions pkg/contracts/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RPC_URL=
ALLO_PROXY=0x1133eA7Af70876e64665ecD07C0A0476d09465a1
ALLO_IMPL=0xB087535DB0df98fC4327136e897A5985E5Cfbd66
REGISTRY=0x4AAcca72145e1dF2aeC137E1f3C5E3D75DB8b5f3
18 changes: 0 additions & 18 deletions pkg/contracts/script/Counter.s.sol

This file was deleted.

113 changes: 113 additions & 0 deletions pkg/contracts/script/DeployCV.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/console2.sol";

import "forge-std/Script.sol";

import "../src/CVStrategy.sol";

import {IAllo} from "allo-v2-contracts/core/interfaces/IAllo.sol";

import {Allo} from "allo-v2-contracts/core/Allo.sol";

import {IRegistry} from "allo-v2-contracts/core/interfaces/IRegistry.sol";

import {Native} from "allo-v2-contracts/core/libraries/Native.sol";

import {CVStrategyHelpers} from "../test/CVStrategyHelpers.sol";

import {MockERC20 as AMockERC20} from "allo-v2-test/utils/MockERC20.sol";
// import "allo-v2-test/utils/MockERC20.sol";

import {RegistryFactory} from "../src/RegistryFactory.sol";
import {SafeSetup} from "../test/shared/SafeSetup.sol";
import {Metadata} from "allo-v2-contracts/core/libraries/Metadata.sol";

import {Accounts} from "allo-v2-test/foundry/shared/Accounts.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract DeployCV is Native, CVStrategyHelpers, Script, SafeSetup {
address public ALLO_PROXY_ADDRESS;

uint256 public constant MINIMUM_STAKE = 50;

AMockERC20 public token;

function pool_admin() public virtual override returns (address) {
// return makeAddr("pool_admin");
return address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
}

function run() public {
ALLO_PROXY_ADDRESS = vm.envAddress("ALLO_PROXY");
Allo allo = Allo(ALLO_PROXY_ADDRESS);

vm.startBroadcast(pool_admin());

token = new AMockERC20();

IRegistry registry = allo.getRegistry();

RegistryFactory registryFactory = new RegistryFactory();
RegistryGardens.InitializeParams memory params;
params._allo = address(allo);

params._gardenToken = IERC20(address(token));

params._minimumStakeAmount = MINIMUM_STAKE;
params._protocolFee = 2;
params._metadata = metadata;
params._councilSafe = payable(address(_councilSafe()));
RegistryGardens registryGardens = RegistryGardens(registryFactory.createRegistry(params));

CVStrategy strategy = new CVStrategy(ALLO_PROXY_ADDRESS);

vm.stopBroadcast();

address[] memory membersStaked = new address[](4);

membersStaked[0] = address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
membersStaked[1] = address(0x70997970C51812dc3A010C7d01b50e0d17dc79C8);
membersStaked[2] = address(0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC);
membersStaked[3] = address(0x90F79bf6EB2c4f870365E785982E1f101E93b906);

for (uint256 i = 0; i < membersStaked.length; i++) {
vm.startBroadcast(address(membersStaked[i]));
token.mint(address(membersStaked[i]), 100 ether);
token.approve(address(registryGardens), MINIMUM_STAKE);
registryGardens.stakeAndregisterMember();
vm.stopBroadcast();
}

vm.startBroadcast(address(allo.owner()));
allo.addToCloneableStrategies(address(strategy));
vm.stopBroadcast();

vm.startBroadcast(pool_admin());
vm.deal(address(pool_admin()), 1 ether);

token.mint(address(pool_admin()), 100 ether);

uint256 poolId = createPool(Allo(address(allo)), address(strategy), address(0), registry, address(token));
token.approve(address(allo), 100 ether);
allo.fundPool(poolId, 0.1 ether); // gonna sue TOKENS here

uint256 poolIdNative = createPool(Allo(address(allo)), address(strategy), address(0), registry, address(0));
allo.fundPool{value: 0.1 ether}(poolIdNative, 0.1 ether);

vm.stopBroadcast();

console2.log("PoolId: %s", poolId);
console2.log("Allo Addr: %s", address(allo));
console2.log("Strategy Addr: %s", address(strategy));
console2.log("Token Addr: %s", address(token));

console2.log("Registry Gardens Addr: %s", address(registryGardens));

console2.log("Registry Addr: %s", address(registry));
console2.log("Pool Admin: %s", pool_admin());
console2.log("Council Safe: %s", address(_councilSafe()));
}
}
11 changes: 10 additions & 1 deletion pkg/contracts/src/CVStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ contract CVStrategy is BaseStrategy, IWithdrawMember {
error NotEnoughPointsToSupport(uint256 pointsSupport, uint256 pointsBalance);
error TokenCannotBeZero();
error ProposalSupportDuplicated(uint256 _proposalId, uint256 index);
error ProposalIdAlreadyExist(uint256 _proposalId);

/*|--------------------------------------------|*/
/*| CUSTOM EVENTS |*/
/*|--------------------------------------------|*/

event InitializedCV(uint256 poolId, bytes data);
/*|--------------------------------------------|*o
/*| STRUCTS/ENUMS |*/
Expand All @@ -54,6 +57,7 @@ contract CVStrategy is BaseStrategy, IWithdrawMember {
Paused, // A vote that is being challenged by Agreements
Cancelled, // A vote that has been cancelled
Executed // A vote that has been executed

}

struct Proposal {
Expand Down Expand Up @@ -186,7 +190,13 @@ contract CVStrategy is BaseStrategy, IWithdrawMember {
if (proposal.amountRequested == 0) {
revert UserCannotBeZero();
}

Proposal storage p = proposals[proposal.proposalId];

if (p.proposalId == proposal.proposalId) {
revert ProposalIdAlreadyExist(proposal.proposalId);
}

p.proposalId = proposal.proposalId;
p.submitter = _sender;
p.beneficiary = proposal.beneficiary;
Expand Down Expand Up @@ -481,7 +491,6 @@ contract CVStrategy is BaseStrategy, IWithdrawMember {
* @param _oldAmount Amount of tokens staked until now
* @return Current conviction
*/

function calculateConviction(uint256 _timePassed, uint256 _lastConv, uint256 _oldAmount)
public
view
Expand Down
3 changes: 1 addition & 2 deletions pkg/contracts/src/RegistryGardens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ contract RegistryGardens is ReentrancyGuard, AccessControl {
_;
}


/*|--------------------------------------------|*/
/*| CUSTOM ERRORS |*/
/*|--------------------------------------------|*/
Expand Down Expand Up @@ -152,7 +151,7 @@ contract RegistryGardens is ReentrancyGuard, AccessControl {
}

function acceptCouncilSafe() public {
if (msg.sender != pendingCouncilSafe){
if (msg.sender != pendingCouncilSafe) {
revert CallerIsNotNewOnwer();
}
_changeCouncilSafe();
Expand Down
59 changes: 59 additions & 0 deletions pkg/contracts/test/CVStrategyHelpers.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-License-Identifier: UNLICENSED

pragma solidity ^0.8.13;

import {Allo} from "allo-v2-contracts/core/Allo.sol";
import {Metadata} from "allo-v2-contracts/core/libraries/Metadata.sol";
import {CVStrategy} from "../src/CVStrategy.sol";
import {Native} from "allo-v2-contracts/core/libraries/Native.sol";
import {IRegistry} from "allo-v2-contracts/core/interfaces/IRegistry.sol";

import {Accounts} from "allo-v2-test/foundry/shared/Accounts.sol";

contract CVStrategyHelpers is Native, Accounts {
Metadata public metadata = Metadata({protocol: 1, pointer: "strategy pointer"});

bytes32 internal _poolProfileId_;

function poolProfile_id(IRegistry registry) public virtual returns (bytes32) {
if (_poolProfileId_ == bytes32(0)) {
_poolProfileId_ = registry.createProfile(
0, "Pool Profile 1", Metadata({protocol: 1, pointer: "PoolProfile1"}), pool_admin(), pool_managers()
);
}
return _poolProfileId_;
}

function createPool(Allo allo, address strategy, address registryGardens, IRegistry registry, address token)
public
returns (uint256 poolId)
{
// IAllo allo = IAllo(ALLO_PROXY_ADDRESS);
CVStrategy.InitializeParams memory params;
params.decay = _etherToFloat(0.9 ether); // alpha = decay
params.maxRatio = _etherToFloat(0.2 ether); // beta = maxRatio
params.weight = _etherToFloat(0.002 ether); // RHO = p = weight
params.minThresholdStakePercentage = 0.2 ether; // 20%
params.registryGardens = registryGardens;

address[] memory pool_managers = new address[](2);
pool_managers[0] = address(this);
pool_managers[1] = address(msg.sender);

// bytes32 memory_poolProfileId_ = registry.createProfile(
// 0, "Pool Profile 1", Metadata({protocol: 1, pointer: "PoolProfile1"}), pool_admin(), pool_managers()
// );
address _token = NATIVE;
if (token != address(0)) {
_token = token;
}
// poolId = allo.createPoolWithCustomStrategy(
poolId = allo.createPool(
poolProfile_id(registry), address(strategy), abi.encode(params), _token, 0, metadata, pool_managers
);
}

function _etherToFloat(uint256 _amount) internal pure returns (uint256) {
return _amount / 10 ** 11;
}
}
18 changes: 15 additions & 3 deletions pkg/contracts/test/CVStrategyTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ contract CVStrategyTest is Test, AlloSetup, RegistrySetupFull, Native, Errors, G
params._metadata = metadata;
params._councilSafe = payable(address(_councilSafe()));
registryGardens = RegistryGardens(registryFactory.createRegistry(params));

}

function _registryGardens() internal view returns (RegistryGardens) {
Expand Down Expand Up @@ -206,9 +205,11 @@ contract CVStrategyTest is Test, AlloSetup, RegistrySetupFull, Native, Errors, G
*/
startMeasuringGas("Support a Proposal");
CVStrategy.ProposalSupport[] memory votes = new CVStrategy.ProposalSupport[](1);
votes[0] = CVStrategy.ProposalSupport(1, 80); // 0 + 70 = 70% = 35
votes[0] = CVStrategy.ProposalSupport(1, 80); // 0 + 70 = 70% = 35 range is -100 +100
bytes memory data = abi.encode(votes);

allo().allocate(poolId, data);

stopMeasuringGas();

CVStrategy cv = CVStrategy(payable(address(pool.strategy)));
Expand All @@ -231,6 +232,7 @@ contract CVStrategyTest is Test, AlloSetup, RegistrySetupFull, Native, Errors, G
assertEq(cv.getProposalStakedAmount(1), 40 + 50);
}

// @todo write that test vote without have points
function test_conviction_check_function() public {
(IAllo.Pool memory pool, uint256 poolId) = _createProposal();

Expand Down Expand Up @@ -459,7 +461,6 @@ contract CVStrategyTest is Test, AlloSetup, RegistrySetupFull, Native, Errors, G
* ASSERTS
*
*/

vm.warp(10 days);

(
Expand Down Expand Up @@ -488,4 +489,15 @@ contract CVStrategyTest is Test, AlloSetup, RegistrySetupFull, Native, Errors, G
// console.log("Beneficiary: %s", beneficiary);
// console.log("Submitter: %s", submitter);
}

function testRevert_registerRecipient_ProposalIdAlreadyExist() public {
(, uint256 poolId) = _createProposal();

CVStrategy.CreateProposal memory proposal = CVStrategy.CreateProposal(
1, poolId, pool_admin(), pool_admin(), CVStrategy.ProposalType.Signaling, REQUESTED_AMOUNT, NATIVE
);
bytes memory data = abi.encode(proposal);
vm.expectRevert(abi.encodeWithSelector(CVStrategy.ProposalIdAlreadyExist.selector, 1));
allo().registerRecipient(poolId, data);
}
}
Loading
Loading