What can the vault do?
| Function | Who | What it does |
|---|---|---|
deposit(token, amount) | Anyone | Pulls tokens into the vault |
withdraw(token, amount, to) | Owner | Sends tokens out |
swapViaRouter(tokenIn, amountIn, tokenOut, minOut, router, data, purpose) | Operator | Sends tokens to a router, then calls it |
swapViaApproval(...) | Operator | Same, but approves the router first |
setOperator(address) | Owner | Changes the operator |
setRouter(address, bool) | Owner | Allows or blocks a router |
pause(), unpause() | Owner | Stops or resumes swaps |
transferOwnership, acceptOwnership | Owner, then new owner | Two-step owner change |
sweepNative(to) | Owner | Sends out stray ETH |
A swap checks six things:
- The router is allowed.
- The vault is not paused.
tokenInis nottokenOut.- The call data is at least 4 bytes.
- After the call,
tokenOutgrew by at leastminOut. tokenInfell by at mostamountIn.
purpose marks the reason. 0 is a gap trade. 1 is a buyback. The vault never sends ETH with a swap.
| Event | When |
|---|---|
Deposit | Tokens came in |
Withdraw | Tokens went out |
Trade | A swap passed all checks |
Sample
Section titled “Sample”The operator sends 1,000 USDG to the router. It asks for at least 9.9 NVDA. The vault gets 9.95 NVDA. The check passes. A Trade event is written.