Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid Insurance Fund #238

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b35899d
feat: Liquid Insurance Funds
exdx May 1, 2024
e072543
fix: Remove marginfi account pubkey
exdx May 23, 2024
66e1dd4
fix: Rename authority to admin; update shares to WrappedI80F48
exdx May 23, 2024
47308c7
fix: Update to use request timestamp at the time of the request
exdx May 23, 2024
e8ec7ec
fix: Remove lif token mint functionality entirely
exdx May 24, 2024
536ad42
fix: Remove unnecessary fields from lif
exdx May 28, 2024
450546c
fix: Use lif seed in state; remove other mint seeds
exdx May 28, 2024
48b4b71
fix: Use shares explicitly when depositing, add withdraw params to
exdx May 28, 2024
062391b
fix: Remove extra signers; fix withdrawals to use amount instead of
exdx May 29, 2024
9da4479
fix: Clean up withdraw to use amount instead of shares
exdx May 29, 2024
06ce16a
fix: Use anchor close macro on withdraw
exdx May 29, 2024
da2861f
fix: Return Result<> when creating a fund
exdx May 29, 2024
a4e0323
wip: Internal accounting model
exdx May 30, 2024
6f80884
fix: Use correct deposit seeds
exdx May 30, 2024
a8f5dab
feat: Add haircut_shares to reprice lif shares in case of bankruptcy or
exdx May 30, 2024
3477229
fix: Move InsuranceFundAccount to state
exdx May 30, 2024
0b50360
wip: Move lif module up one level; add account based accounting
exdx May 31, 2024
a2c90ec
feat: Add user deposit accounting
exdx Jun 2, 2024
5b18378
wip: Create withdraw address
exdx Jun 3, 2024
876e8ed
deposit/withdraw accounting
cavemanloverboy Jun 6, 2024
7af12e5
initial lif implementation with tests
cavemanloverboy Jun 12, 2024
e82b743
clarify lazy evaluation
cavemanloverboy Jun 12, 2024
cf7c5f2
unnecessary pubkey comparison
cavemanloverboy Jun 12, 2024
b7b793e
revert unnecessary deser
cavemanloverboy Jun 12, 2024
d33b8d1
Merge branch 'main' into cavey/lif
cavemanloverboy Jun 13, 2024
6e9d575
Merge branch 'main' into cavey/lif
jkbpvsc Jul 1, 2024
2b0a0de
rebase wip
cavemanloverboy Aug 6, 2024
0f51e72
fix t22 program key in tests
cavemanloverboy Aug 13, 2024
ed083e7
fix deposit accounting for t22
cavemanloverboy Aug 13, 2024
479b854
fix init lif for t22
cavemanloverboy Aug 13, 2024
de5c18e
pubkey arg for maybe_take_bank_mint
cavemanloverboy Aug 14, 2024
92931b7
lif test suite: deposits, withdraw, liqudiations
cavemanloverboy Aug 14, 2024
883c97f
lif test suite: bad debt
cavemanloverboy Aug 14, 2024
07c03f5
fix: M-01
cavemanloverboy Nov 15, 2024
f7af6ef
fix: L-01
cavemanloverboy Nov 15, 2024
0ba6f70
add if -> lif conversion test
cavemanloverboy Nov 15, 2024
d988c7c
fix: I-02
cavemanloverboy Nov 15, 2024
5ee4335
fix: I-03
cavemanloverboy Nov 15, 2024
55224ac
fix: I-04
cavemanloverboy Nov 15, 2024
3d707b9
fix: I-07
cavemanloverboy Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions .github/actions/build-program/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ inputs:
runs:
using: "composite"
steps:
- uses: actions/cache@v2
name: Cache Cargo registry + index
id: cache-cargo-registry
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
# - uses: actions/cache@v2
# name: Cache Cargo registry + index
# id: cache-cargo-registry
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

