Program
The hush_vault program: addresses, the config account, instructions and errors.
hush_vault is an Anchor program. It holds the deposited SOL and USDC, mints hSOL and hUSDC against them, and burns and releases on a withdraw. Every amount it moves is public. Encrypted balances, sends and proofs are Token-2022's own instructions, run on the two mints this program created.
Program id: Gc2VRibTyvsu83LuX8Yd6k9gyuLWKAwc2G1Eno49fMaD
The API's config returns the program id, both mints and both vaults for the network it serves. The SDK derives the same addresses with hushAddresses.
Addresses
Every account the program owns sits at a program-derived address with one fixed seed, so each exists once.
| Address | Seed | Holds |
|---|---|---|
config | "config" | The Config account. |
authority | "authority" | No data. It signs for the program: mint authority of hSOL and hUSDC, and owner of the USDC vault. |
sol_vault | "vault_sol" | The deposited SOL, as the lamports of a data-less account the program owns. |
usdc_vault | "vault_usdc" | The deposited USDC, in an SPL Token account owned by authority. |
hsol_mint | "hsol" | The hSOL mint, a Token-2022 mint with the Confidential Transfer extension. |
husdc_mint | "husdc" | The hUSDC mint, the same kind. |
A wallet's Hush account is its associated token account for the hSOL or hUSDC mint under Token-2022. The program doesn't create it. Set up does, through the token program.
Config
initialize creates the Config account. It is 173 bytes and holds the program's settings.
| Field | Type | Offset | Description |
|---|---|---|---|
admin | Pubkey | 8 | The wallet that may call set_fee. |
fee_recipient | Pubkey | 40 | The wallet the withdraw fee is paid to. |
fee_bps | u16 | 72 | The withdraw fee in basis points. |
usdc_mint | Pubkey | 74 | The USDC mint the vault accepts. |
hsol_mint | Pubkey | 106 | The hSOL mint. |
husdc_mint | Pubkey | 138 | The hUSDC mint. |
bump | u8 | 170 | Bump of the config address. |
authority_bump | u8 | 171 | Bump of the authority address. |
sol_vault_bump | u8 | 172 | Bump of the SOL vault address. |
Bytes 0 to 7 are the account discriminator.
Constants
| Constant | Type | Value | Description |
|---|---|---|---|
MAX_FEE_BPS | u16 | 100 | The highest withdraw fee initialize and set_fee accept: 1%. |
SOL_DECIMALS | u8 | 9 | Decimals of hSOL. |
USDC_DECIMALS | u8 | 6 | Decimals of hUSDC. |
Instructions
Accounts are listed in the order the instruction takes them.
initialize
Runs once. Creates the config, both vaults and both mints. Each mint gets the Confidential Transfer extension with no auditor key, automatic account approval and no authority that could change either, and the program's authority address as its mint authority, with no freeze authority.
| Argument | Type | Description |
|---|---|---|
fee_bps | u16 | The withdraw fee in basis points. At most MAX_FEE_BPS. |
fee_recipient | Pubkey | The wallet the fee is paid to. |
| Account | Writable | Signer | Description |
|---|---|---|---|
admin | Yes | Yes | Pays for the new accounts and becomes the admin. |
config | Yes | The Config account. | |
authority | The program's signing address. | ||
sol_vault | Yes | Created here. | |
usdc_vault | Yes | Created here. | |
hsol_mint | Yes | Created here. | |
husdc_mint | Yes | Created here. | |
usdc_mint | The USDC mint to accept. | ||
token_program | The SPL Token program, which owns USDC. | ||
token_2022_program | Token-2022. | ||
system_program | The System program. |
Errors: FeeTooHigh.
deposit_sol
Moves amount lamports from the owner into the SOL vault and mints the same amount of hSOL to the owner's Hush account.
| Argument | Type | Description |
|---|---|---|
amount | u64 | The lamports to deposit, in base units. Above 0. |
| Account | Writable | Signer | Description |
|---|---|---|---|
owner | Yes | Yes | The depositor. |
config | The Config account. | ||
authority | The program's signing address. | ||
sol_vault | Yes | Receives the lamports. | |
hsol_mint | Yes | Must be the mint in config. | |
h_account | Yes | The owner's hSOL account. Receives the hSOL. | |
token_2022_program | Token-2022. | ||
system_program | The System program. |
Errors: ZeroAmount.
deposit_usdc
Moves amount USDC from the owner's USDC account into the USDC vault and mints the same amount of hUSDC to the owner's Hush account.
| Argument | Type | Description |
|---|---|---|
amount | u64 | The USDC to deposit, in base units. Above 0. |
| Account | Writable | Signer | Description |
|---|---|---|---|
owner | Yes | The depositor. | |
config | The Config account. | ||
authority | The program's signing address. | ||
usdc_vault | Yes | Receives the USDC. | |
usdc_mint | Must be the USDC mint in config. | ||
owner_usdc | Yes | The owner's USDC account. | |
husdc_mint | Yes | Must be the mint in config. | |
h_account | Yes | The owner's hUSDC account. Receives the hUSDC. | |
token_program | The SPL Token program, which owns USDC. | ||
token_2022_program | Token-2022. |
Errors: ZeroAmount.
withdraw_sol
Burns amount hSOL from the owner's Hush account, taken from its public balance. Releases amount minus the fee from the SOL vault to the owner, and the fee to the fee recipient.
| Argument | Type | Description |
|---|---|---|
amount | u64 | The hSOL to burn, in base units. Above 0. |
| Account | Writable | Signer | Description |
|---|---|---|---|
owner | Yes | Yes | Burns, and receives the SOL. |
config | The Config account. | ||
sol_vault | Yes | Pays out. | |
fee_recipient | Yes | Must be the fee recipient in config. Receives the fee. | |
hsol_mint | Yes | Must be the mint in config. | |
h_account | Yes | The owner's hSOL account. | |
token_2022_program | Token-2022. |
Errors: ZeroAmount, InsufficientBalance, InsufficientVault.
withdraw_usdc
Burns amount hUSDC from the owner's Hush account, taken from its public balance. Releases amount minus the fee from the USDC vault to the owner's USDC account, and the fee to the fee recipient's.
| Argument | Type | Description |
|---|---|---|
amount | u64 | The hUSDC to burn, in base units. Above 0. |
| Account | Writable | Signer | Description |
|---|---|---|---|
owner | Yes | Burns. | |
config | The Config account. | ||
authority | The program's signing address. | ||
usdc_vault | Yes | Pays out. | |
usdc_mint | Must be the USDC mint in config. | ||
owner_usdc | Yes | The owner's USDC account. Receives the USDC. | |
fee_recipient_usdc | Yes | The fee recipient's associated USDC account. Receives the fee. | |
husdc_mint | Yes | Must be the mint in config. | |
h_account | Yes | The owner's hUSDC account. | |
token_program | The SPL Token program, which owns USDC. | ||
token_2022_program | Token-2022. |
Errors: ZeroAmount, InsufficientBalance, WrongFeeAccount.
set_fee
Sets the withdraw fee and its recipient. The admin signs.
| Argument | Type | Description |
|---|---|---|
fee_bps | u16 | The new fee in basis points. At most MAX_FEE_BPS. |
fee_recipient | Pubkey | The new recipient. |
| Account | Writable | Signer | Description |
|---|---|---|---|
admin | Yes | Must be the admin in config. | |
config | Yes | The Config account. |
Errors: FeeTooHigh.
How a withdraw uses them
withdraw_sol and withdraw_usdc burn from a Hush account's public balance. An amount gets there through Token-2022's confidential withdraw instruction, which carries the proofs. So a withdraw is two steps, the confidential withdraw and then withdraw_sol or withdraw_usdc, and a burn of more than the public balance holds fails with InsufficientBalance.
The fee is amount × fee_bps / 10,000, rounded down, at 0.10% today. Fees and the HUSH token covers where it goes.
Errors
| Code | Name | Message | Raised when |
|---|---|---|---|
| 6000 | FeeTooHigh | The fee is above the 1% cap. | initialize or set_fee was given a fee above MAX_FEE_BPS. |
| 6001 | ZeroAmount | The amount must be greater than zero. | A deposit or a withdraw was given an amount of 0. |
| 6002 | InsufficientVault | The vault holds less than this withdraw. | withdraw_sol would take the SOL vault below its rent-exempt minimum. |
| 6003 | InsufficientBalance | The public hToken balance is below this amount. Withdraw from the confidential balance first. | A withdraw asks to burn more than the Hush account's public balance. |
| 6004 | WrongFeeAccount | The fee account is not the fee recipient's USDC account. | withdraw_usdc was given a fee account other than the fee recipient's associated USDC account. |
An account that fails one of the checks in the tables above, such as a mint that isn't the one in config, is refused with Anchor's own constraint errors.
Events
The program emits no events. What happened is read from the transactions themselves: the instruction, its accounts and its amount.