# Delegation

Takers may provide allowances on specific offer lists, so other addresses (called "delegate takers") can execute market orders in their name. Allowance may be set using the `approve` function, or through an [EIP712](https://eips.ethereum.org/EIPS/eip-712) permit using the `permit` function.

Allowances are set on a token pair (A, B) without specifying `tickSpacing`, meaning "delegate taker has the right to trade token A against token B at any `tickSpacing`".

## Setting Delegation Allowance

To set allowance, use either the `permit` or `approve` function:

Signature

```solidity
function permit(
    address outbound_tkn,
    address inbound_tkn,
    address owner,
    address spender,
    uint value,
    uint deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

function approve(
    address outbound_tkn,
    address inbound_tkn,
    address spender,
    uint value
) external returns (bool);
```

### Inputs

#### `permit()`

* `(outbound_tkn, inbound_tkn)` the outbound and inbound tokens of the offer lists on which the `Delegate Taker` will be permitted to execute market orders.
* `owner` the address of the taker providing the permit.
* `spender` the address of the `Delegate Taker`.
* `value` the maximal amount of inbound tokens the `Delegate Taker` is permitted to spend.
* `deadline` the block number beyond which the delegator's signature can no longer be used to obtain permission.
* `(v,r,s)` the `secp256k1` [signature](https://eips.ethereum.org/EIPS/eip-2612) identifying the `owner`.

#### `approve()`

* `(outbound_tkn, inbound_tkn)` the outbound and inbound tokens of the offer lists on which the `Delegate Taker` will be permitted to execute market orders.
* `spender` the address of the `Delegate Taker`.
* `value` the maximal amount of inbound tokens the `Delegate Taker` is permitted to spend.

`msg.sender` is the taker who is approving `spender`.

## Executing Delegated Orders

Once granted, a delegate taker can execute market orders via the `marketOrderFor*` functions:

```solidity
function marketOrderForByTick(
  OLKey memory olKey,
  Tick maxTick,
  uint fillVolume,
  bool fillWants,
  address taker
) external returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);

function marketOrderForByVolume(
    OLKey memory olKey,
    uint takerWants,
    uint takerGives,
    bool fillWants,
    address taker
) external returns (uint takerGot, uint takerGave, uint bounty, uint feePaid);
```

These behave identically to their non-delegated versions, except that the funds and results are attributed to the specified `taker` address.


---

# 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://docs.mangrove.exchange/dev/protocol/technical-references/takers/delegation.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.