- name: Cache Anchor Build
uses: actions/cache@v2
id: cache-anchor-build
with:
path: |
./target/
key: build-${{ runner.os }}-${{env.ANCHOR_CLI_VERSION}}-${{env.ANCHOR_SHA}}-v0002-${{ hashFiles('./programs/**/**', '**/Cargo.lock') }}-${{ inputs.program_lib_name }}
# - name: Cache Anchor Build
# uses: actions/cache@v2
# id: cache-anchor-build
# with:
# path: |
# ./target/
# key: build-${{ runner.os }}-${{env.ANCHOR_CLI_VERSION}}-${{env.ANCHOR_SHA}}-v0002-${{ hashFiles('./programs/**/**', '**/Cargo.lock') }}-${{ inputs.program_lib_name }}

- run: ./scripts/build-program.sh ${{ inputs.program_lib_name }} mainnet
if: steps.cache-anchor-build.outputs.cache-hit != 'true'
# if: steps.cache-anchor-build.outputs.cache-hit != 'true'
shell: bash
35 changes: 17 additions & 18 deletions .github/actions/build-verifiable-program/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@ inputs:
runs:
using: "composite"
steps:
- uses: actions/cache@v2
name: Cache Cargo registry + index
id: cache-cargo-registry
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-${{ runner.os }}-v0001-${{ hashFiles('**/Cargo.lock') }}
# - uses: actions/cache@v2
# name: Cache Cargo registry + index
# id: cache-cargo-registry
# with:
# path: |
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# key: cargo-${{ runner.os }}-v0001-${{ hashFiles('**/Cargo.lock') }}

- uses: actions/cache@v2
name: Cache Solana Verify
id: cache-solana-verify
with:
path: |
~/.cargo/bin/solana-verify
key: cargo-${{ runner.os }}-solana-verify
# - uses: actions/cache@v2
# name: Cache Solana Verify
# id: cache-solana-verify
# with:
# path: |
# ~/.cargo/bin/solana-verify
# key: cargo-${{ runner.os }}-solana-verify

- run: cargo install solana-verify --git https://github.com/Ellipsis-Labs/solana-verifiable-build --rev 8f6f56908a0b0f35cb84d06f167c25c286ccf0ac
if: steps.cache-solana-verify.outputs.cache-hit != 'true'
# if: steps.cache-solana-verify.outputs.cache-hit != 'true'
shell: bash

- run: ./scripts/build-program-verifiable.sh ${{ inputs.program_lib_name }} ${{ inputs.devnet == 'true' && 'devnet' || 'mainnet' }}
shell: bash
env:
PROGRAM: ${{ inputs.program_lib_name }}

36 changes: 18 additions & 18 deletions .github/actions/build-workspace/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ description: "Build Anchor Workspace"
runs:
using: "composite"
steps:
- uses: actions/cache@v2
name: Cache Cargo registry + index
id: cache-cargo-registry
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
# - uses: actions/cache@v2
# name: Cache Cargo registry + index
# id: cache-cargo-registry
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

- name: Cache Anchor Build
uses: actions/cache@v2
id: cache-anchor-build
with:
path: |
./target/
key: build-${{ runner.os }}-${{env.ANCHOR_CLI_VERSION}}-${{env.ANCHOR_SHA}}-v0002-${{ hashFiles('./programs/**/**', '**/Cargo.lock') }}-workspace
# - name: Cache Anchor Build
# uses: actions/cache@v2
# id: cache-anchor-build
# with:
# path: |
# ./target/
# key: build-${{ runner.os }}-${{env.ANCHOR_CLI_VERSION}}-${{env.ANCHOR_SHA}}-v0002-${{ hashFiles('./programs/**/**', '**/Cargo.lock') }}-workspace

