# DAO Treasury

A Treasury for DAOs. It can receive and send `sui::coin::Coin`.

## Structs

### <mark style="color:blue;">**DaoTreasury**</mark>

```rust
struct DaoTreasury<phantom DaoWitness: drop> has key, store {
    id: UID,
    coins: Bag,
    dao: ID,
}
```

* **coins** - Stores the treasury coins
* **dao**- The `sui::object::ID` of the DAO.

### <mark style="color:blue;">**DaoTreasury**</mark>

```rust
struct FlashLoan<phantom DaoWitness, phantom CoinType> {
    amount: u64,
    fee: u64,
    type: TypeName
}
```

* **amounts:** The amount being borrowed
* **fee**- The fee amount to be repaid.
* **type:** The std::type\_name::TypeName of the CoinType to repay the loan.

## Interface

### <mark style="color:blue;">dao</mark>

**Returns the `sui::object::ID` of the Dao that owns the `treasury`.**

```rust
public fun dao<DaoWitness: drop>(treasury: &DaoTreasury<DaoWitness>): ID 
```

* **@param treasury:** A DaoTreasury.
* **@return** ID

### <mark style="color:blue;">balance</mark>

**Returns the amount of Coin in the `treasury`.**

```rust
public fun balance<DaoWitness: drop, CoinType>(treasury: &DaoTreasury<DaoWitness>): u64
```

* **@param treasury:** A DaoTreasury.
* **@return** u64

### <mark style="color:blue;">donate</mark>

**Adds `token` to the `treasury`.**

```rust
public fun donate<DaoWitness: drop, CoinType>(treasury: &mut DaoTreasury<DaoWitness>, token: Coin<CoinType>, ctx: &mut TxContext)
```

* **@param treasury A DaoTreasury.**
* **@param token It will be donated to the `treasury`.**

### <mark style="color:blue;">transfer</mark>

**Withdraws a coin from the `treasury`.**

```rust
public fun transfer<DaoWitness: drop, CoinType, TransferCoin>(
    treasury: &mut DaoTreasury<DaoWitness>,
    _: &DaoAdmin<DaoWitness>,
    value: u64,
    ctx: &mut TxContext
): Coin<CoinType>
```

* **@param treasury:** A DaoTreasury.
* **@param \_ :** Immutable reference to the DaoAdmin.
* **@param value :** The amount to withdraw.
* **@return** Coin

### <mark style="color:blue;">transfer\_linear\_vesting\_wallet</mark>

**Withdraws a LinearWallet from the `treasury`.**

```rust
public fun transfer_linear_vesting_wallet<DaoWitness: drop, CoinType, TransferCoin>(
    treasury: &mut DaoTreasury<DaoWitness>,
    _: &DaoAdmin<DaoWitness>,
    c: &Clock,
    value: u64,
    start: u64,
    duration: u64,
    ctx: &mut TxContext    
): LinearWallet<CoinType>
```

* **@param treasury:** A DaoTreasury.
* **@param \_ :** Immutable reference to the DaoAdmin.
* **@param c:** The `sui::clock::Clock`
* **@param value :** The amount to withdraw.
* **@param start :** The amount to withdraw.
* **@param duration :** The duration of the vesting schedule.
* **@return** LinearWallet.

### <mark style="color:blue;">flash\_loan</mark>

**Requests a Flash Loan from the `treasury`.**

```rust
public fun flash_loan<DaoWitness: drop, CoinType>(
    treasury: &mut DaoTreasury<DaoWitness>, 
    value: u64, 
    ctx: &mut TxContext
): (Coin<CoinType>, FlashLoan<DaoWitness, CoinType>)
```

* **@param treasury:** A DaoTreasury.
* **@param value :** The amount of the loan.
* **@return Coin\<CoinType>.** The coin that is being borrowed.
* **@return** FlashLoan\<DaoWitness, CoinType>. Hot potato to ensure that the coin is returned within the same transaction block.&#x20;

### <mark style="color:blue;">fee</mark>

**Returns the service fee amount that must be paid.**

```rust
public fun fee<DaoWitness: drop, CoinType>(flash_loan: &FlashLoan<DaoWitness, CoinType>): u64
```

* **@param flash\_loan:**  A FlashLoan hot potato.
* **@return u64.**&#x20;

### <mark style="color:blue;">amount</mark>

**Returns the amount of the loan without the fees.**

```rust
public fun amount<DaoWitness: drop, CoinType>(flash_loan: &FlashLoan<DaoWitness, CoinType>): u64
```

* **@param flash\_loan:**  A FlashLoan hot potato.
* **@return u64.**&#x20;

### <mark style="color:blue;">repay\_flash\_loan</mark>

**Repays the `flash_loan` to the `treasury`.**

<pre class="language-rust"><code class="lang-rust">public fun repay_flash_loan&#x3C;DaoWitness: drop, CoinType>(
    treasury: &#x26;mut DaoTreasury&#x3C;DaoWitness>, 
    flash_loan: FlashLoan&#x3C;DaoWitness, CoinType>,
    token: Coin&#x3C;CoinType>
<strong>)
</strong></code></pre>

* **@param treasury:** A DaoTreasury.
* **@param flash\_loan:**  A FlashLoan hot potato.
* **@param token:**  The borrowed coin + fee.&#x20;

**Aborts**

* `token.value` is smaller than the initial loan amount + fee amount.


---

# 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.interestprotocol.com/overview/deprecated/sui-tears/governance/dao-treasury.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.
