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

feat: New Adapter - Reimbursement #412

Merged
merged 64 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
988bf1e
add new reimbursement adapter
adridadou Sep 23, 2021
2a2fed6
Merge branch 'master' into adapter-reimbursement
adridadou Sep 25, 2021
568da26
Merge branch 'master' into adapter-reimbursement
adridadou Sep 30, 2021
eb4ed1b
merge master
adridadou Oct 1, 2021
80e2ccc
make reimbursement a modifier instead of an adapter
adridadou Oct 1, 2021
a6321c3
example of reimbursable in onboarding
adridadou Oct 1, 2021
6811d00
make it fault tolerant
adridadou Oct 1, 2021
9be50de
reimbursable means also reentrancyGuard
adridadou Oct 1, 2021
c224c03
cleanup
adridadou Oct 1, 2021
cf962b4
add reimbursement
adridadou Oct 4, 2021
498a8cb
reimbursement working for onboarding
adridadou Oct 5, 2021
ba916e0
Merge branch 'master' into adapter-reimbursement
adridadou Oct 5, 2021
09bc38a
remove hardhat config
adridadou Oct 5, 2021
d0243b0
merge master
adridadou Oct 5, 2021
f9c8359
revert Voting to master and clear slither issues
adridadou Oct 5, 2021
a954ed0
cleanup reimbursement
adridadou Oct 5, 2021
d6a645f
remove duplicate code
adridadou Oct 5, 2021
742ffdf
remove storage test
adridadou Oct 5, 2021
6e8a64a
remove unused files
adridadou Oct 5, 2021
284f930
WIP adding reimbursable in relevant places
adridadou Oct 6, 2021
72747f4
reorg Reimbursable modifier to avoid polluting the stack to avoid 'st…
adridadou Oct 8, 2021
5607c1f
add reimbursable to tribute nft
adridadou Oct 8, 2021
efc8de6
improve reimbursement
adridadou Oct 8, 2021
3e4924c
add reimbursement configuration
adridadou Oct 11, 2021
da1ca9e
merge master
adridadou Oct 11, 2021
8ad3ee2
add a way to add eth directly into bank + fix verify script
adridadou Oct 18, 2021
ffa5572
Merge branch 'master' into adapter-reimbursement
adridadou Oct 21, 2021
e9d35d2
merge master
adridadou Oct 27, 2021
11ae0ee
update web3.js, fix verify and deployment for rinkeby
adridadou Oct 29, 2021
09ccea2
Merge branch 'master' into adapter-reimbursement
adridadou Oct 29, 2021
3a08e6f
merge master
adridadou Nov 4, 2021
ba620a6
added fee percentage and fixed gas
adridadou Nov 4, 2021
61b95fe
cleanup bank error message
adridadou Nov 4, 2021
f2e510e
cleanup reimbursement
adridadou Nov 5, 2021
9f4359a
merge master
adridadou Nov 6, 2021
6353db6
lint
adridadou Nov 6, 2021
da312a7
fix master merge
adridadou Nov 6, 2021
5878148
lint
adridadou Nov 6, 2021
b8d6ab4
fix test
adridadou Nov 6, 2021
6a19e3c
lint
adridadou Nov 6, 2021
e5f8eb3
add usage of sendEth
adridadou Nov 8, 2021
efd4823
get reimbursement working again, todo fix gelato integration
adridadou Nov 17, 2021
9db287a
merge master
adridadou Nov 17, 2021
856f9b8
prepare for gelato integration
adridadou Nov 18, 2021
586e09a
merge master
adridadou Nov 24, 2021
bc7e08a
lint
adridadou Nov 25, 2021
0efe77a
merge master
adridadou Nov 25, 2021
62a6954
fix compile error
adridadou Nov 25, 2021
d810a2f
use withdrawTo in reimbursement
adridadou Nov 25, 2021
69c81aa
reimbursement works with old and new bank
adridadou Nov 25, 2021
2615ebe
added reimbursable to relevant places
adridadou Nov 29, 2021
039244c
fix tests
adridadou Nov 29, 2021
1c21a42
fix deployment script
adridadou Nov 29, 2021
2743e34
merge master
adridadou Nov 30, 2021
5575e1f
add reimbursement for sending NFTs to TributeNFT
adridadou Dec 2, 2021
210a40a
Merge branch 'master' into adapter-reimbursement
adridadou Dec 2, 2021
5bd84c5
fix reimbursement when someone sends an NFT. we need to reimburse fro…
adridadou Dec 2, 2021
6d46bf8
revert solc version for slither
adridadou Dec 2, 2021
5fdfa84
added documentation
adridadou Dec 2, 2021
a14ea74
fix documentation
adridadou Dec 2, 2021
acf5861
merge master
adridadou Dec 3, 2021
614343e
disable slither issues
adridadou Dec 3, 2021
076eebe
disabled false-positite slither issues
fforbeck Dec 3, 2021
0704637
fixes for deployment and tests
fforbeck Dec 3, 2021
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ contracts-backup
.coverage_artifacts
.coverage_contracts