- run: ./scripts/build-workspace.sh
if: steps.cache-anchor-build.outputs.cache-hit != 'true'
# if: steps.cache-anchor-build.outputs.cache-hit != 'true'
shell: bash
32 changes: 16 additions & 16 deletions .github/actions/setup-anchor-cli/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ runs:
steps:
- uses: ./.github/actions/setup-common/
- uses: ./.github/actions/setup-solana-cli/
- uses: actions/cache@v2
name: Cache Anchor Cli
id: cache-anchor-cli
with:
path: |
~/.cargo/bin/anchor
key: anchor-cli-${{ runner.os }}-v0003-${{ env.ANCHOR_CLI_VERSION }}-${{ env.ANCHOR_SHA }}
# - uses: actions/cache@v2
# name: Cache Anchor Cli
# id: cache-anchor-cli
# with:
# path: |
# ~/.cargo/bin/anchor
# key: anchor-cli-${{ runner.os }}-v0003-${{ env.ANCHOR_CLI_VERSION }}-${{ env.ANCHOR_SHA }}-${{ env.RUST_TOOLCHAIN }}
- run: cargo install --git https://github.com/coral-xyz/anchor --tag "v$ANCHOR_CLI_VERSION" anchor-cli --locked
shell: bash
if: steps.cache-anchor-cli.outputs.cache-hit != 'true'
- uses: actions/cache@v2
name: Cache Toml Cli
id: cache-toml-cli
with:
path: |
~/.cargo/bin/toml
key: toml-cli-${{ runner.os }}-v0002
# if: steps.cache-anchor-cli.outputs.cache-hit != 'true'
# - uses: actions/cache@v2
# name: Cache Toml Cli
# id: cache-toml-cli
# with:
# path: |
# ~/.cargo/bin/toml
# key: toml-cli-${{ runner.os }}-v0002
- run: (cargo install toml-cli || true)
if: steps.cache-toml-cli.outputs.cache-hit != 'true'
# if: steps.cache-toml-cli.outputs.cache-hit != 'true'
shell: bash
29 changes: 17 additions & 12 deletions .github/actions/setup-common/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ description: "Setup common"
runs:
using: "composite"
steps:
- run: sudo apt-get update
shell: bash
- run: sudo apt-get install -y pkg-config build-essential libudev-dev
shell: bash
- uses: actions-rs/toolchain@v1
name: Install minimal rust toolchain with clippy and rustfmt
with:
profile: minimal
toolchain: nightly-2023-04-19
target: x86_64-unknown-linux-gnu
components: rustfmt, clippy
default: true
- run: sudo apt-get update
shell: bash

- run: sudo apt-get install -y pkg-config build-essential libudev-dev
shell: bash

- uses: actions-rs/toolchain@v1
name: Install minimal rust toolchain with clippy and rustfmt
with:
profile: minimal
toolchain: ${{ env.RUST_TOOLCHAIN }}
target: x86_64-unknown-linux-gnu
components: rustfmt, clippy
default: true

- run: (cargo install cargo-nextest || true)
shell: bash
37 changes: 20 additions & 17 deletions .github/actions/setup-solana-cli/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ description: "Setup Solana CLI"
runs:
using: "composite"
steps:
- uses: actions/cache@v2
name: Cache Solana Tool Suite
id: cache-solana
with:
path: |
~/.cache/solana/
~/.local/share/solana/
key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}
- run: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
shell: bash
if: steps.cache-solana.outputs.cache-hit != 'true'
- run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- run: solana-keygen new -s --no-bip39-passphrase --force
shell: bash
- run: solana config set --url localhost
shell: bash
# - uses: actions/cache@v2
# name: Cache Solana Tool Suite
# id: cache-solana
# with:
# path: |
# ~/.cache/solana/
# ~/.local/share/solana/
# key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}-${{ env.RUST_TOOLCHAIN }}
- run: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
shell: bash
# if: steps.cache-solana.outputs.cache-hit != 'true'
- run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- run: cargo install solana-keygen --version ${{ env.SOLANA_CLI_VERSION }} --locked
# if: steps.cache-solana-verify.outputs.cache-hit != 'true'
shell: bash
- run: solana-keygen new -s --no-bip39-passphrase --force
shell: bash
- run: solana config set --url localhost
shell: bash
81 changes: 37 additions & 44 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ defaults:
working-directory: .

