# Dao.sol

DAO is ERC20 itself, we call this token – GT (Governance Token). Balance in this token is voting power. Transfers are prohibited, but transfers with voting are allowed.

All voting are offchain (with signatures)

To create voting you need to generate hash, sign it with your private key, get the same signatures from your friends and provide them as argument to execute() function

```javascript
function execute(
        address _target,
        bytes calldata _data,
        uint256 _value,
        uint256 _nonce,
        uint256 _timestamp,
        bytes[] memory _sigs
    ) external nonReentrant returns (bool) {
        require(checkSubscription(), "DAO: subscription not paid");

        require(balanceOf(msg.sender) > 0, "DAO: only for members");

        require(
            _timestamp + VOTING_DURATION >= block.timestamp,
            "DAO: voting is over"
        );

        bytes32 txHash = getTxHash(_target, _data, _value, _nonce, _timestamp);

        require(!executedTx[txHash], "DAO: voting already executed");

        require(_checkSigs(_sigs, txHash), "DAO: quorum is not reached");

        executedTx[txHash] = true;

        executedVotings.push(
            ExecutedVoting({
                target: _target,
                data: _data,
                value: _value,
                nonce: _nonce,
                timestamp: _timestamp,
                executionTimestamp: block.timestamp,
                txHash: txHash,
                sigs: _sigs
            })
        );

        if (_data.length == 0) {
            payable(_target).sendValue(_value);
        } else {
            if (_value == 0) {
                _target.functionCall(_data);
            } else {
                _target.functionCallWithValue(_data, _value);
            }
        }

        emit Executed(
            _target,
            _data,
            _value,
            _nonce,
            _timestamp,
            block.timestamp,
            txHash,
            _sigs
        );

        return true;
    }
```

JS Snippets to generate this you can find in test/utils.ts

```javascript
export const createData = (
  func: string,
  argtypes: string[] = [],
  args: any[] = []
): string =>
  argtypes.length === 0 && args.length === 0
    ? id(`${func}()`).slice(0, 10) + new AbiCoder().encode([], []).slice(2)
    : id(`${func}(${argtypes.join(",")})`).slice(0, 10) +
      new AbiCoder().encode(argtypes, args).slice(2)

export const createTxHash = (
  daoAddress: string,
  target: string,
  data: string,
  value: BigNumberish,
  nonce: BigNumberish,
  timestamp: BigNumberish
): Uint8Array =>
  arrayify(
    keccak256(
      new AbiCoder().encode(
        ["address", "address", "bytes", "uint256", "uint256", "uint256"],
        [daoAddress, target, data, value, nonce, timestamp]
      )
    )
  )

```

Permitted Address Set – these addresses can execute from DAO without voting

```javascript
function executePermitted(
        address _target,
        bytes calldata _data,
        uint256 _value
    ) external nonReentrant returns (bool) {
        require(checkSubscription(), "DAO: subscription not paid");

        require(permitted.contains(msg.sender), "DAO: only for permitted");

        if (_data.length == 0) {
            payable(_target).sendValue(_value);
        } else {
            if (_value == 0) {
                _target.functionCall(_data);
            } else {
                _target.functionCallWithValue(_data, _value);
            }
        }

        executedPermitted.push(
            ExecutedPermitted({
                target: _target,
                data: _data,
                value: _value,
                executionTimestamp: block.timestamp,
                executor: msg.sender
            })
        );

        emit ExecutedP(_target, _data, _value, msg.sender);

        return true;
    }
```

Adapters Address Set – these permitted contracts help to withdraw your share when you burn your LP tokens


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://modagavr.gitbook.io/xdao-contracts/dao.sol.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