.env
.env*

subgraph/docker/data
artifacts
Expand Down
21 changes: 16 additions & 5 deletions contracts/adapters/BankAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../extensions/bank/Bank.sol";
import "../guards/AdapterGuard.sol";
import "../adapters/interfaces/IVoting.sol";
import "../helpers/DaoHelper.sol";
import "./modifiers/Reimbursable.sol";

/**
MIT License
Expand All @@ -32,7 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract BankAdapterContract is AdapterGuard {
contract BankAdapterContract is AdapterGuard, Reimbursable {
/**
* @notice Allows the member/advisor of the DAO to withdraw the funds from their internal bank account.
* @notice Only accounts that are not reserved can withdraw the funds.
Expand All @@ -45,7 +46,7 @@ contract BankAdapterContract is AdapterGuard {
DaoRegistry dao,
address payable account,
address token
) external reentrancyGuard(dao) {
) external reimbursable(dao) {
require(
DaoHelper.isNotReservedAddress(account),
"withdraw::reserved address"
Expand Down Expand Up @@ -74,9 +75,19 @@ contract BankAdapterContract is AdapterGuard {
{
// We do not need to check if the token is supported by the bank,
// because if it is not, the balance will always be zero.
BankExtension bank = BankExtension(
dao.getExtensionAddress(DaoHelper.BANK)
BankExtension(dao.getExtensionAddress(DaoHelper.BANK)).updateToken(
token
);
bank.updateToken(token);
}

/*
* @notice Allows anyone to send eth to the bank extension
* @param dao The DAO address.
*/
function sendEth(DaoRegistry dao) external payable reimbursable(dao) {
require(msg.value > 0, "no eth sent!");
BankExtension(dao.getExtensionAddress(DaoHelper.BANK)).addToBalance{
value: msg.value
}(DaoHelper.GUILD, DaoHelper.ETH_TOKEN, msg.value);
}
}
7 changes: 4 additions & 3 deletions contracts/adapters/Configuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import "../core/DaoRegistry.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "./interfaces/IConfiguration.sol";
import "../adapters/interfaces/IVoting.sol";
import "../helpers/DaoHelper.sol";
Expand Down Expand Up @@ -32,7 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract ConfigurationContract is IConfiguration, AdapterGuard {
contract ConfigurationContract is IConfiguration, AdapterGuard, Reimbursable {
mapping(address => mapping(bytes32 => Configuration[]))
private _configurations;

Expand All @@ -49,7 +50,7 @@ contract ConfigurationContract is IConfiguration, AdapterGuard {
bytes32 proposalId,
Configuration[] calldata configs,
bytes calldata data
) external override reentrancyGuard(dao) {
) external override reimbursable(dao) {
require(configs.length > 0, "missing configs");

dao.submitProposal(proposalId);
Expand Down Expand Up @@ -92,7 +93,7 @@ contract ConfigurationContract is IConfiguration, AdapterGuard {
function processProposal(DaoRegistry dao, bytes32 proposalId)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
dao.processProposal(proposalId);

Expand Down
7 changes: 4 additions & 3 deletions contracts/adapters/CouponOnboarding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pragma solidity ^0.8.0;
import "../core/DaoRegistry.sol";
import "../extensions/bank/Bank.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "../utils/Signatures.sol";
import "../helpers/DaoHelper.sol";

Expand Down Expand Up @@ -32,7 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract CouponOnboardingContract is AdapterGuard, Signatures {
contract CouponOnboardingContract is Reimbursable, AdapterGuard, Signatures {
struct Coupon {
address authorizedMember;
uint256 amount;
Expand Down Expand Up @@ -117,7 +118,7 @@ contract CouponOnboardingContract is AdapterGuard, Signatures {
)
);

return hashMessage(dao, block.chainid, address(this), message);
return hashMessage(dao, address(this), message);
}

/**
Expand All @@ -136,7 +137,7 @@ contract CouponOnboardingContract is AdapterGuard, Signatures {
uint256 amount,
uint256 nonce,
bytes memory signature
) external reentrancyGuard(dao) {
) external reimbursable(dao) {
uint256 currentFlag = _flags[address(dao)][nonce / 256];
_flags[address(dao)][nonce / 256] = DaoHelper.setFlag(
currentFlag,
Expand Down
9 changes: 5 additions & 4 deletions contracts/adapters/Distribute.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import "../core/DaoRegistry.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "../adapters/interfaces/IVoting.sol";
import "../adapters/interfaces/IDistribute.sol";
import "../helpers/FairShareHelper.sol";
Expand Down Expand Up @@ -34,7 +35,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract DistributeContract is IDistribute, AdapterGuard {
contract DistributeContract is IDistribute, AdapterGuard, Reimbursable {
// Event to indicate the distribution process has been completed
// if the unitHolder address is 0x0, then the amount were distributed to all members of the DAO.
event Distributed(
Expand Down Expand Up @@ -95,7 +96,7 @@ contract DistributeContract is IDistribute, AdapterGuard {
address token,
uint256 amount,
bytes calldata data
) external override reentrancyGuard(dao) {
) external override reimbursable(dao) {
IVoting votingContract = IVoting(
dao.getAdapterAddress(DaoHelper.VOTING)
);
Expand Down Expand Up @@ -156,7 +157,7 @@ contract DistributeContract is IDistribute, AdapterGuard {
function processProposal(DaoRegistry dao, bytes32 proposalId)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
dao.processProposal(proposalId);

Expand Down Expand Up @@ -224,7 +225,7 @@ contract DistributeContract is IDistribute, AdapterGuard {
function distribute(DaoRegistry dao, uint256 toIndex)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
// Checks if the proposal does not exist or is not completed yet
bytes32 ongoingProposalId = ongoingDistributions[address(dao)];
Expand Down
7 changes: 4 additions & 3 deletions contracts/adapters/Financing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "../core/DaoRegistry.sol";
import "../extensions/bank/Bank.sol";
import "../adapters/interfaces/IVoting.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "../helpers/DaoHelper.sol";

/**
Expand All @@ -33,7 +34,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract FinancingContract is IFinancing, AdapterGuard {
contract FinancingContract is IFinancing, AdapterGuard, Reimbursable {
struct ProposalDetails {
address applicant; // the proposal applicant address, can not be a reserved address
uint256 amount; // the amount requested for funding
Expand Down Expand Up @@ -64,7 +65,7 @@ contract FinancingContract is IFinancing, AdapterGuard {
address token,
uint256 amount,
bytes memory data
) external override reentrancyGuard(dao) {
) external override reimbursable(dao) {
require(amount > 0, "invalid requested amount");
BankExtension bank = BankExtension(
dao.getExtensionAddress(DaoHelper.BANK)
Expand Down Expand Up @@ -107,7 +108,7 @@ contract FinancingContract is IFinancing, AdapterGuard {
function processProposal(DaoRegistry dao, bytes32 proposalId)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
ProposalDetails memory details = proposals[address(dao)][proposalId];

Expand Down
7 changes: 4 additions & 3 deletions contracts/adapters/GuildKick.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;

import "../core/DaoRegistry.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "./interfaces/IGuildKick.sol";
import "../helpers/GuildKickHelper.sol";
import "../adapters/interfaces/IVoting.sol";
Expand Down Expand Up @@ -34,7 +35,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract GuildKickContract is IGuildKick, AdapterGuard {
contract GuildKickContract is IGuildKick, AdapterGuard, Reimbursable {
// State of the guild kick proposal
struct GuildKick {
// The address of the member to kick out of the DAO.
Expand All @@ -61,7 +62,7 @@ contract GuildKickContract is IGuildKick, AdapterGuard {
bytes32 proposalId,
address memberToKick,
bytes calldata data
) external override reentrancyGuard(dao) {
) external override reimbursable(dao) {
IVoting votingContract = IVoting(
dao.getAdapterAddress(DaoHelper.VOTING)
);
Expand Down Expand Up @@ -115,7 +116,7 @@ contract GuildKickContract is IGuildKick, AdapterGuard {
function processProposal(DaoRegistry dao, bytes32 proposalId)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
dao.processProposal(proposalId);

Expand Down
12 changes: 9 additions & 3 deletions contracts/adapters/KycOnboarding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../utils/Signatures.sol";
import "../helpers/WETH.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "./modifiers/Reimbursable.sol";

/**
MIT License
Expand All @@ -34,7 +35,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract KycOnboardingContract is AdapterGuard, MemberGuard, Signatures {
contract KycOnboardingContract is
AdapterGuard,
MemberGuard,
Signatures,
Reimbursable
{
using Address for address payable;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -184,7 +190,7 @@ contract KycOnboardingContract is AdapterGuard, MemberGuard, Signatures {
abi.encode(COUPON_MESSAGE_TYPEHASH, coupon.kycedMember)
);

return hashMessage(dao, block.chainid, address(this), message);
return hashMessage(dao, address(this), message);
}

/**
Expand Down Expand Up @@ -234,7 +240,7 @@ contract KycOnboardingContract is AdapterGuard, MemberGuard, Signatures {
address tokenAddr,
uint256 amount,
bytes memory signature
) internal reentrancyGuard(dao) {
) internal reimbursable(dao) {
require(!isActiveMember(dao, kycedMember), "already member");
uint256 maxMembers = dao.getConfiguration(
_configKey(tokenAddr, MaxMembers)
Expand Down
30 changes: 19 additions & 11 deletions contracts/adapters/LendNFT.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "../extensions/token/erc20/InternalTokenVestingExtension.sol";
import "../adapters/interfaces/IVoting.sol";
import "../helpers/DaoHelper.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";

Expand Down Expand Up @@ -36,7 +37,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {
contract LendNFTContract is
AdapterGuard,
Reimbursable,
IERC1155Receiver,
IERC721Receiver
{
using Address for address payable;

struct ProcessProposal {
Expand Down Expand Up @@ -70,16 +76,18 @@ contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {

/**
* @notice Configures the adapter for a particular DAO.
* @notice Registers the DAO internal token UNITS with the DAO Bank.
* @notice Registers the DAO internal token with the DAO Bank.
* @dev Only adapters registered to the DAO can execute the function call (or if the DAO is in creation mode).
* @dev A DAO Bank extension must exist and be configured with proper access for this adapter.
* @param dao The DAO address.
* @param token The token address that will be configured as internal token.
*/
function configureDao(DaoRegistry dao) external onlyAdapter(dao) {
BankExtension bank = BankExtension(
dao.getExtensionAddress(DaoHelper.BANK)
);
bank.registerPotentialNewInternalToken(DaoHelper.UNITS);
function configureDao(DaoRegistry dao, address token)
external
onlyAdapter(dao)
{
BankExtension(dao.getExtensionAddress(DaoHelper.BANK))
.registerPotentialNewInternalToken(token);
}

/**
Expand All @@ -104,7 +112,7 @@ contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {
uint88 requestAmount,
uint64 lendingPeriod,
bytes memory data
) external reentrancyGuard(dao) {
) external reimbursable(dao) {
require(
DaoHelper.isNotReservedAddress(applicant),
"applicant is reserved address"
Expand Down Expand Up @@ -228,7 +236,7 @@ contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {
// slither-disable-next-line reentrancy-benign
function sendNFTBack(DaoRegistry dao, bytes32 proposalId)
external
reentrancyGuard(dao)
reimbursable(dao)
{
ProposalDetails storage proposal = proposals[address(dao)][proposalId];
require(proposal.lendingStart > 0, "lending not started");
Expand Down Expand Up @@ -314,7 +322,7 @@ contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {
address from,
uint256 id,
uint256 value
) internal reentrancyGuard(dao) returns (bytes4) {
) internal reimbursable(dao) returns (bytes4) {
(
ProposalDetails storage proposal,
IVoting.VotingState voteResult
Expand Down Expand Up @@ -375,7 +383,7 @@ contract LendNFTContract is AdapterGuard, IERC1155Receiver, IERC721Receiver {
bytes32 proposalId,
address from,
uint256 tokenId
) internal reentrancyGuard(dao) returns (bytes4) {
) internal reimbursable(dao) returns (bytes4) {
(
ProposalDetails storage proposal,
IVoting.VotingState voteResult
Expand Down
7 changes: 4 additions & 3 deletions contracts/adapters/Managing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "./interfaces/IManaging.sol";
import "../core/DaoRegistry.sol";
import "../adapters/interfaces/IVoting.sol";
import "../guards/AdapterGuard.sol";
import "./modifiers/Reimbursable.sol";
import "../helpers/DaoHelper.sol";

/**
Expand All @@ -32,7 +33,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

contract ManagingContract is IManaging, AdapterGuard {
contract ManagingContract is IManaging, AdapterGuard, Reimbursable {
// DAO => (ProposalID => ProposalDetails)
mapping(address => mapping(bytes32 => ProposalDetails)) public proposals;
// DAO => (ProposalId => Configuration[])
Expand All @@ -57,7 +58,7 @@ contract ManagingContract is IManaging, AdapterGuard {
ProposalDetails calldata proposal,
Configuration[] memory configs,
bytes calldata data
) external override reentrancyGuard(dao) {
) external override reimbursable(dao) {
require(
proposal.keys.length == proposal.values.length,
"must be an equal number of config keys and values"
Expand Down Expand Up @@ -120,7 +121,7 @@ contract ManagingContract is IManaging, AdapterGuard {
function processProposal(DaoRegistry dao, bytes32 proposalId)
external
override
reentrancyGuard(dao)
reimbursable(dao)
{
ProposalDetails memory proposal = proposals[address(dao)][proposalId];

Expand Down
Loading