Skip to content

Commit 33f2598

Browse files
authored
Contract structure set up. (#60)
GovernanceAdapter that enables a Set to interact with the GovernanceModule via the BaseManager contract.
1 parent 93c8d9e commit 33f2598

File tree

17 files changed

+1507
-12
lines changed

17 files changed

+1507
-12
lines changed
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
/*
2+
Copyright 2021 IndexCooperative
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
pragma solidity 0.6.10;
18+
19+
import { BaseAdapter } from "../lib/BaseAdapter.sol";
20+
import { IBaseManager } from "../interfaces/IBaseManager.sol";
21+
import { IGovernanceModule } from "../interfaces/IGovernanceModule.sol";
22+
import { ISetToken } from "../interfaces/ISetToken.sol";
23+
24+
/**
25+
* @title GovernanceAdapter
26+
* @author Set Protocol
27+
*
28+
* Smart contract adapter that acts as a manager interface for interacting with the Set Protocol
29+
* GovernanceModule to perform meta-governance actions. All governance functions are callable only
30+
* by a subset of allowed callers. The operator has the power to add/remove callers from the allowed
31+
* callers mapping.
32+
*/
33+
contract GovernanceAdapter is BaseAdapter {
34+
35+
/* ============ State Variables ============ */
36+
37+
ISetToken public setToken;
38+
IGovernanceModule public governanceModule;
39+
40+
/* ============ Constructor ============ */
41+
42+
constructor(IBaseManager _manager, IGovernanceModule _governanceModule) public BaseAdapter(_manager) {
43+
governanceModule = _governanceModule;
44+
setToken = manager.setToken();
45+
}
46+
47+
/* ============ External Functions ============ */
48+
49+
/**
50+
* ONLY APPROVED CALLER: Submits a delegate call to the GovernanceModule. Approved caller mapping
51+
* is part of BaseAdapter.
52+
*
53+
* @param _governanceName Name of governance adapter being used
54+
55+
*/
56+
function delegate(
57+
string memory _governanceName,
58+
address _delegatee
59+
)
60+
external
61+
onlyAllowedCaller(msg.sender)
62+
{
63+
bytes memory callData = abi.encodeWithSelector(
64+
IGovernanceModule.delegate.selector,
65+
setToken,
66+
_governanceName,
67+
_delegatee
68+
);
69+
70+
invokeManager(address(governanceModule), callData);
71+
}
72+
73+
/**
74+
* ONLY APPROVED CALLER: Submits a proposal call to the GovernanceModule. Approved caller mapping
75+
* is part of BaseAdapter.
76+
*
77+
* @param _governanceName Name of governance adapter being used
78+
* @param _proposalData Byte data of proposal
79+
*/
80+
function propose(
81+
string memory _governanceName,
82+
bytes memory _proposalData
83+
)
84+
external
85+
onlyAllowedCaller(msg.sender)
86+
{
87+
bytes memory callData = abi.encodeWithSelector(
88+
IGovernanceModule.propose.selector,
89+
setToken,
90+
_governanceName,
91+
_proposalData
92+
);
93+
94+
invokeManager(address(governanceModule), callData);
95+
}
96+
97+
/**
98+
* ONLY APPROVED CALLER: Submits a register call to the GovernanceModule. Approved caller mapping
99+
* is part of BaseAdapter.
100+
*
101+
* @param _governanceName Name of governance adapter being used
102+
*/
103+
function register(string memory _governanceName) external onlyAllowedCaller(msg.sender) {
104+
bytes memory callData = abi.encodeWithSelector(
105+
IGovernanceModule.register.selector,
106+
setToken,
107+
_governanceName
108+
);
109+
110+
invokeManager(address(governanceModule), callData);
111+
}
112+
113+
/**
114+
* ONLY APPROVED CALLER: Submits a revoke call to the GovernanceModule. Approved caller mapping
115+
* is part of BaseAdapter.
116+
*
117+
* @param _governanceName Name of governance adapter being used
118+
*/
119+
function revoke(string memory _governanceName) external onlyAllowedCaller(msg.sender) {
120+
bytes memory callData = abi.encodeWithSelector(
121+
IGovernanceModule.revoke.selector,
122+
setToken,
123+
_governanceName
124+
);
125+
126+
invokeManager(address(governanceModule), callData);
127+
}
128+
129+
/**
130+
* ONLY APPROVED CALLER: Submits a vote call to the GovernanceModule. Approved caller mapping
131+
* is part of BaseAdapter.
132+
*
133+
* @param _governanceName Name of governance adapter being used
134+
* @param _proposalId Id of proposal being voted on
135+
* @param _support Boolean indicating if supporting proposal
136+
* @param _data Arbitrary bytes to be used to construct vote call data
137+
*/
138+
function vote(
139+
string memory _governanceName,
140+
uint256 _proposalId,
141+
bool _support,
142+
bytes memory _data
143+
)
144+
external
145+
onlyAllowedCaller(msg.sender)
146+
{
147+
bytes memory callData = abi.encodeWithSelector(
148+
IGovernanceModule.vote.selector,
149+
setToken,
150+
_governanceName,
151+
_proposalId,
152+
_support,
153+
_data
154+
);
155+
156+
invokeManager(address(governanceModule), callData);
157+
}
158+
159+
/**
160+
* ONLY OPERATOR: Initialize GovernanceModule for Set
161+
*/
162+
function initialize() external onlyOperator {
163+
bytes memory callData = abi.encodeWithSelector(
164+
IGovernanceModule.initialize.selector,
165+
setToken
166+
);
167+
168+
invokeManager(address(governanceModule), callData);
169+
}
170+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2020 Set Labs Inc.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
SPDX-License-Identifier: Apache License, Version 2.0
13+
*/
14+
pragma solidity 0.6.10;
15+
16+
import { ISetToken } from "./ISetToken.sol";
17+
18+
interface IGovernanceModule {
19+
function delegate(ISetToken _setToken, string memory _governanceName, address _delegatee) external;
20+
function propose(ISetToken _setToken, string memory _governanceName, bytes memory _proposalData) external;
21+
function register(ISetToken _setToken, string memory _governanceName) external;
22+
function revoke(ISetToken _setToken, string memory _governanceName) external;
23+
function vote(
24+
ISetToken _setToken,
25+
string memory _governanceName,
26+
uint256 _proposalId,
27+
bool _support,
28+
bytes memory _data
29+
)
30+
external;
31+
function initialize(ISetToken _setToken) external;
32+
}

0 commit comments

Comments
 (0)