> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mystockline.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# ProtocolSupply

> ProtocolSupply holds the protocol-owned dollars in the lending pool.

ProtocolSupply holds the protocol-owned dollars in the lending pool. After the STK auction, the treasury swaps ETH proceeds to USDG and calls `deposit`; the contract mints sUSDG to itself and tracks the principal. That principal cannot leave before `lockUntil`. After the lock, only the Timelock can take it out, and only after a notice period, in tranches capped per period. Those three rules are immutable. `harvest` is permissionless and sends yield above principal to AuctionYield while the yield term runs, then to the treasury. A Guardian pause blocks `withdraw` and `harvest` like any other pool withdrawal.

`ProtocolSupply` lets you:

* Deposit treasury USDG into the pool as protocol-owned supply
* Move interest above principal to AuctionYield, then to the treasury after the term
* Withdraw principal through the Timelock only, after lock, notice, and per-period cap
* Read the lock date, notice period, tranche cap, and tracked principal

This contract is not deployed on a listed network yet. Watch [Addresses](/resources/addresses).

| Network                 | Address      |
| ----------------------- | ------------ |
| Robinhood Chain testnet | Not deployed |
| Robinhood Chain         | Not deployed |

The source code is [`src/token/ProtocolSupply.sol`](https://github.com/stockline-xyz/contracts/blob/main/src/token/ProtocolSupply.sol) on GitHub. The ABI is [`/abis/ProtocolSupply.json`](/abis/ProtocolSupply.json).

## Write methods

### deposit

```solidity theme={"system"}
function deposit(uint256 amount) external nonReentrant
```

Pulls `amount` USDG from the caller, deposits it into USDGPool for sUSDG held by this contract, and raises `principal`. Only the treasury or the Timelock can call it. Reverts with NotAuthorized otherwise and ZeroAmount for 0.

<Warning>
  Treasury or Timelock only. The caller must approve ProtocolSupply for `amount`.
</Warning>

**Input parameters**

| Name   | Type      | Description                    |
| ------ | --------- | ------------------------------ |
| amount | `uint256` | USDG to deposit, native units. |

### notice

```solidity theme={"system"}
function notice(uint256 amount) external
```

Queues a principal withdrawal of `amount`. Timelock only, and only at or after `lockUntil`. Records the notice time; `withdraw` becomes possible `noticeDays` later. Reverts with Locked before the lock date.

<Warning>
  Timelock only. A new notice replaces the pending one and restarts the wait.
</Warning>

**Input parameters**

| Name   | Type      | Description                            |
| ------ | --------- | -------------------------------------- |
| amount | `uint256` | USDG the Timelock intends to withdraw. |

### withdraw

```solidity theme={"system"}
function withdraw() external nonReentrant
```

Takes principal after a notice has matured. Timelock only. The amount is the smallest of the noticed amount, the unused tranche room for this period (`maxTranchePct` of the current position), remaining principal, and pool cash. Reverts with NoNotice, NoticePending, or CapExceeded when nothing can move.

<Warning>
  Timelock only. Cannot exceed the per-period cap. Never touches yield.
</Warning>

### harvest

```solidity theme={"system"}
function harvest() external nonReentrant
```

Redeems the yield above `principal`, capped by pool cash. Before `yieldTermEnd` the USDG goes to AuctionYield through `notifyReward`; after, it goes to the treasury. Permissionless. Reverts with NothingToHarvest when the position is at or below principal.

<Note>
  A Guardian pause reverts this call. A pause that spans `yieldTermEnd` sends the next harvest to the treasury. The amount can be 1 wei below the economic yield because of ERC-4626 rounding.
</Note>

### sweep

```solidity theme={"system"}
function sweep(address token) external
```

Sends the full balance of any stray ERC-20 held here to the treasury. Timelock only. Cannot sweep sUSDG. Reverts with InvalidParams for the pool token or the zero address.

<Warning>
  Timelock only.
</Warning>

**Input parameters**

| Name  | Type      | Description        |
| ----- | --------- | ------------------ |
| token | `address` | ERC-20 to recover. |

## Events

### Deposited

```solidity theme={"system"}
event Deposited(
    address indexed from,
    uint256 assets,
    uint256 shares
)
```

Fires on each deposit with the caller, USDG in, and sUSDG minted.

### NoticeQueued

```solidity theme={"system"}
event NoticeQueued(uint256 amount, uint256 noticeAt)
```

Fires when the Timelock queues a withdrawal.

### Withdrawn

```solidity theme={"system"}
event Withdrawn(uint256 assets)
```

Fires when principal leaves to the Timelock.

### Harvested

```solidity theme={"system"}
event Harvested(uint256 assets, address indexed to)
```

Fires on each harvest with the amount and the recipient (AuctionYield or treasury).

### Swept

```solidity theme={"system"}
event Swept(address indexed token, uint256 amount)
```

Fires when a stray token is recovered.

## Errors

### ZeroAddress

```solidity theme={"system"}
error ZeroAddress()
```

A constructor address was zero.

### ZeroAmount

```solidity theme={"system"}
error ZeroAmount()
```

An amount was zero.

### InvalidParams

```solidity theme={"system"}
error InvalidParams()
```

Bad constructor values, or sweep targeted sUSDG or the zero address.

### NotTimelock

```solidity theme={"system"}
error NotTimelock()
```

Only the Timelock can notice, withdraw, or sweep.

### NotAuthorized

```solidity theme={"system"}
error NotAuthorized()
```

Only the treasury or the Timelock can deposit.

### Locked

```solidity theme={"system"}
error Locked()
```

The lock date has not passed.

### NoNotice

```solidity theme={"system"}
error NoNotice()
```

withdraw was called without a queued notice.

### NoticePending

```solidity theme={"system"}
error NoticePending()
```

The notice period has not elapsed.

### CapExceeded

```solidity theme={"system"}
error CapExceeded()
```

No principal can move: the tranche cap, principal, or pool cash is exhausted.

### NothingToHarvest

```solidity theme={"system"}
error NothingToHarvest()
```

The position is at or below principal, or the pool has no cash.
