# PsyFi Euros Vault Program

## Introduction

PsyFi Euros program is an automated options strategies protocol designed to
execute secured put and covered call strategies using the Tokenized Euros protocol
to generate sustainable yield on a single token asset.

## Folder Structure

```
.
├── ...
├── deps                        # Dependencies
|   ├── tokenized-euros         # PsyOptions Tokenized Euros program, used for local integration tests.
├── programs                    # Anchor Programs
│   ├── pyth                    # Program simulating Pyth Oracle, used for local integration tests.
│   ├── psyfi_euros             # PsyFi Euros Program
|   │   ├── src
|   |   |   ├── instructions    # Directory containing program instructions.
|   |   |   |   ├── dex         # Subdirectory containing instructions interacting with Serum program.
|   |   |   |   ├── receipt     # Subdirectory containing instructions interacting with receipts state.
|   |   |   |   ├── settings    # Subdirectory containing instructions interacting with vault settings.
|   |   │   ├── account.rs      # Contains Account struct definitions.
|   |   │   ├── calculators.rs  # Contains functions for exchange rate and token conversion calcuation.
|   |   │   ├── constraints.rs  # Contains program constraints and checks.
|   |   │   ├── errors.rs       # Contains ErrorCode Enum definitions.
|   |   │   ├── lib.rs          # Contains handlers for program entry.
|   |   │   ├── verifiers.rs    # Contains functions for verifying of program state.
│   └── tests                   # Integration tests
└── ...
```

## Program Architecture

[Read Here](docs/architecture.md)

## Installation

1. Follow [instructions](https://project-serum.github.io/anchor/getting-started/installation.html) to install Rust, Solana and Anchor.
2. If you run into any difficulties, try updating Rust to latest release with `rustup update` and update dependencies
   `sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev`.
   If that still does not work and installation is stuck at compilation step, it could be a memory issue and ensure
   system has at least 4gb of memory.
3. Run `yarn install` to install node packages for testing.

## Dependencies

### Setup Tokenized Euros as submodule to enable integration tests

Using HTTPS (recommended):

1. Allow HTTPS cloning from private repository by [caching your Github credentials in Git](https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git#git-credential-manager). Git Credentials Manager sets up well on M1 Macbook.
2. Add Tokenized Euros as a git submodule in `deps/` with `git submodule add https://github.com/mithraiclabs/tokenized-euros.git deps/tokenized-euros`
3. Build the dependency by running `anchor build` in `deps/tokenized-euros`.

Using SSH:

1. Setup Tokenized Euros as a git submodule in `deps/` with `git submodule add https://username:passsord@github.com/mithraiclabs/tokenized-euros.git deps/tokenized-euros`
2. Build the dependency by running `anchor build` in `deps/tokenized-euros`.

### To update an existing submodule

Using HTTPS (recommended):
Run `git submodule update --remote`

Using SSH:

1. Remove local submodule with `git rm deps/tokenized-euros`
2. Run `rm -rf .git/modules/deps/tokenized-euros/`
3. Add remote submodule again with `git submodule add https://username:passsord@github.com/mithraiclabs/tokenized-euros.git deps/tokenized-euros`.

## Testing

### Local Testing

Unit Tests: Run `cargo test --lib`
Integration Tests: Run `anchor test`

### Devnet Testing

1. Ensure that program ids declared in `Anchor.toml` are configured correctly for the Devnet deployments.
2. Run `anchor build -- --features devnet`.
3. Airdrop sufficient SOL for program deployment with `solana airdrop 2 <pubkey> --url https://api.devnet.solana.com`. Last deployment took 7.3 SOL.
4. If neccessary, generate a new keypair with `solana-keygen new --outfile deploy-wallet/psyfi-devnet`
5. Run `solana program deploy --program-id deploy-wallet/psyfi-devnet --url https://psytrbhymqlkfrhudd.dev.genesysgo.net:8899/ psyfi-euros/target/deploy/psyfi_euros.so `. Note that the above directories and
   RPC endpoint should be changed to whichever that is setup locally.
6. Ensure that providers for wallet and mints have sufficient SOL.
7. Run client test scripts.

## Development Tips:

- To get the dynamically generated ProgramID, run:
  `solana address -k target/deploy/petitsolana-keypair.json`
- Use spl_token [cli](https://spl.solana.com/token) to create the USDC and BTC mints.
- Anchor tests can be run for builds with special flags (e.g. `anchor build -- --features devnet`) with `anchor test --skip-build`.
- When Cargo is built with `anchor build -- --features devnet`, the `devnet` feature defined in `Cargo.toml` is active. Code after `#[cfg(feature = "devnet")]` will be included in the build. [Read More](https://doc.rust-lang.org/cargo/reference/features.html)

### Code Formatting

- JS: Install [Prettier](https://prettier.io/) in your IDE and configure it to run each time on save.
- Rust: Install [rustfmt](https://github.com/rust-lang/rustfmt). Run `cargo fmt` to format code.

### Treatment of Payer

User-facing methods have the same Signer as the payer of transaction (to initialize
accounts with lamports), while system-facing methods have a different Signer and
Payer to enable the use of MultiSig PDA as the Signer, and regular wallets as the
Payer.

## TS Package

To publish an update to the package:

1. Update version in `package.json`.
2. Build package first with `npm run build:package`.
3. Publish with `npm publish`