env:
RUST_TOOLCHAIN: 1.66.1
SOLANA_CLI_VERSION: 1.16.20
ANCHOR_CLI_VERSION: 0.29.0
ANCHOR_SHA: fc9fd6d24b9be84abb2f40e47ed3faf7b11864ae
RUST_TOOLCHAIN: 1.75.0
SOLANA_CLI_VERSION: 1.18.11
ANCHOR_CLI_VERSION: 0.30.1
ANCHOR_SHA: e6d7dafe12da661a36ad1b4f3b5970e8986e5321
CARGO_TERM_COLOR: always

concurrency:
Expand All @@ -28,29 +28,27 @@ jobs:
lint:
name: Rust Lint
runs-on: ubuntu-latest
env:
RUSTUP_TOOLCHAIN: stable

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-common/
- uses: ./.github/actions/setup-anchor-cli/

- uses: actions/cache@v2
name: Cache Cargo registry + index
id: cache-cargo-build
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
# - uses: actions/cache@v2
# name: Cache Cargo registry + index
# id: cache-cargo-build
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

- run: cargo fmt -- --check

- run: cargo clippy --features=test,test-bpf,admin -- -D warnings -A unused-imports -A clippy::result_large_err -A clippy::await_holding_refcell_ref -A clippy::comparison_chain -A clippy::bind_instead_of_map -A clippy::to-string-trait-impl
- run: ./scripts/lint.sh

test-unit:
name: Rust Unit Tests
Expand All @@ -63,24 +61,22 @@ jobs:
- uses: ./.github/actions/setup-common/
- uses: ./.github/actions/setup-anchor-cli/

- uses: actions/cache@v2
name: Cache Cargo registry + index
id: cache-cargo-build
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
# - uses: actions/cache@v2
# name: Cache Cargo registry + index
# id: cache-cargo-build
# with:
# path: |
# ~/.cargo/bin/
# ~/.cargo/registry/index/
# ~/.cargo/registry/cache/
# ~/.cargo/git/db/
# key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}

- run: cargo test --lib

test-programs:
name: Build and Test Anchor Programs
build-and-test-workspace:
name: Build And Test Anchor Programs
runs-on: ubuntu-latest
env:
RUSTUP_TOOLCHAIN: stable

steps:
- uses: actions/checkout@v2
Expand All @@ -90,34 +86,31 @@ jobs:

- uses: ./.github/actions/build-workspace/

- run: ./scripts/test-program.sh marginfi
shell: bash

- run: ./scripts/test-program.sh liquidity-incentive-program
- run: ./scripts/test-program.sh all --sane
shell: bash

fuzz:
name: Fuzz The marginfi Program
runs-on: ubuntu-latest
env:
RUST_TOOLCHAIN: 1.77.1
RUSTUP_TOOLCHAIN: nightly-2024-03-26
defaults:
run:
shell: bash
working-directory: ./programs/marginfi/fuzz

steps:
- uses: actions/checkout@v3
- name: cache dependencies
uses: Swatinem/rust-cache@v2
# - name: cache dependencies
# uses: Swatinem/rust-cache@v2
- name: Install full rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-03-26
toolchain: nightly-2024-06-05
components: rust-src
override: true
- name: Run fuzz tests in fuzz dir
run: |
cd programs/marginfi
python ./generate_corpus.py
cargo install cargo-fuzz --locked
cargo fuzz run lend -Zbuild-std --strip-dead-code --no-cfg-fuzzing -- -max_total_time=300
cargo +nightly-2024-06-05 fuzz run lend -Zbuild-std --strip-dead-code --no-cfg-fuzzing -- -max_total_time=300
- name: Pass after fuzzing
run: echo "Fuzzing completed"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ node_modules
.idea/
test-ledger/
*.profraw

# keypairs
*.json
Loading