Skip to content

Commit

Permalink
docs: lint + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Nov 24, 2021
1 parent 99a7d7d commit 20007b2
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 64 deletions.
94 changes: 56 additions & 38 deletions contracts/adapters/KycOnboarding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import "../extensions/bank/Bank.sol";
import "../guards/AdapterGuard.sol";
import "../utils/Signatures.sol";
import "../helpers/WETH.sol";

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

Expand Down Expand Up @@ -40,11 +39,19 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
using SafeERC20 for IERC20;

event Onboarded(DaoRegistry dao, address member, uint256 units);

struct Coupon {
address kycedMember;
}

struct OnboardingDetails {
uint88 chunkSize;
uint88 numberOfChunks;
uint88 unitsPerChunk;
uint88 unitsRequested;
uint88 maximumTotalUnits;
uint160 amount;
}

string public constant COUPON_MESSAGE_TYPE = "Message(address kycedMember)";
bytes32 public constant COUPON_MESSAGE_TYPEHASH =
keccak256(abi.encodePacked(COUPON_MESSAGE_TYPE));
Expand All @@ -65,22 +72,6 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
WETH private _weth;
IERC20 private _weth20;

event CouponRedeemed(
address daoAddress,
uint256 nonce,
address authorizedMember,
uint256 amount
);

struct OnboardingDetails {
uint88 chunkSize;
uint88 numberOfChunks;
uint88 unitsPerChunk;
uint88 unitsRequested;
uint88 maximumTotalUnits;
uint160 amount;
}

mapping(DaoRegistry => mapping(address => uint256)) public totalUnits;

