<div align="center">
  <img height="170" src="https://www.psyoptions.io/static/Gradient-3b03130caf20b8bf48093eaa1f567a3a.png" />

  <h1>PsyStake: PsyOptions Staking Program</h1>

  <p>
    <a href="https://discord.com/invite/Ew3dq7dKwp"><img alt="Discord Chat" src="https://img.shields.io/discord/821571258852442142?color=blue" /></a>
  </p>

  <h4>
    <a href="https://psyoptions.io/">Website</a>
    <span> | </span>
    <a href="https://discord.com/invite/Ew3dq7dKwp">Discord</a>
    <span> | </span>
    <a href="https://trade.psyoptions.io/">Trade</a>
    <span> | </span>
    <a href="https://app.psyfi.io">Structured Products</a>
  </h4>
</div>

## Program Deployments

| Program                          | Devnet                                         | Mainnet Beta                                  |
| -------------------------------- | ---------------------------------------------- | --------------------------------------------- |
| [PsyStake](/programs/psy-stake/) | `5LrZkBFgDkFiKEePeT2N9VuKfd2k8Rrad9PG6mKGbCRk` | `pSystkitWgLkzprdAvraP8DSBiXwee715wiSXGJe8yr` |

## Introduction

PsyStake is a on-chain program designed to allow the operation of a staking or liquidiy mining program for any SPL Token, with built-in support for cross-program invokations by the [PsyFi Euros](https://github.com/mithraiclabs/psyfi-euros) program to enable a seamless staking process.

## Folder Structure

```
.
├── ...
├── deps                            # Dependencies
|   ├── psyfi-euros                 # PsyFinance European Options Strategies Vault program.
├── programs                        # Anchor Program
│   ├── psy-stake                   # PsyStake Program
|   │   ├── src
|   |   |   ├── instructions        # Directory containing program instructions.
|   |   |   |   ├── permisionless   # Subdirectory containing instructions to be run permissionless by cranks.
|   |   |   |   ├── staker          # Subdirectory containing instructions invoked by users staking with the program.
|   |   |   |   ├── vault           # Subdirectory containing instructions invoked by the PsyFi Euros program.
|   |   │   ├── account.rs          # Contains Account struct definitions.
|   |   │   ├── constants.rs        # Contains program constants.
|   |   │   ├── errors.rs           # Contains ErrorCode Enum definitions.
|   |   │   ├── lib.rs              # Contains handlers for program entry.
|   |   │   ├── utils.rs            # Contains utility functions.
│   └── tests                       # Integration tests
└── ...
```

## Program Architecture

[Read Here](docs/architecture.md)

## Setup

### Setup Submodules:

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 PsyFi Euros as a git submodule in `deps/` with `git submodule add https://github.com/mithraiclabs/psyfi-euros.git deps/psyfi-euros`.
3. Update dependencies of submodule with `git submodule update --init --recursive`.
4. Build the dependency by running `anchor build` in `deps/psyfi-euros`.
5. Run `yarn install` in the node dependencies, including `deps/psyfi-euros/packages/psyfi-euros`, `deps/psyfi-euros`.

## Testing:

### Local Testing

Unit Tests: Run `cargo test --lib`  
Integration Tests: Run `anchor test -- --features localnet`.

## Deployment

### Devnet

1. As of writing, you will have to install Solana `v1.8.14` to deploy the program to Devnet: `sh -c "$(curl -sSfL https://release.solana.com/v1.8.14/install)"`. Newer versions of Solana will fail to deploy with an invalid blockhash error.
2. Build program with `anchor build -- --features devnet`.
3. Fund your deployment wallet with `solana airdrop 2 <pubkey> --url https://api.devnet.solana.com`.
4. Generate a new program keypair with `solana-keygen new -o <destination_filepath>`.
5. Run `solana program deploy <path_to_repo/psyfi-euros/target/deploy/psyfi_euros.so --url https://api.devnet.solana.com --verbose --program-id <path_to_new_program_keypair> --keypair <path_to_deployment_wallet>`.
