# Core Functions

#### 1. **Staking (`stake`)**

Users stake USDC and receive STS in return, representing a share of the vault’s USDC balance.

**STS minting logic:**

```solidity
solidityCopyEditstsToMint = (amount * totalSupply()) / vaultBalance;
```

* If `totalSupply() == 0`, STS is minted at a 1:1 ratio scaled by `1e12` to align with USDC decimals (6) vs. STS decimals (18).
* Otherwise, mint proportionally to existing vault state.

**Stake Details:**

* Tracked via `StakeRecord[]`:
  * `stsShares`: Amount of STS minted
  * `durationDays`: Lockup period (0, 90, or 180)
  * `lockEndTime`: Timestamp when the stake becomes redeemable
  * `active`: Whether the stake is still claimable

**Sanctions Check:**

* Uses Chainalysis Oracle via `checkSanctions(msg.sender)`
* If oracle fails or flags the address, the tx is reverted

***

#### 2. **Unstaking (`unstake`)**

* Users burn STS to redeem a share of the vault’s USDC
* Amount returned is based on the **pro-rata share** of current vault balance:

```solidity
solidityCopyEditusdcToReturn = (stsAmountToBurn * vaultBalance) / totalSupply();
```

* Lock period must be expired (`block.timestamp >= lockEndTime`)
* Stake is marked as inactive and shares zeroed out

***

#### 3. **Non-Transferability**

STS is a non-transferable ERC20:

```solidity
solidityCopyEditrequire(from == address(0) || to == address(0), "STS: token is non-transferable");
```

* Transfers are blocked unless minting (`from == 0`) or burning (`to == 0`)
* Prevents secondary market speculation and enforces 1:1 mint/burn lifecycle

***

#### 4. **Acquisition Withdrawals (`withdrawForAcquisition`)**

* Admin-only method to withdraw USDC for real estate purchases
* This directly impacts vault balance → **STS value is diluted**

```solidity
solidityCopyEditusdc.safeTransfer(to, amount);
emit AcquisitionWithdrawal(to, amount);
```

***

#### 5. **Rescuing Mistaken Tokens**

* Recovers any tokens mistakenly sent to vault (except USDC or STS)
* Safeguard against misrouted assets or phishing

```solidity
solidityCopyEditrequire(tokenAddress != address(usdc));
require(tokenAddress != address(this));
```

***

#### 6. **Oracle Management (`setSanctionsOracleAddress`)**

* Updates the sanctions oracle used for address screening
* Emits `SanctionsOracleUpdated`

***

#### 7. **Pause Mechanism**

* `pause()` and `unpause()` let the owner halt operations during threats
* Uses OpenZeppelin’s `Pausable` modifier

### &#x20;View Functions

| Function                                            | Description                                            |
| --------------------------------------------------- | ------------------------------------------------------ |
| `getTotalVaultedUSDC()`                             | Returns the current USDC balance of the vault          |
| `getCurrentValueOfActiveStakes(user)`               | Calculates user’s total USDC share based on active STS |
| `getUserStakeRecordsPaginated(user, cursor, limit)` | Returns paginated view of user's stake records         |
| `getUserStakeCount(user)`                           | Total number of stakes recorded by the user            |
| `getStakeRecord(user, index)`                       | Returns the full struct for a given user stake         |

***


---

# 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://subunit.gitbook.io/subunit-docs/subvault/subvault-technical-docs/core-functions.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.