constructor(address payable weth) {
Expand All @@ -94,7 +85,12 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
* @param signerAddress is the DAO instance to be configured
* @param chunkSize how many wei per chunk
* @param unitsPerChunk how many units do we get per chunk
* @param maximumChunks how many chunks can you get at most
* @param maximumChunks maximum number of chunks allowed
* @param maxUnits how many internal tokens can be minted
* @param maxMembers maximum number of members allowed to join
* @param fundTargetAddress multisig address to transfer the money from, set it to address(0) if you dont want to use a multisig
* @param tokenAddr the token in which the onboarding can take place
* @param internalTokensToMint the token that will be minted when the member joins the DAO
*/
function configureDao(
DaoRegistry dao,
Expand Down Expand Up @@ -191,24 +187,11 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
return hashMessage(dao, block.chainid, address(this), message);
}

function _checkKycCoupon(
DaoRegistry dao,
address kycedMember,
address tokenAddr,
bytes memory signature
) internal view {
require(
ECDSA.recover(
hashCouponMessage(dao, Coupon(kycedMember)),
signature
) ==
dao.getAddressConfiguration(
_configKey(tokenAddr, SignerAddressConfig)
),
"invalid sig"
);
}

/**
* @notice Starts the onboarding propocess of a kyc member that is using ETH to join the DAO.
* @param kycedMember The address of the kyced member that wants to join the DAO.
* @param signature The signature that will be verified to redeem the coupon.
*/
function onboardEth(
DaoRegistry dao,
address kycedMember,
Expand All @@ -217,6 +200,13 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
_onboard(dao, kycedMember, DaoHelper.ETH_TOKEN, msg.value, signature);
}

/**
* @notice Starts the onboarding propocess of a kyc member that is any ERC20 token to join the DAO.
* @param kycedMember The address of the kyced member that wants to join the DAO.
* @param tokenAddr The address of the ERC20 token that contains that funds of the kycedMember.
* @param amount The amount in ERC20 that will be contributed to the DAO in exchange for the DAO units.
* @param signature The signature that will be verified to redeem the coupon.
*/
function onboard(
DaoRegistry dao,
address kycedMember,
Expand All @@ -228,9 +218,10 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
}

/**
* @notice Redeems a coupon to add a new member.
* @notice Redeems a coupon to add a new member
* @param dao is the DAO instance to be configured
* @param kycedMember is the address that this coupon authorized to become a new member
* @param tokenAddr is the address the ETH address(0) or an ERC20 Token address
* @param signature is message signature for verification
*/
function _onboard(
Expand Down Expand Up @@ -303,6 +294,9 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
emit Onboarded(dao, kycedMember, details.unitsRequested);
}

/**
* @notice Verifies if the given amount is enough to join the DAO
*/
function _checkData(
DaoRegistry dao,
address tokenAddr,
Expand Down Expand Up @@ -338,6 +332,30 @@ contract KycOnboardingContract is AdapterGuard, Signatures {
);
}

/**
* @notice Checks if the given signature is valid, if so the member is allowed to reedem the coupon and join the DAO.
* @param kycedMember is the address that this coupon authorized to become a new member
* @param tokenAddr is the address the ETH address(0) or an ERC20 Token address.
* @param signature is message signature for verification
*/
function _checkKycCoupon(
DaoRegistry dao,
address kycedMember,
address tokenAddr,
bytes memory signature
) internal view {
require(
ECDSA.recover(
hashCouponMessage(dao, Coupon(kycedMember)),
signature
) ==
dao.getAddressConfiguration(
_configKey(tokenAddr, SignerAddressConfig)
),
"invalid sig"
);
}

/**
* @notice Builds the configuration key by encoding an address with a string key.
* @param tokenAddrToMint The address to encode.
Expand Down
141 changes: 119 additions & 22 deletions website/docs/contracts/adapters/onboarding/KycOnboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The only difference between Kyc Onboarding and the two others is that if configu
To join the DAO, any member needs to first get KYCed and then contribute the right amount to get his UNITS.
A member can use KYCOnboarding only once, i.e. if he is already a member he cannot use it.

There is no proposal involved here, i.e. if you are elligible to become a member you can join automatically.
There is no proposal involved here, i.e. if you are eligible to become a member you can join automatically.

## Access Flags

Expand Down Expand Up @@ -45,6 +45,10 @@ There is no proposal involved here, i.e. if you are elligible to become a member

## Structs

### Coupon

- `kycedMember`: The address of the member that has been verified, and is allowed to redeem a coupon to join the DAO.

### OnboardingDetails

- `chunkSize`: How many tokens need to be minted per chunk bought.
Expand All @@ -67,55 +71,148 @@ Accounting to see the amount of a particular internal token that has been minted
Configures the adapter for a particular DAO. The modifier is adapterOnly which means that only if the sender is either a registered adapter of the DAO or if it is in creation mode can it be called. The function checks that chunkSize, unitsPerChunks and maximumChunks cannot be 0.

```solidity
/**
* @notice Updates the DAO registry with the new configurations if valid.
* @notice Updated the Bank extension with the new potential tokens if valid.
* @param unitsToMint Which token needs to be minted if the proposal passes, it is whitelisted in the Bank.
* @param chunkSize How many tokens need to be minted per chunk bought.
* @param unitsPerChunk How many units (tokens from tokenAddr) are being minted per chunk.
* @param maximumChunks How many chunks can someone buy max. This helps force decentralization of token holders.
* @param tokenAddr In which currency (tokenAddr) should the onboarding take place.
/**
* @notice Configures the Adapter with the coupon signer address and token to mint.
* @param dao the dao to configure
* @param signerAddress is the DAO instance to be configured
* @param chunkSize how many wei per chunk
* @param unitsPerChunk how many units do we get per chunk
* @param maximumChunks maximum number of chunks allowed
* @param maxUnits how many internal tokens can be minted
* @param maxMembers maximum number of members allowed to join
* @param fundTargetAddress multisig address to transfer the money from, set it to address(0) if you dont want to use a multisig
* @param tokenAddr the token in which the onboarding can take place
* @param internalTokensToMint the token that will be minted when the member joins the DAO
*/
function configureDao(
DaoRegistry dao,
address unitsToMint,
address signerAddress,
uint256 chunkSize,
uint256 unitsPerChunk,
uint256 maximumChunks,
address tokenAddr
uint256 maxUnits,
uint256 maxMembers,
address fundTargetAddress,
address tokenAddr,
address internalTokensToMint
) external onlyAdapter(dao)
```

### \_onboardEth
### hashCouponMessage

```solidity
/**
* @notice Hashes the provided coupon as an ERC712 hash.
* @param dao is the DAO instance to be configured
* @param coupon is the coupon to hash
*/
function hashCouponMessage(DaoRegistry dao, Coupon memory coupon)
public
view
returns (bytes32)
```

### onboardEth

```solidity
/**
* @notice Builds the configuration key by encoding an address with a string key.
* @param tokenAddrToMint The address to encode.
* @param key The key to encode.
* @notice Starts the onboarding propocess of a kyc member that is using ETH to join the DAO.
* @param kycedMember The address of the kyced member that wants to join the DAO.
* @param signature The signature that will be verified to redeem the coupon.
*/
function _configKey(address tokenAddrToMint, bytes32 key)
internal
pure
function onboardEth(
DaoRegistry dao,
address kycedMember,
bytes memory signature
) external payable
```

### \_onboard
### onboard

```solidity
/**
* @notice Starts the onboarding process of a kyc member that is any ERC20 token to join the DAO.
* @param kycedMember The address of the kyced member that wants to join the DAO.
* @param tokenAddr The address of the ERC20 token that contains that funds of the kycedMember.
* @param amount The amount in ERC20 that will be contributed to the DAO in exchange for the DAO units.
* @param signature The signature that will be verified to redeem the coupon.
*/
function onboard(
DaoRegistry dao,
address kycedMember,
address tokenAddr,
uint256 amount,
bytes memory signature
) external
```

### \_onboard

```solidity
/**
* @notice Redeems a coupon to add a new member
* @param dao is the DAO instance to be configured
* @param kycedMember is the address that this coupon authorized to become a new member
* @param tokenAddr is the address the ETH address(0) or an ERC20 Token address
* @param signature is message signature for verification
*/
function _onboard(
DaoRegistry dao,
address kycedMember,
address tokenAddr,
uint256 amount,
bytes memory signature
) internal reentrancyGuard(dao)
```

### \_checkData

```solidity
/**
* @notice Verifies if the given amount is enough to join the DAO
*/
function _checkData(
DaoRegistry dao,
address tokenAddr,
uint256 amount
) internal view returns (OnboardingDetails memory details)
```

### \_checkKycCoupon

```solidity
/**
* @notice Checks if the given signature is valid, if so the member is allowed to reedem the coupon and join the DAO.
* @param kycedMember is the address that this coupon authorized to become a new member
* @param tokenAddr is the address the ETH address(0) or an ERC20 Token address.
* @param signature is message signature for verification
*/
function _checkKycCoupon(
DaoRegistry dao,
address kycedMember,
address tokenAddr,
bytes memory signature
) internal view
```

### \_configKey

```solidity
/**
* @notice Builds the configuration key by encoding an address with a string key.
* @param tokenAddrToMint The address to encode.
* @param key The key to encode.
*/
function _configKey(address tokenAddrToMint, bytes32 key)
internal
pure
returns (bytes32)
```

### Events

No events are emitted.
### Onboarded

## Events
When the onboarding process is completed the `Onboarded` event is emitted with the `dao` and `member` addresses, and `amount` of units minted to the new member.

- No events are emitted.
- `event Onboarded(DaoRegistry dao, address member, uint256 units);`
4 changes: 0 additions & 4 deletions website/docs/contracts/adapters/onboarding/Onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,3 @@ Starts a vote on the proposal to onboard a new member.
### Events

No events are emitted.

## Events

- No events are emitted.

0 comments on commit 20007b2

Please sign in to comment.