Skip to content

Commit

Permalink
✨ supportProposal func
Browse files Browse the repository at this point in the history
✨ oz contracts
✨ remove FORK and add Deploy Allo
  • Loading branch information
kamikazebr committed Jan 7, 2024
1 parent 9b51f8b commit 6126efa
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "lib/safe-contracts"]
path = lib/safe-contracts
url = https://github.com/safe-global/safe-contracts
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
51 changes: 51 additions & 0 deletions apps/web/app/(app)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import React from "react";
import { NavBar } from "@/components";
import {
Abi,
AbiFunctionNotFoundError,
AbiItem,
GetAbiItemParameters,
getAbiItem,
} from "viem";

import CVStrategyABI from "#/contracts/out/CVStrategy.sol/CVStrategy.json";
import { encodeAbiParameters } from "viem/utils";

export default function layout({ children }: { children: React.ReactNode }) {
const abi = CVStrategyABI.abi as Abi;
const functionName = "supportProposal";
const args = [[[1, -10]]];

const data = encodeFunctionParams(abi, functionName, args);

console.log(data);

return (
<>
<NavBar />
Expand All @@ -10,3 +28,36 @@ export default function layout({ children }: { children: React.ReactNode }) {
</>
);
}
function encodeFunctionParams(
abi: Abi,
functionName: string,
args: readonly unknown[] = [],
) {
let abiItem = abi[0] as AbiItem;

if (functionName) {
abiItem = getAbiItem({
abi,
args,
name: functionName,
} as GetAbiItemParameters);

if (!abiItem) {
throw new AbiFunctionNotFoundError(functionName, {
docsPath: "/docs/contract/encodeFunctionData",
});
}
}

if (abiItem.type !== "function") {
throw new AbiFunctionNotFoundError(undefined, {
docsPath: "/docs/contract/encodeFunctionData",
});
}

const data =
"inputs" in abiItem && abiItem.inputs
? encodeAbiParameters(abiItem.inputs, (args ?? []) as readonly unknown[])
: undefined;
return data;
}
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 54b3f1
13 changes: 9 additions & 4 deletions pkg/contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ print :
deploy :
-forge script script/DeployCV.s.sol:DeployCV \
--rpc-url $(RPC_URL_LOCALHOST) \
--sender 0x34d82D1ED8B4fB6e6A569d6D086A39f9f734107E \
0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 \
--sender 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 \
--unlocked \
--broadcast -vv

fork:
anvil --host=0.0.0.0 -f $(RPC_URL)

Expand All @@ -28,4 +26,11 @@ test1:

cast1:
cast send --account pk --rpc-url $(RPC_URL_LOCALHOST) \
"0xfEcFbe13c84595Ba47464CD4d8d3bb359372Fc6f" "nonce()"
"0xfEcFbe13c84595Ba47464CD4d8d3bb359372Fc6f" "nonce()"

fund_arb:
cast send \
--from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
--unlocked 0xefeab1ea32a5d7c6b1de6192ee531a2ef51198d9 \
--value 100ether \
--rpc-url=$(RPC_URL_LOCALHOST)
64 changes: 31 additions & 33 deletions pkg/contracts/script/DeployCV.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,58 @@
pragma solidity ^0.8.13;

import "forge-std/console2.sol";

import "forge-std/Script.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.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 {Registry} from "allo-v2-contracts/core/Registry.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;

Allo _allo_;
Registry _registry_;

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);

// console2.log("allo.owner(): %s", address(allo.owner()));
// vm.prank(address(allo.owner()));
// allo.transferOwnership(local());

// console2.log("allo.owner2(): %s", address(allo.owner()));
// console2.log("local(): %s", address(local()));
function allo_owner() public virtual override returns (address) {
return address(0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266);
}

function run() public {
vm.startBroadcast(pool_admin());

Allo allo = Allo(deployAllo());

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);
CVStrategy strategy = new CVStrategy(address(allo));

vm.stopBroadcast();

Expand All @@ -88,19 +72,17 @@ contract DeployCV is Native, CVStrategyHelpers, Script, SafeSetup {
vm.stopBroadcast();
}

// vm.startBroadcast(address(local()));
vm.startBroadcast(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
allo.fundPool(poolId, 0.1 ether);

uint256 poolIdNative = createPool(Allo(address(allo)), address(strategy), address(0), registry, address(0));
allo.fundPool{value: 0.1 ether}(poolIdNative, 0.1 ether);
Expand All @@ -118,4 +100,20 @@ contract DeployCV is Native, CVStrategyHelpers, Script, SafeSetup {
console2.log("Pool Admin: %s", pool_admin());
console2.log("Council Safe: %s", address(_councilSafe()));
}

function deployAllo() public returns (address) {
_registry_ = new Registry();
_registry_.initialize(registry_owner());
_allo_ = new Allo();

_allo_.initialize(
allo_owner(), // _owner
address(_registry_), // _registry
allo_treasury(), // _treasury
0, // _percentFee
0 // _baseFee
);

return address(_allo_);
}
}
5 changes: 5 additions & 0 deletions pkg/contracts/src/CVStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ contract CVStrategy is BaseStrategy, IWithdrawMember {
// @TODO: emit events
}

function supportProposal(ProposalSupport[] memory) public {
// _allocate(abi.encode(_support), msg.sender);
revert("not implemented");
}

// only called via allo.sol by users to allocate to a recipient
// this will update some data in this contract to store votes, etc.
function _allocate(bytes memory _data, address _sender) internal override {
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"foundry#fork": {
"cache": false
},
"web#generate": {
"cache": false
},
"subgraph#build": {
"dependsOn": [
"foundry#build"
Expand Down

0 comments on commit 6126efa

Please sign in to comment.