diff --git a/.github/actions/setup-solana/scripts/solana-install-init.sh b/.github/actions/setup-solana/scripts/solana-install-init.sh index db36dc61e2..cf2d1babf3 100755 --- a/.github/actions/setup-solana/scripts/solana-install-init.sh +++ b/.github/actions/setup-solana/scripts/solana-install-init.sh @@ -10,25 +10,25 @@ # except according to those terms. # This is just a little script that can be downloaded from the internet to -# install solana-install. It just does platform detection, downloads the installer +# install agave-install. It just does platform detection, downloads the installer # and runs it. { # this ensures the entire script is downloaded # if [ -z "$SOLANA_DOWNLOAD_ROOT" ]; then - SOLANA_DOWNLOAD_ROOT="https://github.com/solana-labs/solana/releases/download/" + SOLANA_DOWNLOAD_ROOT="https://github.com/anza-xyz/agave/releases/download/" fi -GH_LATEST_RELEASE="https://api.github.com/repos/solana-labs/solana/releases/latest" +GH_LATEST_RELEASE="https://api.github.com/repos/anza-xyz/agave/releases/latest" set -e usage() { cat 1>&2 < --pubkey + agave-install-init [FLAGS] [OPTIONS] --data_dir --pubkey FLAGS: -h, --help Prints help information @@ -81,7 +81,7 @@ main() { esac TARGET="${_cputype}-${_ostype}" - temp_dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t solana-install-init)" + temp_dir="$(mktemp -d 2>/dev/null || ensure mktemp -d -t agave-install-init)" ensure mkdir -p "$temp_dir" # Check for SOLANA_RELEASE environment variable override. Otherwise fetch @@ -101,8 +101,8 @@ main() { fi fi - download_url="$SOLANA_DOWNLOAD_ROOT/$release/solana-install-init-$TARGET" - solana_install_init="$temp_dir/solana-install-init" + download_url="$SOLANA_DOWNLOAD_ROOT/$release/agave-install-init-$TARGET" + solana_install_init="$temp_dir/agave-install-init" printf 'downloading %s installer\n' "$release" 1>&2 @@ -111,7 +111,7 @@ main() { ensure chmod u+x "$solana_install_init" if [ ! -x "$solana_install_init" ]; then printf '%s\n' "Cannot execute $solana_install_init (likely because of mounting /tmp as noexec)." 1>&2 - printf '%s\n' "Please copy the file to a location where you can execute binaries and run ./solana-install-init." 1>&2 + printf '%s\n' "Please copy the file to a location where you can execute binaries and run ./agave-install-init." 1>&2 exit 1 fi @@ -130,7 +130,7 @@ main() { } err() { - printf 'solana-install-init: %s\n' "$1" >&2 + printf 'agave-install-init: %s\n' "$1" >&2 exit 1 } diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 65968818a9..4aa400d6bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,15 +13,17 @@ defaults: env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: 1.70.0 - SOLANA_VERSION: "1.16.27" + RUST_TOOLCHAIN: 1.91.1 + SOLANA_VERSION: 2.3.0 + ANCHOR_VERSION: 0.32.1 + NODE_VERSION: "22.14.x" jobs: fmt-clippy: name: fmt & clippy runs-on: ubicloud steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Rust nightly uses: actions-rs/toolchain@v1 with: @@ -39,7 +41,7 @@ jobs: name: Unit tests runs-on: ubicloud steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: @@ -57,7 +59,7 @@ jobs: # name: Cargo audit # runs-on: ubicloud # steps: -# - uses: actions/checkout@v2 +# - uses: actions/checkout@v4 # - name: Cache cargo-audit version # uses: Swatinem/rust-cache@v1 # - name: Download cargo-audit @@ -70,11 +72,11 @@ jobs: yarn-prettier: runs-on: ubicloud steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup node uses: actions/setup-node@v2 with: - node-version: "22.14.x" + node-version: ${{ env.NODE_VERSION }} registry-url: "https://registry.npmjs.org" - name: Install yarn run: yarn @@ -85,11 +87,11 @@ jobs: yarn-lint: runs-on: ubicloud steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup node uses: actions/setup-node@v2 with: - node-version: "22.14.x" + node-version: ${{ env.NODE_VERSION }} registry-url: "https://registry.npmjs.org" - name: Install yarn run: yarn @@ -99,7 +101,7 @@ jobs: runs-on: ubicloud timeout-minutes: 60 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 @@ -119,16 +121,18 @@ jobs: uses: actions/cache@v4 with: path: ~/.cargo/bin/anchor - key: ${{ runner.os }}-anchor-cli-0.29.0 + key: ${{ runner.os }}-anchor-cli-${{ env.ANCHOR_VERSION }} - name: Install Anchor CLI if: steps.cache-anchor.outputs.cache-hit != 'true' - run: cargo install --git https://github.com/coral-xyz/anchor --tag v0.29.0 anchor-cli --locked + run: | + sudo apt install libudev-dev + cargo install --git https://github.com/coral-xyz/anchor --tag v${{ env.ANCHOR_VERSION }} anchor-cli --locked - name: Setup node uses: actions/setup-node@v2 with: - node-version: "22.14.x" + node-version: ${{ env.NODE_VERSION }} registry-url: "https://registry.npmjs.org" - name: Setup yarn @@ -156,12 +160,12 @@ jobs: name: Verify SDK Configs runs-on: ubicloud steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v2 with: - node-version: "22.14.x" + node-version: ${{ env.NODE_VERSION }} registry-url: 'https://registry.npmjs.org' - name: Install dependencies @@ -195,7 +199,7 @@ jobs: sdk: ${{ steps.filter.outputs.sdk }} steps: # For pull requests it's not necessary to checkout the code - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dorny/paths-filter@v2 id: filter with: @@ -220,11 +224,11 @@ jobs: outputs: version: ${{ steps.git-commit.outputs.version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup node uses: actions/setup-node@v2 with: - node-version: "22.14.x" + node-version: ${{ env.NODE_VERSION }} registry-url: "https://registry.npmjs.org" - name: Build sdk run: yarn @@ -288,7 +292,7 @@ jobs: ] steps: - name: Checkout code with new updated version - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Emit dispatch event run: | curl -X POST \ @@ -310,7 +314,7 @@ jobs: program: ${{ steps.filter.outputs.program }} steps: # For pull requests it's not necessary to checkout the code - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: dorny/paths-filter@v2 id: filter with: @@ -327,16 +331,11 @@ jobs: if: ${{ needs.check-for-program-version-changes.outputs.program == 'true' }} steps: - name: Checkout - uses: actions/checkout@v3 - - - name: Install Solana Verify - run: | - cargo install --version 0.2.13 solana-verify - solana-verify --version + uses: actions/checkout@v4 - name: Verifiable Build run: | - solana-verify build --library-name drift --base-image ellipsislabs/solana:1.16.6 + anchor build --verifiable -s ${{ env.SOLANA_VERSION }} -d solanafoundation/anchor:v${{ env.ANCHOR_VERSION }} - name: Upload Artifact uses: actions/upload-artifact@v4 diff --git a/Anchor.toml b/Anchor.toml index dbaa023761..1cc60b748d 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -2,6 +2,10 @@ cluster = "localnet" wallet = "~/.config/solana/id.json" +[toolchain] +solana_version = "2.3.0" +anchor_version = "0.32.1" + [workspace] exclude = ["programs/openbook_v2"] @@ -25,4 +29,4 @@ filename = "./deps/configs/usdc.json" [[test.validator.account]] address = "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" -filename = "./deps/configs/pyth_lazer_storage.json" \ No newline at end of file +filename = "./deps/configs/pyth_lazer_storage.json" diff --git a/Cargo.lock b/Cargo.lock index 953bb15314..4292dd72d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,33 +1,33 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "aead" -version = "0.4.3" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" dependencies = [ + "crypto-common", "generic-array", ] [[package]] name = "aes" -version = "0.7.5" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", "cipher", "cpufeatures", - "opaque-debug", ] [[package]] name = "aes-gcm-siv" -version = "0.10.3" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589c637f0e68c877bbd59a4599bbe849cac8e5f3e4b5a3ebae8f528cd218dcdc" +checksum = "ae0784134ba9375416d469ec31e7c5f9fa94405049cf08c5ce5b4698be673e0d" dependencies = [ "aead", "aes", @@ -40,33 +40,20 @@ dependencies = [ [[package]] name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom 0.2.9", - "once_cell", - "version_check", -] - -[[package]] -name = "ahash" -version = "0.8.6" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "cfg-if", - "getrandom 0.2.9", + "getrandom 0.2.16", "once_cell", "version_check", - "zerocopy", ] [[package]] name = "aho-corasick" -version = "0.7.18" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -79,114 +66,120 @@ checksum = "6b2d54853319fd101b8dd81de382bcbf3e03410a64d8928bbee85a3e7dcde483" [[package]] name = "anchor-attribute-access-control" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f619f1d04f53621925ba8a2e633ba5a6081f2ae14758cbb67f38fd823e0a3e" +checksum = "7a883ca44ef14b2113615fc6d3a85fefc68b5002034e88db37f7f1f802f88aa9" dependencies = [ "anchor-syn", "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-attribute-account" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f2a3e1df4685f18d12a943a9f2a7456305401af21a07c9fe076ef9ecd6e400" +checksum = "61c4d97763b29030412b4b80715076377edc9cc63bc3c9e667297778384b9fd2" dependencies = [ "anchor-syn", - "bs58 0.5.0", + "bs58 0.5.1", "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-attribute-constant" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9423945cb55627f0b30903288e78baf6f62c6c8ab28fb344b6b25f1ffee3dca7" +checksum = "aae3328bbf9bbd517a51621b1ba6cbec06cbbc25e8cfc7403bddf69bcf088206" dependencies = [ "anchor-syn", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-attribute-error" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ed12720033cc3c3bf3cfa293349c2275cd5ab99936e33dd4bf283aaad3e241" +checksum = "cf2398a6d9e16df1ee9d7d37d970a8246756de898c8dd16ef6bdbe4da20cf39a" dependencies = [ "anchor-syn", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-attribute-event" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef4dc0371eba2d8c8b54794b0b0eb786a234a559b77593d6f80825b6d2c77a2" +checksum = "f12758f4ec2f0e98d4d56916c6fe95cb23d74b8723dd902c762c5ef46ebe7b65" dependencies = [ "anchor-syn", "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-attribute-program" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b18c4f191331e078d4a6a080954d1576241c29c56638783322a18d308ab27e4f" +checksum = "8c7193b5af2649813584aae6e3569c46fd59616a96af2083c556b13136c3830f" dependencies = [ + "anchor-lang-idl", "anchor-syn", + "anyhow", + "bs58 0.5.1", + "heck", + "proc-macro2", "quote", - "syn 1.0.92", + "serde_json", + "syn 1.0.109", ] [[package]] name = "anchor-derive-accounts" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de10d6e9620d3bcea56c56151cad83c5992f50d5960b3a9bebc4a50390ddc3c" +checksum = "d332d1a13c0fca1a446de140b656e66110a5e8406977dcb6a41e5d6f323760b0" dependencies = [ "anchor-syn", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-derive-serde" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" +checksum = "8656e4af182edaeae665fa2d2d7ee81148518b5bd0be9a67f2a381bb17da7d46" dependencies = [ "anchor-syn", - "borsh-derive-internal 0.10.3", + "borsh-derive-internal", "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-derive-space" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecc31d19fa54840e74b7a979d44bcea49d70459de846088a1d71e87ba53c419" +checksum = "dcff2a083560cd79817db07d89a4de39a2c4b2eaa00c1742cf0df49b25ff2bed" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "anchor-lang" -version = "0.29.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35da4785497388af0553586d55ebdc08054a8b1724720ef2749d313494f2b8ad" +checksum = "e67d85d5376578f12d840c29ff323190f6eecd65b00a0b5f2b2f232751d049cc" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", @@ -197,210 +190,116 @@ dependencies = [ "anchor-derive-accounts", "anchor-derive-serde", "anchor-derive-space", - "arrayref", - "base64 0.13.0", + "anchor-lang-idl", + "base64 0.21.7", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", - "getrandom 0.2.9", - "solana-program", - "thiserror", -] - -[[package]] -name = "anchor-spl" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c4fd6e43b2ca6220d2ef1641539e678bfc31b6cc393cf892b373b5997b6a39a" -dependencies = [ - "anchor-lang", - "solana-program", - "spl-associated-token-account", - "spl-token 4.0.0", - "spl-token-2022", -] - -[[package]] -name = "anchor-syn" -version = "0.29.0" + "solana-account-info", + "solana-clock", + "solana-cpi", + "solana-define-syscall", + "solana-feature-gate-interface", + "solana-instruction", + "solana-instructions-sysvar", + "solana-invoke", + "solana-loader-v3-interface", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-sysvar-id", + "thiserror 1.0.69", +] + +[[package]] +name = "anchor-lang-idl" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9101b84702fed2ea57bd22992f75065da5648017135b844283a2f6d74f27825" +checksum = "32e8599d21995f68e296265aa5ab0c3cef582fd58afec014d01bd0bce18a4418" dependencies = [ + "anchor-lang-idl-spec", "anyhow", - "bs58 0.5.0", "heck", - "proc-macro2", - "quote", + "regex", "serde", "serde_json", - "sha2 0.10.8", - "syn 1.0.92", - "thiserror", -] - -[[package]] -name = "anyhow" -version = "1.0.70" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" - -[[package]] -name = "ark-bn254" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-std", -] - -[[package]] -name = "ark-ec" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" -dependencies = [ - "ark-ff", - "ark-poly", - "ark-serialize", - "ark-std", - "derivative", - "hashbrown 0.13.2", - "itertools 0.10.5", - "num-traits", - "zeroize", -] - -[[package]] -name = "ark-ff" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" -dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", - "derivative", - "digest 0.10.7", - "itertools 0.10.5", - "num-bigint", - "num-traits", - "paste", - "rustc_version 0.4.0", - "zeroize", -] - -[[package]] -name = "ark-ff-asm" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" -dependencies = [ - "quote", - "syn 1.0.92", -] - -[[package]] -name = "ark-ff-macros" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" -dependencies = [ - "num-bigint", - "num-traits", - "proc-macro2", - "quote", - "syn 1.0.92", + "sha2 0.10.9", ] [[package]] -name = "ark-poly" -version = "0.4.2" +name = "anchor-lang-idl-spec" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +checksum = "2bdf143115440fe621bdac3a29a1f7472e09f6cd82b2aa569429a0c13f103838" dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "derivative", - "hashbrown 0.13.2", + "anyhow", + "serde", ] [[package]] -name = "ark-serialize" -version = "0.4.2" +name = "anchor-spl" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +checksum = "3397ab3fc5b198bbfe55d827ff58bd69f2a8d3f9f71c3732c23c2093fec4d3ef" dependencies = [ - "ark-serialize-derive", - "ark-std", - "digest 0.10.7", - "num-bigint", + "anchor-lang", + "spl-associated-token-account", + "spl-pod", + "spl-token", + "spl-token-2022", + "spl-token-group-interface", + "spl-token-metadata-interface", ] [[package]] -name = "ark-serialize-derive" -version = "0.4.2" +name = "anchor-syn" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +checksum = "b93b69aa7d099b59378433f6d7e20e1008fc10c69e48b220270e5b3f2ec4c8be" dependencies = [ + "anyhow", + "bs58 0.5.1", + "cargo_toml", + "heck", "proc-macro2", "quote", - "syn 1.0.92", -] - -[[package]] -name = "ark-std" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" -dependencies = [ - "num-traits", - "rand 0.8.5", + "serde", + "serde_json", + "sha2 0.10.9", + "syn 1.0.109", + "thiserror 1.0.69", ] [[package]] -name = "array-bytes" -version = "1.4.1" +name = "anyhow" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ad284aeb45c13f2fb4f084de4a420ebf447423bdf9386c0540ce33cb3ef4b8c" +checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "arrayref" -version = "0.3.7" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" +checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" [[package]] name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - -[[package]] -name = "assert_matches" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" - -[[package]] -name = "atty" -version = "0.2.14" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "autocfg" -version = "1.0.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "base64" @@ -410,9 +309,9 @@ checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" [[package]] name = "base64" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" @@ -420,6 +319,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bincode" version = "1.3.3" @@ -431,18 +336,9 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitmaps" -version = "2.1.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "031043d04099746d8db04daf1fa424b2bc8bd69d92b25962dcde24da39ab64a2" -dependencies = [ - "typenum", -] +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "bitvec" @@ -458,9 +354,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.5.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" +checksum = "3888aaa89e4b2a40fca9848e400f6a658a5a3978de7be858e209cafa8be9a4a0" dependencies = [ "arrayref", "arrayvec", @@ -476,7 +372,6 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "block-padding", "generic-array", ] @@ -489,124 +384,72 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - -[[package]] -name = "borsh" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" -dependencies = [ - "borsh-derive 0.9.3", - "hashbrown 0.11.2", -] - [[package]] name = "borsh" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +checksum = "115e54d64eb62cdebad391c19efc9dce4981c690c85a33a12199d99bb9546fee" dependencies = [ - "borsh-derive 0.10.3", - "hashbrown 0.13.2", + "borsh-derive 0.10.4", + "hashbrown 0.12.3", ] [[package]] name = "borsh" -version = "1.1.1" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e3f7359eeed8d454c38bbb25eb89d98b888b1060bbfeed2cda71cb013ff2dc2" +checksum = "ad8646f98db542e39fc66e68a20b2144f6a732636df7c2354e74645faaa433ce" dependencies = [ - "borsh-derive 1.1.1", + "borsh-derive 1.5.7", "cfg_aliases", ] [[package]] name = "borsh-derive" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" -dependencies = [ - "borsh-derive-internal 0.9.3", - "borsh-schema-derive-internal 0.9.3", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn 1.0.92", -] - -[[package]] -name = "borsh-derive" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +checksum = "831213f80d9423998dd696e2c5345aba6be7a0bd8cd19e31c5243e13df1cef89" dependencies = [ - "borsh-derive-internal 0.10.3", - "borsh-schema-derive-internal 0.10.3", + "borsh-derive-internal", + "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", "proc-macro2", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "borsh-derive" -version = "1.1.1" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "318d18ba283f9aa5bfef1405996ce66c584127f401be1403729ec88b10adc772" +checksum = "fdd1d3c0c2f5833f22386f252fe8ed005c7f59fdcddeef025c01b4c3b9fd9ac3" dependencies = [ "once_cell", - "proc-macro-crate 1.2.1", - "proc-macro2", - "quote", - "syn 2.0.48", - "syn_derive", -] - -[[package]] -name = "borsh-derive-internal" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" -dependencies = [ + "proc-macro-crate 3.4.0", "proc-macro2", "quote", - "syn 1.0.92", + "syn 2.0.109", ] [[package]] name = "borsh-derive-internal" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb438156919598d2c7bad7e1c0adf3d26ed3840dbc010db1a882a65583ca2fb" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.92", -] - -[[package]] -name = "borsh-schema-derive-internal" -version = "0.9.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" +checksum = "65d6ba50644c98714aa2a70d13d7df3cd75cd2b523a2b452bf010443800976b3" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "borsh-schema-derive-internal" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +checksum = "276691d96f063427be83e6692b86148e488ebba9f48f77788724ca027ba3b6d4" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] @@ -617,18 +460,18 @@ checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] name = "bs58" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ "tinyvec", ] [[package]] name = "bumpalo" -version = "3.9.1" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "bv" @@ -642,9 +485,9 @@ dependencies = [ [[package]] name = "bytecheck" -version = "0.6.11" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b6372023ac861f6e6dc89c8344a8f398fb42aaba2b5dbc649ca0c0e9dbcb627" +checksum = "23cdc57ce23ac53c931e88a43d06d070a6fd142f2617be5855eb75efc9beb1c2" dependencies = [ "bytecheck_derive", "ptr_meta", @@ -659,79 +502,81 @@ checksum = "3db406d29fbcd95542e92559bed4d8ad92636d1ca8b3b72ede10b4bcc010e659" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "bytemuck" -version = "1.21.0" +version = "1.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3" +checksum = "1fbdf580320f38b612e485521afda1ee26d10cc9884efaaa750d383e13e3c5f4" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.4.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" +checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.2.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] -name = "cc" -version = "1.0.83" +name = "cargo_toml" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "a98356df42a2eb1bd8f1793ae4ee4de48e384dd974ce5eac8eee802edb7492be" dependencies = [ - "jobserver", - "libc", + "serde", + "toml 0.8.23", ] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "cc" +version = "1.2.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3" +dependencies = [ + "find-msvc-tools", + "shlex", +] [[package]] -name = "cfg_aliases" -version = "0.1.1" +name = "cfg-if" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] -name = "chrono" -version = "0.4.30" +name = "cfg_aliases" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "defd4e7873dbddba6c7c91e199c7fcb946abc4a6a4ac3195400bcfb01b5de877" -dependencies = [ - "num-traits", -] +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] name = "cipher" -version = "0.3.0" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" dependencies = [ - "generic-array", + "crypto-common", + "inout", ] [[package]] @@ -756,9 +601,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" [[package]] name = "convert_case" @@ -768,177 +613,92 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" dependencies = [ "libc", ] [[package]] -name = "crossbeam-channel" -version = "0.5.6" +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + +[[package]] +name = "crypto-common" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "cfg-if", - "crossbeam-utils", + "generic-array", + "rand_core 0.6.4", + "typenum", ] [[package]] -name = "crossbeam-deque" -version = "0.8.2" +name = "ctr" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", + "cipher", ] [[package]] -name = "crossbeam-epoch" -version = "0.9.10" +name = "curve25519-dalek" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "autocfg", "cfg-if", - "crossbeam-utils", - "memoffset 0.6.5", - "once_cell", - "scopeguard", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rand_core 0.6.4", + "rustc_version", + "serde", + "subtle", + "zeroize", ] [[package]] -name = "crossbeam-utils" -version = "0.8.11" +name = "curve25519-dalek-derive" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "cfg-if", - "once_cell", + "proc-macro2", + "quote", + "syn 2.0.109", ] [[package]] -name = "crunchy" -version = "0.2.2" +name = "derivation-path" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "6e5c37193a1db1d8ed868c03ec7b152175f26160a5b740e5e484143877e0adf0" [[package]] -name = "crypto-common" -version = "0.1.3" +name = "derive_more" +version = "0.99.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +checksum = "6edb4b64a43d977b8e99788fe3a04d483834fba1215a7e02caa415b626497f7f" dependencies = [ - "generic-array", - "typenum", + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.109", ] [[package]] -name = "crypto-mac" -version = "0.8.0" +name = "digest" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "ctr" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" -dependencies = [ - "cipher", -] - -[[package]] -name = "curve25519-dalek" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" -dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "serde", - "subtle", - "zeroize", -] - -[[package]] -name = "darling" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn 2.0.48", -] - -[[package]] -name = "darling_macro" -version = "0.20.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" -dependencies = [ - "darling_core", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "derivation-path" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5c37193a1db1d8ed868c03ec7b152175f26160a5b740e5e484143877e0adf0" - -[[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.92", -] - -[[package]] -name = "derive_more" -version = "0.99.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" -dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 2.0.48", -] - -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ "generic-array", ] @@ -961,8 +721,7 @@ dependencies = [ "anchor-lang", "anchor-spl", "arrayref", - "base64 0.13.0", - "borsh 0.10.3", + "base64 0.13.1", "bytemuck", "byteorder", "bytes", @@ -973,6 +732,7 @@ dependencies = [ "num-traits", "openbook-v2-light", "phoenix-v1", + "proc-macro2", "pyth", "pyth-client", "pyth-lazer-solana-contract", @@ -990,65 +750,31 @@ dependencies = [ [[package]] name = "drift-macros" version = "0.1.0" -source = "git+https://github.com/drift-labs/drift-macros.git?rev=c57d87#c57d87e073d13d43f4d1fb09fe6822915a4ccc11" +source = "git+https://github.com/drift-labs/drift-macros?rev=6e246ba#6e246bacf5fc3bb11d04710753a2f2f5ef0fb06d" dependencies = [ "quote", - "syn 1.0.92", -] - -[[package]] -name = "ed25519" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" -dependencies = [ - "signature", -] - -[[package]] -name = "ed25519-dalek" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" -dependencies = [ - "curve25519-dalek", - "ed25519", - "rand 0.7.3", - "serde", - "sha2 0.9.9", - "zeroize", -] - -[[package]] -name = "ed25519-dalek-bip32" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d2be62a4061b872c8c0873ee4fc6f101ce7b889d039f019c5fa2af471a59908" -dependencies = [ - "derivation-path", - "ed25519-dalek", - "hmac 0.12.1", - "sha2 0.10.8", + "static_assertions", + "syn 1.0.109", ] [[package]] name = "either" -version = "1.8.1" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "ellipsis-macros" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598d7f4a52f256bc6d065f0ee1c8dd07275952f9425bdfc1639595c924e1498e" +checksum = "0db15a500beac067d37fce7042bbaa349cf1303aadd902f8e0cfde4422d04403" dependencies = [ "bs58 0.4.0", "proc-macro2", "quote", "rustversion", "solana-program", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] @@ -1068,21 +794,14 @@ checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] -name = "env_logger" -version = "0.9.3" +name = "equivalent" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "fast-math" @@ -1099,16 +818,52 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "field-offset" -version = "0.3.4" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" + +[[package]] +name = "five8" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75b8549488b4715defcb0d8a8a1c1c76a80661b5fa106b4ca0e7fce59d7d875" +dependencies = [ + "five8_core", +] + +[[package]] +name = "five8_const" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e1c54951450cbd39f3dbcf1005ac413b49487dabf18a720ad2383eccfeffb92" +checksum = "26dec3da8bc3ef08f2c04f61eab298c3ab334523e55f076354d6d6f613799a7b" dependencies = [ - "memoffset 0.6.5", - "rustc_version 0.3.3", + "five8_core", ] +[[package]] +name = "five8_core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2551bf44bc5f776c15044b9b94153a00198be06743e262afaaa61f11ac7523a5" + [[package]] name = "fnv" version = "1.0.7" @@ -1123,11 +878,10 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "generic-array" -version = "0.14.7" +version = "0.14.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "4bb6743198531e02858aeaea5398fcc883e71851fcbcb5a2f773e2fb6cb1edf2" dependencies = [ - "serde", "typenum", "version_check", ] @@ -1139,70 +893,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", - "js-sys", "libc", "wasi 0.9.0+wasi-snapshot-preview1", - "wasm-bindgen", ] [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi 0.11.1+wasi-snapshot-preview1", "wasm-bindgen", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" -dependencies = [ - "ahash 0.7.6", -] - [[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash 0.7.6", + "ahash", ] [[package]] name = "hashbrown" -version = "0.13.2" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash 0.8.6", -] +checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" [[package]] name = "heck" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" dependencies = [ "unicode-segmentation", ] -[[package]] -name = "hermit-abi" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" -dependencies = [ - "libc", -] - [[package]] name = "hex" version = "0.4.3" @@ -1212,16 +943,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hmac" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" -dependencies = [ - "crypto-mac", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.12.1" @@ -1231,29 +952,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "hmac-drbg" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" -dependencies = [ - "digest 0.9.0", - "generic-array", - "hmac 0.8.1", -] - -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "ieee754" version = "0.2.6" @@ -1261,19 +959,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9007da9cacbd3e6343da136e98b0d2df013f553d35bdec8b518f07bea768e19c" [[package]] -name = "im" -version = "15.1.0" +name = "indexmap" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0acd33ff0285af998aaf9b57342af478078f53492322fafc47450e09397e0e9" +checksum = "6717a8d2a5a929a1a2eb43a12812498ed141a0bcfb7e8f7844fbdbe4303bba9f" dependencies = [ - "bitmaps", - "rand_core 0.6.4", - "rand_xoshiro", - "rayon", - "serde", - "sized-chunks", - "typenum", - "version_check", + "equivalent", + "hashbrown 0.16.0", +] + +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", ] [[package]] @@ -1287,9 +988,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.5" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" dependencies = [ "either", ] @@ -1305,57 +1006,52 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - -[[package]] -name = "jobserver" -version = "0.1.26" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" -dependencies = [ - "libc", -] +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.67" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" dependencies = [ + "once_cell", "wasm-bindgen", ] [[package]] name = "keccak" -version = "0.1.0" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lib-sokoban" -version = "0.3.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6295db13f26aaa8bb4fb38e0c9ff50253814aa490eef7b4d6aa106ba6fc843" +checksum = "1acf72a87f85040eb8128c9edbce1ec6e951caf9b07efe15a484edcd8a59e2e5" dependencies = [ "bytemuck", "num-derive 0.3.3", "num-traits", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "libc" -version = "0.2.152" +version = "0.2.177" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" +checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976" [[package]] name = "libsecp256k1" @@ -1366,14 +1062,12 @@ dependencies = [ "arrayref", "base64 0.12.3", "digest 0.9.0", - "hmac-drbg", "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", "rand 0.7.3", "serde", "sha2 0.9.9", - "typenum", ] [[package]] @@ -1407,51 +1101,30 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.17" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "memchr" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" - -[[package]] -name = "memmap2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" -dependencies = [ - "libc", -] - -[[package]] -name = "memoffset" -version = "0.6.5" +version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" [[package]] name = "memoffset" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] @@ -1470,9 +1143,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-bigint", "num-complex", @@ -1484,20 +1157,19 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-complex" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] @@ -1510,35 +1182,34 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "num-derive" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] name = "num-integer" -version = "0.1.44" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.44" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", @@ -1547,11 +1218,10 @@ dependencies = [ [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", "num-bigint", "num-integer", "num-traits", @@ -1559,112 +1229,61 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] -name = "num_cpus" -version = "1.13.1" +name = "num_enum" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +checksum = "b1207a7e20ad57b847bbddc6776b968420d38292bbfe2089accff5e19e82454c" dependencies = [ - "hermit-abi", - "libc", + "num_enum_derive", + "rustversion", ] [[package]] -name = "num_enum" -version = "0.5.9" +name = "num_enum_derive" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" +checksum = "ff32365de1b6743cb203b710788263c44a03de03802daf96092f2da4fe6ba4d7" dependencies = [ - "num_enum_derive 0.5.11", + "proc-macro-crate 3.4.0", + "proc-macro2", + "quote", + "syn 2.0.109", ] [[package]] -name = "num_enum" -version = "0.6.1" +name = "once_cell" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive 0.6.1", -] +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] -name = "num_enum" -version = "0.7.2" +name = "opaque-debug" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "openbook-v2-light" +version = "0.1.0" dependencies = [ - "num_enum_derive 0.7.2", + "anchor-lang", + "borsh 0.10.4", + "bytemuck", ] [[package]] -name = "num_enum_derive" -version = "0.5.11" +name = "parking_lot" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" -dependencies = [ - "proc-macro-crate 1.2.1", - "proc-macro2", - "quote", - "syn 1.0.92", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate 1.2.1", - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "num_enum_derive" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" -dependencies = [ - "proc-macro-crate 1.2.1", - "proc-macro2", - "quote", - "syn 2.0.48", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - -[[package]] -name = "openbook-v2-light" -version = "0.1.0" -dependencies = [ - "anchor-lang", - "borsh 0.10.3", - "bytemuck", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ "lock_api", "parking_lot_core", @@ -1672,30 +1291,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.3" +version = "0.9.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", -] - -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - -[[package]] -name = "pbkdf2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216eaa586a190f0a738f2f918511eecfa90f13295abec0e457cdebcceda80cbd" -dependencies = [ - "crypto-mac", + "windows-link", ] [[package]] @@ -1709,44 +1313,35 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" - -[[package]] -name = "pest" -version = "2.1.3" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "phoenix-v1" version = "0.2.4" -source = "git+https://github.com/drift-labs/phoenix-v1?rev=7703c5#7703c50cf92f2bb321dcd1e2824e1c041135ec5c" +source = "git+https://github.com/jordy25519/phoenix-v1?branch=master#fcf37149707a300cf42bfd5106bb675de53c8962" dependencies = [ - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "ellipsis-macros", - "itertools 0.10.5", + "itertools 0.12.1", "lib-sokoban", - "num_enum 0.5.9", + "num_enum", "shank", "solana-program", "solana-security-txt", "spl-associated-token-account", - "spl-token 3.5.0", + "spl-token", "static_assertions", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "polyval" -version = "0.5.3" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" dependencies = [ "cfg-if", "cpufeatures", @@ -1756,9 +1351,12 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] [[package]] name = "proc-macro-crate" @@ -1766,48 +1364,23 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" dependencies = [ - "toml", + "toml 0.5.11", ] [[package]] name = "proc-macro-crate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" -dependencies = [ - "once_cell", - "thiserror", - "toml", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +checksum = "219cb19e96be00ab2e37d6e299658a0cfa83e52429179969b0f0121b4ac46983" dependencies = [ - "proc-macro2", - "quote", - "version_check", + "toml_edit 0.23.7", ] [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8" dependencies = [ "unicode-ident", ] @@ -1829,7 +1402,7 @@ checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] @@ -1849,7 +1422,7 @@ checksum = "44de48029c54ec1ca570786b5baeb906b0fc2409c8e0145585e287ee7a526c72" [[package]] name = "pyth-lazer-protocol" version = "0.1.2" -source = "git+https://github.com/drift-labs/pyth-crosschain?rev=d790d1cb4da873a949cf33ff70349b7614b232eb#d790d1cb4da873a949cf33ff70349b7614b232eb" +source = "git+https://github.com/jordy25519/pyth-crosschain#e43b2765edf680a52f1649ae57024d63ef645443" dependencies = [ "anyhow", "byteorder", @@ -1862,20 +1435,20 @@ dependencies = [ [[package]] name = "pyth-lazer-solana-contract" version = "0.2.0" -source = "git+https://github.com/drift-labs/pyth-crosschain?rev=d790d1cb4da873a949cf33ff70349b7614b232eb#d790d1cb4da873a949cf33ff70349b7614b232eb" +source = "git+https://github.com/jordy25519/pyth-crosschain#e43b2765edf680a52f1649ae57024d63ef645443" dependencies = [ "anchor-lang", "bytemuck", "byteorder", "pyth-lazer-protocol", "solana-program", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "pyth-solana-receiver-sdk" version = "0.3.0" -source = "git+https://github.com/drift-labs/pyth-crosschain?rev=d790d1cb4da873a949cf33ff70349b7614b232eb#d790d1cb4da873a949cf33ff70349b7614b232eb" +source = "git+https://github.com/jordy25519/pyth-crosschain#e43b2765edf680a52f1649ae57024d63ef645443" dependencies = [ "anchor-lang", "hex", @@ -1886,22 +1459,22 @@ dependencies = [ [[package]] name = "pythnet-sdk" version = "2.1.0" -source = "git+https://github.com/drift-labs/pyth-crosschain?rev=d790d1cb4da873a949cf33ff70349b7614b232eb#d790d1cb4da873a949cf33ff70349b7614b232eb" +source = "git+https://github.com/jordy25519/pyth-crosschain#e43b2765edf680a52f1649ae57024d63ef645443" dependencies = [ "anchor-lang", "bincode", - "borsh 0.10.3", + "borsh 0.10.4", "bytemuck", "byteorder", "fast-math", "hex", "proc-macro2", - "rustc_version 0.4.0", + "rustc_version", "serde", - "sha3 0.10.4", + "sha3", "slow_primes", "solana-program", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1915,9 +1488,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" dependencies = [ "proc-macro2", ] @@ -1987,7 +1560,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.9", + "getrandom 0.2.16", ] [[package]] @@ -2000,52 +1573,31 @@ dependencies = [ ] [[package]] -name = "rand_xoshiro" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa" -dependencies = [ - "rand_core 0.6.4", -] - -[[package]] -name = "rayon" -version = "1.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d" -dependencies = [ - "autocfg", - "crossbeam-deque", - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.9.3" +name = "redox_syscall" +version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", + "bitflags", ] [[package]] -name = "redox_syscall" -version = "0.2.13" +name = "regex" +version = "1.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +checksum = "843bc0191f75f3e22651ae5f1e72939ab2f72a4bc30fa80a066bd66edefc24d4" dependencies = [ - "bitflags", + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", ] [[package]] -name = "regex" -version = "1.5.4" +name = "regex-automata" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" +checksum = "5276caf25ac86c8d810222b3dbb938e512c55c6831a10f3e6ed1c93b84041f1c" dependencies = [ "aho-corasick", "memchr", @@ -2054,9 +1606,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "rend" @@ -2069,12 +1621,13 @@ dependencies = [ [[package]] name = "rkyv" -version = "0.7.42" +version = "0.7.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0200c8230b013893c0b2d6213d6ec64ed2b9be2e0e016682b7224ff82cff5c58" +checksum = "9008cd6385b9e161d8229e1f6549dd23c3d022f132a2ea37ac3a10ac4935779b" dependencies = [ "bitvec", "bytecheck", + "bytes", "hashbrown 0.12.3", "ptr_meta", "rend", @@ -2092,17 +1645,17 @@ checksum = "503d1d27590a2b0a3a4ca4c94755aa2875657196ecbf401a42eff41d7de532c0" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] name = "rust_decimal" -version = "1.36.0" +version = "1.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +checksum = "35affe401787a9bd846712274d97654355d21b2a2c092a3139aabe31e9022282" dependencies = [ "arrayvec", - "borsh 1.1.1", + "borsh 1.5.7", "bytes", "num-traits", "rand 0.8.5", @@ -2111,53 +1664,38 @@ dependencies = [ "serde_json", ] -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.18", + "semver", ] [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "safe-transmute" -version = "0.11.2" +version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98a01dab6acf992653be49205bdd549f32f17cb2803e8eacf1560bf97259aae8" +checksum = "3944826ff8fa8093089aba3acb4ef44b9446a99a16f3bf4e74af3f77d340ab7d" [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "seahash" @@ -2167,94 +1705,76 @@ checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" [[package]] name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver" -version = "1.0.18" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" [[package]] -name = "semver-parser" -version = "0.10.2" +name = "serde" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ - "pest", + "serde_core", + "serde_derive", ] [[package]] -name = "serde" -version = "1.0.209" +name = "serde_bytes" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" dependencies = [ - "serde_derive", + "serde", + "serde_core", ] [[package]] -name = "serde_bytes" -version = "0.11.14" +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ - "serde", + "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.209" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] name = "serde_json" -version = "1.0.111" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" +checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c" dependencies = [ "itoa", + "memchr", "ryu", "serde", + "serde_core", ] [[package]] -name = "serde_with" -version = "2.3.3" +name = "serde_spanned" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" dependencies = [ "serde", - "serde_with_macros", -] - -[[package]] -name = "serde_with_macros" -version = "2.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn 2.0.48", ] [[package]] name = "serum_dex" version = "0.5.6" -source = "git+https://github.com/project-serum/serum-dex?rev=85b4f14#85b4f1499017f22da4b355781bdb5973b3b2646f" +source = "git+https://github.com/drift-labs/serum-dex?branch=master#2347e4810ace967ab186202e22b6188b9cab03ba" dependencies = [ "arrayref", "bincode", @@ -2264,13 +1784,13 @@ dependencies = [ "field-offset", "itertools 0.9.0", "num-traits", - "num_enum 0.5.9", + "num_enum", "safe-transmute", "serde", "solana-program", - "spl-token 3.5.0", + "spl-token", "static_assertions", - "thiserror", + "thiserror 1.0.69", "without-alloc", ] @@ -2289,9 +1809,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", @@ -2300,21 +1820,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "keccak", - "opaque-debug", -] - -[[package]] -name = "sha3" -version = "0.10.4" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaedf34ed289ea47c2b741bb72e5357a209512d67bcd4bda44359e5bf0470f56" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" dependencies = [ "digest 0.10.7", "keccak", @@ -2339,7 +1847,7 @@ dependencies = [ "quote", "shank_macro_impl", "shank_render", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] @@ -2352,7 +1860,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 1.0.92", + "syn 1.0.109", ] [[package]] @@ -2367,10 +1875,10 @@ dependencies = [ ] [[package]] -name = "signature" -version = "1.6.4" +name = "shlex" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "simdutf8" @@ -2378,16 +1886,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" -[[package]] -name = "sized-chunks" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16d69225bde7a69b235da73377861095455d298f2b970996eec25ddbb42b3d1e" -dependencies = [ - "bitmaps", - "typenum", -] - [[package]] name = "slow_primes" version = "0.1.14" @@ -2399,427 +1897,1289 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.8.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] -name = "solana-frozen-abi" -version = "1.16.25" +name = "solana-account" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7077f6495ccc313dff49c3e3f3ed03e49058258bae7fee77ac29ba0a474ba82" +checksum = "0f949fe4edaeaea78c844023bfc1c898e0b1f5a100f8a8d2d0f85d0a7b090258" dependencies = [ - "ahash 0.8.6", - "blake3", - "block-buffer 0.10.4", - "bs58 0.4.0", - "bv", - "byteorder", - "cc", - "either", - "generic-array", - "getrandom 0.1.16", - "im", - "lazy_static", - "log", - "memmap2", - "once_cell", - "rand_core 0.6.4", - "rustc_version 0.4.0", + "solana-account-info", + "solana-clock", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-account-info" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8f5152a288ef1912300fc6efa6c2d1f9bb55d9398eb6c72326360b8063987da" +dependencies = [ + "bincode", "serde", - "serde_bytes", - "serde_derive", - "serde_json", - "sha2 0.10.8", - "solana-frozen-abi-macro", - "subtle", - "thiserror", + "solana-program-error", + "solana-program-memory", + "solana-pubkey", ] [[package]] -name = "solana-frozen-abi-macro" -version = "1.16.25" +name = "solana-address-lookup-table-interface" +version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f516f992211a2ab70de5c367190575c97e02d156f9f1d8b76886d673f30e88a2" +checksum = "d1673f67efe870b64a65cb39e6194be5b26527691ce5922909939961a6e6b395" dependencies = [ - "proc-macro2", - "quote", - "rustc_version 0.4.0", - "syn 2.0.48", + "bincode", + "bytemuck", + "serde", + "serde_derive", + "solana-clock", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-slot-hashes", ] [[package]] -name = "solana-logger" -version = "1.16.25" +name = "solana-atomic-u64" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b64def674bfaa4a3f8be7ba19c03c9caec4ec028ba62b9a427ec1bf608a2486" +checksum = "d52e52720efe60465b052b9e7445a01c17550666beec855cce66f44766697bc2" dependencies = [ - "env_logger", - "lazy_static", - "log", + "parking_lot", ] [[package]] -name = "solana-program" -version = "1.16.25" +name = "solana-big-mod-exp" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e92350aa5b42564681655331e7e0b9d5c99a442de317ceeb4741efbbe9a6c05" +checksum = "75db7f2bbac3e62cfd139065d15bcda9e2428883ba61fc8d27ccb251081e7567" dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "ark-serialize", - "array-bytes", - "base64 0.21.7", - "bincode", - "bitflags", - "blake3", - "borsh 0.10.3", - "borsh 0.9.3", - "bs58 0.4.0", - "bv", - "bytemuck", - "cc", - "console_error_panic_hook", - "console_log", - "curve25519-dalek", - "getrandom 0.2.9", - "itertools 0.10.5", - "js-sys", - "lazy_static", - "libc", - "libsecp256k1", - "log", - "memoffset 0.9.0", "num-bigint", - "num-derive 0.3.3", "num-traits", - "parking_lot", - "rand 0.7.3", - "rand_chacha 0.2.2", - "rustc_version 0.4.0", - "rustversion", - "serde", - "serde_bytes", - "serde_derive", - "serde_json", - "sha2 0.10.8", - "sha3 0.10.4", - "solana-frozen-abi", - "solana-frozen-abi-macro", - "solana-sdk-macro", - "thiserror", - "tiny-bip39", - "wasm-bindgen", - "zeroize", + "solana-define-syscall", ] [[package]] -name = "solana-sdk" -version = "1.16.25" +name = "solana-bincode" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2087e15c92d4d6b3f085dc12fbe9614141c811f90a54cc418240ac30b608133f" +checksum = "19a3787b8cf9c9fe3dd360800e8b70982b9e5a8af9e11c354b6665dd4a003adc" dependencies = [ - "assert_matches", - "base64 0.21.7", "bincode", - "bitflags", - "borsh 0.10.3", - "bs58 0.4.0", - "bytemuck", - "byteorder", - "chrono", - "derivation-path", - "digest 0.10.7", - "ed25519-dalek", - "ed25519-dalek-bip32", - "generic-array", - "hmac 0.12.1", - "itertools 0.10.5", - "js-sys", - "lazy_static", - "libsecp256k1", - "log", - "memmap2", - "num-derive 0.3.3", - "num-traits", - "num_enum 0.6.1", - "pbkdf2 0.11.0", - "qstring", - "rand 0.7.3", - "rand_chacha 0.2.2", - "rustc_version 0.4.0", - "rustversion", "serde", - "serde_bytes", - "serde_derive", - "serde_json", - "serde_with", - "sha2 0.10.8", - "sha3 0.10.4", - "solana-frozen-abi", - "solana-frozen-abi-macro", - "solana-logger", - "solana-program", - "solana-sdk-macro", - "thiserror", - "uriparse", - "wasm-bindgen", + "solana-instruction", +] + +[[package]] +name = "solana-blake3-hasher" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a0801e25a1b31a14494fc80882a036be0ffd290efc4c2d640bfcca120a4672" +dependencies = [ + "blake3", + "solana-define-syscall", + "solana-hash", + "solana-sanitize", +] + +[[package]] +name = "solana-borsh" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718333bcd0a1a7aed6655aa66bef8d7fb047944922b2d3a18f49cbc13e73d004" +dependencies = [ + "borsh 0.10.4", + "borsh 1.5.7", +] + +[[package]] +name = "solana-clock" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb482ab70fced82ad3d7d3d87be33d466a3498eb8aa856434ff3c0dfc2e2e31" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-cpi" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc71126edddc2ba014622fc32d0f5e2e78ec6c5a1e0eb511b85618c09e9ea11" +dependencies = [ + "solana-account-info", + "solana-define-syscall", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-stable-layout", +] + +[[package]] +name = "solana-curve25519" +version = "2.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae4261b9a8613d10e77ac831a8fa60b6fa52b9b103df46d641deff9f9812a23" +dependencies = [ + "bytemuck", + "bytemuck_derive", + "curve25519-dalek", + "solana-define-syscall", + "subtle", + "thiserror 2.0.17", +] + +[[package]] +name = "solana-decode-error" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c781686a18db2f942e70913f7ca15dc120ec38dcab42ff7557db2c70c625a35" +dependencies = [ + "num-traits", +] + +[[package]] +name = "solana-define-syscall" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ae3e2abcf541c8122eafe9a625d4d194b4023c20adde1e251f94e056bb1aee2" + +[[package]] +name = "solana-derivation-path" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939756d798b25c5ec3cca10e06212bdca3b1443cb9bb740a38124f58b258737b" +dependencies = [ + "derivation-path", + "qstring", + "uriparse", +] + +[[package]] +name = "solana-epoch-rewards" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b575d3dd323b9ea10bb6fe89bf6bf93e249b215ba8ed7f68f1a3633f384db7" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-epoch-schedule" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fce071fbddecc55d727b1d7ed16a629afe4f6e4c217bc8d00af3b785f6f67ed" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-example-mocks" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84461d56cbb8bb8d539347151e0525b53910102e4bced875d49d5139708e39d3" +dependencies = [ + "serde", + "serde_derive", + "solana-address-lookup-table-interface", + "solana-clock", + "solana-hash", + "solana-instruction", + "solana-keccak-hasher", + "solana-message", + "solana-nonce", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", + "thiserror 2.0.17", +] + +[[package]] +name = "solana-feature-gate-interface" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43f5c5382b449e8e4e3016fb05e418c53d57782d8b5c30aa372fc265654b956d" +dependencies = [ + "bincode", + "serde", + "serde_derive", + "solana-account", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-fee-calculator" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89bc408da0fb3812bc3008189d148b4d3e08252c79ad810b245482a3f70cd8d" +dependencies = [ + "log", + "serde", + "serde_derive", +] + +[[package]] +name = "solana-hash" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b96e9f0300fa287b545613f007dfe20043d7812bee255f418c1eb649c93b63" +dependencies = [ + "borsh 1.5.7", + "bytemuck", + "bytemuck_derive", + "five8", + "js-sys", + "serde", + "serde_derive", + "solana-atomic-u64", + "solana-sanitize", + "wasm-bindgen", +] + +[[package]] +name = "solana-instruction" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab5682934bd1f65f8d2c16f21cb532526fcc1a09f796e2cacdb091eee5774ad" +dependencies = [ + "bincode", + "borsh 1.5.7", + "getrandom 0.2.16", + "js-sys", + "num-traits", + "serde", + "serde_derive", + "serde_json", + "solana-define-syscall", + "solana-pubkey", + "wasm-bindgen", +] + +[[package]] +name = "solana-instructions-sysvar" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0e85a6fad5c2d0c4f5b91d34b8ca47118fc593af706e523cdbedf846a954f57" +dependencies = [ + "bitflags", + "solana-account-info", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-sanitize", + "solana-sdk-ids", + "solana-serialize-utils", + "solana-sysvar-id", +] + +[[package]] +name = "solana-invoke" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f5693c6de226b3626658377168b0184e94e8292ff16e3d31d4766e65627565" +dependencies = [ + "solana-account-info", + "solana-define-syscall", + "solana-instruction", + "solana-program-entrypoint", + "solana-stable-layout", +] + +[[package]] +name = "solana-keccak-hasher" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aeb957fbd42a451b99235df4942d96db7ef678e8d5061ef34c9b34cae12f79" +dependencies = [ + "sha3", + "solana-define-syscall", + "solana-hash", + "solana-sanitize", +] + +[[package]] +name = "solana-last-restart-slot" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6360ac2fdc72e7463565cd256eedcf10d7ef0c28a1249d261ec168c1b55cdd" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-loader-v2-interface" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8ab08006dad78ae7cd30df8eea0539e207d08d91eaefb3e1d49a446e1c49654" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-loader-v3-interface" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa4be76cfa9afd84ca2f35ebc09f0da0f0092935ccdac0595d98447f259538c2" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-loader-v4-interface" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "706a777242f1f39a83e2a96a2a6cb034cb41169c6ecbee2cf09cb873d9659e7e" +dependencies = [ + "serde", + "serde_bytes", + "serde_derive", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-system-interface", +] + +[[package]] +name = "solana-message" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1796aabce376ff74bf89b78d268fa5e683d7d7a96a0a4e4813ec34de49d5314b" +dependencies = [ + "bincode", + "blake3", + "lazy_static", + "serde", + "serde_derive", + "solana-bincode", + "solana-hash", + "solana-instruction", + "solana-pubkey", + "solana-sanitize", + "solana-sdk-ids", + "solana-short-vec", + "solana-system-interface", + "solana-transaction-error", + "wasm-bindgen", +] + +[[package]] +name = "solana-msg" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36a1a14399afaabc2781a1db09cb14ee4cc4ee5c7a5a3cfcc601811379a8092" +dependencies = [ + "solana-define-syscall", +] + +[[package]] +name = "solana-native-token" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61515b880c36974053dd499c0510066783f0cc6ac17def0c7ef2a244874cf4a9" + +[[package]] +name = "solana-nonce" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "703e22eb185537e06204a5bd9d509b948f0066f2d1d814a6f475dafb3ddf1325" +dependencies = [ + "serde", + "serde_derive", + "solana-fee-calculator", + "solana-hash", + "solana-pubkey", + "solana-sha256-hasher", +] + +[[package]] +name = "solana-program" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "586469467e93ceb79048f8d8e3a619bf61d05396ee7de95cb40280301a589d05" +dependencies = [ + "bincode", + "blake3", + "borsh 0.10.4", + "borsh 1.5.7", + "bs58 0.5.1", + "bytemuck", + "console_error_panic_hook", + "console_log", + "getrandom 0.2.16", + "lazy_static", + "log", + "memoffset", + "num-bigint", + "num-derive 0.4.2", + "num-traits", + "rand 0.8.5", + "serde", + "serde_bytes", + "serde_derive", + "solana-account-info", + "solana-address-lookup-table-interface", + "solana-atomic-u64", + "solana-big-mod-exp", + "solana-bincode", + "solana-blake3-hasher", + "solana-borsh", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-define-syscall", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-example-mocks", + "solana-feature-gate-interface", + "solana-fee-calculator", + "solana-hash", + "solana-instruction", + "solana-instructions-sysvar", + "solana-keccak-hasher", + "solana-last-restart-slot", + "solana-loader-v2-interface", + "solana-loader-v3-interface", + "solana-loader-v4-interface", + "solana-message", + "solana-msg", + "solana-native-token", + "solana-nonce", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sanitize", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-secp256k1-recover", + "solana-serde-varint", + "solana-serialize-utils", + "solana-sha256-hasher", + "solana-short-vec", + "solana-slot-hashes", + "solana-slot-history", + "solana-stable-layout", + "solana-stake-interface", + "solana-system-interface", + "solana-sysvar", + "solana-sysvar-id", + "solana-vote-interface", + "thiserror 2.0.17", + "wasm-bindgen", +] + +[[package]] +name = "solana-program-entrypoint" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ce041b1a0ed275290a5008ee1a4a6c48f5054c8a3d78d313c08958a06aedbd" +dependencies = [ + "solana-account-info", + "solana-msg", + "solana-program-error", + "solana-pubkey", +] + +[[package]] +name = "solana-program-error" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ee2e0217d642e2ea4bee237f37bd61bb02aec60da3647c48ff88f6556ade775" +dependencies = [ + "borsh 1.5.7", + "num-traits", + "serde", + "serde_derive", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-pubkey", +] + +[[package]] +name = "solana-program-memory" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a5426090c6f3fd6cfdc10685322fede9ca8e5af43cd6a59e98bfe4e91671712" +dependencies = [ + "solana-define-syscall", +] + +[[package]] +name = "solana-program-option" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc677a2e9bc616eda6dbdab834d463372b92848b2bfe4a1ed4e4b4adba3397d0" + +[[package]] +name = "solana-program-pack" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "319f0ef15e6e12dc37c597faccb7d62525a509fec5f6975ecb9419efddeb277b" +dependencies = [ + "solana-program-error", +] + +[[package]] +name = "solana-pubkey" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b62adb9c3261a052ca1f999398c388f1daf558a1b492f60a6d9e64857db4ff1" +dependencies = [ + "borsh 0.10.4", + "borsh 1.5.7", + "bytemuck", + "bytemuck_derive", + "curve25519-dalek", + "five8", + "five8_const", + "getrandom 0.2.16", + "js-sys", + "num-traits", + "serde", + "serde_derive", + "solana-atomic-u64", + "solana-decode-error", + "solana-define-syscall", + "solana-sanitize", + "solana-sha256-hasher", + "wasm-bindgen", +] + +[[package]] +name = "solana-rent" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1aea8fdea9de98ca6e8c2da5827707fb3842833521b528a713810ca685d2480" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-sysvar-id", +] + +[[package]] +name = "solana-sanitize" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61f1bc1357b8188d9c4a3af3fc55276e56987265eb7ad073ae6f8180ee54cecf" + +[[package]] +name = "solana-sdk-ids" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5d8b9cc68d5c88b062a33e23a6466722467dde0035152d8fb1afbcdf350a5f" +dependencies = [ + "solana-pubkey", ] [[package]] name = "solana-sdk-macro" -version = "1.16.25" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e0e0e7ee984b0f9179a1d4f4e9e67ce675de2324b5a98b61d2bdb61be3c19bb" +checksum = "86280da8b99d03560f6ab5aca9de2e38805681df34e0bb8f238e69b29433b9df" dependencies = [ - "bs58 0.4.0", + "bs58 0.5.1", "proc-macro2", "quote", - "rustversion", - "syn 2.0.48", + "syn 2.0.109", +] + +[[package]] +name = "solana-secp256k1-recover" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa3120b6cdaa270f39444f5093a90a7b03d296d362878f7a6991d6de3bbe496" +dependencies = [ + "libsecp256k1", + "solana-define-syscall", + "thiserror 2.0.17", +] + +[[package]] +name = "solana-security-txt" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "468aa43b7edb1f9b7b7b686d5c3aeb6630dc1708e86e31343499dd5c4d775183" + +[[package]] +name = "solana-seed-derivable" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3beb82b5adb266c6ea90e5cf3967235644848eac476c5a1f2f9283a143b7c97f" +dependencies = [ + "solana-derivation-path", +] + +[[package]] +name = "solana-seed-phrase" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36187af2324f079f65a675ec22b31c24919cb4ac22c79472e85d819db9bbbc15" +dependencies = [ + "hmac", + "pbkdf2", + "sha2 0.10.9", +] + +[[package]] +name = "solana-serde-varint" +version = "2.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a7e155eba458ecfb0107b98236088c3764a09ddf0201ec29e52a0be40857113" +dependencies = [ + "serde", +] + +[[package]] +name = "solana-serialize-utils" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "817a284b63197d2b27afdba829c5ab34231da4a9b4e763466a003c40ca4f535e" +dependencies = [ + "solana-instruction", + "solana-pubkey", + "solana-sanitize", +] + +[[package]] +name = "solana-sha256-hasher" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa3feb32c28765f6aa1ce8f3feac30936f16c5c3f7eb73d63a5b8f6f8ecdc44" +dependencies = [ + "sha2 0.10.9", + "solana-define-syscall", + "solana-hash", +] + +[[package]] +name = "solana-short-vec" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c54c66f19b9766a56fa0057d060de8378676cb64987533fa088861858fc5a69" +dependencies = [ + "serde", +] + +[[package]] +name = "solana-signature" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64c8ec8e657aecfc187522fc67495142c12f35e55ddeca8698edbb738b8dbd8c" +dependencies = [ + "five8", + "solana-sanitize", +] + +[[package]] +name = "solana-signer" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c41991508a4b02f021c1342ba00bcfa098630b213726ceadc7cb032e051975b" +dependencies = [ + "solana-pubkey", + "solana-signature", + "solana-transaction-error", +] + +[[package]] +name = "solana-slot-hashes" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8691982114513763e88d04094c9caa0376b867a29577939011331134c301ce" +dependencies = [ + "serde", + "serde_derive", + "solana-hash", + "solana-sdk-ids", + "solana-sysvar-id", +] + +[[package]] +name = "solana-slot-history" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ccc1b2067ca22754d5283afb2b0126d61eae734fc616d23871b0943b0d935e" +dependencies = [ + "bv", + "serde", + "serde_derive", + "solana-sdk-ids", + "solana-sysvar-id", +] + +[[package]] +name = "solana-stable-layout" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f14f7d02af8f2bc1b5efeeae71bc1c2b7f0f65cd75bcc7d8180f2c762a57f54" +dependencies = [ + "solana-instruction", + "solana-pubkey", +] + +[[package]] +name = "solana-stake-interface" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5269e89fde216b4d7e1d1739cf5303f8398a1ff372a81232abbee80e554a838c" +dependencies = [ + "borsh 0.10.4", + "borsh 1.5.7", + "num-traits", + "serde", + "serde_derive", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-program-error", + "solana-pubkey", + "solana-system-interface", + "solana-sysvar-id", +] + +[[package]] +name = "solana-system-interface" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94d7c18cb1a91c6be5f5a8ac9276a1d7c737e39a21beba9ea710ab4b9c63bc90" +dependencies = [ + "js-sys", + "num-traits", + "serde", + "serde_derive", + "solana-decode-error", + "solana-instruction", + "solana-pubkey", + "wasm-bindgen", +] + +[[package]] +name = "solana-sysvar" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c3595f95069f3d90f275bb9bd235a1973c4d059028b0a7f81baca2703815db" +dependencies = [ + "base64 0.22.1", + "bincode", + "bytemuck", + "bytemuck_derive", + "lazy_static", + "serde", + "serde_derive", + "solana-account-info", + "solana-clock", + "solana-define-syscall", + "solana-epoch-rewards", + "solana-epoch-schedule", + "solana-fee-calculator", + "solana-hash", + "solana-instruction", + "solana-instructions-sysvar", + "solana-last-restart-slot", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-pubkey", + "solana-rent", + "solana-sanitize", + "solana-sdk-ids", + "solana-sdk-macro", + "solana-slot-hashes", + "solana-slot-history", + "solana-stake-interface", + "solana-sysvar-id", +] + +[[package]] +name = "solana-sysvar-id" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5762b273d3325b047cfda250787f8d796d781746860d5d0a746ee29f3e8812c1" +dependencies = [ + "solana-pubkey", + "solana-sdk-ids", +] + +[[package]] +name = "solana-transaction-error" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a9dc8fdb61c6088baab34fc3a8b8473a03a7a5fd404ed8dd502fa79b67cb1" +dependencies = [ + "solana-instruction", + "solana-sanitize", +] + +[[package]] +name = "solana-vote-interface" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b80d57478d6599d30acc31cc5ae7f93ec2361a06aefe8ea79bc81739a08af4c3" +dependencies = [ + "bincode", + "num-derive 0.4.2", + "num-traits", + "serde", + "serde_derive", + "solana-clock", + "solana-decode-error", + "solana-hash", + "solana-instruction", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-serde-varint", + "solana-serialize-utils", + "solana-short-vec", + "solana-system-interface", ] [[package]] -name = "solana-security-txt" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e0461f3afb29d8591300b3dd09b5472b3772d65688a2826ad960b8c0d5fa605" - -[[package]] -name = "solana-zk-token-sdk" -version = "1.16.25" +name = "solana-zk-sdk" +version = "2.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1457c85ab70a518438b9ac2b0c56037b9f6693060dfb617bbb93c7116e4f0c22" +checksum = "97b9fc6ec37d16d0dccff708ed1dd6ea9ba61796700c3bb7c3b401973f10f63b" dependencies = [ "aes-gcm-siv", - "base64 0.21.7", + "base64 0.22.1", "bincode", "bytemuck", - "byteorder", + "bytemuck_derive", "curve25519-dalek", - "getrandom 0.1.16", - "itertools 0.10.5", - "lazy_static", + "itertools 0.12.1", + "js-sys", "merlin", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", - "rand 0.7.3", + "rand 0.8.5", "serde", + "serde_derive", "serde_json", - "sha3 0.9.1", - "solana-program", - "solana-sdk", + "sha3", + "solana-derivation-path", + "solana-instruction", + "solana-pubkey", + "solana-sdk-ids", + "solana-seed-derivable", + "solana-seed-phrase", + "solana-signature", + "solana-signer", "subtle", - "thiserror", + "thiserror 2.0.17", + "wasm-bindgen", "zeroize", ] [[package]] name = "spl-associated-token-account" -version = "2.2.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "385e31c29981488f2820b2022d8e731aae3b02e6e18e2fd854e4c9a94dc44fc3" +checksum = "ae179d4a26b3c7a20c839898e6aed84cb4477adf108a366c95532f058aea041b" dependencies = [ - "assert_matches", - "borsh 0.10.3", - "num-derive 0.4.1", + "borsh 1.5.7", + "num-derive 0.4.2", "num-traits", "solana-program", - "spl-token 4.0.0", + "spl-associated-token-account-client", + "spl-token", "spl-token-2022", - "thiserror", + "thiserror 2.0.17", +] + +[[package]] +name = "spl-associated-token-account-client" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f8349dbcbe575f354f9a533a21f272f3eb3808a49e2fdc1c34393b88ba76cb" +dependencies = [ + "solana-instruction", + "solana-pubkey", ] [[package]] name = "spl-discriminator" -version = "0.1.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" +checksum = "a7398da23554a31660f17718164e31d31900956054f54f52d5ec1be51cb4f4b3" dependencies = [ "bytemuck", - "solana-program", + "solana-program-error", + "solana-sha256-hasher", "spl-discriminator-derive", ] [[package]] name = "spl-discriminator-derive" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fadbefec4f3c678215ca72bd71862697bb06b41fd77c0088902dd3203354387b" +checksum = "d9e8418ea6269dcfb01c712f0444d2c75542c04448b480e87de59d2865edc750" dependencies = [ "quote", "spl-discriminator-syn", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] name = "spl-discriminator-syn" -version = "0.1.1" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e5f2044ca42c8938d54d1255ce599c79a1ffd86b677dfab695caa20f9ffc3f2" +checksum = "5d1dbc82ab91422345b6df40a79e2b78c7bce1ebb366da323572dd60b7076b67" dependencies = [ "proc-macro2", "quote", - "sha2 0.10.8", - "syn 2.0.48", - "thiserror", + "sha2 0.10.9", + "syn 2.0.109", + "thiserror 1.0.69", +] + +[[package]] +name = "spl-elgamal-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65edfeed09cd4231e595616aa96022214f9c9d2be02dea62c2b30d5695a6833a" +dependencies = [ + "bytemuck", + "solana-account-info", + "solana-cpi", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-system-interface", + "solana-sysvar", + "solana-zk-sdk", + "spl-pod", + "spl-token-confidential-transfer-proof-extraction", ] [[package]] name = "spl-memo" -version = "4.0.0" +version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0f180b03318c3dbab3ef4e1e4d46d5211ae3c780940dd0a28695aba4b59a75a" +checksum = "9f09647c0974e33366efeb83b8e2daebb329f0420149e74d3a4bd2c08cf9f7cb" dependencies = [ - "solana-program", + "solana-account-info", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-pubkey", ] [[package]] name = "spl-pod" -version = "0.1.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2881dddfca792737c0706fa0175345ab282b1b0879c7d877bad129645737c079" +checksum = "d994afaf86b779104b4a95ba9ca75b8ced3fdb17ee934e38cb69e72afbe17799" dependencies = [ - "borsh 0.10.3", + "borsh 1.5.7", "bytemuck", - "solana-program", - "solana-zk-token-sdk", - "spl-program-error", + "bytemuck_derive", + "num-derive 0.4.2", + "num-traits", + "solana-decode-error", + "solana-msg", + "solana-program-error", + "solana-program-option", + "solana-pubkey", + "solana-zk-sdk", + "thiserror 2.0.17", ] [[package]] name = "spl-program-error" -version = "0.3.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "249e0318493b6bcf27ae9902600566c689b7dfba9f1bdff5893e92253374e78c" +checksum = "9cdebc8b42553070b75aa5106f071fef2eb798c64a7ec63375da4b1f058688c6" dependencies = [ - "num-derive 0.4.1", + "num-derive 0.4.2", "num-traits", - "solana-program", + "solana-decode-error", + "solana-msg", + "solana-program-error", "spl-program-error-derive", - "thiserror", + "thiserror 2.0.17", ] [[package]] name = "spl-program-error-derive" -version = "0.3.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5269c8e868da17b6552ef35a51355a017bd8e0eae269c201fef830d35fa52c" +checksum = "2a2539e259c66910d78593475540e8072f0b10f0f61d7607bbf7593899ed52d0" dependencies = [ "proc-macro2", "quote", - "sha2 0.10.8", - "syn 2.0.48", + "sha2 0.10.9", + "syn 2.0.109", ] [[package]] name = "spl-tlv-account-resolution" -version = "0.4.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "062e148d3eab7b165582757453632ffeef490c02c86a48bfdb4988f63eefb3b9" +checksum = "1408e961215688715d5a1063cbdcf982de225c45f99c82b4f7d7e1dd22b998d7" dependencies = [ "bytemuck", - "solana-program", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", "spl-discriminator", "spl-pod", "spl-program-error", "spl-type-length-value", + "thiserror 2.0.17", ] [[package]] name = "spl-token" -version = "3.5.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e85e168a785e82564160dcb87b2a8e04cee9bfd1f4d488c729d53d6a4bd300d" +checksum = "053067c6a82c705004f91dae058b11b4780407e9ccd6799dc9e7d0fab5f242da" dependencies = [ "arrayref", "bytemuck", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", - "num_enum 0.5.9", - "solana-program", - "thiserror", + "num_enum", + "solana-account-info", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-sysvar", + "thiserror 2.0.17", ] [[package]] -name = "spl-token" -version = "4.0.0" +name = "spl-token-2022" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08459ba1b8f7c1020b4582c4edf0f5c7511a5e099a7a97570c9698d4f2337060" +checksum = "31f0dfbb079eebaee55e793e92ca5f433744f4b71ee04880bfd6beefba5973e5" dependencies = [ "arrayref", "bytemuck", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", - "num_enum 0.6.1", - "solana-program", - "thiserror", + "num_enum", + "solana-account-info", + "solana-clock", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-native-token", + "solana-program-entrypoint", + "solana-program-error", + "solana-program-memory", + "solana-program-option", + "solana-program-pack", + "solana-pubkey", + "solana-rent", + "solana-sdk-ids", + "solana-security-txt", + "solana-system-interface", + "solana-sysvar", + "solana-zk-sdk", + "spl-elgamal-registry", + "spl-memo", + "spl-pod", + "spl-token", + "spl-token-confidential-transfer-ciphertext-arithmetic", + "spl-token-confidential-transfer-proof-extraction", + "spl-token-confidential-transfer-proof-generation", + "spl-token-group-interface", + "spl-token-metadata-interface", + "spl-transfer-hook-interface", + "spl-type-length-value", + "thiserror 2.0.17", ] [[package]] -name = "spl-token-2022" -version = "0.9.0" +name = "spl-token-confidential-transfer-ciphertext-arithmetic" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4abf34a65ba420584a0c35f3903f8d727d1f13ababbdc3f714c6b065a686e86" +checksum = "cddd52bfc0f1c677b41493dafa3f2dbbb4b47cf0990f08905429e19dc8289b35" +dependencies = [ + "base64 0.22.1", + "bytemuck", + "solana-curve25519", + "solana-zk-sdk", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-extraction" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe2629860ff04c17bafa9ba4bed8850a404ecac81074113e1f840dbd0ebb7bd6" +dependencies = [ + "bytemuck", + "solana-account-info", + "solana-curve25519", + "solana-instruction", + "solana-instructions-sysvar", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "solana-sdk-ids", + "solana-zk-sdk", + "spl-pod", + "thiserror 2.0.17", +] + +[[package]] +name = "spl-token-confidential-transfer-proof-generation" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa27b9174bea869a7ebf31e0be6890bce90b1a4288bc2bbf24bd413f80ae3fde" +dependencies = [ + "curve25519-dalek", + "solana-zk-sdk", + "thiserror 2.0.17", +] + +[[package]] +name = "spl-token-group-interface" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5597b4cd76f85ce7cd206045b7dc22da8c25516573d42d267c8d1fd128db5129" dependencies = [ - "arrayref", "bytemuck", - "num-derive 0.4.1", + "num-derive 0.4.2", "num-traits", - "num_enum 0.7.2", - "solana-program", - "solana-zk-token-sdk", - "spl-memo", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", + "spl-discriminator", "spl-pod", - "spl-token 4.0.0", - "spl-token-metadata-interface", - "spl-transfer-hook-interface", - "spl-type-length-value", - "thiserror", + "thiserror 2.0.17", ] [[package]] name = "spl-token-metadata-interface" -version = "0.2.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" +checksum = "304d6e06f0de0c13a621464b1fd5d4b1bebf60d15ca71a44d3839958e0da16ee" dependencies = [ - "borsh 0.10.3", - "solana-program", + "borsh 1.5.7", + "num-derive 0.4.2", + "num-traits", + "solana-borsh", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", "spl-discriminator", "spl-pod", - "spl-program-error", "spl-type-length-value", + "thiserror 2.0.17", ] [[package]] name = "spl-transfer-hook-interface" -version = "0.3.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051d31803f873cabe71aec3c1b849f35248beae5d19a347d93a5c9cccc5d5a9b" +checksum = "a7e905b849b6aba63bde8c4badac944ebb6c8e6e14817029cbe1bc16829133bd" dependencies = [ "arrayref", "bytemuck", - "solana-program", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-cpi", + "solana-decode-error", + "solana-instruction", + "solana-msg", + "solana-program-error", + "solana-pubkey", "spl-discriminator", "spl-pod", "spl-program-error", "spl-tlv-account-resolution", "spl-type-length-value", + "thiserror 2.0.17", ] [[package]] name = "spl-type-length-value" -version = "0.3.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" +checksum = "d417eb548214fa822d93f84444024b4e57c13ed6719d4dcc68eec24fb481e9f5" dependencies = [ "bytemuck", - "solana-program", + "num-derive 0.4.2", + "num-traits", + "solana-account-info", + "solana-decode-error", + "solana-msg", + "solana-program-error", "spl-discriminator", "spl-pod", - "spl-program-error", + "thiserror 2.0.17", ] [[package]] @@ -2828,24 +3188,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "subtle" -version = "2.4.1" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "switchboard" version = "0.1.0" dependencies = [ "anchor-lang", - "base64 0.13.0", + "base64 0.13.1", ] [[package]] @@ -2853,45 +3207,33 @@ name = "switchboard-on-demand" version = "0.1.0" dependencies = [ "anchor-lang", - "base64 0.13.0", + "base64 0.13.1", "bytemuck", "solana-program", ] [[package]] name = "syn" -version = "1.0.92" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "syn" -version = "2.0.48" +version = "2.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "syn_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" -dependencies = [ - "proc-macro-error", - "proc-macro2", - "quote", - "syn 2.0.48", -] - [[package]] name = "tap" version = "1.0.1" @@ -2899,58 +3241,50 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] -name = "termcolor" -version = "1.2.0" +name = "thiserror" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "winapi-util", + "thiserror-impl 1.0.69", ] [[package]] name = "thiserror" -version = "1.0.56" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" +checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.17", ] [[package]] name = "thiserror-impl" -version = "1.0.56" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] -name = "tiny-bip39" -version = "0.8.2" +name = "thiserror-impl" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d" +checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" dependencies = [ - "anyhow", - "hmac 0.8.1", - "once_cell", - "pbkdf2 0.4.0", - "rand 0.7.3", - "rustc-hash", - "sha2 0.9.9", - "thiserror", - "unicode-normalization", - "wasm-bindgen", - "zeroize", + "proc-macro2", + "quote", + "syn 2.0.109", ] [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" dependencies = [ "tinyvec_macros", ] @@ -2972,74 +3306,133 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.8" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" dependencies = [ "serde", ] [[package]] -name = "typenum" -version = "1.15.0" +name = "toml" +version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime 0.6.11", + "toml_edit 0.22.27", +] [[package]] -name = "ucd-trie" -version = "0.1.4" +name = "toml_datetime" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] [[package]] -name = "uint" -version = "0.9.1" +name = "toml_datetime" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6470ab50f482bde894a037a57064480a246dbfdd5960bd65a44824693f08da5f" +checksum = "f2cdb639ebbc97961c51720f858597f7f24c4fc295327923af55b74c3c724533" dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", + "serde_core", ] [[package]] -name = "unicode-ident" -version = "1.0.8" +name = "toml_edit" +version = "0.22.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime 0.6.11", + "toml_write", + "winnow", +] [[package]] -name = "unicode-normalization" -version = "0.1.22" +name = "toml_edit" +version = "0.23.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "6485ef6d0d9b5d0ec17244ff7eb05310113c3f316f2d14200d4de56b3cb98f8d" dependencies = [ - "tinyvec", + "indexmap", + "toml_datetime 0.7.3", + "toml_parser", + "winnow", ] [[package]] -name = "unicode-segmentation" -version = "1.7.1" +name = "toml_parser" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" +checksum = "c0cbe268d35bdb4bb5a56a2de88d0ad0eb70af5384a99d648cd4b3d04039800e" +dependencies = [ + "winnow", +] [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "typenum" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" + +[[package]] +name = "unicode-segmentation" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "universal-hash" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" dependencies = [ - "generic-array", + "crypto-common", "subtle", ] +[[package]] +name = "unsize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fa7a7a734c1a5664a662ddcea0b6c9472a21da8888c957c7f1eaa09dba7a939" +dependencies = [ + "autocfg", +] + [[package]] name = "uriparse" version = "0.6.4" @@ -3052,15 +3445,19 @@ dependencies = [ [[package]] name = "uuid" -version = "1.11.0" +version = "1.18.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" @@ -3070,40 +3467,28 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasm-bindgen" -version = "0.2.90" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" dependencies = [ "cfg-if", - "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.90" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" -dependencies = [ - "bumpalo", - "log", "once_cell", - "proc-macro2", - "quote", - "syn 2.0.48", + "rustversion", + "wasm-bindgen-macro", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.90" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3111,114 +3496,59 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.90" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" dependencies = [ + "bumpalo", "proc-macro2", "quote", - "syn 2.0.48", - "wasm-bindgen-backend", + "syn 2.0.109", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.90" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "3a1f95c0d03a47f4ae1f7a64643a6bb97465d9b740f0fa8f90ea33915c99a9a1" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-sys" -version = "0.36.1" +name = "winnow" +version = "0.7.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +checksum = "21a0236b59786fed61e2a80582dd500fe61f18b5dca67a4a067d0bc9039339cf" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "memchr", ] -[[package]] -name = "windows_aarch64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" - -[[package]] -name = "windows_i686_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" - -[[package]] -name = "windows_i686_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.36.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" - [[package]] name = "without-alloc" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e34736feff52a0b3e5680927e947a4d8fac1f0b80dc8120b080dd8de24d75e2" +checksum = "375db0478b203b950ef10d1cce23cdbe5f30c2454fd9e7673ff56656df23adbb" dependencies = [ "alloc-traits", + "unsize", ] [[package]] @@ -3232,29 +3562,29 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] [[package]] name = "zeroize" -version = "1.3.0" +version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" dependencies = [ "zeroize_derive", ] @@ -3267,5 +3597,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.109", ] diff --git a/Cargo.toml b/Cargo.toml index f686c06993..6129c26246 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ resolver = "2" [profile.release] lto = "fat" codegen-units = 1 +overflow-checks = true [profile.release.build-override] opt-level = 3 diff --git a/bun.lock b/bun.lock index 865ade9e6e..a2652fec3a 100644 --- a/bun.lock +++ b/bun.lock @@ -5,8 +5,8 @@ "dependencies": { "@ellipsis-labs/phoenix-sdk": "1.4.2", "@pythnetwork/pyth-solana-receiver": "0.8.0", - "@switchboard-xyz/common": "3.0.14", - "@switchboard-xyz/on-demand": "2.4.1", + "@switchboard-xyz/common": "5.5.0", + "@switchboard-xyz/on-demand": "3.7.3", "anchor-bankrun": "0.3.0", "chai-bn": "0.2.2", "csvtojson": "2.0.10", @@ -19,8 +19,8 @@ "zstddec": "0.1.0", }, "devDependencies": { - "@coral-xyz/anchor": "0.29.0", - "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", + "@coral-xyz/anchor": "npm:@coral-xyz/anchor@0.31.1", + "@coral-xyz/anchor-29": "npm:@coral-xyz/anchor@0.29.0", "@project-serum/common": "0.0.1-beta.3", "@project-serum/serum": "0.13.65", "@pythnetwork/client": "2.21.0", @@ -44,49 +44,42 @@ }, }, "overrides": { + "debug": "<4.4.2", + "supports-color": "7.2.0", "ansi-regex": "5.0.1", + "color-convert": "<3.1.1", "ansi-styles": "4.3.0", - "backslash": "<0.2.1", + "wrap-ansi": "7.0.0", "chalk": "4.1.2", - "chalk-template": "<1.1.1", - "color-convert": "<3.1.1", - "color-name": "<2.0.1", - "color-string": "<2.1.1", - "debug": "<4.4.2", - "error-ex": "<1.3.3", - "has-ansi": "<6.0.1", - "is-arrayish": "<0.3.3", - "simple-swizzle": "<0.2.3", - "slice-ansi": "3.0.0", "strip-ansi": "6.0.1", - "supports-color": "7.2.0", - "supports-hyperlinks": "<4.1.1", - "wrap-ansi": "7.0.0", + "color-name": "<2.0.1", }, "packages": { - "@babel/runtime": ["@babel/runtime@7.28.3", "", {}, "sha512-9uIQ10o0WGdpP6GDhXcdOJPJuDgFtIDtN/9+ArJQ2NAfAmiuhTQdzkaTGR33v43GYS2UrSA0eX2pPPHoFVvpxA=="], + "@babel/runtime": ["@babel/runtime@7.28.4", "", {}, "sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ=="], + + "@coral-xyz/anchor": ["@coral-xyz/anchor@0.31.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.31.1", "@coral-xyz/borsh": "^0.31.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.69.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA=="], - "@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@coral-xyz/anchor-29": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], - "@coral-xyz/anchor-30": ["@coral-xyz/anchor@0.30.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.30.1", "@coral-xyz/borsh": "^0.30.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ=="], + "@coral-xyz/anchor-31": ["@coral-xyz/anchor@0.31.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.31.1", "@coral-xyz/borsh": "^0.31.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.69.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA=="], - "@coral-xyz/anchor-errors": ["@coral-xyz/anchor-errors@0.30.1", "", {}, "sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ=="], + "@coral-xyz/anchor-errors": ["@coral-xyz/anchor-errors@0.31.1", "", {}, "sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ=="], - "@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + "@coral-xyz/borsh": ["@coral-xyz/borsh@0.31.1", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.69.0" } }, "sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw=="], "@ellipsis-labs/phoenix-sdk": ["@ellipsis-labs/phoenix-sdk@1.4.2", "", { "dependencies": { "@metaplex-foundation/beet": "^0.7.1", "@metaplex-foundation/rustbin": "^0.3.1", "@metaplex-foundation/solita": "^0.12.2", "@solana/spl-token": "^0.3.7", "@types/node": "^18.11.13", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^5.0.0" } }, "sha512-7Rf2aWHZwuLX8jcrNSRUDf2aHuBnBzsDBN4GzClTdJYVGo4uQzf9ixju5J3apZ+xkQ6qvrEVYOXtogdgOhJFvw=="], - "@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.7.0", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-dyybb3AcajC7uha6CvhdVRJqaKyn7w2YKqKyAN37NKYgZT36w+iRb0Dymmc5qEJ549c/S31cMMSFd75bteCpCw=="], + "@eslint-community/eslint-utils": ["@eslint-community/eslint-utils@4.9.0", "", { "dependencies": { "eslint-visitor-keys": "^3.4.3" }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "sha512-ayVFHdtZ+hsq1t2Dy24wCmGXGe4q9Gu3smhLYALJrr473ZH27MsnSL+LKUlimp4BWJqMDMLmPpx/Q9R3OAlL4g=="], - "@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.1", "", {}, "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ=="], + "@eslint-community/regexpp": ["@eslint-community/regexpp@4.12.2", "", {}, "sha512-EriSTlt5OC9/7SXkRSCAhfSxxoSUgBm33OH+IkwbdpgoqsSsUg7y3uh+IICI/Qg4BBWr3U2i39RpmycbxMq4ew=="], "@eslint/eslintrc": ["@eslint/eslintrc@2.1.4", "", { "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", "espree": "^9.6.0", "globals": "^13.19.0", "ignore": "^5.2.0", "import-fresh": "^3.2.1", "js-yaml": "^4.1.0", "minimatch": "^3.1.2", "strip-json-comments": "^3.1.1" } }, "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ=="], "@eslint/js": ["@eslint/js@8.57.0", "", {}, "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g=="], - "@grpc/grpc-js": ["@grpc/grpc-js@1.13.4", "", { "dependencies": { "@grpc/proto-loader": "^0.7.13", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-GsFaMXCkMqkKIvwCQjCrwH+GHbPKBjhwo/8ZuUkWHqbI73Kky9I+pQltrlT0+MWpedCoosda53lgjYfyEPgxBg=="], + "@grpc/grpc-js": ["@grpc/grpc-js@1.14.2", "", { "dependencies": { "@grpc/proto-loader": "^0.8.0", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-QzVUtEFyu05UNx2xr0fCQmStUO17uVQhGNowtxs00IgTZT6/W2PBLfUkj30s0FKJ29VtTa3ArVNIhNP6akQhqA=="], - "@grpc/proto-loader": ["@grpc/proto-loader@0.7.15", "", { "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", "protobufjs": "^7.2.5", "yargs": "^17.7.2" }, "bin": { "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" } }, "sha512-tMXdRCfYVixjuFK+Hk0Q1s38gV9zDiDJfWL3h1rv4Qc39oILCu1TRTDt7+fGUI8K4G1Fj125Hx/ru3azECWTyQ=="], + "@grpc/proto-loader": ["@grpc/proto-loader@0.8.0", "", { "dependencies": { "lodash.camelcase": "^4.3.0", "long": "^5.0.0", "protobufjs": "^7.5.3", "yargs": "^17.7.2" }, "bin": { "proto-loader-gen-types": "build/bin/proto-loader-gen-types.js" } }, "sha512-rc1hOQtjIWGxcxpb9aHAfLpIctjEnsDehj0DAiVfBlmT84uvR0uUtN2hEi/ecvWVjXUGf5qPF4qEgiLOx1YIMQ=="], "@humanwhocodes/config-array": ["@humanwhocodes/config-array@0.11.14", "", { "dependencies": { "@humanwhocodes/object-schema": "^2.0.2", "debug": "^4.3.1", "minimatch": "^3.0.5" } }, "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg=="], @@ -152,11 +145,11 @@ "@pythnetwork/price-service-client": ["@pythnetwork/price-service-client@1.9.0", "", { "dependencies": { "@pythnetwork/price-service-sdk": "*", "@types/ws": "^8.5.3", "axios": "^1.5.1", "axios-retry": "^3.8.0", "isomorphic-ws": "^4.0.1", "ts-log": "^2.2.4", "ws": "^8.6.0" } }, "sha512-SLm3IFcfmy9iMqHeT4Ih6qMNZhJEefY14T9yTlpsH2D/FE5+BaGGnfcexUifVlfH6M7mwRC4hEFdNvZ6ebZjJg=="], - "@pythnetwork/price-service-sdk": ["@pythnetwork/price-service-sdk@1.8.0", "", { "dependencies": { "bn.js": "^5.2.1" } }, "sha512-tFZ1thj3Zja06DzPIX2dEWSi7kIfIyqreoywvw5NQ3Z1pl5OJHQGMEhxt6Li3UCGSp2ooYZS9wl8/8XfrfrNSA=="], + "@pythnetwork/price-service-sdk": ["@pythnetwork/price-service-sdk@1.9.0", "", { "dependencies": { "bn.js": "^5.2.1" } }, "sha512-DX8N4VUqllyervqnCx/Z6Tjz130EcoczYYa96F1YjlbZf0rFyU8VCzX1yAf60q+b8EVcVFVeSkdzJTZD3n6+jQ=="], "@pythnetwork/pyth-solana-receiver": ["@pythnetwork/pyth-solana-receiver@0.8.0", "", { "dependencies": { "@coral-xyz/anchor": "^0.29.0", "@noble/hashes": "^1.4.0", "@pythnetwork/price-service-sdk": ">=1.6.0", "@pythnetwork/solana-utils": "*", "@solana/web3.js": "^1.90.0" } }, "sha512-5lhLtggAqsiHtffTPM8vcKJmhBdxzidBmiNNUlqPyg9XmhZ4Z+roY0dfzluEoX5xer9rEA1ThsBpX0bG1DRIGA=="], - "@pythnetwork/solana-utils": ["@pythnetwork/solana-utils@0.5.0", "", { "dependencies": { "@coral-xyz/anchor": "^0.29.0", "@solana/web3.js": "^1.90.0", "bs58": "^5.0.0", "jito-ts": "^3.0.1", "ts-log": "^2.2.7" } }, "sha512-6F99H/FiLNcleLlagBbM5YKPEp7QGo+bk5IUf+PPfEdk64sflRVq74M4rRghm+LpK4TuTbCA2Gh4aKJUZLG08Q=="], + "@pythnetwork/solana-utils": ["@pythnetwork/solana-utils@0.6.0", "", { "dependencies": { "@coral-xyz/anchor": "^0.29.0", "@solana/web3.js": "^1.90.0", "bs58": "^5.0.0", "jito-ts": "^3.0.1", "ts-log": "^2.2.7" } }, "sha512-dkjenNL7fiLHnJoBBxZh+NC5CKeAUKJKhnuKQpR8dW3oX44cF1MyMaY3j1x+8I9GvaXa4jhoudriiJKBfYOZfQ=="], "@solana/buffer-layout": ["@solana/buffer-layout@4.0.1", "", { "dependencies": { "buffer": "~6.0.3" } }, "sha512-E1ImOIAD1tBZFRdjeM4/pzTiTApC0AOBGwyAMS4fwIodCWArzJ3DWdoh8cKxeFM2fElkxBh2Aqts1BPC373rHA=="], @@ -164,7 +157,7 @@ "@solana/codecs": ["@solana/codecs@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/codecs-data-structures": "2.0.0-rc.1", "@solana/codecs-numbers": "2.0.0-rc.1", "@solana/codecs-strings": "2.0.0-rc.1", "@solana/options": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-qxoR7VybNJixV51L0G1RD2boZTcxmwUWnKCaJJExQ5qNKwbpSyDdWfFJfM5JhGyKe9DnPVOZB+JHWXnpbZBqrQ=="], - "@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], + "@solana/codecs-core": ["@solana/codecs-core@2.3.0", "", { "dependencies": { "@solana/errors": "2.3.0" }, "peerDependencies": { "typescript": ">=5.3.3" } }, "sha512-oG+VZzN6YhBHIoSKgS5ESM9VIGzhWjEHEGNPSibiDTxFhsFWxNaz8LbMDPjBUE69r9wmdGLkrQ+wVPbnJcZPvw=="], "@solana/codecs-data-structures": ["@solana/codecs-data-structures@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/codecs-numbers": "2.0.0-rc.1", "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-rinCv0RrAVJ9rE/rmaibWJQxMwC5lSaORSZuwjopSUE6T0nb/MVg6Z1siNCXhh/HFTOg0l8bNvZHgBcN/yvXog=="], @@ -186,9 +179,9 @@ "@swc/helpers": ["@swc/helpers@0.5.17", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-5IKx/Y13RsYd+sauPb2x+U/xZikHjolzfuDgTAl/Tdf3Q8rslRvC19NKDLgAJQ6wsqADk10ntlv08nPFw/gO/A=="], - "@switchboard-xyz/common": ["@switchboard-xyz/common@3.0.14", "", { "dependencies": { "@solana/web3.js": "^1.98.0", "axios": "^1.8.3", "big.js": "^6.2.2", "bn.js": "^5.2.1", "bs58": "^6.0.0", "buffer": "^6.0.3", "decimal.js": "^10.4.3", "js-sha256": "^0.11.0", "protobufjs": "^7.4.0", "yaml": "^2.6.1" } }, "sha512-LpxzEywO0DjPYIgPzQYkf32C7agwW4YRsPN6BcIvYrw0iJdDMtPZ3SQfIGHLSlD1fwvn2KLUYuGaKegeq4aBTw=="], + "@switchboard-xyz/common": ["@switchboard-xyz/common@5.5.0", "", { "dependencies": { "@solana/web3.js": "^1.98.2", "axios": "^1.9.0", "big.js": "^6.2.2", "bn.js": "^5.2.1", "bs58": "^6.0.0", "buffer": "^6.0.3", "decimal.js": "^10.4.3", "js-sha256": "^0.11.0", "protobufjs": "^7.4.0" } }, "sha512-Wvs9KJw+YSe8O2IOsMUvPE8aQHb0t2vi/9hEQC7Pc6279s7tTTI8eVgT/0Jb2z897OHgIZTD3oGQ8IEBqIgV0w=="], - "@switchboard-xyz/on-demand": ["@switchboard-xyz/on-demand@2.4.1", "", { "dependencies": { "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", "@isaacs/ttlcache": "^1.4.1", "@switchboard-xyz/common": ">=3.0.0", "axios": "^1.8.3", "bs58": "^6.0.0", "buffer": "^6.0.3", "js-yaml": "^4.1.0" } }, "sha512-eSlBp+c8lxpcSgh0/2xK8OaLHPziTSZlcs8V96gZGdiCJz1KgWJRNE1qnIJDOwaGdFecZdwcmajfQRtLRLED3w=="], + "@switchboard-xyz/on-demand": ["@switchboard-xyz/on-demand@3.7.3", "", { "dependencies": { "@coral-xyz/anchor-31": "npm:@coral-xyz/anchor@0.31.1", "@isaacs/ttlcache": "^1.4.1", "@solana/spl-token": "^0.4.14", "@solana/web3.js": "^1.98.4", "@switchboard-xyz/common": "^5.2.9", "axios": "^1.9", "bs58": "^6.0.0", "buffer": "^6.0.3", "events": "^3.3.0", "isomorphic-ws": "^5.0.0", "js-yaml": "^4.1.0", "tweetnacl": "^1.0.3", "ws": "^8.18.1" } }, "sha512-sG9errSwjYlQbIlQl0iptUQcbKrPe7QVxX20+qXuucG3qIWlA/w6sXGnITeYbt+BERyBYdfue0viBjmjOsCZrg=="], "@types/bn.js": ["@types/bn.js@5.1.6", "", { "dependencies": { "@types/node": "*" } }, "sha512-Xh8vSwUeMKeYYrj3cX4lGQgFSF/N03r+tv4AiLl1SucqV+uTQpxRcnM8AkXKHwYP9ZPXOYXRr2KPXpVlIvqh9w=="], @@ -200,9 +193,9 @@ "@types/mocha": ["@types/mocha@8.2.3", "", {}, "sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw=="], - "@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@types/semver": ["@types/semver@7.7.0", "", {}, "sha512-k107IF4+Xr7UHjwDc7Cfd6PRQfbdkiRabXGRjo07b4WyPahFBZCZ1sE+BNxYIJPPg73UkfOsVOLwqVc/6ETrIA=="], + "@types/semver": ["@types/semver@7.7.1", "", {}, "sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA=="], "@types/uuid": ["@types/uuid@8.3.4", "", {}, "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw=="], @@ -256,7 +249,7 @@ "available-typed-arrays": ["available-typed-arrays@1.0.7", "", { "dependencies": { "possible-typed-array-names": "^1.0.0" } }, "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ=="], - "axios": ["axios@1.11.0", "", { "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", "proxy-from-env": "^1.1.0" } }, "sha512-1Lx3WLFQWm3ooKDYZD1eXmoGO9fxYQjrycfHFC8P0sCfQVXyROp0p9PFWBehewBOdCwHc+f/b8I0fMto5eSfwA=="], + "axios": ["axios@1.13.2", "", { "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.4", "proxy-from-env": "^1.1.0" } }, "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA=="], "axios-retry": ["axios-retry@3.9.1", "", { "dependencies": { "@babel/runtime": "^7.15.4", "is-retry-allowed": "^2.2.0" } }, "sha512-8PJDLJv7qTTMMwdnbMvrLYuvB47M81wRtxQmEdV5w4rgbTXTt+vtPkXwajOfOdSyv/wZICJOC+/UhXH4aQ/R+w=="], @@ -312,9 +305,9 @@ "cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="], - "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="], + "color-convert": ["color-convert@3.1.0", "", { "dependencies": { "color-name": "^2.0.0" } }, "sha512-TVoqAq8ZDIpK5lsQY874DDnu65CSsc9vzq0wLpNQ6UMBq81GSZocVazPiBbYGzngzBOIRahpkTzCLVe2at4MfA=="], - "color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="], + "color-name": ["color-name@2.0.0", "", {}, "sha512-SbtvAMWvASO5TE2QP07jHBMXKafgdZz8Vrsrn96fiL+O92/FN/PLARzUW5sKt013fjAprK2d2iCn2hk2Xb5oow=="], "combined-stream": ["combined-stream@1.0.8", "", { "dependencies": { "delayed-stream": "~1.0.0" } }, "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg=="], @@ -396,6 +389,8 @@ "eventemitter3": ["eventemitter3@4.0.7", "", {}, "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="], + "events": ["events@3.3.0", "", {}, "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="], + "eyes": ["eyes@0.1.8", "", {}, "sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ=="], "fast-deep-equal": ["fast-deep-equal@3.1.3", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="], @@ -434,12 +429,14 @@ "for-each": ["for-each@0.3.5", "", { "dependencies": { "is-callable": "^1.2.7" } }, "sha512-dKx12eRCVIzqCxFGplyFKJMPvLEWgmNtUrpTiJIR5u97zEhRG8ySrtboPHZXx7daLxQVrl643cTzbab2tkQjxg=="], - "form-data": ["form-data@4.0.4", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow=="], + "form-data": ["form-data@4.0.5", "", { "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", "hasown": "^2.0.2", "mime-types": "^2.1.12" } }, "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w=="], "fs.realpath": ["fs.realpath@1.0.0", "", {}, "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="], "function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="], + "generator-function": ["generator-function@2.0.1", "", {}, "sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g=="], + "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="], "get-func-name": ["get-func-name@2.0.2", "", {}, "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ=="], @@ -494,7 +491,7 @@ "is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="], - "is-generator-function": ["is-generator-function@1.1.0", "", { "dependencies": { "call-bound": "^1.0.3", "get-proto": "^1.0.0", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" } }, "sha512-nPUB5km40q9e8UfN/Zc24eLlzdSf9OfKByBw9CIdw4H1giPMeA0OIJvbchsCu4npfI2QcMVBsGEBHKZ7wLTWmQ=="], + "is-generator-function": ["is-generator-function@1.1.2", "", { "dependencies": { "call-bound": "^1.0.4", "generator-function": "^2.0.0", "get-proto": "^1.0.1", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" } }, "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA=="], "is-glob": ["is-glob@4.0.3", "", { "dependencies": { "is-extglob": "^2.1.1" } }, "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg=="], @@ -522,7 +519,7 @@ "js-sha256": ["js-sha256@0.11.1", "", {}, "sha512-o6WSo/LUvY2uC4j7mO50a2ms7E/EAdbP0swigLV+nzHKTTaYnaLIWJ02VdXrsJX0vGedDESQnLsOekr94ryfjg=="], - "js-yaml": ["js-yaml@4.1.0", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA=="], + "js-yaml": ["js-yaml@4.1.1", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA=="], "json-buffer": ["json-buffer@3.0.1", "", {}, "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ=="], @@ -652,7 +649,7 @@ "safe-regex-test": ["safe-regex-test@1.1.0", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "is-regex": "^1.2.1" } }, "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw=="], - "semver": ["semver@7.7.2", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA=="], + "semver": ["semver@7.7.3", "", { "bin": { "semver": "bin/semver.js" } }, "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q=="], "set-function-length": ["set-function-length@1.2.2", "", { "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.2" } }, "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg=="], @@ -718,6 +715,8 @@ "tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], + "tweetnacl": ["tweetnacl@1.0.3", "", {}, "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="], + "type-check": ["type-check@0.4.0", "", { "dependencies": { "prelude-ls": "^1.2.1" } }, "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew=="], "type-detect": ["type-detect@4.1.0", "", {}, "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw=="], @@ -728,7 +727,7 @@ "typescript": ["typescript@5.4.5", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ=="], - "undici-types": ["undici-types@7.10.0", "", {}, "sha512-t5Fy/nfn+14LuOc2KNYg75vZqClpAiqscVvMygNnlsHBFpSXdJaYtXMcdNLpl/Qvc3P2cB3s6lOV51nqsFq4ag=="], + "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="], "uri-js": ["uri-js@4.4.1", "", { "dependencies": { "punycode": "^2.1.0" } }, "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg=="], @@ -760,8 +759,6 @@ "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="], - "yaml": ["yaml@2.8.1", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-lcYcMxX2PO9XMGvAJkJ3OsNMw+/7FKes7/hgerGUYWIoWu5j/+YQqcZr5JnPZWzOsEBgMbSbiSTn/dv/69Mkpw=="], - "yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], "yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="], @@ -772,11 +769,15 @@ "zstddec": ["zstddec@0.1.0", "", {}, "sha512-w2NTI8+3l3eeltKAdK8QpiLo/flRAr2p8AGeakfMZOXBxOg9HIu4LVDxBi81sYgVhFhdJjv1OrB5ssI8uFPoLg=="], - "@coral-xyz/anchor-30/@coral-xyz/borsh": ["@coral-xyz/borsh@0.30.1", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ=="], + "@coral-xyz/anchor/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + + "@coral-xyz/anchor-29/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@coral-xyz/anchor-31/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], "@ellipsis-labs/phoenix-sdk/@solana/spl-token": ["@solana/spl-token@0.3.11", "", { "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", "@solana/spl-token-metadata": "^0.1.2", "buffer": "^6.0.3" }, "peerDependencies": { "@solana/web3.js": "^1.88.0" } }, "sha512-bvohO3rIMSVL24Pb+I4EYTJ6cL82eFpInEXD/I8K8upOGjpqHsKUoAempR/RnUlI1qSFNyFlWJfu6MNUgfbCQQ=="], - "@ellipsis-labs/phoenix-sdk/@types/node": ["@types/node@18.19.123", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-K7DIaHnh0mzVxreCR9qwgNxp3MH9dltPNIEddW9MYUlcKAzm+3grKNSTe2vCJHI1FaLpvpL5JGJrz1UZDKYvDg=="], + "@ellipsis-labs/phoenix-sdk/@types/node": ["@types/node@18.19.130", "", { "dependencies": { "undici-types": "~5.26.4" } }, "sha512-GRaXQx6jGfL8sKfaIDD6OupbIHBr9jv7Jnaml9tB7l4v068PAOXqfcujMMo5PhbIs6ggR1XODELqahT2R8v0fg=="], "@ellipsis-labs/phoenix-sdk/bs58": ["bs58@5.0.0", "", { "dependencies": { "base-x": "^4.0.0" } }, "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ=="], @@ -802,31 +803,41 @@ "@project-serum/serum/@solana/spl-token": ["@solana/spl-token@0.1.8", "", { "dependencies": { "@babel/runtime": "^7.10.5", "@solana/web3.js": "^1.21.0", "bn.js": "^5.1.0", "buffer": "6.0.3", "buffer-layout": "^1.2.0", "dotenv": "10.0.0" } }, "sha512-LZmYCKcPQDtJgecvWOgT/cnoIQPWjdH+QVyzPcFvyDUiT0DiRjZaam4aqNUyvchLFhzgunv3d9xOoyE34ofdoQ=="], + "@pythnetwork/client/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@pythnetwork/client/@coral-xyz/borsh": ["@coral-xyz/borsh@0.28.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-/u1VTzw7XooK7rqeD7JLUSwOyRSesPUk0U37BV9zK0axJc1q0nRbKFGFLYCQ16OtdOJTTwGfGp11Lx9B45bRCQ=="], + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@pythnetwork/pyth-solana-receiver/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + "@pythnetwork/solana-utils/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@pythnetwork/solana-utils/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], "@pythnetwork/solana-utils/bs58": ["bs58@5.0.0", "", { "dependencies": { "base-x": "^4.0.0" } }, "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ=="], "@solana/buffer-layout-utils/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + "@solana/codecs/@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], + "@solana/codecs/@solana/codecs-numbers": ["@solana/codecs-numbers@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-J5i5mOkvukXn8E3Z7sGIPxsThRCgSdgTWJDQeZvucQ9PT6Y3HiVXJ0pcWiOWAoQ3RX8e/f4I3IC+wE6pZiJzDQ=="], - "@solana/codecs-core/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], + "@solana/codecs-data-structures/@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], "@solana/codecs-data-structures/@solana/codecs-numbers": ["@solana/codecs-numbers@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-J5i5mOkvukXn8E3Z7sGIPxsThRCgSdgTWJDQeZvucQ9PT6Y3HiVXJ0pcWiOWAoQ3RX8e/f4I3IC+wE6pZiJzDQ=="], "@solana/codecs-data-structures/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], - "@solana/codecs-numbers/@solana/codecs-core": ["@solana/codecs-core@2.3.0", "", { "dependencies": { "@solana/errors": "2.3.0" }, "peerDependencies": { "typescript": ">=5.3.3" } }, "sha512-oG+VZzN6YhBHIoSKgS5ESM9VIGzhWjEHEGNPSibiDTxFhsFWxNaz8LbMDPjBUE69r9wmdGLkrQ+wVPbnJcZPvw=="], + "@solana/codecs-strings/@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], "@solana/codecs-strings/@solana/codecs-numbers": ["@solana/codecs-numbers@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-J5i5mOkvukXn8E3Z7sGIPxsThRCgSdgTWJDQeZvucQ9PT6Y3HiVXJ0pcWiOWAoQ3RX8e/f4I3IC+wE6pZiJzDQ=="], "@solana/codecs-strings/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], - "@solana/errors/commander": ["commander@14.0.0", "", {}, "sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA=="], + "@solana/errors/commander": ["commander@14.0.2", "", {}, "sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ=="], + + "@solana/options/@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], "@solana/options/@solana/codecs-numbers": ["@solana/codecs-numbers@2.0.0-rc.1", "", { "dependencies": { "@solana/codecs-core": "2.0.0-rc.1", "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-J5i5mOkvukXn8E3Z7sGIPxsThRCgSdgTWJDQeZvucQ9PT6Y3HiVXJ0pcWiOWAoQ3RX8e/f4I3IC+wE6pZiJzDQ=="], @@ -840,8 +851,14 @@ "@switchboard-xyz/common/bs58": ["bs58@6.0.0", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="], + "@switchboard-xyz/on-demand/@solana/spl-token": ["@solana/spl-token@0.4.14", "", { "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", "@solana/spl-token-group": "^0.0.7", "@solana/spl-token-metadata": "^0.1.6", "buffer": "^6.0.3" }, "peerDependencies": { "@solana/web3.js": "^1.95.5" } }, "sha512-u09zr96UBpX4U685MnvQsNzlvw9TiY005hk1vJmJr7gMJldoPG1eYU5/wNEyOA5lkMLiR/gOi9SFD4MefOYEsA=="], + + "@switchboard-xyz/on-demand/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + "@switchboard-xyz/on-demand/bs58": ["bs58@6.0.0", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="], + "@switchboard-xyz/on-demand/isomorphic-ws": ["isomorphic-ws@5.0.0", "", { "peerDependencies": { "ws": "*" } }, "sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw=="], + "@typescript-eslint/typescript-estree/minimatch": ["minimatch@9.0.3", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg=="], "fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], @@ -866,6 +883,18 @@ "typedoc/minimatch": ["minimatch@5.1.6", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g=="], + "@coral-xyz/anchor-31/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], + + "@coral-xyz/anchor-31/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], + + "@coral-xyz/anchor-31/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], + + "@coral-xyz/anchor/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], + + "@coral-xyz/anchor/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@ellipsis-labs/phoenix-sdk/@types/node/undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="], "@ellipsis-labs/phoenix-sdk/bs58/base-x": ["base-x@4.0.1", "", {}, "sha512-uAZ8x6r6S3aUM9rbHGVOIsR15U/ZSc82b3ymnCPsT45Gk1DDvhDPdIgB5MrhirZWt+5K0EEPQH985kNqZgNPFw=="], @@ -874,7 +903,7 @@ "@metaplex-foundation/beet-solana/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@metaplex-foundation/beet-solana/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@metaplex-foundation/beet-solana/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@metaplex-foundation/beet-solana/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], @@ -882,13 +911,13 @@ "@metaplex-foundation/solita/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@metaplex-foundation/solita/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@metaplex-foundation/solita/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@metaplex-foundation/solita/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], "@project-serum/anchor/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@project-serum/anchor/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@project-serum/anchor/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@project-serum/anchor/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], @@ -896,17 +925,29 @@ "@project-serum/serum/@solana/spl-token/dotenv": ["dotenv@10.0.0", "", {}, "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q=="], + "@pythnetwork/client/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor/@solana/web3.js": ["@solana/web3.js@1.73.2", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@noble/ed25519": "^1.7.0", "@noble/hashes": "^1.1.2", "@noble/secp256k1": "^1.6.3", "@solana/buffer-layout": "^4.0.0", "agentkeepalive": "^4.2.1", "bigint-buffer": "^1.1.5", "bn.js": "^5.0.0", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.1", "fast-stable-stringify": "^1.0.0", "jayson": "^3.4.4", "node-fetch": "2", "rpc-websockets": "^7.5.0", "superstruct": "^0.14.2" } }, "sha512-9WACF8W4Nstj7xiDw3Oom22QmrhBh0VyZyZ7JvvG3gOxLWLlX3hvm5nPVJOGcCE/9fFavBbCUb5A6CIuvMGdoA=="], + "@pythnetwork/pyth-solana-receiver/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@pythnetwork/pyth-solana-receiver/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@pythnetwork/pyth-solana-receiver/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@pythnetwork/pyth-solana-receiver/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@pythnetwork/solana-utils/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor/@solana/web3.js": ["@solana/web3.js@1.73.2", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@noble/ed25519": "^1.7.0", "@noble/hashes": "^1.1.2", "@noble/secp256k1": "^1.6.3", "@solana/buffer-layout": "^4.0.0", "agentkeepalive": "^4.2.1", "bigint-buffer": "^1.1.5", "bn.js": "^5.0.0", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.1", "fast-stable-stringify": "^1.0.0", "jayson": "^3.4.4", "node-fetch": "2", "rpc-websockets": "^7.5.0", "superstruct": "^0.14.2" } }, "sha512-9WACF8W4Nstj7xiDw3Oom22QmrhBh0VyZyZ7JvvG3gOxLWLlX3hvm5nPVJOGcCE/9fFavBbCUb5A6CIuvMGdoA=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], + "@pythnetwork/solana-utils/@solana/web3.js/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], "@pythnetwork/solana-utils/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@pythnetwork/solana-utils/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@pythnetwork/solana-utils/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@pythnetwork/solana-utils/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], @@ -914,16 +955,16 @@ "@solana/buffer-layout-utils/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@solana/buffer-layout-utils/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@solana/buffer-layout-utils/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@solana/buffer-layout-utils/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], - "@solana/codecs-core/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], - "@solana/codecs-data-structures/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], "@solana/codecs-strings/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], + "@solana/codecs/@solana/codecs-core/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], + "@solana/codecs/@solana/codecs-numbers/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], "@solana/options/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], @@ -932,17 +973,25 @@ "@switchboard-xyz/common/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@switchboard-xyz/common/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@switchboard-xyz/common/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@switchboard-xyz/common/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], "@switchboard-xyz/common/bs58/base-x": ["base-x@5.0.1", "", {}, "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg=="], + "@switchboard-xyz/on-demand/@solana/web3.js/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@switchboard-xyz/on-demand/bs58/base-x": ["base-x@5.0.1", "", {}, "sha512-M7uio8Zt++eg3jPj+rHMfCC+IuygQHHCOU+IYsVtik6FWjuYpVt/+MRKcgsAMHh8mMFAwnB+Bs+mTrFiXjMzKg=="], "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="], - "jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], "jito-ts/@solana/web3.js/superstruct": ["superstruct@0.14.2", "", {}, "sha512-nPewA6m9mR3d6k7WkZ8N8zpTWfenFH3q9pA2PkuiZxINr9DKB2+40wEQf0ixn8VaGuJ78AB6iWOtStI+/4FKZQ=="], @@ -956,12 +1005,32 @@ "solana-bankrun/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "solana-bankrun/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "solana-bankrun/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "solana-bankrun/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], "typedoc/minimatch/brace-expansion": ["brace-expansion@2.0.2", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ=="], + "@coral-xyz/anchor-31/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], + + "@coral-xyz/anchor-31/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], + + "@coral-xyz/anchor-31/@solana/web3.js/jayson/commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="], + + "@coral-xyz/anchor-31/@solana/web3.js/jayson/ws": ["ws@7.5.10", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="], + + "@coral-xyz/anchor-31/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson/commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson/ws": ["ws@7.5.10", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="], + + "@coral-xyz/anchor/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + "@metaplex-foundation/beet-solana/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], "@metaplex-foundation/beet-solana/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], @@ -994,10 +1063,14 @@ "@project-serum/serum/@solana/spl-token/@solana/web3.js/jayson": ["jayson@4.2.0", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "stream-json": "^1.9.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-VfJ9t1YLwacIubLhONk0KFeosUBwstRWQ0IRT1KDjEjnVnSOVHC3uwugyV7L0c7R9lpVyrUGT2XWiBA1UTtpyg=="], - "@project-serum/serum/@solana/spl-token/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.3", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-I+kNjW0udB4Fetr3vvtRuYZJS0PcSPyyvBcH5sDdoV8DFs5E4W2pTr7aiMlKfPxANTClP9RlqCPolj9dd5MsEA=="], + "@project-serum/serum/@solana/spl-token/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.3.2", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA=="], "@project-serum/serum/@solana/spl-token/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor/@solana/web3.js/buffer": ["buffer@6.0.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" } }, "sha512-rVAXBwEcEoYtxnHSO5iWyhzV/O1WMtkUYWlfdLS7FjU4PnSJJHEfHXi/uHPI5EwltmOA794gN3bm3/pzuctWjQ=="], + + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor/@solana/web3.js/superstruct": ["superstruct@0.14.2", "", {}, "sha512-nPewA6m9mR3d6k7WkZ8N8zpTWfenFH3q9pA2PkuiZxINr9DKB2+40wEQf0ixn8VaGuJ78AB6iWOtStI+/4FKZQ=="], + "@pythnetwork/pyth-solana-receiver/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], "@pythnetwork/pyth-solana-receiver/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], @@ -1008,6 +1081,10 @@ "@pythnetwork/pyth-solana-receiver/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + "@pythnetwork/solana-utils/@coral-xyz/anchor/@solana/web3.js/buffer": ["buffer@6.0.1", "", { "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" } }, "sha512-rVAXBwEcEoYtxnHSO5iWyhzV/O1WMtkUYWlfdLS7FjU4PnSJJHEfHXi/uHPI5EwltmOA794gN3bm3/pzuctWjQ=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor/@solana/web3.js/superstruct": ["superstruct@0.14.2", "", {}, "sha512-nPewA6m9mR3d6k7WkZ8N8zpTWfenFH3q9pA2PkuiZxINr9DKB2+40wEQf0ixn8VaGuJ78AB6iWOtStI+/4FKZQ=="], + "@pythnetwork/solana-utils/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], "@pythnetwork/solana-utils/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], @@ -1028,6 +1105,8 @@ "@solana/buffer-layout-utils/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + "@solana/codecs/@solana/codecs-core/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], + "@solana/codecs/@solana/codecs-numbers/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], "@switchboard-xyz/common/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], @@ -1040,7 +1119,19 @@ "@switchboard-xyz/common/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], - "jito-ts/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/@types/ws": ["@types/ws@7.4.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/isomorphic-ws": ["isomorphic-ws@4.0.1", "", { "peerDependencies": { "ws": "*" } }, "sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/ws": ["ws@7.5.10", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + + "jito-ts/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], "solana-bankrun/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], @@ -1052,11 +1143,15 @@ "solana-bankrun/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], - "@metaplex-foundation/beet-solana/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@coral-xyz/anchor-31/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], + + "@coral-xyz/anchor/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@metaplex-foundation/solita/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@metaplex-foundation/beet-solana/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@project-serum/anchor/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@metaplex-foundation/solita/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], + + "@project-serum/anchor/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], "@project-serum/serum/@solana/spl-token/@solana/web3.js/jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], @@ -1068,16 +1163,18 @@ "@project-serum/serum/@solana/spl-token/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], - "@pythnetwork/pyth-solana-receiver/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@pythnetwork/pyth-solana-receiver/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], + + "@pythnetwork/solana-utils/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@pythnetwork/solana-utils/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@solana/buffer-layout-utils/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@solana/buffer-layout-utils/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@switchboard-xyz/common/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@switchboard-xyz/common/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@switchboard-xyz/on-demand/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "solana-bankrun/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "solana-bankrun/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], - "@project-serum/serum/@solana/spl-token/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.3.0", "", { "dependencies": { "undici-types": "~7.10.0" } }, "sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow=="], + "@project-serum/serum/@solana/spl-token/@solana/web3.js/jayson/@types/ws/@types/node": ["@types/node@24.10.1", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="], } } diff --git a/package.json b/package.json index 4b30b26fde..146e55ada6 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "author": "", "license": "ISC", "devDependencies": { - "@coral-xyz/anchor": "0.29.0", - "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", + "@coral-xyz/anchor": "npm:@coral-xyz/anchor@0.31.1", + "@coral-xyz/anchor-29": "npm:@coral-xyz/anchor@0.29.0", "@project-serum/common": "0.0.1-beta.3", "@project-serum/serum": "0.13.65", "@pythnetwork/client": "2.21.0", @@ -30,8 +30,8 @@ "dependencies": { "@ellipsis-labs/phoenix-sdk": "1.4.2", "@pythnetwork/pyth-solana-receiver": "0.8.0", - "@switchboard-xyz/common": "3.0.14", - "@switchboard-xyz/on-demand": "2.4.1", + "@switchboard-xyz/common": "5.5.0", + "@switchboard-xyz/on-demand": "3.7.3", "anchor-bankrun": "0.3.0", "chai-bn": "0.2.2", "csvtojson": "2.0.10", @@ -50,7 +50,7 @@ "prettify:fix": "prettier --write './sdk/src/**/*.ts' './tests/**.ts' './cli/**.ts'", "lint": "eslint . --ext ts --quiet --format unix", "lint:fix": "eslint . --ext ts --fix", - "update-idl": "anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json" + "update-idl": "anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/drift.json && cp target/types/drift.ts sdk/src/idl/drift.ts" }, "engines": { "node": ">=12" @@ -95,4 +95,4 @@ "supports-hyperlinks": "<4.1.1", "has-ansi": "<6.0.1" } -} +} \ No newline at end of file diff --git a/programs/drift/Cargo.toml b/programs/drift/Cargo.toml index 594aa04b69..15e91a4506 100644 --- a/programs/drift/Cargo.toml +++ b/programs/drift/Cargo.toml @@ -12,37 +12,44 @@ path = "src/lib.rs" [features] no-entrypoint = [] cpi = ["no-entrypoint"] -mainnet-beta=[] -anchor-test= [] -default=["mainnet-beta", "no-entrypoint"] -drift-rs=[] +mainnet-beta =[] +anchor-test = [] +default = ["mainnet-beta", "no-entrypoint"] +drift-rs = [] +idl-build = [ + "anchor-lang/idl-build", + "anchor-spl/idl-build", + "openbook-v2-light/idl-build", + "pythnet-sdk/idl-build", + "switchboard-on-demand/idl-build" +] [dependencies] -anchor-lang = "0.29.0" -solana-program = "1.16" -anchor-spl = { version = "0.29.0", features = [] } +anchor-lang = "0.32.1" +anchor-spl = { version = "0.32.1", features = ["idl-build"] } +solana-program = "=2.2.1" pyth-client = "0.2.2" -pyth-lazer-solana-contract = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "d790d1cb4da873a949cf33ff70349b7614b232eb", features = ["no-entrypoint"]} -pythnet-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "d790d1cb4da873a949cf33ff70349b7614b232eb"} -pyth-solana-receiver-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "d790d1cb4da873a949cf33ff70349b7614b232eb"} -bytemuck = { version = "1.4.0" } -borsh = "0.10.3" +pyth-lazer-solana-contract = { git = "https://github.com/jordy25519/pyth-crosschain", features = ["no-entrypoint"]} +pyth-solana-receiver-sdk = { git = "https://github.com/jordy25519/pyth-crosschain" } +pythnet-sdk = { git = "https://github.com/jordy25519/pyth-crosschain", features = ["idl-build"] } +bytemuck = "1.4.0" hex = "0.4.3" -num-traits = "0.2" uint = { version = "0.9.1", default-features = false } num-integer = "0.1.44" +num-traits = "0.2" arrayref = "0.3.6" base64 = "0.13.0" -serum_dex = { git = "https://github.com/project-serum/serum-dex", rev = "85b4f14", version = "0.5.6", features = ["no-entrypoint"] } +serum_dex = { git = "https://github.com/drift-labs/serum-dex", branch = "master", features = ["no-entrypoint"] } enumflags2 = "0.6.4" -phoenix-v1 = { git = "https://github.com/drift-labs/phoenix-v1", rev = "7703c5", version = "0.2.4", features = ["no-entrypoint"] } +phoenix-v1 = { git = "https://github.com/jordy25519/phoenix-v1", branch = "master", features = ["no-entrypoint"] } solana-security-txt = "1.1.0" static_assertions = "1.1.0" -drift-macros = { git = "https://github.com/drift-labs/drift-macros.git", rev = "c57d87" } +drift-macros = { git = "https://github.com/drift-labs/drift-macros", rev = "6e246ba" } switchboard = { path = "../switchboard", features = ["no-entrypoint"] } openbook-v2-light = { path = "../openbook_v2", features = ["no-entrypoint"] } switchboard-on-demand = { path = "../switchboard-on-demand", features = ["no-entrypoint"] } byteorder = "1.4.3" +proc-macro2 = { version = "1.0.103", features = ["span-locations"] } [dev-dependencies] bytes = "1.2.0" diff --git a/programs/drift/src/controller/amm.rs b/programs/drift/src/controller/amm.rs index 0579d0f6de..898a897ff8 100644 --- a/programs/drift/src/controller/amm.rs +++ b/programs/drift/src/controller/amm.rs @@ -87,8 +87,8 @@ pub fn swap_base_asset( quote_asset_amount_surplus, ) = calculate_base_swap_output_with_spread(&market.amm, base_asset_swap_amount, direction)?; - market.amm.base_asset_reserve = new_base_asset_reserve; - market.amm.quote_asset_reserve = new_quote_asset_reserve; + market.amm.set_base_asset_reserve(new_base_asset_reserve); + market.amm.set_quote_asset_reserve(new_quote_asset_reserve); Ok(( quote_asset_amount, @@ -114,33 +114,33 @@ pub fn calculate_base_swap_output_with_spread( base_asset_swap_amount.cast()?, base_asset_reserve_with_spread, direction, - amm.sqrt_k, + amm.sqrt_k(), )?; let quote_asset_amount = calculate_quote_asset_amount_swapped( quote_asset_reserve_with_spread, new_quote_asset_reserve_with_spread, direction, - amm.peg_multiplier, + amm.peg_multiplier(), )?; let (new_quote_asset_reserve, new_base_asset_reserve) = amm::calculate_swap_output( base_asset_swap_amount.cast()?, - amm.base_asset_reserve, + amm.base_asset_reserve(), direction, - amm.sqrt_k, + amm.sqrt_k(), )?; // calculate the quote asset surplus by taking the difference between what quote_asset_amount is // with and without spread let quote_asset_amount_surplus = calculate_quote_asset_amount_surplus( new_quote_asset_reserve, - amm.quote_asset_reserve, + amm.quote_asset_reserve(), match direction { SwapDirection::Remove => SwapDirection::Add, SwapDirection::Add => SwapDirection::Remove, }, - amm.peg_multiplier, + amm.peg_multiplier(), quote_asset_amount, direction == SwapDirection::Remove, )?; @@ -160,19 +160,31 @@ pub fn update_spread_reserves(market: &mut PerpMarket) -> DriftResult { calculate_spread_reserves(market, PositionDirection::Short)?; if market.amm.reference_price_offset == 0 { - market.amm.ask_base_asset_reserve = - new_ask_base_asset_reserve.min(market.amm.base_asset_reserve); - market.amm.bid_base_asset_reserve = - new_bid_base_asset_reserve.max(market.amm.base_asset_reserve); - market.amm.ask_quote_asset_reserve = - new_ask_quote_asset_reserve.max(market.amm.quote_asset_reserve); - market.amm.bid_quote_asset_reserve = - new_bid_quote_asset_reserve.min(market.amm.quote_asset_reserve); + market.amm.set_ask_base_asset_reserve( + new_ask_base_asset_reserve.min(market.amm.base_asset_reserve()), + ); + market.amm.set_bid_base_asset_reserve( + new_bid_base_asset_reserve.max(market.amm.base_asset_reserve()), + ); + market.amm.set_ask_quote_asset_reserve( + new_ask_quote_asset_reserve.max(market.amm.quote_asset_reserve()), + ); + market.amm.set_bid_quote_asset_reserve( + new_bid_quote_asset_reserve.min(market.amm.quote_asset_reserve()), + ); } else { - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); } Ok(()) @@ -188,10 +200,10 @@ pub fn update_spreads( let reference_price_offset = if max_ref_offset > 0 { let liquidity_ratio = amm_spread::calculate_inventory_liquidity_ratio_for_reference_price_offset( - market.amm.base_asset_amount_with_amm, - market.amm.base_asset_reserve, - market.amm.min_base_asset_reserve, - market.amm.max_base_asset_reserve, + market.amm.base_asset_amount_with_amm(), + market.amm.base_asset_reserve(), + market.amm.min_base_asset_reserve(), + market.amm.max_base_asset_reserve(), )?; let signed_liquidity_ratio = @@ -233,16 +245,16 @@ pub fn update_spreads( market.amm.last_oracle_reserve_price_spread_pct, market.amm.last_oracle_conf_pct, market.amm.max_spread, - market.amm.quote_asset_reserve, - market.amm.terminal_quote_asset_reserve, - market.amm.peg_multiplier, - market.amm.base_asset_amount_with_amm, + market.amm.quote_asset_reserve(), + market.amm.terminal_quote_asset_reserve(), + market.amm.peg_multiplier(), + market.amm.base_asset_amount_with_amm(), reserve_price, - market.amm.total_fee_minus_distributions, + market.amm.total_fee_minus_distributions(), market.amm.net_revenue_since_last_funding, - market.amm.base_asset_reserve, - market.amm.min_base_asset_reserve, - market.amm.max_base_asset_reserve, + market.amm.base_asset_reserve(), + market.amm.min_base_asset_reserve(), + market.amm.max_base_asset_reserve(), market.amm.mark_std, market.amm.oracle_std, market.amm.long_intensity_volume, @@ -357,13 +369,13 @@ pub fn update_concentration_coef(market: &mut PerpMarket, scale: u128) -> DriftR "invalid new_concentration_coef", )?; - market.amm.concentration_coef = new_concentration_coef; + market.amm.set_concentration_coef(new_concentration_coef); let (_, terminal_quote_reserves, terminal_base_reserves) = amm::calculate_terminal_price_and_reserves(&market.amm)?; validate!( - terminal_quote_reserves == market.amm.terminal_quote_asset_reserve, + terminal_quote_reserves == market.amm.terminal_quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "invalid terminal_quote_reserves", )?; @@ -372,17 +384,21 @@ pub fn update_concentration_coef(market: &mut PerpMarket, scale: u128) -> DriftR // doing so adds ability to improve amm constant product curve's slippage // by increasing k as same factor as scale w/o increasing imbalance risk let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, terminal_base_reserves)?; + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), terminal_base_reserves)?; - market.amm.max_base_asset_reserve = max_base_asset_reserve; - market.amm.min_base_asset_reserve = min_base_asset_reserve; + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); let reserve_price_after = market.amm.reserve_price()?; update_spreads(market, reserve_price_after, None)?; let (max_bids, max_asks) = amm::calculate_market_open_bids_asks(&market.amm)?; validate!( - max_bids > market.amm.base_asset_amount_with_amm && max_asks < market.amm.base_asset_amount_with_amm, + max_bids > market.amm.base_asset_amount_with_amm() && max_asks < market.amm.base_asset_amount_with_amm(), ErrorCode::InvalidConcentrationCoef, "amm.base_asset_amount_with_amm exceeds the unload liquidity available after concentration adjustment" )?; @@ -396,10 +412,10 @@ pub fn formulaic_update_k( funding_imbalance_cost: i128, now: i64, ) -> DriftResult { - let peg_multiplier_before = market.amm.peg_multiplier; - let base_asset_reserve_before = market.amm.base_asset_reserve; - let quote_asset_reserve_before = market.amm.quote_asset_reserve; - let sqrt_k_before = market.amm.sqrt_k; + let peg_multiplier_before = market.amm.peg_multiplier(); + let base_asset_reserve_before = market.amm.base_asset_reserve(); + let quote_asset_reserve_before = market.amm.quote_asset_reserve(); + let sqrt_k_before = market.amm.sqrt_k(); let funding_imbalance_cost_i64 = funding_imbalance_cost.cast::()?; @@ -420,7 +436,9 @@ pub fn formulaic_update_k( 0 }; - if (budget > 0 && market.amm.sqrt_k < MAX_SQRT_K) || (budget < 0 && market.amm.can_lower_k()?) { + if (budget > 0 && market.amm.sqrt_k() < MAX_SQRT_K) + || (budget < 0 && market.amm.can_lower_k()?) + { // single k scale is capped by .1% increase and .1% decrease (regardless of budget) let k_pct_upper_bound = K_BPS_UPDATE_SCALE + MAX_K_BPS_INCREASE * (market.amm.curve_update_intensity as i128) / 100; @@ -434,7 +452,7 @@ pub fn formulaic_update_k( k_pct_lower_bound, )?; - let new_sqrt_k = bn::U192::from(market.amm.sqrt_k) + let new_sqrt_k = bn::U192::from(market.amm.sqrt_k()) .safe_mul(bn::U192::from(k_scale_numerator))? .safe_div(bn::U192::from(k_scale_denominator))?; @@ -447,10 +465,10 @@ pub fn formulaic_update_k( if cost_applied { cp_curve::update_k(market, &update_k_result)?; - let peg_multiplier_after = market.amm.peg_multiplier; - let base_asset_reserve_after = market.amm.base_asset_reserve; - let quote_asset_reserve_after = market.amm.quote_asset_reserve; - let sqrt_k_after = market.amm.sqrt_k; + let peg_multiplier_after = market.amm.peg_multiplier(); + let base_asset_reserve_after = market.amm.base_asset_reserve(); + let quote_asset_reserve_after = market.amm.quote_asset_reserve(); + let sqrt_k_after = market.amm.sqrt_k(); emit!(CurveRecord { ts: now, @@ -464,13 +482,13 @@ pub fn formulaic_update_k( base_asset_reserve_after, quote_asset_reserve_after, sqrt_k_after, - base_asset_amount_long: market.amm.base_asset_amount_long.unsigned_abs(), - base_asset_amount_short: market.amm.base_asset_amount_short.unsigned_abs(), - base_asset_amount_with_amm: market.amm.base_asset_amount_with_amm, + base_asset_amount_long: market.amm.base_asset_amount_long().unsigned_abs(), + base_asset_amount_short: market.amm.base_asset_amount_short().unsigned_abs(), + base_asset_amount_with_amm: market.amm.base_asset_amount_with_amm(), number_of_users: market.number_of_users, adjustment_cost, - total_fee: market.amm.total_fee, - total_fee_minus_distributions: market.amm.total_fee_minus_distributions, + total_fee: market.amm.total_fee(), + total_fee_minus_distributions: market.amm.total_fee_minus_distributions(), oracle_price: market.amm.historical_oracle_data.last_oracle_price, fill_record: market.next_fill_record_id as u128, }); @@ -512,14 +530,14 @@ fn calculate_revenue_pool_transfer( let fee_pool_threshold = amm_fee_pool_token_amount_after .saturating_sub( FEE_POOL_TO_REVENUE_POOL_THRESHOLD - .safe_add(market.amm.total_social_loss)? + .safe_add(market.amm.total_social_loss())? .cast()?, ) .cast()?; let total_liq_fees_for_revenue_pool = market .amm - .total_liquidation_fee + .total_liquidation_fee() .min( market .insurance_claim @@ -545,7 +563,7 @@ fn calculate_revenue_pool_transfer( let revenue_pool_transfer = total_fee_for_if .safe_add(total_liq_fees_for_revenue_pool)? - .saturating_sub(market.amm.total_fee_withdrawn.cast()?) + .saturating_sub(market.amm.total_fee_withdrawn().cast()?) .max(0) .min(fee_pool_threshold) .min(max_revenue_to_settle.cast()?); @@ -567,7 +585,7 @@ fn calculate_revenue_pool_transfer( .cast::()? .min( get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )? @@ -612,9 +630,9 @@ pub fn update_pool_balances( let amm_target_max_fee_pool_token_amount = market .amm - .total_fee_minus_distributions - .safe_add(market.amm.total_liquidation_fee.cast()?)? - .safe_sub(market.amm.total_fee_withdrawn.cast()?)?; + .total_fee_minus_distributions() + .safe_add(market.amm.total_liquidation_fee().cast()?)? + .safe_sub(market.amm.total_fee_withdrawn().cast()?)?; if amm_target_max_fee_pool_token_amount <= amm_fee_pool_token_amount { // owe the market pnl pool before settling user @@ -635,8 +653,8 @@ pub fn update_pool_balances( { let amm_target_min_fee_pool_token_amount = get_total_fee_lower_bound(market)? - .safe_add(market.amm.total_liquidation_fee)? - .safe_sub(market.amm.total_fee_withdrawn)?; + .safe_add(market.amm.total_liquidation_fee())? + .safe_sub(market.amm.total_fee_withdrawn())?; let amm_fee_pool_token_amount = get_token_amount( market.amm.fee_pool.balance(), @@ -673,8 +691,8 @@ pub fn update_pool_balances( let terminal_state_surplus = market .amm - .total_fee_minus_distributions - .safe_sub(market.amm.total_fee_withdrawn.cast()?)?; + .total_fee_minus_distributions() + .safe_sub(market.amm.total_fee_withdrawn().cast()?)?; // market can perform withdraw from revenue pool if spot_market.insurance_fund.last_revenue_settle_ts @@ -705,10 +723,12 @@ pub fn update_pool_balances( &mut market.amm.fee_pool, )?; - market.amm.total_fee_withdrawn = market - .amm - .total_fee_withdrawn - .safe_add(revenue_pool_transfer.unsigned_abs())?; + market.amm.set_total_fee_withdrawn( + market + .amm + .total_fee_withdrawn() + .safe_add(revenue_pool_transfer.unsigned_abs())?, + ); } Ordering::Less => { transfer_revenue_pool_to_spot_balance( @@ -721,10 +741,12 @@ pub fn update_pool_balances( } if revenue_pool_transfer != 0 { - market.amm.total_fee_minus_distributions = market - .amm - .total_fee_minus_distributions - .safe_sub(revenue_pool_transfer)?; + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_sub(revenue_pool_transfer)?, + ); market.insurance_claim.revenue_withdraw_since_last_settle = market .insurance_claim @@ -796,7 +818,7 @@ pub fn update_pnl_pool_and_user_balance( let pnl_to_settle_with_user = if unrealized_pnl_with_fee > 0 { unrealized_pnl_with_fee.min( get_token_amount( - market.pnl_pool.scaled_balance, + market.pnl_pool.scaled_balance(), bank, market.pnl_pool.balance_type(), )? @@ -846,35 +868,42 @@ pub fn move_price( quote_asset_reserve: u128, sqrt_k: u128, ) -> DriftResult { - market.amm.base_asset_reserve = base_asset_reserve; + market.amm.set_base_asset_reserve(base_asset_reserve); let k = bn::U256::from(sqrt_k).safe_mul(bn::U256::from(sqrt_k))?; - market.amm.quote_asset_reserve = k - .safe_div(bn::U256::from(base_asset_reserve))? - .try_to_u128()?; + market.amm.set_quote_asset_reserve( + k.safe_div(bn::U256::from(base_asset_reserve))? + .try_to_u128()?, + ); validate!( - (quote_asset_reserve.cast::()? - market.amm.quote_asset_reserve.cast::()?) + (quote_asset_reserve.cast::()? - market.amm.quote_asset_reserve().cast::()?) .abs() < 100, ErrorCode::InvalidAmmDetected, "quote_asset_reserve passed doesnt reconcile enough {} vs {}", quote_asset_reserve.cast::()?, - market.amm.quote_asset_reserve.cast::()? + market.amm.quote_asset_reserve().cast::()? )?; - market.amm.sqrt_k = sqrt_k; + market.amm.set_sqrt_k(sqrt_k); let (_, terminal_quote_reserves, terminal_base_reserves) = amm::calculate_terminal_price_and_reserves(&market.amm)?; - market.amm.terminal_quote_asset_reserve = terminal_quote_reserves; + market + .amm + .set_terminal_quote_asset_reserve(terminal_quote_reserves); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, terminal_base_reserves)?; + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), terminal_base_reserves)?; - market.amm.max_base_asset_reserve = max_base_asset_reserve; - market.amm.min_base_asset_reserve = min_base_asset_reserve; + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); let reserve_price_after = market.amm.reserve_price()?; update_spreads(market, reserve_price_after, None)?; @@ -889,48 +918,56 @@ pub fn recenter_perp_market_amm( sqrt_k: u128, ) -> DriftResult { // calculate base/quote reserves for balanced terminal reserves - let swap_direction = if market.amm.base_asset_amount_with_amm > 0 { + let swap_direction = if market.amm.base_asset_amount_with_amm() > 0 { SwapDirection::Remove } else { SwapDirection::Add }; let (new_quote_asset_amount, new_base_asset_amount) = amm::calculate_swap_output( - market.amm.base_asset_amount_with_amm.unsigned_abs(), + market.amm.base_asset_amount_with_amm().unsigned_abs(), sqrt_k, swap_direction, sqrt_k, )?; - market.amm.base_asset_reserve = new_base_asset_amount; + market.amm.set_base_asset_reserve(new_base_asset_amount); let k = bn::U256::from(sqrt_k).safe_mul(bn::U256::from(sqrt_k))?; - market.amm.quote_asset_reserve = k - .safe_div(bn::U256::from(new_base_asset_amount))? - .try_to_u128()?; + market.amm.set_quote_asset_reserve( + k.safe_div(bn::U256::from(new_base_asset_amount))? + .try_to_u128()?, + ); validate!( - (new_quote_asset_amount.cast::()? - market.amm.quote_asset_reserve.cast::()?) - .abs() + (new_quote_asset_amount.cast::()? + - market.amm.quote_asset_reserve().cast::()?) + .abs() < 100, ErrorCode::InvalidAmmDetected, "quote_asset_reserve passed doesnt reconcile enough" )?; - market.amm.sqrt_k = sqrt_k; + market.amm.set_sqrt_k(sqrt_k); // todo: ensure correct terminal state cost for altering sqrt_k - market.amm.peg_multiplier = peg_multiplier; + market.amm.set_peg_multiplier(peg_multiplier); let (_, terminal_quote_reserves, terminal_base_reserves) = amm::calculate_terminal_price_and_reserves(&market.amm)?; - market.amm.terminal_quote_asset_reserve = terminal_quote_reserves; + market + .amm + .set_terminal_quote_asset_reserve(terminal_quote_reserves); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, terminal_base_reserves)?; + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), terminal_base_reserves)?; - market.amm.max_base_asset_reserve = max_base_asset_reserve; - market.amm.min_base_asset_reserve = min_base_asset_reserve; + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); let reserve_price_after = market.amm.reserve_price()?; update_spreads(market, reserve_price_after, None)?; @@ -946,13 +983,13 @@ pub fn calculate_perp_market_amm_summary_stats( exclude_liquidation_fee: bool, ) -> DriftResult { let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), spot_market, perp_market.pnl_pool.balance_type(), )?; let fee_pool_token_amount = get_token_amount( - perp_market.amm.fee_pool.scaled_balance, + perp_market.amm.fee_pool.scaled_balance(), spot_market, perp_market.amm.fee_pool.balance_type(), )?; @@ -968,7 +1005,7 @@ pub fn calculate_perp_market_amm_summary_stats( if exclude_liquidation_fee { new_total_fee_minus_distributions = new_total_fee_minus_distributions - .safe_sub(perp_market.amm.total_liquidation_fee.cast()?)?; + .safe_sub(perp_market.amm.total_liquidation_fee().cast()?)?; } Ok(new_total_fee_minus_distributions) diff --git a/programs/drift/src/controller/amm/tests.rs b/programs/drift/src/controller/amm/tests.rs index ba51779f5e..6eb0a5c2ac 100644 --- a/programs/drift/src/controller/amm/tests.rs +++ b/programs/drift/src/controller/amm/tests.rs @@ -10,14 +10,14 @@ use crate::state::perp_market::{InsuranceClaim, PoolBalance}; fn concentration_coef_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 500 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - base_asset_amount_with_amm: -12295081967, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (500 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + base_asset_amount_with_amm: (-12295081967).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -28,8 +28,8 @@ fn concentration_coef_tests() { let new_scale = 1; update_concentration_coef(&mut market, new_scale).unwrap(); - assert_eq!(market.amm.min_base_asset_reserve, 353556781219); - assert_eq!(market.amm.max_base_asset_reserve, 707100000000); + assert_eq!(market.amm.min_base_asset_reserve(), 353556781219); + assert_eq!(market.amm.max_base_asset_reserve(), 707100000000); let (orig_open_bids, orig_open_asks) = amm::calculate_market_open_bids_asks(&market.amm).unwrap(); @@ -38,20 +38,20 @@ fn concentration_coef_tests() { let new_scale = 2; update_concentration_coef(&mut market, new_scale).unwrap(); - assert_eq!(market.amm.min_base_asset_reserve, 414215889321); - assert_eq!(market.amm.max_base_asset_reserve, 603550000000); + assert_eq!(market.amm.min_base_asset_reserve(), 414215889321); + assert_eq!(market.amm.max_base_asset_reserve(), 603550000000); let new_scale = 5; update_concentration_coef(&mut market, new_scale).unwrap(); - assert_eq!(market.amm.min_base_asset_reserve, 461748734808); - assert_eq!(market.amm.max_base_asset_reserve, 541420000000); - let new_sqrt_k = market.amm.sqrt_k * new_scale; + assert_eq!(market.amm.min_base_asset_reserve(), 461748734808); + assert_eq!(market.amm.max_base_asset_reserve(), 541420000000); + let new_sqrt_k = market.amm.sqrt_k() * new_scale; let update_k_result = get_update_k_result(&market, bn::U192::from(new_sqrt_k), false).unwrap(); let adjustment_cost = cp_curve::adjust_k_cost(&mut market, &update_k_result).unwrap(); assert_eq!(adjustment_cost, 11_575_563); cp_curve::update_k(&mut market, &update_k_result).unwrap(); - assert_eq!(market.amm.sqrt_k, new_sqrt_k); + assert_eq!(market.amm.sqrt_k(), new_sqrt_k); let (open_bids, open_asks) = amm::calculate_market_open_bids_asks(&market.amm).unwrap(); assert_eq!(open_bids, 207313827452); @@ -66,32 +66,32 @@ fn concentration_coef_tests() { // different default market let mut market_balanced = PerpMarket::default_test(); - assert_eq!(market_balanced.amm.base_asset_amount_with_amm, 0); - assert_eq!(market_balanced.amm.sqrt_k, 100000000000); + assert_eq!(market_balanced.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market_balanced.amm.sqrt_k(), 100000000000); let new_scale = 20; update_concentration_coef(&mut market_balanced, new_scale).unwrap(); - assert_eq!(market_balanced.amm.min_base_asset_reserve, 97971020172); - assert_eq!(market_balanced.amm.max_base_asset_reserve, 102071000000); + assert_eq!(market_balanced.amm.min_base_asset_reserve(), 97971020172); + assert_eq!(market_balanced.amm.max_base_asset_reserve(), 102071000000); let new_scale = AMM_RESERVE_PRECISION; // too large, err assert!(update_concentration_coef(&mut market_balanced, new_scale).is_err()); - assert_eq!(market_balanced.amm.min_base_asset_reserve, 97971020172); - assert_eq!(market_balanced.amm.max_base_asset_reserve, 102071000000); + assert_eq!(market_balanced.amm.min_base_asset_reserve(), 97971020172); + assert_eq!(market_balanced.amm.max_base_asset_reserve(), 102071000000); let new_scale = 140000; // near limit, very little liquidity update_concentration_coef(&mut market_balanced, new_scale).unwrap(); - assert_eq!(market_balanced.amm.min_base_asset_reserve, 99999800000); - assert_eq!(market_balanced.amm.max_base_asset_reserve, 100000200000); + assert_eq!(market_balanced.amm.min_base_asset_reserve(), 99999800000); + assert_eq!(market_balanced.amm.max_base_asset_reserve(), 100000200000); - let new_sqrt_k = market_balanced.amm.sqrt_k * new_scale; + let new_sqrt_k = market_balanced.amm.sqrt_k() * new_scale; let update_k_result = get_update_k_result(&market_balanced, bn::U192::from(new_sqrt_k), false).unwrap(); let adjustment_cost = cp_curve::adjust_k_cost(&mut market_balanced, &update_k_result).unwrap(); assert_eq!(adjustment_cost, 0); cp_curve::update_k(&mut market_balanced, &update_k_result).unwrap(); - assert_eq!(market_balanced.amm.sqrt_k, new_sqrt_k); + assert_eq!(market_balanced.amm.sqrt_k(), new_sqrt_k); let (open_bids, open_asks) = amm::calculate_market_open_bids_asks(&market_balanced.amm).unwrap(); @@ -103,13 +103,13 @@ fn concentration_coef_tests() { fn formualic_k_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - base_asset_amount_with_amm: -12295081967, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + base_asset_amount_with_amm: (-12295081967).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -117,14 +117,20 @@ fn formualic_k_tests() { }; let (new_terminal_quote_reserve, new_terminal_base_reserve) = amm::calculate_terminal_reserves(&market.amm).unwrap(); - market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; + market + .amm + .set_terminal_quote_asset_reserve(new_terminal_quote_reserve); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, new_terminal_base_reserve) + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), new_terminal_base_reserve) .unwrap(); - market.amm.min_base_asset_reserve = min_base_asset_reserve; - market.amm.max_base_asset_reserve = max_base_asset_reserve; + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); - let prev_sqrt_k = market.amm.sqrt_k; + let prev_sqrt_k = market.amm.sqrt_k(); // let reserve_price = market.amm.reserve_price().unwrap(); let now = 10000; @@ -139,46 +145,49 @@ fn formualic_k_tests() { // zero funding cost let funding_cost: i128 = 0; formulaic_update_k(&mut market, &oracle_price_data, funding_cost, now).unwrap(); - assert_eq!(prev_sqrt_k, market.amm.sqrt_k); + assert_eq!(prev_sqrt_k, market.amm.sqrt_k()); assert_eq!( - market.amm.total_fee_minus_distributions, + market.amm.total_fee_minus_distributions(), 1000 * QUOTE_PRECISION as i128 ); // positive means amm supossedly paid $500 in funding payments for interval let funding_cost_2: i128 = (500 * QUOTE_PRECISION) as i128; formulaic_update_k(&mut market, &oracle_price_data, funding_cost_2, now).unwrap(); - assert_eq!(market.amm.sqrt_k, 499500000000); // max k decrease (.1%) - assert!(prev_sqrt_k > market.amm.sqrt_k); - assert_eq!(market.amm.total_fee_minus_distributions, 1000014768); //$.014768 acquired from slippage increase + assert_eq!(market.amm.sqrt_k(), 499500000000); // max k decrease (.1%) + assert!(prev_sqrt_k > market.amm.sqrt_k()); + assert_eq!(market.amm.total_fee_minus_distributions(), 1000014768); //$.014768 acquired from slippage increase // negative means amm recieved $500 in funding payments for interval let funding_cost_2: i128 = -((500 * QUOTE_PRECISION) as i128); formulaic_update_k(&mut market, &oracle_price_data, funding_cost_2, now).unwrap(); - assert_eq!(market.amm.sqrt_k, 499999500000); // max k increase (.1%) - assert_eq!(market.amm.total_fee_minus_distributions, 1000000013); //almost full spent from slippage decrease + assert_eq!(market.amm.sqrt_k(), 499999500000); // max k increase (.1%) + assert_eq!(market.amm.total_fee_minus_distributions(), 1000000013); //almost full spent from slippage decrease // negative means amm recieved $.001 in funding payments for interval let funding_cost_2: i128 = -((QUOTE_PRECISION / 1000) as i128); formulaic_update_k(&mut market, &oracle_price_data, funding_cost_2, now).unwrap(); // new numbers bc of increased sqrt_k precision - assert_eq!(market.amm.sqrt_k, 500015999983); // increase k by 1.000033x - assert_eq!(market.amm.total_fee_minus_distributions - 1000000013, -486); // ~$0.000486 spent from slippage decrease + assert_eq!(market.amm.sqrt_k(), 500015999983); // increase k by 1.000033x + assert_eq!( + market.amm.total_fee_minus_distributions() - 1000000013, + -486 + ); // ~$0.000486 spent from slippage decrease } #[test] fn iterative_bounds_formualic_k_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - base_asset_amount_with_amm: -12295081967, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + base_asset_amount_with_amm: (-12295081967).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -198,32 +207,32 @@ fn iterative_bounds_formualic_k_tests() { // negative funding cost let mut count = 0; - let mut prev_k = market.amm.sqrt_k; + let mut prev_k = market.amm.sqrt_k(); let mut new_k = 0; while prev_k != new_k && count < 10000 { let funding_cost = -(QUOTE_PRECISION as i128); - prev_k = market.amm.sqrt_k; + prev_k = market.amm.sqrt_k(); formulaic_update_k(&mut market, &oracle_price_data, funding_cost, now).unwrap(); - new_k = market.amm.sqrt_k; + new_k = market.amm.sqrt_k(); count += 1 } - assert_eq!(market.amm.base_asset_amount_with_amm, -12295081967); - assert_eq!(market.amm.sqrt_k, 10958340658498292); - assert_eq!(market.amm.total_fee_minus_distributions, 985_612_320); + assert_eq!(market.amm.base_asset_amount_with_amm(), -12295081967); + assert_eq!(market.amm.sqrt_k(), 10958340658498292); + assert_eq!(market.amm.total_fee_minus_distributions(), 985_612_320); } #[test] fn iterative_no_bounds_formualic_k_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - base_asset_amount_with_amm: -12295081967, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + base_asset_amount_with_amm: (-12295081967).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -243,31 +252,31 @@ fn iterative_no_bounds_formualic_k_tests() { // negative funding cost let mut count = 0; - let mut prev_k = market.amm.sqrt_k; + let mut prev_k = market.amm.sqrt_k(); let mut new_k = 0; while prev_k != new_k && count < 100000 && prev_k < MAX_SQRT_K * 99 / 100 { let funding_cost = -((QUOTE_PRECISION * 100000) as i128); - prev_k = market.amm.sqrt_k; + prev_k = market.amm.sqrt_k(); formulaic_update_k(&mut market, &oracle_price_data, funding_cost, now).unwrap(); - new_k = market.amm.sqrt_k; + new_k = market.amm.sqrt_k(); count += 1 } - assert_eq!(market.amm.base_asset_amount_with_amm, -12295081967); - assert_eq!(market.amm.sqrt_k, 991917456633894384209); // below MAX_SQRT_K - assert_eq!(market.amm.total_fee_minus_distributions, 985625029); + assert_eq!(market.amm.base_asset_amount_with_amm(), -12295081967); + assert_eq!(market.amm.sqrt_k(), 991917456633894384209); // below MAX_SQRT_K + assert_eq!(market.amm.total_fee_minus_distributions(), 985625029); } #[test] fn update_pool_balances_test_high_util_borrow() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 5122950819670000, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000, - base_asset_amount_with_amm: -122950819670000, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 5122950819670000.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000.into(), + base_asset_amount_with_amm: (-122950819670000).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -276,13 +285,13 @@ fn update_pool_balances_test_high_util_borrow() { let now = 33928058; let mut spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; // 100% util - spot_market.deposit_balance = 10_u128.pow(19_u32); - spot_market.borrow_balance = 10_u128.pow(19_u32); + spot_market.set_deposit_balance(10_u128.pow(19_u32)); + spot_market.set_borrow_balance(10_u128.pow(19_u32)); spot_market.deposit_token_twap = 10_u64.pow(16_u32); // would lead to a borrow @@ -300,7 +309,7 @@ fn update_pool_balances_test_high_util_borrow() { assert_eq!(to_settle_with_user, 0); // util is low => neg settle ok - spot_market.borrow_balance = 0; + spot_market.set_borrow_balance(0); let unsettled_pnl = -100; let to_settle_with_user = update_pool_balances( &mut market, @@ -313,7 +322,7 @@ fn update_pool_balances_test_high_util_borrow() { assert_eq!(to_settle_with_user, unsettled_pnl); // util is high - spot_market.borrow_balance = 10_u128.pow(19_u32); + spot_market.set_borrow_balance(10_u128.pow(19_u32)); // user has a little bit deposited => settle how much they have deposited update_spot_balances( 50, @@ -357,12 +366,12 @@ fn update_pool_balances_test_high_util_borrow() { fn update_pool_balances_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 5122950819670000, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000, - base_asset_amount_with_amm: -122950819670000, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, + base_asset_reserve: 5122950819670000.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000.into(), + base_asset_amount_with_amm: (-122950819670000).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), curve_update_intensity: 100, ..AMM::default() }, @@ -371,11 +380,11 @@ fn update_pool_balances_test() { let now = 33928058; let mut spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; - spot_market.deposit_balance = 10_u128.pow(19_u32); + spot_market.set_deposit_balance(10_u128.pow(19_u32)); spot_market.deposit_token_twap = 10_u64.pow(16_u32); let spot_position = SpotPosition::default(); @@ -422,7 +431,7 @@ fn update_pool_balances_test() { assert_eq!(pnl_pool_token_amount, 0); assert_eq!(amm_fee_pool_token_amount, 1); - market.amm.total_fee_minus_distributions = 0; + market.amm.set_total_fee_minus_distributions(0); update_pool_balances(&mut market, &mut spot_market, &spot_position, -1, now).unwrap(); let amm_fee_pool_token_amount = get_token_amount( market.amm.fee_pool.balance(), @@ -439,7 +448,9 @@ fn update_pool_balances_test() { assert_eq!(pnl_pool_token_amount, 2); assert_eq!(amm_fee_pool_token_amount, 0); - market.amm.total_fee_minus_distributions = 90_000 * QUOTE_PRECISION as i128; + market + .amm + .set_total_fee_minus_distributions(90_000 * QUOTE_PRECISION as i128); update_pool_balances( &mut market, &mut spot_market, @@ -464,7 +475,7 @@ fn update_pool_balances_test() { assert_eq!(amm_fee_pool_token_amount, 33333333); // negative fee pool - market.amm.total_fee_minus_distributions = -8_008_123_456; + market.amm.set_total_fee_minus_distributions(-8_008_123_456); update_pool_balances( &mut market, @@ -494,29 +505,29 @@ fn update_pool_balances_test() { fn update_pool_balances_fee_to_revenue_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 5122950819670000, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000, - base_asset_amount_with_amm: -122950819670000, - - total_exchange_fee: 10 * QUOTE_PRECISION, - total_fee: 10 * QUOTE_PRECISION as i128, - total_mm_fee: 990 * QUOTE_PRECISION as i128, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, - total_liquidation_fee: QUOTE_PRECISION, + base_asset_reserve: 5122950819670000.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000.into(), + base_asset_amount_with_amm: (-122950819670000).into(), + + total_exchange_fee: (10 * QUOTE_PRECISION).into(), + total_fee: (10 * QUOTE_PRECISION as i128).into(), + total_mm_fee: (990 * QUOTE_PRECISION as i128).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), + total_liquidation_fee: QUOTE_PRECISION.into(), net_revenue_since_last_funding: 10000 * QUOTE_PRECISION as i64, curve_update_intensity: 100, fee_pool: PoolBalance { - scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -530,18 +541,18 @@ fn update_pool_balances_fee_to_revenue_test() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance::default(), ..SpotMarket::default() }; - let prev_fee_pool = market.amm.fee_pool.scaled_balance; - let prev_pnl_pool = market.amm.fee_pool.scaled_balance; - let prev_rev_pool = spot_market.revenue_pool.scaled_balance; + let prev_fee_pool = market.amm.fee_pool.scaled_balance(); + let prev_pnl_pool = market.amm.fee_pool.scaled_balance(); + let prev_rev_pool = spot_market.revenue_pool.scaled_balance(); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); assert_eq!( get_token_amount( @@ -555,7 +566,7 @@ fn update_pool_balances_fee_to_revenue_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit ) @@ -566,68 +577,68 @@ fn update_pool_balances_fee_to_revenue_test() { let spot_position = SpotPosition::default(); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 50000000000000000); // under FEE_POOL_TO_REVENUE_POOL_THRESHOLD - assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.fee_pool.scaled_balance(), 50000000000000000); // under FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.pnl_pool.scaled_balance(), 50000000000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); - assert!(market.amm.fee_pool.scaled_balance == prev_fee_pool); - assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); - assert!(spot_market.revenue_pool.scaled_balance == prev_rev_pool); + assert!(market.amm.fee_pool.scaled_balance() == prev_fee_pool); + assert_eq!(market.pnl_pool.scaled_balance(), prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance() == prev_rev_pool); // add FEE_POOL_TO_REVENUE_POOL_THRESHOLD let prev_fee_pool_2 = (FEE_POOL_TO_REVENUE_POOL_THRESHOLD + 50 * QUOTE_PRECISION) * SPOT_BALANCE_PRECISION; - market.amm.fee_pool.scaled_balance = prev_fee_pool_2; + market.amm.fee_pool.set_scaled_balance(prev_fee_pool_2); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(market.amm.total_fee_withdrawn, 5000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 5000000000000000); - assert_eq!(market.amm.fee_pool.scaled_balance, 295000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.pnl_pool.scaled_balance(), 50000000000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 5000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 5000000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 295000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD - assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool_2); - assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); - assert!(spot_market.revenue_pool.scaled_balance > prev_rev_pool); + assert!(market.amm.fee_pool.scaled_balance() < prev_fee_pool_2); + assert_eq!(market.pnl_pool.scaled_balance(), prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance() > prev_rev_pool); market.insurance_claim.quote_max_insurance = 1; // add min insurance update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.total_fee_withdrawn, 5000001); - assert_eq!(spot_market.revenue_pool.scaled_balance, 5000001000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 5000001); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 5000001000000000); market.insurance_claim.quote_max_insurance = 100000000; // add lots of insurance update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.total_fee_withdrawn, 6000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 6000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 6000000000000000); } #[test] fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 5122950819670000, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000, - base_asset_amount_with_amm: -122950819670000, - - total_exchange_fee: 10 * QUOTE_PRECISION, - total_fee: 10 * QUOTE_PRECISION as i128, - total_mm_fee: 990 * QUOTE_PRECISION as i128, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION as i128, - total_liquidation_fee: QUOTE_PRECISION, + base_asset_reserve: 5122950819670000.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000.into(), + base_asset_amount_with_amm: (-122950819670000).into(), + + total_exchange_fee: (10 * QUOTE_PRECISION).into(), + total_fee: (10 * QUOTE_PRECISION as i128).into(), + total_mm_fee: (990 * QUOTE_PRECISION as i128).into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION as i128).into(), + total_liquidation_fee: QUOTE_PRECISION.into(), net_revenue_since_last_funding: QUOTE_PRECISION as i64, curve_update_intensity: 100, fee_pool: PoolBalance { - scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -641,18 +652,18 @@ fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (100 * QUOTE_PRECISION * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance::default(), ..SpotMarket::default() }; - let prev_fee_pool = market.amm.fee_pool.scaled_balance; - let prev_pnl_pool = market.amm.fee_pool.scaled_balance; - let prev_rev_pool = spot_market.revenue_pool.scaled_balance; + let prev_fee_pool = market.amm.fee_pool.scaled_balance(); + let prev_pnl_pool = market.amm.fee_pool.scaled_balance(); + let prev_rev_pool = spot_market.revenue_pool.scaled_balance(); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); assert_eq!( get_token_amount( @@ -666,7 +677,7 @@ fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit ) @@ -677,71 +688,71 @@ fn update_pool_balances_fee_to_revenue_low_amm_revenue_test() { let spot_position = SpotPosition::default(); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 50000000000000000); // under FEE_POOL_TO_REVENUE_POOL_THRESHOLD - assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.fee_pool.scaled_balance(), 50000000000000000); // under FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.pnl_pool.scaled_balance(), 50000000000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); - assert!(market.amm.fee_pool.scaled_balance == prev_fee_pool); - assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); - assert!(spot_market.revenue_pool.scaled_balance == prev_rev_pool); + assert!(market.amm.fee_pool.scaled_balance() == prev_fee_pool); + assert_eq!(market.pnl_pool.scaled_balance(), prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance() == prev_rev_pool); // add FEE_POOL_TO_REVENUE_POOL_THRESHOLD let prev_fee_pool_2 = (FEE_POOL_TO_REVENUE_POOL_THRESHOLD + 50 * QUOTE_PRECISION) * SPOT_BALANCE_PRECISION; - market.amm.fee_pool.scaled_balance = prev_fee_pool_2; + market.amm.fee_pool.set_scaled_balance(prev_fee_pool_2); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 50000000000000000); - assert_eq!(market.amm.total_fee_withdrawn, 1000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 1000000000000000); - assert_eq!(market.amm.fee_pool.scaled_balance, 299000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD + assert_eq!(market.pnl_pool.scaled_balance(), 50000000000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 1000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 1000000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 299000000000000000); // > FEE_POOL_TO_REVENUE_POOL_THRESHOLD - assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool_2); - assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); - assert!(spot_market.revenue_pool.scaled_balance > prev_rev_pool); + assert!(market.amm.fee_pool.scaled_balance() < prev_fee_pool_2); + assert_eq!(market.pnl_pool.scaled_balance(), prev_pnl_pool); + assert!(spot_market.revenue_pool.scaled_balance() > prev_rev_pool); market.insurance_claim.quote_max_insurance = 1; // add min insurance market.amm.net_revenue_since_last_funding = 1; update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.total_fee_withdrawn, 1000001); - assert_eq!(spot_market.revenue_pool.scaled_balance, 1000001000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 1000001); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 1000001000000000); market.insurance_claim.quote_max_insurance = 100000000; // add lots of insurance market.amm.net_revenue_since_last_funding = 100000000; update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.total_fee_withdrawn, 6000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 6000000000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 6000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 6000000000000000); } #[test] fn update_pool_balances_revenue_to_fee_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 5122950819670000, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000, - base_asset_amount_with_amm: -122950819670000, + base_asset_reserve: 5122950819670000.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000.into(), + base_asset_amount_with_amm: (-122950819670000).into(), - total_exchange_fee: 10 * QUOTE_PRECISION, - total_fee: 10 * QUOTE_PRECISION as i128, - total_mm_fee: 990 * QUOTE_PRECISION as i128, - total_fee_minus_distributions: -(10000 * QUOTE_PRECISION as i128), + total_exchange_fee: (10 * QUOTE_PRECISION).into(), + total_fee: (10 * QUOTE_PRECISION as i128).into(), + total_mm_fee: (990 * QUOTE_PRECISION as i128).into(), + total_fee_minus_distributions: (-(10000 * QUOTE_PRECISION as i128)).into(), curve_update_intensity: 100, fee_pool: PoolBalance { - scaled_balance: 50 * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 50 * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -750,12 +761,12 @@ fn update_pool_balances_revenue_to_fee_test() { let mut now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 100 * SPOT_BALANCE_PRECISION, + scaled_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, decimals: 6, @@ -763,12 +774,12 @@ fn update_pool_balances_revenue_to_fee_test() { }; let spot_position = SpotPosition::default(); - let prev_fee_pool = market.amm.fee_pool.scaled_balance; - let prev_pnl_pool = market.amm.fee_pool.scaled_balance; - let prev_rev_pool = spot_market.revenue_pool.scaled_balance; - let prev_tfmd = market.amm.total_fee_minus_distributions; + let prev_fee_pool = market.amm.fee_pool.scaled_balance(); + let prev_pnl_pool = market.amm.fee_pool.scaled_balance(); + let prev_rev_pool = spot_market.revenue_pool.scaled_balance(); + let prev_tfmd = market.amm.total_fee_minus_distributions(); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); assert_eq!(spot_market.insurance_fund.revenue_settle_period, 0); spot_market.insurance_fund.revenue_settle_period = 0; @@ -776,11 +787,13 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(res, 0); spot_market.insurance_fund.revenue_settle_period = 1; - spot_market.revenue_pool.scaled_balance = 0; + spot_market.revenue_pool.set_scaled_balance(0); let res = settle_revenue_to_insurance_fund(200000000, 0, &mut spot_market, now + 1, false).unwrap(); assert_eq!(res, 0); - spot_market.revenue_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION; + spot_market + .revenue_pool + .set_scaled_balance(100 * SPOT_BALANCE_PRECISION); now += 2; assert_eq!( @@ -795,7 +808,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!( get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit ) @@ -803,51 +816,57 @@ fn update_pool_balances_revenue_to_fee_test() { 200 * QUOTE_PRECISION ); assert_eq!( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), 100 * SPOT_BALANCE_PRECISION ); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); assert_eq!( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), 5 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.pnl_pool.scaled_balance, 95 * SPOT_BALANCE_PRECISION); assert_eq!( - spot_market.revenue_pool.scaled_balance, + market.pnl_pool.scaled_balance(), + 95 * SPOT_BALANCE_PRECISION + ); + assert_eq!( + spot_market.revenue_pool.scaled_balance(), 100 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(market.amm.total_fee_minus_distributions, prev_tfmd); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), prev_tfmd); - assert!(market.amm.fee_pool.scaled_balance < prev_fee_pool); - assert_eq!(market.pnl_pool.scaled_balance > prev_pnl_pool, true); + assert!(market.amm.fee_pool.scaled_balance() < prev_fee_pool); + assert_eq!(market.pnl_pool.scaled_balance() > prev_pnl_pool, true); assert_eq!( - spot_market.revenue_pool.scaled_balance == prev_rev_pool, + spot_market.revenue_pool.scaled_balance() == prev_rev_pool, true ); assert_eq!(market.insurance_claim.revenue_withdraw_since_last_settle, 0); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 0); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!(spot_market.deposit_balance(), 200 * SPOT_BALANCE_PRECISION); assert_eq!( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), 100 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.amm.total_fee_minus_distributions, -10000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -10000000000); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); assert_eq!( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), 105 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.pnl_pool.scaled_balance, 95 * SPOT_BALANCE_PRECISION); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(market.amm.total_fee_minus_distributions, -9900000000); + assert_eq!( + market.pnl_pool.scaled_balance(), + 95 * SPOT_BALANCE_PRECISION + ); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), -9900000000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, 100000000 @@ -855,7 +874,7 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, now); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -865,50 +884,61 @@ fn update_pool_balances_revenue_to_fee_test() { // calling multiple times doesnt effect other than fee pool -> pnl pool update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); assert_eq!( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), 5 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.pnl_pool.scaled_balance, 195 * SPOT_BALANCE_PRECISION); - assert_eq!(market.amm.total_fee_minus_distributions, -9900000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!( + market.pnl_pool.scaled_balance(), + 195 * SPOT_BALANCE_PRECISION + ); + assert_eq!(market.amm.total_fee_minus_distributions(), -9900000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); assert_eq!( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), 5 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.pnl_pool.scaled_balance, 195 * SPOT_BALANCE_PRECISION); - assert_eq!(market.amm.total_fee_minus_distributions, -9900000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!( + market.pnl_pool.scaled_balance(), + 195 * SPOT_BALANCE_PRECISION + ); + assert_eq!(market.amm.total_fee_minus_distributions(), -9900000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); // add deposits and revenue to pool - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); - spot_market.revenue_pool.scaled_balance = 9900000001000; + assert_eq!(spot_market.deposit_balance(), 200 * SPOT_BALANCE_PRECISION); + spot_market.revenue_pool.set_scaled_balance(9900000001000); let spot_market_backup = spot_market; let market_backup = market; assert!(update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).is_err()); // assert is_err if any way has revenue pool above deposit balances spot_market = spot_market_backup; market = market_backup; - spot_market.deposit_balance += 9900000001000; + spot_market.set_deposit_balance( + spot_market + .deposit_balance() + .safe_add(9900000001000) + .unwrap(), + ); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap() as u64; - assert_eq!(spot_market.deposit_balance, 10100000001000); + assert_eq!(spot_market.deposit_balance(), 10100000001000); assert_eq!(spot_market_vault_amount, 10100000001); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(spot_market.deposit_balance, 10100000001000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); - assert_eq!(market.amm.fee_pool.scaled_balance, 105000000000); - assert_eq!(market.pnl_pool.scaled_balance, 195000000000); - assert_eq!(market.amm.total_fee_minus_distributions, -9800000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(spot_market.deposit_balance(), 10100000001000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9800000001000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 105000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 195000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -9800000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, market.insurance_claim.max_revenue_withdraw_per_period as i64 @@ -917,11 +947,11 @@ fn update_pool_balances_revenue_to_fee_test() { // calling again only does fee -> pnl pool update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 5000000000); - assert_eq!(market.pnl_pool.scaled_balance, 295000000000); - assert_eq!(market.amm.total_fee_minus_distributions, -9800000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 5000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 295000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -9800000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9800000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, market.insurance_claim.max_revenue_withdraw_per_period as i64 @@ -930,11 +960,11 @@ fn update_pool_balances_revenue_to_fee_test() { // calling again does nothing update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 5000000000); - assert_eq!(market.pnl_pool.scaled_balance, 295000000000); - assert_eq!(market.amm.total_fee_minus_distributions, -9800000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 5000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 295000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -9800000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9800000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, market.insurance_claim.max_revenue_withdraw_per_period as i64 @@ -943,7 +973,7 @@ fn update_pool_balances_revenue_to_fee_test() { // do a revenue settlement to allow up to max again assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33928059); - assert_eq!(spot_market.deposit_balance, 10100000001000); + assert_eq!(spot_market.deposit_balance(), 10100000001000); spot_market.insurance_fund.total_factor = 1; spot_market.insurance_fund.revenue_settle_period = 1; @@ -958,24 +988,24 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(res, 9800000001); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap() as u64; - assert_eq!(spot_market.deposit_balance, 300000000000); // 100000000 was added to market fee/pnl pool - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance(), 300000000000); // 100000000 was added to market fee/pnl pool + assert_eq!(spot_market.borrow_balance(), 0); assert_eq!(spot_market_vault_amount, 300000000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); assert_eq!( spot_market.insurance_fund.last_revenue_settle_ts, now + 3600 ); // add deposits and revenue to pool - spot_market.revenue_pool.scaled_balance = 9800000001000; + spot_market.revenue_pool.set_scaled_balance(9800000001000); let market_backup = market; let spot_market_backup = spot_market; assert!( @@ -983,13 +1013,18 @@ fn update_pool_balances_revenue_to_fee_test() { ); // assert is_err if any way has revenue pool above deposit balances market = market_backup; spot_market = spot_market_backup; - spot_market.deposit_balance += 9800000000001; + spot_market.set_deposit_balance( + spot_market + .deposit_balance() + .safe_add(9800000000001) + .unwrap(), + ); - assert_eq!(market.amm.fee_pool.scaled_balance, 5000000000); - assert_eq!(market.pnl_pool.scaled_balance, 295000000000); - assert_eq!(market.amm.total_fee_minus_distributions, -9800000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9800000001000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 5000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 295000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -9800000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9800000001000); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928060); assert_eq!( spot_market.insurance_fund.last_revenue_settle_ts, @@ -1001,11 +1036,11 @@ fn update_pool_balances_revenue_to_fee_test() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33931660); assert_eq!(spot_market.insurance_fund.last_revenue_settle_ts, 33931660); - assert_eq!(market.amm.fee_pool.scaled_balance, 205000000000); - assert_eq!(market.pnl_pool.scaled_balance, 295000000000); - assert_eq!(market.amm.total_fee_minus_distributions, -9600000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9600000001000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 205000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 295000000000); + assert_eq!(market.amm.total_fee_minus_distributions(), -9600000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9600000001000); assert_eq!( market.insurance_claim.revenue_withdraw_since_last_settle, market.insurance_claim.max_revenue_withdraw_per_period as i64 @@ -1016,26 +1051,26 @@ fn update_pool_balances_revenue_to_fee_test() { fn update_pool_balances_revenue_to_fee_devnet_state_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 916769960813655, - quote_asset_reserve: 932609131198775, - sqrt_k: 924655631391254, - peg_multiplier: 20242531, - base_asset_amount_with_amm: 7563264495267, - - quote_asset_amount: -90559143969, - - total_exchange_fee: 18223810834, - total_fee: 130757047337, - total_mm_fee: 112696236155, - total_fee_minus_distributions: 338762376993, - total_fee_withdrawn: 161959731500, - total_liquidation_fee: 152847899222, - total_social_loss: 74768391959, + base_asset_reserve: 916769960813655.into(), + quote_asset_reserve: 932609131198775.into(), + sqrt_k: 924655631391254.into(), + peg_multiplier: 20242531.into(), + base_asset_amount_with_amm: 7563264495267.into(), + + quote_asset_amount: (-90559143969).into(), + + total_exchange_fee: 18223810834.into(), + total_fee: 130757047337.into(), + total_mm_fee: 112696236155.into(), + total_fee_minus_distributions: 338762376993.into(), + total_fee_withdrawn: 161959731500.into(), + total_liquidation_fee: 152847899222.into(), + total_social_loss: 74768391959.into(), curve_update_intensity: 100, net_revenue_since_last_funding: 229827181, fee_pool: PoolBalance { - scaled_balance: 1821 * SPOT_BALANCE_PRECISION, + scaled_balance: (1821 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1043,7 +1078,7 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 381047 * SPOT_BALANCE_PRECISION, + scaled_balance: (381047 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1057,12 +1092,12 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 100 * SPOT_BALANCE_PRECISION, + scaled_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, decimals: 6, @@ -1070,35 +1105,35 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { }; let spot_position = SpotPosition::default(); - let prev_fee_pool = market.amm.fee_pool.scaled_balance; - let prev_pnl_pool = market.amm.fee_pool.scaled_balance; - let prev_rev_pool = spot_market.revenue_pool.scaled_balance; - let prev_tfmd = market.amm.total_fee_minus_distributions; + let prev_fee_pool = market.amm.fee_pool.scaled_balance(); + let prev_pnl_pool = market.amm.fee_pool.scaled_balance(); + let prev_rev_pool = spot_market.revenue_pool.scaled_balance(); + let prev_tfmd = market.amm.total_fee_minus_distributions(); update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 1821000000000); - assert_eq!(market.pnl_pool.scaled_balance, 381047000000000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 1821000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 381047000000000); assert_eq!( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), 100 * SPOT_BALANCE_PRECISION ); - assert_eq!(market.amm.total_fee_withdrawn, 161959731500); - assert_eq!(market.amm.total_fee_minus_distributions, prev_tfmd); + assert_eq!(market.amm.total_fee_withdrawn(), 161959731500); + assert_eq!(market.amm.total_fee_minus_distributions(), prev_tfmd); - assert_eq!(market.amm.fee_pool.scaled_balance, prev_fee_pool); - assert_eq!(market.pnl_pool.scaled_balance > prev_pnl_pool, true); + assert_eq!(market.amm.fee_pool.scaled_balance(), prev_fee_pool); + assert_eq!(market.pnl_pool.scaled_balance() > prev_pnl_pool, true); assert_eq!( - spot_market.revenue_pool.scaled_balance == prev_rev_pool, + spot_market.revenue_pool.scaled_balance() == prev_rev_pool, true ); assert_eq!(market.insurance_claim.revenue_withdraw_since_last_settle, 0); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 0); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); + assert_eq!(spot_market.deposit_balance(), 200 * SPOT_BALANCE_PRECISION); assert_eq!( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), 100 * SPOT_BALANCE_PRECISION ); } @@ -1107,26 +1142,26 @@ fn update_pool_balances_revenue_to_fee_devnet_state_test() { fn update_pool_balances_revenue_to_fee_new_market() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 6165301473685, - quote_asset_reserve: 6165301473685, - sqrt_k: 6165301473685, - peg_multiplier: 324000000, - base_asset_amount_with_amm: 0, - - quote_asset_amount: 0, - - total_exchange_fee: 26000, - total_fee: 26000, - total_mm_fee: 0, - total_fee_minus_distributions: 26000, - total_fee_withdrawn: 0, - total_liquidation_fee: 0, - total_social_loss: 0, + base_asset_reserve: 6165301473685.into(), + quote_asset_reserve: 6165301473685.into(), + sqrt_k: 6165301473685.into(), + peg_multiplier: 324000000.into(), + base_asset_amount_with_amm: 0.into(), + + quote_asset_amount: 0.into(), + + total_exchange_fee: 26000.into(), + total_fee: 26000.into(), + total_mm_fee: 0.into(), + total_fee_minus_distributions: 26000.into(), + total_fee_withdrawn: 0.into(), + total_liquidation_fee: 0.into(), + total_social_loss: 0.into(), curve_update_intensity: 100, net_revenue_since_last_funding: 0, fee_pool: PoolBalance { - scaled_balance: 0, + scaled_balance: 0.into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1134,7 +1169,7 @@ fn update_pool_balances_revenue_to_fee_new_market() { ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 0, + scaled_balance: 0.into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1148,12 +1183,12 @@ fn update_pool_balances_revenue_to_fee_new_market() { let now = 33928058; let mut spot_market = SpotMarket { - deposit_balance: 200 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 100 * SPOT_BALANCE_PRECISION, + scaled_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, decimals: 6, @@ -1162,22 +1197,22 @@ fn update_pool_balances_revenue_to_fee_new_market() { let spot_position = SpotPosition::default(); // let prev_fee_pool = market.amm.fee_pool.scaled_balance; - let prev_pnl_pool = market.amm.fee_pool.scaled_balance; - let prev_rev_pool = spot_market.revenue_pool.scaled_balance; + let prev_pnl_pool = market.amm.fee_pool.scaled_balance(); + let prev_rev_pool = spot_market.revenue_pool.scaled_balance(); // let prev_tfmd = market.amm.total_fee_minus_distributions; update_pool_balances(&mut market, &mut spot_market, &spot_position, 0, now).unwrap(); - assert_eq!(market.amm.fee_pool.scaled_balance, 50000000000); // $50 + assert_eq!(market.amm.fee_pool.scaled_balance(), 50000000000); // $50 - assert_eq!(market.pnl_pool.scaled_balance, 0); - assert_eq!(spot_market.revenue_pool.scaled_balance, 50000000000); - assert_eq!(market.amm.total_fee_withdrawn, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 50026000); + assert_eq!(market.pnl_pool.scaled_balance(), 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 50000000000); + assert_eq!(market.amm.total_fee_withdrawn(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 50026000); - assert_eq!(market.pnl_pool.scaled_balance, prev_pnl_pool); + assert_eq!(market.pnl_pool.scaled_balance(), prev_pnl_pool); assert_eq!( - spot_market.revenue_pool.scaled_balance < prev_rev_pool, + spot_market.revenue_pool.scaled_balance() < prev_rev_pool, true ); assert_eq!( @@ -1187,8 +1222,8 @@ fn update_pool_balances_revenue_to_fee_new_market() { assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 33928058); market.insurance_claim.max_revenue_withdraw_per_period = 100000000 * 2; - assert_eq!(spot_market.deposit_balance, 200 * SPOT_BALANCE_PRECISION); - assert_eq!(spot_market.revenue_pool.scaled_balance, 50000000000); + assert_eq!(spot_market.deposit_balance(), 200 * SPOT_BALANCE_PRECISION); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 50000000000); } mod revenue_pool_transfer_tests { @@ -1204,10 +1239,10 @@ mod revenue_pool_transfer_tests { // Set up input parameters let mut market = PerpMarket { amm: AMM { - total_social_loss: 0, - total_liquidation_fee: 0, + total_social_loss: 0.into(), + total_liquidation_fee: 0.into(), net_revenue_since_last_funding: 0, - total_fee_withdrawn: 0, + total_fee_withdrawn: 0.into(), ..AMM::default() }, insurance_claim: InsuranceClaim { @@ -1220,12 +1255,12 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (20020 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 100 * SPOT_BALANCE_PRECISION, + scaled_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, decimals: 6, @@ -1294,8 +1329,8 @@ mod revenue_pool_transfer_tests { // Test case 2: When amm_budget_surplus is greater than zero and max_revenue_to_settle is greater than zero, revenue_pool_transfer should be greater than zero market.amm.net_revenue_since_last_funding = 1000 * QUOTE_PRECISION_I64; - market.amm.total_fee_withdrawn = 500 * QUOTE_PRECISION; - market.amm.total_liquidation_fee = 300 * QUOTE_PRECISION; + market.amm.set_total_fee_withdrawn(500 * QUOTE_PRECISION); + market.amm.set_total_liquidation_fee(300 * QUOTE_PRECISION); market.insurance_claim.quote_max_insurance = 100 * QUOTE_PRECISION_U64; market.insurance_claim.quote_settled_insurance = 50 * QUOTE_PRECISION_U64; market.insurance_claim.revenue_withdraw_since_last_settle = 200 * QUOTE_PRECISION_I64; @@ -1338,8 +1373,8 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 20 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; - market.amm.total_exchange_fee = 3000 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); + market.amm.set_total_exchange_fee(3000 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1352,7 +1387,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1365,8 +1400,8 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; - market.amm.total_liquidation_fee = 800 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); + market.amm.set_total_liquidation_fee(800 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1379,8 +1414,8 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; - market.amm.total_liquidation_fee = 200 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); + market.amm.set_total_liquidation_fee(200 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1388,7 +1423,7 @@ mod revenue_pool_transfer_tests { terminal_state_surplus, ); let expected_result: i128 = (amm_fee_pool_token_amount_after - - market.amm.total_social_loss + - market.amm.total_social_loss() - FEE_POOL_TO_REVENUE_POOL_THRESHOLD) as i128; assert_eq!(result.unwrap(), expected_result); @@ -1396,7 +1431,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 600 * QUOTE_PRECISION; + market.amm.set_total_social_loss(600 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1409,7 +1444,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after: u128 = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 40 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1422,7 +1457,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = 1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1431,13 +1466,15 @@ mod revenue_pool_transfer_tests { ); assert_eq!(result.unwrap(), 150000000); - spot_market.revenue_pool.scaled_balance = 15000 * SPOT_BALANCE_PRECISION; + spot_market + .revenue_pool + .set_scaled_balance(15000 * SPOT_BALANCE_PRECISION); //Test case 11: claim max_revenue_withdraw_per_period let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = -1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 1000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1450,7 +1487,7 @@ mod revenue_pool_transfer_tests { let amm_fee_pool_token_amount_after = 500 * QUOTE_PRECISION; let terminal_state_surplus = -1000 * QUOTE_PRECISION_I128; market.insurance_claim.max_revenue_withdraw_per_period = 2000 * QUOTE_PRECISION_U64; - market.amm.total_social_loss = 100 * QUOTE_PRECISION; + market.amm.set_total_social_loss(100 * QUOTE_PRECISION); let result = calculate_revenue_pool_transfer( &market, &spot_market, @@ -1465,20 +1502,20 @@ mod revenue_pool_transfer_tests { // Set up input parameters let mut market = PerpMarket { amm: AMM { - total_social_loss: 0, - total_liquidation_fee: 0, - total_fee_withdrawn: 0, + total_social_loss: 0.into(), + total_liquidation_fee: 0.into(), + total_fee_withdrawn: 0.into(), net_revenue_since_last_funding: 169 * QUOTE_PRECISION_I64, - total_fee_minus_distributions: 1420420420420, - total_exchange_fee: 420420420420, + total_fee_minus_distributions: 1420420420420.into(), + total_exchange_fee: 420420420420.into(), fee_pool: PoolBalance { - scaled_balance: 81000 * SPOT_BALANCE_PRECISION, + scaled_balance: (81000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 10000 * SPOT_BALANCE_PRECISION, + scaled_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, insurance_claim: InsuranceClaim { @@ -1491,13 +1528,13 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020 * SPOT_BALANCE_PRECISION, + deposit_balance: (20020 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 20020 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 10000 * SPOT_BALANCE_PRECISION, + scaled_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, insurance_fund: InsuranceFund { @@ -1523,7 +1560,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 100); - assert_eq!(spot_market.revenue_pool.scaled_balance, 10065000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 10065000000000); // revenue pool not yet settled let now = 10000; @@ -1538,7 +1575,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 100); - assert_eq!(spot_market.revenue_pool.scaled_balance, 10065000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 10065000000000); // revenue pool settled but negative revenue for hour spot_market.insurance_fund.last_revenue_settle_ts = 3600 + 100; @@ -1556,7 +1593,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 100); - assert_eq!(spot_market.revenue_pool.scaled_balance, 10065000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 10065000000000); // revenue pool settled and positive revenue for hour spot_market.insurance_fund.last_revenue_settle_ts = 3600 + 100; @@ -1574,7 +1611,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 10000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 10065000169000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 10065000169000); } #[test] @@ -1582,20 +1619,20 @@ mod revenue_pool_transfer_tests { // Set up input parameters let mut market = PerpMarket { amm: AMM { - total_social_loss: 0, - total_liquidation_fee: 0, - total_fee_withdrawn: 0, + total_social_loss: 0.into(), + total_liquidation_fee: 0.into(), + total_fee_withdrawn: 0.into(), net_revenue_since_last_funding: 169 * QUOTE_PRECISION_I64, - total_fee_minus_distributions: -6969696969, - total_exchange_fee: 420420420420, + total_fee_minus_distributions: (-6969696969).into(), + total_exchange_fee: 420420420420.into(), fee_pool: PoolBalance { - scaled_balance: 81000 * SPOT_BALANCE_PRECISION, + scaled_balance: (81000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: 10000 * SPOT_BALANCE_PRECISION, + scaled_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, insurance_claim: InsuranceClaim { @@ -1608,13 +1645,13 @@ mod revenue_pool_transfer_tests { ..PerpMarket::default() }; let mut spot_market = SpotMarket { - deposit_balance: 20020000 * SPOT_BALANCE_PRECISION, + deposit_balance: (20020000 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 20020000 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 10000 * SPOT_BALANCE_PRECISION, + scaled_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, insurance_fund: InsuranceFund { @@ -1640,7 +1677,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 100); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9935000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9935000000000); // revenue pool not yet settled let now = 10000; @@ -1655,7 +1692,7 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 100); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9935000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9935000000000); // revenue pool settled and negative/positive revenue for hour irrelevant for withdraw spot_market.insurance_fund.last_revenue_settle_ts = 3600 + 100; @@ -1673,6 +1710,6 @@ mod revenue_pool_transfer_tests { assert_eq!(to_settle_with_user, -100); assert_eq!(market.insurance_claim.last_revenue_withdraw_ts, 10000); - assert_eq!(spot_market.revenue_pool.scaled_balance, 9870000000000); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 9870000000000); } } diff --git a/programs/drift/src/controller/funding.rs b/programs/drift/src/controller/funding.rs index eaa2dd9833..3293bf6d2b 100644 --- a/programs/drift/src/controller/funding.rs +++ b/programs/drift/src/controller/funding.rs @@ -46,9 +46,9 @@ pub fn settle_funding_payment( let amm: &AMM = &market.amm; let amm_cumulative_funding_rate = if user.perp_positions[position_index].base_asset_amount > 0 { - amm.cumulative_funding_rate_long + amm.cumulative_funding_rate_long() } else { - amm.cumulative_funding_rate_short + amm.cumulative_funding_rate_short() }; if amm_cumulative_funding_rate @@ -72,8 +72,8 @@ pub fn settle_funding_payment( market_index: market_position.market_index, funding_payment: market_funding_payment, //10e13 user_last_cumulative_funding: market_position.last_cumulative_funding_rate, //10e14 - amm_cumulative_funding_long: amm.cumulative_funding_rate_long, //10e14 - amm_cumulative_funding_short: amm.cumulative_funding_rate_short, //10e14 + amm_cumulative_funding_long: amm.cumulative_funding_rate_long(), //10e14 + amm_cumulative_funding_short: amm.cumulative_funding_rate_short(), //10e14 base_asset_amount: market_position.base_asset_amount, //10e13 }); @@ -105,9 +105,9 @@ pub fn settle_funding_payments( let amm_cumulative_funding_rate = if user.perp_positions[position_index].base_asset_amount > 0 { - amm.cumulative_funding_rate_long + amm.cumulative_funding_rate_long() } else { - amm.cumulative_funding_rate_short + amm.cumulative_funding_rate_short() }; if amm_cumulative_funding_rate @@ -131,8 +131,8 @@ pub fn settle_funding_payments( market_index: market_position.market_index, funding_payment: market_funding_payment, //1e6 user_last_cumulative_funding: market_position.last_cumulative_funding_rate, //1e9 - amm_cumulative_funding_long: amm.cumulative_funding_rate_long, //1e9 - amm_cumulative_funding_short: amm.cumulative_funding_rate_short, //1e9 + amm_cumulative_funding_long: amm.cumulative_funding_rate_long(), //1e9 + amm_cumulative_funding_short: amm.cumulative_funding_rate_short(), //1e9 base_asset_amount: market_position.base_asset_amount, //1e9 }); @@ -260,15 +260,19 @@ pub fn update_funding_rate( formulaic_update_k(market, oracle_price_data, funding_imbalance_cost, now)?; } - market.amm.cumulative_funding_rate_long = market - .amm - .cumulative_funding_rate_long - .safe_add(funding_rate_long)?; + market.amm.set_cumulative_funding_rate_long( + market + .amm + .cumulative_funding_rate_long() + .safe_add(funding_rate_long)?, + ); - market.amm.cumulative_funding_rate_short = market - .amm - .cumulative_funding_rate_short - .safe_add(funding_rate_short)?; + market.amm.set_cumulative_funding_rate_short( + market + .amm + .cumulative_funding_rate_short() + .safe_add(funding_rate_short)?, + ); market.amm.last_funding_rate = funding_rate; market.amm.last_funding_oracle_twap = oracle_price_twap; @@ -296,13 +300,13 @@ pub fn update_funding_rate( funding_rate, funding_rate_long, funding_rate_short, - cumulative_funding_rate_long: market.amm.cumulative_funding_rate_long, - cumulative_funding_rate_short: market.amm.cumulative_funding_rate_short, + cumulative_funding_rate_long: market.amm.cumulative_funding_rate_long(), + cumulative_funding_rate_short: market.amm.cumulative_funding_rate_short(), mark_price_twap: mid_price_twap, oracle_price_twap, period_revenue: market.amm.net_revenue_since_last_funding, - base_asset_amount_with_amm: market.amm.base_asset_amount_with_amm, - base_asset_amount_with_unsettled_lp: market.amm.base_asset_amount_with_unsettled_lp, + base_asset_amount_with_amm: market.amm.base_asset_amount_with_amm(), + base_asset_amount_with_unsettled_lp: market.amm.base_asset_amount_with_unsettled_lp(), }); market.amm.net_revenue_since_last_funding = 0; diff --git a/programs/drift/src/controller/insurance.rs b/programs/drift/src/controller/insurance.rs index fa53164733..4268ae7043 100644 --- a/programs/drift/src/controller/insurance.rs +++ b/programs/drift/src/controller/insurance.rs @@ -63,13 +63,13 @@ pub fn update_user_stats_if_stake_amount( let if_stake_amount = if if_stake_amount_delta >= 0 { if_shares_to_vault_amount( insurance_fund_stake.checked_if_shares(spot_market)?, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount.safe_add(if_stake_amount_delta.unsigned_abs())?, )? } else { if_shares_to_vault_amount( insurance_fund_stake.checked_if_shares(spot_market)?, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount.safe_sub(if_stake_amount_delta.unsigned_abs())?, )? }; @@ -115,7 +115,7 @@ pub fn add_insurance_fund_stake( admin_deposit: bool, ) -> DriftResult { validate!( - !(insurance_vault_amount == 0 && spot_market.insurance_fund.total_shares != 0), + !(insurance_vault_amount == 0 && spot_market.insurance_fund.total_shares() != 0), ErrorCode::InvalidIFForNewStakes, "Insurance Fund balance should be non-zero for new stakers to enter" )?; @@ -124,12 +124,12 @@ pub fn add_insurance_fund_stake( apply_rebase_to_insurance_fund_stake(insurance_fund_stake, spot_market)?; let if_shares_before = insurance_fund_stake.checked_if_shares(spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); let n_shares = vault_amount_to_if_shares( amount, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; @@ -142,11 +142,19 @@ pub fn add_insurance_fund_stake( insurance_fund_stake.increase_if_shares(n_shares, spot_market)?; - spot_market.insurance_fund.total_shares = - spot_market.insurance_fund.total_shares.safe_add(n_shares)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_add(n_shares)?, + ); - spot_market.insurance_fund.user_shares = - spot_market.insurance_fund.user_shares.safe_add(n_shares)?; + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_add(n_shares)?, + ); update_user_stats_if_stake_amount( amount.cast()?, @@ -174,8 +182,8 @@ pub fn add_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); Ok(()) @@ -186,31 +194,39 @@ pub fn apply_rebase_to_insurance_fund( spot_market: &mut SpotMarket, ) -> DriftResult { if insurance_fund_vault_balance != 0 - && insurance_fund_vault_balance.cast::()? < spot_market.insurance_fund.total_shares + && insurance_fund_vault_balance.cast::()? < spot_market.insurance_fund.total_shares() { let (expo_diff, rebase_divisor) = calculate_rebase_info( - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_fund_vault_balance, )?; - spot_market.insurance_fund.total_shares = spot_market - .insurance_fund - .total_shares - .safe_div(rebase_divisor)?; - spot_market.insurance_fund.user_shares = spot_market - .insurance_fund - .user_shares - .safe_div(rebase_divisor)?; - spot_market.insurance_fund.shares_base = spot_market - .insurance_fund - .shares_base - .safe_add(expo_diff.cast::()?)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_div(rebase_divisor)?, + ); + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_div(rebase_divisor)?, + ); + spot_market.insurance_fund.set_shares_base( + spot_market + .insurance_fund + .shares_base() + .safe_add(expo_diff.cast::()?)?, + ); msg!("rebasing insurance fund: expo_diff={}", expo_diff); } - if insurance_fund_vault_balance != 0 && spot_market.insurance_fund.total_shares == 0 { - spot_market.insurance_fund.total_shares = insurance_fund_vault_balance.cast::()?; + if insurance_fund_vault_balance != 0 && spot_market.insurance_fund.total_shares() == 0 { + spot_market + .insurance_fund + .set_total_shares(insurance_fund_vault_balance.cast::()?); } Ok(()) @@ -220,25 +236,25 @@ pub fn apply_rebase_to_insurance_fund_stake( insurance_fund_stake: &mut InsuranceFundStake, spot_market: &mut SpotMarket, ) -> DriftResult { - if spot_market.insurance_fund.shares_base != insurance_fund_stake.if_base { + if spot_market.insurance_fund.shares_base() != insurance_fund_stake.if_base() { validate!( - spot_market.insurance_fund.shares_base > insurance_fund_stake.if_base, + spot_market.insurance_fund.shares_base() > insurance_fund_stake.if_base(), ErrorCode::InvalidIFRebase, "Rebase expo out of bounds" )?; - let expo_diff = (spot_market.insurance_fund.shares_base - insurance_fund_stake.if_base) + let expo_diff = (spot_market.insurance_fund.shares_base() - insurance_fund_stake.if_base()) .cast::()?; let rebase_divisor = 10_u128.pow(expo_diff); msg!( "rebasing insurance fund stake: base: {} -> {} ", - insurance_fund_stake.if_base, - spot_market.insurance_fund.shares_base, + insurance_fund_stake.if_base(), + spot_market.insurance_fund.shares_base(), ); - insurance_fund_stake.if_base = spot_market.insurance_fund.shares_base; + insurance_fund_stake.set_if_base(spot_market.insurance_fund.shares_base()); let old_if_shares = insurance_fund_stake.unchecked_if_shares(); let new_if_shares = old_if_shares.safe_div(rebase_divisor)?; @@ -250,9 +266,11 @@ pub fn apply_rebase_to_insurance_fund_stake( insurance_fund_stake.update_if_shares(new_if_shares, spot_market)?; - insurance_fund_stake.last_withdraw_request_shares = insurance_fund_stake - .last_withdraw_request_shares - .safe_div(rebase_divisor)?; + insurance_fund_stake.set_last_withdraw_request_shares( + insurance_fund_stake + .last_withdraw_request_shares() + .safe_div(rebase_divisor)?, + ); } Ok(()) @@ -267,33 +285,33 @@ pub fn request_remove_insurance_fund_stake( now: i64, ) -> DriftResult { msg!("n_shares {}", n_shares); - insurance_fund_stake.last_withdraw_request_shares = n_shares; + insurance_fund_stake.set_last_withdraw_request_shares(n_shares); apply_rebase_to_insurance_fund(insurance_vault_amount, spot_market)?; apply_rebase_to_insurance_fund_stake(insurance_fund_stake, spot_market)?; let if_shares_before = insurance_fund_stake.checked_if_shares(spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); validate!( - insurance_fund_stake.last_withdraw_request_shares + insurance_fund_stake.last_withdraw_request_shares() <= insurance_fund_stake.checked_if_shares(spot_market)?, ErrorCode::InvalidInsuranceUnstakeSize, "last_withdraw_request_shares exceeds if_shares {} > {}", - insurance_fund_stake.last_withdraw_request_shares, + insurance_fund_stake.last_withdraw_request_shares(), insurance_fund_stake.checked_if_shares(spot_market)? )?; validate!( - insurance_fund_stake.if_base == spot_market.insurance_fund.shares_base, + insurance_fund_stake.if_base() == spot_market.insurance_fund.shares_base(), ErrorCode::InvalidIFRebase, "if stake base != spot market base" )?; insurance_fund_stake.last_withdraw_request_value = if_shares_to_vault_amount( - insurance_fund_stake.last_withdraw_request_shares, - spot_market.insurance_fund.total_shares, + insurance_fund_stake.last_withdraw_request_shares(), + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )? .min(insurance_vault_amount.saturating_sub(1)); @@ -327,8 +345,8 @@ pub fn request_remove_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); insurance_fund_stake.last_withdraw_request_ts = now; @@ -347,17 +365,17 @@ pub fn cancel_request_remove_insurance_fund_stake( apply_rebase_to_insurance_fund_stake(insurance_fund_stake, spot_market)?; let if_shares_before = insurance_fund_stake.checked_if_shares(spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); validate!( - insurance_fund_stake.if_base == spot_market.insurance_fund.shares_base, + insurance_fund_stake.if_base() == spot_market.insurance_fund.shares_base(), ErrorCode::InvalidIFRebase, "if stake base != spot market base" )?; validate!( - insurance_fund_stake.last_withdraw_request_shares != 0, + insurance_fund_stake.last_withdraw_request_shares() != 0, ErrorCode::InvalidIFUnstakeCancel, "No withdraw request in progress" )?; @@ -367,15 +385,19 @@ pub fn cancel_request_remove_insurance_fund_stake( insurance_fund_stake.decrease_if_shares(if_shares_lost, spot_market)?; - spot_market.insurance_fund.total_shares = spot_market - .insurance_fund - .total_shares - .safe_sub(if_shares_lost)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_sub(if_shares_lost)?, + ); - spot_market.insurance_fund.user_shares = spot_market - .insurance_fund - .user_shares - .safe_sub(if_shares_lost)?; + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_sub(if_shares_lost)?, + ); let if_shares_after = insurance_fund_stake.checked_if_shares(spot_market)?; @@ -399,11 +421,11 @@ pub fn cancel_request_remove_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); - insurance_fund_stake.last_withdraw_request_shares = 0; + insurance_fund_stake.set_last_withdraw_request_shares(0); insurance_fund_stake.last_withdraw_request_value = 0; insurance_fund_stake.last_withdraw_request_ts = now; @@ -429,10 +451,10 @@ pub fn remove_insurance_fund_stake( apply_rebase_to_insurance_fund_stake(insurance_fund_stake, spot_market)?; let if_shares_before = insurance_fund_stake.checked_if_shares(spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); - let n_shares = insurance_fund_stake.last_withdraw_request_shares; + let n_shares = insurance_fund_stake.last_withdraw_request_shares(); validate!( n_shares > 0, @@ -447,7 +469,7 @@ pub fn remove_insurance_fund_stake( let amount = if_shares_to_vault_amount( n_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; @@ -462,14 +484,22 @@ pub fn remove_insurance_fund_stake( .cost_basis .safe_sub(withdraw_amount.cast()?)?; - spot_market.insurance_fund.total_shares = - spot_market.insurance_fund.total_shares.safe_sub(n_shares)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_sub(n_shares)?, + ); - spot_market.insurance_fund.user_shares = - spot_market.insurance_fund.user_shares.safe_sub(n_shares)?; + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_sub(n_shares)?, + ); // reset insurance_fund_stake withdraw request info - insurance_fund_stake.last_withdraw_request_shares = 0; + insurance_fund_stake.set_last_withdraw_request_shares(0); insurance_fund_stake.last_withdraw_request_value = 0; insurance_fund_stake.last_withdraw_request_ts = now; @@ -495,8 +525,8 @@ pub fn remove_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); Ok(withdraw_amount) @@ -511,8 +541,8 @@ pub fn admin_remove_insurance_fund_stake( ) -> DriftResult { apply_rebase_to_insurance_fund(insurance_vault_amount, spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); let if_shares_before = total_if_shares_before.safe_sub(user_if_shares_before)?; @@ -526,16 +556,20 @@ pub fn admin_remove_insurance_fund_stake( let withdraw_amount = if_shares_to_vault_amount( n_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; - spot_market.insurance_fund.total_shares = - spot_market.insurance_fund.total_shares.safe_sub(n_shares)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_sub(n_shares)?, + ); let if_shares_after = spot_market .insurance_fund - .total_shares + .total_shares() .safe_sub(user_if_shares_before)?; emit!(InsuranceFundStakeRecord { @@ -549,8 +583,8 @@ pub fn admin_remove_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); Ok(withdraw_amount) @@ -567,8 +601,8 @@ pub fn transfer_protocol_insurance_fund_stake( ) -> DriftResult { apply_rebase_to_insurance_fund(insurance_vault_amount, spot_market)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; - let user_if_shares_before = spot_market.insurance_fund.user_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); + let user_if_shares_before = spot_market.insurance_fund.user_shares(); let if_shares_before = total_if_shares_before.safe_sub(user_if_shares_before)?; let target_if_shares_before = target_insurance_fund_stake.checked_if_shares(spot_market)?; @@ -580,8 +614,12 @@ pub fn transfer_protocol_insurance_fund_stake( n_shares )?; - spot_market.insurance_fund.user_shares = - spot_market.insurance_fund.user_shares.safe_add(n_shares)?; + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_add(n_shares)?, + ); target_insurance_fund_stake.increase_if_shares(n_shares, spot_market)?; @@ -590,27 +628,27 @@ pub fn transfer_protocol_insurance_fund_stake( if spot_market.market_index == QUOTE_SPOT_MARKET_INDEX { user_stats.if_staked_quote_asset_amount = if_shares_to_vault_amount( target_if_shares_after, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; } else if spot_market.market_index == GOV_SPOT_MARKET_INDEX { user_stats.if_staked_gov_token_amount = if_shares_to_vault_amount( target_if_shares_after, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; } let withdraw_amount = if_shares_to_vault_amount( n_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; - let user_if_shares_after = spot_market.insurance_fund.user_shares; + let user_if_shares_after = spot_market.insurance_fund.user_shares(); let protocol_if_shares_after = spot_market .insurance_fund - .total_shares + .total_shares() .safe_sub(user_if_shares_after)?; emit!(InsuranceFundStakeRecord { @@ -624,8 +662,8 @@ pub fn transfer_protocol_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after: protocol_if_shares_after, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); emit!(InsuranceFundStakeRecord { @@ -639,8 +677,8 @@ pub fn transfer_protocol_insurance_fund_stake( user_if_shares_before, total_if_shares_before, if_shares_after: target_insurance_fund_stake.checked_if_shares(spot_market)?, - total_if_shares_after: spot_market.insurance_fund.total_shares, - user_if_shares_after: spot_market.insurance_fund.user_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), + user_if_shares_after: spot_market.insurance_fund.user_shares(), }); Ok(withdraw_amount) @@ -735,7 +773,7 @@ pub fn settle_revenue_to_insurance_fund( validate_spot_market_vault_amount(spot_market, spot_market_vault_amount)?; let mut token_amount = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )?; @@ -745,7 +783,7 @@ pub fn settle_revenue_to_insurance_fund( token_amount = depositors_claim.max(0).cast::()?.safe_div(2)?; } - if spot_market.insurance_fund.user_shares > 0 { + if spot_market.insurance_fund.user_shares() > 0 { // only allow MAX_APR_PER_REVENUE_SETTLE_TO_INSURANCE_FUND_VAULT or 1/10th of revenue pool to be settled let max_apr_per_revenue_settle: u128 = if spot_market.market_index == GOV_SPOT_MARKET_INDEX { @@ -795,15 +833,19 @@ pub fn settle_revenue_to_insurance_fund( insurance_fund_token_amount .safe_mul(protocol_if_factor.cast()?)? .safe_div(spot_market.insurance_fund.total_factor.cast()?)?, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_vault_amount, )?; - spot_market.insurance_fund.total_shares = - spot_market.insurance_fund.total_shares.safe_add(n_shares)?; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_add(n_shares)?, + ); } - let total_if_shares_before = spot_market.insurance_fund.total_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); update_revenue_pool_balances( insurance_fund_token_amount.cast::()?, @@ -822,7 +864,7 @@ pub fn settle_revenue_to_insurance_fund( vault_amount_before: spot_market_vault_amount, insurance_vault_amount_before: insurance_vault_amount, total_if_shares_before, - total_if_shares_after: spot_market.insurance_fund.total_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), }); insurance_fund_token_amount.cast() @@ -836,14 +878,14 @@ pub fn resolve_perp_pnl_deficit( now: i64, ) -> DriftResult { validate!( - market.amm.total_fee_minus_distributions < 0, + market.amm.total_fee_minus_distributions() < 0, ErrorCode::NoAmmPerpPnlDeficit, "market.amm.total_fee_minus_distributions={} must be negative", - market.amm.total_fee_minus_distributions + market.amm.total_fee_minus_distributions() )?; let pnl_pool_token_amount = get_token_amount( - market.pnl_pool.scaled_balance, + market.pnl_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )?; @@ -866,7 +908,7 @@ pub fn resolve_perp_pnl_deficit( update_spot_market_cumulative_interest(spot_market, None, now)?; - let total_if_shares_before = spot_market.insurance_fund.total_shares; + let total_if_shares_before = spot_market.insurance_fund.total_shares(); let excess_user_pnl_imbalance = if market.unrealized_pnl_max_imbalance > 0 { let net_unsettled_pnl = calculate_net_user_pnl( @@ -931,10 +973,12 @@ pub fn resolve_perp_pnl_deficit( excess_user_pnl_imbalance )?; - market.amm.total_fee_minus_distributions = market - .amm - .total_fee_minus_distributions - .safe_add(insurance_withdraw)?; + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_add(insurance_withdraw)?, + ); market.insurance_claim.revenue_withdraw_since_last_settle = market .insurance_claim @@ -975,7 +1019,7 @@ pub fn resolve_perp_pnl_deficit( vault_amount_before: vault_amount, insurance_vault_amount_before: insurance_vault_amount, total_if_shares_before, - total_if_shares_after: spot_market.insurance_fund.total_shares, + total_if_shares_after: spot_market.insurance_fund.total_shares(), }); insurance_withdraw.cast() @@ -1021,28 +1065,28 @@ pub fn handle_if_end_swap( let out_insurance_fund_vault_amount_before = out_insurance_fund_vault_amount_after.safe_sub(out_amount)?; - let in_if_total_shares_before = in_spot_market.insurance_fund.total_shares; - let out_if_total_shares_before = out_spot_market.insurance_fund.total_shares; - let in_if_user_shares_before = in_spot_market.insurance_fund.user_shares; - let out_if_user_shares_before = out_spot_market.insurance_fund.user_shares; + let in_if_total_shares_before = in_spot_market.insurance_fund.total_shares(); + let out_if_total_shares_before = out_spot_market.insurance_fund.total_shares(); + let in_if_user_shares_before = in_spot_market.insurance_fund.user_shares(); + let out_if_user_shares_before = out_spot_market.insurance_fund.user_shares(); let in_share_price_before = calculate_share_price( - in_spot_market.insurance_fund.total_shares, + in_spot_market.insurance_fund.total_shares(), in_insurance_fund_vault_amount_before, )?; let out_share_price_before = calculate_share_price( - out_spot_market.insurance_fund.total_shares, + out_spot_market.insurance_fund.total_shares(), out_insurance_fund_vault_amount_before, )?; let in_shares = vault_amount_to_if_shares( in_amount, - in_spot_market.insurance_fund.total_shares, + in_spot_market.insurance_fund.total_shares(), in_insurance_fund_vault_amount_before, )?; let out_shares = vault_amount_to_if_shares( out_amount, - out_spot_market.insurance_fund.total_shares, + out_spot_market.insurance_fund.total_shares(), out_insurance_fund_vault_amount_before, )?; @@ -1056,21 +1100,25 @@ pub fn handle_if_end_swap( )?; // increment spot market insurance funds total shares - in_spot_market.insurance_fund.total_shares = in_spot_market - .insurance_fund - .total_shares - .safe_sub(in_shares)?; - out_spot_market.insurance_fund.total_shares = out_spot_market - .insurance_fund - .total_shares - .safe_add(out_shares)?; + in_spot_market.insurance_fund.set_total_shares( + in_spot_market + .insurance_fund + .total_shares() + .safe_sub(in_shares)?, + ); + out_spot_market.insurance_fund.set_total_shares( + out_spot_market + .insurance_fund + .total_shares() + .safe_add(out_shares)?, + ); let in_share_price_after = calculate_share_price( - in_spot_market.insurance_fund.total_shares, + in_spot_market.insurance_fund.total_shares(), in_insurance_fund_vault_amount_after, )?; let out_share_price_after = calculate_share_price( - out_spot_market.insurance_fund.total_shares, + out_spot_market.insurance_fund.total_shares(), out_insurance_fund_vault_amount_after, )?; @@ -1163,10 +1211,10 @@ pub fn handle_if_end_swap( out_if_total_shares_before, in_if_user_shares_before, out_if_user_shares_before, - in_if_total_shares_after: in_spot_market.insurance_fund.total_shares, - out_if_total_shares_after: out_spot_market.insurance_fund.total_shares, - in_if_user_shares_after: in_spot_market.insurance_fund.user_shares, - out_if_user_shares_after: out_spot_market.insurance_fund.user_shares, + in_if_total_shares_after: in_spot_market.insurance_fund.total_shares(), + out_if_total_shares_after: out_spot_market.insurance_fund.total_shares(), + in_if_user_shares_after: in_spot_market.insurance_fund.user_shares(), + out_if_user_shares_after: out_spot_market.insurance_fund.user_shares(), }); Ok(()) @@ -1183,7 +1231,7 @@ pub fn transfer_protocol_if_shares_to_revenue_pool( let shares = vault_amount_to_if_shares( amount, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_fund_vault_amount_before, )?; @@ -1205,8 +1253,9 @@ pub fn transfer_protocol_if_shares_to_revenue_pool( if_rebalance_config.max_transfer_amount()? )?; - spot_market.insurance_fund.total_shares = - spot_market.insurance_fund.total_shares.safe_sub(shares)?; + spot_market + .insurance_fund + .set_total_shares(spot_market.insurance_fund.total_shares().safe_sub(shares)?); update_revenue_pool_balances(amount.cast()?, &SpotBalanceType::Deposit, spot_market)?; diff --git a/programs/drift/src/controller/insurance/tests.rs b/programs/drift/src/controller/insurance/tests.rs index c71948c3d3..04150329b0 100644 --- a/programs/drift/src/controller/insurance/tests.rs +++ b/programs/drift/src/controller/insurance/tests.rs @@ -25,8 +25,8 @@ pub fn basic_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -58,8 +58,8 @@ pub fn basic_stake_if_test() { .is_err()); assert_eq!(if_stake.unchecked_if_shares(), amount as u128); - assert_eq!(spot_market.insurance_fund.total_shares, amount as u128); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), amount as u128); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); request_remove_insurance_fund_stake( if_stake.unchecked_if_shares(), @@ -71,13 +71,13 @@ pub fn basic_stake_if_test() { ) .unwrap(); assert_eq!( - if_stake.last_withdraw_request_shares, + if_stake.last_withdraw_request_shares(), if_stake.unchecked_if_shares() ); assert_eq!(if_stake.last_withdraw_request_value, if_balance - 1); //rounding in favor assert_eq!(if_stake.unchecked_if_shares(), amount as u128); - assert_eq!(spot_market.insurance_fund.total_shares, amount as u128); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), amount as u128); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); let amount_returned = (remove_insurance_fund_stake( if_balance, @@ -92,10 +92,10 @@ pub fn basic_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 1); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); assert_eq!(if_balance, 1); add_insurance_fund_stake( @@ -109,9 +109,9 @@ pub fn basic_stake_if_test() { ) .unwrap(); assert_eq!(if_stake.cost_basis, 1234); - assert_eq!(spot_market.insurance_fund.user_shares, 1234); - assert_eq!(spot_market.insurance_fund.total_shares, 1235); // protocol claims the 1 balance - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 1234); + assert_eq!(spot_market.insurance_fund.total_shares(), 1235); // protocol claims the 1 balance + assert_eq!(spot_market.insurance_fund.shares_base(), 0); } #[test] @@ -124,8 +124,8 @@ pub fn basic_seeded_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -133,8 +133,8 @@ pub fn basic_seeded_stake_if_test() { ..SpotMarket::default() }; - assert_eq!(spot_market.insurance_fund.total_shares, 0); - assert_eq!(spot_market.insurance_fund.user_shares, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); add_insurance_fund_stake( amount, @@ -148,10 +148,10 @@ pub fn basic_seeded_stake_if_test() { .unwrap(); assert_eq!( - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), (1001 * QUOTE_PRECISION) ); // seeded works - assert_eq!(spot_market.insurance_fund.user_shares, QUOTE_PRECISION); + assert_eq!(spot_market.insurance_fund.user_shares(), QUOTE_PRECISION); assert_eq!(if_stake.unchecked_if_shares(), amount as u128); if_balance += amount; @@ -176,7 +176,7 @@ pub fn basic_seeded_stake_if_test() { ) .unwrap(); assert_eq!( - if_stake.last_withdraw_request_shares, + if_stake.last_withdraw_request_shares(), if_stake.unchecked_if_shares() ); assert_eq!(if_stake.last_withdraw_request_value, 1000000); @@ -194,7 +194,7 @@ pub fn basic_seeded_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 0); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_balance, 1000000000); @@ -224,8 +224,8 @@ pub fn large_num_seeded_stake_if_test() { // all funds in revenue pool let mut spot_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, revenue_settle_period: 1, @@ -233,14 +233,14 @@ pub fn large_num_seeded_stake_if_test() { }, revenue_pool: PoolBalance { market_index: 0, - scaled_balance: 100 * SPOT_BALANCE_PRECISION, + scaled_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..PoolBalance::default() }, ..SpotMarket::default() }; - assert_eq!(spot_market.insurance_fund.total_shares, 0); - assert_eq!(spot_market.insurance_fund.user_shares, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); add_insurance_fund_stake( amount, @@ -253,8 +253,8 @@ pub fn large_num_seeded_stake_if_test() { ) .unwrap(); - assert_eq!(spot_market.insurance_fund.total_shares, 199000199000001); // seeded works - assert_eq!(spot_market.insurance_fund.user_shares, 199000001); + assert_eq!(spot_market.insurance_fund.total_shares(), 199000199000001); // seeded works + assert_eq!(spot_market.insurance_fund.user_shares(), 199000001); assert_eq!(if_stake.unchecked_if_shares(), amount as u128); if_balance += amount; @@ -269,7 +269,7 @@ pub fn large_num_seeded_stake_if_test() { .is_err()); assert_eq!(if_stake.unchecked_if_shares(), amount as u128); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -285,9 +285,9 @@ pub fn large_num_seeded_stake_if_test() { ) .unwrap(); assert_eq!(flow, 11); - assert_eq!(spot_market.revenue_pool.scaled_balance, 90099009901); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 90099009901); let spot_market_vault_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -306,7 +306,7 @@ pub fn large_num_seeded_stake_if_test() { ) .unwrap(); assert_eq!( - if_stake.last_withdraw_request_shares, + if_stake.last_withdraw_request_shares(), if_stake.unchecked_if_shares() ); assert_eq!(if_stake.last_withdraw_request_value, 199000001); @@ -324,13 +324,15 @@ pub fn large_num_seeded_stake_if_test() { assert_eq!(if_stake.unchecked_if_shares(), 0); assert_eq!(if_stake.cost_basis, 0); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_balance, 199000000000011); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 199000000000000); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 199000000000000); - spot_market.revenue_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION; + spot_market + .revenue_pool + .set_scaled_balance(100 * SPOT_BALANCE_PRECISION); add_insurance_fund_stake( 199033744205760, @@ -343,7 +345,7 @@ pub fn large_num_seeded_stake_if_test() { ) .unwrap(); assert_eq!(if_stake.cost_basis, 199033744205760); - assert_eq!(spot_market.insurance_fund.user_shares, 199033744205748); + assert_eq!(spot_market.insurance_fund.user_shares(), 199033744205748); add_insurance_fund_stake( 199033744205760, @@ -356,7 +358,7 @@ pub fn large_num_seeded_stake_if_test() { ) .unwrap(); assert_eq!(if_stake.cost_basis, 398067488411520); - assert_eq!(spot_market.insurance_fund.user_shares, 597134982544960); + assert_eq!(spot_market.insurance_fund.user_shares(), 597134982544960); } #[test] @@ -369,8 +371,8 @@ pub fn gains_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -494,8 +496,8 @@ pub fn losses_stake_if_test() { }; let amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -622,8 +624,8 @@ pub fn escrow_losses_stake_if_test() { }; let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks ..InsuranceFund::default() @@ -654,11 +656,11 @@ pub fn escrow_losses_stake_if_test() { let o = if_shares_to_vault_amount( n_shares / 3, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); request_remove_insurance_fund_stake( n_shares / 3, @@ -669,7 +671,7 @@ pub fn escrow_losses_stake_if_test() { now, ) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 33333333333); + assert_eq!(if_stake.last_withdraw_request_shares(), 33333333333); assert_eq!( if_stake.last_withdraw_request_value, expected_amount_returned @@ -719,12 +721,12 @@ pub fn escrow_gains_stake_if_test() { }; let amount = 100_000_384_939_u64; // $100k + change let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks - total_shares: 1, - user_shares: 0, + total_shares: 1.into(), + user_shares: 0.into(), ..InsuranceFund::default() }, ..SpotMarket::default() @@ -767,11 +769,11 @@ pub fn escrow_gains_stake_if_test() { let n_shares = if_stake.unchecked_if_shares(); let expected_amount_returned = - (if_balance as u128 * n_shares / spot_market.insurance_fund.total_shares) as u64; + (if_balance as u128 * n_shares / spot_market.insurance_fund.total_shares()) as u64; let o = if_shares_to_vault_amount( n_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); @@ -802,7 +804,7 @@ pub fn escrow_gains_stake_if_test() { if_balance = if_balance + if_balance / 412; let ideal_amount_returned = - (if_balance as u128 * n_shares / spot_market.insurance_fund.total_shares) as u64; + (if_balance as u128 * n_shares / spot_market.insurance_fund.total_shares()) as u64; // appropriate time for withdraw let amount_returned = (remove_insurance_fund_stake( @@ -813,7 +815,7 @@ pub fn escrow_gains_stake_if_test() { now + 60 * 60 * 24 * 7 + 3254, )) .unwrap(); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); if_balance -= amount_returned; @@ -839,12 +841,12 @@ pub fn drained_stake_if_test_rebase_on_new_add() { let amount = 100_000_384_939_u64; // $100k + change let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 60 * 60 * 24 * 7, // 7 weeks - total_shares: 100_000 * QUOTE_PRECISION, - user_shares: 80_000 * QUOTE_PRECISION, + total_shares: (100_000 * QUOTE_PRECISION).into(), + user_shares: (80_000 * QUOTE_PRECISION).into(), ..InsuranceFund::default() }, ..SpotMarket::default() @@ -875,9 +877,9 @@ pub fn drained_stake_if_test_rebase_on_new_add() { .is_err()); assert_eq!(if_stake.unchecked_if_shares(), 0); - assert_eq!(spot_market.insurance_fund.total_shares, 100_000_000_000); + assert_eq!(spot_market.insurance_fund.total_shares(), 100_000_000_000); assert_eq!( - spot_market.insurance_fund.user_shares, + spot_market.insurance_fund.user_shares(), 80_000 * QUOTE_PRECISION ); @@ -896,27 +898,28 @@ pub fn drained_stake_if_test_rebase_on_new_add() { if_balance += amount; // check rebase math - assert_eq!(spot_market.insurance_fund.total_shares, 1000003849400); - assert_eq!(spot_market.insurance_fund.user_shares, 1000003849398); + assert_eq!(spot_market.insurance_fund.total_shares(), 1000003849400); + assert_eq!(spot_market.insurance_fund.user_shares(), 1000003849398); assert_eq!(if_stake.unchecked_if_shares(), 1000003849390); assert_eq!( - if_stake.unchecked_if_shares() < spot_market.insurance_fund.user_shares, + if_stake.unchecked_if_shares() < spot_market.insurance_fund.user_shares(), true ); assert_eq!( - spot_market.insurance_fund.user_shares - if_stake.unchecked_if_shares(), + spot_market.insurance_fund.user_shares() - if_stake.unchecked_if_shares(), 8 ); - assert_eq!(spot_market.insurance_fund.shares_base, 10); - assert_eq!(if_stake.if_base, 10); + assert_eq!(spot_market.insurance_fund.shares_base(), 10); + assert_eq!(if_stake.if_base(), 10); // check orig if stake is good (on add) - assert_eq!(orig_if_stake.if_base, 0); + assert_eq!(orig_if_stake.if_base(), 0); assert_eq!(orig_if_stake.unchecked_if_shares(), 80000000000); let expected_shares_for_amount = - vault_amount_to_if_shares(1, spot_market.insurance_fund.total_shares, if_balance).unwrap(); + vault_amount_to_if_shares(1, spot_market.insurance_fund.total_shares(), if_balance) + .unwrap(); assert_eq!(expected_shares_for_amount, 10); add_insurance_fund_stake( @@ -930,8 +933,8 @@ pub fn drained_stake_if_test_rebase_on_new_add() { ) .unwrap(); - assert_eq!(spot_market.insurance_fund.shares_base, 10); - assert_eq!(orig_if_stake.if_base, 10); + assert_eq!(spot_market.insurance_fund.shares_base(), 10); + assert_eq!(orig_if_stake.if_base(), 10); assert_eq!( orig_if_stake.unchecked_if_shares(), 80000000000 / 10000000000 + expected_shares_for_amount @@ -947,12 +950,12 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all() { let mut if_balance = 0; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, - total_shares: 100_000 * QUOTE_PRECISION, - user_shares: 80_000 * QUOTE_PRECISION, + total_shares: (100_000 * QUOTE_PRECISION).into(), + user_shares: (80_000 * QUOTE_PRECISION).into(), ..InsuranceFund::default() }, ..SpotMarket::default() @@ -971,9 +974,9 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all() { assert_eq!(if_balance, 0); // right now other users have claim on a zero balance IF... should not give them your money here - assert_eq!(spot_market.insurance_fund.total_shares, 100_000_000_000); + assert_eq!(spot_market.insurance_fund.total_shares(), 100_000_000_000); assert_eq!( - spot_market.insurance_fund.user_shares, + spot_market.insurance_fund.user_shares(), 80_000 * QUOTE_PRECISION ); @@ -998,8 +1001,8 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all() { // check rebase math assert_eq!(amount_returned, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 20000000000); - assert_eq!(spot_market.insurance_fund.user_shares, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 20000000000); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); // make non-zero if_balance = 1; @@ -1029,9 +1032,9 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all() { ) .unwrap(); - assert_eq!(spot_market.insurance_fund.shares_base, 9); - assert_eq!(spot_market.insurance_fund.total_shares, 200000000000020); - assert_eq!(spot_market.insurance_fund.user_shares, 200000000000000); + assert_eq!(spot_market.insurance_fund.shares_base(), 9); + assert_eq!(spot_market.insurance_fund.total_shares(), 200000000000020); + assert_eq!(spot_market.insurance_fund.user_shares(), 200000000000000); if_balance += 10_000_000_000_000; assert_eq!(if_balance, 10000000000001); } @@ -1041,12 +1044,12 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { let mut if_balance = 0; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, - total_shares: 100_930_021_053, - user_shares: 83_021 * QUOTE_PRECISION + 135723, + total_shares: 100_930_021_053.into(), + user_shares: (83_021 * QUOTE_PRECISION + 135723).into(), ..InsuranceFund::default() }, ..SpotMarket::default() @@ -1085,15 +1088,15 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { // check rebase math assert_eq!(amount_returned, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 60930021053); - assert_eq!(spot_market.insurance_fund.user_shares, 43021135723); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 60930021053); + assert_eq!(spot_market.insurance_fund.user_shares(), 43021135723); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); if_balance = QUOTE_PRECISION as u64; let unstake_amt = if_stake.unchecked_if_shares() / 2; assert_eq!(unstake_amt, 20000000000); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(if_stake.last_withdraw_request_ts, 0); @@ -1108,20 +1111,20 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { .unwrap(); // rebase occurs in request - assert_eq!(if_stake.last_withdraw_request_shares, unstake_amt / 1000); + assert_eq!(if_stake.last_withdraw_request_shares(), unstake_amt / 1000); // (that rebase occurs when you pass in shares you wanna unstake) :/ assert_eq!(if_stake.unchecked_if_shares(), 40000000); assert_eq!(if_stake.last_withdraw_request_value, 328245); assert_eq!(if_stake.last_withdraw_request_ts, 10); - assert_eq!(spot_market.insurance_fund.total_shares, 60930021); - assert_eq!(spot_market.insurance_fund.user_shares, 43021135); + assert_eq!(spot_market.insurance_fund.total_shares(), 60930021); + assert_eq!(spot_market.insurance_fund.user_shares(), 43021135); - assert_eq!(spot_market.insurance_fund.shares_base, 3); + assert_eq!(spot_market.insurance_fund.shares_base(), 3); let expected_amount_for_shares = if_shares_to_vault_amount( if_stake.unchecked_if_shares() / 2, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); @@ -1131,15 +1134,15 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { ); let user_expected_amount_for_shares_before_double = if_shares_to_vault_amount( - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); let protocol_expected_amount_for_shares_before_double = if_shares_to_vault_amount( - spot_market.insurance_fund.total_shares - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares() - spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); @@ -1155,15 +1158,15 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { if_balance *= 2; // double the IF vault before withdraw let protocol_expected_amount_for_shares_after_double = if_shares_to_vault_amount( - spot_market.insurance_fund.total_shares - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares() - spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); let user_expected_amount_for_shares_after_double = if_shares_to_vault_amount( - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); @@ -1178,22 +1181,22 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { .unwrap(); let protocol_expected_amount_for_shares_after_user_withdraw = if_shares_to_vault_amount( - spot_market.insurance_fund.total_shares - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares() - spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares(), if_balance, ) .unwrap(); // check rebase math assert_eq!(if_stake.unchecked_if_shares(), 20000000); - assert_eq!(if_stake.if_base, spot_market.insurance_fund.shares_base); - assert_eq!(if_stake.last_withdraw_request_shares, 0); + assert_eq!(if_stake.if_base(), spot_market.insurance_fund.shares_base()); + assert_eq!(if_stake.last_withdraw_request_shares(), 0); assert_eq!(if_stake.last_withdraw_request_value, 0); assert_eq!(amount_returned, 328245); - assert_eq!(spot_market.insurance_fund.total_shares, 40930021); - assert_eq!(spot_market.insurance_fund.user_shares, 23021135); - assert_eq!(spot_market.insurance_fund.shares_base, 3); + assert_eq!(spot_market.insurance_fund.total_shares(), 40930021); + assert_eq!(spot_market.insurance_fund.user_shares(), 23021135); + assert_eq!(spot_market.insurance_fund.shares_base(), 3); assert_eq!( protocol_expected_amount_for_shares_after_double, @@ -1231,9 +1234,9 @@ pub fn drained_stake_if_test_rebase_on_old_remove_all_2() { .unwrap(); if_balance += 10_000_000_000_000; - assert_eq!(spot_market.insurance_fund.total_shares, 204650145930021); - assert_eq!(spot_market.insurance_fund.user_shares, 204650128021135); - assert_eq!(spot_market.insurance_fund.shares_base, 3); + assert_eq!(spot_market.insurance_fund.total_shares(), 204650145930021); + assert_eq!(spot_market.insurance_fund.user_shares(), 204650128021135); + assert_eq!(spot_market.insurance_fund.shares_base(), 3); assert_eq!(if_balance, 10000002000000); } @@ -1255,8 +1258,8 @@ pub fn multiple_if_stakes_and_rebase() { let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -1290,8 +1293,8 @@ pub fn multiple_if_stakes_and_rebase() { // if gets drained if_balance = QUOTE_PRECISION as u64; - assert_eq!(if_stake_1.if_base, 0); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(if_stake_1.if_base(), 0); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); request_remove_insurance_fund_stake( if_stake_1.unchecked_if_shares(), @@ -1302,8 +1305,8 @@ pub fn multiple_if_stakes_and_rebase() { 0, ) .unwrap(); - assert_eq!(if_stake_1.if_base, 4); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_1.if_base(), 4); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); let amount_returned = (remove_insurance_fund_stake( if_balance, @@ -1316,8 +1319,8 @@ pub fn multiple_if_stakes_and_rebase() { assert_eq!(amount_returned, 500000); if_balance -= amount_returned; - assert_eq!(if_stake_2.if_base, 0); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_2.if_base(), 0); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); request_remove_insurance_fund_stake( if_stake_2.unchecked_if_shares(), if_balance, @@ -1327,15 +1330,15 @@ pub fn multiple_if_stakes_and_rebase() { 0, ) .unwrap(); - assert_eq!(if_stake_2.if_base, 4); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_2.if_base(), 4); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); assert_eq!( - if_stake_2.if_base < spot_market.insurance_fund.total_shares, + if_stake_2.if_base() < spot_market.insurance_fund.total_shares(), true ); assert_eq!( if_stake_2.unchecked_if_shares(), - spot_market.insurance_fund.user_shares + spot_market.insurance_fund.user_shares() ); assert_eq!(if_balance, 500000); @@ -1352,8 +1355,8 @@ pub fn multiple_if_stakes_and_rebase() { if_balance -= amount_returned; assert_eq!(if_balance, 1); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); } #[test] @@ -1374,8 +1377,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { let amount = (QUOTE_PRECISION * 100_000) as u64; // $100k let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() @@ -1395,9 +1398,9 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { if_balance -= amount_returned; assert_eq!(amount_returned, (50 * QUOTE_PRECISION) as u64); - assert_eq!(spot_market.insurance_fund.user_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); assert_eq!( - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), 50 * QUOTE_PRECISION ); @@ -1430,8 +1433,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { // if gets drained if_balance = QUOTE_PRECISION as u64; - assert_eq!(if_stake_1.if_base, 0); - assert_eq!(spot_market.insurance_fund.shares_base, 0); + assert_eq!(if_stake_1.if_base(), 0); + assert_eq!(spot_market.insurance_fund.shares_base(), 0); request_remove_insurance_fund_stake( if_stake_1.unchecked_if_shares(), @@ -1442,8 +1445,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { 0, ) .unwrap(); - assert_eq!(if_stake_1.if_base, 4); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_1.if_base(), 4); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); let amount_returned = (remove_insurance_fund_stake( if_balance, @@ -1456,8 +1459,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { assert_eq!(amount_returned, 499750); if_balance -= amount_returned; - assert_eq!(if_stake_2.if_base, 0); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_2.if_base(), 0); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); request_remove_insurance_fund_stake( if_stake_2.unchecked_if_shares(), if_balance, @@ -1467,22 +1470,22 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { 0, ) .unwrap(); - assert_eq!(if_stake_2.if_base, 4); - assert_eq!(spot_market.insurance_fund.shares_base, 4); + assert_eq!(if_stake_2.if_base(), 4); + assert_eq!(spot_market.insurance_fund.shares_base(), 4); assert_eq!( - if_stake_2.if_base < spot_market.insurance_fund.total_shares, + if_stake_2.if_base() < spot_market.insurance_fund.total_shares(), true ); assert_eq!( if_stake_2.unchecked_if_shares(), - spot_market.insurance_fund.user_shares + spot_market.insurance_fund.user_shares() ); assert_eq!(if_balance, 500250); // withdraw all let amount_returned = admin_remove_insurance_fund_stake( if_balance, - spot_market.insurance_fund.total_shares - spot_market.insurance_fund.user_shares, + spot_market.insurance_fund.total_shares() - spot_market.insurance_fund.user_shares(), &mut spot_market, 1, Pubkey::default(), @@ -1492,8 +1495,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { assert_eq!(amount_returned, 499); assert_eq!( - spot_market.insurance_fund.user_shares, - spot_market.insurance_fund.total_shares + spot_market.insurance_fund.user_shares(), + spot_market.insurance_fund.total_shares() ); // half of it back @@ -1512,8 +1515,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { if_balance -= amount_returned; assert_eq!(if_balance, 250); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); let amount_returned = admin_remove_insurance_fund_stake(if_balance, 250, &mut spot_market, 1, Pubkey::default()) @@ -1521,8 +1524,8 @@ pub fn multiple_if_stakes_and_rebase_and_admin_remove() { // if_balance -= amount_returned; assert_eq!(amount_returned, 250); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); } #[test] @@ -1536,23 +1539,23 @@ fn test_transfer_protocol_owned_stake() { }; let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, ..InsuranceFund::default() }, ..SpotMarket::default() }; - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); - spot_market.insurance_fund.total_shares = 42210407198; // make price != 1 + spot_market.insurance_fund.set_total_shares(42210407198); // make price != 1 // withdraw half let amount_returned = admin_remove_insurance_fund_stake( if_balance, - spot_market.insurance_fund.total_shares / 2, + spot_market.insurance_fund.total_shares() / 2, &mut spot_market, 1, Pubkey::default(), @@ -1561,8 +1564,8 @@ fn test_transfer_protocol_owned_stake() { if_balance -= amount_returned; assert_eq!(amount_returned, 99500000000_u64); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 21105203599); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 21105203599); let now = 6969696969; @@ -1576,7 +1579,7 @@ fn test_transfer_protocol_owned_stake() { Pubkey::default(), ) .unwrap(); - assert_eq!(0, spot_market.insurance_fund.user_shares); + assert_eq!(0, spot_market.insurance_fund.user_shares()); assert_eq!(transfer_num_0, 0); let transfer_num_1 = transfer_protocol_insurance_fund_stake( @@ -1589,13 +1592,13 @@ fn test_transfer_protocol_owned_stake() { Pubkey::default(), ) .unwrap(); - assert_eq!(1, spot_market.insurance_fund.user_shares); - assert_eq!(21105203599, spot_market.insurance_fund.total_shares); + assert_eq!(1, spot_market.insurance_fund.user_shares()); + assert_eq!(21105203599, spot_market.insurance_fund.total_shares()); assert_eq!(transfer_num_1, 4); assert!(transfer_protocol_insurance_fund_stake( if_balance, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), &mut if_stake_2, &mut user_stats_2, &mut spot_market, @@ -1606,7 +1609,7 @@ fn test_transfer_protocol_owned_stake() { let transfer_num_2 = transfer_protocol_insurance_fund_stake( if_balance, - spot_market.insurance_fund.total_shares - spot_market.insurance_fund.user_shares, + spot_market.insurance_fund.total_shares() - spot_market.insurance_fund.user_shares(), &mut if_stake_2, &mut user_stats_2, &mut spot_market, @@ -1616,8 +1619,8 @@ fn test_transfer_protocol_owned_stake() { .unwrap(); assert_eq!( - spot_market.insurance_fund.total_shares, - spot_market.insurance_fund.user_shares + spot_market.insurance_fund.total_shares(), + spot_market.insurance_fund.user_shares() ); assert_eq!(transfer_num_2, 99499999995); @@ -1631,7 +1634,7 @@ fn test_transfer_protocol_owned_stake() { assert!(transfer_protocol_insurance_fund_stake( if_balance, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), &mut if_stake_2, &mut user_stats_2, &mut spot_market, diff --git a/programs/drift/src/controller/liquidation.rs b/programs/drift/src/controller/liquidation.rs index 4e5543d313..f695366951 100644 --- a/programs/drift/src/controller/liquidation.rs +++ b/programs/drift/src/controller/liquidation.rs @@ -531,10 +531,10 @@ pub fn liquidate_perp( market.amm.order_step_size )?; - market.amm.total_liquidation_fee = market + let tlf = market.amm.total_liquidation_fee(); + market .amm - .total_liquidation_fee - .safe_add(if_fee.unsigned_abs().cast()?)?; + .set_total_liquidation_fee(tlf.safe_add(if_fee.unsigned_abs().cast()?)?); ( user_existing_position_direction, @@ -672,10 +672,10 @@ pub fn liquidate_perp( maker_order_cumulative_quote_asset_amount_filled: Some(base_asset_value), oracle_price, bit_flags: 0, - taker_existing_quote_entry_amount: taker_existing_quote_entry_amount, - taker_existing_base_asset_amount: taker_existing_base_asset_amount, - maker_existing_quote_entry_amount: maker_existing_quote_entry_amount, - maker_existing_base_asset_amount: maker_existing_base_asset_amount, + taker_existing_quote_entry_amount, + taker_existing_base_asset_amount, + maker_existing_quote_entry_amount, + maker_existing_base_asset_amount, trigger_price: None, builder_idx: None, builder_fee: None, @@ -1103,10 +1103,10 @@ pub fn liquidate_perp_with_fill( let user_position = user.get_perp_position_mut(market_index)?; update_quote_asset_and_break_even_amount(user_position, &mut market, if_fee)?; - market.amm.total_liquidation_fee = market - .amm - .total_liquidation_fee - .safe_add(if_fee.unsigned_abs().cast()?)?; + let total_liquidation_fee = market.amm.total_liquidation_fee(); + market.amm.set_total_liquidation_fee( + total_liquidation_fee.safe_add(if_fee.unsigned_abs().cast()?)?, + ); } let (margin_freed_for_perp_position, margin_calculation_after) = calculate_margin_freed( @@ -3427,20 +3427,20 @@ pub fn resolve_perp_bankruptcy( if loss_to_socialize < 0 { let mut market = perp_market_map.get_ref_mut(&market_index)?; - market.amm.total_social_loss = market + let total_social_loss = market.amm.total_social_loss(); + market .amm - .total_social_loss - .safe_add(loss_to_socialize.unsigned_abs())?; + .set_total_social_loss(total_social_loss.safe_add(loss_to_socialize.unsigned_abs())?); - market.amm.cumulative_funding_rate_long = market - .amm - .cumulative_funding_rate_long - .safe_add(cumulative_funding_rate_delta)?; + let cumulative_funding_rate_long = market.amm.cumulative_funding_rate_long(); + market.amm.set_cumulative_funding_rate_long( + cumulative_funding_rate_long.safe_add(cumulative_funding_rate_delta)?, + ); - market.amm.cumulative_funding_rate_short = market - .amm - .cumulative_funding_rate_short - .safe_sub(cumulative_funding_rate_delta)?; + let cumulative_funding_rate_short = market.amm.cumulative_funding_rate_short(); + market.amm.set_cumulative_funding_rate_short( + cumulative_funding_rate_short.safe_sub(cumulative_funding_rate_delta)?, + ); } // clear bad debt @@ -3600,17 +3600,18 @@ pub fn resolve_spot_bankruptcy( None, )?; - spot_market.cumulative_deposit_interest = spot_market - .cumulative_deposit_interest - .safe_sub(cumulative_deposit_interest_delta)?; + let cumulative_deposit_interest = spot_market.cumulative_deposit_interest(); + spot_market.set_cumulative_deposit_interest( + cumulative_deposit_interest.safe_sub(cumulative_deposit_interest_delta)?, + ); - spot_market.total_social_loss = spot_market - .total_social_loss - .safe_add(borrow_amount.cast()?)?; + let total_social_loss = spot_market.total_social_loss(); + spot_market.set_total_social_loss(total_social_loss.safe_add(borrow_amount.cast()?)?); - spot_market.total_quote_social_loss = spot_market - .total_quote_social_loss - .safe_add(quote_social_loss.unsigned_abs().cast()?)?; + let total_quote_social_loss = spot_market.total_quote_social_loss(); + spot_market.set_total_quote_social_loss( + total_quote_social_loss.safe_add(quote_social_loss.unsigned_abs().cast()?)?, + ); } // exit bankruptcy diff --git a/programs/drift/src/controller/liquidation/tests.rs b/programs/drift/src/controller/liquidation/tests.rs index e8cf21acde..27e29eaf48 100644 --- a/programs/drift/src/controller/liquidation/tests.rs +++ b/programs/drift/src/controller/liquidation/tests.rs @@ -55,19 +55,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -86,7 +86,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -182,7 +182,7 @@ pub mod liquidate_perp { ); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 0); + assert_eq!(market_after.amm.total_liquidation_fee(), 0); } #[test] @@ -204,19 +204,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: 3600, @@ -236,7 +236,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -332,7 +332,7 @@ pub mod liquidate_perp { ); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 0); + assert_eq!(market_after.amm.total_liquidation_fee(), 0); } #[test] @@ -354,19 +354,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: 3600, @@ -385,7 +385,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -488,19 +488,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -520,7 +520,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -615,7 +615,7 @@ pub mod liquidate_perp { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, -49500000); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 0) + assert_eq!(market_after.amm.total_liquidation_fee(), 0) } #[test] @@ -637,19 +637,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -669,7 +669,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -794,7 +794,7 @@ pub mod liquidate_perp { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, -178200000); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 1800000) + assert_eq!(market_after.amm.total_liquidation_fee(), 1800000) } #[test] @@ -816,19 +816,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -849,7 +849,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -994,7 +994,7 @@ pub mod liquidate_perp { ); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, QUOTE_PRECISION); + assert_eq!(market_after.amm.total_liquidation_fee(), QUOTE_PRECISION); } #[test] @@ -1016,19 +1016,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1048,7 +1048,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1148,19 +1148,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1180,7 +1180,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1280,19 +1280,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1312,7 +1312,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -1402,7 +1402,7 @@ pub mod liquidate_perp { let market_after = perp_market_map.get_ref(&0).unwrap(); assert_eq!( - market_after.amm.total_liquidation_fee, + market_after.amm.total_liquidation_fee(), QUOTE_PRECISION / 100 ); } @@ -1426,19 +1426,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1458,7 +1458,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1703,19 +1703,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1735,7 +1735,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1840,19 +1840,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -1872,7 +1872,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1964,19 +1964,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: 3600, @@ -1997,7 +1997,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2070,7 +2070,7 @@ pub mod liquidate_perp { let market_after = perp_market_map.get_ref(&0).unwrap(); // .5% * 100 * .95 =$0.475 - assert_eq!(market_after.amm.total_liquidation_fee, 475000); + assert_eq!(market_after.amm.total_liquidation_fee(), 475000); } #[test] @@ -2092,19 +2092,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: 3600, @@ -2125,7 +2125,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2198,7 +2198,7 @@ pub mod liquidate_perp { let market_after = perp_market_map.get_ref(&0).unwrap(); assert!(!user.is_being_liquidated()); - assert_eq!(market_after.amm.total_liquidation_fee, 41787043); + assert_eq!(market_after.amm.total_liquidation_fee(), 41787043); } #[test] @@ -2220,19 +2220,19 @@ pub mod liquidate_perp { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), funding_period: ONE_HOUR, @@ -2254,7 +2254,7 @@ pub mod liquidate_perp { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2373,7 +2373,7 @@ pub mod liquidate_perp { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, -149250000); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 750000) + assert_eq!(market_after.amm.total_liquidation_fee(), 750000) } } @@ -2431,21 +2431,21 @@ pub mod liquidate_perp_with_fill { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: 0, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: 0.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -2464,7 +2464,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2618,7 +2618,7 @@ pub mod liquidate_perp_with_fill { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, 3600); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 360000); + assert_eq!(market_after.amm.total_liquidation_fee(), 360000); } #[test] @@ -2640,21 +2640,21 @@ pub mod liquidate_perp_with_fill { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: 0, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: 0.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -2673,7 +2673,7 @@ pub mod liquidate_perp_with_fill { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2827,7 +2827,7 @@ pub mod liquidate_perp_with_fill { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, 3600); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 360000); + assert_eq!(market_after.amm.total_liquidation_fee(), 360000); } #[test] @@ -2851,21 +2851,21 @@ pub mod liquidate_perp_with_fill { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: 0, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: 0.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -2879,15 +2879,15 @@ pub mod liquidate_perp_with_fill { ..PerpMarket::default() }; market.amm.max_fill_reserve_fraction = 1; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let perp_market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -2998,7 +2998,7 @@ pub mod liquidate_perp_with_fill { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, 3587); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 358708); + assert_eq!(market_after.amm.total_liquidation_fee(), 358708); } #[test] @@ -3022,21 +3022,21 @@ pub mod liquidate_perp_with_fill { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: 0, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: 0.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -3050,15 +3050,15 @@ pub mod liquidate_perp_with_fill { ..PerpMarket::default() }; market.amm.max_fill_reserve_fraction = 1; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let perp_market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -3169,7 +3169,7 @@ pub mod liquidate_perp_with_fill { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, 3613); let market_after = perp_market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 361300); + assert_eq!(market_after.amm.total_liquidation_fee(), 361300); } } @@ -3226,11 +3226,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3244,15 +3244,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -3369,11 +3369,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3387,15 +3387,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 1442 / 10000), @@ -3543,11 +3543,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3561,15 +3561,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -3725,7 +3725,7 @@ pub mod liquidate_spot { let market_after = spot_market_map.get_ref(&1).unwrap(); let market_revenue = get_token_amount( - market_after.revenue_pool.scaled_balance, + market_after.revenue_pool.scaled_balance(), &market_after, &SpotBalanceType::Deposit, ) @@ -3734,7 +3734,7 @@ pub mod liquidate_spot { assert_eq!(market_revenue, 593); assert_eq!( liquidator.spot_positions[1].scaled_balance + user.spot_positions[1].scaled_balance - - market_after.revenue_pool.scaled_balance as u64, + - market_after.revenue_pool.scaled_balance() as u64, SPOT_BALANCE_PRECISION_U64 ); } @@ -3762,11 +3762,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3780,15 +3780,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -3889,11 +3889,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -3907,15 +3907,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -4016,11 +4016,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4034,15 +4034,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4148,11 +4148,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4166,15 +4166,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, - borrow_balance: 10 * SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (10 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4378,11 +4378,11 @@ pub mod liquidate_spot { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4396,15 +4396,15 @@ pub mod liquidate_spot { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 20, historical_oracle_data: HistoricalOracleData { @@ -4418,11 +4418,11 @@ pub mod liquidate_spot { let mut usdt_market = SpotMarket { market_index: 2, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4506,7 +4506,7 @@ pub mod liquidate_spot { let liability_market = spot_market_map.get_ref(&1).unwrap(); let revenue_pool_token_amount = get_token_amount( - liability_market.revenue_pool.scaled_balance, + liability_market.revenue_pool.scaled_balance(), &liability_market, &SpotBalanceType::Deposit, ) @@ -4579,19 +4579,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -4610,11 +4610,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4628,15 +4628,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -4734,19 +4734,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -4765,11 +4765,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4783,15 +4783,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -4906,7 +4906,7 @@ pub mod liquidate_borrow_for_perp_pnl { let market_after = spot_market_map.get_ref(&1).unwrap(); let market_revenue = get_token_amount( - market_after.revenue_pool.scaled_balance, + market_after.revenue_pool.scaled_balance(), &market_after, &SpotBalanceType::Deposit, ) @@ -4934,19 +4934,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -4964,11 +4964,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -4982,15 +4982,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5088,19 +5088,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -5119,11 +5119,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5137,15 +5137,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5235,19 +5235,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -5266,11 +5266,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5284,15 +5284,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5382,19 +5382,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -5413,11 +5413,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5431,15 +5431,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION / 50, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: (SPOT_BALANCE_PRECISION / 50).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -5539,19 +5539,19 @@ pub mod liquidate_borrow_for_perp_pnl { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -5570,11 +5570,11 @@ pub mod liquidate_borrow_for_perp_pnl { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5588,15 +5588,15 @@ pub mod liquidate_borrow_for_perp_pnl { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - borrow_balance: 11 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (11 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { @@ -5813,19 +5813,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -5844,11 +5844,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -5862,15 +5862,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -5968,19 +5968,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6000,11 +6000,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6018,15 +6018,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6105,7 +6105,7 @@ pub mod liquidate_perp_pnl_for_deposit { assert_eq!(liquidator.perp_positions[0].quote_asset_amount, -25636363); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_liquidation_fee, 0); + assert_eq!(market_after.amm.total_liquidation_fee(), 0); } #[test] @@ -6127,19 +6127,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6158,11 +6158,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6176,15 +6176,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6282,19 +6282,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6313,11 +6313,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6331,15 +6331,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6429,19 +6429,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6460,11 +6460,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6478,15 +6478,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6576,19 +6576,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6608,11 +6608,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6626,15 +6626,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6732,19 +6732,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6764,11 +6764,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -6782,15 +6782,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -6965,19 +6965,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -6996,11 +6996,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, asset_tier: AssetTier::Collateral, historical_oracle_data: HistoricalOracleData { @@ -7016,15 +7016,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -7197,19 +7197,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -7228,19 +7228,19 @@ pub mod liquidate_perp_pnl_for_deposit { let mut bonk_market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 8000, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 8000.into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: sol_oracle_price_key, ..AMM::default() }, @@ -7266,11 +7266,11 @@ pub mod liquidate_perp_pnl_for_deposit { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -7284,15 +7284,15 @@ pub mod liquidate_perp_pnl_for_deposit { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (sol_oracle_price.agg.price * 99 / 100), @@ -7476,24 +7476,24 @@ pub mod resolve_perp_bankruptcy { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_long: 5 * BASE_PRECISION_I128, - base_asset_amount_short: -5 * BASE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_long: (5 * BASE_PRECISION_I128).into(), + base_asset_amount_short: (-5 * BASE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, - cumulative_funding_rate_long: 1000 * FUNDING_RATE_PRECISION_I128, - cumulative_funding_rate_short: -1000 * FUNDING_RATE_PRECISION_I128, + cumulative_funding_rate_long: (1000 * FUNDING_RATE_PRECISION_I128).into(), + cumulative_funding_rate_short: (-1000 * FUNDING_RATE_PRECISION_I128).into(), ..AMM::default() }, margin_ratio_initial: 1000, @@ -7509,7 +7509,7 @@ pub mod resolve_perp_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, historical_oracle_data: HistoricalOracleData { @@ -7567,10 +7567,16 @@ pub mod resolve_perp_bankruptcy { expected_user.total_social_loss = 100000000; let mut expected_market = market; - expected_market.amm.cumulative_funding_rate_long = 1010 * FUNDING_RATE_PRECISION_I128; - expected_market.amm.cumulative_funding_rate_short = -1010 * FUNDING_RATE_PRECISION_I128; - expected_market.amm.total_social_loss = 100000000; - expected_market.amm.quote_asset_amount = -50 * QUOTE_PRECISION_I128; + expected_market + .amm + .set_cumulative_funding_rate_long(1010 * FUNDING_RATE_PRECISION_I128); + expected_market + .amm + .set_cumulative_funding_rate_short(-1010 * FUNDING_RATE_PRECISION_I128); + expected_market.amm.set_total_social_loss(100000000); + expected_market + .amm + .set_quote_asset_amount(-50 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; resolve_perp_bankruptcy( @@ -7686,26 +7692,26 @@ pub mod resolve_perp_bankruptcy { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_long: 5 * BASE_PRECISION_I128, - base_asset_amount_short: -5 * BASE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_long: (5 * BASE_PRECISION_I128).into(), + base_asset_amount_short: (-5 * BASE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, - cumulative_funding_rate_long: 1000 * FUNDING_RATE_PRECISION_I128, - cumulative_funding_rate_short: -1000 * FUNDING_RATE_PRECISION_I128, + cumulative_funding_rate_long: (1000 * FUNDING_RATE_PRECISION_I128).into(), + cumulative_funding_rate_short: (-1000 * FUNDING_RATE_PRECISION_I128).into(), fee_pool: PoolBalance { - scaled_balance: 50 * SPOT_BALANCE_PRECISION, + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -7723,9 +7729,9 @@ pub mod resolve_perp_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, - deposit_balance: 500 * SPOT_BALANCE_PRECISION, + deposit_balance: (500 * SPOT_BALANCE_PRECISION).into(), oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -7778,12 +7784,18 @@ pub mod resolve_perp_bankruptcy { expected_user.total_social_loss = 100000000; let mut expected_market = market; - expected_market.amm.cumulative_funding_rate_long = 1005 * FUNDING_RATE_PRECISION_I128; - expected_market.amm.cumulative_funding_rate_short = -1005 * FUNDING_RATE_PRECISION_I128; - expected_market.amm.total_social_loss = 50000000; - expected_market.amm.quote_asset_amount = -50 * QUOTE_PRECISION_I128; + expected_market + .amm + .set_cumulative_funding_rate_long(1005 * FUNDING_RATE_PRECISION_I128); + expected_market + .amm + .set_cumulative_funding_rate_short(-1005 * FUNDING_RATE_PRECISION_I128); + expected_market.amm.set_total_social_loss(50000000); + expected_market + .amm + .set_quote_asset_amount(-50 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; - expected_market.amm.fee_pool.scaled_balance = 0; + expected_market.amm.fee_pool.set_scaled_balance(0); resolve_perp_bankruptcy( 0, @@ -7929,24 +7941,24 @@ pub mod resolve_spot_bankruptcy { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: 5 * BASE_PRECISION_I128, - base_asset_amount_short: -5 * BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: (5 * BASE_PRECISION_I128).into(), + base_asset_amount_short: (-5 * BASE_PRECISION_I128).into(), oracle: oracle_price_key, - cumulative_funding_rate_long: 1000 * FUNDING_RATE_PRECISION_I128, - cumulative_funding_rate_short: -1000 * FUNDING_RATE_PRECISION_I128, + cumulative_funding_rate_long: (1000 * FUNDING_RATE_PRECISION_I128).into(), + cumulative_funding_rate_short: (-1000 * FUNDING_RATE_PRECISION_I128).into(), ..AMM::default() }, margin_ratio_initial: 1000, @@ -7961,12 +7973,12 @@ pub mod resolve_spot_bankruptcy { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -8015,11 +8027,11 @@ pub mod resolve_spot_bankruptcy { expected_user.total_social_loss = 100000000; let mut expected_spot_market = spot_market; - expected_spot_market.borrow_balance = 0; - expected_spot_market.cumulative_deposit_interest = - 9 * SPOT_CUMULATIVE_INTEREST_PRECISION / 10; - expected_spot_market.total_social_loss = 100 * QUOTE_PRECISION; - expected_spot_market.total_quote_social_loss = 100 * QUOTE_PRECISION; + expected_spot_market.set_borrow_balance(0); + expected_spot_market + .set_cumulative_deposit_interest(9 * SPOT_CUMULATIVE_INTEREST_PRECISION / 10); + expected_spot_market.set_total_social_loss(100 * QUOTE_PRECISION); + expected_spot_market.set_total_quote_social_loss(100 * QUOTE_PRECISION); resolve_spot_bankruptcy( 0, @@ -8039,7 +8051,7 @@ pub mod resolve_spot_bankruptcy { assert_eq!(expected_spot_market, *spot_market_map.get_ref(&0).unwrap()); let spot_market = spot_market_map.get_ref_mut(&0).unwrap(); - let deposit_balance = spot_market.deposit_balance; + let deposit_balance = spot_market.deposit_balance(); let deposit_token_amount = get_token_amount(deposit_balance, &spot_market, &SpotBalanceType::Deposit).unwrap(); @@ -8095,19 +8107,19 @@ pub mod set_user_status_to_being_liquidated { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -8126,7 +8138,7 @@ pub mod set_user_status_to_being_liquidated { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -8272,19 +8284,19 @@ pub mod set_user_status_to_being_liquidated { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -8303,7 +8315,7 @@ pub mod set_user_status_to_being_liquidated { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -8413,11 +8425,11 @@ pub mod liquidate_spot_with_swap { let mut usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 200 * SPOT_BALANCE_PRECISION, + deposit_balance: (200 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: QUOTE_PRECISION_I64, @@ -8431,15 +8443,15 @@ pub mod liquidate_spot_with_swap { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, if_liquidation_fee: LIQUIDATION_FEE_PRECISION / 100, historical_oracle_data: HistoricalOracleData { @@ -8579,7 +8591,7 @@ pub mod liquidate_spot_with_swap { ); let market_revenue = get_token_amount( - sol_spot_market.revenue_pool.scaled_balance, + sol_spot_market.revenue_pool.scaled_balance(), &sol_spot_market, &SpotBalanceType::Deposit, ) diff --git a/programs/drift/src/controller/lp.rs b/programs/drift/src/controller/lp.rs index 9dc8e3b489..5f967dbbc9 100644 --- a/programs/drift/src/controller/lp.rs +++ b/programs/drift/src/controller/lp.rs @@ -40,25 +40,25 @@ pub fn apply_lp_rebase_to_perp_market( let rebase_divisor: i128 = 10_i128.pow(expo_diff.abs().cast()?); if expo_diff > 0 { - perp_market.amm.base_asset_amount_per_lp = perp_market + perp_market.amm.set_base_asset_amount_per_lp(perp_market .amm - .base_asset_amount_per_lp - .safe_mul(rebase_divisor)?; + .base_asset_amount_per_lp() + .safe_mul(rebase_divisor)?); - perp_market.amm.quote_asset_amount_per_lp = perp_market + perp_market.amm.set_quote_asset_amount_per_lp(perp_market .amm - .quote_asset_amount_per_lp - .safe_mul(rebase_divisor)?; + .quote_asset_amount_per_lp() + .safe_mul(rebase_divisor)?); } else { - perp_market.amm.base_asset_amount_per_lp = perp_market + perp_market.amm.set_base_asset_amount_per_lp(perp_market .amm - .base_asset_amount_per_lp - .safe_div(rebase_divisor)?; + .base_asset_amount_per_lp() + .safe_div(rebase_divisor)?); - perp_market.amm.quote_asset_amount_per_lp = perp_market + perp_market.amm.set_quote_asset_amount_per_lp(perp_market .amm - .quote_asset_amount_per_lp - .safe_div(rebase_divisor)?; + .quote_asset_amount_per_lp() + .safe_div(rebase_divisor)?); } msg!( @@ -260,10 +260,10 @@ pub fn burn_lp_shares( let base_asset_amount = position.remainder_base_asset_amount as i128; // user closes the dust - market.amm.base_asset_amount_with_amm = market + market.amm.set_base_asset_amount_with_amm(market .amm - .base_asset_amount_with_amm - .safe_sub(base_asset_amount)?; + .base_asset_amount_with_amm() + .safe_sub(base_asset_amount)?); market.amm.base_asset_amount_with_unsettled_lp = market .amm diff --git a/programs/drift/src/controller/orders.rs b/programs/drift/src/controller/orders.rs index 76407a7dad..56937bd917 100644 --- a/programs/drift/src/controller/orders.rs +++ b/programs/drift/src/controller/orders.rs @@ -391,17 +391,17 @@ pub fn place_perp_order( )?; } - let max_oi = market.amm.max_open_interest; + let max_oi = market.amm.max_open_interest(); if max_oi != 0 && risk_increasing { let oi_plus_order = match params.direction { PositionDirection::Long => market .amm - .base_asset_amount_long + .base_asset_amount_long() .safe_add(order_base_asset_amount.cast()?)? .unsigned_abs(), PositionDirection::Short => market .amm - .base_asset_amount_short + .base_asset_amount_short() .safe_sub(order_base_asset_amount.cast()?)? .unsigned_abs(), }; @@ -1354,7 +1354,7 @@ pub fn fill_perp_order( let market = perp_market_map.get_ref(&market_index)?; let open_interest = market.get_open_interest(); - let max_open_interest = market.amm.max_open_interest; + let max_open_interest = market.amm.max_open_interest(); validate!( max_open_interest == 0 || max_open_interest > open_interest, @@ -2299,16 +2299,24 @@ pub fn fulfill_perp_order_with_amm( } // Increment the protocol's total fee variables - market.amm.total_fee = market.amm.total_fee.safe_add(fee_to_market.cast()?)?; - market.amm.total_exchange_fee = market.amm.total_exchange_fee.safe_add(user_fee.cast()?)?; - market.amm.total_mm_fee = market + market .amm - .total_mm_fee - .safe_add(quote_asset_amount_surplus.cast()?)?; - market.amm.total_fee_minus_distributions = market + .set_total_fee(market.amm.total_fee().safe_add(fee_to_market.cast()?)?); + market .amm - .total_fee_minus_distributions - .safe_add(fee_to_market.cast()?)?; + .set_total_exchange_fee(market.amm.total_exchange_fee().safe_add(user_fee.cast()?)?); + market.amm.set_total_mm_fee( + market + .amm + .total_mm_fee() + .safe_add(quote_asset_amount_surplus.cast()?)?, + ); + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_add(fee_to_market.cast()?)?, + ); market.amm.net_revenue_since_last_funding = market .amm .net_revenue_since_last_funding @@ -2812,15 +2820,21 @@ pub fn fulfill_perp_order_with_match( } // Increment the markets house's total fee variables - market.amm.total_fee = market.amm.total_fee.safe_add(fee_to_market.cast()?)?; - market.amm.total_exchange_fee = market - .amm - .total_exchange_fee - .safe_add(fee_to_market.cast()?)?; - market.amm.total_fee_minus_distributions = market + market .amm - .total_fee_minus_distributions - .safe_add(fee_to_market.cast()?)?; + .set_total_fee(market.amm.total_fee().safe_add(fee_to_market.cast()?)?); + market.amm.set_total_exchange_fee( + market + .amm + .total_exchange_fee() + .safe_add(fee_to_market.cast()?)?, + ); + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_add(fee_to_market.cast()?)?, + ); market.amm.net_revenue_since_last_funding = market .amm .net_revenue_since_last_funding @@ -4991,7 +5005,11 @@ pub fn fulfill_spot_order_with_match( } // Update base market - base_market.total_spot_fee = base_market.total_spot_fee.safe_add(fee_to_market.cast()?)?; + base_market.set_total_spot_fee( + base_market + .total_spot_fee() + .safe_add(fee_to_market.cast()?)?, + ); update_spot_balances( fee_to_market.cast()?, @@ -5159,7 +5177,7 @@ pub fn fulfill_spot_order_with_external_market( )?; let fee_pool_amount = get_token_amount( - base_market.spot_fee_pool.scaled_balance, + base_market.spot_fee_pool.scaled_balance(), quote_market, &SpotBalanceType::Deposit, )?; @@ -5280,7 +5298,11 @@ pub fn fulfill_spot_order_with_external_market( )?; } - base_market.total_spot_fee = base_market.total_spot_fee.safe_add(fee_to_market.cast()?)?; + base_market.set_total_spot_fee( + base_market + .total_spot_fee() + .safe_add(fee_to_market.cast()?)?, + ); let fill_record_id = get_then_update_id!(base_market, next_fill_record_id); let order_action_record = get_order_action_record( diff --git a/programs/drift/src/controller/orders/amm_jit_tests.rs b/programs/drift/src/controller/orders/amm_jit_tests.rs index 4ab526d1f9..25668a8a29 100644 --- a/programs/drift/src/controller/orders/amm_jit_tests.rs +++ b/programs/drift/src/controller/orders/amm_jit_tests.rs @@ -115,12 +115,12 @@ pub mod amm_jit { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -145,9 +145,9 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.base_asset_reserve = 0; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_base_asset_reserve(0); + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -155,10 +155,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); // shouldnt throw an error when bids/asks are zero crate::math::amm_jit::calculate_jit_base_asset_amount( @@ -191,12 +199,12 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -221,8 +229,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -230,10 +238,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); assert_eq!(new_bid_quote_asset_reserve, 99000000000); create_anchor_account_info!(market, PerpMarket, market_account_info); @@ -242,7 +258,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -375,8 +391,8 @@ pub mod amm_jit { let market_after = market_map.get_ref(&0).unwrap(); // amm jit doesnt take anything assert_eq!( - market_after.amm.base_asset_amount_with_amm, - market.amm.base_asset_amount_with_amm + market_after.amm.base_asset_amount_with_amm(), + market.amm.base_asset_amount_with_amm() ); } @@ -400,16 +416,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_short: -((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 90 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (90 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -423,8 +439,8 @@ pub mod amm_jit { ..HistoricalOracleData::default() }, - user_lp_shares: 10 * AMM_RESERVE_PRECISION, // some lps exist - concentration_coef: CONCENTRATION_PRECISION + 1, + user_lp_shares: (10 * AMM_RESERVE_PRECISION).into(), // some lps exist + concentration_coef: (CONCENTRATION_PRECISION + 1).into(), ..AMM::default() }, margin_ratio_initial: 1000, @@ -432,8 +448,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -441,7 +457,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -529,11 +545,11 @@ pub mod amm_jit { let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -588,12 +604,12 @@ pub mod amm_jit { // nets to zero let market_after = market_map.get_ref(&0).unwrap(); assert_eq!( - market_after.amm.base_asset_amount_with_amm, + market_after.amm.base_asset_amount_with_amm(), BASE_PRECISION_I128 / 2 ); // make sure lps didnt get anything - assert_eq!(market_after.amm.base_asset_amount_per_lp, 0); + assert_eq!(market_after.amm.base_asset_amount_per_lp(), 0); } #[test] @@ -616,16 +632,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_short: -((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -639,8 +655,8 @@ pub mod amm_jit { ..HistoricalOracleData::default() }, - user_lp_shares: 10 * AMM_RESERVE_PRECISION, // some lps exist - concentration_coef: CONCENTRATION_PRECISION + 1, + user_lp_shares: (10 * AMM_RESERVE_PRECISION).into(), // some lps exist + concentration_coef: (CONCENTRATION_PRECISION + 1).into(), ..AMM::default() }, margin_ratio_initial: 1000, @@ -648,8 +664,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -657,7 +673,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -745,11 +761,11 @@ pub mod amm_jit { let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -795,17 +811,17 @@ pub mod amm_jit { let market_after = market_map.get_ref(&0).unwrap(); // nets to zero - assert_eq!(market_after.amm.base_asset_amount_with_amm, 0); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 0); // make sure lps didnt get anything - assert_eq!(market_after.amm.base_asset_amount_per_lp, 0); + assert_eq!(market_after.amm.base_asset_amount_per_lp(), 0); let maker = makers_and_referrers.get_ref_mut(&maker_key).unwrap(); let maker_position = &maker.perp_positions[0]; // maker got (full - net_baa) assert_eq!( maker_position.base_asset_amount as i128, - -BASE_PRECISION_I128 * 2 - market.amm.base_asset_amount_with_amm + -BASE_PRECISION_I128 * 2 - market.amm.base_asset_amount_with_amm() ); } @@ -829,16 +845,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -860,8 +876,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -869,7 +885,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -957,11 +973,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -1007,14 +1023,14 @@ pub mod amm_jit { let market_after = market_map.get_ref(&0).unwrap(); // nets to zero - assert_eq!(market_after.amm.base_asset_amount_with_amm, 0); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 0); let maker = makers_and_referrers.get_ref_mut(&maker_key).unwrap(); let maker_position = &maker.perp_positions[0]; // maker got (full - net_baa) assert_eq!( maker_position.base_asset_amount as i128, - BASE_PRECISION_I128 * taker_mul as i128 - market.amm.base_asset_amount_with_amm + BASE_PRECISION_I128 * taker_mul as i128 - market.amm.base_asset_amount_with_amm() ); } @@ -1038,16 +1054,16 @@ pub mod amm_jit { // amm is short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), // bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, // bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, // ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, // ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_short: -((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1071,18 +1087,26 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); assert_eq!(new_bid_quote_asset_reserve, 99000000000); @@ -1092,7 +1116,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1235,7 +1259,7 @@ pub mod amm_jit { assert_eq!(maker_position.open_orders, 0); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, -1000000000); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), -1000000000); } #[test] @@ -1258,15 +1282,15 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), base_spread: 250, long_spread: 125, short_spread: 125, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1288,8 +1312,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -1297,10 +1321,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1308,7 +1340,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1395,11 +1427,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -1448,11 +1480,12 @@ pub mod amm_jit { let market_after = market_map.get_ref(&0).unwrap(); assert!( - market_after.amm.base_asset_amount_with_amm.abs() - < market.amm.base_asset_amount_with_amm.abs() + market_after.amm.base_asset_amount_with_amm().abs() + < market.amm.base_asset_amount_with_amm().abs() ); - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - market.amm.total_mm_fee; + let quote_asset_amount_surplus = + market_after.amm.total_mm_fee() - market.amm.total_mm_fee(); assert!(quote_asset_amount_surplus > 0); } @@ -1476,24 +1509,24 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), base_spread: 250, long_spread: 125, short_spread: 125, max_spread: 20000, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - user_lp_shares: 20 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + user_lp_shares: (20 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, oracle: oracle_price_key, amm_jit_intensity: 100, - concentration_coef: CONCENTRATION_PRECISION + 1, + concentration_coef: (CONCENTRATION_PRECISION + 1).into(), historical_oracle_data: HistoricalOracleData { last_oracle_price: (100 * PRICE_PRECISION) as i64, last_oracle_price_twap: (100 * PRICE_PRECISION) as i64, @@ -1509,8 +1542,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -1518,10 +1551,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1529,7 +1570,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1616,11 +1657,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let (base_asset_amount, _) = fulfill_perp_order( &mut taker, @@ -1655,7 +1696,8 @@ pub mod amm_jit { assert_eq!(base_asset_amount, 500000000); // 1/2 base (half of otherwise) let market_after = market_map.get_ref(&0).unwrap(); - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - market.amm.total_mm_fee; + let quote_asset_amount_surplus = + market_after.amm.total_mm_fee() - market.amm.total_mm_fee(); assert_eq!(quote_asset_amount_surplus, 0); @@ -1683,16 +1725,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_short: -((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -1714,8 +1756,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -1723,10 +1765,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1734,7 +1784,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -1868,8 +1918,8 @@ pub mod amm_jit { // net baa improves let market_after = market_map.get_ref(&0).unwrap(); assert!( - market_after.amm.base_asset_amount_with_amm.abs() - < market.amm.base_asset_amount_with_amm.abs() + market_after.amm.base_asset_amount_with_amm().abs() + < market.amm.base_asset_amount_with_amm().abs() ); } @@ -1893,16 +1943,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_short: -((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1924,8 +1974,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1933,7 +1983,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2019,11 +2069,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -2075,16 +2125,17 @@ pub mod amm_jit { assert_eq!(maker_position.base_asset_amount, -BASE_PRECISION_I64 / 2); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, -250000000); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), -250000000); let taker_position = &taker.perp_positions[0]; assert_eq!( taker_position.base_asset_amount, - BASE_PRECISION_I64 + market_after.amm.base_asset_amount_with_amm as i64 + BASE_PRECISION_I64 + market_after.amm.base_asset_amount_with_amm() as i64 ); // market pays extra for trade - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - market.amm.total_mm_fee; + let quote_asset_amount_surplus = + market_after.amm.total_mm_fee() - market.amm.total_mm_fee(); assert!(quote_asset_amount_surplus < 0); } @@ -2108,16 +2159,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 100, @@ -2139,8 +2190,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2148,7 +2199,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2234,11 +2285,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let order_index = 0; let min_auction_duration = 10; @@ -2294,7 +2345,8 @@ pub mod amm_jit { ); // mm gains from trade - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - market.amm.total_mm_fee; + let quote_asset_amount_surplus = + market_after.amm.total_mm_fee() - market.amm.total_mm_fee(); assert!(quote_asset_amount_surplus < 0); } @@ -2320,12 +2372,12 @@ pub mod amm_jit { let reserves = 5 * AMM_RESERVE_PRECISION; let mut market = PerpMarket { amm: AMM { - base_asset_reserve: reserves, - quote_asset_reserve: reserves, - base_asset_amount_with_amm: -(100 * AMM_RESERVE_PRECISION as i128), - base_asset_amount_short: -(100 * AMM_RESERVE_PRECISION as i128), - sqrt_k: reserves, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: reserves.into(), + quote_asset_reserve: reserves.into(), + base_asset_amount_with_amm: (-(100 * AMM_RESERVE_PRECISION as i128)).into(), + base_asset_amount_short: (-(100 * AMM_RESERVE_PRECISION as i128)).into(), + sqrt_k: reserves.into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2350,8 +2402,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -2359,10 +2411,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2370,7 +2430,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2433,15 +2493,15 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let (mut neg, mut pos, mut none) = (false, false, false); let mut prev_mm_fee = 0; - let mut prev_net_baa = market.amm.base_asset_amount_with_amm; + let mut prev_net_baa = market.amm.base_asset_amount_with_amm(); // track scaling let mut prev_qas = 0; let mut has_set_prev_qas = false; @@ -2537,12 +2597,12 @@ pub mod amm_jit { .unwrap(); let market_after = market_map.get_ref(&0).unwrap(); - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - prev_mm_fee; - prev_mm_fee = market_after.amm.total_mm_fee; + let quote_asset_amount_surplus = market_after.amm.total_mm_fee() - prev_mm_fee; + prev_mm_fee = market_after.amm.total_mm_fee(); // imbalance decreases - assert!(market_after.amm.base_asset_amount_with_amm.abs() < prev_net_baa.abs()); - prev_net_baa = market_after.amm.base_asset_amount_with_amm; + assert!(market_after.amm.base_asset_amount_with_amm().abs() < prev_net_baa.abs()); + prev_net_baa = market_after.amm.base_asset_amount_with_amm(); println!( "slot {} auction: {} surplus: {}", @@ -2602,12 +2662,12 @@ pub mod amm_jit { let reserves = 5 * AMM_RESERVE_PRECISION; let mut market = PerpMarket { amm: AMM { - base_asset_reserve: reserves, - quote_asset_reserve: reserves, - base_asset_amount_with_amm: 100 * AMM_RESERVE_PRECISION as i128, - base_asset_amount_long: 100 * AMM_RESERVE_PRECISION as i128, - sqrt_k: reserves, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: reserves.into(), + quote_asset_reserve: reserves.into(), + base_asset_amount_with_amm: (100 * AMM_RESERVE_PRECISION as i128).into(), + base_asset_amount_long: (100 * AMM_RESERVE_PRECISION as i128).into(), + sqrt_k: reserves.into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1, @@ -2633,8 +2693,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -2642,10 +2702,18 @@ pub mod amm_jit { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2653,7 +2721,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -2717,15 +2785,15 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); let (mut neg, mut pos, mut none) = (false, false, false); let mut prev_mm_fee = 0; - let mut prev_net_baa = market.amm.base_asset_amount_with_amm; + let mut prev_net_baa = market.amm.base_asset_amount_with_amm(); // track scaling let mut prev_qas = 0; let mut has_set_prev_qas = false; @@ -2837,12 +2905,12 @@ pub mod amm_jit { .unwrap(); let market_after = market_map.get_ref(&0).unwrap(); - let quote_asset_amount_surplus = market_after.amm.total_mm_fee - prev_mm_fee; - prev_mm_fee = market_after.amm.total_mm_fee; + let quote_asset_amount_surplus = market_after.amm.total_mm_fee() - prev_mm_fee; + prev_mm_fee = market_after.amm.total_mm_fee(); // imbalance decreases or remains the same (damm wont always take on positions) - assert!(market_after.amm.base_asset_amount_with_amm.abs() <= prev_net_baa.abs()); - prev_net_baa = market_after.amm.base_asset_amount_with_amm; + assert!(market_after.amm.base_asset_amount_with_amm().abs() <= prev_net_baa.abs()); + prev_net_baa = market_after.amm.base_asset_amount_with_amm(); println!( "slot {} auction: {} surplus: {}", @@ -2900,16 +2968,16 @@ pub mod amm_jit { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -2931,8 +2999,8 @@ pub mod amm_jit { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2940,7 +3008,7 @@ pub mod amm_jit { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3030,11 +3098,11 @@ pub mod amm_jit { let maker_and_referrer_stats = UserStatsMap::load_one(&maker_stats_account_info).unwrap(); let mut filler_stats = UserStats::default(); - assert_eq!(market.amm.total_fee, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee(), 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_mm_fee, 0); - assert_eq!(market.amm.total_fee_withdrawn, 0); + assert_eq!(market.amm.total_mm_fee(), 0); + assert_eq!(market.amm.total_fee_withdrawn(), 0); assert_eq!(taker.perp_positions[0].open_orders, 1); // fulfill with match @@ -3085,7 +3153,7 @@ pub mod amm_jit { assert_eq!(base_asset_amount, 1000000000); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.total_mm_fee, 2033008); // jit occured even tho maker offered full amount - assert_eq!(market_after.amm.total_fee, 2057287); + assert_eq!(market_after.amm.total_mm_fee(), 2033008); // jit occured even tho maker offered full amount + assert_eq!(market_after.amm.total_fee(), 2057287); } } diff --git a/programs/drift/src/controller/orders/fuel_tests.rs b/programs/drift/src/controller/orders/fuel_tests.rs index 5684875e6f..d12e5f9843 100644 --- a/programs/drift/src/controller/orders/fuel_tests.rs +++ b/programs/drift/src/controller/orders/fuel_tests.rs @@ -124,12 +124,12 @@ pub mod fuel_scoring { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -157,8 +157,8 @@ pub mod fuel_scoring { fuel_boost_taker: 50, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -166,10 +166,18 @@ pub mod fuel_scoring { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); assert_eq!(new_bid_quote_asset_reserve, 99000000000); create_anchor_account_info!(market, PerpMarket, market_account_info); @@ -178,7 +186,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -315,8 +323,8 @@ pub mod fuel_scoring { let market_after = market_map.get_ref(&0).unwrap(); assert_eq!( - market_after.amm.base_asset_amount_with_amm, - market.amm.base_asset_amount_with_amm + market_after.amm.base_asset_amount_with_amm(), + market.amm.base_asset_amount_with_amm() ); assert_ne!(taker.get_perp_position(0).unwrap().base_asset_amount, 0); let maker_after: std::cell::RefMut = @@ -402,12 +410,12 @@ pub mod fuel_scoring { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -435,8 +443,8 @@ pub mod fuel_scoring { fuel_boost_taker: 50, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -444,10 +452,18 @@ pub mod fuel_scoring { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); assert_eq!(new_bid_quote_asset_reserve, 99000000000); create_anchor_account_info!(market, PerpMarket, market_account_info); @@ -456,7 +472,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -473,8 +489,8 @@ pub mod fuel_scoring { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION * 2, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION * 4, + cumulative_deposit_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION * 2).into(), + cumulative_borrow_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION * 4).into(), decimals: 9, initial_asset_weight: SPOT_WEIGHT_PRECISION * 8 / 10, maintenance_asset_weight: SPOT_WEIGHT_PRECISION * 9 / 10, @@ -588,8 +604,8 @@ pub mod fuel_scoring { let market_after = market_map.get_ref(&0).unwrap(); assert_eq!( - market_after.amm.base_asset_amount_with_amm, - market.amm.base_asset_amount_with_amm + market_after.amm.base_asset_amount_with_amm(), + market.amm.base_asset_amount_with_amm() ); assert_eq!(taker.get_perp_position(0).unwrap().base_asset_amount, 0); now += 86400; // one day @@ -672,12 +688,12 @@ pub mod fuel_scoring { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -705,8 +721,8 @@ pub mod fuel_scoring { fuel_boost_taker: 50, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) @@ -714,10 +730,18 @@ pub mod fuel_scoring { let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); assert_eq!(new_bid_quote_asset_reserve, 99000000000); create_anchor_account_info!(market, PerpMarket, market_account_info); @@ -726,7 +750,7 @@ pub mod fuel_scoring { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -819,8 +843,8 @@ pub mod fuel_scoring { let market_after = market_map.get_ref(&0).unwrap(); assert_eq!( - market_after.amm.base_asset_amount_with_amm, - market.amm.base_asset_amount_with_amm + market_after.amm.base_asset_amount_with_amm(), + market.amm.base_asset_amount_with_amm() ); assert_eq!(taker.get_perp_position(0).unwrap().base_asset_amount, 0); now += 86400; // one day diff --git a/programs/drift/src/controller/orders/tests.rs b/programs/drift/src/controller/orders/tests.rs index 931c0edeec..fe866f8e12 100644 --- a/programs/drift/src/controller/orders/tests.rs +++ b/programs/drift/src/controller/orders/tests.rs @@ -138,11 +138,11 @@ pub mod fill_order_protected_maker { let mut market = PerpMarket { paused_operations: PerpOperation::AmmFill as u8, amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -166,25 +166,33 @@ pub mod fill_order_protected_maker { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = i128::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(i128::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -572,12 +580,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_stats.maker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(maker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -697,12 +705,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_stats.maker_volume_30d, 160 * QUOTE_PRECISION_U64); assert!(maker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -32000); - assert_eq!(market.amm.total_fee, 32000); - assert_eq!(market.amm.total_fee_minus_distributions, 32000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -32000); + assert_eq!(market.amm.total_fee(), 32000); + assert_eq!(market.amm.total_fee_minus_distributions(), 32000); assert_eq!(market.amm.net_revenue_since_last_funding, 32000); } @@ -822,12 +830,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_stats.maker_volume_30d, 180 * QUOTE_PRECISION_U64); assert!(maker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -36000); - assert_eq!(market.amm.total_fee, 36000); - assert_eq!(market.amm.total_fee_minus_distributions, 36000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -36000); + assert_eq!(market.amm.total_fee(), 36000); + assert_eq!(market.amm.total_fee_minus_distributions(), 36000); assert_eq!(market.amm.net_revenue_since_last_funding, 36000); } @@ -947,12 +955,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_stats.maker_volume_30d, 140 * QUOTE_PRECISION_U64); assert!(maker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -28000); - assert_eq!(market.amm.total_fee, 28000); - assert_eq!(market.amm.total_fee_minus_distributions, 28000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -28000); + assert_eq!(market.amm.total_fee(), 28000); + assert_eq!(market.amm.total_fee_minus_distributions(), 28000); assert_eq!(market.amm.net_revenue_since_last_funding, 28000); } @@ -1428,10 +1436,10 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_position.quote_break_even_amount, 120072000); assert_eq!(maker_stats.maker_volume_30d, 120 * QUOTE_PRECISION_U64); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -48000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -48000); } #[test] @@ -1540,10 +1548,10 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_position.quote_break_even_amount, 120072000); assert_eq!(maker_stats.maker_volume_30d, 120 * QUOTE_PRECISION_U64); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -48000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -48000); } #[test] @@ -1667,12 +1675,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(maker_stats.maker_volume_30d, 150 * QUOTE_PRECISION_U64); assert!(maker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -30000); - assert_eq!(market.amm.total_fee, 30000); - assert_eq!(market.amm.total_fee_minus_distributions, 30000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -30000); + assert_eq!(market.amm.total_fee(), 30000); + assert_eq!(market.amm.total_fee_minus_distributions(), 30000); assert_eq!(market.amm.net_revenue_since_last_funding, 30000); } @@ -1789,12 +1797,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -1912,12 +1920,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -1964,16 +1972,16 @@ pub mod fulfill_order_with_maker_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -2078,16 +2086,16 @@ pub mod fulfill_order_with_maker_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -2315,12 +2323,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -2468,12 +2476,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -2619,12 +2627,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -2771,12 +2779,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -2904,12 +2912,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } @@ -3036,12 +3044,12 @@ pub mod fulfill_order_with_maker_order { assert_eq!(taker_stats.taker_volume_30d, 100 * QUOTE_PRECISION_U64); assert!(taker.orders[0].is_available()); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.base_asset_amount_long, BASE_PRECISION_I128); - assert_eq!(market.amm.base_asset_amount_short, -BASE_PRECISION_I128); - assert_eq!(market.amm.quote_asset_amount, -20000); - assert_eq!(market.amm.total_fee, 20000); - assert_eq!(market.amm.total_fee_minus_distributions, 20000); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.base_asset_amount_long(), BASE_PRECISION_I128); + assert_eq!(market.amm.base_asset_amount_short(), -BASE_PRECISION_I128); + assert_eq!(market.amm.quote_asset_amount(), -20000); + assert_eq!(market.amm.total_fee(), 20000); + assert_eq!(market.amm.total_fee_minus_distributions(), 20000); assert_eq!(market.amm.net_revenue_since_last_funding, 20000); } } @@ -3087,14 +3095,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -3116,8 +3124,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let mut state = State { oracle_guard_rails: OracleGuardRails { @@ -3174,14 +3182,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3202,8 +3210,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = i128::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(i128::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let mut state = State { min_perp_auction_duration: 1, @@ -3243,14 +3251,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3271,8 +3279,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3280,7 +3288,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3446,10 +3454,10 @@ pub mod fulfill_order { assert_eq!(filler.perp_positions[0].quote_asset_amount, 5012); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 500000000); - assert_eq!(market_after.amm.base_asset_amount_long, 1000000000); - assert_eq!(market_after.amm.base_asset_amount_short, -500000000); - assert_eq!(market_after.amm.quote_asset_amount, -50281374); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 500000000); + assert_eq!(market_after.amm.base_asset_amount_long(), 1000000000); + assert_eq!(market_after.amm.base_asset_amount_short(), -500000000); + assert_eq!(market_after.amm.quote_asset_amount(), -50281374); let expected_market_fee = ((taker_stats.fees.total_fee_paid - (maker_stats.fees.total_fee_rebate @@ -3458,9 +3466,9 @@ pub mod fulfill_order { + 1; //todo // assert_eq!(expected_market_fee, 35100); - assert_eq!(market_after.amm.total_fee, expected_market_fee); + assert_eq!(market_after.amm.total_fee(), expected_market_fee); assert_eq!( - market_after.amm.total_fee_minus_distributions, + market_after.amm.total_fee_minus_distributions(), expected_market_fee ); assert_eq!( @@ -3491,14 +3499,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3519,8 +3527,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3528,7 +3536,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3710,14 +3718,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100_050 * PEG_PRECISION / 1000, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100_050 * PEG_PRECISION / 1000).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3738,8 +3746,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3747,7 +3755,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -3910,19 +3918,19 @@ pub mod fulfill_order { assert_eq!(filler.perp_positions[0].quote_asset_amount, 5013); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 500000000); - assert_eq!(market_after.amm.base_asset_amount_long, 1000000000); - assert_eq!(market_after.amm.base_asset_amount_short, -500000000); - assert_eq!(market_after.amm.quote_asset_amount, -50306510); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 500000000); + assert_eq!(market_after.amm.base_asset_amount_long(), 1000000000); + assert_eq!(market_after.amm.base_asset_amount_short(), -500000000); + assert_eq!(market_after.amm.quote_asset_amount(), -50306510); let expected_market_fee = (taker_stats.fees.total_fee_paid - (maker_stats.fees.total_fee_rebate + filler.perp_positions[0].quote_asset_amount as u64)) as i128; assert_eq!(expected_market_fee, 30128); - assert_eq!(market_after.amm.total_fee, expected_market_fee); + assert_eq!(market_after.amm.total_fee(), expected_market_fee); assert_eq!( - market_after.amm.total_fee_minus_distributions, + market_after.amm.total_fee_minus_distributions(), expected_market_fee ); assert_eq!( @@ -3938,14 +3946,14 @@ pub mod fulfill_order { fn fulfill_with_maker_with_auction_incomplete() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 1, order_tick_size: 1, historical_oracle_data: HistoricalOracleData { @@ -3969,7 +3977,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4126,12 +4134,12 @@ pub mod fulfill_order { assert_eq!(maker_stats.maker_volume_30d, 50 * QUOTE_PRECISION_U64); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 0); - assert_eq!(market_after.amm.base_asset_amount_long, 500000000); - assert_eq!(market_after.amm.base_asset_amount_short, -500000000); - assert_eq!(market_after.amm.quote_asset_amount, -10000); - assert_eq!(market_after.amm.total_fee, 10000); - assert_eq!(market_after.amm.total_fee_minus_distributions, 10000); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market_after.amm.base_asset_amount_long(), 500000000); + assert_eq!(market_after.amm.base_asset_amount_short(), -500000000); + assert_eq!(market_after.amm.quote_asset_amount(), -10000); + assert_eq!(market_after.amm.total_fee(), 10000); + assert_eq!(market_after.amm.total_fee_minus_distributions(), 10000); assert_eq!(market_after.amm.net_revenue_since_last_funding, 10000); } @@ -4154,14 +4162,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 10, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -4182,8 +4190,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -4191,7 +4199,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4294,12 +4302,12 @@ pub mod fulfill_order { assert!(taker.orders[0].is_available()); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 1000000000); - assert_eq!(market_after.amm.base_asset_amount_long, 1000000000); - assert_eq!(market_after.amm.base_asset_amount_short, 0); - assert_eq!(market_after.amm.quote_asset_amount, -104133674); - assert_eq!(market_after.amm.total_fee, 3123572); - assert_eq!(market_after.amm.total_fee_minus_distributions, 3123572); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 1000000000); + assert_eq!(market_after.amm.base_asset_amount_long(), 1000000000); + assert_eq!(market_after.amm.base_asset_amount_short(), 0); + assert_eq!(market_after.amm.quote_asset_amount(), -104133674); + assert_eq!(market_after.amm.total_fee(), 3123572); + assert_eq!(market_after.amm.total_fee_minus_distributions(), 3123572); assert_eq!(market_after.amm.net_revenue_since_last_funding, 3123572); } @@ -4323,14 +4331,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4352,8 +4360,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -4361,7 +4369,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4527,14 +4535,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4555,8 +4563,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -4564,7 +4572,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4714,14 +4722,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4742,8 +4750,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let reserve_price_before = market.amm.reserve_price().unwrap(); let bid_price = market.amm.bid_price(reserve_price_before).unwrap(); @@ -4755,7 +4763,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -4863,12 +4871,12 @@ pub mod fulfill_order { assert_eq!(taker_stats.maker_volume_30d, 3499697); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, -35032000); - assert_eq!(market_after.amm.base_asset_amount_long, 0); - assert_eq!(market_after.amm.base_asset_amount_short, -35032000); - assert_eq!(market_after.amm.quote_asset_amount, 3500868); - assert_eq!(market_after.amm.total_fee, 1105); - assert_eq!(market_after.amm.total_fee_minus_distributions, 1105); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), -35032000); + assert_eq!(market_after.amm.base_asset_amount_long(), 0); + assert_eq!(market_after.amm.base_asset_amount_short(), -35032000); + assert_eq!(market_after.amm.quote_asset_amount(), 3500868); + assert_eq!(market_after.amm.total_fee(), 1105); + assert_eq!(market_after.amm.total_fee_minus_distributions(), 1105); assert_eq!(market_after.amm.net_revenue_since_last_funding, 1105); let market_after = market_map.get_ref(&0).unwrap(); @@ -4896,14 +4904,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4924,8 +4932,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u64::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u64::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let reserve_price_before = market.amm.reserve_price().unwrap(); let bid_price = market.amm.bid_price(reserve_price_before).unwrap(); @@ -4937,7 +4945,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5045,12 +5053,12 @@ pub mod fulfill_order { assert_eq!(taker_stats.maker_volume_30d, 3500096); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 34966000); - assert_eq!(market_after.amm.base_asset_amount_long, 34966000); - assert_eq!(market_after.amm.base_asset_amount_short, 0); - assert_eq!(market_after.amm.quote_asset_amount, -3498924); - assert_eq!(market_after.amm.total_fee, 1100); - assert_eq!(market_after.amm.total_fee_minus_distributions, 1100); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 34966000); + assert_eq!(market_after.amm.base_asset_amount_long(), 34966000); + assert_eq!(market_after.amm.base_asset_amount_short(), 0); + assert_eq!(market_after.amm.quote_asset_amount(), -3498924); + assert_eq!(market_after.amm.total_fee(), 1100); + assert_eq!(market_after.amm.total_fee_minus_distributions(), 1100); assert_eq!(market_after.amm.net_revenue_since_last_funding, 1100); let market_after = market_map.get_ref(&0).unwrap(); @@ -5086,15 +5094,15 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -5117,8 +5125,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); market.status = MarketStatus::Active; create_anchor_account_info!(market, PerpMarket, market_account_info); @@ -5127,7 +5135,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5396,14 +5404,14 @@ pub mod fulfill_order { fn fulfill_users_with_multiple_orders_and_markets() { let mut sol_market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 1, order_tick_size: 1, historical_oracle_data: HistoricalOracleData { @@ -5422,14 +5430,14 @@ pub mod fulfill_order { create_anchor_account_info!(sol_market, PerpMarket, sol_market_account_info); let mut btc_market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 20000 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (20000 * PEG_PRECISION).into(), order_step_size: 1, order_tick_size: 1, historical_oracle_data: HistoricalOracleData { @@ -5456,7 +5464,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5678,12 +5686,12 @@ pub mod fulfill_order { assert_eq!(maker.orders[0], maker_before.orders[0]); let market_after = market_map.get_ref(&0).unwrap(); - assert_eq!(market_after.amm.base_asset_amount_with_amm, 0); - assert_eq!(market_after.amm.base_asset_amount_long, 500000000); - assert_eq!(market_after.amm.base_asset_amount_short, -500000000); - assert_eq!(market_after.amm.quote_asset_amount, -10000); - assert_eq!(market_after.amm.total_fee, 10000); - assert_eq!(market_after.amm.total_fee_minus_distributions, 10000); + assert_eq!(market_after.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market_after.amm.base_asset_amount_long(), 500000000); + assert_eq!(market_after.amm.base_asset_amount_short(), -500000000); + assert_eq!(market_after.amm.quote_asset_amount(), -10000); + assert_eq!(market_after.amm.total_fee(), 10000); + assert_eq!(market_after.amm.total_fee_minus_distributions(), 10000); assert_eq!(market_after.amm.net_revenue_since_last_funding, 10000); assert_eq!(market_after.amm.last_mark_price_twap_ts, 1); @@ -5733,14 +5741,14 @@ pub mod fulfill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -5761,8 +5769,8 @@ pub mod fulfill_order { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -5770,7 +5778,7 @@ pub mod fulfill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -5983,11 +5991,11 @@ pub mod fill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -6011,25 +6019,33 @@ pub mod fill_order { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = i128::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(i128::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6184,11 +6200,11 @@ pub mod fill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -6212,25 +6228,33 @@ pub mod fill_order { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = i128::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(i128::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6364,21 +6388,21 @@ pub mod fill_order { fn expire_order() { let mut market = PerpMarket { amm: AMM { - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 10000000, order_tick_size: 1, - max_base_asset_reserve: 200 * AMM_RESERVE_PRECISION, - min_base_asset_reserve: 50 * AMM_RESERVE_PRECISION, + max_base_asset_reserve: (200 * AMM_RESERVE_PRECISION).into(), + min_base_asset_reserve: (50 * AMM_RESERVE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(PRICE_PRECISION_I64), ..AMM::default() }, @@ -6396,7 +6420,7 @@ pub mod fill_order { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -6523,17 +6547,17 @@ pub mod fill_order { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, order_tick_size: 1, oracle: oracle_price_key, - max_open_interest: 100, + max_open_interest: 100.into(), max_spread: 1000, base_spread: 0, long_spread: 0, @@ -6552,25 +6576,33 @@ pub mod fill_order { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = i128::MAX as u128; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(i128::MAX as u128); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -6728,11 +6760,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -6792,8 +6824,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -6853,11 +6885,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 161 * SPOT_BALANCE_PRECISION, + deposit_balance: (161 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -6917,8 +6949,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 160000000); assert_eq!(maker_stats.fees.total_fee_rebate, 48000); - assert_eq!(base_market.total_spot_fee, 32000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 32000000); + assert_eq!(base_market.total_spot_fee(), 32000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 32000000); } #[test] @@ -6978,11 +7010,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7042,8 +7074,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -7103,11 +7135,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7167,8 +7199,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 70000000); assert_eq!(maker_stats.fees.total_fee_rebate, 21000); - assert_eq!(base_market.total_spot_fee, 14000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 14000000); + assert_eq!(base_market.total_spot_fee(), 14000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 14000000); } #[test] @@ -7228,11 +7260,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7327,11 +7359,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7426,11 +7458,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7525,11 +7557,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7624,11 +7656,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7700,8 +7732,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -7761,11 +7793,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7837,8 +7869,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -7900,11 +7932,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -7964,8 +7996,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -8023,11 +8055,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8087,8 +8119,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -8146,11 +8178,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8210,8 +8242,8 @@ pub mod fulfill_spot_order_with_match { assert_eq!(maker_stats.maker_volume_30d, 100000000); assert_eq!(maker_stats.fees.total_fee_rebate, 30000); - assert_eq!(base_market.total_spot_fee, 20000); - assert_eq!(base_market.spot_fee_pool.scaled_balance, 20000000); + assert_eq!(base_market.total_spot_fee(), 20000); + assert_eq!(base_market.spot_fee_pool.scaled_balance(), 20000000); } #[test] @@ -8270,11 +8302,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8367,11 +8399,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -8464,12 +8496,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 101 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() @@ -8564,11 +8596,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0.into(), ..SpotMarket::default_quote_market() }; @@ -8661,12 +8693,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -8760,12 +8792,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0.into(), deposit_token_twap: 0, ..SpotMarket::default_quote_market() }; @@ -8859,12 +8891,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -8958,11 +8990,11 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: 0, + deposit_balance: 0.into(), ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -9055,12 +9087,12 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 101 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -9154,14 +9186,14 @@ pub mod fulfill_spot_order_with_match { }; let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), utilization_twap: SPOT_UTILIZATION_PRECISION as u64, ..SpotMarket::default_base_market() }; let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, - borrow_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (101 * SPOT_BALANCE_PRECISION).into(), utilization_twap: SPOT_UTILIZATION_PRECISION as u64, ..SpotMarket::default_quote_market() }; @@ -9468,7 +9500,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() @@ -9476,7 +9508,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut second_base_market = SpotMarket { market_index: 2, - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() }; @@ -9487,7 +9519,7 @@ pub mod fulfill_spot_order { ); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -9740,7 +9772,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: 2 * SPOT_BALANCE_PRECISION, + deposit_balance: (2 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), ..SpotMarket::default_base_market() @@ -9748,7 +9780,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10027,7 +10059,7 @@ pub mod fulfill_spot_order { let mut base_market = SpotMarket { market_index: 1, - deposit_balance: 10 * SPOT_BALANCE_PRECISION, + deposit_balance: (10 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 10 * LAMPORTS_PER_SOL_U64, oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(100 * PRICE_PRECISION_I64), @@ -10036,7 +10068,7 @@ pub mod fulfill_spot_order { create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { market_index: 0, - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10215,13 +10247,13 @@ pub mod fill_spot_order { let perp_market_map = PerpMarketMap::empty(); let mut base_market = SpotMarket { - deposit_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), historical_oracle_data: HistoricalOracleData::default_price(PRICE_PRECISION_I64), ..SpotMarket::default_base_market() }; create_anchor_account_info!(base_market, SpotMarket, base_market_account_info); let mut quote_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; create_anchor_account_info!(quote_market, SpotMarket, quote_market_account_info); @@ -10397,15 +10429,15 @@ pub mod force_cancel_orders { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), // bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, // bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, // ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, // ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -10429,27 +10461,35 @@ pub mod force_cancel_orders { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - deposit_balance: SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -10459,9 +10499,9 @@ pub mod force_cancel_orders { let mut sol_spot_market = SpotMarket { market_index: 1, - deposit_balance: SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -10691,11 +10731,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -10719,25 +10759,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -10881,11 +10929,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -10909,25 +10957,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11072,11 +11128,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -11100,25 +11156,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11249,11 +11313,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -11277,25 +11341,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11500,11 +11572,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -11528,25 +11600,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11693,11 +11773,11 @@ pub mod get_maker_orders_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 100, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -11721,25 +11801,33 @@ pub mod get_maker_orders_info { ..PerpMarket::default() }; market.status = MarketStatus::Active; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let (new_ask_base_asset_reserve, new_ask_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Long) .unwrap(); let (new_bid_base_asset_reserve, new_bid_quote_asset_reserve) = crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11942,7 +12030,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -11952,7 +12040,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12099,7 +12187,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12109,7 +12197,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12258,7 +12346,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12268,7 +12356,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12402,7 +12490,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12412,7 +12500,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12624,7 +12712,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12634,7 +12722,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; @@ -12785,7 +12873,7 @@ pub mod get_spot_maker_orders_info { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -12795,7 +12883,7 @@ pub mod get_spot_maker_orders_info { create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); let mut base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), oracle: oracle_price_key, ..SpotMarket::default_base_market() }; diff --git a/programs/drift/src/controller/pnl.rs b/programs/drift/src/controller/pnl.rs index 98add9fa67..ba85a8a489 100644 --- a/programs/drift/src/controller/pnl.rs +++ b/programs/drift/src/controller/pnl.rs @@ -68,8 +68,8 @@ pub fn settle_pnl( update_spot_market_cumulative_interest(spot_market, None, now)?; tvl_before = spot_market.get_tvl()?; - deposits_balance_before = spot_market.deposit_balance; - borrows_balance_before = spot_market.borrow_balance; + deposits_balance_before = spot_market.deposit_balance(); + borrows_balance_before = spot_market.borrow_balance(); } let mut market = perp_market_map.get_ref_mut(&market_index)?; @@ -220,13 +220,13 @@ pub fn settle_pnl( } let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), spot_market, perp_market.pnl_pool.balance_type(), )?; let fraction_of_fee_pool_token_amount = get_token_amount( - perp_market.amm.fee_pool.scaled_balance, + perp_market.amm.fee_pool.scaled_balance(), spot_market, perp_market.amm.fee_pool.balance_type(), )? @@ -256,8 +256,8 @@ pub fn settle_pnl( )?; // if the spot market balance has changed, we have to fail if we are in try settle mode - if (spot_market.deposit_balance != deposits_balance_before - || spot_market.borrow_balance != borrows_balance_before) + if (spot_market.deposit_balance() != deposits_balance_before + || spot_market.borrow_balance() != borrows_balance_before) && mode == SettlePnlMode::TrySettle { msg!("Spot market balance has changed, switch to MUST_SETTLE mode"); @@ -554,10 +554,10 @@ pub fn settle_expired_position( update_settled_pnl(user, position_index, pnl_to_settle_with_user.cast()?)?; - perp_market.amm.base_asset_amount_with_amm = perp_market - .amm - .base_asset_amount_with_amm - .safe_add(position_delta.base_asset_amount.cast()?)?; + let base_asset_amount_with_amm = perp_market.amm.base_asset_amount_with_amm(); + perp_market.amm.set_base_asset_amount_with_amm( + base_asset_amount_with_amm.safe_add(position_delta.base_asset_amount.cast()?)?, + ); let quote_asset_amount_after = user.perp_positions[position_index].quote_asset_amount; diff --git a/programs/drift/src/controller/pnl/delisting.rs b/programs/drift/src/controller/pnl/delisting.rs index db148230f0..b33b7d02d3 100644 --- a/programs/drift/src/controller/pnl/delisting.rs +++ b/programs/drift/src/controller/pnl/delisting.rs @@ -78,16 +78,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -100,8 +100,8 @@ pub mod delisting_test { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -109,7 +109,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -192,16 +192,16 @@ pub mod delisting_test { // net users are long let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -212,7 +212,7 @@ pub mod delisting_test { last_oracle_price_twap_5min: (99 * PRICE_PRECISION) as i64, ..HistoricalOracleData::default() }, - quote_asset_amount: -(QUOTE_PRECISION_I128 * 50), //longs have $100 cost basis + quote_asset_amount: (-(QUOTE_PRECISION_I128 * 50)).into(), //longs have $100 cost basis ..AMM::default() }, margin_ratio_initial: 1000, @@ -222,8 +222,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -231,7 +231,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -302,16 +302,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -322,7 +322,7 @@ pub mod delisting_test { last_oracle_price_twap_5min: (99 * PRICE_PRECISION) as i64, ..HistoricalOracleData::default() }, - quote_asset_amount: -(QUOTE_PRECISION_I128 * 10), //longs have $20 cost basis + quote_asset_amount: (-(QUOTE_PRECISION_I128 * 10)).into(), //longs have $20 cost basis ..AMM::default() }, margin_ratio_initial: 1000, @@ -332,8 +332,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -341,7 +341,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -415,16 +415,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -435,8 +435,8 @@ pub mod delisting_test { last_oracle_price_twap_5min: (99 * PRICE_PRECISION) as i64, ..HistoricalOracleData::default() }, - total_fee_minus_distributions: -(100000 * QUOTE_PRECISION_I128), // down $100k - quote_asset_amount: -(QUOTE_PRECISION_I128 * 10), //longs have $20 cost basis + total_fee_minus_distributions: (-(100000 * QUOTE_PRECISION_I128)).into(), // down $100k + quote_asset_amount: (-(QUOTE_PRECISION_I128 * 10)).into(), //longs have $20 cost basis ..AMM::default() }, margin_ratio_initial: 1000, @@ -446,8 +446,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -455,7 +455,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -529,16 +529,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION / 2) as i128), - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION / 2) as i128)).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -549,8 +549,8 @@ pub mod delisting_test { last_oracle_price_twap_5min: (99 * PRICE_PRECISION) as i64, ..HistoricalOracleData::default() }, - total_fee_minus_distributions: -(100000 * QUOTE_PRECISION_I128), // down $100k - quote_asset_amount: (QUOTE_PRECISION_I128 * 10), //shorts have $20 cost basis + total_fee_minus_distributions: (-(100000 * QUOTE_PRECISION_I128)).into(), // down $100k + quote_asset_amount: (QUOTE_PRECISION_I128 * 10).into(), //shorts have $20 cost basis ..AMM::default() }, margin_ratio_initial: 1000, @@ -560,8 +560,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -569,7 +569,7 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, ..SpotMarket::default() @@ -639,16 +639,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -659,8 +659,8 @@ pub mod delisting_test { last_oracle_price_twap_5min: (99 * PRICE_PRECISION) as i64, ..HistoricalOracleData::default() }, - quote_asset_amount: -(QUOTE_PRECISION_I128 * 10), //longs have $20 cost basis - total_fee_minus_distributions: 0, + quote_asset_amount: (-(QUOTE_PRECISION_I128 * 10)).into(), //longs have $20 cost basis + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 1, @@ -669,7 +669,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -677,8 +677,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -686,14 +686,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -801,7 +801,7 @@ pub mod delisting_test { assert_eq!(margin_requirement, 10000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); assert_eq!(taker.spot_positions[0].scaled_balance, 100000000000); assert_eq!(taker.perp_positions[0].quote_asset_amount, -10000000); drop(market); @@ -822,7 +822,7 @@ pub mod delisting_test { assert_eq!(taker.spot_positions[0].scaled_balance, 139450500000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 960549500000); + assert_eq!(market.pnl_pool.scaled_balance(), 960549500000); drop(market); assert_eq!(taker.perp_positions[0].open_orders, 0); @@ -858,16 +858,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 2) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 2) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 2) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -879,8 +879,8 @@ pub mod delisting_test { ..HistoricalOracleData::default() }, - quote_asset_amount: (QUOTE_PRECISION_I128 * 10), //longs have -$20 cost basis - total_fee_minus_distributions: 0, + quote_asset_amount: (QUOTE_PRECISION_I128 * 10).into(), //longs have -$20 cost basis + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 1, @@ -889,7 +889,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -897,8 +897,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -906,14 +906,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1021,7 +1021,7 @@ pub mod delisting_test { assert_eq!(margin_requirement, 10000); // settlement in margin now let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); assert_eq!(taker.spot_positions[0].scaled_balance, 100000000000); assert_eq!(taker.perp_positions[0].quote_asset_amount, 10000000); drop(market); @@ -1042,7 +1042,7 @@ pub mod delisting_test { assert_eq!(taker.spot_positions[0].scaled_balance, 159450500000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 940549500000); + assert_eq!(market.pnl_pool.scaled_balance(), 940549500000); drop(market); assert_eq!(taker.perp_positions[0].open_orders, 0); @@ -1081,16 +1081,16 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION * 2000) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION * 2000) as i128, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION * 2000) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION * 2000) as i128).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1102,8 +1102,8 @@ pub mod delisting_test { ..HistoricalOracleData::default() }, - quote_asset_amount: (QUOTE_PRECISION_I128 * 20 * 2000), //longs have -$20 cost basis - total_fee_minus_distributions: 0, + quote_asset_amount: (QUOTE_PRECISION_I128 * 20 * 2000).into(), //longs have -$20 cost basis + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 1, @@ -1112,7 +1112,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1120,8 +1120,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1129,14 +1129,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1228,7 +1228,7 @@ pub mod delisting_test { assert_eq!(margin_requirement, 10000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); assert_eq!(taker.spot_positions[0].scaled_balance, 100000000000); assert_eq!(taker.perp_positions[0].quote_asset_amount, 40000000000); drop(market); @@ -1248,8 +1248,8 @@ pub mod delisting_test { assert_eq!(taker.spot_positions[0].scaled_balance > 100000000000, true); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 39002002000); // no settle fee since base_asse_value=0 (since price is negative) - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 39002002000); // no settle fee since base_asse_value=0 (since price is negative) + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); drop(market); assert_eq!(taker.perp_positions[0].open_orders, 0); @@ -1285,17 +1285,17 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION * 1000) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION * 2000) as i128, - base_asset_amount_short: -((AMM_RESERVE_PRECISION * 1000) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION * 1000) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION * 2000) as i128).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION * 1000) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1307,8 +1307,9 @@ pub mod delisting_test { ..HistoricalOracleData::default() }, - quote_asset_amount: -(QUOTE_PRECISION_I128 * 20 * 1000 - QUOTE_PRECISION_I128), - total_fee_minus_distributions: 0, + quote_asset_amount: (-(QUOTE_PRECISION_I128 * 20 * 1000 - QUOTE_PRECISION_I128)) + .into(), + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 2, @@ -1317,7 +1318,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1325,8 +1326,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1334,14 +1335,14 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 300000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (300000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1350,15 +1351,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), @@ -1532,7 +1533,7 @@ pub mod delisting_test { .unwrap(); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); let orig_short_balance = shorter.spot_positions[0].scaled_balance; @@ -1582,8 +1583,8 @@ pub mod delisting_test { assert_eq!(shorter_loss, 1019997999000); //$1020 loss let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 2019997999000); //$2020 - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 2019997999000); //$2020 + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); drop(market); assert_eq!(shorter.perp_positions[0].open_orders, 0); @@ -1610,7 +1611,7 @@ pub mod delisting_test { assert_eq!(margin_requirement, 10000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 2019997999000); + assert_eq!(market.pnl_pool.scaled_balance(), 2019997999000); assert_eq!(longer.spot_positions[0].scaled_balance, 20000000000000); assert_eq!(longer.perp_positions[0].quote_asset_amount, -40001000000); drop(market); @@ -1631,8 +1632,8 @@ pub mod delisting_test { assert_eq!(longer.spot_positions[0].scaled_balance, 21955000002000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 64997997000); //fee from settling - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 64997997000); //fee from settling + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); drop(market); assert_eq!(longer.perp_positions[0].open_orders, 0); @@ -1651,7 +1652,7 @@ pub mod delisting_test { let market = market_map.get_ref_mut(&0).unwrap(); assert_eq!(market.number_of_users_with_base, 0); - assert_eq!(market.amm.quote_asset_amount, 2000000); + assert_eq!(market.amm.quote_asset_amount(), 2000000); drop(market); settle_expired_position( 0, @@ -1675,12 +1676,12 @@ pub mod delisting_test { assert_eq!(liq.spot_positions[0].scaled_balance > 0, true); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), 0); assert_eq!(market.number_of_users_with_base, 0); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.quote_asset_amount, 0); - assert_eq!(market.amm.total_social_loss, 0); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.quote_asset_amount(), 0); + assert_eq!(market.amm.total_social_loss(), 0); drop(market); } @@ -1710,17 +1711,17 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION * 800) as i128), - base_asset_amount_long: (AMM_RESERVE_PRECISION * 200) as i128, - base_asset_amount_short: -((AMM_RESERVE_PRECISION * 1000) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION * 800) as i128)).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION * 200) as i128).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION * 1000) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -1732,9 +1733,10 @@ pub mod delisting_test { ..HistoricalOracleData::default() }, - quote_asset_amount: (QUOTE_PRECISION_I128 * 200) - + (QUOTE_PRECISION_I128 * 97 * 1000), - total_fee_minus_distributions: 0, + quote_asset_amount: ((QUOTE_PRECISION_I128 * 200) + + (QUOTE_PRECISION_I128 * 97 * 1000)) + .into(), + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 2, @@ -1742,7 +1744,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1750,8 +1752,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -1759,15 +1761,15 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1776,15 +1778,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), @@ -1960,7 +1962,7 @@ pub mod delisting_test { assert_eq!(margin_requirement, 10000); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); assert_eq!(longer.spot_positions[0].scaled_balance, 20000000000000); assert_eq!(longer.perp_positions[0].quote_asset_amount, 2000000000); let longer_balance_before = longer.spot_positions[0].scaled_balance; @@ -1988,8 +1990,8 @@ pub mod delisting_test { ); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); drop(market); } @@ -2094,17 +2096,17 @@ pub mod delisting_test { // net users are short let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - base_asset_amount_with_amm: -((AMM_RESERVE_PRECISION * 800) as i128), - base_asset_amount_long: (AMM_RESERVE_PRECISION * 200) as i128, - base_asset_amount_short: -((AMM_RESERVE_PRECISION * 1000) as i128), - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + base_asset_amount_with_amm: (-((AMM_RESERVE_PRECISION * 800) as i128)).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION * 200) as i128).into(), + base_asset_amount_short: (-((AMM_RESERVE_PRECISION * 1000) as i128)).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -2116,8 +2118,8 @@ pub mod delisting_test { ..HistoricalOracleData::default() }, - quote_asset_amount: QUOTE_PRECISION_I128 * (97 * 1000 + 200), - total_fee_minus_distributions: 0, + quote_asset_amount: (QUOTE_PRECISION_I128 * (97 * 1000 + 200)).into(), + total_fee_minus_distributions: 0.into(), ..AMM::default() }, number_of_users_with_base: 2, @@ -2126,7 +2128,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -2134,8 +2136,8 @@ pub mod delisting_test { ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2143,15 +2145,15 @@ pub mod delisting_test { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 40000 * SPOT_BALANCE_PRECISION, - borrow_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (40000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -2160,15 +2162,15 @@ pub mod delisting_test { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), @@ -2338,7 +2340,7 @@ pub mod delisting_test { .unwrap(); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 1000000000000); + assert_eq!(market.pnl_pool.scaled_balance(), 1000000000000); let orig_short_balance = shorter.spot_positions[0].scaled_balance; @@ -2386,10 +2388,10 @@ pub mod delisting_test { assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!( - market.amm.base_asset_amount_long + market.amm.base_asset_amount_short, + market.amm.base_asset_amount_long() + market.amm.base_asset_amount_short(), -800000000000 ); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); drop(market); @@ -2456,17 +2458,17 @@ pub mod delisting_test { assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!( - market.amm.base_asset_amount_long + market.amm.base_asset_amount_short, + market.amm.base_asset_amount_long() + market.amm.base_asset_amount_short(), -800000000000 ); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); assert_eq!(shorter.perp_positions[0].base_asset_amount, 0); assert_eq!(shorter.perp_positions[0].quote_asset_amount, -23250001000); assert_eq!( liquidator.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_short + market.amm.base_asset_amount_short() ); assert_eq!( liquidator.perp_positions[0].quote_asset_amount, @@ -2476,10 +2478,10 @@ pub mod delisting_test { assert_eq!( longer.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_long + market.amm.base_asset_amount_long() ); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); drop(market); } @@ -2511,10 +2513,10 @@ pub mod delisting_test { let mut market = market_map.get_ref_mut(&0).unwrap(); let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); - assert_eq!(market.amm.cumulative_funding_rate_long, 0); - assert_eq!(market.amm.cumulative_funding_rate_short, 0); + assert_eq!(market.amm.cumulative_funding_rate_long(), 0); + assert_eq!(market.amm.cumulative_funding_rate_short(), 0); let strict_quote_price = StrictOraclePrice::test(QUOTE_PRECISION_I64); let (perp_margin_requirement, weighted_pnl, _, _, _) = @@ -2544,17 +2546,17 @@ pub mod delisting_test { assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!( - market.amm.base_asset_amount_long + market.amm.base_asset_amount_short, + market.amm.base_asset_amount_long() + market.amm.base_asset_amount_short(), -800000000000 ); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); assert_eq!(shorter.perp_positions[0].base_asset_amount, 0); assert_eq!(shorter.perp_positions[0].quote_asset_amount, -23249001000); assert_eq!( liquidator.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_short + market.amm.base_asset_amount_short() ); assert_eq!( @@ -2564,11 +2566,11 @@ pub mod delisting_test { assert_eq!( longer.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_long + market.amm.base_asset_amount_long() ); assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); - assert_eq!(market.amm.quote_asset_amount, 201000000 + 96999000000); + assert_eq!(market.amm.quote_asset_amount(), 201000000 + 96999000000); // add a liq fee now market.liquidator_fee = 10000; @@ -2603,10 +2605,10 @@ pub mod delisting_test { let market = market_map.get_ref_mut(&0).unwrap(); let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); - assert_eq!(market.amm.quote_asset_amount, 20000010000 + 77199990000); + assert_eq!(market.amm.quote_asset_amount(), 20000010000 + 77199990000); - assert_eq!(market.amm.cumulative_funding_rate_long, 0); - assert_eq!(market.amm.cumulative_funding_rate_short, 0); + assert_eq!(market.amm.cumulative_funding_rate_long(), 0); + assert_eq!(market.amm.cumulative_funding_rate_short(), 0); let strict_quote_price = StrictOraclePrice::test(QUOTE_PRECISION_I64); let (perp_margin_requirement, weighted_pnl, _, _, _) = @@ -2636,17 +2638,17 @@ pub mod delisting_test { assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!( - market.amm.base_asset_amount_long + market.amm.base_asset_amount_short, + market.amm.base_asset_amount_long() + market.amm.base_asset_amount_short(), -800000000000 ); - assert_eq!(market.amm.quote_asset_amount, 97200000000); + assert_eq!(market.amm.quote_asset_amount(), 97200000000); assert_eq!(shorter.perp_positions[0].base_asset_amount, 0); assert_eq!(shorter.perp_positions[0].quote_asset_amount, -3449991000); assert_eq!( liquidator.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_short + market.amm.base_asset_amount_short() ); assert_eq!( liquidator.perp_positions[0].quote_asset_amount, @@ -2655,12 +2657,12 @@ pub mod delisting_test { assert_eq!( longer.perp_positions[0].base_asset_amount as i128, - market.amm.base_asset_amount_long + market.amm.base_asset_amount_long() ); assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000,); - assert_eq!(market.amm.quote_asset_amount, 20000010000 + 77199990000); - assert_eq!(market.amm.total_social_loss, 0); + assert_eq!(market.amm.quote_asset_amount(), 20000010000 + 77199990000); + assert_eq!(market.amm.total_social_loss(), 0); drop(market); } @@ -2734,16 +2736,16 @@ pub mod delisting_test { assert_eq!(shorter_loss, 20000000000000); //$16629 loss let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.amm.total_social_loss, 3449991000); - assert_eq!(market.amm.base_asset_amount_long, 200000000000); - assert_eq!(market.amm.base_asset_amount_short, 0); - assert_eq!(market.amm.base_asset_amount_with_amm, 200000000000); + assert_eq!(market.amm.total_social_loss(), 3449991000); + assert_eq!(market.amm.base_asset_amount_long(), 200000000000); + assert_eq!(market.amm.base_asset_amount_short(), 0); + assert_eq!(market.amm.base_asset_amount_with_amm(), 200000000000); - assert_eq!(market.amm.cumulative_funding_rate_long, 17249955000); - assert_eq!(market.amm.cumulative_funding_rate_short, -17249955000); + assert_eq!(market.amm.cumulative_funding_rate_long(), 17249955000); + assert_eq!(market.amm.cumulative_funding_rate_short(), -17249955000); - assert_eq!(market.pnl_pool.scaled_balance, 20920260001000); //$20920 - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 20920260001000); //$20920 + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); drop(market); assert_eq!(shorter.perp_positions[0].open_orders, 0); @@ -2794,22 +2796,22 @@ pub mod delisting_test { .unwrap(); let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 20920260001000); + assert_eq!(market.pnl_pool.scaled_balance(), 20920260001000); assert_eq!(longer.spot_positions[0].scaled_balance, 20000000000000); assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!(longer.perp_positions[0].quote_asset_amount, 200000000); assert_eq!(longer.perp_positions[0].last_cumulative_funding_rate, 0); - assert_eq!(market.amm.cumulative_funding_rate_long, 17249955000); + assert_eq!(market.amm.cumulative_funding_rate_long(), 17249955000); let longer_funding_payment = calculate_funding_payment( - market.amm.cumulative_funding_rate_long, + market.amm.cumulative_funding_rate_long(), &longer.perp_positions[0], ) .unwrap(); assert_eq!(longer_funding_payment, -3449991000); - assert_eq!(market.amm.quote_asset_amount, 200000000); - assert_eq!(market.amm.total_social_loss, 3449991000); + assert_eq!(market.amm.quote_asset_amount(), 200000000); + assert_eq!(market.amm.total_social_loss(), 3449991000); drop(market); @@ -2832,25 +2834,25 @@ pub mod delisting_test { assert_eq!(longer.spot_positions[0].scaled_balance, 40775959200000); //$40775 let market = market_map.get_ref_mut(&0).unwrap(); - assert_eq!(market.pnl_pool.scaled_balance, 144300801000); // fees collected - assert_eq!(market.amm.fee_pool.scaled_balance, 0); + assert_eq!(market.pnl_pool.scaled_balance(), 144300801000); // fees collected + assert_eq!(market.amm.fee_pool.scaled_balance(), 0); assert_eq!(market.number_of_users_with_base, 0); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), 0); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); - assert_eq!(market.amm.quote_asset_amount, 0); + assert_eq!(market.amm.quote_asset_amount(), 0); - assert_eq!(market.amm.total_social_loss, 3449991000); + assert_eq!(market.amm.total_social_loss(), 3449991000); let oracle_price_data = oracle_map.get_price_data(&market.oracle_id()).unwrap(); assert_eq!(oracle_price_data.price, 100 * PRICE_PRECISION_I64); let net_pnl = calculate_net_user_pnl(&market.amm, oracle_price_data.price).unwrap(); assert_eq!(net_pnl, 3449991000); assert_eq!(market.amm.net_unsettled_funding_pnl, 3449991000); //todo? - assert_eq!(market.amm.quote_asset_amount_per_lp, 0); + assert_eq!(market.amm.quote_asset_amount_per_lp(), 0); drop(market); diff --git a/programs/drift/src/controller/pnl/tests.rs b/programs/drift/src/controller/pnl/tests.rs index 4a35df4e49..3fee1d5440 100644 --- a/programs/drift/src/controller/pnl/tests.rs +++ b/programs/drift/src/controller/pnl/tests.rs @@ -66,20 +66,20 @@ pub fn user_no_position() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -95,7 +95,7 @@ pub fn user_no_position() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -107,10 +107,10 @@ pub fn user_no_position() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default() }; create_anchor_account_info!(spot_market, SpotMarket, spot_market_account_info); @@ -184,20 +184,20 @@ pub fn user_does_not_meet_maintenance_requirement() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -213,7 +213,7 @@ pub fn user_does_not_meet_maintenance_requirement() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -226,11 +226,11 @@ pub fn user_does_not_meet_maintenance_requirement() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -309,20 +309,20 @@ pub fn user_does_not_meet_strict_maintenance_requirement() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -338,7 +338,7 @@ pub fn user_does_not_meet_strict_maintenance_requirement() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -351,11 +351,11 @@ pub fn user_does_not_meet_strict_maintenance_requirement() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap_5min: PRICE_PRECISION_I64 / 2, ..HistoricalOracleData::default_price(QUOTE_PRECISION_I64) @@ -451,20 +451,20 @@ pub fn user_unsettled_negative_pnl() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -481,7 +481,7 @@ pub fn user_unsettled_negative_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -494,11 +494,11 @@ pub fn user_unsettled_negative_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -530,8 +530,12 @@ pub fn user_unsettled_negative_pnl() { expected_user.spot_positions[0].scaled_balance = 50 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = -100 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(100 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(-100 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; settle_pnl( @@ -588,20 +592,20 @@ pub fn user_unsettled_positive_pnl_more_than_pool() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -617,7 +621,7 @@ pub fn user_unsettled_positive_pnl_more_than_pool() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -630,11 +634,11 @@ pub fn user_unsettled_positive_pnl_more_than_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -666,8 +670,10 @@ pub fn user_unsettled_positive_pnl_more_than_pool() { expected_user.spot_positions[0].scaled_balance = 150 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 0; - expected_market.amm.quote_asset_amount = -200 * QUOTE_PRECISION_I128; + expected_market.pnl_pool.set_scaled_balance(0); + expected_market + .amm + .set_quote_asset_amount(-200 * QUOTE_PRECISION_I128); settle_pnl( 0, @@ -723,20 +729,20 @@ pub fn user_unsettled_positive_pnl_less_than_pool() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -753,7 +759,7 @@ pub fn user_unsettled_positive_pnl_less_than_pool() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -766,11 +772,11 @@ pub fn user_unsettled_positive_pnl_less_than_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -802,8 +808,12 @@ pub fn user_unsettled_positive_pnl_less_than_pool() { expected_user.spot_positions[0].scaled_balance = 125 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 25 * SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = -175 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(25 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(-175 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; settle_pnl( @@ -861,22 +871,22 @@ pub fn market_fee_pool_receives_portion() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, - total_fee_minus_distributions: QUOTE_PRECISION_I128, + total_fee_minus_distributions: QUOTE_PRECISION_I128.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, last_oracle_price_twap_5min: oracle_price.agg.price, @@ -892,7 +902,7 @@ pub fn market_fee_pool_receives_portion() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -905,11 +915,11 @@ pub fn market_fee_pool_receives_portion() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -941,9 +951,16 @@ pub fn market_fee_pool_receives_portion() { expected_user.spot_positions[0].scaled_balance = 100 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 149 * SPOT_BALANCE_PRECISION; - expected_market.amm.fee_pool.scaled_balance = SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = -50 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(149 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .fee_pool + .set_scaled_balance(SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(-50 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; settle_pnl( @@ -1000,24 +1017,24 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, - total_fee_minus_distributions: QUOTE_PRECISION_I128, + total_fee_minus_distributions: QUOTE_PRECISION_I128.into(), fee_pool: PoolBalance { - scaled_balance: (2 * SPOT_BALANCE_PRECISION), + scaled_balance: (2 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1036,7 +1053,7 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1049,11 +1066,11 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1085,9 +1102,16 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { expected_user.spot_positions[0].scaled_balance = 100 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 151 * SPOT_BALANCE_PRECISION; - expected_market.amm.fee_pool.scaled_balance = SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = -50 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(151 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .fee_pool + .set_scaled_balance(SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(-50 * QUOTE_PRECISION_I128); expected_market.number_of_users = 0; settle_pnl( @@ -1144,20 +1168,20 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 151 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (151 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -1173,7 +1197,7 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1186,11 +1210,11 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1225,8 +1249,10 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl() { expected_user.spot_positions[0].scaled_balance = 150 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 0; - expected_market.amm.quote_asset_amount = -200 * QUOTE_PRECISION_I128; + expected_market.pnl_pool.set_scaled_balance(0); + expected_market + .amm + .set_quote_asset_amount(-200 * QUOTE_PRECISION_I128); settle_pnl( 0, @@ -1282,20 +1308,20 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl_price_breached() let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 121 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (121 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -1311,7 +1337,7 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl_price_breached() status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1324,11 +1350,11 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl_price_breached() let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1363,8 +1389,10 @@ pub fn user_long_positive_unrealized_pnl_up_to_max_positive_pnl_price_breached() expected_user.spot_positions[0].cumulative_deposits = 50 * QUOTE_PRECISION_I64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 0; - expected_market.amm.quote_asset_amount = -200 * QUOTE_PRECISION_I128; + expected_market.pnl_pool.set_scaled_balance(0); + expected_market + .amm + .set_quote_asset_amount(-200 * QUOTE_PRECISION_I128); assert!(settle_pnl( 0, @@ -1417,20 +1445,20 @@ pub fn user_long_negative_unrealized_pnl() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 51 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (51 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: -150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (-150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -1446,7 +1474,7 @@ pub fn user_long_negative_unrealized_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1459,11 +1487,11 @@ pub fn user_long_negative_unrealized_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1498,8 +1526,12 @@ pub fn user_long_negative_unrealized_pnl() { expected_user.spot_positions[0].scaled_balance = 50 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = -100 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(100 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(-100 * QUOTE_PRECISION_I128); settle_pnl( 0, @@ -1555,20 +1587,20 @@ pub fn user_short_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 51 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (51 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -1584,7 +1616,7 @@ pub fn user_short_positive_unrealized_pnl_up_to_max_positive_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1597,11 +1629,11 @@ pub fn user_short_positive_unrealized_pnl_up_to_max_positive_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1636,8 +1668,10 @@ pub fn user_short_positive_unrealized_pnl_up_to_max_positive_pnl() { expected_user.spot_positions[0].scaled_balance = 150 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 0; - expected_market.amm.quote_asset_amount = 100 * QUOTE_PRECISION_I128; + expected_market.pnl_pool.set_scaled_balance(0); + expected_market + .amm + .set_quote_asset_amount(100 * QUOTE_PRECISION_I128); settle_pnl( 0, @@ -1693,20 +1727,20 @@ pub fn user_short_negative_unrealized_pnl() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -1722,7 +1756,7 @@ pub fn user_short_negative_unrealized_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1735,11 +1769,11 @@ pub fn user_short_negative_unrealized_pnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -1774,8 +1808,12 @@ pub fn user_short_negative_unrealized_pnl() { expected_user.spot_positions[0].scaled_balance = 50 * SPOT_BALANCE_PRECISION_U64; let mut expected_market = market; - expected_market.pnl_pool.scaled_balance = 100 * SPOT_BALANCE_PRECISION; - expected_market.amm.quote_asset_amount = 200 * QUOTE_PRECISION_I128; + expected_market + .pnl_pool + .set_scaled_balance(100 * SPOT_BALANCE_PRECISION); + expected_market + .amm + .set_quote_asset_amount(200 * QUOTE_PRECISION_I128); settle_pnl( 0, @@ -1832,20 +1870,20 @@ pub fn user_invalid_oracle_position() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, curve_update_intensity: 100, historical_oracle_data: HistoricalOracleData { @@ -1862,7 +1900,7 @@ pub fn user_invalid_oracle_position() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1872,11 +1910,11 @@ pub fn user_invalid_oracle_position() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), historical_oracle_data: HistoricalOracleData::default_price(QUOTE_PRECISION_I64), ..SpotMarket::default() }; @@ -2053,20 +2091,20 @@ pub fn is_price_divergence_ok_on_invalid_oracle() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 150 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, - base_asset_amount_long: BASE_PRECISION_I128, + quote_asset_amount: (150 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), + base_asset_amount_long: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price.agg.price, @@ -2082,7 +2120,7 @@ pub fn is_price_divergence_ok_on_invalid_oracle() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION), + scaled_balance: (50 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, diff --git a/programs/drift/src/controller/position.rs b/programs/drift/src/controller/position.rs index 6b6ec530d5..47ec779d64 100644 --- a/programs/drift/src/controller/position.rs +++ b/programs/drift/src/controller/position.rs @@ -1,6 +1,5 @@ use crate::msg; use anchor_lang::prelude::*; -use borsh::{BorshDeserialize, BorshSerialize}; use crate::controller; use crate::controller::amm::SwapDirection; @@ -24,7 +23,7 @@ use crate::validate; #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum PositionDirection { #[default] Long, @@ -193,139 +192,183 @@ pub fn update_position_and_market( market.number_of_users_with_base = market.number_of_users_with_base.saturating_sub(1); } - market.amm.quote_asset_amount = market - .amm - .quote_asset_amount - .safe_add(delta.quote_asset_amount.cast()?)?; + market.amm.set_quote_asset_amount( + market + .amm + .quote_asset_amount() + .safe_add(delta.quote_asset_amount.cast()?)?, + ); match update_type { PositionUpdateType::Open | PositionUpdateType::Increase => { if new_base_asset_amount > 0 { - market.amm.base_asset_amount_long = market - .amm - .base_asset_amount_long - .safe_add(delta.base_asset_amount.cast()?)?; - market.amm.quote_entry_amount_long = market - .amm - .quote_entry_amount_long - .safe_add(delta.quote_asset_amount.cast()?)?; - market.amm.quote_break_even_amount_long = + market.amm.set_base_asset_amount_long( + market + .amm + .base_asset_amount_long() + .safe_add(delta.base_asset_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_long( market .amm - .quote_break_even_amount_long - .safe_add(delta.quote_asset_amount.cast()?)?; + .quote_entry_amount_long() + .safe_add(delta.quote_asset_amount.cast()?)?, + ); + market.amm.set_quote_break_even_amount_long( + market + .amm + .quote_break_even_amount_long() + .safe_add(delta.quote_asset_amount.cast()?)?, + ); } else { - market.amm.base_asset_amount_short = market - .amm - .base_asset_amount_short - .safe_add(delta.base_asset_amount.cast()?)?; - market.amm.quote_entry_amount_short = market - .amm - .quote_entry_amount_short - .safe_add(delta.quote_asset_amount.cast()?)?; - market.amm.quote_break_even_amount_short = market - .amm - .quote_break_even_amount_short - .safe_add(delta.quote_asset_amount.cast()?)?; + market.amm.set_base_asset_amount_short( + market + .amm + .base_asset_amount_short() + .safe_add(delta.base_asset_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_short( + market + .amm + .quote_entry_amount_short() + .safe_add(delta.quote_asset_amount.cast()?)?, + ); + market.amm.set_quote_break_even_amount_short( + market + .amm + .quote_break_even_amount_short() + .safe_add(delta.quote_asset_amount.cast()?)?, + ); } } PositionUpdateType::Reduce | PositionUpdateType::Close => { if position.base_asset_amount > 0 { - market.amm.base_asset_amount_long = market - .amm - .base_asset_amount_long - .safe_add(delta.base_asset_amount.cast()?)?; - market.amm.quote_entry_amount_long = market.amm.quote_entry_amount_long.safe_sub( - position - .quote_entry_amount - .safe_sub(new_quote_entry_amount)? - .cast()?, - )?; - market.amm.quote_break_even_amount_long = - market.amm.quote_break_even_amount_long.safe_sub( + market.amm.set_base_asset_amount_long( + market + .amm + .base_asset_amount_long() + .safe_add(delta.base_asset_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_long( + market.amm.quote_entry_amount_long().safe_sub( + position + .quote_entry_amount + .safe_sub(new_quote_entry_amount)? + .cast()?, + )?, + ); + market.amm.set_quote_break_even_amount_long( + market.amm.quote_break_even_amount_long().safe_sub( position .quote_break_even_amount .safe_sub(new_quote_break_even_amount)? .cast()?, - )?; + )?, + ); } else { - market.amm.base_asset_amount_short = market - .amm - .base_asset_amount_short - .safe_add(delta.base_asset_amount.cast()?)?; - market.amm.quote_entry_amount_short = - market.amm.quote_entry_amount_short.safe_sub( + market.amm.set_base_asset_amount_short( + market + .amm + .base_asset_amount_short() + .safe_add(delta.base_asset_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_short( + market.amm.quote_entry_amount_short().safe_sub( position .quote_entry_amount .safe_sub(new_quote_entry_amount)? .cast()?, - )?; - market.amm.quote_break_even_amount_short = - market.amm.quote_break_even_amount_short.safe_sub( + )?, + ); + market.amm.set_quote_break_even_amount_short( + market.amm.quote_break_even_amount_short().safe_sub( position .quote_break_even_amount .safe_sub(new_quote_break_even_amount)? .cast()?, - )?; + )?, + ); } } PositionUpdateType::Flip => { if new_base_asset_amount > 0 { - market.amm.base_asset_amount_short = market - .amm - .base_asset_amount_short - .safe_sub(position.base_asset_amount.cast()?)?; - market.amm.base_asset_amount_long = market - .amm - .base_asset_amount_long - .safe_add(new_base_asset_amount.cast()?)?; - - market.amm.quote_entry_amount_short = market - .amm - .quote_entry_amount_short - .safe_sub(position.quote_entry_amount.cast()?)?; - market.amm.quote_entry_amount_long = market - .amm - .quote_entry_amount_long - .safe_add(new_quote_entry_amount.cast()?)?; - - market.amm.quote_break_even_amount_short = market - .amm - .quote_break_even_amount_short - .safe_sub(position.quote_break_even_amount.cast()?)?; - market.amm.quote_break_even_amount_long = + market.amm.set_base_asset_amount_short( market .amm - .quote_break_even_amount_long - .safe_add(new_quote_break_even_amount.cast()?)?; + .base_asset_amount_short() + .safe_sub(position.base_asset_amount.cast()?)?, + ); + market.amm.set_base_asset_amount_long( + market + .amm + .base_asset_amount_long() + .safe_add(new_base_asset_amount.cast()?)?, + ); + + market.amm.set_quote_entry_amount_short( + market + .amm + .quote_entry_amount_short() + .safe_sub(position.quote_entry_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_long( + market + .amm + .quote_entry_amount_long() + .safe_add(new_quote_entry_amount.cast()?)?, + ); + + market.amm.set_quote_break_even_amount_short( + market + .amm + .quote_break_even_amount_short() + .safe_sub(position.quote_break_even_amount.cast()?)?, + ); + market.amm.set_quote_break_even_amount_long( + market + .amm + .quote_break_even_amount_long() + .safe_add(new_quote_break_even_amount.cast()?)?, + ); } else { - market.amm.base_asset_amount_long = market - .amm - .base_asset_amount_long - .safe_sub(position.base_asset_amount.cast()?)?; - market.amm.base_asset_amount_short = market - .amm - .base_asset_amount_short - .safe_add(new_base_asset_amount.cast()?)?; - - market.amm.quote_entry_amount_long = market - .amm - .quote_entry_amount_long - .safe_sub(position.quote_entry_amount.cast()?)?; - market.amm.quote_entry_amount_short = market - .amm - .quote_entry_amount_short - .safe_add(new_quote_entry_amount.cast()?)?; - - market.amm.quote_break_even_amount_long = + market.amm.set_base_asset_amount_long( + market + .amm + .base_asset_amount_long() + .safe_sub(position.base_asset_amount.cast()?)?, + ); + market.amm.set_base_asset_amount_short( + market + .amm + .base_asset_amount_short() + .safe_add(new_base_asset_amount.cast()?)?, + ); + + market.amm.set_quote_entry_amount_long( + market + .amm + .quote_entry_amount_long() + .safe_sub(position.quote_entry_amount.cast()?)?, + ); + market.amm.set_quote_entry_amount_short( + market + .amm + .quote_entry_amount_short() + .safe_add(new_quote_entry_amount.cast()?)?, + ); + + market.amm.set_quote_break_even_amount_long( + market + .amm + .quote_break_even_amount_long() + .safe_sub(position.quote_break_even_amount.cast()?)?, + ); + market.amm.set_quote_break_even_amount_short( market .amm - .quote_break_even_amount_long - .safe_sub(position.quote_break_even_amount.cast()?)?; - market.amm.quote_break_even_amount_short = market - .amm - .quote_break_even_amount_short - .safe_add(new_quote_break_even_amount.cast()?)?; + .quote_break_even_amount_short() + .safe_add(new_quote_break_even_amount.cast()?)?, + ); } } } @@ -334,20 +377,20 @@ pub fn update_position_and_market( match position.get_direction() { PositionDirection::Long if position.base_asset_amount != 0 => { validate!( - position.last_cumulative_funding_rate.cast::()? == market.amm.cumulative_funding_rate_long, + position.last_cumulative_funding_rate.cast::()? == market.amm.cumulative_funding_rate_long(), ErrorCode::InvalidPositionLastFundingRate, "position.last_cumulative_funding_rate {} market.amm.cumulative_funding_rate_long {}", position.last_cumulative_funding_rate.cast::()?, - market.amm.cumulative_funding_rate_long, + market.amm.cumulative_funding_rate_long(), )?; } PositionDirection::Short => { validate!( - position.last_cumulative_funding_rate == market.amm.cumulative_funding_rate_short.cast::()?, + position.last_cumulative_funding_rate == market.amm.cumulative_funding_rate_short().cast::()?, ErrorCode::InvalidPositionLastFundingRate, "position.last_cumulative_funding_rate {} market.amm.cumulative_funding_rate_short {}", position.last_cumulative_funding_rate, - market.amm.cumulative_funding_rate_short, + market.amm.cumulative_funding_rate_short(), )?; } _ => {} @@ -362,10 +405,10 @@ pub fn update_position_and_market( ) { if new_base_asset_amount > 0 { position.last_cumulative_funding_rate = - market.amm.cumulative_funding_rate_long.cast()?; + market.amm.cumulative_funding_rate_long().cast()?; } else { position.last_cumulative_funding_rate = - market.amm.cumulative_funding_rate_short.cast()?; + market.amm.cumulative_funding_rate_short().cast()?; } } @@ -424,16 +467,18 @@ pub fn update_position_with_base_asset_amount( &position_delta, )?; - market.amm.base_asset_amount_with_amm = market - .amm - .base_asset_amount_with_amm - .safe_add(position_delta.base_asset_amount.cast()?)?; + market.amm.set_base_asset_amount_with_amm( + market + .amm + .base_asset_amount_with_amm() + .safe_add(position_delta.base_asset_amount.cast()?)?, + ); validate!( - market.amm.base_asset_amount_with_amm.unsigned_abs() <= MAX_BASE_ASSET_AMOUNT_WITH_AMM, + market.amm.base_asset_amount_with_amm().unsigned_abs() <= MAX_BASE_ASSET_AMOUNT_WITH_AMM, ErrorCode::InvalidAmmDetected, "market.amm.base_asset_amount_with_amm={} cannot exceed MAX_BASE_ASSET_AMOUNT_WITH_AMM", - market.amm.base_asset_amount_with_amm + market.amm.base_asset_amount_with_amm() )?; controller::amm::update_spread_reserves(market)?; @@ -490,7 +535,9 @@ pub fn update_quote_asset_amount( position.quote_asset_amount = position.quote_asset_amount.safe_add(delta)?; - market.amm.quote_asset_amount = market.amm.quote_asset_amount.safe_add(delta.cast()?)?; + market + .amm + .set_quote_asset_amount(market.amm.quote_asset_amount().safe_add(delta.cast()?)?); if position.quote_asset_amount == 0 && position.base_asset_amount == 0 { market.number_of_users = market.number_of_users.saturating_sub(1); @@ -510,18 +557,18 @@ pub fn update_quote_break_even_amount( position.quote_break_even_amount = position.quote_break_even_amount.safe_add(delta)?; match position.get_direction() { - PositionDirection::Long => { - market.amm.quote_break_even_amount_long = market + PositionDirection::Long => market.amm.set_quote_break_even_amount_long( + market .amm - .quote_break_even_amount_long - .safe_add(delta.cast()?)? - } - PositionDirection::Short => { - market.amm.quote_break_even_amount_short = market + .quote_break_even_amount_long() + .safe_add(delta.cast()?)?, + ), + PositionDirection::Short => market.amm.set_quote_break_even_amount_short( + market .amm - .quote_break_even_amount_short - .safe_add(delta.cast()?)? - } + .quote_break_even_amount_short() + .safe_add(delta.cast()?)?, + ), } Ok(()) diff --git a/programs/drift/src/controller/position/tests.rs b/programs/drift/src/controller/position/tests.rs index b16f14d096..ca452caa6f 100644 --- a/programs/drift/src/controller/position/tests.rs +++ b/programs/drift/src/controller/position/tests.rs @@ -71,12 +71,12 @@ fn amm_pool_balance_liq_fees_example() { ); let mut spot_market = SpotMarket { - cumulative_deposit_interest: 11425141382, - cumulative_borrow_interest: 12908327537, + cumulative_deposit_interest: 11425141382.into(), + cumulative_borrow_interest: 12908327537.into(), decimals: 6, ..SpotMarket::default() }; - spot_market.deposit_balance = 10_u128.pow(19_u32); + spot_market.set_deposit_balance(10_u128.pow(19_u32)); spot_market.deposit_token_twap = 10_u64.pow(16_u32); let spot_position = SpotPosition::default(); @@ -85,11 +85,14 @@ fn amm_pool_balance_liq_fees_example() { let mut perp_market = perp_market_loader.load_mut().unwrap(); // assert_eq!(perp_market.amm.oracle, Pubkey::default()); - assert_eq!(perp_market.pnl_pool.scaled_balance, 0); - assert_eq!(perp_market.amm.fee_pool.scaled_balance, 1349764971875250); - let fee_before = perp_market.amm.fee_pool.scaled_balance; + assert_eq!(perp_market.pnl_pool.scaled_balance(), 0); + assert_eq!(perp_market.amm.fee_pool.scaled_balance(), 1349764971875250); + let fee_before = perp_market.amm.fee_pool.scaled_balance(); - assert_eq!(perp_market.amm.total_fee_minus_distributions, 1276488252050); + assert_eq!( + perp_market.amm.total_fee_minus_distributions(), + 1276488252050 + ); let new_total_fee_minus_distributions = crate::controller::amm::calculate_perp_market_amm_summary_stats( @@ -100,11 +103,19 @@ fn amm_pool_balance_liq_fees_example() { ) .unwrap(); let fee_difference = new_total_fee_minus_distributions - .safe_sub(perp_market.amm.total_fee_minus_distributions) + .safe_sub(perp_market.amm.total_fee_minus_distributions()) .unwrap(); - perp_market.amm.total_fee = perp_market.amm.total_fee.saturating_add(fee_difference); - perp_market.amm.total_mm_fee = perp_market.amm.total_mm_fee.saturating_add(fee_difference); - perp_market.amm.total_fee_minus_distributions = new_total_fee_minus_distributions; + let total_fee = perp_market.amm.total_fee(); + perp_market + .amm + .set_total_fee(total_fee.saturating_add(fee_difference)); + let total_mm_fee = perp_market.amm.total_mm_fee(); + perp_market + .amm + .set_total_mm_fee(total_mm_fee.saturating_add(fee_difference)); + perp_market + .amm + .set_total_fee_minus_distributions(new_total_fee_minus_distributions); assert_eq!(new_total_fee_minus_distributions, 640881949608); @@ -138,7 +149,7 @@ fn amm_pool_balance_liq_fees_example() { assert_eq!(fee_pool_token_amount, 1276764026200); // 1.27M // assert_eq!(perp_market.amm.fee_pool.scaled_balance, fee_before + 1000000000); // pre change - assert!(perp_market.amm.fee_pool.scaled_balance < fee_before); // post change + assert!(perp_market.amm.fee_pool.scaled_balance() < fee_before); // post change } } @@ -204,7 +215,7 @@ fn amm_pred_expiry_price_yes_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -223,7 +234,7 @@ fn amm_pred_expiry_price_yes_market_example() { { let mut perp_market = perp_market_loader.load_mut().unwrap(); perp_market.amm.historical_oracle_data.last_oracle_price = 1_000_000; - perp_market.amm.base_asset_amount_with_amm = 0; + perp_market.amm.set_base_asset_amount_with_amm(0); market_index = perp_market.market_index; assert_eq!(perp_market.expiry_ts, 1725559200); @@ -317,7 +328,7 @@ fn amm_pred_expiry_price_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -336,7 +347,7 @@ fn amm_pred_expiry_price_market_example() { { let mut perp_market = perp_market_loader.load_mut().unwrap(); market_index = perp_market.market_index; - perp_market.amm.base_asset_amount_with_amm = 0; + perp_market.amm.set_base_asset_amount_with_amm(0); perp_market.amm.historical_oracle_data.last_oracle_price = 1; assert_eq!(perp_market.expiry_ts, 1725559200); @@ -429,7 +440,7 @@ fn amm_pred_settle_market_example() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, @@ -511,15 +522,18 @@ fn amm_pred_market_example() { assert_eq!(max_bids, 3_824_624_394_874); // 3824 shares assert_eq!(max_asks, -5_241_195_799_744); // -5000 shares - assert_eq!(perp_market.amm.sqrt_k, 56_649_660_613_272); + assert_eq!(perp_market.amm.sqrt_k(), 56_649_660_613_272); let (optimal_peg, fee_budget, _check_lower_bound) = repeg::calculate_optimal_peg_and_budget(&perp_market, &mm_oracle_price_data).unwrap(); - assert_eq!(perp_market.amm.terminal_quote_asset_reserve, 56405211622548); - assert_eq!(perp_market.amm.quote_asset_reserve, 56933567973708); assert_eq!( - perp_market.amm.quote_asset_reserve - perp_market.amm.terminal_quote_asset_reserve, + perp_market.amm.terminal_quote_asset_reserve(), + 56405211622548 + ); + assert_eq!(perp_market.amm.quote_asset_reserve(), 56933567973708); + assert_eq!( + perp_market.amm.quote_asset_reserve() - perp_market.amm.terminal_quote_asset_reserve(), 528356351160 ); @@ -589,10 +603,10 @@ fn amm_ref_price_decay_tail_test() { assert_eq!(max_ref_offset, 10000); let liquidity_ratio = crate::math::amm_spread::calculate_inventory_liquidity_ratio( - perp_market.amm.base_asset_amount_with_amm, - perp_market.amm.base_asset_reserve, - perp_market.amm.max_base_asset_reserve, - perp_market.amm.min_base_asset_reserve, + perp_market.amm.base_asset_amount_with_amm(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.max_base_asset_reserve(), + perp_market.amm.min_base_asset_reserve(), ) .unwrap(); @@ -766,10 +780,10 @@ fn amm_ref_price_offset_decay_logic() { let max_ref_offset = perp_market.amm.get_max_reference_price_offset().unwrap(); let liquidity_ratio = crate::math::amm_spread::calculate_inventory_liquidity_ratio( - perp_market.amm.base_asset_amount_with_amm, - perp_market.amm.base_asset_reserve, - perp_market.amm.max_base_asset_reserve, - perp_market.amm.min_base_asset_reserve, + perp_market.amm.base_asset_amount_with_amm(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.max_base_asset_reserve(), + perp_market.amm.min_base_asset_reserve(), ) .unwrap(); @@ -943,10 +957,10 @@ fn amm_negative_ref_price_offset_decay_logic() { let max_ref_offset = perp_market.amm.get_max_reference_price_offset().unwrap(); let liquidity_ratio = crate::math::amm_spread::calculate_inventory_liquidity_ratio( - perp_market.amm.base_asset_amount_with_amm, - perp_market.amm.base_asset_reserve, - perp_market.amm.max_base_asset_reserve, - perp_market.amm.min_base_asset_reserve, + perp_market.amm.base_asset_amount_with_amm(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.max_base_asset_reserve(), + perp_market.amm.min_base_asset_reserve(), ) .unwrap(); @@ -1113,7 +1127,7 @@ fn amm_perp_ref_offset() { AccountLoader::try_from(&perp_market_account_info).unwrap(); let mut perp_market = perp_market_loader.load_mut().unwrap(); - perp_market.amm.base_asset_amount_with_amm = 40000000000; // override old LP related fields + perp_market.amm.set_base_asset_amount_with_amm(40000000000); // override old LP related fields let reserve_price = perp_market.amm.reserve_price().unwrap(); let (b1, a1) = perp_market.amm.bid_ask_price(reserve_price).unwrap(); @@ -1133,16 +1147,16 @@ fn amm_perp_ref_offset() { .last_oracle_price_twap_ts, 1741207620 ); - assert_eq!(perp_market.amm.bid_base_asset_reserve, 4674304094737516); - assert_eq!(perp_market.amm.ask_base_asset_reserve, 4631420570932586); + assert_eq!(perp_market.amm.bid_base_asset_reserve(), 4674304094737516); + assert_eq!(perp_market.amm.ask_base_asset_reserve(), 4631420570932586); let max_ref_offset = perp_market.amm.get_max_reference_price_offset().unwrap(); let liquidity_ratio = crate::math::amm_spread::calculate_inventory_liquidity_ratio( - perp_market.amm.base_asset_amount_with_amm, - perp_market.amm.base_asset_reserve, - perp_market.amm.max_base_asset_reserve, - perp_market.amm.min_base_asset_reserve, + perp_market.amm.base_asset_amount_with_amm(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.max_base_asset_reserve(), + perp_market.amm.min_base_asset_reserve(), ) .unwrap(); @@ -1217,8 +1231,8 @@ fn amm_perp_ref_offset() { assert_eq!(perp_market.amm.max_spread, 90000); assert_eq!(r, 7101599); - assert_eq!(perp_market.amm.bid_base_asset_reserve, 4672004879737647); - assert_eq!(perp_market.amm.ask_base_asset_reserve, 4669662283322685); + assert_eq!(perp_market.amm.bid_base_asset_reserve(), 4672004879737647); + assert_eq!(perp_market.amm.ask_base_asset_reserve(), 4669662283322685); crate::validation::perp_market::validate_perp_market(&perp_market).unwrap(); @@ -1281,8 +1295,8 @@ fn test_position_entry_sim() { }; let mut market = PerpMarket { amm: AMM { - cumulative_funding_rate_long: 1, - sqrt_k: 1, + cumulative_funding_rate_long: 1.into(), + sqrt_k: 1.into(), order_step_size: (BASE_PRECISION_I64 / 10) as u64, ..AMM::default() }, @@ -1337,8 +1351,8 @@ fn increase_long_from_no_position() { }; let mut market = PerpMarket { amm: AMM { - cumulative_funding_rate_long: 1, - sqrt_k: 1, + cumulative_funding_rate_long: 1.into(), + sqrt_k: 1.into(), order_step_size: 1, ..AMM::default() }, @@ -1357,14 +1371,14 @@ fn increase_long_from_no_position() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); - assert_eq!(market.amm.base_asset_amount_with_amm, 0); - assert_eq!(market.amm.quote_asset_amount, -1); - assert_eq!(market.amm.quote_entry_amount_long, -1); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -1); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); + assert_eq!(market.amm.base_asset_amount_with_amm(), 0); + assert_eq!(market.amm.quote_asset_amount(), -1); + assert_eq!(market.amm.quote_entry_amount_long(), -1); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -1); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1376,7 +1390,7 @@ fn increase_short_from_no_position() { }; let mut market = PerpMarket { amm: AMM { - cumulative_funding_rate_short: 1, + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 0, @@ -1394,13 +1408,13 @@ fn increase_short_from_no_position() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); - assert_eq!(market.amm.quote_asset_amount, 1); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 1); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 1); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); + assert_eq!(market.amm.quote_asset_amount(), 1); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 1); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 1); } #[test] @@ -1419,13 +1433,13 @@ fn increase_long() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 1, - base_asset_amount_long: 1, - base_asset_amount_short: 0, - quote_asset_amount: -1, - quote_break_even_amount_long: -2, - quote_entry_amount_long: -1, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 1.into(), + base_asset_amount_long: 1.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: (-1).into(), + quote_break_even_amount_long: (-2).into(), + quote_entry_amount_long: (-1).into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1443,15 +1457,15 @@ fn increase_long() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 2); - assert_eq!(market.amm.base_asset_amount_short, 0); - assert_eq!(market.amm.quote_asset_amount, -2); - assert_eq!(market.amm.quote_entry_amount_long, -2); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -3); - assert_eq!(market.amm.quote_break_even_amount_short, 0); - - assert_eq!(market.amm.base_asset_amount_with_amm, 1); // todo: update_position_and_market doesnt modify this properly? + assert_eq!(market.amm.base_asset_amount_long(), 2); + assert_eq!(market.amm.base_asset_amount_short(), 0); + assert_eq!(market.amm.quote_asset_amount(), -2); + assert_eq!(market.amm.quote_entry_amount_long(), -2); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -3); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); + + assert_eq!(market.amm.base_asset_amount_with_amm(), 1); // todo: update_position_and_market doesnt modify this properly? } #[test] @@ -1470,12 +1484,12 @@ fn increase_short() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_short: -1, - base_asset_amount_long: 0, - quote_asset_amount: 1, - quote_entry_amount_short: 1, - quote_break_even_amount_short: 2, - cumulative_funding_rate_short: 1, + base_asset_amount_short: (-1).into(), + base_asset_amount_long: 0.into(), + quote_asset_amount: 1.into(), + quote_entry_amount_short: 1.into(), + quote_break_even_amount_short: 2.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1493,13 +1507,13 @@ fn increase_short() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -2); - assert_eq!(market.amm.quote_asset_amount, 2); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 2); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 3); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -2); + assert_eq!(market.amm.quote_asset_amount(), 2); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 2); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 3); } #[test] @@ -1518,13 +1532,13 @@ fn reduce_long_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 10, - base_asset_amount_long: 10, - base_asset_amount_short: 0, - quote_asset_amount: -10, - quote_entry_amount_long: -10, - quote_break_even_amount_long: -12, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 10.into(), + base_asset_amount_long: 10.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: (-10).into(), + quote_entry_amount_long: (-10).into(), + quote_break_even_amount_long: (-12).into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1542,14 +1556,14 @@ fn reduce_long_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 9); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 9); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 9); - assert_eq!(market.amm.quote_asset_amount, -5); - assert_eq!(market.amm.quote_entry_amount_long, -9); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -11); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), -5); + assert_eq!(market.amm.quote_entry_amount_long(), -9); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -11); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1568,13 +1582,13 @@ fn reduce_long_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 10, - base_asset_amount_long: 10, - base_asset_amount_short: 0, - quote_asset_amount: -100, - quote_entry_amount_long: -100, - quote_break_even_amount_long: -200, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 10.into(), + base_asset_amount_long: 10.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: (-100).into(), + quote_entry_amount_long: (-100).into(), + quote_break_even_amount_long: (-200).into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1592,14 +1606,14 @@ fn reduce_long_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 9); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 9); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 9); - assert_eq!(market.amm.quote_asset_amount, -95); - assert_eq!(market.amm.quote_entry_amount_long, -90); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -180); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), -95); + assert_eq!(market.amm.quote_entry_amount_long(), -90); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -180); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1618,14 +1632,14 @@ fn flip_long_to_short_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 10, - base_asset_amount_long: 10, - base_asset_amount_short: 0, - quote_asset_amount: -10, - quote_break_even_amount_long: -12, - quote_entry_amount_long: -10, - cumulative_funding_rate_short: 2, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 10.into(), + base_asset_amount_long: 10.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: (-10).into(), + quote_break_even_amount_long: (-12).into(), + quote_entry_amount_long: (-10).into(), + cumulative_funding_rate_short: 2.into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1643,14 +1657,14 @@ fn flip_long_to_short_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 2); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); // assert_eq!(market.amm.base_asset_amount_with_amm, -1); - assert_eq!(market.amm.quote_asset_amount, 12); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 2); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 2); + assert_eq!(market.amm.quote_asset_amount(), 12); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 2); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 2); } #[test] @@ -1669,14 +1683,14 @@ fn flip_long_to_short_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 10, - base_asset_amount_long: 10, - base_asset_amount_short: 0, - quote_asset_amount: -10, - quote_break_even_amount_long: -12, - quote_entry_amount_long: -10, - cumulative_funding_rate_short: 2, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 10.into(), + base_asset_amount_long: 10.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: (-10).into(), + quote_break_even_amount_long: (-12).into(), + quote_entry_amount_long: (-10).into(), + cumulative_funding_rate_short: 2.into(), + cumulative_funding_rate_long: 1.into(), order_step_size: 1, ..AMM::default() }, @@ -1695,14 +1709,14 @@ fn flip_long_to_short_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 2); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); // assert_eq!(market.amm.base_asset_amount_with_amm, -1); - assert_eq!(market.amm.quote_asset_amount, 0); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 1); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 1); + assert_eq!(market.amm.quote_asset_amount(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 1); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 1); } #[test] @@ -1721,12 +1735,12 @@ fn reduce_short_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_long: 0, - base_asset_amount_short: -10, - quote_asset_amount: 100, - quote_entry_amount_short: 100, - quote_break_even_amount_short: 200, - cumulative_funding_rate_short: 1, + base_asset_amount_long: 0.into(), + base_asset_amount_short: (-10).into(), + quote_asset_amount: 100.into(), + quote_entry_amount_short: 100.into(), + quote_break_even_amount_short: 200.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1744,13 +1758,13 @@ fn reduce_short_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -9); - assert_eq!(market.amm.quote_asset_amount, 95); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 90); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 180); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -9); + assert_eq!(market.amm.quote_asset_amount(), 95); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 90); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 180); } #[test] @@ -1769,12 +1783,12 @@ fn decrease_short_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_long: 0, - base_asset_amount_short: -10, - quote_asset_amount: 100, - quote_entry_amount_short: 100, - quote_break_even_amount_short: 200, - cumulative_funding_rate_short: 1, + base_asset_amount_long: 0.into(), + base_asset_amount_short: (-10).into(), + quote_asset_amount: 100.into(), + quote_entry_amount_short: 100.into(), + quote_break_even_amount_short: 200.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1792,13 +1806,13 @@ fn decrease_short_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 1); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -9); - assert_eq!(market.amm.quote_asset_amount, 85); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 90); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 180); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -9); + assert_eq!(market.amm.quote_asset_amount(), 85); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 90); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 180); } #[test] @@ -1817,14 +1831,14 @@ fn flip_short_to_long_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: -10, - base_asset_amount_long: 0, - base_asset_amount_short: -10, - quote_asset_amount: 100, - quote_entry_amount_short: 100, - quote_break_even_amount_short: 200, - cumulative_funding_rate_long: 2, - cumulative_funding_rate_short: 1, + base_asset_amount_with_amm: (-10).into(), + base_asset_amount_long: 0.into(), + base_asset_amount_short: (-10).into(), + quote_asset_amount: 100.into(), + quote_entry_amount_short: 100.into(), + quote_break_even_amount_short: 200.into(), + cumulative_funding_rate_long: 2.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1842,14 +1856,14 @@ fn flip_short_to_long_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 2); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 1); - assert_eq!(market.amm.quote_asset_amount, 40); - assert_eq!(market.amm.quote_entry_amount_long, -6); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -6); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), 40); + assert_eq!(market.amm.quote_entry_amount_long(), -6); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -6); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1868,14 +1882,14 @@ fn flip_short_to_long_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: -10, - base_asset_amount_long: 0, - base_asset_amount_short: -10, - quote_asset_amount: 100, - quote_entry_amount_short: 100, - quote_break_even_amount_short: 200, - cumulative_funding_rate_long: 2, - cumulative_funding_rate_short: 1, + base_asset_amount_with_amm: (-10).into(), + base_asset_amount_long: 0.into(), + base_asset_amount_short: (-10).into(), + quote_asset_amount: 100.into(), + quote_entry_amount_short: 100.into(), + quote_break_even_amount_short: 200.into(), + cumulative_funding_rate_long: 2.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 1, @@ -1893,14 +1907,14 @@ fn flip_short_to_long_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 2); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 1); - assert_eq!(market.amm.quote_asset_amount, -20); - assert_eq!(market.amm.quote_entry_amount_long, -11); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -11); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), -20); + assert_eq!(market.amm.quote_entry_amount_long(), -11); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -11); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1919,12 +1933,12 @@ fn close_long_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 11, - base_asset_amount_long: 11, - quote_asset_amount: -11, - quote_entry_amount_long: -11, - quote_break_even_amount_long: -13, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 11.into(), + base_asset_amount_long: 11.into(), + quote_asset_amount: (-11).into(), + quote_entry_amount_long: (-11).into(), + quote_break_even_amount_long: (-13).into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 2, @@ -1942,15 +1956,15 @@ fn close_long_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 1); // not 5 because quote asset amount long was -11 not -10 before - assert_eq!(market.amm.quote_asset_amount, 4); - assert_eq!(market.amm.quote_entry_amount_long, -1); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -1); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), 4); + assert_eq!(market.amm.quote_entry_amount_long(), -1); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -1); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -1969,12 +1983,12 @@ fn close_long_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 11, - base_asset_amount_long: 11, - quote_asset_amount: -11, - quote_entry_amount_long: -11, - quote_break_even_amount_long: -13, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 11.into(), + base_asset_amount_long: 11.into(), + quote_asset_amount: (-11).into(), + quote_entry_amount_long: (-11).into(), + quote_break_even_amount_long: (-13).into(), + cumulative_funding_rate_long: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 2, @@ -1992,14 +2006,14 @@ fn close_long_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 1); - assert_eq!(market.amm.quote_asset_amount, -6); - assert_eq!(market.amm.quote_entry_amount_long, -1); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, -1); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), -6); + assert_eq!(market.amm.quote_entry_amount_long(), -1); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), -1); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -2018,11 +2032,11 @@ fn close_short_profitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_short: -11, - quote_asset_amount: 11, - quote_entry_amount_short: 11, - quote_break_even_amount_short: 13, - cumulative_funding_rate_short: 1, + base_asset_amount_short: (-11).into(), + quote_asset_amount: 11.into(), + quote_entry_amount_short: 11.into(), + quote_break_even_amount_short: 13.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 2, @@ -2040,13 +2054,13 @@ fn close_short_profitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); - assert_eq!(market.amm.quote_asset_amount, 6); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 1); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 1); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); + assert_eq!(market.amm.quote_asset_amount(), 6); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 1); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 1); } #[test] @@ -2065,11 +2079,11 @@ fn close_short_unprofitable() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_short: -11, - quote_asset_amount: 11, - quote_entry_amount_short: 11, - quote_break_even_amount_short: 13, - cumulative_funding_rate_short: 1, + base_asset_amount_short: (-11).into(), + quote_asset_amount: 11.into(), + quote_entry_amount_short: 11.into(), + quote_break_even_amount_short: 13.into(), + cumulative_funding_rate_short: 1.into(), ..AMM::default_test() }, number_of_users_with_base: 2, @@ -2087,13 +2101,13 @@ fn close_short_unprofitable() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); - assert_eq!(market.amm.quote_asset_amount, -4); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 1); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 1); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); + assert_eq!(market.amm.quote_asset_amount(), -4); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 1); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 1); } #[test] @@ -2112,12 +2126,12 @@ fn close_long_with_quote_break_even_amount_less_than_quote_asset_amount() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 11, - base_asset_amount_long: 11, - quote_asset_amount: -11, - quote_entry_amount_long: -8, - quote_break_even_amount_long: -9, - cumulative_funding_rate_long: 1, + base_asset_amount_with_amm: 11.into(), + base_asset_amount_long: 11.into(), + quote_asset_amount: (-11).into(), + quote_entry_amount_long: (-8).into(), + quote_break_even_amount_long: (-9).into(), + cumulative_funding_rate_long: 1.into(), order_step_size: 1, ..AMM::default() }, @@ -2136,14 +2150,14 @@ fn close_long_with_quote_break_even_amount_less_than_quote_asset_amount() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 1); - assert_eq!(market.amm.base_asset_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 1); + assert_eq!(market.amm.base_asset_amount_short(), 0); // assert_eq!(market.amm.base_asset_amount_with_amm, 1); - assert_eq!(market.amm.quote_asset_amount, -6); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.quote_asset_amount(), -6); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -2162,11 +2176,11 @@ fn close_short_with_quote_break_even_amount_more_than_quote_asset_amount() { }; let mut market = PerpMarket { amm: AMM { - base_asset_amount_short: -11, - quote_asset_amount: 11, - quote_entry_amount_short: 15, - quote_break_even_amount_short: 17, - cumulative_funding_rate_short: 1, + base_asset_amount_short: (-11).into(), + quote_asset_amount: 11.into(), + quote_entry_amount_short: 15.into(), + quote_break_even_amount_short: 17.into(), + cumulative_funding_rate_short: 1.into(), order_step_size: 1, ..AMM::default() }, @@ -2185,13 +2199,13 @@ fn close_short_with_quote_break_even_amount_more_than_quote_asset_amount() { assert_eq!(existing_position.last_cumulative_funding_rate, 0); assert_eq!(market.number_of_users_with_base, 1); - assert_eq!(market.amm.base_asset_amount_long, 0); - assert_eq!(market.amm.base_asset_amount_short, -1); - assert_eq!(market.amm.quote_asset_amount, -4); - assert_eq!(market.amm.quote_entry_amount_long, 0); - assert_eq!(market.amm.quote_entry_amount_short, 0); - assert_eq!(market.amm.quote_break_even_amount_long, 0); - assert_eq!(market.amm.quote_break_even_amount_short, 0); + assert_eq!(market.amm.base_asset_amount_long(), 0); + assert_eq!(market.amm.base_asset_amount_short(), -1); + assert_eq!(market.amm.quote_asset_amount(), -4); + assert_eq!(market.amm.quote_entry_amount_long(), 0); + assert_eq!(market.amm.quote_entry_amount_short(), 0); + assert_eq!(market.amm.quote_break_even_amount_long(), 0); + assert_eq!(market.amm.quote_break_even_amount_short(), 0); } #[test] @@ -2227,15 +2241,21 @@ fn update_amm_near_boundary() { OracleMap::load_one(&jto_market_account_info, slot, None).unwrap(); let mut perp_market = perp_market_loader.load_mut().unwrap(); - assert_eq!(perp_market.amm.base_asset_amount_with_amm, 23831444927173); + assert_eq!(perp_market.amm.base_asset_amount_with_amm(), 23831444927173); assert_eq!( - perp_market.amm.base_asset_amount_with_unsettled_lp, + perp_market.amm.base_asset_amount_with_unsettled_lp(), 562555072827 ); - perp_market.amm.base_asset_amount_with_amm += - perp_market.amm.base_asset_amount_with_unsettled_lp; - perp_market.amm.base_asset_amount_with_unsettled_lp = 0; + let base_asset_amount_with_amm = perp_market.amm.base_asset_amount_with_amm; + let base_asset_amount_with_unsettled_lp = perp_market.amm.base_asset_amount_with_unsettled_lp(); + perp_market.amm.set_base_asset_amount_with_amm( + base_asset_amount_with_amm + .as_i128() + .safe_add(base_asset_amount_with_unsettled_lp) + .unwrap(), + ); + perp_market.amm.set_base_asset_amount_with_unsettled_lp(0); println!("perp_market: {:?}", perp_market.amm.last_update_slot); let oracle_price_data = oracle_map.get_price_data(&perp_market.oracle_id()).unwrap(); @@ -2346,7 +2366,7 @@ fn recenter_amm_1() { assert_eq!(cost, 2538958); - let inv = perp_market.amm.base_asset_amount_with_amm; + let inv = perp_market.amm.base_asset_amount_with_amm(); assert_eq!(inv, 24521505718700); let (_, _, r1_orig, r2_orig) = calculate_base_swap_output_with_spread( @@ -2359,15 +2379,15 @@ fn recenter_amm_1() { assert_eq!(r1_orig, 334835274409); assert_eq!(r2_orig, 704841208); - let current_k = perp_market.amm.sqrt_k; - let _current_peg = perp_market.amm.peg_multiplier; + let current_k = perp_market.amm.sqrt_k(); + let _current_peg = perp_market.amm.peg_multiplier(); let new_k = (current_k * 900000) / 100; recenter_perp_market_amm(&mut perp_market, oracle_price_data.price as u128, new_k).unwrap(); - assert_eq!(perp_market.amm.sqrt_k, new_k); + assert_eq!(perp_market.amm.sqrt_k(), new_k); assert_eq!( - perp_market.amm.peg_multiplier, + perp_market.amm.peg_multiplier(), oracle_price_data.price as u128 ); @@ -2432,9 +2452,9 @@ fn recenter_amm_2() { ); // previous values - assert_eq!(perp_market.amm.peg_multiplier, 5); - assert_eq!(perp_market.amm.quote_asset_reserve, 64381518181749930705); - assert_eq!(perp_market.amm.base_asset_reserve, 307161425106214); + assert_eq!(perp_market.amm.peg_multiplier(), 5); + assert_eq!(perp_market.amm.quote_asset_reserve(), 64381518181749930705); + assert_eq!(perp_market.amm.base_asset_reserve(), 307161425106214); let oracle_price_data = oracle_map .get_price_data(&(oracle_price_key, OracleSource::Pyth)) @@ -2454,7 +2474,7 @@ fn recenter_amm_2() { assert_eq!(cost, 0); - let inv = perp_market.amm.base_asset_amount_with_amm; + let inv = perp_market.amm.base_asset_amount_with_amm(); assert_eq!(inv, -291516212); let (_, _, r1_orig, r2_orig) = calculate_base_swap_output_with_spread( @@ -2467,34 +2487,40 @@ fn recenter_amm_2() { assert_eq!(r1_orig, 326219); assert_eq!(r2_orig, 20707); - let current_k = perp_market.amm.sqrt_k; - let _current_peg = perp_market.amm.peg_multiplier; + let current_k = perp_market.amm.sqrt_k(); + let _current_peg = perp_market.amm.peg_multiplier(); let new_k = current_k * 2; // refusal to decrease further assert_eq!(current_k, current_k); - assert_eq!(perp_market.amm.user_lp_shares, current_k - 1); + assert_eq!(perp_market.amm.user_lp_shares(), current_k - 1); assert_eq!( perp_market.amm.get_lower_bound_sqrt_k().unwrap(), perp_market.amm.min_order_size as u128 ); - perp_market.amm.base_asset_amount_with_amm += - perp_market.amm.base_asset_amount_with_unsettled_lp; - perp_market.amm.base_asset_amount_with_unsettled_lp = 0; + let base_asset_amount_with_amm = perp_market.amm.base_asset_amount_with_amm; + let base_asset_amount_with_unsettled_lp = perp_market.amm.base_asset_amount_with_unsettled_lp; + perp_market.amm.set_base_asset_amount_with_amm( + base_asset_amount_with_amm + .as_i128() + .safe_add(base_asset_amount_with_unsettled_lp.as_i128()) + .unwrap(), + ); + perp_market.amm.set_base_asset_amount_with_unsettled_lp(0); recenter_perp_market_amm(&mut perp_market, oracle_price_data.price as u128, new_k).unwrap(); - assert_eq!(perp_market.amm.sqrt_k, new_k); + assert_eq!(perp_market.amm.sqrt_k(), new_k); assert_eq!( - perp_market.amm.peg_multiplier, + perp_market.amm.peg_multiplier(), oracle_price_data.price as u128 ); - assert_eq!(perp_market.amm.peg_multiplier, 1_120_000); + assert_eq!(perp_market.amm.peg_multiplier(), 1_120_000); // assert_eq!(perp_market.amm.quote_asset_reserve, 140625455708483789 * 2); // assert_eq!(perp_market.amm.base_asset_reserve, 140625456291516213 * 2); - assert_eq!(perp_market.amm.base_asset_reserve, 281254004000000002); - assert_eq!(perp_market.amm.quote_asset_reserve, 281247820033992278); + assert_eq!(perp_market.amm.base_asset_reserve(), 281254004000000002); + assert_eq!(perp_market.amm.quote_asset_reserve(), 281247820033992278); crate::validation::perp_market::validate_perp_market(&perp_market).unwrap(); @@ -2510,15 +2536,15 @@ fn recenter_amm_2() { assert_eq!(r2, 22129); let new_scale = 2; - let new_sqrt_k = perp_market.amm.sqrt_k * new_scale; + let new_sqrt_k = perp_market.amm.sqrt_k() * new_scale; let update_k_result = get_update_k_result(&perp_market, U192::from(new_sqrt_k), false).unwrap(); let adjustment_cost = adjust_k_cost(&mut perp_market, &update_k_result).unwrap(); assert_eq!(adjustment_cost, 19035); update_k(&mut perp_market, &update_k_result).unwrap(); - assert_eq!(perp_market.amm.sqrt_k, new_sqrt_k); - assert_eq!(perp_market.amm.user_lp_shares, current_k - 1); + assert_eq!(perp_market.amm.sqrt_k(), new_sqrt_k); + assert_eq!(perp_market.amm.user_lp_shares(), current_k - 1); assert_eq!( perp_market.amm.get_lower_bound_sqrt_k().unwrap(), 3092000000000 @@ -2567,16 +2593,18 @@ fn test_move_amm() { // let perp_market_old = market_map.get_ref(&4).unwrap(); let mut perp_market = market_map.get_ref_mut(&9).unwrap(); - perp_market.amm.base_asset_amount_with_amm = -3092 * BASE_PRECISION as i128; + perp_market + .amm + .set_base_asset_amount_with_amm(-3092 * BASE_PRECISION as i128); println!( "perp_market latest slot: {:?}", perp_market.amm.last_update_slot ); // previous values - assert_eq!(perp_market.amm.peg_multiplier, 5); - assert_eq!(perp_market.amm.quote_asset_reserve, 64381518181749930705); - assert_eq!(perp_market.amm.base_asset_reserve, 307161425106214); + assert_eq!(perp_market.amm.peg_multiplier(), 5); + assert_eq!(perp_market.amm.quote_asset_reserve(), 64381518181749930705); + assert_eq!(perp_market.amm.base_asset_reserve(), 307161425106214); let oracle_price_data = oracle_map .get_price_data(&(oracle_price_key, OracleSource::Pyth)) @@ -2596,7 +2624,7 @@ fn test_move_amm() { assert_eq!(cost, 0); - let inv = perp_market.amm.base_asset_amount_with_amm; + let inv = perp_market.amm.base_asset_amount_with_amm(); assert_eq!(inv, -3092000000000); let (_, _, r1_orig, r2_orig) = calculate_base_swap_output_with_spread( @@ -2608,9 +2636,9 @@ fn test_move_amm() { assert_eq!(r1_orig, 3489128798); assert_eq!(r2_orig, 215737299); - let current_bar = perp_market.amm.base_asset_reserve; - let _current_qar = perp_market.amm.quote_asset_reserve; - let current_k = perp_market.amm.sqrt_k; + let current_bar = perp_market.amm.base_asset_reserve(); + let _current_qar = perp_market.amm.quote_asset_reserve(); + let current_k = perp_market.amm.sqrt_k(); let inc_numerator = BASE_PRECISION + BASE_PRECISION / 100; let new_k = current_k * inc_numerator / BASE_PRECISION; @@ -2624,6 +2652,6 @@ fn test_move_amm() { ) .unwrap(); crate::validation::perp_market::validate_perp_market(&perp_market).unwrap(); - assert_eq!(perp_market.amm.sqrt_k, new_k); - assert_eq!(perp_market.amm.peg_multiplier, 5); // still same + assert_eq!(perp_market.amm.sqrt_k(), new_k); + assert_eq!(perp_market.amm.peg_multiplier(), 5); // still same } diff --git a/programs/drift/src/controller/repeg.rs b/programs/drift/src/controller/repeg.rs index f41af93fdc..7685b9ff6d 100644 --- a/programs/drift/src/controller/repeg.rs +++ b/programs/drift/src/controller/repeg.rs @@ -49,7 +49,7 @@ pub fn repeg( ) -> DriftResult { // for adhoc admin only repeg - if new_peg_candidate == market.amm.peg_multiplier { + if new_peg_candidate == market.amm.peg_multiplier() { return Err(ErrorCode::InvalidRepegRedundant); } let (terminal_price_before, _terminal_quote_reserves, _terminal_base_reserves) = @@ -91,7 +91,7 @@ pub fn repeg( // modify market's total fee change and peg change let cost_applied = apply_cost_to_market(market, adjustment_cost, true)?; if cost_applied { - market.amm.peg_multiplier = new_peg_candidate; + market.amm.set_peg_multiplier(new_peg_candidate); } else { return Err(ErrorCode::InvalidRepegProfitability); } @@ -201,12 +201,14 @@ pub fn _update_amm( cp_curve::update_k( market, &UpdateKResult { - sqrt_k: repegged_market.amm.sqrt_k, - base_asset_reserve: repegged_market.amm.base_asset_reserve, - quote_asset_reserve: repegged_market.amm.quote_asset_reserve, + sqrt_k: repegged_market.amm.sqrt_k(), + base_asset_reserve: repegged_market.amm.base_asset_reserve(), + quote_asset_reserve: repegged_market.amm.quote_asset_reserve(), }, )?; - market.amm.peg_multiplier = repegged_market.amm.peg_multiplier; + market + .amm + .set_peg_multiplier(repegged_market.amm.peg_multiplier()); amm_update_cost = repegged_cost; } else { msg!("amm_not_successfully_updated = true (repeg cost not applied for check_lower_bound={})", check_lower_bound); @@ -291,28 +293,34 @@ pub fn apply_cost_to_market( // Reduce pnl to quote asset precision and take the absolute value if cost > 0 { let new_total_fee_minus_distributions = - market.amm.total_fee_minus_distributions.safe_sub(cost)?; + market.amm.total_fee_minus_distributions().safe_sub(cost)?; let fee_reserved_for_protocol = repeg::get_total_fee_lower_bound(market)? - .safe_add(market.amm.total_liquidation_fee)? - .safe_sub(market.amm.total_fee_withdrawn)? + .safe_add(market.amm.total_liquidation_fee())? + .safe_sub(market.amm.total_fee_withdrawn())? .cast::()?; // Only a portion of the protocol fees are allocated to repegging // This checks that the total_fee_minus_distributions does not decrease too much after repeg if check_lower_bound { if new_total_fee_minus_distributions >= fee_reserved_for_protocol { - market.amm.total_fee_minus_distributions = new_total_fee_minus_distributions; + market + .amm + .set_total_fee_minus_distributions(new_total_fee_minus_distributions); } else { return Ok(false); } } else { - market.amm.total_fee_minus_distributions = new_total_fee_minus_distributions; + market + .amm + .set_total_fee_minus_distributions(new_total_fee_minus_distributions); } } else { - market.amm.total_fee_minus_distributions = market - .amm - .total_fee_minus_distributions - .safe_add(cost.abs())?; + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_add(cost.abs())?, + ); } market.amm.net_revenue_since_last_funding = market @@ -349,24 +357,24 @@ pub fn settle_expired_market( )?; validate!( - market.amm.base_asset_amount_with_unsettled_lp == 0, + market.amm.base_asset_amount_with_unsettled_lp() == 0, ErrorCode::MarketSettlementRequiresSettledLP, "Outstanding LP in market" )?; let spot_market = &mut spot_market_map.get_ref_mut("E_SPOT_MARKET_INDEX)?; let fee_reserved_for_protocol = repeg::get_total_fee_lower_bound(market)? - .safe_add(market.amm.total_liquidation_fee)? - .safe_sub(market.amm.total_fee_withdrawn)? + .safe_add(market.amm.total_liquidation_fee())? + .safe_sub(market.amm.total_fee_withdrawn())? .cast::()?; let budget = market .amm - .total_fee_minus_distributions + .total_fee_minus_distributions() .safe_sub(fee_reserved_for_protocol)? .max(0); let available_fee_pool = get_token_amount( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )? @@ -400,7 +408,7 @@ pub fn settle_expired_market( K_BPS_UPDATE_SCALE, )?; - let new_sqrt_k = bn::U192::from(market.amm.sqrt_k) + let new_sqrt_k = bn::U192::from(market.amm.sqrt_k()) .safe_mul(bn::U192::from(k_scale_numerator))? .safe_div(bn::U192::from(k_scale_denominator))? .min(bn::U192::from(MAX_SQRT_K)); @@ -447,13 +455,13 @@ pub fn settle_expired_market( )?; let pnl_pool_token_amount = get_token_amount( - market.pnl_pool.scaled_balance, + market.pnl_pool.scaled_balance(), spot_market, market.pnl_pool.balance_type(), )?; let fee_pool_token_amount = get_token_amount( - market.amm.fee_pool.scaled_balance, + market.amm.fee_pool.scaled_balance(), spot_market, market.amm.fee_pool.balance_type(), )?; diff --git a/programs/drift/src/controller/repeg/tests.rs b/programs/drift/src/controller/repeg/tests.rs index cc369c25e1..534bb23a4d 100644 --- a/programs/drift/src/controller/repeg/tests.rs +++ b/programs/drift/src/controller/repeg/tests.rs @@ -18,12 +18,12 @@ use crate::state::user::MarketType; pub fn update_amm_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 65 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 63015384615, - terminal_quote_asset_reserve: 64 * AMM_RESERVE_PRECISION, - sqrt_k: 64 * AMM_RESERVE_PRECISION, - peg_multiplier: 19_400 * PEG_PRECISION, - base_asset_amount_with_amm: -(AMM_RESERVE_PRECISION as i128), + base_asset_reserve: (65 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: 63015384615.into(), + terminal_quote_asset_reserve: (64 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (64 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (19_400 * PEG_PRECISION).into(), + base_asset_amount_with_amm: (-(AMM_RESERVE_PRECISION as i128)).into(), mark_std: PRICE_PRECISION as u64, last_mark_price_twap_ts: 0, historical_oracle_data: HistoricalOracleData { @@ -35,7 +35,7 @@ pub fn update_amm_test() { base_spread: 250, curve_update_intensity: 100, max_spread: 55500, - concentration_coef: 31020710, //unrealistic but for poc + concentration_coef: 31020710.into(), //unrealistic but for poc ..AMM::default() }, status: MarketStatus::Initialized, @@ -48,10 +48,14 @@ pub fn update_amm_test() { // market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; assert_eq!(new_terminal_quote_reserve, 64000000000); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, new_terminal_base_reserve) + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), new_terminal_base_reserve) .unwrap(); - market.amm.min_base_asset_reserve = min_base_asset_reserve; - market.amm.max_base_asset_reserve = max_base_asset_reserve; + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); let state = State { oracle_guard_rails: OracleGuardRails { @@ -104,7 +108,7 @@ pub fn update_amm_test() { let cost_of_update = _update_amm(&mut market, &mm_oracle_price_data, &state, now, slot).unwrap(); - assert_eq!(market.amm.sqrt_k, 63936000000); + assert_eq!(market.amm.sqrt_k(), 63936000000); let is_oracle_valid = oracle::oracle_validity( MarketType::Perp, market.market_index, @@ -150,8 +154,8 @@ pub fn update_amm_test() { .unwrap(); assert!(too_diverge); - let profit = market.amm.total_fee_minus_distributions; - let peg = market.amm.peg_multiplier; + let profit = market.amm.total_fee_minus_distributions(); + let peg = market.amm.peg_multiplier(); assert_eq!(-cost_of_update, profit); assert!(is_oracle_valid); assert!(profit < 0); @@ -184,15 +188,15 @@ pub fn update_amm_test() { pub fn update_amm_test_bad_oracle() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 65 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 630153846154000, - terminal_quote_asset_reserve: 64 * AMM_RESERVE_PRECISION, - sqrt_k: 64 * AMM_RESERVE_PRECISION, - peg_multiplier: 19_400_000, - base_asset_amount_with_amm: -(AMM_RESERVE_PRECISION as i128), + base_asset_reserve: (65 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: 630153846154000.into(), + terminal_quote_asset_reserve: (64 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (64 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 19_400_000.into(), + base_asset_amount_with_amm: (-(AMM_RESERVE_PRECISION as i128)).into(), mark_std: PRICE_PRECISION as u64, last_mark_price_twap_ts: 0, - concentration_coef: 1020710, + concentration_coef: 1020710.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: 19_400 * PRICE_PRECISION_I64, ..HistoricalOracleData::default() @@ -263,7 +267,7 @@ pub fn update_amm_larg_conf_test() { let slot = 81680085; let mut market = PerpMarket::default_btc_test(); - assert_eq!(market.amm.base_asset_amount_with_amm, -1000000000); + assert_eq!(market.amm.base_asset_amount_with_amm(), -1000000000); let state = State { oracle_guard_rails: OracleGuardRails { @@ -332,7 +336,7 @@ pub fn update_amm_larg_conf_test() { assert_eq!(mrk, 18849999999); assert_eq!(market.amm.long_spread, 2237); - assert_eq!(market.amm.peg_multiplier, 19443664550); + assert_eq!(market.amm.peg_multiplier(), 19443664550); assert_eq!(market.amm.short_spread, 26454); // add move lower @@ -345,16 +349,16 @@ pub fn update_amm_larg_conf_test() { }; let fee_budget = calculate_fee_pool(&market).unwrap(); - assert_eq!(market.amm.total_fee_minus_distributions, 42992787); + assert_eq!(market.amm.total_fee_minus_distributions(), 42992787); assert_eq!(fee_budget, 42992787); let optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), oracle_price_data.price as u64, ) .unwrap(); - assert_eq!(market.amm.peg_multiplier, 19443664550); + assert_eq!(market.amm.peg_multiplier(), 19443664550); assert_eq!(optimal_peg, 19412719726); let optimal_peg_cost = calculate_repeg_cost(&market.amm, optimal_peg).unwrap(); @@ -412,9 +416,11 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() { let slot = 81680085; let mut market = PerpMarket::default_btc_test(); - market.amm.concentration_coef = 1414213; - market.amm.total_fee_minus_distributions = -(10000 * QUOTE_PRECISION as i128); - assert_eq!(market.amm.base_asset_amount_with_amm, -1000000000); + market.amm.set_concentration_coef(1414213); + market + .amm + .set_total_fee_minus_distributions(-(10000 * QUOTE_PRECISION as i128)); + assert_eq!(market.amm.base_asset_amount_with_amm(), -1000000000); let state = State { oracle_guard_rails: OracleGuardRails { @@ -448,25 +454,25 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() { assert_eq!(market.amm.long_spread, 0); assert_eq!(market.amm.short_spread, 0); assert_eq!(market.amm.last_update_slot, 0); - assert_eq!(market.amm.sqrt_k, 64000000000); - let prev_peg_multiplier = market.amm.peg_multiplier; - let prev_total_fee_minus_distributions = market.amm.total_fee_minus_distributions; + assert_eq!(market.amm.sqrt_k(), 64000000000); + let prev_peg_multiplier = market.amm.peg_multiplier(); + let prev_total_fee_minus_distributions = market.amm.total_fee_minus_distributions(); let cost_of_update = _update_amm(&mut market, &mm_oracle_price_data, &state, now, slot).unwrap(); assert!(market.amm.is_recent_oracle_valid(slot).unwrap()); assert_eq!(cost_of_update, -42992787); // amm wins when price increases - assert_eq!(market.amm.sqrt_k, 64000000000); - assert_eq!(market.amm.base_asset_reserve, 65000000000); - assert_eq!(market.amm.quote_asset_reserve, 63015384615); - assert_eq!(market.amm.terminal_quote_asset_reserve, 64000000000); - assert_eq!(market.amm.min_base_asset_reserve, 45254851991); - assert_eq!(market.amm.max_base_asset_reserve, 90509632000); - assert_eq!(market.amm.peg_multiplier, 19443664550); - assert_eq!(market.amm.peg_multiplier > prev_peg_multiplier, true); - assert_eq!(market.amm.total_fee_minus_distributions, -9957007213); + assert_eq!(market.amm.sqrt_k(), 64000000000); + assert_eq!(market.amm.base_asset_reserve(), 65000000000); + assert_eq!(market.amm.quote_asset_reserve(), 63015384615); + assert_eq!(market.amm.terminal_quote_asset_reserve(), 64000000000); + assert_eq!(market.amm.min_base_asset_reserve(), 45254851991); + assert_eq!(market.amm.max_base_asset_reserve(), 90509632000); + assert_eq!(market.amm.peg_multiplier(), 19443664550); + assert_eq!(market.amm.peg_multiplier() > prev_peg_multiplier, true); + assert_eq!(market.amm.total_fee_minus_distributions(), -9957007213); assert_eq!( - market.amm.total_fee_minus_distributions > prev_total_fee_minus_distributions, + market.amm.total_fee_minus_distributions() > prev_total_fee_minus_distributions, true ); @@ -529,37 +535,37 @@ pub fn update_amm_larg_conf_w_neg_tfmd_test() { .unwrap(); let fee_budget = calculate_fee_pool(&market).unwrap(); - assert_eq!(market.amm.total_fee_minus_distributions, -9957007213); + assert_eq!(market.amm.total_fee_minus_distributions(), -9957007213); assert_eq!(fee_budget, 0); let optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), oracle_price_data.price as u64, ) .unwrap(); - assert_eq!(market.amm.peg_multiplier, 19443664550); + assert_eq!(market.amm.peg_multiplier(), 19443664550); assert_eq!(optimal_peg, 19412719726); let optimal_peg_cost = calculate_repeg_cost(&market.amm, optimal_peg).unwrap(); assert_eq!(optimal_peg_cost, 30468749); - let prev_peg_multiplier = market.amm.peg_multiplier; - let prev_total_fee_minus_distributions = market.amm.total_fee_minus_distributions; + let prev_peg_multiplier = market.amm.peg_multiplier(); + let prev_total_fee_minus_distributions = market.amm.total_fee_minus_distributions(); let cost_of_update = _update_amm(&mut market, &mm_oracle_price_data, &state, now, slot).unwrap(); assert_eq!(cost_of_update, 21459587); // amm loses when price decreases (given users are net short) - assert_eq!(market.amm.sqrt_k, 63936000000); // k lowered since cost_of_update is positive and total_fee_minus_distributions negative - assert_eq!(market.amm.base_asset_reserve, 64935000065); - assert_eq!(market.amm.quote_asset_reserve, 62952369167); - assert_eq!(market.amm.terminal_quote_asset_reserve, 63936999950); - assert_eq!(market.amm.min_base_asset_reserve, 45208890078); - assert_eq!(market.amm.max_base_asset_reserve, 90417708246); - assert_eq!(market.amm.peg_multiplier, 19421869997); - assert_eq!(market.amm.peg_multiplier < prev_peg_multiplier, true); + assert_eq!(market.amm.sqrt_k(), 63936000000); // k lowered since cost_of_update is positive and total_fee_minus_distributions negative + assert_eq!(market.amm.base_asset_reserve(), 64935000065); + assert_eq!(market.amm.quote_asset_reserve(), 62952369167); + assert_eq!(market.amm.terminal_quote_asset_reserve(), 63936999950); + assert_eq!(market.amm.min_base_asset_reserve(), 45208890078); + assert_eq!(market.amm.max_base_asset_reserve(), 90417708246); + assert_eq!(market.amm.peg_multiplier(), 19421869997); + assert_eq!(market.amm.peg_multiplier() < prev_peg_multiplier, true); // assert_eq!(market.amm.total_fee_minus_distributions, -9978167413); assert_eq!( - market.amm.total_fee_minus_distributions < prev_total_fee_minus_distributions, + market.amm.total_fee_minus_distributions() < prev_total_fee_minus_distributions, true ); diff --git a/programs/drift/src/controller/revenue_share.rs b/programs/drift/src/controller/revenue_share.rs index 61681cd7a4..8adedabd26 100644 --- a/programs/drift/src/controller/revenue_share.rs +++ b/programs/drift/src/controller/revenue_share.rs @@ -70,7 +70,7 @@ pub fn sweep_completed_revenue_share_for_market<'a>( } let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), quote_spot_market, perp_market.pnl_pool.balance_type(), )?; diff --git a/programs/drift/src/controller/spot_balance.rs b/programs/drift/src/controller/spot_balance.rs index f8e1b625e9..95f06c19e1 100644 --- a/programs/drift/src/controller/spot_balance.rs +++ b/programs/drift/src/controller/spot_balance.rs @@ -39,13 +39,13 @@ pub fn update_spot_market_twap_stats( let from_start = max(1_i64, SPOT_MARKET_TOKEN_TWAP_WINDOW.safe_sub(since_last)?); let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )?; @@ -151,18 +151,22 @@ pub fn update_spot_market_cumulative_interest( deposit_interest.safe_sub(deposit_interest_for_stakers)?; if deposit_interest_for_lenders > 0 { - spot_market.cumulative_deposit_interest = spot_market - .cumulative_deposit_interest - .safe_add(deposit_interest_for_lenders)?; - - spot_market.cumulative_borrow_interest = spot_market - .cumulative_borrow_interest - .safe_add(borrow_interest)?; + spot_market.set_cumulative_deposit_interest( + spot_market + .cumulative_deposit_interest() + .safe_add(deposit_interest_for_lenders)?, + ); + + spot_market.set_cumulative_borrow_interest( + spot_market + .cumulative_borrow_interest() + .safe_add(borrow_interest)?, + ); spot_market.last_interest_ts = now.cast()?; // add deposit_interest_for_stakers as balance for revenue_pool let token_amount = get_interest_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, deposit_interest_for_stakers, )?; @@ -172,10 +176,10 @@ pub fn update_spot_market_cumulative_interest( emit!(SpotInterestRecord { ts: now, market_index: spot_market.market_index, - deposit_balance: spot_market.deposit_balance, - cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - borrow_balance: spot_market.borrow_balance, - cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + deposit_balance: spot_market.deposit_balance(), + cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + borrow_balance: spot_market.borrow_balance(), + cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), optimal_utilization: spot_market.optimal_utilization, optimal_borrow_rate: spot_market.optimal_borrow_rate, max_borrow_rate: spot_market.max_borrow_rate, @@ -261,13 +265,13 @@ pub fn update_spot_balances( if is_leaving_drift && update_direction == &SpotBalanceType::Borrow { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )?; @@ -302,10 +306,10 @@ pub fn transfer_spot_balances( if from_spot_balance.balance_type() == &SpotBalanceType::Deposit { validate!( - spot_market.deposit_balance >= from_spot_balance.balance(), + spot_market.deposit_balance() >= from_spot_balance.balance(), ErrorCode::InvalidSpotMarketState, "spot_market.deposit_balance={} lower than individual spot balance={}", - spot_market.deposit_balance, + spot_market.deposit_balance(), from_spot_balance.balance() )?; } @@ -435,10 +439,10 @@ fn increase_spot_balance( ) -> DriftResult { match balance_type { SpotBalanceType::Deposit => { - spot_market.deposit_balance = spot_market.deposit_balance.safe_add(delta)? + spot_market.set_deposit_balance(spot_market.deposit_balance().safe_add(delta)?) } SpotBalanceType::Borrow => { - spot_market.borrow_balance = spot_market.borrow_balance.safe_add(delta)? + spot_market.set_borrow_balance(spot_market.borrow_balance().safe_add(delta)?) } } @@ -452,10 +456,10 @@ fn decrease_spot_balance( ) -> DriftResult { match balance_type { SpotBalanceType::Deposit => { - spot_market.deposit_balance = spot_market.deposit_balance.safe_sub(delta)? + spot_market.set_deposit_balance(spot_market.deposit_balance().safe_sub(delta)?) } SpotBalanceType::Borrow => { - spot_market.borrow_balance = spot_market.borrow_balance.safe_sub(delta)? + spot_market.set_borrow_balance(spot_market.borrow_balance().safe_sub(delta)?) } } diff --git a/programs/drift/src/controller/spot_balance/tests.rs b/programs/drift/src/controller/spot_balance/tests.rs index b1c19153c1..844b90925a 100644 --- a/programs/drift/src/controller/spot_balance/tests.rs +++ b/programs/drift/src/controller/spot_balance/tests.rs @@ -72,19 +72,19 @@ fn test_daily_withdraw_limits() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -102,14 +102,14 @@ fn test_daily_withdraw_limits() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, status: MarketStatus::Active, @@ -120,15 +120,15 @@ fn test_daily_withdraw_limits() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), deposit_token_twap: (SPOT_BALANCE_PRECISION * 10) as u64, borrow_token_twap: 0, @@ -159,11 +159,11 @@ fn test_daily_withdraw_limits() { let amount: u64 = QUOTE_PRECISION as u64; assert_eq!( - spot_market.cumulative_deposit_interest, + spot_market.cumulative_deposit_interest(), SPOT_CUMULATIVE_INTEREST_PRECISION ); assert_eq!( - spot_market.cumulative_borrow_interest, + spot_market.cumulative_borrow_interest(), SPOT_CUMULATIVE_INTEREST_PRECISION ); @@ -181,13 +181,13 @@ fn test_daily_withdraw_limits() { .is_err()); spot_market = spot_market_backup; user = user_backup; - assert_eq!(spot_market.deposit_balance, SPOT_BALANCE_PRECISION); + assert_eq!(spot_market.deposit_balance(), SPOT_BALANCE_PRECISION); // .50 * .2 = .1 assert_eq!(spot_market.deposit_token_twap, 500000); assert_eq!(user.spot_positions[0].scaled_balance, 1000000000); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance(), 1000000000); + assert_eq!(spot_market.borrow_balance(), 0); assert_eq!((amount / 2), 500000); update_spot_balances_and_cumulative_deposits_with_limits( (amount / 2) as u128, @@ -198,8 +198,8 @@ fn test_daily_withdraw_limits() { .unwrap(); assert_eq!(user.spot_positions[0].scaled_balance, 499999999); assert_eq!(spot_market.deposit_token_twap, 500000); - assert_eq!(spot_market.deposit_balance, 499999999); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance(), 499999999); + assert_eq!(spot_market.borrow_balance(), 0); // .50 * .25 = .125 update_spot_balances_and_cumulative_deposits_with_limits( @@ -222,7 +222,7 @@ fn test_daily_withdraw_limits() { .is_err()); spot_market = spot_market_backup; user = user_backup; - assert_eq!(spot_market.deposit_balance, 375001998); + assert_eq!(spot_market.deposit_balance(), 375001998); assert_eq!(user.spot_positions[0].scaled_balance, 375001998); assert_eq!(user.spot_positions[0].market_index, 0); @@ -245,7 +245,7 @@ fn test_daily_withdraw_limits() { &mut user, ) .unwrap(); - assert_eq!(spot_market.deposit_balance, 100000375001998); + assert_eq!(spot_market.deposit_balance(), 100000375001998); assert_eq!(user.spot_positions[0].scaled_balance, 100000375001998); assert_eq!(user.spot_positions[1].scaled_balance, 0); @@ -268,7 +268,7 @@ fn test_daily_withdraw_limits() { }), ..User::default() }; - sol_spot_market.deposit_balance = 50 * SPOT_BALANCE_PRECISION; + sol_spot_market.set_deposit_balance(50 * SPOT_BALANCE_PRECISION); sol_spot_market.deposit_token_twap = (500 * SPOT_BALANCE_PRECISION) as u64; sol_spot_market.optimal_utilization = 1_000_000 as u32; //20% APR @@ -344,8 +344,8 @@ fn test_daily_withdraw_limits() { ) .unwrap(); - assert_eq!(sol_spot_market.deposit_balance, 50000000000); - assert_eq!(sol_spot_market.borrow_balance, 8000000002); + assert_eq!(sol_spot_market.deposit_balance(), 50000000000); + assert_eq!(sol_spot_market.borrow_balance(), 8000000002); assert_eq!(sol_spot_market.borrow_token_twap, 0); update_spot_market_cumulative_interest(&mut sol_spot_market, None, now + 3655 * 24).unwrap(); @@ -419,14 +419,14 @@ fn test_check_withdraw_limits() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, status: MarketStatus::Active, @@ -437,15 +437,15 @@ fn test_check_withdraw_limits() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 2 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (2 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 28_000_000_000_u64, status: MarketStatus::Active, @@ -512,8 +512,8 @@ fn test_check_withdraw_limits_below_optimal_utilization() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: 1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, - cumulative_borrow_interest: 1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + cumulative_deposit_interest: (1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), + cumulative_borrow_interest: (1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), optimal_utilization: 700000, optimal_borrow_rate: 60000, @@ -524,8 +524,8 @@ fn test_check_withdraw_limits_below_optimal_utilization() { maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200_000 * SPOT_BALANCE_PRECISION, // 200k sol - borrow_balance: 100_000 * SPOT_BALANCE_PRECISION, + deposit_balance: (200_000 * SPOT_BALANCE_PRECISION).into(), // 200k sol + borrow_balance: (100_000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 204000000000000_u64, borrow_token_twap: 122200000000000_u64, @@ -541,13 +541,13 @@ fn test_check_withdraw_limits_below_optimal_utilization() { ); // below optimal util let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance(), &sol_spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - sol_spot_market.borrow_balance, + sol_spot_market.borrow_balance(), &sol_spot_market, &SpotBalanceType::Borrow, ) @@ -584,11 +584,11 @@ fn test_check_withdraw_limits_below_optimal_utilization() { assert_eq!(valid_withdraw, true); // ensure it fails due to higher min_dep above - sol_spot_market.deposit_balance = 174571428571428 / 1020 * 1000; + sol_spot_market.set_deposit_balance(174571428571428 / 1020 * 1000); sol_spot_market.utilization_twap = 100000; let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance(), &sol_spot_market, &SpotBalanceType::Deposit, ) @@ -613,8 +613,8 @@ fn test_check_withdraw_limits_above_optimal_utilization() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: 1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, - cumulative_borrow_interest: 1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + cumulative_deposit_interest: (1020 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), + cumulative_borrow_interest: (1222 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), optimal_utilization: 700000, // 70% optimal_borrow_rate: 60000, // 6% @@ -625,8 +625,8 @@ fn test_check_withdraw_limits_above_optimal_utilization() { maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 200_000 * SPOT_BALANCE_PRECISION, // 200k sol - borrow_balance: 160_000 * SPOT_BALANCE_PRECISION, + deposit_balance: (200_000 * SPOT_BALANCE_PRECISION).into(), // 200k sol + borrow_balance: (160_000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, deposit_token_twap: 204000000000000_u64, borrow_token_twap: 199200000000000_u64, @@ -642,13 +642,13 @@ fn test_check_withdraw_limits_above_optimal_utilization() { ); // below optimal util let deposit_tokens_1 = get_token_amount( - sol_spot_market.deposit_balance, + sol_spot_market.deposit_balance(), &sol_spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - sol_spot_market.borrow_balance, + sol_spot_market.borrow_balance(), &sol_spot_market, &SpotBalanceType::Borrow, ) @@ -711,7 +711,7 @@ fn test_check_withdraw_limits_above_optimal_utilization() { assert_eq!(valid_withdraw, true); // now ensure it fails due to higher min_dep above - sol_spot_market.deposit_balance = min_dep / 1020 * 1000; + sol_spot_market.set_deposit_balance(min_dep / 1020 * 1000); let valid_withdraw = check_withdraw_limits(&sol_spot_market, None, None).unwrap(); assert_eq!(valid_withdraw, false); } @@ -735,19 +735,19 @@ fn check_fee_collection() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -765,13 +765,13 @@ fn check_fee_collection() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 / 2, @@ -787,15 +787,15 @@ fn check_fee_collection() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, insurance_fund: InsuranceFund { revenue_settle_period: 1, @@ -827,8 +827,8 @@ fn check_fee_collection() { spot_market.insurance_fund.total_factor = 1000; //1_000_000 assert_eq!(spot_market.utilization_twap, 0); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.deposit_balance(), 1000000000); + assert_eq!(spot_market.borrow_balance(), 0); let amount = QUOTE_PRECISION / 4; update_spot_balances_and_cumulative_deposits_with_limits( @@ -842,33 +842,33 @@ fn check_fee_collection() { assert_eq!(user.total_deposits, 0); assert_eq!(user.total_withdraws, 0); - assert_eq!(spot_market.deposit_balance, 1000000000); - assert_eq!(spot_market.borrow_balance, 125000001); + assert_eq!(spot_market.deposit_balance(), 1000000000); + assert_eq!(spot_market.borrow_balance(), 125000001); assert_eq!(spot_market.utilization_twap, 0); update_spot_market_cumulative_interest(&mut spot_market, None, now + 100).unwrap(); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); - assert_eq!(spot_market.cumulative_deposit_interest, 10000019799); - assert_eq!(spot_market.cumulative_borrow_interest, 10000158551); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); + assert_eq!(spot_market.cumulative_deposit_interest(), 10000019799); + assert_eq!(spot_market.cumulative_borrow_interest(), 10000158551); assert_eq!(spot_market.last_interest_ts, 100); assert_eq!(spot_market.last_twap_ts, 100); assert_eq!(spot_market.utilization_twap, 143); let deposit_tokens_1 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_1 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Borrow, ) @@ -884,24 +884,24 @@ fn check_fee_collection() { assert_eq!(spot_market.last_twap_ts, 7500); assert_eq!(spot_market.utilization_twap, 10846); - assert_eq!(spot_market.cumulative_deposit_interest, 10001484937); - assert_eq!(spot_market.cumulative_borrow_interest, 10011891454); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!(spot_market.cumulative_deposit_interest(), 10001484937); + assert_eq!(spot_market.cumulative_borrow_interest(), 10011891454); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); let deposit_tokens_2 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_2 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_2 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Borrow, ) @@ -926,24 +926,24 @@ fn check_fee_collection() { now = now + 750 + (60 * 60 * 24 * 365); - assert_eq!(spot_market.cumulative_deposit_interest, 16257818378); - assert_eq!(spot_market.cumulative_borrow_interest, 60112684636); - assert_eq!(spot_market.revenue_pool.scaled_balance, 385045); + assert_eq!(spot_market.cumulative_deposit_interest(), 16257818378); + assert_eq!(spot_market.cumulative_borrow_interest(), 60112684636); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 385045); let deposit_tokens_3 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_3 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_3 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Borrow, ) @@ -964,7 +964,7 @@ fn check_fee_collection() { ); // settle IF pool to 100% utilization boundary - assert_eq!(spot_market.revenue_pool.scaled_balance, 385045); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 385045); assert_eq!(spot_market.utilization_twap, 462004); spot_market.insurance_fund.revenue_settle_period = 1; @@ -978,26 +978,26 @@ fn check_fee_collection() { .unwrap(); assert_eq!(settle_amount, 626); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); assert_eq!(if_tokens_3 - (settle_amount as u128), 1689); - assert_eq!(spot_market.revenue_pool.scaled_balance, 0); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 0); assert_eq!(spot_market.utilization_twap, 462005); let deposit_tokens_4 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_4 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_4 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1026,19 +1026,19 @@ fn check_fee_collection() { .unwrap(); let deposit_tokens_5 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_5 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let _if_tokens_5 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1070,13 +1070,13 @@ fn check_fee_collection() { .unwrap(); let deposit_tokens_6 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_6 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) @@ -1108,19 +1108,19 @@ fn check_fee_collection_larger_nums() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -1138,13 +1138,13 @@ fn check_fee_collection_larger_nums() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000000 * SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: (1000000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 / 2, @@ -1158,15 +1158,15 @@ fn check_fee_collection_larger_nums() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: SPOT_BALANCE_PRECISION.into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, ..SpotMarket::default() }; @@ -1194,10 +1194,10 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.utilization_twap, 0); assert_eq!( - spot_market.deposit_balance, + spot_market.deposit_balance(), 1000000 * SPOT_BALANCE_PRECISION ); - assert_eq!(spot_market.borrow_balance, 0); + assert_eq!(spot_market.borrow_balance(), 0); let amount = 540510 * QUOTE_PRECISION; update_spot_balances( @@ -1210,37 +1210,37 @@ fn check_fee_collection_larger_nums() { .unwrap(); assert_eq!( - spot_market.deposit_balance, + spot_market.deposit_balance(), 1000000 * SPOT_BALANCE_PRECISION ); - assert_eq!(spot_market.borrow_balance, 540510000000001); + assert_eq!(spot_market.borrow_balance(), 540510000000001); assert_eq!(spot_market.utilization_twap, 0); update_spot_market_cumulative_interest(&mut spot_market, None, now + 100).unwrap(); let br = calculate_borrow_rate(&spot_market, spot_market.get_utilization().unwrap()).unwrap(); assert_eq!(br, 20173678); - assert_eq!(spot_market.revenue_pool.scaled_balance, 3457492406); - assert_eq!(spot_market.cumulative_deposit_interest, 10000311188); - assert_eq!(spot_market.cumulative_borrow_interest, 10000639702); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 3457492406); + assert_eq!(spot_market.cumulative_deposit_interest(), 10000311188); + assert_eq!(spot_market.cumulative_borrow_interest(), 10000639702); assert_eq!(spot_market.last_interest_ts, 100); assert_eq!(spot_market.last_twap_ts, 100); assert_eq!(spot_market.utilization_twap, 624); let deposit_tokens_1 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_1 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_1 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1256,24 +1256,24 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.last_twap_ts, 7500); assert_eq!(spot_market.utilization_twap, 46964); - assert_eq!(spot_market.cumulative_deposit_interest, 10023340555); - assert_eq!(spot_market.cumulative_borrow_interest, 10047980763); - assert_eq!(spot_market.revenue_pool.scaled_balance, 258744322775); + assert_eq!(spot_market.cumulative_deposit_interest(), 10023340555); + assert_eq!(spot_market.cumulative_borrow_interest(), 10047980763); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 258744322775); let deposit_tokens_2 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_2 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_2 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1300,24 +1300,24 @@ fn check_fee_collection_larger_nums() { assert_eq!(spot_market.get_utilization().unwrap(), 961580); - assert_eq!(spot_market.cumulative_deposit_interest, 108608729074); - assert_eq!(spot_market.cumulative_borrow_interest, 212759822472); - assert_eq!(spot_market.revenue_pool.scaled_balance, 101141669831135); + assert_eq!(spot_market.cumulative_deposit_interest(), 108608729074); + assert_eq!(spot_market.cumulative_borrow_interest(), 212759822472); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 101141669831135); let deposit_tokens_3 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_3 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_3 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1340,7 +1340,7 @@ fn check_fee_collection_larger_nums() { // settle IF pool to 100% utilization boundary // only half of depositors available claim was settled (to protect vault) - assert_eq!(spot_market.revenue_pool.scaled_balance, 101141669831135); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 101141669831135); spot_market.insurance_fund.revenue_settle_period = 1; let settle_amount = settle_revenue_to_insurance_fund( deposit_tokens_3 as u64, @@ -1351,29 +1351,29 @@ fn check_fee_collection_larger_nums() { ) .unwrap(); assert_eq!(settle_amount, 229739282275); - assert_eq!(spot_market.insurance_fund.user_shares, 0); - assert_eq!(spot_market.insurance_fund.total_shares, 0); + assert_eq!(spot_market.insurance_fund.user_shares(), 0); + assert_eq!(spot_market.insurance_fund.total_shares(), 0); if_balance_2 += settle_amount; assert_eq!(if_balance_2, 229739282275); assert_eq!(if_tokens_3 - (settle_amount as u128), 868747539403); // w/ update interest for settle_spot_market_to_if - assert_eq!(spot_market.revenue_pool.scaled_balance, 79996002243946); + assert_eq!(spot_market.revenue_pool.scaled_balance(), 79996002243946); assert_eq!(spot_market.utilization_twap, 961580); let deposit_tokens_4 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), &spot_market, &SpotBalanceType::Deposit, ) .unwrap(); let borrow_tokens_4 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), &spot_market, &SpotBalanceType::Borrow, ) .unwrap(); let if_tokens_4 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), &spot_market, &SpotBalanceType::Deposit, ) @@ -1388,13 +1388,13 @@ fn test_multi_stage_borrow_rate_curve() { let spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1_000_000 * SPOT_BALANCE_PRECISION, - borrow_balance: 0, + deposit_balance: (1_000_000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, optimal_utilization: SPOT_UTILIZATION_PRECISION_U32 * 70 / 100, // 70% @@ -1525,15 +1525,15 @@ fn attempt_borrow_with_massive_upnl() { // sol coin let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, - quote_asset_amount: 50 * QUOTE_PRECISION_I128, - base_asset_amount_with_amm: BASE_PRECISION_I128, + quote_asset_amount: (50 * QUOTE_PRECISION_I128).into(), + base_asset_amount_with_amm: BASE_PRECISION_I128.into(), oracle: oracle_price_key, historical_oracle_data: HistoricalOracleData::default_price(oracle_price.agg.price), ..AMM::default() @@ -1553,14 +1553,14 @@ fn attempt_borrow_with_massive_upnl() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1572,15 +1572,15 @@ fn attempt_borrow_with_massive_upnl() { market_index: 1, oracle_source: OracleSource::Pyth, oracle: oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 10, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, - deposit_balance: 100 * SPOT_BALANCE_PRECISION, - borrow_balance: SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: SPOT_BALANCE_PRECISION.into(), liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, status: MarketStatus::Active, @@ -1682,13 +1682,13 @@ fn check_usdc_spot_market_twap() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1827,13 +1827,13 @@ fn check_spot_market_max_borrow_fraction() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1851,7 +1851,7 @@ fn check_spot_market_max_borrow_fraction() { .validate_max_token_deposits_and_borrows(true) .is_ok()); - spot_market.borrow_balance = spot_market.deposit_balance; + spot_market.set_borrow_balance(spot_market.deposit_balance()); assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); @@ -1861,27 +1861,27 @@ fn check_spot_market_max_borrow_fraction() { assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100); assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000 - 2); // just above 10000th + spot_market.set_borrow_balance(spot_market.deposit_balance() / (10000 - 2)); // just above 10000th assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_err()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000); // exactly 10000th of deposit + spot_market.set_borrow_balance(spot_market.deposit_balance() / (10000)); // exactly 10000th of deposit assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); - spot_market.borrow_balance = spot_market.deposit_balance / (10000 + 1); // < 10000th of deposit + spot_market.set_borrow_balance(spot_market.deposit_balance() / (10000 + 1)); // < 10000th of deposit assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); - spot_market.borrow_balance = spot_market.deposit_balance / 100000; // 1/10th of 10000 + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100000); // 1/10th of 10000 assert!(spot_market .validate_max_token_deposits_and_borrows(true) .is_ok()); @@ -1896,13 +1896,13 @@ fn check_spot_market_min_borrow_rate() { let mut spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 100_000_000 * SPOT_BALANCE_PRECISION, //$100M usdc - borrow_balance: 0, + deposit_balance: (100_000_000 * SPOT_BALANCE_PRECISION).into(), //$100M usdc + borrow_balance: 0.into(), deposit_token_twap: QUOTE_PRECISION_U64 / 2, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), status: MarketStatus::Active, @@ -1928,28 +1928,28 @@ fn check_spot_market_min_borrow_rate() { assert_eq!(accum_interest.deposit_interest, 0); spot_market.min_borrow_rate = 1; // .5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100); let accum_interest = calculate_accumulated_interest(&spot_market, now + 10000).unwrap(); assert_eq!(accum_interest.borrow_interest, 15903); assert_eq!(accum_interest.deposit_interest, 159); spot_market.min_borrow_rate = 10; // 5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100); let accum_interest = calculate_accumulated_interest(&spot_market, now + 10000).unwrap(); assert_eq!(accum_interest.borrow_interest, 159025); assert_eq!(accum_interest.deposit_interest, 1590); spot_market.min_borrow_rate = 10; // 5% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100); let accum_interest = calculate_accumulated_interest(&spot_market, now + 1000000).unwrap(); assert_eq!(accum_interest.borrow_interest, 15855372); assert_eq!(accum_interest.deposit_interest, 158553); spot_market.min_borrow_rate = 200; // 100% - spot_market.borrow_balance = spot_market.deposit_balance / 100; + spot_market.set_borrow_balance(spot_market.deposit_balance() / 100); let accum_interest = calculate_accumulated_interest(&spot_market, now + 1000000).unwrap(); assert_eq!(accum_interest.borrow_interest, 317107433); diff --git a/programs/drift/src/controller/spot_position/tests.rs b/programs/drift/src/controller/spot_position/tests.rs index 9618d09969..fc2d3002a7 100644 --- a/programs/drift/src/controller/spot_position/tests.rs +++ b/programs/drift/src/controller/spot_position/tests.rs @@ -31,7 +31,7 @@ mod update_spot_position_balance { fn borrow() { let mut user = User::default(); let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -55,7 +55,7 @@ mod update_spot_position_balance { let mut user2 = User::default(); let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; @@ -111,12 +111,12 @@ mod update_spot_position_balance { }; let mut spot_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_quote_market() }; let mut sol_market = SpotMarket { - deposit_balance: 101 * SPOT_BALANCE_PRECISION, + deposit_balance: (101 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default_base_market() }; diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index 3feeabb796..5a339645af 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -1,5 +1,10 @@ use crate::{msg, FeatureBitFlags}; use anchor_lang::prelude::*; +use anchor_spl::token_2022::spl_token_2022::extension::transfer_hook::TransferHook; +use anchor_spl::token_2022::spl_token_2022::extension::{ + BaseStateWithExtensions, StateWithExtensions, +}; +use anchor_spl::token_2022::spl_token_2022::state::Mint as MintInner; use anchor_spl::token_2022::Token2022; use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface}; use phoenix::quantities::WrapperU64; @@ -85,12 +90,6 @@ use crate::validation::spot_market::validate_borrow_rate; use crate::{load_mut, PTYH_PRICE_FEED_SEED_PREFIX}; use crate::{math, safe_decrement, safe_increment}; -use anchor_spl::token_2022::spl_token_2022::extension::transfer_hook::TransferHook; -use anchor_spl::token_2022::spl_token_2022::extension::{ - BaseStateWithExtensions, StateWithExtensions, -}; -use anchor_spl::token_2022::spl_token_2022::state::Mint as MintInner; - pub fn handle_initialize(ctx: Context) -> Result<()> { let (drift_signer, drift_signer_nonce) = Pubkey::find_program_address(&[b"drift_signer".as_ref()], ctx.program_id); @@ -303,7 +302,7 @@ pub fn handle_initialize_spot_market( mint: ctx.accounts.spot_market_mint.key(), vault: ctx.accounts.spot_market_vault.key(), revenue_pool: PoolBalance { - scaled_balance: 0, + scaled_balance: 0.into(), market_index: spot_market_index, ..PoolBalance::default() }, // in base asset @@ -311,16 +310,16 @@ pub fn handle_initialize_spot_market( optimal_utilization, optimal_borrow_rate, max_borrow_rate, - deposit_balance: 0, - borrow_balance: 0, + deposit_balance: 0.into(), + borrow_balance: 0.into(), max_token_deposits: 0, deposit_token_twap: 0, borrow_token_twap: 0, utilization_twap: 0, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - total_social_loss: 0, - total_quote_social_loss: 0, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + total_social_loss: 0.into(), + total_quote_social_loss: 0.into(), last_interest_ts: now, last_twap_ts: now, initial_asset_weight, @@ -338,7 +337,7 @@ pub fn handle_initialize_spot_market( next_fill_record_id: 1, next_deposit_record_id: 1, spot_fee_pool: PoolBalance::default(), // in quote asset - total_spot_fee: 0, + total_spot_fee: 0.into(), orders_enabled: spot_market_index != 0, paused_operations: 0, if_paused_operations: 0, @@ -997,16 +996,16 @@ pub fn handle_initialize_perp_market( amm: AMM { oracle: *ctx.accounts.oracle.key, oracle_source, - base_asset_reserve: amm_base_asset_reserve, - quote_asset_reserve: amm_quote_asset_reserve, - terminal_quote_asset_reserve: amm_quote_asset_reserve, - ask_base_asset_reserve: amm_base_asset_reserve, - ask_quote_asset_reserve: amm_quote_asset_reserve, - bid_base_asset_reserve: amm_base_asset_reserve, - bid_quote_asset_reserve: amm_quote_asset_reserve, - cumulative_funding_rate_long: 0, - cumulative_funding_rate_short: 0, - total_social_loss: 0, + base_asset_reserve: amm_base_asset_reserve.into(), + quote_asset_reserve: amm_quote_asset_reserve.into(), + terminal_quote_asset_reserve: amm_quote_asset_reserve.into(), + ask_base_asset_reserve: amm_base_asset_reserve.into(), + ask_quote_asset_reserve: amm_quote_asset_reserve.into(), + bid_base_asset_reserve: amm_base_asset_reserve.into(), + bid_quote_asset_reserve: amm_quote_asset_reserve.into(), + cumulative_funding_rate_long: 0.into(), + cumulative_funding_rate_short: 0.into(), + total_social_loss: 0.into(), last_funding_rate: 0, last_funding_rate_long: 0, last_funding_rate_short: 0, @@ -1016,17 +1015,17 @@ pub fn handle_initialize_perp_market( last_mark_price_twap: init_reserve_price, last_mark_price_twap_5min: init_reserve_price, last_mark_price_twap_ts: now, - sqrt_k: amm_base_asset_reserve, - concentration_coef, - min_base_asset_reserve, - max_base_asset_reserve, - peg_multiplier: amm_peg_multiplier, - total_fee: 0, - total_fee_withdrawn: 0, - total_fee_minus_distributions: 0, - total_mm_fee: 0, - total_exchange_fee: 0, - total_liquidation_fee: 0, + sqrt_k: amm_base_asset_reserve.into(), + concentration_coef: concentration_coef.into(), + min_base_asset_reserve: min_base_asset_reserve.into(), + max_base_asset_reserve: max_base_asset_reserve.into(), + peg_multiplier: amm_peg_multiplier.into(), + total_fee: 0.into(), + total_fee_withdrawn: 0.into(), + total_fee_minus_distributions: 0.into(), + total_mm_fee: 0.into(), + total_exchange_fee: 0.into(), + total_liquidation_fee: 0.into(), net_revenue_since_last_funding: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price: oracle_price, @@ -1051,15 +1050,15 @@ pub fn handle_initialize_perp_market( max_spread, last_bid_price_twap: init_reserve_price, last_ask_price_twap: init_reserve_price, - base_asset_amount_with_amm: 0, - base_asset_amount_long: 0, - base_asset_amount_short: 0, - quote_asset_amount: 0, - quote_entry_amount_long: 0, - quote_entry_amount_short: 0, - quote_break_even_amount_long: 0, - quote_break_even_amount_short: 0, - max_open_interest, + base_asset_amount_with_amm: 0.into(), + base_asset_amount_long: 0.into(), + base_asset_amount_short: 0.into(), + quote_asset_amount: 0.into(), + quote_entry_amount_long: 0.into(), + quote_entry_amount_short: 0.into(), + quote_break_even_amount_long: 0.into(), + quote_break_even_amount_short: 0.into(), + max_open_interest: max_open_interest.into(), mark_std: 0, oracle_std: 0, volume_24h: 0, @@ -1069,13 +1068,13 @@ pub fn handle_initialize_perp_market( last_trade_ts: now, curve_update_intensity, fee_pool: PoolBalance::default(), - base_asset_amount_per_lp: 0, - quote_asset_amount_per_lp: 0, + base_asset_amount_per_lp: 0.into(), + quote_asset_amount_per_lp: 0.into(), last_update_slot: clock_slot, // lp stuff - base_asset_amount_with_unsettled_lp: 0, - user_lp_shares: 0, + base_asset_amount_with_unsettled_lp: 0.into(), + user_lp_shares: 0.into(), amm_jit_intensity, last_oracle_valid: false, @@ -1240,16 +1239,16 @@ pub fn handle_delete_initialized_spot_market( "spot_market.status != Initialized", )?; validate!( - spot_market.deposit_balance == 0, + spot_market.deposit_balance() == 0, ErrorCode::InvalidMarketAccountforDeletion, "spot_market.number_of_users={} != 0", - spot_market.deposit_balance, + spot_market.deposit_balance(), )?; validate!( - spot_market.borrow_balance == 0, + spot_market.borrow_balance() == 0, ErrorCode::InvalidMarketAccountforDeletion, "spot_market.borrow_balance={} != 0", - spot_market.borrow_balance, + spot_market.borrow_balance(), )?; validate!( spot_market.market_index == market_index, @@ -1547,20 +1546,20 @@ pub fn handle_move_amm_price( perp_market.market_index ); - let base_asset_reserve_before = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve; - let sqrt_k_before = perp_market.amm.sqrt_k; - let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_before = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve(); + let sqrt_k_before = perp_market.amm.sqrt_k(); + let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve(); controller::amm::move_price(perp_market, base_asset_reserve, quote_asset_reserve, sqrt_k)?; validate_perp_market(perp_market)?; - let base_asset_reserve_after = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve; - let sqrt_k_after = perp_market.amm.sqrt_k; - let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_after = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve(); + let sqrt_k_after = perp_market.amm.sqrt_k(); + let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve(); msg!( "base_asset_reserve {} -> {}", @@ -1606,22 +1605,22 @@ pub fn handle_recenter_perp_market_amm( perp_market.market_index ); - let base_asset_reserve_before = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve; - let sqrt_k_before = perp_market.amm.sqrt_k; - let peg_multiplier_before = perp_market.amm.peg_multiplier; - let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_before = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve(); + let sqrt_k_before = perp_market.amm.sqrt_k(); + let peg_multiplier_before = perp_market.amm.peg_multiplier(); + let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve(); controller::amm::recenter_perp_market_amm(perp_market, peg_multiplier, sqrt_k)?; validate_perp_market(perp_market)?; - let base_asset_reserve_after = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve; - let sqrt_k_after = perp_market.amm.sqrt_k; - let peg_multiplier_after = perp_market.amm.peg_multiplier; - let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_after = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve(); + let sqrt_k_after = perp_market.amm.sqrt_k(); + let peg_multiplier_after = perp_market.amm.peg_multiplier(); + let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve(); msg!( "base_asset_reserve {} -> {}", @@ -1680,12 +1679,12 @@ pub fn handle_recenter_perp_market_amm_crank( perp_market.market_index ); - let base_asset_reserve_before = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve; - let sqrt_k_before = perp_market.amm.sqrt_k; - let peg_multiplier_before = perp_market.amm.peg_multiplier; - let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_before = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve(); + let sqrt_k_before = perp_market.amm.sqrt_k(); + let peg_multiplier_before = perp_market.amm.peg_multiplier(); + let max_base_asset_reserve_before = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_before = perp_market.amm.min_base_asset_reserve(); let mut sqrt_k = sqrt_k_before; let peg_multiplier: u128 = oracle_price.cast()?; @@ -1706,12 +1705,12 @@ pub fn handle_recenter_perp_market_amm_crank( controller::amm::recenter_perp_market_amm(perp_market, peg_multiplier, sqrt_k)?; validate_perp_market(perp_market)?; - let base_asset_reserve_after = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve; - let sqrt_k_after = perp_market.amm.sqrt_k; - let peg_multiplier_after = perp_market.amm.peg_multiplier; - let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve; - let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve; + let base_asset_reserve_after = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve(); + let sqrt_k_after = perp_market.amm.sqrt_k(); + let peg_multiplier_after = perp_market.amm.peg_multiplier(); + let max_base_asset_reserve_after = perp_market.amm.max_base_asset_reserve(); + let min_base_asset_reserve_after = perp_market.amm.min_base_asset_reserve(); msg!( "base_asset_reserve {} -> {}", @@ -1826,28 +1825,39 @@ pub fn handle_update_perp_market_amm_summary_stats( msg!( "total_fee_minus_distributions: {:?} -> {:?}", - perp_market.amm.total_fee_minus_distributions, + perp_market.amm.total_fee_minus_distributions(), new_total_fee_minus_distributions, ); let fee_difference = new_total_fee_minus_distributions - .safe_sub(perp_market.amm.total_fee_minus_distributions)?; + .safe_sub(perp_market.amm.total_fee_minus_distributions())?; msg!( "perp_market.amm.total_fee: {} -> {}", - perp_market.amm.total_fee, - perp_market.amm.total_fee.saturating_add(fee_difference) + perp_market.amm.total_fee(), + perp_market.amm.total_fee().saturating_add(fee_difference) ); msg!( "perp_market.amm.total_mm_fee: {} -> {}", - perp_market.amm.total_mm_fee, - perp_market.amm.total_mm_fee.saturating_add(fee_difference) + perp_market.amm.total_mm_fee(), + perp_market + .amm + .total_mm_fee() + .saturating_add(fee_difference) ); - perp_market.amm.total_fee = perp_market.amm.total_fee.saturating_add(fee_difference); - perp_market.amm.total_mm_fee = perp_market.amm.total_mm_fee.saturating_add(fee_difference); - perp_market.amm.total_fee_minus_distributions = new_total_fee_minus_distributions; + let total_fee = perp_market.amm.total_fee(); + perp_market + .amm + .set_total_fee(total_fee.saturating_add(fee_difference)); + let total_mm_fee = perp_market.amm.total_mm_fee(); + perp_market + .amm + .set_total_mm_fee(total_mm_fee.saturating_add(fee_difference)); + perp_market + .amm + .set_total_fee_minus_distributions(new_total_fee_minus_distributions); } validate_perp_market(perp_market)?; @@ -1893,13 +1903,13 @@ pub fn handle_settle_expired_market_pools_to_revenue_pool( )?; validate!( - perp_market.amm.base_asset_amount_long == 0 - && perp_market.amm.base_asset_amount_short == 0 + perp_market.amm.base_asset_amount_long() == 0 + && perp_market.amm.base_asset_amount_short() == 0 && perp_market.number_of_users_with_base == 0, ErrorCode::DefaultError, "outstanding base_asset_amounts must be balanced {} {} {}", - perp_market.amm.base_asset_amount_long, - perp_market.amm.base_asset_amount_short, + perp_market.amm.base_asset_amount_long(), + perp_market.amm.base_asset_amount_short(), perp_market.number_of_users_with_base )?; @@ -1936,12 +1946,12 @@ pub fn handle_settle_expired_market_pools_to_revenue_pool( )?; let fee_pool_token_amount = get_token_amount( - perp_market.amm.fee_pool.scaled_balance, + perp_market.amm.fee_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )?; let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )?; @@ -1996,17 +2006,17 @@ pub fn handle_deposit_into_perp_market_fee_pool<'c: 'info, 'info>( msg!( "perp_market.amm.total_fee_minus_distributions: {:?} -> {:?}", - perp_market.amm.total_fee_minus_distributions, + perp_market.amm.total_fee_minus_distributions(), perp_market .amm - .total_fee_minus_distributions + .total_fee_minus_distributions() .safe_add(amount.cast()?)?, ); - perp_market.amm.total_fee_minus_distributions = perp_market + let total_fee_minus_distributions = perp_market.amm.total_fee_minus_distributions(); + perp_market .amm - .total_fee_minus_distributions - .safe_add(amount.cast()?)?; + .set_total_fee_minus_distributions(total_fee_minus_distributions.safe_add(amount.cast()?)?); let quote_spot_market = &mut load_mut!(ctx.accounts.quote_spot_market)?; @@ -2111,11 +2121,11 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( let token_precision = spot_market.get_precision(); - let cumulative_deposit_interest_before = spot_market.cumulative_deposit_interest; + let cumulative_deposit_interest_before = spot_market.cumulative_deposit_interest(); let cumulative_deposit_interest_after = deposit_token_amount_after .safe_mul(SPOT_CUMULATIVE_INTEREST_PRECISION)? - .safe_div(spot_market.deposit_balance)? + .safe_div(spot_market.deposit_balance())? .safe_mul(SPOT_BALANCE_PRECISION)? .safe_div(token_precision.cast()?)?; @@ -2127,7 +2137,7 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( cumulative_deposit_interest_before )?; - spot_market.cumulative_deposit_interest = cumulative_deposit_interest_after; + spot_market.set_cumulative_deposit_interest(cumulative_deposit_interest_after); controller::token::receive( &ctx.accounts.token_program, @@ -2151,7 +2161,7 @@ pub fn handle_deposit_into_spot_market_vault<'c: 'info, 'info>( emit!(SpotMarketVaultDepositRecord { ts: Clock::get()?.unix_timestamp, market_index: spot_market.market_index, - deposit_balance: spot_market.deposit_balance, + deposit_balance: spot_market.deposit_balance(), cumulative_deposit_interest_before, cumulative_deposit_interest_after, deposit_token_amount_before: deposit_token_amount_before.cast()?, @@ -2182,10 +2192,10 @@ pub fn handle_repeg_amm_curve(ctx: Context, new_peg_candidate: u128) .. } = get_oracle_price(&perp_market.amm.oracle_source, price_oracle, clock.slot)?; - let peg_multiplier_before = perp_market.amm.peg_multiplier; - let base_asset_reserve_before = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve; - let sqrt_k_before = perp_market.amm.sqrt_k; + let peg_multiplier_before = perp_market.amm.peg_multiplier(); + let base_asset_reserve_before = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve(); + let sqrt_k_before = perp_market.amm.sqrt_k(); let oracle_validity_rails = &ctx.accounts.state.oracle_guard_rails; @@ -2197,10 +2207,10 @@ pub fn handle_repeg_amm_curve(ctx: Context, new_peg_candidate: u128) oracle_validity_rails, )?; - let peg_multiplier_after = perp_market.amm.peg_multiplier; - let base_asset_reserve_after = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve; - let sqrt_k_after = perp_market.amm.sqrt_k; + let peg_multiplier_after = perp_market.amm.peg_multiplier(); + let base_asset_reserve_after = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_after = perp_market.amm.quote_asset_reserve(); + let sqrt_k_after = perp_market.amm.sqrt_k(); msg!( "perp_market.amm.peg_multiplier {} -> {}", @@ -2238,12 +2248,12 @@ pub fn handle_repeg_amm_curve(ctx: Context, new_peg_candidate: u128) base_asset_reserve_after, quote_asset_reserve_after, sqrt_k_after, - base_asset_amount_long: perp_market.amm.base_asset_amount_long.unsigned_abs(), - base_asset_amount_short: perp_market.amm.base_asset_amount_short.unsigned_abs(), - base_asset_amount_with_amm: perp_market.amm.base_asset_amount_with_amm, + base_asset_amount_long: perp_market.amm.base_asset_amount_long().unsigned_abs(), + base_asset_amount_short: perp_market.amm.base_asset_amount_short().unsigned_abs(), + base_asset_amount_with_amm: perp_market.amm.base_asset_amount_with_amm(), number_of_users: perp_market.number_of_users, - total_fee: perp_market.amm.total_fee, - total_fee_minus_distributions: perp_market.amm.total_fee_minus_distributions, + total_fee: perp_market.amm.total_fee(), + total_fee_minus_distributions: perp_market.amm.total_fee_minus_distributions(), adjustment_cost, oracle_price, fill_record: 0, @@ -2362,23 +2372,23 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { let perp_market = &mut load_mut!(ctx.accounts.perp_market)?; msg!("updating k for perp market {}", perp_market.market_index); - let base_asset_amount_long = perp_market.amm.base_asset_amount_long.unsigned_abs(); - let base_asset_amount_short = perp_market.amm.base_asset_amount_short.unsigned_abs(); - let base_asset_amount_with_amm = perp_market.amm.base_asset_amount_with_amm; + let base_asset_amount_long = perp_market.amm.base_asset_amount_long().unsigned_abs(); + let base_asset_amount_short = perp_market.amm.base_asset_amount_short().unsigned_abs(); + let base_asset_amount_with_amm = perp_market.amm.base_asset_amount_with_amm(); let number_of_users = perp_market.number_of_users_with_base; let price_before = math::amm::calculate_price( - perp_market.amm.quote_asset_reserve, - perp_market.amm.base_asset_reserve, - perp_market.amm.peg_multiplier, + perp_market.amm.quote_asset_reserve(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.peg_multiplier(), )?; - let peg_multiplier_before = perp_market.amm.peg_multiplier; - let base_asset_reserve_before = perp_market.amm.base_asset_reserve; - let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve; - let sqrt_k_before = perp_market.amm.sqrt_k; + let peg_multiplier_before = perp_market.amm.peg_multiplier(); + let base_asset_reserve_before = perp_market.amm.base_asset_reserve(); + let quote_asset_reserve_before = perp_market.amm.quote_asset_reserve(); + let sqrt_k_before = perp_market.amm.sqrt_k(); - let k_increasing = sqrt_k > perp_market.amm.sqrt_k; + let k_increasing = sqrt_k > perp_market.amm.sqrt_k(); let new_sqrt_k_u192 = bn::U192::from(sqrt_k); @@ -2405,9 +2415,9 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { if adjustment_cost > 0 { let max_cost = perp_market .amm - .total_fee_minus_distributions + .total_fee_minus_distributions() .safe_sub(get_total_fee_lower_bound(perp_market)?.cast()?)? - .safe_sub(perp_market.amm.total_fee_withdrawn.cast()?)?; + .safe_sub(perp_market.amm.total_fee_withdrawn().cast()?)?; validate!( adjustment_cost <= max_cost, @@ -2419,16 +2429,16 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { } validate!( - !k_increasing || perp_market.amm.sqrt_k < MAX_SQRT_K, + !k_increasing || perp_market.amm.sqrt_k() < MAX_SQRT_K, ErrorCode::InvalidUpdateK, "cannot increase sqrt_k={} past MAX_SQRT_K", - perp_market.amm.sqrt_k + perp_market.amm.sqrt_k() )?; - perp_market.amm.total_fee_minus_distributions = perp_market - .amm - .total_fee_minus_distributions - .safe_sub(adjustment_cost)?; + let total_fee_minus_distributions = perp_market.amm.total_fee_minus_distributions(); + perp_market.amm.set_total_fee_minus_distributions( + total_fee_minus_distributions.safe_sub(adjustment_cost)?, + ); perp_market.amm.net_revenue_since_last_funding = perp_market .amm @@ -2438,9 +2448,9 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { let amm = &perp_market.amm; let price_after = math::amm::calculate_price( - amm.quote_asset_reserve, - amm.base_asset_reserve, - amm.peg_multiplier, + amm.quote_asset_reserve(), + amm.base_asset_reserve(), + amm.peg_multiplier(), )?; let price_change_too_large = price_before @@ -2459,24 +2469,29 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { return Err(ErrorCode::InvalidUpdateK.into()); } - let k_sqrt_check = bn::U192::from(amm.base_asset_reserve) - .safe_mul(bn::U192::from(amm.quote_asset_reserve))? + let k_sqrt_check = bn::U192::from(amm.base_asset_reserve()) + .safe_mul(bn::U192::from(amm.quote_asset_reserve()))? .integer_sqrt() .try_to_u128()?; let k_err = k_sqrt_check .cast::()? - .safe_sub(amm.sqrt_k.cast::()?)?; + .safe_sub(amm.sqrt_k().cast::()?)?; if k_err.unsigned_abs() > 100 { - msg!("k_err={:?}, {:?} != {:?}", k_err, k_sqrt_check, amm.sqrt_k); + msg!( + "k_err={:?}, {:?} != {:?}", + k_err, + k_sqrt_check, + amm.sqrt_k() + ); return Err(ErrorCode::InvalidUpdateK.into()); } - let peg_multiplier_after = amm.peg_multiplier; - let base_asset_reserve_after = amm.base_asset_reserve; - let quote_asset_reserve_after = amm.quote_asset_reserve; - let sqrt_k_after = amm.sqrt_k; + let peg_multiplier_after = amm.peg_multiplier(); + let base_asset_reserve_after = amm.base_asset_reserve(); + let quote_asset_reserve_after = amm.quote_asset_reserve(); + let sqrt_k_after = amm.sqrt_k(); msg!( "perp_market.amm.peg_multiplier {} -> {}", @@ -2502,8 +2517,8 @@ pub fn handle_update_k(ctx: Context, sqrt_k: u128) -> Result<()> { sqrt_k_after ); - let total_fee = amm.total_fee; - let total_fee_minus_distributions = amm.total_fee_minus_distributions; + let total_fee = amm.total_fee(); + let total_fee_minus_distributions = amm.total_fee_minus_distributions(); let OraclePriceData { price: oracle_price, @@ -3487,9 +3502,9 @@ pub fn handle_update_perp_market_concentration_coef( let perp_market = &mut load_mut!(ctx.accounts.perp_market)?; msg!("perp market {}", perp_market.market_index); - let prev_concentration_coef = perp_market.amm.concentration_coef; + let prev_concentration_coef = perp_market.amm.concentration_coef(); controller::amm::update_concentration_coef(perp_market, concentration_scale)?; - let new_concentration_coef = perp_market.amm.concentration_coef; + let new_concentration_coef = perp_market.amm.concentration_coef(); msg!( "perp_market.amm.concentration_coef: {} -> {}", @@ -3550,10 +3565,10 @@ pub fn handle_update_perp_market_reference_price_offset_deadband_pct( let liquidity_ratio = crate::math::amm_spread::calculate_inventory_liquidity_ratio_for_reference_price_offset( - perp_market.amm.base_asset_amount_with_amm, - perp_market.amm.base_asset_reserve, - perp_market.amm.min_base_asset_reserve, - perp_market.amm.max_base_asset_reserve, + perp_market.amm.base_asset_amount_with_amm(), + perp_market.amm.base_asset_reserve(), + perp_market.amm.min_base_asset_reserve(), + perp_market.amm.max_base_asset_reserve(), )?; let signed_liquidity_ratio = liquidity_ratio.safe_mul( @@ -4069,11 +4084,11 @@ pub fn handle_update_perp_market_max_open_interest( msg!( "perp_market.amm.max_open_interest: {:?} -> {:?}", - perp_market.amm.max_open_interest, + perp_market.amm.max_open_interest(), max_open_interest ); - perp_market.amm.max_open_interest = max_open_interest; + perp_market.amm.set_max_open_interest(max_open_interest); Ok(()) } @@ -4540,10 +4555,10 @@ pub fn handle_update_protocol_if_shares_transfer_config( if let Some(max_transfer_per_epoch) = max_transfer_per_epoch { msg!( "max_transfer_per_epoch: {:?} -> {:?}", - config.max_transfer_per_epoch, + config.max_transfer_per_epoch(), max_transfer_per_epoch ); - config.max_transfer_per_epoch = max_transfer_per_epoch; + config.set_max_transfer_per_epoch(max_transfer_per_epoch); } else { msg!("max_transfer_per_epoch: unchanged"); } @@ -4908,10 +4923,10 @@ pub fn handle_admin_deposit<'c: 'info, 'info>( direction: DepositDirection::Deposit, amount, oracle_price, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance(), + market_withdraw_balance: spot_market.borrow_balance(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), total_deposits_after, total_withdraws_after, market_index, @@ -5478,7 +5493,7 @@ pub struct InitializeAmmCache<'info> { pub state: Box>, #[account( init, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], space = AmmCache::init_space(), bump, payer = admin @@ -5498,7 +5513,7 @@ pub struct AddMarketToAmmCache<'info> { pub state: Box>, #[account( mut, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump, realloc = AmmCache::space(amm_cache.cache.len() + 1), realloc::payer = admin, @@ -5520,7 +5535,7 @@ pub struct DeleteAmmCache<'info> { pub state: Box>, #[account( mut, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump, close = admin, )] @@ -5775,7 +5790,7 @@ pub struct AdminUpdatePerpMarketOracle<'info> { pub old_oracle: AccountInfo<'info>, #[account( mut, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump = amm_cache.bump, )] pub amm_cache: Box>, diff --git a/programs/drift/src/instructions/if_staker.rs b/programs/drift/src/instructions/if_staker.rs index 3e2381eb5f..c1dae6da3b 100644 --- a/programs/drift/src/instructions/if_staker.rs +++ b/programs/drift/src/instructions/if_staker.rs @@ -1,5 +1,4 @@ use anchor_lang::prelude::*; -use anchor_lang::Discriminator; use anchor_spl::token_interface::{TokenAccount, TokenInterface}; use crate::error::ErrorCode; @@ -95,7 +94,7 @@ pub fn handle_add_insurance_fund_stake<'c: 'info, 'info>( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0 + insurance_fund_stake.last_withdraw_request_shares() == 0 && insurance_fund_stake.last_withdraw_request_value == 0, ErrorCode::IFWithdrawRequestInProgress, "withdraw request in progress" @@ -187,14 +186,14 @@ pub fn handle_request_remove_insurance_fund_stake( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0, + insurance_fund_stake.last_withdraw_request_shares() == 0, ErrorCode::IFWithdrawRequestInProgress, "Withdraw request is already in progress" )?; let n_shares = math::insurance::vault_amount_to_if_shares( amount, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), ctx.accounts.insurance_fund_vault.amount, )?; @@ -236,7 +235,7 @@ pub fn handle_cancel_request_remove_insurance_fund_stake( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares != 0, + insurance_fund_stake.last_withdraw_request_shares() != 0, ErrorCode::NoIFWithdrawRequestInProgress, "No withdraw request in progress" )?; @@ -343,7 +342,8 @@ pub fn handle_transfer_protocol_if_shares( transfer_config.update_epoch(now)?; transfer_config.validate_transfer(shares)?; - transfer_config.current_epoch_transfer += shares; + let current_epoch_transfer = transfer_config.current_epoch_transfer(); + transfer_config.set_current_epoch_transfer(current_epoch_transfer.safe_add(shares)?); let mut if_stake = ctx.accounts.insurance_fund_stake.load_mut()?; let mut user_stats = ctx.accounts.user_stats.load_mut()?; @@ -504,9 +504,9 @@ pub fn handle_begin_insurance_fund_swap<'c: 'info, 'info>( found_end = true; // must be the SwapEnd instruction - let discriminator = crate::instruction::EndInsuranceFundSwap::discriminator(); + let discriminator = crate::instruction::EndInsuranceFundSwap::DISCRIMINATOR; validate!( - ix.data[0..8] == discriminator, + &ix.data[0..8] == discriminator, ErrorCode::InvalidSwap, "last drift ix must be end of swap" )?; @@ -862,7 +862,7 @@ pub fn handle_deposit_into_insurance_fund_stake<'c: 'info, 'info>( )?; validate!( - insurance_fund_stake.last_withdraw_request_shares == 0 + insurance_fund_stake.last_withdraw_request_shares() == 0 && insurance_fund_stake.last_withdraw_request_value == 0, ErrorCode::IFWithdrawRequestInProgress, "withdraw request in progress" diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index dffdd81d63..975da81613 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -1052,8 +1052,7 @@ pub fn place_signed_msg_taker_order<'c: 'info, 'info>( &mut builder_order, )?; - let order_params_hash = - base64::encode(solana_program::hash::hash(&signature.try_to_vec().unwrap()).as_ref()); + let order_params_hash = base64::encode(solana_program::hash::hash(signature.as_ref()).as_ref()); emit!(SignedMsgOrderRecord { user: taker_key, @@ -1673,9 +1672,9 @@ pub fn handle_liquidate_spot_with_swap_begin<'c: 'info, 'info>( found_end = true; // must be the SwapEnd instruction - let discriminator = crate::instruction::LiquidateSpotWithSwapEnd::discriminator(); + let discriminator = crate::instruction::LiquidateSpotWithSwapEnd::DISCRIMINATOR; validate!( - ix.data[0..8] == discriminator, + &ix.data[0..8] == discriminator, ErrorCode::InvalidLiquidateSpotWithSwap, "last drift ix must be end of swap" )?; @@ -3432,12 +3431,12 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>( quote_owed_from_lp: cached_info.quote_owed_from_lp_pool, quote_constituent_token_balance: quote_constituent.vault_token_balance, fee_pool_balance: get_token_amount( - perp_market.amm.fee_pool.scaled_balance, + perp_market.amm.fee_pool.scaled_balance(), quote_market, &SpotBalanceType::Deposit, )?, pnl_pool_balance: get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), quote_market, &SpotBalanceType::Deposit, )?, @@ -3524,7 +3523,7 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>( .last_exchange_fees .safe_sub(cached_info.last_settle_amm_ex_fees)? .cast::()?, - lp_aum: lp_pool.last_aum, + lp_aum: lp_pool.last_aum(), lp_price: lp_pool.get_price(lp_pool.token_supply)?, lp_pool: lp_pool_key, }); @@ -3546,14 +3545,19 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>( // Update LP pool stats match settlement_result.direction { SettlementDirection::FromLpPool => { - lp_pool.cumulative_quote_sent_to_perp_markets = lp_pool - .cumulative_quote_sent_to_perp_markets - .saturating_add(settlement_result.amount_transferred as u128); + let cumulative_quote_sent = lp_pool.cumulative_quote_sent_to_perp_markets(); + lp_pool.set_cumulative_quote_sent_to_perp_markets( + cumulative_quote_sent + .saturating_add(settlement_result.amount_transferred as u128), + ); } SettlementDirection::ToLpPool => { - lp_pool.cumulative_quote_received_from_perp_markets = lp_pool - .cumulative_quote_received_from_perp_markets - .saturating_add(settlement_result.amount_transferred as u128); + let cumulative_quote_received = + lp_pool.cumulative_quote_received_from_perp_markets(); + lp_pool.set_cumulative_quote_received_from_perp_markets( + cumulative_quote_received + .saturating_add(settlement_result.amount_transferred as u128), + ); } SettlementDirection::None => {} } @@ -3673,7 +3677,7 @@ pub struct SettleAmmPnlToLp<'info> { #[account( mut, owner = crate::ID, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), QUOTE_SPOT_MARKET_INDEX.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), QUOTE_SPOT_MARKET_INDEX.to_le_bytes().as_ref()], bump = constituent.load()?.bump, constraint = constituent.load()?.mint.eq("e_market.load()?.mint) )] @@ -3842,7 +3846,7 @@ pub struct PlaceSignedMsgTakerOrder<'info> { pub user_stats: AccountLoader<'info, UserStats>, #[account( mut, - seeds = [SIGNED_MSG_PDA_SEED.as_ref(), user.load()?.authority.as_ref()], + seeds = [SIGNED_MSG_PDA_SEED.as_bytes(), user.load()?.authority.as_ref()], bump, )] /// CHECK: checked in SignedMsgUserOrdersZeroCopy checks diff --git a/programs/drift/src/instructions/lp_admin.rs b/programs/drift/src/instructions/lp_admin.rs index 0d5fcc9b67..d5b2bbcf00 100644 --- a/programs/drift/src/instructions/lp_admin.rs +++ b/programs/drift/src/instructions/lp_admin.rs @@ -62,20 +62,20 @@ pub fn handle_initialize_lp_pool( constituent_target_base: ctx.accounts.constituent_target_base.key(), constituent_correlations: ctx.accounts.constituent_correlations.key(), constituents: 0, - max_aum, - last_aum: 0, + max_aum: max_aum.into(), + last_aum: 0.into(), last_aum_slot: 0, max_settle_quote_amount: max_settle_quote_amount_per_market, _padding: 0, - total_mint_redeem_fees_paid: 0, + total_mint_redeem_fees_paid: 0.into(), bump: ctx.bumps.lp_pool, min_mint_fee, token_supply: 0, mint_redeem_id: 1, settle_id: 1, quote_consituent_index: 0, - cumulative_quote_sent_to_perp_markets: 0, - cumulative_quote_received_from_perp_markets: 0, + cumulative_quote_sent_to_perp_markets: 0.into(), + cumulative_quote_received_from_perp_markets: 0.into(), gamma_execution: 2, volatility: 4, xi: 2, @@ -466,12 +466,12 @@ pub fn handle_update_lp_pool_params<'info>( if let Some(max_aum) = lp_pool_params.max_aum { validate!( - max_aum >= lp_pool.max_aum, + max_aum >= lp_pool.max_aum(), ErrorCode::DefaultError, "new max_aum must be greater than or equal to current max_aum" )?; - msg!("max_aum: {:?} -> {:?}", lp_pool.max_aum, max_aum); - lp_pool.max_aum = max_aum; + msg!("max_aum: {:?} -> {:?}", lp_pool.max_aum(), max_aum); + lp_pool.set_max_aum(max_aum); } Ok(()) @@ -728,9 +728,9 @@ pub fn handle_begin_lp_swap<'c: 'info, 'info>( found_end = true; // must be the SwapEnd instruction - let discriminator = crate::instruction::EndLpSwap::discriminator(); + let discriminator = crate::instruction::EndLpSwap::DISCRIMINATOR; validate!( - ix.data[0..8] == discriminator, + &ix.data[0..8] == discriminator, ErrorCode::InvalidSwap, "last drift ix must be end of swap" )?; @@ -1045,7 +1045,7 @@ pub struct InitializeLpPool<'info> { #[account( init, - seeds = [AMM_MAP_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [AMM_MAP_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, space = AmmConstituentMapping::space(0 as usize), payer = admin, @@ -1054,7 +1054,7 @@ pub struct InitializeLpPool<'info> { #[account( init, - seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, space = ConstituentTargetBase::space(0 as usize), payer = admin, @@ -1063,7 +1063,7 @@ pub struct InitializeLpPool<'info> { #[account( init, - seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, space = ConstituentCorrelations::space(0 as usize), payer = admin, @@ -1094,7 +1094,7 @@ pub struct InitializeConstituent<'info> { #[account( mut, - seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump = constituent_target_base.bump, realloc = ConstituentTargetBase::space(constituent_target_base.targets.len() + 1_usize), realloc::payer = admin, @@ -1104,7 +1104,7 @@ pub struct InitializeConstituent<'info> { #[account( mut, - seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump = constituent_correlations.bump, realloc = ConstituentCorrelations::space(constituent_target_base.targets.len() + 1_usize), realloc::payer = admin, @@ -1114,7 +1114,7 @@ pub struct InitializeConstituent<'info> { #[account( init, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), spot_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), spot_market_index.to_le_bytes().as_ref()], bump, space = Constituent::SIZE, payer = admin, @@ -1131,7 +1131,7 @@ pub struct InitializeConstituent<'info> { pub spot_market_mint: Box>, #[account( init, - seeds = [CONSTITUENT_VAULT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), spot_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_VAULT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), spot_market_index.to_le_bytes().as_ref()], bump, payer = admin, token::mint = spot_market_mint, @@ -1148,7 +1148,7 @@ pub struct UpdateConstituentParams<'info> { pub lp_pool: AccountLoader<'info, LPPool>, #[account( mut, - seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump = constituent_target_base.bump, constraint = constituent.load()?.lp_pool == lp_pool.key() )] @@ -1220,7 +1220,7 @@ pub struct AddAmmConstituentMappingData<'info> { #[account( mut, - seeds = [AMM_MAP_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [AMM_MAP_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, realloc = AmmConstituentMapping::space(amm_constituent_mapping.weights.len() + amm_constituent_mapping_data.len()), realloc::payer = admin, @@ -1229,7 +1229,7 @@ pub struct AddAmmConstituentMappingData<'info> { pub amm_constituent_mapping: Box>, #[account( mut, - seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_TARGET_BASE_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, realloc = ConstituentTargetBase::space(constituent_target_base.targets.len() + 1_usize), realloc::payer = admin, @@ -1254,7 +1254,7 @@ pub struct UpdateAmmConstituentMappingData<'info> { #[account( mut, - seeds = [AMM_MAP_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [AMM_MAP_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, )] pub amm_constituent_mapping: Box>, @@ -1273,7 +1273,7 @@ pub struct RemoveAmmConstituentMappingData<'info> { #[account( mut, - seeds = [AMM_MAP_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [AMM_MAP_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, realloc = AmmConstituentMapping::space(amm_constituent_mapping.weights.len() - 1), realloc::payer = admin, @@ -1295,7 +1295,7 @@ pub struct UpdateConstituentCorrelation<'info> { #[account( mut, - seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [CONSTITUENT_CORRELATIONS_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump = constituent_correlations.bump, )] pub constituent_correlations: Box>, @@ -1354,13 +1354,13 @@ pub struct LPTakerSwap<'info> { /// Constituents #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], bump = out_constituent.load()?.bump, )] pub out_constituent: AccountLoader<'info, Constituent>, #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump = in_constituent.load()?.bump, )] pub in_constituent: AccountLoader<'info, Constituent>, @@ -1382,7 +1382,7 @@ pub struct UpdatePerpMarketLpPoolStatus<'info> { pub state: Box>, #[account(mut)] pub perp_market: AccountLoader<'info, PerpMarket>, - #[account(mut, seeds = [AMM_POSITIONS_CACHE.as_ref()], + #[account(mut, seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump = amm_cache.bump,)] pub amm_cache: Box>, } @@ -1397,7 +1397,7 @@ pub struct UpdateInitialAmmCacheInfo<'info> { pub admin: Signer<'info>, #[account( mut, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump = amm_cache.bump, )] pub amm_cache: Box>, @@ -1413,7 +1413,7 @@ pub struct ResetAmmCache<'info> { pub state: Box>, #[account( mut, - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump = amm_cache.bump, realloc = AmmCache::space(state.number_of_markets as usize), realloc::payer = admin, diff --git a/programs/drift/src/instructions/lp_pool.rs b/programs/drift/src/instructions/lp_pool.rs index 3108af7ca9..7f0d8151b6 100644 --- a/programs/drift/src/instructions/lp_pool.rs +++ b/programs/drift/src/instructions/lp_pool.rs @@ -376,13 +376,13 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum(), )?; let out_target_weight = constituent_target_base.get_target_weight( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum(), )?; let in_target_datum = constituent_target_base.get(in_constituent.constituent_index as u32); let in_target_position_slot_delay = slot.saturating_sub(in_target_datum.last_position_slot); @@ -463,20 +463,20 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>( in_constituent_index: in_constituent.constituent_index, out_oracle_price: out_oracle.price, in_oracle_price: in_oracle.price, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: in_constituent.get_weight( in_oracle.price, &in_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum(), )?, in_market_target_weight: in_target_weight, out_market_current_weight: out_constituent.get_weight( out_oracle.price, &out_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum(), )?, out_market_target_weight: out_target_weight, in_swap_id, @@ -722,15 +722,15 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( update_spot_market_cumulative_interest(&mut in_spot_market, Some(&in_oracle), now)?; - msg!("aum: {}", lp_pool.last_aum); - let in_target_weight = if lp_pool.last_aum == 0 { + msg!("aum: {}", lp_pool.last_aum()); + let in_target_weight = if lp_pool.last_aum() == 0 { PERCENTAGE_PRECISION_I64 // 100% weight if no aum } else { constituent_target_base.get_target_weight( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, // TODO: add in_amount * in_oracle to est post add_liquidity aum + lp_pool.last_aum(), // TODO: add in_amount * in_oracle to est post add_liquidity aum )? }; @@ -817,14 +817,17 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( let mut lp_pool = ctx.accounts.lp_pool.load_mut()?; - lp_pool.last_aum = lp_pool.last_aum.safe_add( - in_amount - .cast::()? - .safe_mul(in_oracle.price.cast::()?)? - .safe_div(10_u128.pow(in_spot_market.decimals))?, - )?; + let last_aum = lp_pool.last_aum(); + lp_pool.set_last_aum( + last_aum.safe_add( + in_amount + .cast::()? + .safe_mul(in_oracle.price.cast::()?)? + .safe_div(10_u128.pow(in_spot_market.decimals))?, + )?, + ); - if lp_pool.last_aum > lp_pool.max_aum { + if lp_pool.last_aum() > lp_pool.max_aum() { return Err(ErrorCode::MaxDlpAumBreached.into()); } @@ -864,13 +867,13 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>( lp_fee: lp_fee_amount, lp_price: lp_price_after, mint_redeem_id, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: in_constituent.get_weight( in_oracle.price, &in_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum(), )?, in_market_target_weight: in_target_weight, lp_pool: lp_pool_key, @@ -938,15 +941,15 @@ pub fn handle_view_lp_pool_add_liquidity_fees<'c: 'info, 'info>( return Err(ErrorCode::InvalidOracle.into()); } - msg!("aum: {}", lp_pool.last_aum); - let in_target_weight = if lp_pool.last_aum == 0 { + msg!("aum: {}", lp_pool.last_aum()); + let in_target_weight = if lp_pool.last_aum() == 0 { PERCENTAGE_PRECISION_I64 // 100% weight if no aum } else { constituent_target_base.get_target_weight( in_constituent.constituent_index, &in_spot_market, in_oracle.price, - lp_pool.last_aum, // TODO: add in_amount * in_oracle to est post add_liquidity aum + lp_pool.last_aum(), // TODO: add in_amount * in_oracle to est post add_liquidity aum )? }; @@ -1094,7 +1097,7 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, // TODO: remove out_amount * out_oracle to est post remove_liquidity aum + lp_pool.last_aum(), // TODO: remove out_amount * out_oracle to est post remove_liquidity aum )?; let dlp_total_supply = ctx.accounts.lp_mint.supply; @@ -1219,12 +1222,15 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( let mut lp_pool = ctx.accounts.lp_pool.load_mut()?; - lp_pool.last_aum = lp_pool.last_aum.safe_sub( - out_amount_net_fees - .cast::()? - .safe_mul(out_oracle.price.cast::()?)? - .safe_div(10_u128.pow(out_spot_market.decimals))?, - )?; + let last_aum = lp_pool.last_aum(); + lp_pool.set_last_aum( + last_aum.safe_sub( + out_amount_net_fees + .cast::()? + .safe_mul(out_oracle.price.cast::()?)? + .safe_div(10_u128.pow(out_spot_market.decimals))?, + )?, + ); ctx.accounts.constituent_out_token_account.reload()?; ctx.accounts.lp_mint.reload()?; @@ -1262,13 +1268,13 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>( lp_fee: lp_fee_amount, lp_price: lp_price_after, mint_redeem_id, - last_aum: lp_pool.last_aum, + last_aum: lp_pool.last_aum(), last_aum_slot: lp_pool.last_aum_slot, in_market_current_weight: out_constituent.get_weight( out_oracle.price, &out_spot_market, 0, - lp_pool.last_aum, + lp_pool.last_aum(), )?, in_market_target_weight: out_target_weight, lp_pool: lp_pool_key, @@ -1346,7 +1352,7 @@ pub fn handle_view_lp_pool_remove_liquidity_fees<'c: 'info, 'info>( out_constituent.constituent_index, &out_spot_market, out_oracle.price, - lp_pool.last_aum, + lp_pool.last_aum(), )?; let dlp_total_supply = ctx.accounts.lp_mint.supply; @@ -1881,14 +1887,14 @@ pub struct LPPoolSwap<'info> { #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump=in_constituent.load()?.bump, constraint = in_constituent.load()?.mint.eq(&constituent_in_token_account.mint) )] pub in_constituent: AccountLoader<'info, Constituent>, #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], bump=out_constituent.load()?.bump, constraint = out_constituent.load()?.mint.eq(&constituent_out_token_account.mint) )] @@ -1938,14 +1944,14 @@ pub struct ViewLPPoolSwapFees<'info> { #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump=in_constituent.load()?.bump, constraint = in_constituent.load()?.mint.eq(&constituent_in_token_account.mint) )] pub in_constituent: AccountLoader<'info, Constituent>, #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], bump=out_constituent.load()?.bump, constraint = out_constituent.load()?.mint.eq(&constituent_out_token_account.mint) )] @@ -1969,7 +1975,7 @@ pub struct LPPoolAddLiquidity<'info> { pub in_market_mint: Box>, #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump, constraint = in_constituent.load()?.mint.eq(&constituent_in_token_account.mint) @@ -2005,7 +2011,7 @@ pub struct LPPoolAddLiquidity<'info> { #[account( mut, - seeds = [LP_POOL_TOKEN_VAULT_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [LP_POOL_TOKEN_VAULT_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, )] pub lp_pool_token_vault: Box>, @@ -2023,7 +2029,7 @@ pub struct ViewLPPoolAddLiquidityFees<'info> { pub authority: Signer<'info>, pub in_market_mint: Box>, #[account( - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump, )] pub in_constituent: AccountLoader<'info, Constituent>, @@ -2053,7 +2059,7 @@ pub struct LPPoolRemoveLiquidity<'info> { pub out_market_mint: Box>, #[account( mut, - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), out_market_index.to_le_bytes().as_ref()], bump, constraint = out_constituent.load()?.mint.eq(&constituent_out_token_account.mint) @@ -2093,7 +2099,7 @@ pub struct LPPoolRemoveLiquidity<'info> { #[account( mut, - seeds = [LP_POOL_TOKEN_VAULT_PDA_SEED.as_ref(), lp_pool.key().as_ref()], + seeds = [LP_POOL_TOKEN_VAULT_PDA_SEED.as_bytes(), lp_pool.key().as_ref()], bump, )] pub lp_pool_token_vault: Box>, @@ -2101,7 +2107,7 @@ pub struct LPPoolRemoveLiquidity<'info> { pub token_program: Interface<'info, TokenInterface>, #[account( - seeds = [AMM_POSITIONS_CACHE.as_ref()], + seeds = [AMM_POSITIONS_CACHE.as_bytes()], bump, )] /// CHECK: checked in AmmCacheZeroCopy checks @@ -2118,7 +2124,7 @@ pub struct ViewLPPoolRemoveLiquidityFees<'info> { pub authority: Signer<'info>, pub out_market_mint: Box>, #[account( - seeds = [CONSTITUENT_PDA_SEED.as_ref(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], + seeds = [CONSTITUENT_PDA_SEED.as_bytes(), lp_pool.key().as_ref(), in_market_index.to_le_bytes().as_ref()], bump, )] pub out_constituent: AccountLoader<'info, Constituent>, diff --git a/programs/drift/src/instructions/optional_accounts.rs b/programs/drift/src/instructions/optional_accounts.rs index c2365bf0ec..3cad877e38 100644 --- a/programs/drift/src/instructions/optional_accounts.rs +++ b/programs/drift/src/instructions/optional_accounts.rs @@ -134,9 +134,8 @@ pub fn get_referrer_and_referrer_stats<'a>( return Ok((None, None)); } - let user_discriminator: [u8; 8] = User::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != User::DISCRIMINATOR { return Ok((None, None)); } @@ -165,9 +164,8 @@ pub fn get_referrer_and_referrer_stats<'a>( return Ok((None, None)); } - let user_stats_discriminator: [u8; 8] = UserStats::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_stats_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != UserStats::DISCRIMINATOR { return Ok((None, None)); } @@ -262,9 +260,8 @@ pub fn get_high_leverage_mode_config<'a>( return Ok(None); } - let high_leverage_mode_config_discriminator: [u8; 8] = HighLeverageModeConfig::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &high_leverage_mode_config_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != HighLeverageModeConfig::DISCRIMINATOR { return Ok(None); } @@ -293,10 +290,9 @@ pub fn get_revenue_share_escrow_account<'a>( return Ok(None); } - let discriminator: [u8; 8] = RevenueShareEscrow::discriminator(); let borrowed_data = account_info.data.borrow(); let account_discriminator = array_ref![&borrowed_data, 0, 8]; - if account_discriminator != &discriminator { + if account_discriminator != RevenueShareEscrow::DISCRIMINATOR { return Ok(None); } diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index 7811fa2d1e..b7f4d0b4fe 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -1,10 +1,9 @@ use std::convert::TryFrom; use std::ops::DerefMut; -use anchor_lang::prelude::*; -use anchor_lang::Discriminator; -use anchor_spl::associated_token::AssociatedToken; +use anchor_lang::{prelude::*, solana_program::sysvar::instructions, Discriminator}; use anchor_spl::{ + associated_token::AssociatedToken, token::Token, token_2022::Token2022, token_interface::{TokenAccount, TokenInterface}, @@ -117,8 +116,6 @@ use crate::validation::user::validate_user_deletion; use crate::validation::whitelist::validate_whitelist_token; use crate::{controller, math}; use crate::{load_mut, ExchangeStatus}; -use anchor_lang::solana_program::sysvar::instructions; -use borsh::{BorshDeserialize, BorshSerialize}; use solana_program::sysvar::instructions::ID as IX_ID; use super::optional_accounts::get_high_leverage_mode_config; @@ -395,10 +392,8 @@ pub fn handle_initialize_fuel_overflow<'c: 'info, 'info>( .load_init() .or(Err(ErrorCode::UnableToLoadAccountLoader))?; - *fuel_overflow = FuelOverflow { - authority: ctx.accounts.authority.key(), - ..FuelOverflow::default() - }; + *fuel_overflow = FuelOverflow::default(); + fuel_overflow.authority = ctx.accounts.authority.key(); user_stats.update_fuel_overflow_status(true); Ok(()) @@ -426,12 +421,12 @@ pub fn handle_sweep_fuel<'c: 'info, 'info>( user_stats_fuel_positions: user_stats.fuel_positions, user_stats_fuel_taker: user_stats.fuel_taker, user_stats_fuel_maker: user_stats.fuel_maker, - fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance, - fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits, - fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows, - fuel_overflow_fuel_positions: fuel_overflow.fuel_positions, - fuel_overflow_fuel_taker: fuel_overflow.fuel_taker, - fuel_overflow_fuel_maker: fuel_overflow.fuel_maker, + fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance(), + fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits(), + fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows(), + fuel_overflow_fuel_positions: fuel_overflow.fuel_positions(), + fuel_overflow_fuel_taker: fuel_overflow.fuel_taker(), + fuel_overflow_fuel_maker: fuel_overflow.fuel_maker(), }); fuel_overflow.update_from_user_stats(&user_stats, clock.unix_timestamp.cast()?)?; @@ -461,24 +456,24 @@ pub fn handle_reset_fuel_season<'c: 'info, 'info>( user_stats_fuel_positions: user_stats.fuel_positions, user_stats_fuel_taker: user_stats.fuel_taker, user_stats_fuel_maker: user_stats.fuel_maker, - fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance, - fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits, - fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows, - fuel_overflow_fuel_positions: fuel_overflow.fuel_positions, - fuel_overflow_fuel_taker: fuel_overflow.fuel_taker, - fuel_overflow_fuel_maker: fuel_overflow.fuel_maker, + fuel_overflow_fuel_insurance: fuel_overflow.fuel_insurance(), + fuel_overflow_fuel_deposits: fuel_overflow.fuel_deposits(), + fuel_overflow_fuel_borrows: fuel_overflow.fuel_borrows(), + fuel_overflow_fuel_positions: fuel_overflow.fuel_positions(), + fuel_overflow_fuel_taker: fuel_overflow.fuel_taker(), + fuel_overflow_fuel_maker: fuel_overflow.fuel_maker(), }); fuel_overflow.update_from_user_stats(&user_stats, clock.unix_timestamp.cast()?)?; emit!(FuelSeasonRecord { ts: clock.unix_timestamp.cast()?, authority: ctx.accounts.authority.key(), - fuel_insurance: fuel_overflow.fuel_insurance, - fuel_deposits: fuel_overflow.fuel_deposits, - fuel_borrows: fuel_overflow.fuel_borrows, - fuel_positions: fuel_overflow.fuel_positions, - fuel_taker: fuel_overflow.fuel_taker, - fuel_maker: fuel_overflow.fuel_maker, + fuel_insurance: fuel_overflow.fuel_insurance(), + fuel_deposits: fuel_overflow.fuel_deposits(), + fuel_borrows: fuel_overflow.fuel_borrows(), + fuel_positions: fuel_overflow.fuel_positions(), + fuel_taker: fuel_overflow.fuel_taker(), + fuel_maker: fuel_overflow.fuel_maker(), fuel_total: fuel_overflow.total_fuel()?, }); fuel_overflow.reset_fuel(clock.unix_timestamp.cast()?); @@ -822,10 +817,10 @@ pub fn handle_deposit<'c: 'info, 'info>( direction: DepositDirection::Deposit, amount, oracle_price, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance(), + market_withdraw_balance: spot_market.borrow_balance(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), total_deposits_after, total_withdraws_after, market_index, @@ -980,10 +975,10 @@ pub fn handle_withdraw<'c: 'info, 'info>( oracle_price, amount, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance(), + market_withdraw_balance: spot_market.borrow_balance(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), total_deposits_after: user.total_deposits, total_withdraws_after: user.total_withdraws, explanation: deposit_explanation, @@ -1154,10 +1149,10 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( amount, oracle_price, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance(), + market_withdraw_balance: spot_market.borrow_balance(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1222,10 +1217,10 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>( amount, oracle_price, market_index, - market_deposit_balance: spot_market.deposit_balance, - market_withdraw_balance: spot_market.borrow_balance, - market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest, + market_deposit_balance: spot_market.deposit_balance(), + market_withdraw_balance: spot_market.borrow_balance(), + market_cumulative_deposit_interest: spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: spot_market.cumulative_borrow_interest(), total_deposits_after, total_withdraws_after, explanation: DepositExplanation::Transfer, @@ -1435,11 +1430,12 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: deposit_transfer, oracle_price: deposit_from_oracle_price_data.price, market_index: deposit_from_market_index, - market_deposit_balance: deposit_from_spot_market.deposit_balance, - market_withdraw_balance: deposit_from_spot_market.borrow_balance, + market_deposit_balance: deposit_from_spot_market.deposit_balance(), + market_withdraw_balance: deposit_from_spot_market.borrow_balance(), market_cumulative_deposit_interest: deposit_from_spot_market - .cumulative_deposit_interest, - market_cumulative_borrow_interest: deposit_from_spot_market.cumulative_borrow_interest, + .cumulative_deposit_interest(), + market_cumulative_borrow_interest: deposit_from_spot_market + .cumulative_borrow_interest(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1474,10 +1470,11 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: deposit_transfer, oracle_price: deposit_to_oracle_price_data.price, market_index: deposit_to_market_index, - market_deposit_balance: deposit_to_spot_market.deposit_balance, - market_withdraw_balance: deposit_to_spot_market.borrow_balance, - market_cumulative_deposit_interest: deposit_to_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: deposit_to_spot_market.cumulative_borrow_interest, + market_deposit_balance: deposit_to_spot_market.deposit_balance(), + market_withdraw_balance: deposit_to_spot_market.borrow_balance(), + market_cumulative_deposit_interest: deposit_to_spot_market + .cumulative_deposit_interest(), + market_cumulative_borrow_interest: deposit_to_spot_market.cumulative_borrow_interest(), total_deposits_after: to_user.total_deposits, total_withdraws_after: to_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1544,10 +1541,11 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: borrow_transfer, oracle_price: borrow_from_oracle_price_data.price, market_index: borrow_from_market_index, - market_deposit_balance: borrow_from_spot_market.deposit_balance, - market_withdraw_balance: borrow_from_spot_market.borrow_balance, - market_cumulative_deposit_interest: borrow_from_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: borrow_from_spot_market.cumulative_borrow_interest, + market_deposit_balance: borrow_from_spot_market.deposit_balance(), + market_withdraw_balance: borrow_from_spot_market.borrow_balance(), + market_cumulative_deposit_interest: borrow_from_spot_market + .cumulative_deposit_interest(), + market_cumulative_borrow_interest: borrow_from_spot_market.cumulative_borrow_interest(), total_deposits_after: from_user.total_deposits, total_withdraws_after: from_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -1582,10 +1580,10 @@ pub fn handle_transfer_pools<'c: 'info, 'info>( amount: borrow_transfer, oracle_price: borrow_to_oracle_price_data.price, market_index: borrow_to_market_index, - market_deposit_balance: borrow_to_spot_market.deposit_balance, - market_withdraw_balance: borrow_to_spot_market.borrow_balance, - market_cumulative_deposit_interest: borrow_to_spot_market.cumulative_deposit_interest, - market_cumulative_borrow_interest: borrow_to_spot_market.cumulative_borrow_interest, + market_deposit_balance: borrow_to_spot_market.deposit_balance(), + market_withdraw_balance: borrow_to_spot_market.borrow_balance(), + market_cumulative_deposit_interest: borrow_to_spot_market.cumulative_deposit_interest(), + market_cumulative_borrow_interest: borrow_to_spot_market.cumulative_borrow_interest(), total_deposits_after: to_user.total_deposits, total_withdraws_after: to_user.total_withdraws, explanation: DepositExplanation::Transfer, @@ -3650,9 +3648,9 @@ pub fn handle_begin_swap<'c: 'info, 'info>( found_end = true; // must be the SwapEnd instruction - let discriminator = crate::instruction::EndSwap::discriminator(); + let discriminator = crate::instruction::EndSwap::DISCRIMINATOR; validate!( - ix.data[0..8] == discriminator, + &ix.data[0..8] == discriminator, ErrorCode::InvalidSwap, "last drift ix must be end of swap" )?; @@ -3758,7 +3756,7 @@ pub fn handle_begin_swap<'c: 'info, 'info>( Ok(()) } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum SwapReduceOnly { In, Out, @@ -4210,7 +4208,7 @@ pub struct InitializeUserStats<'info> { pub struct InitializeSignedMsgUserOrders<'info> { #[account( init, - seeds = [SIGNED_MSG_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [SIGNED_MSG_PDA_SEED.as_bytes(), authority.key().as_ref()], space = SignedMsgUserOrders::space(num_orders as usize), bump, payer = payer @@ -4229,7 +4227,7 @@ pub struct InitializeSignedMsgUserOrders<'info> { pub struct ResizeSignedMsgUserOrders<'info> { #[account( mut, - seeds = [SIGNED_MSG_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [SIGNED_MSG_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, realloc = SignedMsgUserOrders::space(num_orders as usize), realloc::payer = payer, @@ -4251,7 +4249,7 @@ pub struct ResizeSignedMsgUserOrders<'info> { #[instruction(delegates: Vec)] pub struct InitializeSignedMsgWsDelegates<'info> { #[account( - seeds = [SIGNED_MSG_WS_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [SIGNED_MSG_WS_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, init, space = 8 + 4 + delegates.len() * 32, @@ -4269,7 +4267,7 @@ pub struct InitializeSignedMsgWsDelegates<'info> { pub struct ChangeSignedMsgWsDelegateStatus<'info> { #[account( mut, - seeds = [SIGNED_MSG_WS_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [SIGNED_MSG_WS_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, realloc = SignedMsgWsDelegates::space(&signed_msg_ws_delegates, add), realloc::payer = authority, @@ -4633,7 +4631,7 @@ pub struct PlaceAndMakeSignedMsg<'info> { )] pub taker_stats: AccountLoader<'info, UserStats>, #[account( - seeds = [SIGNED_MSG_PDA_SEED.as_ref(), taker.load()?.authority.as_ref()], + seeds = [SIGNED_MSG_PDA_SEED.as_bytes(), taker.load()?.authority.as_ref()], bump, )] /// CHECK: checked in SignedMsgUserOrdersZeroCopy checks @@ -4708,7 +4706,7 @@ pub struct DeleteSignedMsgUserOrders<'info> { #[account( mut, close = authority, - seeds = [SIGNED_MSG_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [SIGNED_MSG_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, )] pub signed_msg_user_orders: Box>, @@ -4819,7 +4817,7 @@ pub struct UpdateUserProtectedMakerMode<'info> { pub struct InitializeRevenueShare<'info> { #[account( init, - seeds = [REVENUE_SHARE_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [REVENUE_SHARE_PDA_SEED.as_bytes(), authority.key().as_ref()], space = RevenueShare::space(), bump, payer = payer @@ -4838,7 +4836,7 @@ pub struct InitializeRevenueShare<'info> { pub struct InitializeRevenueShareEscrow<'info> { #[account( init, - seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_bytes(), authority.key().as_ref()], space = RevenueShareEscrow::space(num_orders as usize, 1), bump, payer = payer @@ -4862,7 +4860,7 @@ pub struct InitializeRevenueShareEscrow<'info> { pub struct MigrateReferrer<'info> { #[account( mut, - seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, )] pub escrow: Box>, @@ -4882,7 +4880,7 @@ pub struct MigrateReferrer<'info> { pub struct ResizeRevenueShareEscrowOrders<'info> { #[account( mut, - seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, realloc = RevenueShareEscrow::space(num_orders as usize, escrow.approved_builders.len()), realloc::payer = payer, @@ -4902,7 +4900,7 @@ pub struct ResizeRevenueShareEscrowOrders<'info> { pub struct ChangeApprovedBuilder<'info> { #[account( mut, - seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_ref(), authority.key().as_ref()], + seeds = [REVENUE_SHARE_ESCROW_PDA_SEED.as_bytes(), authority.key().as_ref()], bump, // revoking a builder does not remove the slot to avoid unintended reuse realloc = RevenueShareEscrow::space(escrow.orders.len(), if add { escrow.approved_builders.len() + 1 } else { escrow.approved_builders.len() }), diff --git a/programs/drift/src/lib.rs b/programs/drift/src/lib.rs index ae6d90d0ad..2c36ad011d 100644 --- a/programs/drift/src/lib.rs +++ b/programs/drift/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(unexpected_cfgs)] #![allow(clippy::too_many_arguments)] #![allow(clippy::bool_assert_comparison)] #![allow(clippy::comparison_chain)] diff --git a/programs/drift/src/macros.rs b/programs/drift/src/macros.rs index cdd2004825..03daaadd8f 100644 --- a/programs/drift/src/macros.rs +++ b/programs/drift/src/macros.rs @@ -89,32 +89,16 @@ macro_rules! safe_decrement { }}; } -/// Calculate the sha256 digest of anchor encoded `struct` -#[macro_export] -macro_rules! digest_struct { - ($struct:expr) => { - solana_program::hash::hash(&$struct.try_to_vec().unwrap()).to_bytes() - }; -} - -/// Calculate the hexified sha256 digest of anchor encoded `struct` -#[macro_export] -macro_rules! digest_struct_hex { - ($struct:expr) => {{ - hex::encode(digest_struct!($struct)).into_bytes() - }}; -} - /// same as `solana_program::msg!` but it can compile away for off-chain use #[macro_export] macro_rules! msg { ($msg:expr) => { #[cfg(not(feature = "drift-rs"))] - solana_program::msg!($msg) + ::solana_program::msg!($msg) }; ($($arg:tt)*) => { #[cfg(not(feature = "drift-rs"))] - (solana_program::msg!(&format!($($arg)*))); + (::solana_program::msg!(&format!($($arg)*))); } } diff --git a/programs/drift/src/math/amm.rs b/programs/drift/src/math/amm.rs index 914dffe621..82573fe83f 100644 --- a/programs/drift/src/math/amm.rs +++ b/programs/drift/src/math/amm.rs @@ -63,9 +63,9 @@ pub fn calculate_bid_ask_bounds( } pub fn calculate_market_open_bids_asks(amm: &AMM) -> DriftResult<(i128, i128)> { - let base_asset_reserve = amm.base_asset_reserve; - let min_base_asset_reserve = amm.min_base_asset_reserve; - let max_base_asset_reserve = amm.max_base_asset_reserve; + let base_asset_reserve = amm.base_asset_reserve(); + let min_base_asset_reserve = amm.min_base_asset_reserve(); + let max_base_asset_reserve = amm.max_base_asset_reserve(); let (max_bids, max_asks) = _calculate_market_open_bids_asks( base_asset_reserve, @@ -712,16 +712,16 @@ pub fn calculate_quote_asset_amount_swapped( } pub fn calculate_terminal_reserves(amm: &AMM) -> DriftResult<(u128, u128)> { - let swap_direction = if amm.base_asset_amount_with_amm > 0 { + let swap_direction = if amm.base_asset_amount_with_amm() > 0 { SwapDirection::Add } else { SwapDirection::Remove }; let (new_quote_asset_amount, new_base_asset_amount) = calculate_swap_output( - amm.base_asset_amount_with_amm.unsigned_abs(), - amm.base_asset_reserve, + amm.base_asset_amount_with_amm().unsigned_abs(), + amm.base_asset_reserve(), swap_direction, - amm.sqrt_k, + amm.sqrt_k(), )?; Ok((new_quote_asset_amount, new_base_asset_amount)) @@ -733,7 +733,7 @@ pub fn calculate_terminal_price_and_reserves(amm: &AMM) -> DriftResult<(u64, u12 let terminal_price = calculate_price( new_quote_asset_amount, new_base_asset_amount, - amm.peg_multiplier, + amm.peg_multiplier(), )?; Ok(( @@ -844,20 +844,20 @@ pub fn calculate_amm_available_liquidity( amm: &AMM, order_direction: &PositionDirection, ) -> DriftResult { - let max_fill_size: u64 = (amm.base_asset_reserve / amm.max_fill_reserve_fraction as u128) + let max_fill_size: u64 = (amm.base_asset_reserve() / amm.max_fill_reserve_fraction as u128) .min(u64::MAX as u128) .cast()?; // one fill can only take up to half of side's liquidity let max_base_asset_amount_on_side = match order_direction { PositionDirection::Long => { - amm.base_asset_reserve - .saturating_sub(amm.min_base_asset_reserve) + amm.base_asset_reserve() + .saturating_sub(amm.min_base_asset_reserve()) / 2 } PositionDirection::Short => { - amm.max_base_asset_reserve - .saturating_sub(amm.base_asset_reserve) + amm.max_base_asset_reserve() + .saturating_sub(amm.base_asset_reserve()) / 2 } } @@ -870,7 +870,7 @@ pub fn calculate_amm_available_liquidity( } pub fn calculate_net_user_cost_basis(amm: &AMM) -> DriftResult { - amm.quote_asset_amount + amm.quote_asset_amount() .safe_add(amm.quote_asset_amount_with_unsettled_lp.cast()?)? .safe_add(amm.net_unsettled_funding_pnl.cast()?) } @@ -883,8 +883,8 @@ pub fn calculate_net_user_pnl(amm: &AMM, oracle_price: i64) -> DriftResult )?; let net_user_base_asset_value = amm - .base_asset_amount_with_amm - .safe_add(amm.base_asset_amount_with_unsettled_lp)? + .base_asset_amount_with_amm() + .safe_add(amm.base_asset_amount_with_unsettled_lp())? .safe_mul(oracle_price.cast()?)? .safe_div(PRICE_TIMES_AMM_TO_QUOTE_PRECISION_RATIO.cast()?)?; @@ -896,7 +896,7 @@ pub fn calculate_expiry_price( target_price: i64, total_excess_balance: i128, ) -> DriftResult { - if amm.base_asset_amount_with_amm.abs() < amm.order_step_size.cast::()? { + if amm.base_asset_amount_with_amm().abs() < amm.order_step_size.cast::()? { return Ok(target_price); } // net_baa * price + net_quote <= 0 @@ -905,13 +905,13 @@ pub fn calculate_expiry_price( // net_user_unrealized_pnl negative = surplus in market // net_user_unrealized_pnl positive = expiry price needs to differ from oracle let best_expiry_price = -(amm - .quote_asset_amount - .safe_sub(total_excess_balance.cast::()?)? + .quote_asset_amount() + .safe_sub(total_excess_balance)? .safe_mul(PRICE_TIMES_AMM_TO_QUOTE_PRECISION_RATIO_I128)? - .safe_div(amm.base_asset_amount_with_amm)?) + .safe_div(amm.base_asset_amount_with_amm())?) .cast::()?; - let expiry_price = if amm.base_asset_amount_with_amm >= 0 { + let expiry_price = if amm.base_asset_amount_with_amm() >= 0 { // net longs only get as high as oracle_price best_expiry_price.min(target_price).saturating_sub(1) } else { diff --git a/programs/drift/src/math/amm/tests.rs b/programs/drift/src/math/amm/tests.rs index 938dc1e0c0..e458b0fdfa 100644 --- a/programs/drift/src/math/amm/tests.rs +++ b/programs/drift/src/math/amm/tests.rs @@ -26,47 +26,55 @@ fn calculate_amm_available_guards() { }; assert_eq!(market.amm.net_revenue_since_last_funding, 0); - assert_eq!(market.amm.total_fee_minus_distributions, 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 0); assert_eq!(!market.has_too_much_drawdown().unwrap(), true); market.amm.net_revenue_since_last_funding = -100_000_000_000; - market.amm.total_fee_minus_distributions = 100_000_000_000; + market + .amm + .set_total_fee_minus_distributions(100_000_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), false); market.amm.net_revenue_since_last_funding = -10_000_000_000; - market.amm.total_fee_minus_distributions = 100_000_000_000; + market + .amm + .set_total_fee_minus_distributions(100_000_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), false); market.amm.net_revenue_since_last_funding = -5_000_000_000; - market.amm.total_fee_minus_distributions = 100_000_000_000; + market + .amm + .set_total_fee_minus_distributions(100_000_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), false); market.amm.net_revenue_since_last_funding = -1_000_000_000; - market.amm.total_fee_minus_distributions = 100_000_000_000; + market + .amm + .set_total_fee_minus_distributions(100_000_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), true); market.amm.net_revenue_since_last_funding = -1_000_000_000; - market.amm.total_fee_minus_distributions = 1_000_000; + market.amm.set_total_fee_minus_distributions(1_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), true); market.amm.net_revenue_since_last_funding = -6_000_000_000; - market.amm.total_fee_minus_distributions = 1_000_000; + market.amm.set_total_fee_minus_distributions(1_000_000); assert_eq!(!market.has_too_much_drawdown().unwrap(), false); market.amm.net_revenue_since_last_funding = -5_000; - market.amm.total_fee_minus_distributions = -9279797219; + market.amm.set_total_fee_minus_distributions(-9279797219); assert_eq!(!market.has_too_much_drawdown().unwrap(), true); // too small net_revenue_since_last_funding drawdown market.amm.net_revenue_since_last_funding = -88_000_000_000; - market.amm.total_fee_minus_distributions = -9279797219; + market.amm.set_total_fee_minus_distributions(-9279797219); assert_eq!(!market.has_too_much_drawdown().unwrap(), false); // too small net_revenue_since_last_funding drawdown } @@ -79,9 +87,9 @@ fn calculate_net_user_pnl_test() { let px = 32 * PRICE_PRECISION; let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PEG_PRECISION.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: px as i64, last_oracle_price_twap_ts: prev, @@ -142,13 +150,13 @@ fn calculate_expiry_price_long_imbalance_with_loss_test() { let market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: (12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (12295081967_i128).into(), max_spread: 1000, - quote_asset_amount: market_position.quote_asset_amount as i128 * 2, + quote_asset_amount: (market_position.quote_asset_amount as i128 * 2).into(), // assume someone else has other half same entry, ..AMM::default() }, @@ -225,13 +233,13 @@ fn calculate_expiry_price_long_imbalance_test() { let market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: (12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (12295081967_i128).into(), max_spread: 1000, - quote_asset_amount: market_position.quote_asset_amount as i128 * 2, + quote_asset_amount: (market_position.quote_asset_amount as i128 * 2).into(), // assume someone else has other half same entry, ..AMM::default() }, @@ -291,9 +299,9 @@ fn calculate_expiry_price_test() { let px = 32 * PRICE_PRECISION; let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PEG_PRECISION.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: px as i64, last_oracle_price_twap_ts: prev, @@ -342,13 +350,13 @@ fn calculate_expiry_price_test() { let market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: -(12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (-(12295081967_i128)).into(), max_spread: 1000, - quote_asset_amount: market_position.quote_asset_amount as i128 * 2, + quote_asset_amount: (market_position.quote_asset_amount as i128 * 2).into(), // assume someone else has other half same entry, ..AMM::default() }, @@ -408,9 +416,9 @@ fn calc_delayed_mark_twap_tests() { let prev = 1656682258; let now = prev + 60; let mut amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PRICE_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PRICE_PRECISION.into(), base_spread: 655, //base spread is .065%, max_spread: 65535, //base spread is 6.5% mark_std: PRICE_PRECISION as u64, @@ -428,7 +436,7 @@ fn calc_delayed_mark_twap_tests() { ..AMM::default() }; let px = 22850 * PRICE_PRECISION as i64; - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); let trade_direction = PositionDirection::Long; update_mark_twap_from_estimates(&mut amm, now, Some(px as u64), Some(trade_direction), None) .unwrap(); @@ -448,9 +456,9 @@ fn calc_mark_std_tests() { let prev = 1656682258; let mut now = prev + 60; let mut amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PRICE_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PRICE_PRECISION.into(), base_spread: 65535, //max base spread is 6.5% mark_std: PRICE_PRECISION as u64, historical_oracle_data: HistoricalOracleData { @@ -502,7 +510,7 @@ fn calc_mark_std_tests() { update_oracle_price_twap(&mut amm, now, &mm_oracle_price_data, None, None).unwrap(); - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); let trade_direction = PositionDirection::Long; update_mark_twap_from_estimates(&mut amm, now, Some(px), Some(trade_direction), None) .unwrap(); @@ -527,7 +535,7 @@ fn calc_mark_std_tests() { let mut px: u64 = 31_936_658; let stop_time = now + 3600 * 2; assert_eq!(amm.reserve_price().unwrap(), 39397); - amm.peg_multiplier = 31_986_658; + amm.set_peg_multiplier(31_986_658); assert_eq!(amm.reserve_price().unwrap(), 31986658); amm.historical_oracle_data.last_oracle_price = 31986658; @@ -536,7 +544,7 @@ fn calc_mark_std_tests() { if now % 15 == 0 { px = 31_986_658; //31.98 amm.historical_oracle_data.last_oracle_price = (px - 1000000) as i64; - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); let amm_reserve_price = amm.reserve_price().unwrap(); let (amm_bid_price, amm_ask_price) = amm.bid_ask_price(amm_reserve_price).unwrap(); msg!("bid={:?} ask={:?}", amm_bid_price, amm_ask_price); @@ -550,7 +558,7 @@ fn calc_mark_std_tests() { } if now % 189 == 0 { px = 31_883_651; //31.88 - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); amm.historical_oracle_data.last_oracle_price = (px + 1000000) as i64; let amm_reserve_price = amm.reserve_price().unwrap(); @@ -575,7 +583,7 @@ fn calc_mark_std_tests() { now += 1; if now % 2 == 1 { px = 31_986_658; //31.98 - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); amm.historical_oracle_data.last_oracle_price = (px - 1000000) as i64; let trade_direction = PositionDirection::Long; @@ -584,7 +592,7 @@ fn calc_mark_std_tests() { } if now % 2 == 0 { px = 31_883_651; //31.88 - amm.peg_multiplier = px as u128; + amm.set_peg_multiplier(px as u128); amm.historical_oracle_data.last_oracle_price = (px + 1000000) as i64; let trade_direction = PositionDirection::Short; @@ -626,9 +634,9 @@ fn update_mark_twap_tests() { // $40 everything init let mut amm = AMM { - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: 40 * PEG_PRECISION, + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (40 * PEG_PRECISION).into(), base_spread: 800, max_spread: 10000, long_spread: 0, @@ -767,9 +775,9 @@ fn calc_oracle_twap_tests() { let px = 32 * PRICE_PRECISION; let mut amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PEG_PRECISION.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: px as i64, last_oracle_price_twap_ts: prev, @@ -889,9 +897,9 @@ fn calc_oracle_twap_clamp_update_tests() { // $13 everything init let mut amm = AMM { - quote_asset_reserve: 200 * AMM_RESERVE_PRECISION, - base_asset_reserve: 200 * AMM_RESERVE_PRECISION, - peg_multiplier: 13 * PEG_PRECISION, + quote_asset_reserve: (200 * AMM_RESERVE_PRECISION).into(), + base_asset_reserve: (200 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (13 * PEG_PRECISION).into(), base_spread: 0, long_spread: 0, short_spread: 0, @@ -978,9 +986,9 @@ fn test_last_oracle_conf_update() { let now = prev + 1; let mut amm = AMM { - quote_asset_reserve: 200 * AMM_RESERVE_PRECISION, - base_asset_reserve: 200 * AMM_RESERVE_PRECISION, - peg_multiplier: 13 * PEG_PRECISION, + quote_asset_reserve: (200 * AMM_RESERVE_PRECISION).into(), + base_asset_reserve: (200 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (13 * PEG_PRECISION).into(), base_spread: 0, long_spread: 0, short_spread: 0, diff --git a/programs/drift/src/math/amm_jit.rs b/programs/drift/src/math/amm_jit.rs index 2d2c22c0fd..1f62b7c209 100644 --- a/programs/drift/src/math/amm_jit.rs +++ b/programs/drift/src/math/amm_jit.rs @@ -132,7 +132,7 @@ pub fn calculate_clamped_jit_base_asset_amount( // bound it; dont flip the net_baa let max_amm_base_asset_amount = market .amm - .base_asset_amount_with_amm + .base_asset_amount_with_amm() .unsigned_abs() .cast::()?; diff --git a/programs/drift/src/math/amm_jit/tests.rs b/programs/drift/src/math/amm_jit/tests.rs index 5e3488741d..ddd34aea22 100644 --- a/programs/drift/src/math/amm_jit/tests.rs +++ b/programs/drift/src/math/amm_jit/tests.rs @@ -5,7 +5,7 @@ use crate::state::perp_market::AMM; fn balanced_market_zero_jit() { let market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 0, + base_asset_amount_with_amm: 0.into(), amm_jit_intensity: 100, ..AMM::default_test() }, @@ -22,7 +22,7 @@ fn balanced_market_zero_jit() { fn balanced_market_zero_intensity() { let market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 100, + base_asset_amount_with_amm: 100.into(), amm_jit_intensity: 0, ..AMM::default_test() }, @@ -39,7 +39,7 @@ fn balanced_market_zero_intensity() { fn balanced_market_full_intensity() { let market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 100, + base_asset_amount_with_amm: 100.into(), amm_jit_intensity: 100, ..AMM::default_test() }, @@ -56,7 +56,7 @@ fn balanced_market_full_intensity() { fn balanced_market_half_intensity() { let market = PerpMarket { amm: AMM { - base_asset_amount_with_amm: 100, + base_asset_amount_with_amm: 100.into(), amm_jit_intensity: 50, ..AMM::default_test() }, diff --git a/programs/drift/src/math/amm_spread.rs b/programs/drift/src/math/amm_spread.rs index 047be54631..64d45cb850 100644 --- a/programs/drift/src/math/amm_spread.rs +++ b/programs/drift/src/math/amm_spread.rs @@ -27,7 +27,7 @@ pub fn calculate_base_asset_amount_to_trade_to_price( limit_price: u64, direction: PositionDirection, ) -> DriftResult<(u64, PositionDirection)> { - let invariant_sqrt_u192 = U192::from(amm.sqrt_k); + let invariant_sqrt_u192 = U192::from(amm.sqrt_k()); let invariant = invariant_sqrt_u192.safe_mul(invariant_sqrt_u192)?; validate!( @@ -39,7 +39,7 @@ pub fn calculate_base_asset_amount_to_trade_to_price( let new_base_asset_reserve_squared = invariant .safe_mul(U192::from(PRICE_PRECISION))? .safe_div(U192::from(limit_price))? - .safe_mul(U192::from(amm.peg_multiplier))? + .safe_mul(U192::from(amm.peg_multiplier()))? .safe_div(U192::from(PEG_PRECISION))?; let new_base_asset_reserve = new_base_asset_reserve_squared @@ -50,7 +50,7 @@ pub fn calculate_base_asset_amount_to_trade_to_price( let (spread_base_asset_reserve, _) = get_spread_reserves(amm, direction)?; spread_base_asset_reserve } else { - amm.base_asset_reserve + amm.base_asset_reserve() }; if new_base_asset_reserve > base_asset_reserve_before { @@ -519,8 +519,8 @@ pub fn calculate_spread( pub fn get_spread_reserves(amm: &AMM, direction: PositionDirection) -> DriftResult<(u128, u128)> { let (base_asset_reserve, quote_asset_reserve) = match direction { - PositionDirection::Long => (amm.ask_base_asset_reserve, amm.ask_quote_asset_reserve), - PositionDirection::Short => (amm.bid_base_asset_reserve, amm.bid_quote_asset_reserve), + PositionDirection::Long => (amm.ask_base_asset_reserve(), amm.ask_quote_asset_reserve()), + PositionDirection::Short => (amm.bid_base_asset_reserve(), amm.bid_quote_asset_reserve()), }; Ok((base_asset_reserve, quote_asset_reserve)) @@ -548,7 +548,7 @@ pub fn calculate_spread_reserves( BID_ASK_SPREAD_PRECISION_I128 / (spread_with_offset / 2).cast::()?; market .amm - .quote_asset_reserve + .quote_asset_reserve() .cast::()? .safe_div(quote_reserve_divisor)? } else { @@ -558,12 +558,12 @@ pub fn calculate_spread_reserves( let mut quote_asset_reserve = if quote_asset_reserve_delta > 0 { market .amm - .quote_asset_reserve + .quote_asset_reserve() .safe_add(quote_asset_reserve_delta.unsigned_abs())? } else { market .amm - .quote_asset_reserve + .quote_asset_reserve() .safe_sub(quote_asset_reserve_delta.unsigned_abs())? }; @@ -577,7 +577,7 @@ pub fn calculate_spread_reserves( ); } - let invariant_sqrt_u192 = U192::from(market.amm.sqrt_k); + let invariant_sqrt_u192 = U192::from(market.amm.sqrt_k()); let invariant = invariant_sqrt_u192.safe_mul(invariant_sqrt_u192)?; let base_asset_reserve = invariant diff --git a/programs/drift/src/math/amm_spread/tests.rs b/programs/drift/src/math/amm_spread/tests.rs index eaf55b5333..daa4d6e4ee 100644 --- a/programs/drift/src/math/amm_spread/tests.rs +++ b/programs/drift/src/math/amm_spread/tests.rs @@ -194,12 +194,12 @@ mod test { fn calculate_reference_price_offset_deadband_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: AMM_RESERVE_PRECISION * 11, - quote_asset_reserve: AMM_RESERVE_PRECISION * 10, - sqrt_k: AMM_RESERVE_PRECISION * 10, - peg_multiplier: 34_000_000, - min_base_asset_reserve: AMM_RESERVE_PRECISION * 7, - max_base_asset_reserve: AMM_RESERVE_PRECISION * 14, + base_asset_reserve: (AMM_RESERVE_PRECISION * 11).into(), + quote_asset_reserve: (AMM_RESERVE_PRECISION * 10).into(), + sqrt_k: (AMM_RESERVE_PRECISION * 10).into(), + peg_multiplier: 34_000_000.into(), + min_base_asset_reserve: (AMM_RESERVE_PRECISION * 7).into(), + max_base_asset_reserve: (AMM_RESERVE_PRECISION * 14).into(), base_spread: 1000, max_spread: 20_000, curve_update_intensity: 110, @@ -219,12 +219,14 @@ mod test { let reserve_price = 4216 * 10000; - market.amm.base_asset_amount_with_amm = (AMM_RESERVE_PRECISION * 7 / 20) as i128; + market + .amm + .set_base_asset_amount_with_amm((AMM_RESERVE_PRECISION * 7 / 20) as i128); let inventory_ratio = calculate_inventory_liquidity_ratio_for_reference_price_offset( - market.amm.base_asset_amount_with_amm, - market.amm.base_asset_reserve, - market.amm.min_base_asset_reserve, - market.amm.max_base_asset_reserve, + market.amm.base_asset_amount_with_amm(), + market.amm.base_asset_reserve(), + market.amm.min_base_asset_reserve(), + market.amm.max_base_asset_reserve(), ) .unwrap(); assert_eq!(inventory_ratio, 100000); // 10% @@ -232,12 +234,16 @@ mod test { market.amm.reference_price_offset_deadband_pct = 10; // 10% // If inventory exceeds threshold positive ref price offset - market.amm.base_asset_amount_with_amm = (AMM_RESERVE_PRECISION * 8 / 20) as i128; + market + .amm + .set_base_asset_amount_with_amm((AMM_RESERVE_PRECISION * 8 / 20) as i128); let (_l, _s) = update_spreads(&mut market, reserve_price as u64, None).unwrap(); assert!(market.amm.reference_price_offset > 0); // If inventory is small, goes to 0 - market.amm.base_asset_amount_with_amm = (AMM_RESERVE_PRECISION * 6 / 20) as i128; + market + .amm + .set_base_asset_amount_with_amm((AMM_RESERVE_PRECISION * 6 / 20) as i128); let (_l, _s) = update_spreads(&mut market, reserve_price as u64, None).unwrap(); assert_eq!(market.amm.reference_price_offset, 0); @@ -246,7 +252,9 @@ mod test { market.amm.last_24h_avg_funding_rate = -1; market.amm.last_mark_price_twap_5min = 4216 * 10000 - 2 * 10000; market.amm.last_mark_price_twap = 4216 * 10000 - 2 * 10000; - market.amm.base_asset_amount_with_amm = (AMM_RESERVE_PRECISION * 8 / 20) as i128 * -1; + market + .amm + .set_base_asset_amount_with_amm((AMM_RESERVE_PRECISION * 8 / 20) as i128 * -1); let (_l, _s) = update_spreads(&mut market, reserve_price as u64, None).unwrap(); println!( "ref offset: {}, {}, {}", @@ -255,7 +263,9 @@ mod test { assert!(market.amm.reference_price_offset - (_s as i32) < 0); // Same for short pos - market.amm.base_asset_amount_with_amm = (AMM_RESERVE_PRECISION * 6 / 20) as i128 * -1; + market + .amm + .set_base_asset_amount_with_amm((AMM_RESERVE_PRECISION * 6 / 20) as i128 * -1); let (_l, _s) = update_spreads(&mut market, reserve_price as u64, None).unwrap(); assert_eq!(market.amm.reference_price_offset, 0); } @@ -443,10 +453,10 @@ mod test { assert_eq!(short_spread5, 500); let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - sqrt_k: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: PEG_PRECISION.into(), long_spread: long_spread5, short_spread: short_spread5, max_spread: 1000, @@ -475,9 +485,9 @@ mod test { assert_eq!(max_ref_offset, 25000); // 250 bps (5% of max spread) let orig_price = calculate_price( - amm.quote_asset_reserve, - amm.base_asset_reserve, - amm.peg_multiplier, + amm.quote_asset_reserve(), + amm.base_asset_reserve(), + amm.peg_multiplier(), ) .unwrap(); assert_eq!(orig_price, 1000000); @@ -490,13 +500,13 @@ mod test { assert_eq!(qar_l, 2027397260); assert_eq!(qar_s, 1999500000); - assert!(qar_l > amm.quote_asset_reserve); - assert!(bar_l < amm.base_asset_reserve); - assert!(qar_s < amm.quote_asset_reserve); - assert!(bar_s > amm.base_asset_reserve); + assert!(qar_l > amm.quote_asset_reserve()); + assert!(bar_l < amm.base_asset_reserve()); + assert!(qar_s < amm.quote_asset_reserve()); + assert!(bar_s > amm.base_asset_reserve()); - let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier).unwrap(); - let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier).unwrap(); + let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier()).unwrap(); + let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier()).unwrap(); assert_eq!(l_price, 1027584); assert_eq!(s_price, 999500); assert!(l_price > s_price); @@ -506,19 +516,19 @@ mod test { let (bar_l, qar_l) = calculate_spread_reserves(&market, PositionDirection::Long).unwrap(); let (bar_s, qar_s) = calculate_spread_reserves(&market, PositionDirection::Short).unwrap(); - assert_eq!(amm.quote_asset_reserve, 2000000000); + assert_eq!(amm.quote_asset_reserve(), 2000000000); assert_eq!(qar_s, 2000500000); // down - assert!(qar_l > amm.quote_asset_reserve); - assert!(bar_l < amm.base_asset_reserve); - assert!(qar_s > amm.quote_asset_reserve); - assert!(bar_s < amm.base_asset_reserve); + assert!(qar_l > amm.quote_asset_reserve()); + assert!(bar_l < amm.base_asset_reserve()); + assert!(qar_s > amm.quote_asset_reserve()); + assert!(bar_s < amm.base_asset_reserve()); assert_eq!(bar_s, 1999500124); // up assert_eq!(bar_l, 1971830986); // down assert_eq!(qar_l, 2028571428); // up - let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier).unwrap(); - let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier).unwrap(); + let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier()).unwrap(); + let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier()).unwrap(); assert_eq!(l_price, 1028775); assert_eq!(s_price, 1000500); assert!(l_price > s_price); @@ -527,17 +537,17 @@ mod test { let (bar_l, qar_l) = calculate_spread_reserves(&market, PositionDirection::Long).unwrap(); let (bar_s, qar_s) = calculate_spread_reserves(&market, PositionDirection::Short).unwrap(); - assert!(qar_l > amm.quote_asset_reserve); - assert!(bar_l < amm.base_asset_reserve); - assert!(qar_s < amm.quote_asset_reserve); - assert!(bar_s > amm.base_asset_reserve); + assert!(qar_l > amm.quote_asset_reserve()); + assert!(bar_l < amm.base_asset_reserve()); + assert!(qar_s < amm.quote_asset_reserve()); + assert!(bar_s > amm.base_asset_reserve()); assert_eq!(bar_s, 2001501501); // up assert_eq!(bar_l, 1974025974); // up assert_eq!(qar_l, 2026315789); // down assert_eq!(qar_s, 1998499625); // down - let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier).unwrap(); - let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier).unwrap(); + let l_price = calculate_price(qar_l, bar_l, amm.peg_multiplier()).unwrap(); + let s_price = calculate_price(qar_s, bar_s, amm.peg_multiplier()).unwrap(); assert_eq!(l_price, 1026488); assert_eq!(s_price, 998500); assert!(l_price > s_price); @@ -1671,10 +1681,10 @@ mod test { #[test] fn calculate_prediction_market_spread_tests_low_price() { let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - sqrt_k: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION / 30, // .02 + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (PEG_PRECISION / 30).into(), // .02 long_spread: 10000, short_spread: 10000, base_spread: 10000, @@ -1700,7 +1710,7 @@ mod test { crate::math::amm::calculate_price( new_ask_quote_asset_reserve, new_ask_base_asset_reserve, - market.amm.peg_multiplier, + market.amm.peg_multiplier(), ) .unwrap(), 50001 // over .05 @@ -1710,7 +1720,7 @@ mod test { crate::math::amm::calculate_price( new_bid_quote_asset_reserve, new_bid_base_asset_reserve, - market.amm.peg_multiplier, + market.amm.peg_multiplier(), ) .unwrap(), 33000 @@ -1720,10 +1730,10 @@ mod test { #[test] fn calculate_prediction_market_spread_tests_high_price() { let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - sqrt_k: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: PEG_PRECISION - PEG_PRECISION / 1000, // .999 + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (PEG_PRECISION - PEG_PRECISION / 1000).into(), // .999 long_spread: 10000, short_spread: 10000, base_spread: 10000, @@ -1749,7 +1759,7 @@ mod test { crate::math::amm::calculate_price( new_ask_quote_asset_reserve, new_ask_base_asset_reserve, - market.amm.peg_multiplier, + market.amm.peg_multiplier(), ) .unwrap(), 1000000 // exactly $1 @@ -1759,7 +1769,7 @@ mod test { crate::math::amm::calculate_price( new_bid_quote_asset_reserve, new_bid_base_asset_reserve, - market.amm.peg_multiplier, + market.amm.peg_multiplier(), ) .unwrap(), 949981 // under .95 diff --git a/programs/drift/src/math/bn.rs b/programs/drift/src/math/bn.rs index 0218b2a5a3..3fcbbe11be 100644 --- a/programs/drift/src/math/bn.rs +++ b/programs/drift/src/math/bn.rs @@ -12,6 +12,285 @@ use uint::construct_uint; use crate::error::DriftResult; +pub mod compat { + #![allow(non_camel_case_types)] + use anchor_lang::prelude::{ + borsh::{self}, + AnchorDeserialize, AnchorSerialize, + }; + use bytemuck::{Pod, Zeroable}; + use std::{ + cmp::Ordering, + convert::TryFrom, + ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, + }; + + use crate::{error::DriftResult, math::casting::Cast}; + + /// `u128` with legacy bit layout + #[derive(Copy, Clone, PartialEq, Eq, Debug, Default, AnchorSerialize, AnchorDeserialize)] + pub struct u128([u8; 16]); + + impl std::fmt::Display for self::u128 { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.as_u128(), f) + } + } + + impl PartialOrd for self::u128 { + fn partial_cmp(&self, other: &Self) -> Option { + self.as_u128().partial_cmp(&other.as_u128()) + } + } + + impl PartialOrd for self::i128 { + fn partial_cmp(&self, other: &Self) -> Option { + self.as_i128().partial_cmp(&other.as_i128()) + } + } + + // Safety: u128 is a transparent wrapper around [u8; 16], which is Pod + Zeroable + unsafe impl Pod for self::u128 {} + unsafe impl Zeroable for self::u128 {} + impl u128 { + pub const ONE: Self = u128(1_u128.to_le_bytes()); + pub const ZERO: Self = u128(0_u128.to_le_bytes()); + /// convert to std u128 + #[inline] + pub fn as_u128(self) -> std::primitive::u128 { + std::primitive::u128::from_le_bytes(self.0) + } + pub const fn one() -> Self { + Self::ONE + } + pub const fn zero() -> Self { + Self::ZERO + } + pub fn cast>(&self) -> DriftResult { + self.as_u128().cast() + } + } + impl From for u128 { + fn from(value: std::primitive::u128) -> Self { + u128(value.to_le_bytes()) + } + } + impl From for std::primitive::u128 { + fn from(value: u128) -> Self { + value.as_u128() + } + } + + impl num_traits::Zero for self::u128 { + fn zero() -> Self { + Self::ZERO + } + fn is_zero(&self) -> bool { + self.0 == Self::ZERO.0 + } + } + + // Arithmetic operations for u128 - using From/Into conversions + impl Add for u128 { + type Output = Self; + #[inline(always)] + fn add(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + let b: std::primitive::u128 = other.into(); + Self::from(a + b) + } + } + impl AddAssign for u128 { + #[inline(always)] + fn add_assign(&mut self, other: Self) { + *self = *self + other; + } + } + impl Sub for u128 { + type Output = Self; + #[inline(always)] + fn sub(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + let b: std::primitive::u128 = other.into(); + Self::from(a - b) + } + } + impl SubAssign for u128 { + #[inline(always)] + fn sub_assign(&mut self, other: Self) { + *self = *self - other; + } + } + impl Mul for u128 { + type Output = Self; + #[inline(always)] + fn mul(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + + let b: std::primitive::u128 = other.into(); + Self::from(a * b) + } + } + impl MulAssign for u128 { + #[inline(always)] + fn mul_assign(&mut self, other: Self) { + *self = *self * other; + } + } + impl Div for u128 { + type Output = Self; + #[inline(always)] + fn div(self, other: Self) -> Self { + let a: std::primitive::u128 = self.into(); + + let b: std::primitive::u128 = other.into(); + Self::from(a / b) + } + } + impl DivAssign for u128 { + #[inline(always)] + fn div_assign(&mut self, other: Self) { + *self = *self / other; + } + } + + /// `i128` with legacy bit layout + #[derive(Copy, Clone, PartialEq, Eq, Debug, Default, AnchorSerialize, AnchorDeserialize)] + pub struct i128([u8; 16]); + + impl std::fmt::Display for self::i128 { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Display::fmt(&self.as_i128(), f) + } + } + + // Safety: i128 is a transparent wrapper around [u8; 16], which is Pod + Zeroable + unsafe impl Pod for self::i128 {} + unsafe impl Zeroable for self::i128 {} + impl i128 { + pub const ONE: Self = i128(1_i128.to_le_bytes()); + pub const ZERO: Self = i128(0_i128.to_le_bytes()); + + pub const fn one() -> Self { + Self::ONE + } + pub const fn zero() -> Self { + Self::ZERO + } + + pub fn abs(&self) -> std::primitive::i128 { + self.as_i128().abs() + } + + pub fn unsigned_abs(&self) -> std::primitive::u128 { + self.as_i128().unsigned_abs() + } + + /// convert to std i128 + #[inline] + pub fn as_i128(self) -> std::primitive::i128 { + std::primitive::i128::from_le_bytes(self.0) + } + + pub fn cast>(&self) -> DriftResult { + self.as_i128().cast() + } + } + + impl num_traits::Zero for self::i128 { + fn zero() -> Self { + Self::ZERO + } + fn is_zero(&self) -> bool { + self.0 == Self::ZERO.0 + } + } + + impl std::ops::Neg for self::i128 { + type Output = std::primitive::i128; + fn neg(self) -> Self::Output { + self.as_i128().neg() + } + } + + impl From for i128 { + fn from(value: std::primitive::i128) -> Self { + i128(value.to_le_bytes()) + } + } + impl From for std::primitive::i128 { + fn from(value: i128) -> Self { + value.as_i128() + } + } + + // Arithmetic operations for i128 - using From/Into conversions + impl Add for i128 { + type Output = Self; + #[inline(always)] + fn add(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a + b) + } + } + impl AddAssign for i128 { + #[inline(always)] + fn add_assign(&mut self, other: Self) { + *self = *self + other; + } + } + impl Sub for i128 { + type Output = Self; + #[inline(always)] + fn sub(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a - b) + } + } + impl SubAssign for i128 { + #[inline(always)] + fn sub_assign(&mut self, other: Self) { + *self = *self - other; + } + } + impl Mul for i128 { + type Output = Self; + #[inline(always)] + fn mul(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a * b) + } + } + impl MulAssign for i128 { + #[inline(always)] + fn mul_assign(&mut self, other: Self) { + *self = *self * other; + } + } + impl Div for i128 { + type Output = Self; + #[inline(always)] + fn div(self, other: Self) -> Self { + let a: std::primitive::i128 = self.into(); + + let b: std::primitive::i128 = other.into(); + Self::from(a / b) + } + } + impl DivAssign for i128 { + #[inline(always)] + fn div_assign(&mut self, other: Self) { + *self = *self / other; + } + } +} + construct_uint! { /// 256-bit unsigned integer. pub struct U256(4); diff --git a/programs/drift/src/math/cp_curve.rs b/programs/drift/src/math/cp_curve.rs index 2ac13376f9..2a76fc6086 100644 --- a/programs/drift/src/math/cp_curve.rs +++ b/programs/drift/src/math/cp_curve.rs @@ -41,11 +41,11 @@ pub fn calculate_budgeted_k_scale( )?; let (numerator, denominator) = _calculate_budgeted_k_scale( - market.amm.base_asset_reserve, - market.amm.quote_asset_reserve, + market.amm.base_asset_reserve(), + market.amm.quote_asset_reserve(), budget, - market.amm.peg_multiplier, - market.amm.base_asset_amount_with_amm, + market.amm.peg_multiplier(), + market.amm.base_asset_amount_with_amm(), k_pct_upper_bound, k_pct_lower_bound, )?; @@ -176,7 +176,7 @@ pub fn adjust_k_cost( // Find the net market value before adjusting k let (current_net_market_value, _) = calculate_base_asset_value_and_pnl( - market_clone.amm.base_asset_amount_with_amm, + market_clone.amm.base_asset_amount_with_amm(), 0, &market_clone.amm, )?; @@ -184,7 +184,7 @@ pub fn adjust_k_cost( update_k(&mut market_clone, update_k_result)?; let (_new_net_market_value, cost) = calculate_base_asset_value_and_pnl( - market_clone.amm.base_asset_amount_with_amm, + market_clone.amm.base_asset_amount_with_amm(), current_net_market_value, &market_clone.amm, )?; @@ -201,12 +201,12 @@ pub fn adjust_k_cost_and_update( ) -> DriftResult { // Find the net market value before adjusting k let current_net_market_value = - calculate_base_asset_value(market.amm.base_asset_amount_with_amm, &market.amm)?; + calculate_base_asset_value(market.amm.base_asset_amount_with_amm(), &market.amm)?; update_k(market, update_k_result)?; let (_new_net_market_value, cost) = calculate_base_asset_value_and_pnl( - market.amm.base_asset_amount_with_amm, + market.amm.base_asset_amount_with_amm(), current_net_market_value, &market.amm, )?; @@ -227,7 +227,7 @@ pub fn get_update_k_result( ) -> DriftResult { let sqrt_k_ratio_precision = bn::U192::from(AMM_RESERVE_PRECISION); - let old_sqrt_k = bn::U192::from(market.amm.sqrt_k); + let old_sqrt_k = bn::U192::from(market.amm.sqrt_k()); let mut sqrt_k_ratio = new_sqrt_k .safe_mul(sqrt_k_ratio_precision)? .safe_div(old_sqrt_k)?; @@ -253,14 +253,14 @@ pub fn get_update_k_result( // only allow too small when market is in reduce only mode if market.status != MarketStatus::ReduceOnly && new_sqrt_k < old_sqrt_k - && market.amm.base_asset_amount_with_amm.unsigned_abs() > sqrt_k + && market.amm.base_asset_amount_with_amm().unsigned_abs() > sqrt_k { // todo, check less lp_tokens as well msg!("new_sqrt_k too small relative to market imbalance"); return Err(ErrorCode::InvalidUpdateK); } - let base_asset_reserve = bn::U192::from(market.amm.base_asset_reserve) + let base_asset_reserve = bn::U192::from(market.amm.base_asset_reserve()) .safe_mul(sqrt_k_ratio)? .safe_div(sqrt_k_ratio_precision)? .try_to_u128()?; @@ -280,18 +280,28 @@ pub fn get_update_k_result( } pub fn update_k(market: &mut PerpMarket, update_k_result: &UpdateKResult) -> DriftResult { - market.amm.base_asset_reserve = update_k_result.base_asset_reserve; - market.amm.quote_asset_reserve = update_k_result.quote_asset_reserve; - market.amm.sqrt_k = update_k_result.sqrt_k; + market + .amm + .set_base_asset_reserve(update_k_result.base_asset_reserve); + market + .amm + .set_quote_asset_reserve(update_k_result.quote_asset_reserve); + market.amm.set_sqrt_k(update_k_result.sqrt_k); let (new_terminal_quote_reserve, new_terminal_base_reserve) = amm::calculate_terminal_reserves(&market.amm)?; - market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; + market + .amm + .set_terminal_quote_asset_reserve(new_terminal_quote_reserve); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, new_terminal_base_reserve)?; - market.amm.min_base_asset_reserve = min_base_asset_reserve; - market.amm.max_base_asset_reserve = max_base_asset_reserve; + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), new_terminal_base_reserve)?; + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); let reserve_price_after = market.amm.reserve_price()?; crate::controller::amm::update_spreads(market, reserve_price_after, None)?; diff --git a/programs/drift/src/math/cp_curve/tests.rs b/programs/drift/src/math/cp_curve/tests.rs index b6c8b667b7..6b4379b3bf 100644 --- a/programs/drift/src/math/cp_curve/tests.rs +++ b/programs/drift/src/math/cp_curve/tests.rs @@ -10,9 +10,9 @@ use crate::state::perp_market::AMM; fn k_update_results_bound_flag() { let init_reserves = 100 * AMM_RESERVE_PRECISION; let amm = AMM { - sqrt_k: init_reserves, - base_asset_reserve: init_reserves, - quote_asset_reserve: init_reserves, + sqrt_k: init_reserves.into(), + base_asset_reserve: init_reserves.into(), + quote_asset_reserve: init_reserves.into(), ..AMM::default() }; let market = PerpMarket { @@ -32,18 +32,18 @@ fn k_update_results_bound_flag() { fn calculate_k_tests_with_spread() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: -12295081967, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: (-12295081967).into(), ..AMM::default() }, ..PerpMarket::default() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); market.amm.base_spread = 10; market.amm.long_spread = 5; market.amm.short_spread = 5; @@ -55,21 +55,29 @@ fn calculate_k_tests_with_spread() { crate::math::amm_spread::calculate_spread_reserves(&market, PositionDirection::Short) .unwrap(); - market.amm.ask_base_asset_reserve = new_ask_base_asset_reserve; - market.amm.bid_base_asset_reserve = new_bid_base_asset_reserve; - market.amm.ask_quote_asset_reserve = new_ask_quote_asset_reserve; - market.amm.bid_quote_asset_reserve = new_bid_quote_asset_reserve; + market + .amm + .set_ask_base_asset_reserve(new_ask_base_asset_reserve); + market + .amm + .set_bid_base_asset_reserve(new_bid_base_asset_reserve); + market + .amm + .set_ask_quote_asset_reserve(new_ask_quote_asset_reserve); + market + .amm + .set_bid_quote_asset_reserve(new_bid_quote_asset_reserve); validate!( - market.amm.bid_base_asset_reserve >= market.amm.base_asset_reserve - && market.amm.bid_quote_asset_reserve <= market.amm.quote_asset_reserve, + market.amm.bid_base_asset_reserve() >= market.amm.base_asset_reserve() + && market.amm.bid_quote_asset_reserve() <= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market index {} amm bid reserves invalid: {} -> {}, quote: {} -> {}", market.market_index, - market.amm.bid_base_asset_reserve, - market.amm.base_asset_reserve, - market.amm.bid_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.bid_base_asset_reserve(), + market.amm.base_asset_reserve(), + market.amm.bid_quote_asset_reserve(), + market.amm.quote_asset_reserve() ) .unwrap(); @@ -79,14 +87,14 @@ fn calculate_k_tests_with_spread() { update_k(&mut market, &update_k_result).unwrap(); validate!( - market.amm.bid_base_asset_reserve >= market.amm.base_asset_reserve - && market.amm.bid_quote_asset_reserve <= market.amm.quote_asset_reserve, + market.amm.bid_base_asset_reserve() >= market.amm.base_asset_reserve() + && market.amm.bid_quote_asset_reserve() <= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "bid reserves out of wack: {} -> {}, quote: {} -> {}", - market.amm.bid_base_asset_reserve, - market.amm.base_asset_reserve, - market.amm.bid_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.bid_base_asset_reserve(), + market.amm.base_asset_reserve(), + market.amm.bid_quote_asset_reserve(), + market.amm.quote_asset_reserve() ) .unwrap(); } @@ -103,12 +111,12 @@ fn calculate_k_with_rounding() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve, - quote_asset_reserve, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - sqrt_k: 10000000000000000000, - peg_multiplier, - base_asset_amount_with_amm, + base_asset_reserve: base_asset_reserve.into(), + quote_asset_reserve: quote_asset_reserve.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + sqrt_k: 10000000000000000000.into(), + peg_multiplier: peg_multiplier.into(), + base_asset_amount_with_amm: base_asset_amount_with_amm.into(), ..AMM::default() }, ..PerpMarket::default() @@ -132,7 +140,7 @@ fn calculate_k_with_rounding() { let k_scale_numerator: u128 = 373175; let k_scale_denominator: u128 = 340980; - let new_sqrt_k = bn::U192::from(market.amm.sqrt_k) + let new_sqrt_k = bn::U192::from(market.amm.sqrt_k()) .safe_mul(bn::U192::from(k_scale_numerator)) .unwrap() .safe_div(bn::U192::from(k_scale_denominator)) @@ -149,12 +157,12 @@ fn calculate_k_with_rounding() { fn calculate_k_tests() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: -12295081967, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: (-12295081967).into(), ..AMM::default() }, ..PerpMarket::default() @@ -167,7 +175,7 @@ fn calculate_k_tests() { // new terminal reserves are balanced, terminal price = peg) assert_eq!(t_qar, 500 * AMM_RESERVE_PRECISION); assert_eq!(t_bar, 500 * AMM_RESERVE_PRECISION); - assert_eq!(t_price as u128, market.amm.peg_multiplier); + assert_eq!(t_price as u128, market.amm.peg_multiplier()); assert_eq!(update_k_up.sqrt_k, 501 * AMM_RESERVE_PRECISION); assert_eq!(update_k_up.base_asset_reserve, 513319672130); @@ -175,7 +183,7 @@ fn calculate_k_tests() { // cost to increase k is always positive when imbalanced let cost = adjust_k_cost_and_update(&mut market, &update_k_up).unwrap(); - assert_eq!(market.amm.terminal_quote_asset_reserve, 500975411043); + assert_eq!(market.amm.terminal_quote_asset_reserve(), 500975411043); assert!(cost > 0); assert_eq!(cost, 29448); @@ -279,11 +287,11 @@ fn calculate_k_tests() { fn calculate_k_tests_wrapper_fcn() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: AMM_RESERVE_PRECISION * 55414, - quote_asset_reserve: AMM_RESERVE_PRECISION * 55530, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 36365000, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION * 66) as i128, + base_asset_reserve: (AMM_RESERVE_PRECISION * 55414).into(), + quote_asset_reserve: (AMM_RESERVE_PRECISION * 55530).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 36365000.into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION * 66) as i128).into(), ..AMM::default() }, ..PerpMarket::default() @@ -309,13 +317,13 @@ fn calculate_k_tests_wrapper_fcn() { fn amm_spread_adj_logic() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - terminal_quote_asset_reserve: 999900009999000 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 50_000_000_000, - base_asset_amount_with_amm: (AMM_RESERVE_PRECISION / 10) as i128, - base_asset_amount_long: (AMM_RESERVE_PRECISION / 10) as i128, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + terminal_quote_asset_reserve: (999900009999000 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50_000_000_000.into(), + base_asset_amount_with_amm: ((AMM_RESERVE_PRECISION / 10) as i128).into(), + base_asset_amount_long: ((AMM_RESERVE_PRECISION / 10) as i128).into(), order_step_size: 5, base_spread: 100, max_spread: 10000, @@ -329,8 +337,10 @@ fn amm_spread_adj_logic() { // todo fix this - market.amm.base_asset_amount_per_lp = 1; - market.amm.quote_asset_amount_per_lp = -QUOTE_PRECISION_I64 as i128; + market.amm.set_base_asset_amount_per_lp(1); + market + .amm + .set_quote_asset_amount_per_lp(-QUOTE_PRECISION_I64 as i128); let reserve_price = market.amm.reserve_price().unwrap(); update_spreads(&mut market, reserve_price, None).unwrap(); diff --git a/programs/drift/src/math/fees.rs b/programs/drift/src/math/fees.rs index 8431be24bf..d227f1cf18 100644 --- a/programs/drift/src/math/fees.rs +++ b/programs/drift/src/math/fees.rs @@ -265,6 +265,7 @@ fn calculate_filler_reward( let min_time_filler_reward = filler_reward_structure .time_based_reward_lower_bound + .as_u128() .safe_mul( multiplier .cast::()? diff --git a/programs/drift/src/math/fees/tests.rs b/programs/drift/src/math/fees/tests.rs index 296f3bfce5..d24470c161 100644 --- a/programs/drift/src/math/fees/tests.rs +++ b/programs/drift/src/math/fees/tests.rs @@ -53,7 +53,7 @@ mod calculate_fee_for_taker_and_maker { let mut fee_structure = FeeStructure::test_default(); fee_structure .filler_reward_structure - .time_based_reward_lower_bound = 10000000000000000; // big number + .time_based_reward_lower_bound = 10000000000000000.into(); // big number let FillFees { user_fee: taker_fee, @@ -1020,7 +1020,7 @@ mod calcuate_fee_tiers { filler_reward_structure: OrderFillerRewardStructure { reward_numerator: 10, reward_denominator: FEE_PERCENTAGE_DENOMINATOR, - time_based_reward_lower_bound: 10_000, // 1 cent + time_based_reward_lower_bound: 10_000.into(), // 1 cent }, flat_filler_fee: 10_000, referrer_reward_epoch_upper_bound: MAX_REFERRER_REWARD_EPOCH_UPPER_BOUND, diff --git a/programs/drift/src/math/floor_div.rs b/programs/drift/src/math/floor_div.rs index fb1fa0ed2a..9e07ed8c68 100644 --- a/programs/drift/src/math/floor_div.rs +++ b/programs/drift/src/math/floor_div.rs @@ -12,7 +12,6 @@ macro_rules! checked_impl { #[inline] fn checked_floor_div(&self, rhs: $t) -> Option<$t> { let quotient = self.checked_div(rhs)?; - let remainder = self.checked_rem(rhs)?; if remainder != <$t>::zero() { diff --git a/programs/drift/src/math/fulfillment/tests.rs b/programs/drift/src/math/fulfillment/tests.rs index 005bbefa63..c99da241d8 100644 --- a/programs/drift/src/math/fulfillment/tests.rs +++ b/programs/drift/src/math/fulfillment/tests.rs @@ -14,14 +14,14 @@ mod determine_perp_fulfillment_methods { fn amm_available_and_taker_doesnt_cross_maker() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -41,8 +41,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -69,14 +69,14 @@ mod determine_perp_fulfillment_methods { fn amm_available_and_maker_better_than_amm() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -96,8 +96,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -130,14 +130,14 @@ mod determine_perp_fulfillment_methods { fn amm_available_and_amm_better_than_maker() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -157,8 +157,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -198,14 +198,14 @@ mod determine_perp_fulfillment_methods { fn maker_amm_maker_amm_maker_ask() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -225,8 +225,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -264,14 +264,14 @@ mod determine_perp_fulfillment_methods { fn maker_maker_amm_ask() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -291,8 +291,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -337,14 +337,14 @@ mod determine_perp_fulfillment_methods { fn amm_maker_amm_maker_amm_ask() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -364,8 +364,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -404,14 +404,14 @@ mod determine_perp_fulfillment_methods { fn maker_amm_maker_amm_maker_bid() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -431,8 +431,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Short, @@ -470,14 +470,14 @@ mod determine_perp_fulfillment_methods { fn maker_maker_amm_bid() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -497,8 +497,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Short, @@ -535,14 +535,14 @@ mod determine_perp_fulfillment_methods { fn amm_maker_amm_maker_amm_bid() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -562,8 +562,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Short, @@ -602,14 +602,14 @@ mod determine_perp_fulfillment_methods { fn no_asks() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -629,8 +629,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Long, @@ -660,14 +660,14 @@ mod determine_perp_fulfillment_methods { fn no_bids() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -687,8 +687,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { direction: PositionDirection::Short, @@ -718,14 +718,14 @@ mod determine_perp_fulfillment_methods { fn amm_available_and_maker_crosses() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -745,8 +745,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { post_only: true, @@ -774,14 +774,14 @@ mod determine_perp_fulfillment_methods { fn amm_available_and_maker_doesnt_cross() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 10000000, @@ -801,8 +801,8 @@ mod determine_perp_fulfillment_methods { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); let taker_order = Order { post_only: true, diff --git a/programs/drift/src/math/funding.rs b/programs/drift/src/math/funding.rs index c723cb37bb..09c915027d 100644 --- a/programs/drift/src/math/funding.rs +++ b/programs/drift/src/math/funding.rs @@ -27,7 +27,7 @@ pub fn calculate_funding_rate_long_short( ) -> DriftResult<(i128, i128, i128)> { // Calculate the funding payment owed by the net_market_position if funding is not capped // If the net market position owes funding payment, the protocol receives payment - let settled_net_market_position = market.amm.base_asset_amount_with_amm; + let settled_net_market_position = market.amm.base_asset_amount_with_amm(); let net_market_position_funding_payment = calculate_funding_payment_in_quote_precision(funding_rate, settled_net_market_position)?; @@ -35,10 +35,12 @@ pub fn calculate_funding_rate_long_short( // If the uncapped_funding_pnl is positive, the protocol receives money. if uncapped_funding_pnl >= 0 { - market.amm.total_fee_minus_distributions = market - .amm - .total_fee_minus_distributions - .safe_add(uncapped_funding_pnl)?; + market.amm.set_total_fee_minus_distributions( + market + .amm + .total_fee_minus_distributions() + .safe_add(uncapped_funding_pnl)?, + ); market.amm.net_revenue_since_last_funding = market .amm @@ -53,7 +55,7 @@ pub fn calculate_funding_rate_long_short( let new_total_fee_minus_distributions = market .amm - .total_fee_minus_distributions + .total_fee_minus_distributions() .safe_add(capped_funding_pnl)?; // protocol is paying part of funding imbalance @@ -67,7 +69,9 @@ pub fn calculate_funding_rate_long_short( return Err(ErrorCode::InvalidFundingProfitability); } } - market.amm.total_fee_minus_distributions = new_total_fee_minus_distributions; + market + .amm + .set_total_fee_minus_distributions(new_total_fee_minus_distributions); market.amm.net_revenue_since_last_funding = market .amm .net_revenue_since_last_funding @@ -107,9 +111,9 @@ fn calculate_capped_funding_rate( let funding_payment_from_users = calculate_funding_payment_in_quote_precision( funding_rate, if funding_rate > 0 { - market.amm.base_asset_amount_long + market.amm.base_asset_amount_long() } else { - market.amm.base_asset_amount_short + market.amm.base_asset_amount_short() }, )?; @@ -122,13 +126,13 @@ fn calculate_capped_funding_rate( // longs receive calculate_funding_rate_from_pnl_limit( funding_rate_pnl_limit, - market.amm.base_asset_amount_long, + market.amm.base_asset_amount_long(), )? } else { // shorts receive calculate_funding_rate_from_pnl_limit( funding_rate_pnl_limit, - market.amm.base_asset_amount_short, + market.amm.base_asset_amount_short(), )? } } else { diff --git a/programs/drift/src/math/funding/tests.rs b/programs/drift/src/math/funding/tests.rs index fb46a5cbce..b8771fb492 100644 --- a/programs/drift/src/math/funding/tests.rs +++ b/programs/drift/src/math/funding/tests.rs @@ -63,15 +63,15 @@ fn balanced_funding_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: sqrt_k, - quote_asset_reserve: sqrt_k, - sqrt_k, - peg_multiplier: px, - base_asset_amount_with_amm: 0, - base_asset_amount_long: 12295081967, - base_asset_amount_short: -12295081967, - total_exchange_fee: (count * 1000000783) / 2888, - total_fee_minus_distributions: (count * 1000000783) as i128, + base_asset_reserve: sqrt_k.into(), + quote_asset_reserve: sqrt_k.into(), + sqrt_k: sqrt_k.into(), + peg_multiplier: px.into(), + base_asset_amount_with_amm: 0.into(), + base_asset_amount_long: 12295081967.into(), + base_asset_amount_short: (-12295081967).into(), + total_exchange_fee: ((count * 1000000783) / 2888).into(), + total_fee_minus_distributions: ((count * 1000000783) as i128).into(), last_mark_price_twap: (px * 999 / 1000) as u64, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (px * 1001 / 1000) as i64, @@ -115,15 +115,15 @@ fn balanced_funding_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: sqrt_k, - quote_asset_reserve: sqrt_k, - sqrt_k, - peg_multiplier: px, - base_asset_amount_with_amm: 0, - base_asset_amount_long: 7845926098328, - base_asset_amount_short: -7845926098328, - total_exchange_fee: (count * 1000000783) / 2888, - total_fee_minus_distributions: (count * 1000000783) as i128, + base_asset_reserve: sqrt_k.into(), + quote_asset_reserve: sqrt_k.into(), + sqrt_k: sqrt_k.into(), + peg_multiplier: px.into(), + base_asset_amount_with_amm: 0.into(), + base_asset_amount_long: 7845926098328.into(), + base_asset_amount_short: (-7845926098328).into(), + total_exchange_fee: ((count * 1000000783) / 2888).into(), + total_fee_minus_distributions: ((count * 1000000783) as i128).into(), last_mark_price_twap: (px * 999 / 1000) as u64, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (px * 888 / 1000) as i64, @@ -172,15 +172,15 @@ fn capped_sym_funding_test() { // more shorts than longs, positive funding, 1/3 of fee pool too small let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: -12295081967, - base_asset_amount_long: 12295081967, - base_asset_amount_short: -12295081967 * 2, - total_exchange_fee: QUOTE_PRECISION / 2, - total_fee_minus_distributions: (QUOTE_PRECISION as i128) / 2, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: (-12295081967).into(), + base_asset_amount_long: 12295081967.into(), + base_asset_amount_short: (-12295081967 * 2).into(), + total_exchange_fee: (QUOTE_PRECISION / 2).into(), + total_fee_minus_distributions: ((QUOTE_PRECISION as i128) / 2).into(), last_mark_price_twap: 50 * PRICE_PRECISION_U64, historical_oracle_data: HistoricalOracleData { @@ -212,20 +212,20 @@ fn capped_sym_funding_test() { assert_eq!(short_funding, 24222164); // only spend 1/3 of fee pool, ((.5-.416667)) * 3 < .25 - assert_eq!(market.amm.total_fee_minus_distributions, 416667); + assert_eq!(market.amm.total_fee_minus_distributions(), 416667); // more longs than shorts, positive funding, amm earns funding market = PerpMarket { amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: 12295081967, - base_asset_amount_long: 12295081967 * 2, - base_asset_amount_short: -12295081967, - total_exchange_fee: QUOTE_PRECISION / 2, - total_fee_minus_distributions: (QUOTE_PRECISION as i128) / 2, + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: 12295081967.into(), + base_asset_amount_long: (12295081967 * 2).into(), + base_asset_amount_short: (-12295081967).into(), + total_exchange_fee: (QUOTE_PRECISION / 2).into(), + total_fee_minus_distributions: ((QUOTE_PRECISION as i128) / 2).into(), last_mark_price_twap: 50 * PRICE_PRECISION_U64, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: (49 * PRICE_PRECISION) as i64, @@ -246,7 +246,7 @@ fn capped_sym_funding_test() { assert_eq!(long_funding, balanced_funding); assert_eq!(long_funding, short_funding); - let new_fees = market.amm.total_fee_minus_distributions; + let new_fees = market.amm.total_fee_minus_distributions(); assert!(new_fees > QUOTE_PRECISION as i128 / 2); assert_eq!(new_fees, 1012295); // made over $.50 } @@ -285,16 +285,16 @@ fn max_funding_rates() { amm: AMM { oracle: oracle_price_key, - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: -12295081967, //~12 - base_asset_amount_long: 12295081967, - base_asset_amount_short: -12295081967 * 2, - base_asset_amount_with_unsettled_lp: -((AMM_RESERVE_PRECISION * 500) as i128), //wowsers - total_exchange_fee: QUOTE_PRECISION / 2, - total_fee_minus_distributions: ((QUOTE_PRECISION * 99999) as i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: (-12295081967).into(), //~12 + base_asset_amount_long: 12295081967.into(), + base_asset_amount_short: (-12295081967 * 2).into(), + base_asset_amount_with_unsettled_lp: (-((AMM_RESERVE_PRECISION * 500) as i128)).into(), //wowsers + total_exchange_fee: (QUOTE_PRECISION / 2).into(), + total_fee_minus_distributions: ((QUOTE_PRECISION * 99999) as i128).into(), last_mark_price_twap: 50 * PRICE_PRECISION_U64, historical_oracle_data: HistoricalOracleData { @@ -372,15 +372,16 @@ fn unsettled_funding_pnl() { amm: AMM { oracle: oracle_price_key, - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 50000000, - base_asset_amount_with_amm: -12295081967 + -((AMM_RESERVE_PRECISION * 500) as i128), //~ 12 - 500 - base_asset_amount_long: 12295081967, - base_asset_amount_short: -12295081967 * 2, - total_exchange_fee: QUOTE_PRECISION / 2, - total_fee_minus_distributions: ((QUOTE_PRECISION * 99999) as i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 50000000.into(), + base_asset_amount_with_amm: (-12295081967 + -((AMM_RESERVE_PRECISION * 500) as i128)) + .into(), //~ 12 - 500 + base_asset_amount_long: 12295081967.into(), + base_asset_amount_short: (-12295081967 * 2).into(), + total_exchange_fee: (QUOTE_PRECISION / 2).into(), + total_fee_minus_distributions: ((QUOTE_PRECISION * 99999) as i128).into(), last_mark_price_twap: 50 * PRICE_PRECISION_U64, historical_oracle_data: HistoricalOracleData { @@ -455,7 +456,7 @@ fn unsettled_funding_pnl() { ) .unwrap(); assert_eq!(block_funding_rate_update, false); - assert_eq!(market.amm.total_fee_minus_distributions, 99999000000); + assert_eq!(market.amm.total_fee_minus_distributions(), 99999000000); let did_succeed = update_funding_rate( 0, @@ -477,14 +478,14 @@ fn unsettled_funding_pnl() { 51000000 ); - assert_eq!(market.amm.cumulative_funding_rate_long, -140002666); // negative funding - assert_eq!(market.amm.cumulative_funding_rate_short, -140002666); + assert_eq!(market.amm.cumulative_funding_rate_long(), -140002666); // negative funding + assert_eq!(market.amm.cumulative_funding_rate_short(), -140002666); assert_eq!(market.amm.last_funding_rate, -140002666); assert_eq!(market.amm.last_24h_avg_funding_rate, -140002666 / 24 + 1); assert_eq!(market.amm.last_funding_rate_ts, now); assert_eq!(market.amm.net_revenue_since_last_funding, 0); // back to 0 - assert_eq!(market.amm.total_fee_minus_distributions, 100070722677); //71.722677 gain - assert_eq!(market.amm.total_fee, 0); + assert_eq!(market.amm.total_fee_minus_distributions(), 100070722677); //71.722677 gain + assert_eq!(market.amm.total_fee(), 0); assert_ne!(market.amm.net_unsettled_funding_pnl, 0); // important: imbalanced market adds funding rev assert_eq!(market.amm.net_unsettled_funding_pnl, -71722677); // users up diff --git a/programs/drift/src/math/insurance.rs b/programs/drift/src/math/insurance.rs index 4658f97db6..10329814c6 100644 --- a/programs/drift/src/math/insurance.rs +++ b/programs/drift/src/math/insurance.rs @@ -87,18 +87,21 @@ pub fn calculate_if_shares_lost( spot_market: &SpotMarket, insurance_fund_vault_balance: u64, ) -> DriftResult { - let n_shares = insurance_fund_stake.last_withdraw_request_shares; + let n_shares = insurance_fund_stake.last_withdraw_request_shares(); let amount = if_shares_to_vault_amount( n_shares, - spot_market.insurance_fund.total_shares, + spot_market.insurance_fund.total_shares(), insurance_fund_vault_balance, )?; let if_shares_lost = if amount > insurance_fund_stake.last_withdraw_request_value { let new_n_shares = vault_amount_to_if_shares( insurance_fund_stake.last_withdraw_request_value, - spot_market.insurance_fund.total_shares.safe_sub(n_shares)?, + spot_market + .insurance_fund + .total_shares() + .safe_sub(n_shares)?, insurance_fund_vault_balance .safe_sub(insurance_fund_stake.last_withdraw_request_value)?, )?; diff --git a/programs/drift/src/math/insurance/tests.rs b/programs/drift/src/math/insurance/tests.rs index 46287cedb3..69cb54095f 100644 --- a/programs/drift/src/math/insurance/tests.rs +++ b/programs/drift/src/math/insurance/tests.rs @@ -101,12 +101,12 @@ pub fn basic_stake_if_test() { pub fn if_shares_lost_test() { let _amount = QUOTE_PRECISION as u64; // $1 let mut spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), insurance_fund: InsuranceFund { unstaking_period: 0, - total_shares: 1000 * QUOTE_PRECISION, - user_shares: 1000 * QUOTE_PRECISION, + total_shares: (1000 * QUOTE_PRECISION).into(), + user_shares: (1000 * QUOTE_PRECISION).into(), ..InsuranceFund::default() }, ..SpotMarket::default() @@ -116,7 +116,7 @@ pub fn if_shares_lost_test() { if_stake .update_if_shares(100 * QUOTE_PRECISION, &spot_market) .unwrap(); - if_stake.last_withdraw_request_shares = 100 * QUOTE_PRECISION; + if_stake.set_last_withdraw_request_shares(100 * QUOTE_PRECISION); if_stake.last_withdraw_request_value = ((100 * QUOTE_PRECISION) - 1) as u64; let if_balance = (1000 * QUOTE_PRECISION) as u64; @@ -126,14 +126,38 @@ pub fn if_shares_lost_test() { assert_eq!(lost_shares, 2); let if_balance = if_balance + (100 * QUOTE_PRECISION) as u64; - spot_market.insurance_fund.total_shares += 100 * QUOTE_PRECISION; - spot_market.insurance_fund.user_shares += 100 * QUOTE_PRECISION; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_add(100 * QUOTE_PRECISION) + .unwrap(), + ); + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_add(100 * QUOTE_PRECISION) + .unwrap(), + ); let lost_shares = calculate_if_shares_lost(&if_stake, &spot_market, if_balance).unwrap(); assert_eq!(lost_shares, 2); // giving up $5 of gains let if_balance = if_balance - (100 * QUOTE_PRECISION) as u64; - spot_market.insurance_fund.total_shares -= 100 * QUOTE_PRECISION; - spot_market.insurance_fund.user_shares -= 100 * QUOTE_PRECISION; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_sub(100 * QUOTE_PRECISION) + .unwrap(), + ); + spot_market.insurance_fund.set_user_shares( + spot_market + .insurance_fund + .user_shares() + .safe_sub(100 * QUOTE_PRECISION) + .unwrap(), + ); let lost_shares = calculate_if_shares_lost(&if_stake, &spot_market, if_balance).unwrap(); assert_eq!(lost_shares, 2); // giving up $5 of gains @@ -150,19 +174,13 @@ pub fn if_shares_lost_test() { // take back gain and total_if_shares alter w/o user alter let if_balance = (2100 * QUOTE_PRECISION) as u64; - spot_market.insurance_fund.total_shares *= 2; + spot_market.insurance_fund.set_total_shares( + spot_market + .insurance_fund + .total_shares() + .safe_mul(2) + .unwrap(), + ); let lost_shares = calculate_if_shares_lost(&if_stake, &spot_market, if_balance).unwrap(); assert_eq!(lost_shares, 5_000_001); // giving up $5 of gains - - let if_balance = (2100 * QUOTE_PRECISION * 10) as u64; - - let expected_gain_if_no_loss = if_balance * 100 / 2000; - assert_eq!(expected_gain_if_no_loss, 1_050_000_000); - let lost_shares = calculate_if_shares_lost(&if_stake, &spot_market, if_balance).unwrap(); - assert_eq!(lost_shares, 90_909_092); // giving up $5 of gains - assert_eq!( - (9090908 * if_balance / ((spot_market.insurance_fund.total_shares - lost_shares) as u64)) - < if_stake.last_withdraw_request_value, - true - ); } diff --git a/programs/drift/src/math/liquidation.rs b/programs/drift/src/math/liquidation.rs index dbe608ceaa..229575f10f 100644 --- a/programs/drift/src/math/liquidation.rs +++ b/programs/drift/src/math/liquidation.rs @@ -265,9 +265,9 @@ pub fn calculate_funding_rate_deltas_to_resolve_bankruptcy( ) -> DriftResult { let total_base_asset_amount = market .amm - .base_asset_amount_long + .base_asset_amount_long() .abs() - .safe_add(market.amm.base_asset_amount_short.abs())?; + .safe_add(market.amm.base_asset_amount_short().abs())?; validate!( total_base_asset_amount != 0, @@ -286,13 +286,13 @@ pub fn calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy( spot_market: &SpotMarket, ) -> DriftResult { let total_deposits = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; spot_market - .cumulative_deposit_interest + .cumulative_deposit_interest() .safe_mul(borrow)? .safe_div_ceil(total_deposits) .or(Ok(0)) diff --git a/programs/drift/src/math/liquidation/tests.rs b/programs/drift/src/math/liquidation/tests.rs index 17315dabbf..4566d017a6 100644 --- a/programs/drift/src/math/liquidation/tests.rs +++ b/programs/drift/src/math/liquidation/tests.rs @@ -503,8 +503,8 @@ mod calculate_funding_rate_deltas_to_resolve_bankruptcy { let loss = -QUOTE_PRECISION_I128; let market = PerpMarket { amm: AMM { - base_asset_amount_long: 0, - base_asset_amount_short: 0, + base_asset_amount_long: 0.into(), + base_asset_amount_short: 0.into(), ..AMM::default() }, ..PerpMarket::default() @@ -518,8 +518,8 @@ mod calculate_funding_rate_deltas_to_resolve_bankruptcy { let loss = -100 * QUOTE_PRECISION_I128; let market = PerpMarket { amm: AMM { - base_asset_amount_long: 7 * BASE_PRECISION_I128, - base_asset_amount_short: -4 * BASE_PRECISION_I128, + base_asset_amount_long: (7 * BASE_PRECISION_I128).into(), + base_asset_amount_short: (-4 * BASE_PRECISION_I128).into(), ..AMM::default() }, ..PerpMarket::default() @@ -543,8 +543,8 @@ mod calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy { fn zero_total_deposits() { let loss = 100 * QUOTE_PRECISION; let spot_market = SpotMarket { - deposit_balance: 0, - cumulative_deposit_interest: 1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000, + deposit_balance: 0.into(), + cumulative_deposit_interest: (1111 * SPOT_CUMULATIVE_INTEREST_PRECISION / 1000).into(), ..SpotMarket::default() }; @@ -559,8 +559,8 @@ mod calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy { fn non_zero_total_deposits() { let loss = 11 * QUOTE_PRECISION; let spot_market = SpotMarket { - deposit_balance: 120 * SPOT_BALANCE_PRECISION, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + deposit_balance: (120 * SPOT_BALANCE_PRECISION).into(), + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, ..SpotMarket::default() }; @@ -574,14 +574,13 @@ mod calculate_cumulative_deposit_interest_delta_to_resolve_bankruptcy { } mod validate_transfer_satisfies_limit_price { - use crate::math::constants::{PRICE_PRECISION_U64, QUOTE_PRECISION}; + use crate::math::constants::{LAMPORTS_PER_SOL_U64, PRICE_PRECISION_U64, QUOTE_PRECISION}; use crate::math::liquidation::validate_transfer_satisfies_limit_price; - use anchor_lang::solana_program::native_token::LAMPORTS_PER_SOL; #[test] fn sol_asset_usdc_liability() { let limit_price = PRICE_PRECISION_U64 / 100; // 1 SOL / $100 USD - let asset = LAMPORTS_PER_SOL as u128; + let asset = LAMPORTS_PER_SOL_U64 as u128; let asset_decimals = 9_u32; let liability = 100 * QUOTE_PRECISION; let liability_decimals = 6_u32; @@ -611,7 +610,7 @@ mod validate_transfer_satisfies_limit_price { let limit_price = PRICE_PRECISION_U64 * 100; // $100 / 1 SOL let asset = 100 * QUOTE_PRECISION; let asset_decimals = 6_u32; - let liability = LAMPORTS_PER_SOL as u128; + let liability = LAMPORTS_PER_SOL_U64 as u128; let liability_decimals = 9_u32; assert!(validate_transfer_satisfies_limit_price( diff --git a/programs/drift/src/math/margin.rs b/programs/drift/src/math/margin.rs index fc31624842..ebeb029dca 100644 --- a/programs/drift/src/math/margin.rs +++ b/programs/drift/src/math/margin.rs @@ -154,9 +154,9 @@ pub fn calculate_perp_position_value_and_pnl( // the funding must be calculated before calculated the unrealized pnl w simulated lp position let unrealized_funding = calculate_funding_payment( if market_position.base_asset_amount > 0 { - market.amm.cumulative_funding_rate_long + market.amm.cumulative_funding_rate_long() } else { - market.amm.cumulative_funding_rate_short + market.amm.cumulative_funding_rate_short() }, market_position, )?; @@ -1060,9 +1060,9 @@ pub fn calculate_user_equity( let unrealized_funding = calculate_funding_payment( if market_position.base_asset_amount > 0 { - market.amm.cumulative_funding_rate_long + market.amm.cumulative_funding_rate_long() } else { - market.amm.cumulative_funding_rate_short + market.amm.cumulative_funding_rate_short() }, market_position, )?; diff --git a/programs/drift/src/math/margin/tests.rs b/programs/drift/src/math/margin/tests.rs index d4b1eefd2e..155068212f 100644 --- a/programs/drift/src/math/margin/tests.rs +++ b/programs/drift/src/math/margin/tests.rs @@ -195,34 +195,34 @@ mod test { decimals: 9, imf_factor: 0, scale_initial_asset_weight_start: 500_000 * QUOTE_PRECISION_U64, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), ..SpotMarket::default() }; let oracle_price = 25 * PRICE_PRECISION_I64; - sol_spot_market.deposit_balance = SPOT_BALANCE_PRECISION; + sol_spot_market.set_deposit_balance(SPOT_BALANCE_PRECISION); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 9000); - sol_spot_market.deposit_balance = 20000 * SPOT_BALANCE_PRECISION; + sol_spot_market.set_deposit_balance(20000 * SPOT_BALANCE_PRECISION); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 9000); - sol_spot_market.deposit_balance = 40000 * SPOT_BALANCE_PRECISION; + sol_spot_market.set_deposit_balance(40000 * SPOT_BALANCE_PRECISION); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); assert_eq!(asset_weight, 4500); - sol_spot_market.deposit_balance = 60000 * SPOT_BALANCE_PRECISION; + sol_spot_market.set_deposit_balance(60000 * SPOT_BALANCE_PRECISION); let asset_weight = sol_spot_market .get_scaled_initial_asset_weight(oracle_price) .unwrap(); @@ -235,11 +235,11 @@ mod test { let mut market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: -(12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (-(12295081967_i128)).into(), max_spread: 1000, ..AMM::default() }, @@ -443,11 +443,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -457,8 +457,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -534,11 +534,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -548,8 +548,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -625,13 +625,13 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -641,15 +641,15 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, initial_liability_weight: 12 * SPOT_WEIGHT_PRECISION / 10, maintenance_liability_weight: 11 * SPOT_WEIGHT_PRECISION / 10, liquidator_fee: LIQUIDATION_FEE_PRECISION / 1000, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), ..SpotMarket::default() }; create_anchor_account_info!(sol_spot_market, SpotMarket, sol_spot_market_account_info); @@ -716,14 +716,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -739,11 +739,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -753,8 +753,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -913,14 +913,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -936,11 +936,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -950,8 +950,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1098,14 +1098,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1121,11 +1121,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1135,8 +1135,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1224,14 +1224,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1247,11 +1247,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1261,8 +1261,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION / 99, // big loss - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: (SPOT_CUMULATIVE_INTEREST_PRECISION / 99).into(), // big loss + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1347,14 +1347,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1370,11 +1370,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1384,8 +1384,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1520,11 +1520,11 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap_5min: PRICE_PRECISION_I64 * 9 / 10, @@ -1537,8 +1537,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1614,14 +1614,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1637,12 +1637,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1652,8 +1652,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1731,14 +1731,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1754,12 +1754,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1769,8 +1769,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1843,14 +1843,14 @@ mod calculate_margin_requirement_and_total_collateral { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -1866,12 +1866,12 @@ mod calculate_margin_requirement_and_total_collateral { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1881,8 +1881,8 @@ mod calculate_margin_requirement_and_total_collateral { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1985,14 +1985,14 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -2008,11 +2008,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2022,8 +2022,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2096,14 +2096,14 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -2120,11 +2120,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2134,8 +2134,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2253,14 +2253,14 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -2276,11 +2276,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2290,8 +2290,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2379,11 +2379,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), oracle: usdc_oracle_price_key, @@ -2394,8 +2394,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2530,13 +2530,13 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, - borrow_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), + borrow_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), oracle: usdc_oracle_price_key, @@ -2547,8 +2547,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2676,11 +2676,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::PythStableCoin, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_price(usdc_price), oracle: usdc_oracle_price_key, @@ -2691,8 +2691,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: usdc_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2711,14 +2711,14 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -2830,14 +2830,14 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -2853,11 +2853,11 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2867,8 +2867,8 @@ mod calculate_margin_requirement_and_total_collateral_and_liability_info { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -2970,11 +2970,11 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2984,8 +2984,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3056,12 +3056,12 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, liquidator_fee: 0, @@ -3073,8 +3073,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3144,12 +3144,12 @@ mod calculate_max_withdrawable_amount { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), initial_liability_weight: SPOT_WEIGHT_PRECISION, maintenance_liability_weight: SPOT_WEIGHT_PRECISION, liquidator_fee: 0, @@ -3161,8 +3161,8 @@ mod calculate_max_withdrawable_amount { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3260,11 +3260,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3273,8 +3273,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3343,11 +3343,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3356,8 +3356,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3426,11 +3426,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3439,8 +3439,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3509,11 +3509,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3522,8 +3522,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3592,11 +3592,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3605,8 +3605,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3675,11 +3675,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3688,8 +3688,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3755,14 +3755,14 @@ mod validate_spot_margin_trading { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -3780,11 +3780,11 @@ mod validate_spot_margin_trading { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; @@ -3793,8 +3793,8 @@ mod validate_spot_margin_trading { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -3902,14 +3902,14 @@ mod calculate_user_equity { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3930,8 +3930,8 @@ mod calculate_user_equity { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3939,11 +3939,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -4000,14 +4000,14 @@ mod calculate_user_equity { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4028,8 +4028,8 @@ mod calculate_user_equity { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -4037,11 +4037,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -4101,11 +4101,11 @@ mod calculate_user_equity { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -4115,8 +4115,8 @@ mod calculate_user_equity { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -4354,11 +4354,11 @@ mod pools { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), pool_id: 1, @@ -4487,14 +4487,14 @@ mod get_margin_calculation_for_disable_high_leverage_mode { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 101 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_step_size: 10000000, oracle: sol_oracle_price_key, ..AMM::default() @@ -4510,11 +4510,11 @@ mod get_margin_calculation_for_disable_high_leverage_mode { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -4524,8 +4524,8 @@ mod get_margin_calculation_for_disable_high_leverage_mode { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, diff --git a/programs/drift/src/math/oracle.rs b/programs/drift/src/math/oracle.rs index 92bf2a47e8..fc97606f96 100644 --- a/programs/drift/src/math/oracle.rs +++ b/programs/drift/src/math/oracle.rs @@ -1,4 +1,7 @@ -use borsh::{BorshDeserialize, BorshSerialize}; +use anchor_lang::prelude::{ + borsh::{self}, + AnchorDeserialize, AnchorSerialize, +}; use crate::error::{DriftResult, ErrorCode}; use crate::math::amm; @@ -18,7 +21,7 @@ use std::fmt; mod tests; // ordered by "severity" -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum OracleValidity { NonPositive, TooVolatile, @@ -125,7 +128,7 @@ impl From for u8 { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum DriftAction { UpdateFunding, SettlePnl, diff --git a/programs/drift/src/math/oracle/tests.rs b/programs/drift/src/math/oracle/tests.rs index adf34a28b4..29ea89984b 100644 --- a/programs/drift/src/math/oracle/tests.rs +++ b/programs/drift/src/math/oracle/tests.rs @@ -15,9 +15,9 @@ fn calculate_oracle_valid() { let px = 32 * PRICE_PRECISION; let amm = AMM { - base_asset_reserve: 2 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 2 * AMM_RESERVE_PRECISION, - peg_multiplier: 33 * PEG_PRECISION, + base_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (2 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (33 * PEG_PRECISION).into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap_5min: px as i64, last_oracle_price_twap: (px as i64) - 1000, diff --git a/programs/drift/src/math/orders/tests.rs b/programs/drift/src/math/orders/tests.rs index 339aa20361..26a82f87d9 100644 --- a/programs/drift/src/math/orders/tests.rs +++ b/programs/drift/src/math/orders/tests.rs @@ -462,12 +462,11 @@ mod get_max_fill_amounts { use crate::state::user::{Order, SpotPosition, User}; use crate::test_utils::get_orders; use crate::LAMPORTS_PER_SOL_U64; - use anchor_spl::token::spl_token::solana_program::native_token::LAMPORTS_PER_SOL; #[test] fn fully_collateralized_selling_base() { let base_market = SpotMarket { - deposit_balance: 4 * 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (4 * 100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 4 * 100 * LAMPORTS_PER_SOL_U64, ..SpotMarket::default_base_market() }; @@ -493,7 +492,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Short, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -502,7 +501,7 @@ mod get_max_fill_amounts { let (max_base, max_quote) = get_max_fill_amounts(&user, 0, &base_market, "e_market, true).unwrap(); - assert_eq!(max_base, Some(100 * LAMPORTS_PER_SOL)); + assert_eq!(max_base, Some(100 * LAMPORTS_PER_SOL_U64)); assert_eq!(max_quote, None); } @@ -531,7 +530,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Short, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -547,7 +546,7 @@ mod get_max_fill_amounts { #[test] fn selling_base_with_borrow_liquidity_greater_than_order() { let base_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * SPOT_BALANCE_PRECISION as u64, ..SpotMarket::default_base_market() }; @@ -572,7 +571,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Short, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -589,7 +588,7 @@ mod get_max_fill_amounts { fn fully_collateralized_selling_quote() { let base_market = SpotMarket::default_base_market(); let quote_market = SpotMarket { - deposit_balance: 4 * 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (4 * 100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 4 * 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() }; @@ -614,7 +613,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Long, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -652,7 +651,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Long, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -669,7 +668,7 @@ mod get_max_fill_amounts { fn selling_quote_with_borrow_liquidity_greater_than_order() { let base_market = SpotMarket::default_base_market(); let quote_market = SpotMarket { - deposit_balance: 100 * SPOT_BALANCE_PRECISION, + deposit_balance: (100 * SPOT_BALANCE_PRECISION).into(), deposit_token_twap: 100 * QUOTE_PRECISION_U64, ..SpotMarket::default_quote_market() @@ -694,7 +693,7 @@ mod get_max_fill_amounts { spot_positions, orders: get_orders(Order { direction: PositionDirection::Long, - base_asset_amount: 100 * LAMPORTS_PER_SOL, + base_asset_amount: 100 * LAMPORTS_PER_SOL_U64, ..Order::default() }), ..User::default() @@ -1109,11 +1108,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1123,8 +1122,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1216,11 +1215,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1230,8 +1229,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1324,11 +1323,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1338,8 +1337,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1431,11 +1430,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1445,8 +1444,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1521,11 +1520,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1535,8 +1534,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1629,11 +1628,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1643,8 +1642,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1737,11 +1736,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1751,8 +1750,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1845,11 +1844,11 @@ mod calculate_max_spot_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -1859,8 +1858,8 @@ mod calculate_max_spot_order_size { market_index: 1, oracle_source: OracleSource::Pyth, oracle: sol_oracle_price_key, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, initial_asset_weight: 8 * SPOT_WEIGHT_PRECISION / 10, maintenance_asset_weight: 9 * SPOT_WEIGHT_PRECISION / 10, @@ -1986,14 +1985,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2014,8 +2013,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2023,11 +2022,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2108,14 +2107,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2136,8 +2135,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2145,11 +2144,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2213,14 +2212,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2241,8 +2240,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2250,11 +2249,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2335,14 +2334,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2363,8 +2362,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2372,11 +2371,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2440,14 +2439,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2468,8 +2467,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2477,11 +2476,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2563,14 +2562,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2591,8 +2590,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2600,11 +2599,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2686,14 +2685,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2715,8 +2714,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2724,11 +2723,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2809,14 +2808,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2837,8 +2836,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2846,11 +2845,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -2932,14 +2931,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -2960,8 +2959,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -2969,11 +2968,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -3055,14 +3054,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3084,8 +3083,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3093,11 +3092,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -3178,14 +3177,14 @@ mod calculate_max_perp_order_size { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -3209,8 +3208,8 @@ mod calculate_max_perp_order_size { status: MarketStatus::Active, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); create_anchor_account_info!(market, PerpMarket, market_account_info); let market_map = PerpMarketMap::load_one(&market_account_info, true).unwrap(); @@ -3218,11 +3217,11 @@ mod calculate_max_perp_order_size { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 10000 * SPOT_BALANCE_PRECISION, + deposit_balance: (10000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: PRICE_PRECISION_I64, @@ -3975,9 +3974,9 @@ pub mod get_price_for_perp_order { #[test] fn bid_crosses_vamm_ask() { let amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_tick_size: 100000, short_spread: BID_ASK_SPREAD_PRECISION_U128 as u32 / 100, ..AMM::default() @@ -4006,9 +4005,9 @@ pub mod get_price_for_perp_order { #[test] fn bid_doesnt_cross_vamm_ask() { let amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_tick_size: 100000, short_spread: BID_ASK_SPREAD_PRECISION_U128 as u32 / 100, ..AMM::default() @@ -4031,9 +4030,9 @@ pub mod get_price_for_perp_order { #[test] fn ask_crosses_vamm_ask() { let amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_tick_size: 100000, long_spread: BID_ASK_SPREAD_PRECISION_U128 as u32 / 100, ..AMM::default() @@ -4062,9 +4061,9 @@ pub mod get_price_for_perp_order { #[test] fn ask_doesnt_cross_vamm_ask() { let amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), order_tick_size: 100000, long_spread: BID_ASK_SPREAD_PRECISION_U128 as u32 / 100, ..AMM::default() @@ -4499,14 +4498,14 @@ mod fallback_price_logic { fn test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - bid_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - ask_quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + bid_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + ask_quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), max_slippage_ratio: 50, max_fill_reserve_fraction: 100, order_step_size: 1000, @@ -4528,8 +4527,8 @@ mod fallback_price_logic { status: MarketStatus::Initialized, ..PerpMarket::default_test() }; - market.amm.max_base_asset_reserve = u128::MAX; - market.amm.min_base_asset_reserve = 0; + market.amm.set_max_base_asset_reserve(u128::MAX); + market.amm.set_min_base_asset_reserve(0); // fallback are wide from oracle cause twaps arent set on amm let result = market diff --git a/programs/drift/src/math/position.rs b/programs/drift/src/math/position.rs index e40c75205d..288e1ed1ce 100644 --- a/programs/drift/src/math/position.rs +++ b/programs/drift/src/math/position.rs @@ -37,9 +37,9 @@ pub fn calculate_base_asset_value(base_asset_amount: i128, amm: &AMM) -> DriftRe let swap_direction = swap_direction_to_close_position(base_asset_amount); let (base_asset_reserve, quote_asset_reserve) = - (amm.base_asset_reserve, amm.quote_asset_reserve); + (amm.base_asset_reserve(), amm.quote_asset_reserve()); - let amm_lp_shares = amm.sqrt_k; + let amm_lp_shares = amm.sqrt_k(); let (new_quote_asset_reserve, _new_base_asset_reserve) = amm::calculate_swap_output( base_asset_amount.unsigned_abs(), @@ -52,7 +52,7 @@ pub fn calculate_base_asset_value(base_asset_amount: i128, amm: &AMM) -> DriftRe quote_asset_reserve, new_quote_asset_reserve, swap_direction, - amm.peg_multiplier, + amm.peg_multiplier(), )?; Ok(base_asset_value) diff --git a/programs/drift/src/math/repeg.rs b/programs/drift/src/math/repeg.rs index 995e425f64..ac6e9af8f5 100644 --- a/programs/drift/src/math/repeg.rs +++ b/programs/drift/src/math/repeg.rs @@ -92,9 +92,9 @@ pub fn calculate_repeg_validity( // if oracle is valid: check on size/direction of repeg if oracle_is_valid { let reserve_price_after = amm::calculate_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, - market.amm.peg_multiplier, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), + market.amm.peg_multiplier(), )?; let oracle_conf_band_top = oracle_price_u128.safe_add(oracle_conf)?; @@ -179,18 +179,18 @@ pub fn adjust_peg_cost( ) -> DriftResult<(PerpMarket, i128)> { let mut market_clone = *market; - let cost = if new_peg_candidate != market_clone.amm.peg_multiplier { + let cost = if new_peg_candidate != market_clone.amm.peg_multiplier() { // Find the net market value before adjusting peg let (current_net_market_value, _) = calculate_base_asset_value_and_pnl( - market_clone.amm.base_asset_amount_with_amm, + market_clone.amm.base_asset_amount_with_amm(), 0, &market_clone.amm, )?; - market_clone.amm.peg_multiplier = new_peg_candidate; + market_clone.amm.set_peg_multiplier(new_peg_candidate); let (_new_net_market_value, cost) = calculate_base_asset_value_and_pnl( - market_clone.amm.base_asset_amount_with_amm, + market_clone.amm.base_asset_amount_with_amm(), current_net_market_value, &market_clone.amm, )?; @@ -203,13 +203,13 @@ pub fn adjust_peg_cost( } pub fn calculate_repeg_cost(amm: &AMM, new_peg: u128) -> DriftResult { - amm.quote_asset_reserve + amm.quote_asset_reserve() .cast::()? - .safe_sub(amm.terminal_quote_asset_reserve.cast()?)? + .safe_sub(amm.terminal_quote_asset_reserve().cast()?)? .safe_mul( new_peg .cast::()? - .safe_sub(amm.peg_multiplier.cast()?)?, + .safe_sub(amm.peg_multiplier().cast()?)?, )? .safe_div(AMM_RESERVE_PRECISION_I128) } @@ -249,17 +249,17 @@ pub fn adjust_amm( let curve_update_intensity = min(market.amm.curve_update_intensity, 100_u8).cast::()?; // return early - if optimal_peg == market.amm.peg_multiplier || curve_update_intensity == 0 { + if optimal_peg == market.amm.peg_multiplier() || curve_update_intensity == 0 { return Ok((Box::new(*market), 0)); } let delta_peg = optimal_peg .cast::()? - .safe_sub(market.amm.peg_multiplier.cast()?)?; // PEG_PRECISION + .safe_sub(market.amm.peg_multiplier().cast()?)?; // PEG_PRECISION let mut per_peg_cost = calculate_per_peg_cost( - market.amm.quote_asset_reserve, - market.amm.terminal_quote_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.terminal_quote_asset_reserve(), )?; // PEG_PRECISION let budget_i128 = budget.cast::()?; @@ -299,8 +299,8 @@ pub fn adjust_amm( let new_sqrt_k = market .amm - .sqrt_k - .safe_sub(market.amm.sqrt_k.safe_div(1000)?)? + .sqrt_k() + .safe_sub(market.amm.sqrt_k().safe_div(1000)?)? .max(new_sqrt_k_lower_bound); let update_k_result = @@ -309,8 +309,8 @@ pub fn adjust_amm( let adjustment_cost = cp_curve::adjust_k_cost_and_update(&mut market_clone, &update_k_result)?; per_peg_cost = calculate_per_peg_cost( - market_clone.amm.quote_asset_reserve, - market_clone.amm.terminal_quote_asset_reserve, + market_clone.amm.quote_asset_reserve(), + market_clone.amm.terminal_quote_asset_reserve(), )?; adjustment_cost @@ -327,13 +327,13 @@ pub fn adjust_amm( new_peg = if budget_delta_peg > 0 { market .amm - .peg_multiplier + .peg_multiplier() .safe_add(budget_delta_peg_magnitude) .unwrap_or(u128::MAX) - } else if market.amm.peg_multiplier > budget_delta_peg_magnitude { + } else if market.amm.peg_multiplier() > budget_delta_peg_magnitude { market .amm - .peg_multiplier + .peg_multiplier() .safe_sub(budget_delta_peg_magnitude)? } else { 1 @@ -341,7 +341,7 @@ pub fn adjust_amm( cost = calculate_repeg_cost(&market_clone.amm, new_peg)?; } - market_clone.amm.peg_multiplier = new_peg; + market_clone.amm.set_peg_multiplier(new_peg); Ok((market_clone, cost)) } @@ -357,8 +357,8 @@ pub fn calculate_optimal_peg_and_budget( let target_price_i64 = mm_oracle_price_data.get_price(); let target_price = target_price_i64.cast()?; let mut optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), target_price, )?; @@ -389,8 +389,8 @@ pub fn calculate_optimal_peg_and_budget( reserve_price_before.safe_sub(mark_adj)? }; optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), target_price.cast()?, )?; @@ -407,16 +407,16 @@ pub fn calculate_optimal_peg_and_budget( pub fn calculate_fee_pool(market: &PerpMarket) -> DriftResult { let total_fee_minus_distributions_lower_bound = get_total_fee_lower_bound(market)? - .safe_add(market.amm.total_liquidation_fee)? - .safe_sub(market.amm.total_fee_withdrawn)? + .safe_add(market.amm.total_liquidation_fee())? + .safe_sub(market.amm.total_fee_withdrawn())? .cast::() .unwrap_or(0); let fee_pool = - if market.amm.total_fee_minus_distributions > total_fee_minus_distributions_lower_bound { + if market.amm.total_fee_minus_distributions() > total_fee_minus_distributions_lower_bound { market .amm - .total_fee_minus_distributions + .total_fee_minus_distributions() .safe_sub(total_fee_minus_distributions_lower_bound)? .cast()? } else { @@ -430,7 +430,7 @@ pub fn get_total_fee_lower_bound(market: &PerpMarket) -> DriftResult { // market to retain half of exchange fees let total_fee_lower_bound = market .amm - .total_exchange_fee + .total_exchange_fee() .safe_mul(SHARE_OF_FEES_ALLOCATED_TO_DRIFT_NUMERATOR)? .safe_div(SHARE_OF_FEES_ALLOCATED_TO_DRIFT_DENOMINATOR)?; diff --git a/programs/drift/src/math/repeg/tests.rs b/programs/drift/src/math/repeg/tests.rs index 0619d0b35f..5ff027965d 100644 --- a/programs/drift/src/math/repeg/tests.rs +++ b/programs/drift/src/math/repeg/tests.rs @@ -33,19 +33,19 @@ fn calc_peg_tests() { fn calculate_optimal_peg_and_budget_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 65 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 63015384615, - terminal_quote_asset_reserve: 64 * AMM_RESERVE_PRECISION, - sqrt_k: 64 * AMM_RESERVE_PRECISION, - peg_multiplier: 19_400_000_000, - base_asset_amount_with_amm: -(AMM_RESERVE_PRECISION as i128), + base_asset_reserve: (65 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: 63015384615.into(), + terminal_quote_asset_reserve: (64 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (64 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 19_400_000_000.into(), + base_asset_amount_with_amm: (-(AMM_RESERVE_PRECISION as i128)).into(), mark_std: PRICE_PRECISION as u64, last_mark_price_twap_ts: 0, base_spread: 250, curve_update_intensity: 100, max_spread: 500 * 100, - total_exchange_fee: QUOTE_PRECISION, - total_fee_minus_distributions: (40 * QUOTE_PRECISION) as i128, + total_exchange_fee: QUOTE_PRECISION.into(), + total_fee_minus_distributions: ((40 * QUOTE_PRECISION) as i128).into(), ..AMM::default() }, margin_ratio_initial: 500, @@ -173,22 +173,26 @@ fn calculate_optimal_peg_and_budget_test() { assert_eq!(budget, 39500000); assert!(check_lb); - market.amm.base_asset_amount_with_amm = AMM_RESERVE_PRECISION as i128; + market + .amm + .set_base_asset_amount_with_amm(AMM_RESERVE_PRECISION as i128); - let swap_direction = if market.amm.base_asset_amount_with_amm > 0 { + let swap_direction = if market.amm.base_asset_amount_with_amm() > 0 { SwapDirection::Add } else { SwapDirection::Remove }; let (new_terminal_quote_reserve, _new_terminal_base_reserve) = amm::calculate_swap_output( - market.amm.base_asset_amount_with_amm.unsigned_abs(), - market.amm.base_asset_reserve, + market.amm.base_asset_amount_with_amm().unsigned_abs(), + market.amm.base_asset_reserve(), swap_direction, - market.amm.sqrt_k, + market.amm.sqrt_k(), ) .unwrap(); - market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; + market + .amm + .set_terminal_quote_asset_reserve(new_terminal_quote_reserve); // negative target_price_gap exceeding max_spread (not in favor of vAMM) let oracle_price_data = OraclePriceData { @@ -218,21 +222,21 @@ fn calculate_optimal_peg_and_budget_test() { fn calculate_optimal_peg_and_budget_2_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: 2270516211133, - quote_asset_reserve: 2270925669621, - terminal_quote_asset_reserve: 2270688451627, - sqrt_k: 2270720931148, - peg_multiplier: 17723081263, - base_asset_amount_with_amm: 237200000, + base_asset_reserve: 2270516211133.into(), + quote_asset_reserve: 2270925669621.into(), + terminal_quote_asset_reserve: 2270688451627.into(), + sqrt_k: 2270720931148.into(), + peg_multiplier: 17723081263.into(), + base_asset_amount_with_amm: 237200000.into(), mark_std: 43112524, last_mark_price_twap_ts: 0, base_spread: 250, curve_update_intensity: 100, max_spread: 500 * 100, - total_exchange_fee: 298628987, - total_fee_minus_distributions: -242668966, - total_fee_withdrawn: 124247717, - concentration_coef: 1020710, + total_exchange_fee: 298628987.into(), + total_fee_minus_distributions: (-242668966).into(), + total_fee_withdrawn: 124247717.into(), + concentration_coef: 1020710.into(), historical_oracle_data: HistoricalOracleData { last_oracle_price_twap: 17765940050, last_oracle_price_twap_5min: 17763317077, @@ -246,12 +250,18 @@ fn calculate_optimal_peg_and_budget_2_test() { }; let (new_terminal_quote_reserve, new_terminal_base_reserve) = amm::calculate_terminal_reserves(&market.amm).unwrap(); - market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; + market + .amm + .set_terminal_quote_asset_reserve(new_terminal_quote_reserve); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, new_terminal_base_reserve) + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), new_terminal_base_reserve) .unwrap(); - market.amm.min_base_asset_reserve = min_base_asset_reserve; - market.amm.max_base_asset_reserve = max_base_asset_reserve; + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); let oracle_price_data = OraclePriceData { price: (17_800 * PRICE_PRECISION) as i64, @@ -310,12 +320,12 @@ fn calc_adjust_amm_tests_repeg_in_favour() { // btc-esque market let market = PerpMarket { amm: AMM { - base_asset_reserve: 65 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 63015384615, - terminal_quote_asset_reserve: 64 * AMM_RESERVE_PRECISION, - sqrt_k: 64 * AMM_RESERVE_PRECISION, - peg_multiplier: 19_400_000_000, - base_asset_amount_with_amm: AMM_RESERVE_PRECISION as i128, + base_asset_reserve: (65 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: 63015384615.into(), + terminal_quote_asset_reserve: (64 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (64 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 19_400_000_000.into(), + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128).into(), mark_std: PRICE_PRECISION as u64, last_mark_price_twap_ts: 0, curve_update_intensity: 100, @@ -328,16 +338,16 @@ fn calc_adjust_amm_tests_repeg_in_favour() { let px = 20_401_125_456; let optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), px, ) .unwrap(); - assert!(optimal_peg > market.amm.peg_multiplier); + assert!(optimal_peg > market.amm.peg_multiplier()); let (repegged_market, _amm_update_cost) = adjust_amm(&market, optimal_peg, 0, true).unwrap(); assert_eq!(_amm_update_cost, -1618354580); - assert_eq!(repegged_market.amm.peg_multiplier, optimal_peg); + assert_eq!(repegged_market.amm.peg_multiplier(), optimal_peg); let post_price = repegged_market.amm.reserve_price().unwrap(); assert_eq!(post_price - prev_price, 1593456817); // todo: (15934564582252/1e4 - 1615699103 is the slippage cost?) @@ -349,21 +359,21 @@ fn calc_adjust_amm_tests_sufficent_fee_for_repeg() { let mut market = PerpMarket { amm: AMM { order_step_size: 1000, - base_asset_reserve: 60437939720095, - quote_asset_reserve: 60440212459368, - terminal_quote_asset_reserve: 60439072663003, - sqrt_k: 60439076079049, - peg_multiplier: 34353000, - base_asset_amount_with_amm: AMM_RESERVE_PRECISION as i128, + base_asset_reserve: 60437939720095.into(), + quote_asset_reserve: 60440212459368.into(), + terminal_quote_asset_reserve: 60439072663003.into(), + sqrt_k: 60439076079049.into(), + peg_multiplier: 34353000.into(), + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128).into(), last_mark_price_twap: 34128370, last_mark_price_twap_ts: 165705, curve_update_intensity: 100, base_spread: 1000, - total_fee_minus_distributions: 304289, - total_fee: 607476, - total_exchange_fee: 0, // new fee pool lowerbound + total_fee_minus_distributions: 304289.into(), + total_fee: 607476.into(), + total_exchange_fee: 0.into(), // new fee pool lowerbound funding_period: 3600, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), ..AMM::default() }, @@ -376,29 +386,35 @@ fn calc_adjust_amm_tests_sufficent_fee_for_repeg() { }; let (new_terminal_quote_reserve, new_terminal_base_reserve) = amm::calculate_terminal_reserves(&market.amm).unwrap(); - market.amm.terminal_quote_asset_reserve = new_terminal_quote_reserve; + market + .amm + .set_terminal_quote_asset_reserve(new_terminal_quote_reserve); let (min_base_asset_reserve, max_base_asset_reserve) = - amm::calculate_bid_ask_bounds(market.amm.concentration_coef, new_terminal_base_reserve) + amm::calculate_bid_ask_bounds(market.amm.concentration_coef(), new_terminal_base_reserve) .unwrap(); - market.amm.min_base_asset_reserve = min_base_asset_reserve; - market.amm.max_base_asset_reserve = max_base_asset_reserve; + market + .amm + .set_min_base_asset_reserve(min_base_asset_reserve); + market + .amm + .set_max_base_asset_reserve(max_base_asset_reserve); let px = 35768 * PRICE_PRECISION_U64 / 1000; let optimal_peg = calculate_peg_from_target_price( - market.amm.quote_asset_reserve, - market.amm.base_asset_reserve, + market.amm.quote_asset_reserve(), + market.amm.base_asset_reserve(), px, ) .unwrap(); - assert!(optimal_peg > market.amm.peg_multiplier); + assert!(optimal_peg > market.amm.peg_multiplier()); let fee_budget = calculate_fee_pool(&market).unwrap(); assert!(fee_budget > 0); let (repegged_market, _amm_update_cost) = adjust_amm(&market, optimal_peg, fee_budget, true).unwrap(); // insufficient fee to repeg - let new_peg = repegged_market.amm.peg_multiplier; - let old_peg = market.amm.peg_multiplier; + let new_peg = repegged_market.amm.peg_multiplier(); + let old_peg = market.amm.peg_multiplier(); assert!(new_peg > old_peg); assert_eq!(new_peg, 34657283); assert_eq!(_amm_update_cost, 304289); diff --git a/programs/drift/src/math/spot_balance.rs b/programs/drift/src/math/spot_balance.rs index da5261a487..c89378ebce 100644 --- a/programs/drift/src/math/spot_balance.rs +++ b/programs/drift/src/math/spot_balance.rs @@ -22,8 +22,8 @@ pub fn get_spot_balance( let precision_increase = 10_u128.pow(19_u32.safe_sub(spot_market.decimals)?); let cumulative_interest = match balance_type { - SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest, - SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest, + SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest(), + SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest(), }; let mut balance = token_amount @@ -45,8 +45,8 @@ pub fn get_token_amount( let precision_decrease = 10_u128.pow(19_u32.safe_sub(spot_market.decimals)?); let cumulative_interest = match balance_type { - SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest, - SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest, + SpotBalanceType::Deposit => spot_market.cumulative_deposit_interest(), + SpotBalanceType::Borrow => spot_market.cumulative_borrow_interest(), }; let token_amount = match balance_type { @@ -111,12 +111,12 @@ pub fn calculate_utilization( pub fn calculate_spot_market_utilization(spot_market: &SpotMarket) -> DriftResult { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )?; @@ -161,14 +161,14 @@ pub fn calculate_accumulated_interest( .safe_div(SPOT_UTILIZATION_PRECISION)?; let borrow_interest = spot_market - .cumulative_borrow_interest + .cumulative_borrow_interest() .safe_mul(modified_borrow_rate)? .safe_div(ONE_YEAR)? .safe_div(SPOT_RATE_PRECISION)? .safe_add(1)?; let deposit_interest = spot_market - .cumulative_deposit_interest + .cumulative_deposit_interest() .safe_mul(modified_deposit_rate)? .safe_div(ONE_YEAR)? .safe_div(SPOT_RATE_PRECISION)?; @@ -206,7 +206,7 @@ pub fn calculate_borrow_rate(spot_market: &SpotMarket, utilization: u128) -> Dri let segment_end = bp; let segment_range = segment_end.safe_sub(segment_start)?; let segment_rate_total = total_extra_rate - .safe_mul(weight as u128)? + .safe_mul(weight)? .safe_div(weights_divisor)?; if utilization <= segment_end { diff --git a/programs/drift/src/math/spot_balance/tests.rs b/programs/drift/src/math/spot_balance/tests.rs index 5fbe7427a4..d9dffd9ff1 100644 --- a/programs/drift/src/math/spot_balance/tests.rs +++ b/programs/drift/src/math/spot_balance/tests.rs @@ -7,7 +7,7 @@ mod test { #[test] fn bonk() { let spot_market = SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 5, ..SpotMarket::default_quote_market() }; diff --git a/programs/drift/src/math/spot_withdraw.rs b/programs/drift/src/math/spot_withdraw.rs index 9f0b3e0b5a..dc64c73696 100644 --- a/programs/drift/src/math/spot_withdraw.rs +++ b/programs/drift/src/math/spot_withdraw.rs @@ -153,12 +153,12 @@ pub fn check_withdraw_limits( // calculates min/max deposit/borrow amounts permitted for immediate withdraw // takes the stricter of absolute caps on level changes and utilization changes vs 24hr moving averrages let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )?; @@ -231,13 +231,13 @@ pub fn get_max_withdraw_for_market_with_token_amount( is_leaving_drift: bool, ) -> DriftResult { let deposit_token_amount = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )?; let borrow_token_amount = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )?; @@ -308,20 +308,20 @@ pub fn get_max_withdraw_for_market_with_token_amount( pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult { let depositors_amount: u64 = get_token_amount( - spot_market.deposit_balance, + spot_market.deposit_balance(), spot_market, &SpotBalanceType::Deposit, )? .cast()?; let borrowers_amount: u64 = get_token_amount( - spot_market.borrow_balance, + spot_market.borrow_balance(), spot_market, &SpotBalanceType::Borrow, )? .cast()?; let revenue_amount: u64 = get_token_amount( - spot_market.revenue_pool.scaled_balance, + spot_market.revenue_pool.scaled_balance(), spot_market, &SpotBalanceType::Deposit, )? @@ -338,7 +338,7 @@ pub fn validate_spot_balances(spot_market: &SpotMarket) -> DriftResult { revenue_amount, depositors_amount, depositors_claim, - spot_market.deposit_balance + spot_market.deposit_balance() )?; Ok(depositors_claim) diff --git a/programs/drift/src/state/amm_cache.rs b/programs/drift/src/state/amm_cache.rs index 1e485b2289..6b98b63b48 100644 --- a/programs/drift/src/state/amm_cache.rs +++ b/programs/drift/src/state/amm_cache.rs @@ -16,7 +16,10 @@ use crate::state::zero_copy::{AccountZeroCopy, AccountZeroCopyMut}; use crate::OracleSource; use crate::{impl_zero_copy_loader, OracleGuardRails}; -use anchor_lang::prelude::*; +use anchor_lang::prelude::{ + borsh::{self, BorshDeserialize, BorshSerialize}, + *, +}; use super::user::MarketType; @@ -32,7 +35,7 @@ pub struct AmmCache { } #[zero_copy] -#[derive(AnchorSerialize, AnchorDeserialize, Debug)] +#[derive(BorshSerialize, BorshDeserialize, Debug)] #[repr(C)] pub struct CacheInfo { pub oracle: Pubkey, @@ -313,13 +316,13 @@ impl<'a> AccountZeroCopyMut<'a, CacheInfo, AmmCacheFixed> { let cached_info = self.get_mut(perp_market.market_index as u32); let fee_pool_token_amount = get_token_amount( - perp_market.amm.fee_pool.scaled_balance, + perp_market.amm.fee_pool.scaled_balance(), "e_market, perp_market.amm.fee_pool.balance_type(), )?; let net_pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), "e_market, perp_market.pnl_pool.balance_type(), )? @@ -338,15 +341,15 @@ impl<'a> AccountZeroCopyMut<'a, CacheInfo, AmmCacheFixed> { { cached_info.last_fee_pool_token_amount = fee_pool_token_amount; cached_info.last_net_pnl_pool_token_amount = net_pnl_pool_token_amount; - cached_info.last_exchange_fees = perp_market.amm.total_exchange_fee; - cached_info.last_settle_amm_ex_fees = perp_market.amm.total_exchange_fee; + cached_info.last_exchange_fees = perp_market.amm.total_exchange_fee(); + cached_info.last_settle_amm_ex_fees = perp_market.amm.total_exchange_fee(); cached_info.last_settle_amm_pnl = net_pnl_pool_token_amount; return Ok(()); } let exchange_fee_delta = perp_market .amm - .total_exchange_fee + .total_exchange_fee() .saturating_sub(cached_info.last_exchange_fees); let amount_to_send_to_lp_pool = amm_amount_available @@ -366,7 +369,7 @@ impl<'a> AccountZeroCopyMut<'a, CacheInfo, AmmCacheFixed> { cached_info.last_fee_pool_token_amount = fee_pool_token_amount; cached_info.last_net_pnl_pool_token_amount = net_pnl_pool_token_amount; - cached_info.last_exchange_fees = perp_market.amm.total_exchange_fee; + cached_info.last_exchange_fees = perp_market.amm.total_exchange_fee(); Ok(()) } diff --git a/programs/drift/src/state/constituent_map.rs b/programs/drift/src/state/constituent_map.rs index 57518c0d4b..8ea2e5b63b 100644 --- a/programs/drift/src/state/constituent_map.rs +++ b/programs/drift/src/state/constituent_map.rs @@ -23,7 +23,7 @@ pub struct ConstituentMap<'a>(pub BTreeMap>) impl<'a> ConstituentMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref(&self, constituent_index: &u16) -> DriftResult> { + pub fn get_ref(&self, constituent_index: &u16) -> DriftResult> { let loader = match self.0.get(constituent_index) { Some(loader) => loader, None => { @@ -56,7 +56,7 @@ impl<'a> ConstituentMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { + pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { let loader = match self.0.get(market_index) { Some(loader) => loader, None => { @@ -94,7 +94,6 @@ impl<'a> ConstituentMap<'a> { ) -> DriftResult> { let mut constituent_map: ConstituentMap = ConstituentMap(BTreeMap::new()); - let constituent_discriminator: [u8; 8] = Constituent::discriminator(); while let Some(account_info) = account_info_iter.peek() { if account_info.owner != &crate::ID { break; @@ -114,12 +113,12 @@ impl<'a> ConstituentMap<'a> { break; } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &constituent_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != Constituent::DISCRIMINATOR { msg!( "didnt match account discriminator {:?}, {:?}", account_discriminator, - constituent_discriminator + Constituent::DISCRIMINATOR ); break; } @@ -176,9 +175,8 @@ impl<'a> ConstituentMap<'a> { return Err(ErrorCode::ConstituentCouldNotLoad); } - let constituent_discriminator: [u8; 8] = Constituent::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &constituent_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != Constituent::DISCRIMINATOR { return Err(ErrorCode::ConstituentCouldNotLoad); } @@ -206,7 +204,6 @@ impl<'a> ConstituentMap<'a> { let account_info_iter = account_info.into_iter(); for account_info in account_info_iter { - let constituent_discriminator: [u8; 8] = Constituent::discriminator(); let data = account_info .try_borrow_data() .or(Err(ErrorCode::ConstituentCouldNotLoad))?; @@ -216,8 +213,8 @@ impl<'a> ConstituentMap<'a> { return Err(ErrorCode::ConstituentCouldNotLoad); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &constituent_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != Constituent::DISCRIMINATOR { return Err(ErrorCode::ConstituentCouldNotLoad); } diff --git a/programs/drift/src/state/events.rs b/programs/drift/src/state/events.rs index 797458fbbc..1a52e7013a 100644 --- a/programs/drift/src/state/events.rs +++ b/programs/drift/src/state/events.rs @@ -1,5 +1,4 @@ use anchor_lang::prelude::*; -use borsh::{BorshDeserialize, BorshSerialize}; use crate::controller::position::PositionDirection; use crate::error::{DriftResult, ErrorCode::InvalidOrder}; @@ -56,7 +55,7 @@ pub struct DepositRecord { pub user_token_amount_after: i128, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum DepositExplanation { #[default] None, @@ -86,7 +85,7 @@ pub struct SpotInterestRecord { pub max_borrow_rate: u32, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum DepositDirection { #[default] Deposit, @@ -356,7 +355,7 @@ pub fn get_order_action_record( }) } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum OrderAction { #[default] Place, @@ -366,7 +365,7 @@ pub enum OrderAction { Expire, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq)] pub enum OrderActionExplanation { None, InsufficientFreeCollateral, @@ -409,7 +408,7 @@ pub struct LPRecord { pub pnl: i64, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum LPAction { #[default] AddLiquidity, @@ -443,7 +442,7 @@ pub struct LiquidationRecord { pub spot_bankruptcy: SpotBankruptcyRecord, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum LiquidationType { #[default] LiquidatePerp, @@ -536,7 +535,7 @@ pub struct SettlePnlRecord { pub explanation: SettlePnlExplanation, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum SettlePnlExplanation { #[default] None, @@ -583,7 +582,7 @@ pub struct InsuranceFundStakeRecord { pub total_if_shares_after: u128, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Default)] pub enum StakeAction { #[default] Stake, @@ -749,7 +748,7 @@ pub fn emit_buffers( ) -> DriftResult { let mut data_writer = std::io::Cursor::new(data_buf); data_writer - .write_all(&::discriminator()) + .write_all(&::DISCRIMINATOR) .safe_unwrap()?; borsh::to_writer(&mut data_writer, &event).safe_unwrap()?; let data_len = data_writer.position() as usize; diff --git a/programs/drift/src/state/fulfillment_params/serum.rs b/programs/drift/src/state/fulfillment_params/serum.rs index fa30f65eac..5c9eae93a5 100644 --- a/programs/drift/src/state/fulfillment_params/serum.rs +++ b/programs/drift/src/state/fulfillment_params/serum.rs @@ -65,7 +65,7 @@ pub struct SerumContext<'a, 'b> { } impl<'a, 'b> SerumContext<'a, 'b> { - pub fn load_serum_market(&self) -> DriftResult { + pub fn load_serum_market(&self) -> DriftResult> { Market::load(self.serum_market, self.serum_program.key, false).map_err(|e| { msg!("{:?}", e); ErrorCode::InvalidSerumMarket diff --git a/programs/drift/src/state/insurance_fund_stake.rs b/programs/drift/src/state/insurance_fund_stake.rs index 25d81f4b0d..35a2d47cc4 100644 --- a/programs/drift/src/state/insurance_fund_stake.rs +++ b/programs/drift/src/state/insurance_fund_stake.rs @@ -3,16 +3,16 @@ use crate::error::ErrorCode; use crate::math::constants::EPOCH_DURATION; use crate::math::safe_math::SafeMath; use crate::math_error; -use crate::safe_decrement; -use crate::safe_increment; use crate::state::spot_market::SpotMarket; use crate::state::traits::Size; use crate::validate; use anchor_lang::prelude::*; +use drift_macros::legacy_layout; #[cfg(test)] mod tests; +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] @@ -39,24 +39,24 @@ impl InsuranceFundStake { InsuranceFundStake { authority, market_index, - last_withdraw_request_shares: 0, + last_withdraw_request_shares: 0.into(), last_withdraw_request_value: 0, last_withdraw_request_ts: 0, cost_basis: 0, - if_base: 0, + if_base: 0.into(), last_valid_ts: now, - if_shares: 0, + if_shares: 0.into(), padding: [0; 14], } } fn validate_base(&self, spot_market: &SpotMarket) -> DriftResult { validate!( - self.if_base == spot_market.insurance_fund.shares_base, + self.if_base == spot_market.insurance_fund.shares_base().into(), ErrorCode::InvalidIFRebase, "if stake bases mismatch. user base: {} market base {}", self.if_base, - spot_market.insurance_fund.shares_base + spot_market.insurance_fund.shares_base() )?; Ok(()) @@ -64,33 +64,35 @@ impl InsuranceFundStake { pub fn checked_if_shares(&self, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - Ok(self.if_shares) + Ok(self.if_shares()) } pub fn unchecked_if_shares(&self) -> u128 { - self.if_shares + self.if_shares() } pub fn increase_if_shares(&mut self, delta: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - safe_increment!(self.if_shares, delta); + let if_shares = self.if_shares.as_u128(); + self.set_if_shares(if_shares.checked_add(delta).ok_or_else(math_error!())?); Ok(()) } pub fn decrease_if_shares(&mut self, delta: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - safe_decrement!(self.if_shares, delta); + let if_shares = self.if_shares.as_u128(); + self.set_if_shares(if_shares.checked_sub(delta).ok_or_else(math_error!())?); Ok(()) } pub fn update_if_shares(&mut self, new_shares: u128, spot_market: &SpotMarket) -> DriftResult { self.validate_base(spot_market)?; - self.if_shares = new_shares; - + self.set_if_shares(new_shares); Ok(()) } } +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] @@ -130,7 +132,7 @@ impl ProtocolIfSharesTransferConfig { .next_epoch_ts .safe_add(EPOCH_DURATION.safe_mul(n_epoch_durations)?)?; - self.current_epoch_transfer = 0; + self.set_current_epoch_transfer(0); } Ok(()) @@ -139,7 +141,8 @@ impl ProtocolIfSharesTransferConfig { pub fn validate_transfer(&self, requested_transfer: u128) -> DriftResult { let max_transfer = self .max_transfer_per_epoch - .saturating_sub(self.current_epoch_transfer); + .as_u128() + .saturating_sub(self.current_epoch_transfer.as_u128()); validate!( requested_transfer < max_transfer, diff --git a/programs/drift/src/state/load_ref.rs b/programs/drift/src/state/load_ref.rs index 00b4a2f0c7..4cac5d4c63 100644 --- a/programs/drift/src/state/load_ref.rs +++ b/programs/drift/src/state/load_ref.rs @@ -1,17 +1,16 @@ use anchor_lang::prelude::*; use anchor_lang::ZeroCopy; -use arrayref::array_ref; use std::cell::{Ref, RefMut}; use std::mem; pub fn load_ref<'a, T: ZeroCopy + Owner>(account_info: &'a AccountInfo) -> Result> { let data = account_info.try_borrow_data()?; - if data.len() < T::discriminator().len() { + if data.len() < T::DISCRIMINATOR.len() { return Err(ErrorCode::AccountDiscriminatorNotFound.into()); } - let disc_bytes = array_ref![data, 0, 8]; - if disc_bytes != &T::discriminator() { + let disc_bytes = &data[..8]; + if disc_bytes != T::DISCRIMINATOR { return Err(ErrorCode::AccountDiscriminatorMismatch.into()); } @@ -24,12 +23,12 @@ pub fn load_ref_mut<'a, T: ZeroCopy + Owner>( account_info: &'a AccountInfo, ) -> Result> { let data = account_info.try_borrow_mut_data()?; - if data.len() < T::discriminator().len() { + if data.len() < T::DISCRIMINATOR.len() { return Err(ErrorCode::AccountDiscriminatorNotFound.into()); } - let disc_bytes = array_ref![data, 0, 8]; - if disc_bytes != &T::discriminator() { + let disc_bytes = &data[..8]; + if disc_bytes != T::DISCRIMINATOR { return Err(ErrorCode::AccountDiscriminatorMismatch.into()); } diff --git a/programs/drift/src/state/lp_pool.rs b/programs/drift/src/state/lp_pool.rs index f975ce9e81..cdc03fe29c 100644 --- a/programs/drift/src/state/lp_pool.rs +++ b/programs/drift/src/state/lp_pool.rs @@ -16,8 +16,11 @@ use crate::state::oracle_map::OracleMap; use crate::state::paused_operations::ConstituentLpOperation; use crate::state::spot_market_map::SpotMarketMap; use crate::state::user::MarketType; -use anchor_lang::prelude::*; -use borsh::{BorshDeserialize, BorshSerialize}; +use anchor_lang::prelude::{ + borsh::{BorshDeserialize, BorshSerialize}, + *, +}; +use drift_macros::legacy_layout; use enumflags2::BitFlags; use super::oracle::OraclePriceData; @@ -59,6 +62,7 @@ pub const MAX_ORACLE_STALENESS_FOR_TARGET_CALC: u64 = 10u64; #[cfg(test)] mod tests; +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Debug)] #[repr(C)] @@ -138,11 +142,11 @@ impl Default for LPPool { whitelist_mint: Pubkey::default(), constituent_target_base: Pubkey::default(), constituent_correlations: Pubkey::default(), - max_aum: 0, - last_aum: 0, - cumulative_quote_sent_to_perp_markets: 0, - cumulative_quote_received_from_perp_markets: 0, - total_mint_redeem_fees_paid: 0, + max_aum: 0.into(), + last_aum: 0.into(), + cumulative_quote_sent_to_perp_markets: 0.into(), + cumulative_quote_received_from_perp_markets: 0.into(), + total_mint_redeem_fees_paid: 0.into(), last_aum_slot: 0, max_settle_quote_amount: 0, _padding: 0, @@ -180,6 +184,7 @@ impl LPPool { // TODO: assuming mint decimals = quote decimals = 6 Ok(self .last_aum + .as_u128() .safe_mul(PRICE_PRECISION)? .safe_div(supply as u128)?) } @@ -297,7 +302,7 @@ impl LPPool { in_target_weight: i64, dlp_total_supply: u64, ) -> DriftResult<(u64, u128, i64, i128)> { - let (mut in_fee_pct, out_fee_pct) = if self.last_aum == 0 { + let (mut in_fee_pct, out_fee_pct) = if self.last_aum == 0.into() { (0, 0) } else { self.get_swap_fees( @@ -341,7 +346,7 @@ impl LPPool { } else { token_amount_usd .safe_mul(dlp_total_supply as u128)? - .safe_div(self.last_aum)? + .safe_div(self.last_aum.into())? .safe_div(token_precision_denominator)? }; @@ -399,6 +404,7 @@ impl LPPool { // Apply proportion to AUM and convert to token amount let out_amount = self .last_aum + .as_u128() .safe_mul(proportion)? .safe_mul(token_precision_denominator)? .safe_div(PERCENTAGE_PRECISION)? @@ -625,7 +631,12 @@ impl LPPool { let trade_ratio: i128 = notional_trade_size .abs() .safe_mul(PERCENTAGE_PRECISION_I128)? - .safe_div(self.last_aum.max(MIN_AUM_EXECUTION_FEE).cast::()?)?; + .safe_div( + self.last_aum + .as_u128() + .max(MIN_AUM_EXECUTION_FEE) + .cast::()?, + )?; // Linear fee computation amount let in_fee_execution_linear = @@ -708,15 +719,17 @@ impl LPPool { self.target_position_delay_fee_bps_per_10_slots, )?; - Ok(oracle_uncertainty_fee + oracle_uncertainty_fee .safe_add(position_uncertainty_fee)? - .cast::()?) + .cast::() } pub fn record_mint_redeem_fees(&mut self, amount: i64) -> DriftResult { self.total_mint_redeem_fees_paid = self .total_mint_redeem_fees_paid - .safe_add(amount.cast::()?)?; + .as_i128() + .safe_add(amount as i128)? + .into(); Ok(()) } @@ -832,7 +845,7 @@ impl LPPool { } let aum_u128 = aum.max(0).cast::()?; - self.last_aum = aum_u128; + self.set_last_aum(aum_u128); self.last_aum_slot = slot; Ok((aum_u128, crypto_delta, derivative_groups)) @@ -847,6 +860,7 @@ impl LPPool { } } +#[legacy_layout] #[zero_copy(unsafe)] #[derive(Default, Eq, PartialEq, Debug, BorshDeserialize, BorshSerialize)] #[repr(C)] @@ -875,16 +889,16 @@ impl SpotBalance for ConstituentSpotBalance { } fn balance(&self) -> u128 { - self.scaled_balance + self.scaled_balance.into() } fn increase_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_add(delta)?; + self.set_scaled_balance(self.scaled_balance().safe_add(delta)?); Ok(()) } fn decrease_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_sub(delta)?; + self.set_scaled_balance(self.scaled_balance().safe_sub(delta)?); Ok(()) } @@ -896,7 +910,7 @@ impl SpotBalance for ConstituentSpotBalance { impl ConstituentSpotBalance { pub fn get_token_amount(&self, spot_market: &SpotMarket) -> DriftResult { - get_token_amount(self.scaled_balance, spot_market, &self.balance_type) + get_token_amount(self.scaled_balance.into(), spot_market, &self.balance_type) } pub fn get_signed_token_amount(&self, spot_market: &SpotMarket) -> DriftResult { @@ -905,6 +919,7 @@ impl ConstituentSpotBalance { } } +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Debug)] #[repr(C)] @@ -990,7 +1005,7 @@ impl Default for Constituent { mint: Pubkey::default(), lp_pool: Pubkey::default(), vault: Pubkey::default(), - total_swap_fees: 0, + total_swap_fees: 0.into(), spot_balance: ConstituentSpotBalance::default(), last_spot_balance_token_amount: 0, cumulative_spot_interest_accrued_token_amount: 0, @@ -1096,7 +1111,7 @@ impl Constituent { } pub fn record_swap_fees(&mut self, amount: i128) -> DriftResult { - self.total_swap_fees = self.total_swap_fees.safe_add(amount)?; + self.total_swap_fees = self.total_swap_fees.as_i128().safe_add(amount)?.into(); Ok(()) } diff --git a/programs/drift/src/state/lp_pool/tests.rs b/programs/drift/src/state/lp_pool/tests.rs index 3e76383af9..c090342007 100644 --- a/programs/drift/src/state/lp_pool/tests.rs +++ b/programs/drift/src/state/lp_pool/tests.rs @@ -581,7 +581,7 @@ mod swap_tests { out_volatility: u64, ) { let lp_pool = LPPool { - last_aum: 1_000_000_000_000, + last_aum: 1_000_000_000_000.into(), target_oracle_delay_fee_bps_per_10_slots: 2, target_position_delay_fee_bps_per_10_slots: 10, ..LPPool::default() @@ -596,10 +596,12 @@ mod swap_tests { ..OraclePriceData::default() }; - let in_notional = (in_current_weight as u128) * lp_pool.last_aum / PERCENTAGE_PRECISION; + let in_notional = + (in_current_weight as u128) * lp_pool.last_aum.as_u128() / PERCENTAGE_PRECISION; let in_token_amount = in_notional * 10_u128.pow(in_decimals) / oracle_0.price as u128; - let out_notional = (out_current_weight as u128) * lp_pool.last_aum / PERCENTAGE_PRECISION; + let out_notional = + (out_current_weight as u128) * lp_pool.last_aum.as_u128() / PERCENTAGE_PRECISION; let out_token_amount = out_notional * 10_u128.pow(out_decimals) / oracle_1.price as u128; let constituent_0 = Constituent { @@ -748,7 +750,7 @@ mod swap_tests { max_weight_deviation: PERCENTAGE_PRECISION_I64 / 10, // 10% spot_market_index: 0, spot_balance: ConstituentSpotBalance { - scaled_balance: 500_000, + scaled_balance: 500_000.into(), cumulative_deposits: 1_000_000, balance_type: SpotBalanceType::Deposit, market_index: 0, @@ -762,7 +764,7 @@ mod swap_tests { let spot_market = SpotMarket { market_index: 0, decimals: 6, - cumulative_deposit_interest: 10_000_000_000_000, + cumulative_deposit_interest: 10_000_000_000_000.into(), ..SpotMarket::default() }; @@ -810,7 +812,7 @@ mod swap_tests { volatility: u64, ) { let lp_pool = LPPool { - last_aum, + last_aum: last_aum.into(), _padding: 0, min_mint_fee: 0, ..LPPool::default() @@ -834,7 +836,7 @@ mod swap_tests { max_weight_deviation: PERCENTAGE_PRECISION_I64 / 10, spot_market_index: 0, spot_balance: ConstituentSpotBalance { - scaled_balance: 0, + scaled_balance: 0.into(), cumulative_deposits: 0, balance_type: SpotBalanceType::Deposit, market_index: 0, @@ -1002,7 +1004,7 @@ mod swap_tests { volatility: u64, ) { let lp_pool = LPPool { - last_aum, + last_aum: last_aum.into(), _padding: 0, min_mint_fee: 100, // 1 bps ..LPPool::default() @@ -1026,7 +1028,7 @@ mod swap_tests { max_weight_deviation: PERCENTAGE_PRECISION_I64 / 10, spot_market_index: 0, spot_balance: ConstituentSpotBalance { - scaled_balance: 0, + scaled_balance: 0.into(), cumulative_deposits: 0, balance_type: SpotBalanceType::Deposit, market_index: 0, @@ -1213,7 +1215,7 @@ mod swap_tests { out_target_weight: i64, ) -> (u128, u128, i128, i128, i128, i128) { let lp_pool = LPPool { - last_aum: 1_000_000_000_000, + last_aum: 1_000_000_000_000.into(), ..LPPool::default() }; @@ -1231,16 +1233,18 @@ mod swap_tests { let in_token_amount = in_notional * 10_i128.pow(6) / oracle_0.price as i128; let in_spot_balance = if in_token_amount > 0 { ConstituentSpotBalance { - scaled_balance: (in_token_amount.abs() as u128) - * (SPOT_BALANCE_PRECISION / 10_u128.pow(6)), + scaled_balance: ((in_token_amount.abs() as u128) + * (SPOT_BALANCE_PRECISION / 10_u128.pow(6))) + .into(), balance_type: SpotBalanceType::Deposit, market_index: 0, ..ConstituentSpotBalance::default() } } else { ConstituentSpotBalance { - scaled_balance: (in_token_amount.abs() as u128) - * (SPOT_BALANCE_PRECISION / 10_u128.pow(6)), + scaled_balance: ((in_token_amount.abs() as u128) + * (SPOT_BALANCE_PRECISION / 10_u128.pow(6))) + .into(), balance_type: SpotBalanceType::Borrow, market_index: 0, ..ConstituentSpotBalance::default() @@ -1252,16 +1256,18 @@ mod swap_tests { let out_token_amount = out_notional * 10_i128.pow(6) / oracle_1.price as i128; let out_spot_balance = if out_token_amount > 0 { ConstituentSpotBalance { - scaled_balance: (out_token_amount.abs() as u128) - * (SPOT_BALANCE_PRECISION / 10_u128.pow(6)), + scaled_balance: ((out_token_amount.abs() as u128) + * (SPOT_BALANCE_PRECISION / 10_u128.pow(6))) + .into(), balance_type: SpotBalanceType::Deposit, market_index: 0, ..ConstituentSpotBalance::default() } } else { ConstituentSpotBalance { - scaled_balance: (out_token_amount.abs() as u128) - * (SPOT_BALANCE_PRECISION / 10_u128.pow(6)), + scaled_balance: ((out_token_amount.abs() as u128) + * (SPOT_BALANCE_PRECISION / 10_u128.pow(6))) + .into(), balance_type: SpotBalanceType::Deposit, market_index: 0, ..ConstituentSpotBalance::default() @@ -1589,7 +1595,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_linear_fee_execution() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1610,7 +1616,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_quadratic_fee_execution() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1631,7 +1637,7 @@ mod swap_fee_tests { #[test] fn test_lp_pool_get_quadratic_fee_inventory() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 ..LPPool::default() }; @@ -1657,7 +1663,7 @@ mod swap_fee_tests { #[test] fn test_target_delays() { let lp_pool = LPPool { - last_aum: 10_000_000 * QUOTE_PRECISION, // $10,000,000 + last_aum: (10_000_000 * QUOTE_PRECISION).into(), // $10,000,000 target_oracle_delay_fee_bps_per_10_slots: 2, target_position_delay_fee_bps_per_10_slots: 10, ..LPPool::default() @@ -2534,7 +2540,7 @@ mod update_aum_tests { let mut usdc_spot_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, historical_oracle_data: HistoricalOracleData::default_quote_oracle(), ..SpotMarket::default() @@ -2545,7 +2551,7 @@ mod update_aum_tests { market_index: 1, oracle_source: OracleSource::PythLazer, oracle: sol_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(200 * PRICE_PRECISION_I64), ..SpotMarket::default() @@ -2556,7 +2562,7 @@ mod update_aum_tests { market_index: 2, oracle_source: OracleSource::PythLazer, oracle: btc_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 8, historical_oracle_data: HistoricalOracleData::default_price( 100_000 * PRICE_PRECISION_I64, @@ -2569,7 +2575,7 @@ mod update_aum_tests { market_index: 3, oracle_source: OracleSource::PythLazer, oracle: bonk_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 5, historical_oracle_data: HistoricalOracleData::default_price(22), ..SpotMarket::default() @@ -2671,7 +2677,8 @@ mod update_aum_tests { // Verify LP pool state was updated assert_eq!( - lp_pool.last_aum, aum, + lp_pool.last_aum, + aum.into(), "{}: last_aum should match calculated AUM", test_name ); @@ -2942,7 +2949,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -2957,7 +2964,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative1_index, oracle_source: OracleSource::PythLazer, oracle: derivative1_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative1_oracle.price), ..SpotMarket::default() @@ -2972,7 +2979,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative2_index, oracle_source: OracleSource::PythLazer, oracle: derivative2_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative2_oracle.price), ..SpotMarket::default() @@ -2987,7 +2994,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative3_index, oracle_source: OracleSource::PythLazer, oracle: derivative3_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative3_oracle.price), ..SpotMarket::default() @@ -3258,7 +3265,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3273,7 +3280,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative_index, oracle_source: OracleSource::PythLazer, oracle: derivative_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative_oracle.price), ..SpotMarket::default() @@ -3547,7 +3554,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3562,7 +3569,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative_index, oracle_source: OracleSource::PythLazer, oracle: derivative_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative_oracle.price), ..SpotMarket::default() @@ -3761,7 +3768,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: parent_index, oracle_source: OracleSource::PythLazer, oracle: parent_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(parent_oracle.price), ..SpotMarket::default() @@ -3776,7 +3783,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative1_index, oracle_source: OracleSource::PythLazer, oracle: derivative1_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative1_oracle.price), ..SpotMarket::default() @@ -3791,7 +3798,7 @@ mod update_constituent_target_base_for_derivatives_tests { market_index: derivative2_index, oracle_source: OracleSource::PythLazer, oracle: derivative2_oracle_pubkey, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 9, historical_oracle_data: HistoricalOracleData::default_price(derivative2_oracle.price), ..SpotMarket::default() diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 0275a5549a..43e6d55e51 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -562,13 +562,13 @@ pub fn get_sb_on_demand_price( let pull_feed_account_info: Ref = load_ref(price_oracle).or(Err(ErrorCode::UnableToLoadOracle))?; - let latest_oracle_submssions: Vec = + let latest_oracle_submissions: Vec = pull_feed_account_info.latest_submissions(); - let average_price = latest_oracle_submssions + let average_price = latest_oracle_submissions .iter() - .map(|submission| submission.value) + .map(|submission| submission.value()) .sum::() - / latest_oracle_submssions.len() as i128; + / latest_oracle_submissions.len() as i128; let price = convert_sb_i128(&average_price)?.cast::()?; @@ -582,7 +582,7 @@ pub fn get_sb_on_demand_price( let delay = clock_slot .cast::()? - .safe_sub(latest_oracle_submssions[0].landed_at.cast()?)?; + .safe_sub(latest_oracle_submissions[0].landed_at.cast()?)?; let has_sufficient_number_of_data_points = true; diff --git a/programs/drift/src/state/oracle/tests.rs b/programs/drift/src/state/oracle/tests.rs index 8d64f725b4..e29fbd4adb 100644 --- a/programs/drift/src/state/oracle/tests.rs +++ b/programs/drift/src/state/oracle/tests.rs @@ -173,11 +173,11 @@ fn use_mm_oracle() { let mut market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: (12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (12295081967_i128).into(), max_spread: 1000, mm_oracle_price: 130 * PRICE_PRECISION_I64 + 973, mm_oracle_slot: slot, @@ -267,11 +267,11 @@ fn mm_oracle_confidence() { let market = PerpMarket { market_index: 0, amm: AMM { - base_asset_reserve: 512295081967, - quote_asset_reserve: 488 * AMM_RESERVE_PRECISION, - sqrt_k: 500 * AMM_RESERVE_PRECISION, - peg_multiplier: 22_100_000_000, - base_asset_amount_with_amm: (12295081967_i128), + base_asset_reserve: 512295081967.into(), + quote_asset_reserve: (488 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (500 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 22_100_000_000.into(), + base_asset_amount_with_amm: (12295081967_i128).into(), max_spread: 1000, mm_oracle_price: 130 * PRICE_PRECISION_I64 + 999, mm_oracle_slot: slot, diff --git a/programs/drift/src/state/oracle_map.rs b/programs/drift/src/state/oracle_map.rs index acbe7c618c..af9644fd46 100644 --- a/programs/drift/src/state/oracle_map.rs +++ b/programs/drift/src/state/oracle_map.rs @@ -12,7 +12,6 @@ use crate::state::user::MarketType; use anchor_lang::prelude::{AccountInfo, Pubkey}; use anchor_lang::Discriminator; use anchor_lang::Key; -use arrayref::array_ref; use std::collections::BTreeMap; use std::iter::Peekable; use std::slice::Iter; @@ -211,14 +210,14 @@ impl<'a> OracleMap<'a> { UnableToLoadOracle })?; - let account_discriminator = array_ref![data, 0, 8]; + let account_discriminator = &data[..8]; - if account_discriminator == &PrelaunchOracle::discriminator() { + if account_discriminator == PrelaunchOracle::DISCRIMINATOR { let expected_data_len = PrelaunchOracle::SIZE; if data.len() < expected_data_len { break; } - } else if account_discriminator == &PythLazerOracle::discriminator() { + } else if account_discriminator == PythLazerOracle::DISCRIMINATOR { let expected_data_len = PythLazerOracle::SIZE; if data.len() < expected_data_len { break; @@ -277,15 +276,15 @@ impl<'a> OracleMap<'a> { UnableToLoadOracle })?; - let account_discriminator = array_ref![data, 0, 8]; + let account_discriminator = &data[..8]; - if account_discriminator == &PrelaunchOracle::discriminator() { + if account_discriminator == PrelaunchOracle::DISCRIMINATOR { let expected_data_len = PrelaunchOracle::SIZE; if data.len() < expected_data_len { msg!("Unexpected account data len loading oracle"); return Err(UnableToLoadOracle); } - } else if account_discriminator == &PythLazerOracle::discriminator() { + } else if account_discriminator == PythLazerOracle::DISCRIMINATOR { let expected_data_len = PythLazerOracle::SIZE; if data.len() < expected_data_len { msg!("Unexpected account data len loading oracle"); diff --git a/programs/drift/src/state/order_params.rs b/programs/drift/src/state/order_params.rs index a5b81b8bb6..f94140cf0c 100644 --- a/programs/drift/src/state/order_params.rs +++ b/programs/drift/src/state/order_params.rs @@ -11,7 +11,6 @@ use crate::state::events::OrderActionExplanation; use crate::state::perp_market::{ContractTier, PerpMarket}; use crate::state::user::{MarketType, OrderTriggerCondition, OrderType}; use anchor_lang::prelude::*; -use borsh::{BorshDeserialize, BorshSerialize}; use std::ops::Div; #[cfg(test)] @@ -38,7 +37,7 @@ pub struct OrderParams { pub auction_end_price: Option, // specified in price or oracle_price_offset } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum OrderParamsBitFlag { ImmediateOrCancel = 0b00000001, UpdateHighLeverageMode = 0b00000010, @@ -917,7 +916,7 @@ fn get_auction_duration( .clamp(1, 180) as u8) // 180 slots max } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum PostOnlyParam { #[default] None, diff --git a/programs/drift/src/state/order_params/tests.rs b/programs/drift/src/state/order_params/tests.rs index d2d54af789..0b3a8a775a 100644 --- a/programs/drift/src/state/order_params/tests.rs +++ b/programs/drift/src/state/order_params/tests.rs @@ -53,12 +53,12 @@ mod update_perp_auction_params { fn test_extreme_sanitize_oracle_order() { let oracle_price = 145 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -149,12 +149,12 @@ mod update_perp_auction_params { fn test_signed_msg_orders_oracle() { let oracle_price = 100 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -272,12 +272,12 @@ mod update_perp_auction_params { fn test_signed_msg_orders_limit() { let oracle_price = 100 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -398,12 +398,12 @@ mod update_perp_auction_params { fn test_extreme_sanitize_oracle_order_huge_market_prem() { let oracle_price = 145 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -446,12 +446,12 @@ mod update_perp_auction_params { fn test_sanitize_limit() { let oracle_price = 100 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -624,12 +624,12 @@ mod update_perp_auction_params { fn test_sanitize_oracle_limit() { let oracle_price = 100 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 1000) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 1000) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -779,12 +779,12 @@ mod update_perp_auction_params { fn test_market_sanitize() { let oracle_price = 99 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 99 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (99 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -889,12 +889,12 @@ mod update_perp_auction_params { fn test_oracle_market_sanitize() { let oracle_price = 99 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -982,12 +982,12 @@ mod update_perp_auction_params { fn test_market_sanatize_no_auction_params() { let oracle_price = 99 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() @@ -1132,12 +1132,12 @@ mod update_perp_auction_params { fn test_oracle_market_sanitize_no_auction_params() { let oracle_price = 99 * PRICE_PRECISION_I64; let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 100) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), volume_24h: 1_000_000 * QUOTE_PRECISION_U64, ..AMM::default() }; diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 36e328037b..f52e447a85 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -36,10 +36,9 @@ use crate::state::oracle::{ }; use crate::state::spot_market::{AssetTier, SpotBalance, SpotBalanceType}; use crate::state::traits::{MarketIndexOffset, Size}; -use borsh::{BorshDeserialize, BorshSerialize}; use crate::state::paused_operations::PerpOperation; -use drift_macros::assert_no_slop; +use drift_macros::{assert_no_slop, legacy_layout}; use static_assertions::const_assert_eq; use super::oracle_map::OracleIdentifier; @@ -51,7 +50,7 @@ use crate::math::oracle::{ #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum MarketStatus { /// warm up period for initialization, fills are paused #[default] @@ -91,7 +90,7 @@ impl MarketStatus { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum LpStatus { /// Not considered #[default] @@ -108,7 +107,7 @@ impl LpStatus { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum ContractType { #[default] Perpetual, @@ -117,7 +116,7 @@ pub enum ContractType { } #[derive( - Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, + Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, )] pub enum ContractTier { /// max insurance capped at A level @@ -154,6 +153,7 @@ impl ContractTier { } } +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug)] #[repr(C)] @@ -373,7 +373,7 @@ impl PerpMarket { .net_revenue_since_last_funding .cast::()? .safe_mul(PERCENTAGE_PRECISION_I128)? - .safe_div(self.amm.total_fee_minus_distributions.max(1))?; + .safe_div(self.amm.total_fee_minus_distributions.as_i128().max(1))?; let percent_drawdown_limit_breached = match self.contract_tier { ContractTier::A => percent_drawdown <= -PERCENTAGE_PRECISION_I128 / 50, @@ -697,6 +697,7 @@ impl PerpMarket { let peg_sqrt = (self .amm .peg_multiplier + .as_u128() .safe_mul(PEG_PRECISION)? .saturating_add(1)) .nth_root(2) @@ -706,8 +707,9 @@ impl PerpMarket { let mut quote_asset_reserve_upper_bound = self .amm .sqrt_k + .as_u128() .safe_mul(peg_sqrt)? - .safe_div(self.amm.peg_multiplier)?; + .safe_div(self.amm.peg_multiplier.into())?; // for price [0,1] maintain following invariants: if direction == PositionDirection::Long { @@ -715,19 +717,21 @@ impl PerpMarket { quote_asset_reserve_lower_bound = self .amm .sqrt_k + .as_u128() .safe_mul(22361)? .safe_mul(peg_sqrt)? .safe_div(100000)? - .safe_div(self.amm.peg_multiplier)? + .safe_div(self.amm.peg_multiplier.into())? } else { // highest bid price is $0.95 quote_asset_reserve_upper_bound = self .amm .sqrt_k + .as_u128() .safe_mul(97467)? .safe_mul(peg_sqrt)? .safe_div(100000)? - .safe_div(self.amm.peg_multiplier)? + .safe_div(self.amm.peg_multiplier.into())? } Ok(( @@ -1025,6 +1029,7 @@ pub struct InsuranceClaim { pub last_revenue_withdraw_ts: i64, } +#[legacy_layout] #[zero_copy(unsafe)] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] @@ -1048,16 +1053,16 @@ impl SpotBalance for PoolBalance { } fn balance(&self) -> u128 { - self.scaled_balance + self.scaled_balance.as_u128() } fn increase_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_add(delta)?; + self.scaled_balance = self.scaled_balance().safe_add(delta)?.into(); Ok(()) } fn decrease_balance(&mut self, delta: u128) -> DriftResult { - self.scaled_balance = self.scaled_balance.safe_sub(delta)?; + self.scaled_balance = self.scaled_balance().safe_sub(delta)?.into(); Ok(()) } @@ -1067,7 +1072,8 @@ impl SpotBalance for PoolBalance { } #[assert_no_slop] -#[zero_copy(unsafe)] +#[legacy_layout] +#[account(zero_copy(unsafe))] #[derive(Debug, PartialEq, Eq)] #[repr(C)] pub struct AMM { @@ -1215,7 +1221,7 @@ pub struct AMM { pub net_revenue_since_last_funding: i64, /// the last funding rate update unix_timestamp pub last_funding_rate_ts: i64, - /// the peridocity of the funding rate updates + /// the periodicity of the funding rate updates pub funding_period: i64, /// the base step size (increment) of orders /// precision: BASE_PRECISION @@ -1296,45 +1302,45 @@ impl Default for AMM { AMM { oracle: Pubkey::default(), historical_oracle_data: HistoricalOracleData::default(), - base_asset_amount_per_lp: 0, - quote_asset_amount_per_lp: 0, + base_asset_amount_per_lp: 0.into(), + quote_asset_amount_per_lp: 0.into(), fee_pool: PoolBalance::default(), - base_asset_reserve: 0, - quote_asset_reserve: 0, - concentration_coef: 0, - min_base_asset_reserve: 0, - max_base_asset_reserve: 0, - sqrt_k: 0, - peg_multiplier: 0, - terminal_quote_asset_reserve: 0, - base_asset_amount_long: 0, - base_asset_amount_short: 0, - base_asset_amount_with_amm: 0, - base_asset_amount_with_unsettled_lp: 0, - max_open_interest: 0, - quote_asset_amount: 0, - quote_entry_amount_long: 0, - quote_entry_amount_short: 0, - quote_break_even_amount_long: 0, - quote_break_even_amount_short: 0, - user_lp_shares: 0, - last_funding_rate: 0, - last_funding_rate_long: 0, - last_funding_rate_short: 0, - last_24h_avg_funding_rate: 0, - total_fee: 0, - total_mm_fee: 0, - total_exchange_fee: 0, - total_fee_minus_distributions: 0, - total_fee_withdrawn: 0, - total_liquidation_fee: 0, - cumulative_funding_rate_long: 0, - cumulative_funding_rate_short: 0, - total_social_loss: 0, - ask_base_asset_reserve: 0, - ask_quote_asset_reserve: 0, - bid_base_asset_reserve: 0, - bid_quote_asset_reserve: 0, + base_asset_reserve: 0.into(), + quote_asset_reserve: 0.into(), + concentration_coef: 0.into(), + min_base_asset_reserve: 0.into(), + max_base_asset_reserve: 0.into(), + sqrt_k: 0.into(), + peg_multiplier: 0.into(), + terminal_quote_asset_reserve: 0.into(), + base_asset_amount_long: 0.into(), + base_asset_amount_short: 0.into(), + base_asset_amount_with_amm: 0.into(), + base_asset_amount_with_unsettled_lp: 0.into(), + max_open_interest: 0.into(), + quote_asset_amount: 0.into(), + quote_entry_amount_long: 0.into(), + quote_entry_amount_short: 0.into(), + quote_break_even_amount_long: 0.into(), + quote_break_even_amount_short: 0.into(), + user_lp_shares: 0.into(), + last_funding_rate: 0.into(), + last_funding_rate_long: 0.into(), + last_funding_rate_short: 0.into(), + last_24h_avg_funding_rate: 0.into(), + total_fee: 0.into(), + total_mm_fee: 0.into(), + total_exchange_fee: 0.into(), + total_fee_minus_distributions: 0.into(), + total_fee_withdrawn: 0.into(), + total_liquidation_fee: 0.into(), + cumulative_funding_rate_long: 0.into(), + cumulative_funding_rate_short: 0.into(), + total_social_loss: 0.into(), + ask_base_asset_reserve: 0.into(), + ask_quote_asset_reserve: 0.into(), + bid_base_asset_reserve: 0.into(), + bid_quote_asset_reserve: 0.into(), last_oracle_normalised_price: 0, last_oracle_reserve_price_spread_pct: 0, last_bid_price_twap: 0, @@ -1443,10 +1449,10 @@ impl AMM { } pub fn get_lower_bound_sqrt_k(self) -> DriftResult { - Ok(self.sqrt_k.min( - (self.min_order_size.cast::()?) - .max(self.base_asset_amount_with_amm.unsigned_abs()), - )) + Ok(self + .sqrt_k + .as_u128() + .min((self.min_order_size as u128).max(self.base_asset_amount_with_amm.unsigned_abs()))) } // direction with_amm is the net user direction @@ -1476,10 +1482,10 @@ impl AMM { pub fn amm_wants_to_jit_make(&self, taker_direction: PositionDirection) -> DriftResult { let amm_wants_to_jit_make = match taker_direction { PositionDirection::Long => { - self.base_asset_amount_with_amm < -(self.order_step_size.cast()?) + self.base_asset_amount_with_amm.as_i128() < -(self.order_step_size as i128) } PositionDirection::Short => { - self.base_asset_amount_with_amm > (self.order_step_size.cast()?) + self.base_asset_amount_with_amm.as_i128() > self.order_step_size as i128 } }; Ok(amm_wants_to_jit_make && self.amm_jit_is_active()) @@ -1491,9 +1497,9 @@ impl AMM { if amm_wants_to_jit_make { // inventory scale let (max_bids, max_asks) = amm::_calculate_market_open_bids_asks( - self.base_asset_reserve, - self.min_base_asset_reserve, - self.max_base_asset_reserve, + self.base_asset_reserve.into(), + self.min_base_asset_reserve.into(), + self.max_base_asset_reserve.into(), )?; let protocol_owned_min_side_liquidity = max_bids.min(max_asks.abs()); @@ -1511,9 +1517,9 @@ impl AMM { pub fn reserve_price(&self) -> DriftResult { amm::calculate_price( - self.quote_asset_reserve, - self.base_asset_reserve, - self.peg_multiplier, + self.quote_asset_reserve.into(), + self.base_asset_reserve.into(), + self.peg_multiplier.into(), ) } @@ -1574,7 +1580,7 @@ impl AMM { .base_asset_amount_with_amm .unsigned_abs() .max(min_order_size_u128) - < self.sqrt_k) + < self.sqrt_k.into()) && (min_order_size_u128 < max_bids.unsigned_abs().max(max_asks.unsigned_abs())); Ok(can_lower) @@ -1760,16 +1766,16 @@ impl AMM { let default_reserves = 100 * AMM_RESERVE_PRECISION; // make sure tests dont have the default sqrt_k = 0 AMM { - base_asset_reserve: default_reserves, - quote_asset_reserve: default_reserves, - sqrt_k: default_reserves, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, + base_asset_reserve: default_reserves.into(), + quote_asset_reserve: default_reserves.into(), + sqrt_k: default_reserves.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), order_step_size: 1, order_tick_size: 1, - max_base_asset_reserve: u64::MAX as u128, - min_base_asset_reserve: 0, - terminal_quote_asset_reserve: default_reserves, - peg_multiplier: crate::math::constants::PEG_PRECISION, + max_base_asset_reserve: (u64::MAX as u128).into(), + min_base_asset_reserve: 0.into(), + terminal_quote_asset_reserve: default_reserves.into(), + peg_multiplier: crate::math::constants::PEG_PRECISION.into(), max_fill_reserve_fraction: 1, max_spread: 1000, historical_oracle_data: HistoricalOracleData { @@ -1785,21 +1791,21 @@ impl AMM { use crate::math::constants::PRICE_PRECISION_I64; AMM { - base_asset_reserve: 65 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 63015384615, - terminal_quote_asset_reserve: 64 * AMM_RESERVE_PRECISION, - sqrt_k: 64 * AMM_RESERVE_PRECISION, + base_asset_reserve: (65 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: 63015384615.into(), + terminal_quote_asset_reserve: (64 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (64 * AMM_RESERVE_PRECISION).into(), - peg_multiplier: 19_400_000_000, + peg_multiplier: 19_400_000_000.into(), - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - max_base_asset_reserve: 90 * AMM_RESERVE_PRECISION, - min_base_asset_reserve: 45 * AMM_RESERVE_PRECISION, + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + max_base_asset_reserve: (90 * AMM_RESERVE_PRECISION).into(), + min_base_asset_reserve: (45 * AMM_RESERVE_PRECISION).into(), - base_asset_amount_with_amm: -(AMM_RESERVE_PRECISION as i128), + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128 * -1).into(), mark_std: PRICE_PRECISION as u64, - quote_asset_amount: 19_000_000_000, // short 1 BTC @ $19000 + quote_asset_amount: 19_000_000_000.into(), // short 1 BTC @ $19000 historical_oracle_data: HistoricalOracleData { last_oracle_price: 19_400 * PRICE_PRECISION_I64, last_oracle_price_twap: 19_400 * PRICE_PRECISION_I64, diff --git a/programs/drift/src/state/perp_market/tests.rs b/programs/drift/src/state/perp_market/tests.rs index 3f09e5c58c..6a489f491d 100644 --- a/programs/drift/src/state/perp_market/tests.rs +++ b/programs/drift/src/state/perp_market/tests.rs @@ -7,12 +7,12 @@ mod amm { #[test] fn last_ask_premium() { let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), ..AMM::default() }; amm.historical_oracle_data.last_oracle_price = 100 * PRICE_PRECISION_I64; @@ -25,12 +25,12 @@ mod amm { #[test] fn last_bid_discount() { let mut amm = AMM { - base_asset_reserve: 100 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 100 * AMM_RESERVE_PRECISION, + base_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (100 * AMM_RESERVE_PRECISION).into(), short_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, long_spread: (BID_ASK_SPREAD_PRECISION / 10) as u32, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 100 * PEG_PRECISION, + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: (100 * PEG_PRECISION).into(), ..AMM::default() }; amm.historical_oracle_data.last_oracle_price = 100 * PRICE_PRECISION_I64; @@ -590,13 +590,13 @@ mod amm_can_fill_order_tests { assert!(!can1); // valid oracle for immediate and user can skip, market can skip due to low inventory => can fill - market.amm.base_asset_amount_with_amm = -2; // taker long improves balance + market.amm.set_base_asset_amount_with_amm(-2); // taker long improves balance market.amm.order_step_size = 1; - market.amm.base_asset_reserve = 1_000_000; - market.amm.quote_asset_reserve = 1_000_000; - market.amm.sqrt_k = 1_000_000; - market.amm.max_base_asset_reserve = 2_000_000; - market.amm.min_base_asset_reserve = 0; + market.amm.set_base_asset_reserve(1_000_000); + market.amm.set_quote_asset_reserve(1_000_000); + market.amm.set_sqrt_k(1_000_000); + market.amm.set_max_base_asset_reserve(2_000_000); + market.amm.set_min_base_asset_reserve(0); let can2 = market .amm_can_fill_order( diff --git a/programs/drift/src/state/perp_market_map.rs b/programs/drift/src/state/perp_market_map.rs index 73c6d37d9d..b9770cb3f2 100644 --- a/programs/drift/src/state/perp_market_map.rs +++ b/programs/drift/src/state/perp_market_map.rs @@ -25,7 +25,7 @@ pub struct PerpMarketMap<'a>(pub BTreeMap>); impl<'a> PerpMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref(&self, market_index: &u16) -> DriftResult> { + pub fn get_ref(&self, market_index: &u16) -> DriftResult> { let loader = match self.0.get(market_index) { Some(loader) => loader, None => { @@ -58,7 +58,7 @@ impl<'a> PerpMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { + pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { let loader = match self.0.get(market_index) { Some(loader) => loader, None => { @@ -95,7 +95,6 @@ impl<'a> PerpMarketMap<'a> { ) -> DriftResult> { let mut perp_market_map: PerpMarketMap = PerpMarketMap(BTreeMap::new()); - let market_discriminator: [u8; 8] = PerpMarket::discriminator(); while let Some(account_info) = account_info_iter.peek() { let data = account_info .try_borrow_data() @@ -106,8 +105,8 @@ impl<'a> PerpMarketMap<'a> { break; } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != PerpMarket::DISCRIMINATOR { break; } @@ -154,9 +153,8 @@ impl<'a> PerpMarketMap<'a> { return Err(ErrorCode::CouldNotLoadMarketData); } - let market_discriminator: [u8; 8] = PerpMarket::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != PerpMarket::DISCRIMINATOR { return Err(ErrorCode::CouldNotLoadMarketData); } @@ -197,9 +195,8 @@ impl<'a> PerpMarketMap<'a> { return Err(ErrorCode::CouldNotLoadMarketData); } - let market_discriminator: [u8; 8] = PerpMarket::discriminator(); - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != PerpMarket::DISCRIMINATOR { return Err(ErrorCode::CouldNotLoadMarketData); } diff --git a/programs/drift/src/state/revenue_share.rs b/programs/drift/src/state/revenue_share.rs index 6d99427054..56598f7cbc 100644 --- a/programs/drift/src/state/revenue_share.rs +++ b/programs/drift/src/state/revenue_share.rs @@ -1,10 +1,10 @@ use std::cell::{Ref, RefMut}; -use anchor_lang::prelude::Pubkey; -use anchor_lang::*; -use anchor_lang::{account, zero_copy}; -use borsh::{BorshDeserialize, BorshSerialize}; -use prelude::AccountInfo; +use anchor_lang::prelude::{ + account, + borsh::{self, BorshDeserialize, BorshSerialize}, + zero_copy, AccountInfo, AnchorDeserialize, AnchorSerialize, Discriminator, Pubkey, +}; use crate::error::{DriftResult, ErrorCode}; use crate::math::casting::Cast; @@ -16,7 +16,7 @@ use crate::{msg, ID}; pub const REVENUE_SHARE_PDA_SEED: &str = "REV_SHARE"; pub const REVENUE_SHARE_ESCROW_PDA_SEED: &str = "REV_ESCROW"; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum RevenueShareOrderBitFlag { #[default] Init = 0b00000000, @@ -513,12 +513,12 @@ impl<'a> RevenueShareEscrowZeroCopyMut<'a> { } pub trait RevenueShareEscrowLoader<'a> { - fn load_zc(&self) -> DriftResult; - fn load_zc_mut(&self) -> DriftResult; + fn load_zc(&self) -> DriftResult>; + fn load_zc_mut(&self) -> DriftResult>; } impl<'a> RevenueShareEscrowLoader<'a> for AccountInfo<'a> { - fn load_zc(&self) -> DriftResult { + fn load_zc(&self) -> DriftResult> { let owner = self.owner; validate!( @@ -531,7 +531,7 @@ impl<'a> RevenueShareEscrowLoader<'a> for AccountInfo<'a> { let (discriminator, data) = Ref::map_split(data, |d| d.split_at(8)); validate!( - *discriminator == RevenueShareEscrow::discriminator(), + discriminator.as_ref() == RevenueShareEscrow::DISCRIMINATOR, ErrorCode::DefaultError, "invalid signed_msg user orders discriminator", )?; @@ -544,7 +544,7 @@ impl<'a> RevenueShareEscrowLoader<'a> for AccountInfo<'a> { }) } - fn load_zc_mut(&self) -> DriftResult { + fn load_zc_mut(&self) -> DriftResult> { let owner = self.owner; validate!( @@ -557,7 +557,7 @@ impl<'a> RevenueShareEscrowLoader<'a> for AccountInfo<'a> { let (discriminator, data) = RefMut::map_split(data, |d| d.split_at_mut(8)); validate!( - *discriminator == RevenueShareEscrow::discriminator(), + discriminator.as_ref() == RevenueShareEscrow::DISCRIMINATOR, ErrorCode::DefaultError, "invalid signed_msg user orders discriminator", )?; diff --git a/programs/drift/src/state/revenue_share_map.rs b/programs/drift/src/state/revenue_share_map.rs index 2e45195040..39347bb048 100644 --- a/programs/drift/src/state/revenue_share_map.rs +++ b/programs/drift/src/state/revenue_share_map.rs @@ -71,7 +71,7 @@ impl<'a> RevenueShareMap<'a> { #[track_caller] #[inline(always)] - pub fn get_user_ref_mut(&self, authority: &Pubkey) -> DriftResult> { + pub fn get_user_ref_mut(&self, authority: &Pubkey) -> DriftResult> { let loader = match self.0.get(authority).and_then(|e| e.user.as_ref()) { Some(loader) => loader, None => { @@ -107,7 +107,7 @@ impl<'a> RevenueShareMap<'a> { pub fn get_revenue_share_account_mut( &self, authority: &Pubkey, - ) -> DriftResult> { + ) -> DriftResult> { let loader = match self.0.get(authority).and_then(|e| e.revenue_share.as_ref()) { Some(loader) => loader, None => { @@ -144,9 +144,6 @@ pub fn load_revenue_share_map<'a: 'b, 'b>( ) -> DriftResult> { let mut revenue_share_map = RevenueShareMap::empty(); - let user_discriminator: [u8; 8] = User::discriminator(); - let rev_share_discriminator: [u8; 8] = RevenueShare::discriminator(); - while let Some(account_info) = account_info_iter.peek() { let data = account_info .try_borrow_data() @@ -156,9 +153,9 @@ pub fn load_revenue_share_map<'a: 'b, 'b>( break; } - let account_discriminator = array_ref![data, 0, 8]; + let account_discriminator = &data[..8]; - if account_discriminator == &user_discriminator { + if account_discriminator == User::DISCRIMINATOR { let user_account_info = account_info_iter.next().safe_unwrap()?; let is_writable = user_account_info.is_writable; if !is_writable { @@ -184,7 +181,7 @@ pub fn load_revenue_share_map<'a: 'b, 'b>( continue; } - if account_discriminator == &rev_share_discriminator { + if account_discriminator == RevenueShare::DISCRIMINATOR { let revenue_share_account_info = account_info_iter.next().safe_unwrap()?; let is_writable = revenue_share_account_info.is_writable; if !is_writable { diff --git a/programs/drift/src/state/settle_pnl_mode.rs b/programs/drift/src/state/settle_pnl_mode.rs index f13002d7db..e5d4375034 100644 --- a/programs/drift/src/state/settle_pnl_mode.rs +++ b/programs/drift/src/state/settle_pnl_mode.rs @@ -1,12 +1,15 @@ use crate::error::{DriftResult, ErrorCode}; use crate::msg; -use borsh::{BorshDeserialize, BorshSerialize}; +use anchor_lang::prelude::{ + borsh::{self}, + AnchorDeserialize, AnchorSerialize, +}; use std::panic::Location; #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum SettlePnlMode { MustSettle, TrySettle, diff --git a/programs/drift/src/state/signed_msg_user.rs b/programs/drift/src/state/signed_msg_user.rs index 953cdd3a6a..5abdc5c327 100644 --- a/programs/drift/src/state/signed_msg_user.rs +++ b/programs/drift/src/state/signed_msg_user.rs @@ -4,11 +4,14 @@ use crate::error::{DriftResult, ErrorCode}; use crate::math::safe_unwrap::SafeUnwrap; use crate::msg; use crate::{validate, ID}; -use anchor_lang::prelude::Pubkey; -use anchor_lang::*; -use anchor_lang::{account, zero_copy}; -use borsh::{BorshDeserialize, BorshSerialize}; -use prelude::AccountInfo; +use anchor_lang::{ + account, + prelude::{ + borsh::{self, BorshDeserialize, BorshSerialize}, + AccountInfo, AnchorDeserialize, AnchorSerialize, Discriminator, Pubkey, + }, + zero_copy, +}; use crate::state::traits::Size; @@ -169,12 +172,12 @@ impl<'a> SignedMsgUserOrdersZeroCopyMut<'a> { } pub trait SignedMsgUserOrdersLoader<'a> { - fn load(&self) -> DriftResult; - fn load_mut(&self) -> DriftResult; + fn load(&self) -> DriftResult>; + fn load_mut(&self) -> DriftResult>; } impl<'a> SignedMsgUserOrdersLoader<'a> for AccountInfo<'a> { - fn load(&self) -> DriftResult { + fn load(&self) -> DriftResult> { let owner = self.owner; validate!( @@ -187,7 +190,7 @@ impl<'a> SignedMsgUserOrdersLoader<'a> for AccountInfo<'a> { let (discriminator, data) = Ref::map_split(data, |d| d.split_at(8)); validate!( - *discriminator == SignedMsgUserOrders::discriminator(), + discriminator.as_ref() == SignedMsgUserOrders::DISCRIMINATOR, ErrorCode::DefaultError, "invalid signed_msg user orders discriminator", )?; @@ -199,7 +202,7 @@ impl<'a> SignedMsgUserOrdersLoader<'a> for AccountInfo<'a> { }) } - fn load_mut(&self) -> DriftResult { + fn load_mut(&self) -> DriftResult> { let owner = self.owner; validate!( @@ -212,7 +215,7 @@ impl<'a> SignedMsgUserOrdersLoader<'a> for AccountInfo<'a> { let (discriminator, data) = RefMut::map_split(data, |d| d.split_at_mut(8)); validate!( - *discriminator == SignedMsgUserOrders::discriminator(), + discriminator.as_ref() == SignedMsgUserOrders::DISCRIMINATOR, ErrorCode::DefaultError, "invalid signed_msg user orders discriminator", )?; diff --git a/programs/drift/src/state/signed_msg_user/tests.rs b/programs/drift/src/state/signed_msg_user/tests.rs index 535a60953b..985a6dec41 100644 --- a/programs/drift/src/state/signed_msg_user/tests.rs +++ b/programs/drift/src/state/signed_msg_user/tests.rs @@ -2,8 +2,7 @@ mod signed_msg_order_id_eviction { use std::cell::RefCell; - use anchor_lang::prelude::Pubkey; - use borsh::BorshSerialize; + use anchor_lang::prelude::{AnchorSerialize, Pubkey}; use crate::{ error::ErrorCode, @@ -142,8 +141,10 @@ mod zero_copy { use crate::test_utils::create_account_info; use crate::ID; - use anchor_lang::{prelude::Pubkey, Discriminator}; - use borsh::BorshSerialize; + use anchor_lang::{ + prelude::{AnchorSerialize, Pubkey}, + Discriminator, + }; use crate::{ error::ErrorCode, @@ -170,7 +171,7 @@ mod zero_copy { } let mut bytes = Vec::with_capacity(8 + orders.try_to_vec().unwrap().len()); - bytes.extend_from_slice(&SignedMsgUserOrders::discriminator()); + bytes.extend_from_slice(&SignedMsgUserOrders::DISCRIMINATOR); bytes.extend_from_slice(&orders.try_to_vec().unwrap()); let pubkey = Pubkey::default(); @@ -211,7 +212,7 @@ mod zero_copy { // invalid discriminator let mut bytes = Vec::with_capacity(8 + orders.try_to_vec().unwrap().len()); bytes.extend_from_slice(&orders.try_to_vec().unwrap()); - bytes.extend_from_slice(&SignedMsgUserOrders::discriminator()); + bytes.extend_from_slice(&SignedMsgUserOrders::DISCRIMINATOR); let orders_account_info = create_account_info(&random_pubkey, false, &mut lamports, &mut bytes, &ID); let result = orders_account_info.load(); @@ -237,7 +238,7 @@ mod zero_copy { } let mut bytes = Vec::with_capacity(8 + orders.try_to_vec().unwrap().len()); - bytes.extend_from_slice(&SignedMsgUserOrders::discriminator()); + bytes.extend_from_slice(&SignedMsgUserOrders::DISCRIMINATOR); bytes.extend_from_slice(&orders.try_to_vec().unwrap()); let pubkey = Pubkey::default(); @@ -279,7 +280,7 @@ mod zero_copy { // invalid discriminator let mut bytes = Vec::with_capacity(8 + orders.try_to_vec().unwrap().len()); bytes.extend_from_slice(&orders.try_to_vec().unwrap()); - bytes.extend_from_slice(&SignedMsgUserOrders::discriminator()); + bytes.extend_from_slice(&SignedMsgUserOrders::DISCRIMINATOR); let orders_account_info = create_account_info(&random_pubkey, true, &mut lamports, &mut bytes, &ID); let result = orders_account_info.load_mut(); diff --git a/programs/drift/src/state/spot_market.rs b/programs/drift/src/state/spot_market.rs index c42000a7b1..e5ea34de34 100644 --- a/programs/drift/src/state/spot_market.rs +++ b/programs/drift/src/state/spot_market.rs @@ -1,11 +1,6 @@ use std::fmt; use std::fmt::{Display, Formatter}; -use anchor_lang::prelude::*; -use anchor_spl::token::spl_token; -use anchor_spl::token_2022::spl_token_2022; -use borsh::{BorshDeserialize, BorshSerialize}; - use crate::error::{DriftResult, ErrorCode}; use crate::math::casting::Cast; use crate::math::constants::{ @@ -20,6 +15,10 @@ use crate::math::margin::{ }; use crate::math::safe_math::SafeMath; use crate::math::spot_balance::{calculate_utilization, get_token_amount, get_token_value}; +use anchor_lang::prelude::*; +use anchor_spl::token::spl_token; +use anchor_spl::token_2022::spl_token_2022; +use drift_macros::legacy_layout; use crate::math::stats::calculate_new_twap; use crate::state::oracle::{HistoricalIndexData, HistoricalOracleData, OracleSource}; @@ -30,6 +29,7 @@ use crate::validate; use super::oracle_map::OracleIdentifier; +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(PartialEq, Eq, Debug)] #[repr(C)] @@ -223,13 +223,13 @@ impl Default for SpotMarket { revenue_pool: PoolBalance::default(), spot_fee_pool: PoolBalance::default(), insurance_fund: InsuranceFund::default(), - total_spot_fee: 0, - deposit_balance: 0, - borrow_balance: 0, - cumulative_deposit_interest: 0, - cumulative_borrow_interest: 0, - total_social_loss: 0, - total_quote_social_loss: 0, + total_spot_fee: 0.into(), + deposit_balance: 0.into(), + borrow_balance: 0.into(), + cumulative_deposit_interest: 0.into(), + cumulative_borrow_interest: 0.into(), + total_social_loss: 0.into(), + total_quote_social_loss: 0.into(), withdraw_guard_threshold: 0, max_token_deposits: 0, deposit_token_twap: 0, @@ -449,11 +449,11 @@ impl SpotMarket { } pub fn get_deposits(&self) -> DriftResult { - get_token_amount(self.deposit_balance, self, &SpotBalanceType::Deposit) + get_token_amount(self.deposit_balance.into(), self, &SpotBalanceType::Deposit) } pub fn get_borrows(&self) -> DriftResult { - get_token_amount(self.borrow_balance, self, &SpotBalanceType::Borrow) + get_token_amount(self.borrow_balance.into(), self, &SpotBalanceType::Borrow) } pub fn get_tvl(&self) -> DriftResult { @@ -500,10 +500,10 @@ impl SpotMarket { pub fn get_available_deposits(&self) -> DriftResult { let deposit_token_amount = - get_token_amount(self.deposit_balance, self, &SpotBalanceType::Deposit)?; + get_token_amount(self.deposit_balance.into(), self, &SpotBalanceType::Deposit)?; let borrow_token_amount = - get_token_amount(self.borrow_balance, self, &SpotBalanceType::Borrow)?; + get_token_amount(self.borrow_balance.into(), self, &SpotBalanceType::Borrow)?; deposit_token_amount.safe_sub(borrow_token_amount) } @@ -513,11 +513,14 @@ impl SpotMarket { } pub fn get_utilization(self) -> DriftResult { - let deposit_token_amount = - get_token_amount(self.deposit_balance, &self, &SpotBalanceType::Deposit)?; + let deposit_token_amount = get_token_amount( + self.deposit_balance.into(), + &self, + &SpotBalanceType::Deposit, + )?; let borrow_token_amount = - get_token_amount(self.borrow_balance, &self, &SpotBalanceType::Borrow)?; + get_token_amount(self.borrow_balance.into(), &self, &SpotBalanceType::Borrow)?; calculate_utilization(deposit_token_amount, borrow_token_amount) } @@ -597,8 +600,8 @@ impl SpotMarket { pub fn default_base_market() -> Self { SpotMarket { market_index: 1, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), initial_liability_weight: 12000, maintenance_liability_weight: 11000, initial_asset_weight: 8000, @@ -613,8 +616,8 @@ impl SpotMarket { pub fn default_quote_market() -> Self { SpotMarket { - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, - cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), + cumulative_borrow_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_liability_weight: 10000, maintenance_liability_weight: 10000, @@ -632,7 +635,7 @@ impl SpotMarket { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Debug, Default)] pub enum SpotBalanceType { #[default] Deposit, @@ -662,7 +665,7 @@ pub trait SpotBalance { fn update_balance_type(&mut self, balance_type: SpotBalanceType) -> DriftResult; } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum SpotFulfillmentConfigStatus { #[default] Enabled, @@ -670,7 +673,7 @@ pub enum SpotFulfillmentConfigStatus { } #[derive( - Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, + Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, )] pub enum AssetTier { /// full priviledge @@ -686,6 +689,7 @@ pub enum AssetTier { Unlisted, } +#[legacy_layout] #[zero_copy(unsafe)] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] @@ -703,11 +707,13 @@ pub struct InsuranceFund { impl InsuranceFund { pub fn get_protocol_shares(&self) -> DriftResult { - self.total_shares.safe_sub(self.user_shares) + self.total_shares + .as_u128() + .safe_sub(self.user_shares.as_u128()) } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum TokenProgramFlag { Token2022 = 0b00000001, TransferHook = 0b00000010, diff --git a/programs/drift/src/state/spot_market_map.rs b/programs/drift/src/state/spot_market_map.rs index e93ad8630a..cb34ed06f6 100644 --- a/programs/drift/src/state/spot_market_map.rs +++ b/programs/drift/src/state/spot_market_map.rs @@ -24,7 +24,7 @@ pub struct SpotMarketMap<'a>( impl<'a> SpotMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref(&self, market_index: &u16) -> DriftResult> { + pub fn get_ref(&self, market_index: &u16) -> DriftResult> { let loader = match self.0.get(market_index) { Some(loader) => loader, None => { @@ -57,7 +57,7 @@ impl<'a> SpotMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { + pub fn get_ref_mut(&self, market_index: &u16) -> DriftResult> { if !self.1.contains(market_index) { let caller = Location::caller(); msg!( @@ -101,7 +101,7 @@ impl<'a> SpotMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_quote_spot_market(&self) -> DriftResult> { + pub fn get_quote_spot_market(&self) -> DriftResult> { let loader = match self.0.get("E_SPOT_MARKET_INDEX) { Some(loader) => loader, None => { @@ -134,7 +134,7 @@ impl<'a> SpotMarketMap<'a> { #[track_caller] #[inline(always)] - pub fn get_quote_spot_market_mut(&self) -> DriftResult> { + pub fn get_quote_spot_market_mut(&self) -> DriftResult> { if !self.1.contains("E_SPOT_MARKET_INDEX) { let caller = Location::caller(); msg!( @@ -183,7 +183,6 @@ impl<'a> SpotMarketMap<'a> { let mut spot_market_map: SpotMarketMap = SpotMarketMap(BTreeMap::new(), writable_spot_markets.clone()); - let spot_market_discriminator: [u8; 8] = SpotMarket::discriminator(); while let Some(account_info) = account_info_iter.peek() { let data = account_info .try_borrow_data() @@ -194,8 +193,8 @@ impl<'a> SpotMarketMap<'a> { break; } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &spot_market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != SpotMarket::DISCRIMINATOR { break; } @@ -232,7 +231,6 @@ impl<'a> SpotMarketMap<'a> { let mut writable_markets = SpotMarketSet::new(); let mut map = BTreeMap::new(); - let spot_market_discriminator: [u8; 8] = SpotMarket::discriminator(); let data = account_info .try_borrow_data() .or(Err(ErrorCode::CouldNotLoadSpotMarketData))?; @@ -242,8 +240,8 @@ impl<'a> SpotMarketMap<'a> { return Err(ErrorCode::CouldNotLoadSpotMarketData); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &spot_market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != SpotMarket::DISCRIMINATOR { return Err(ErrorCode::CouldNotLoadSpotMarketData); } @@ -284,7 +282,6 @@ impl<'a> SpotMarketMap<'a> { let account_info_iter = account_info.into_iter(); for account_info in account_info_iter { - let spot_market_discriminator: [u8; 8] = SpotMarket::discriminator(); let data = account_info .try_borrow_data() .or(Err(ErrorCode::CouldNotLoadSpotMarketData))?; @@ -294,8 +291,8 @@ impl<'a> SpotMarketMap<'a> { return Err(ErrorCode::CouldNotLoadSpotMarketData); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &spot_market_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != SpotMarket::DISCRIMINATOR { return Err(ErrorCode::CouldNotLoadSpotMarketData); } diff --git a/programs/drift/src/state/state.rs b/programs/drift/src/state/state.rs index 07e9213396..14afc90bd9 100644 --- a/programs/drift/src/state/state.rs +++ b/programs/drift/src/state/state.rs @@ -1,4 +1,5 @@ use anchor_lang::prelude::*; +use drift_macros::legacy_layout; use enumflags2::BitFlags; use crate::error::DriftResult; @@ -13,6 +14,7 @@ use crate::state::traits::Size; #[cfg(test)] mod tests; +#[legacy_layout] #[account] #[derive(Default)] #[repr(C)] @@ -254,6 +256,7 @@ impl Default for FeeTier { } } +#[legacy_layout] #[derive(AnchorSerialize, AnchorDeserialize, Default, Clone, Debug)] pub struct OrderFillerRewardStructure { pub reward_numerator: u32, @@ -329,7 +332,7 @@ impl FeeStructure { filler_reward_structure: OrderFillerRewardStructure { reward_numerator: 10, reward_denominator: FEE_PERCENTAGE_DENOMINATOR, - time_based_reward_lower_bound: 10_000, // 1 cent + time_based_reward_lower_bound: 10_000.into(), // 1 cent }, flat_filler_fee: 10_000, referrer_reward_epoch_upper_bound: MAX_REFERRER_REWARD_EPOCH_UPPER_BOUND, @@ -353,7 +356,7 @@ impl FeeStructure { filler_reward_structure: OrderFillerRewardStructure { reward_numerator: 10, reward_denominator: FEE_PERCENTAGE_DENOMINATOR, - time_based_reward_lower_bound: 10_000, // 1 cent + time_based_reward_lower_bound: 10_000.into(), // 1 cent }, flat_filler_fee: 10_000, referrer_reward_epoch_upper_bound: MAX_REFERRER_REWARD_EPOCH_UPPER_BOUND, @@ -380,7 +383,7 @@ impl FeeStructure { filler_reward_structure: OrderFillerRewardStructure { reward_numerator: 10, reward_denominator: FEE_PERCENTAGE_DENOMINATOR, - time_based_reward_lower_bound: 10_000, // 1 cent + time_based_reward_lower_bound: 10_000.into(), // 1 cent }, ..FeeStructure::perps_default() } diff --git a/programs/drift/src/state/user.rs b/programs/drift/src/state/user.rs index 649c6cfcaa..c6ab2aa9c4 100644 --- a/programs/drift/src/state/user.rs +++ b/programs/drift/src/state/user.rs @@ -28,9 +28,13 @@ use crate::state::spot_market::{SpotBalance, SpotBalanceType, SpotMarket}; use crate::state::traits::Size; use crate::validate; use crate::{get_then_update_id, ID}; -use anchor_lang::prelude::*; -use borsh::{BorshDeserialize, BorshSerialize}; +use anchor_lang::prelude::{ + borsh::{self, BorshDeserialize, BorshSerialize}, + *, +}; use bytemuck::{Pod, Zeroable}; +use drift_macros::legacy_layout; +use num_traits::Zero; use std::cmp::max; use std::fmt; use std::ops::Neg; @@ -48,7 +52,7 @@ use crate::state::spot_market_map::SpotMarketMap; #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum UserStatus { // Active = 0 BeingLiquidated = 0b00000001, @@ -1197,7 +1201,7 @@ impl PerpPosition { #[zero_copy(unsafe)] #[repr(C)] -#[derive(AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] +#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] pub struct Order { /// The slot the order was placed pub slot: u64, @@ -1264,7 +1268,7 @@ pub struct Order { pub padding: [u8; 1], } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Debug)] pub enum AssetType { Base, Quote, @@ -1593,7 +1597,7 @@ impl Default for Order { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Eq, Debug)] pub enum OrderStatus { /// The order is not in use Init, @@ -1605,7 +1609,7 @@ pub enum OrderStatus { Canceled, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum OrderType { Market, #[default] @@ -1616,7 +1620,7 @@ pub enum OrderType { Oracle, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum OrderTriggerCondition { #[default] Above, @@ -1625,7 +1629,7 @@ pub enum OrderTriggerCondition { TriggeredBelow, // below condition has been triggered } -#[derive(Default, Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Default, Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum MarketType { #[default] Spot, @@ -1644,7 +1648,7 @@ impl fmt::Display for MarketType { unsafe impl Zeroable for MarketType {} unsafe impl Pod for MarketType {} -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] pub enum OrderBitFlag { SignedMessage = 0b00000001, OracleTriggerMarket = 0b00000010, @@ -1722,7 +1726,7 @@ pub struct UserStats { pub padding: [u8; 12], } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] #[repr(u8)] pub enum ReferrerStatus { IsReferrer = 0b00000001, @@ -2087,7 +2091,7 @@ impl Size for ReferrerName { const SIZE: usize = 136; } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum MarginMode { #[default] Default, @@ -2095,7 +2099,7 @@ pub enum MarginMode { HighLeverageMaintenance, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] #[repr(u8)] pub enum FuelOverflowStatus { Exists = 0b00000001, @@ -2106,6 +2110,8 @@ impl FuelOverflowStatus { status & FuelOverflowStatus::Exists as u8 != 0 } } + +#[legacy_layout] #[account(zero_copy(unsafe))] #[derive(Default, Debug)] #[repr(C)] @@ -2132,40 +2138,57 @@ impl FuelOverflow { pub fn update_from_user_stats(&mut self, user_stats: &UserStats, now: u32) -> DriftResult<()> { self.fuel_insurance = self .fuel_insurance - .safe_add(user_stats.fuel_insurance.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_insurance as u128)? + .into(); self.fuel_deposits = self .fuel_deposits - .safe_add(user_stats.fuel_deposits.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_deposits as u128)? + .into(); self.fuel_borrows = self .fuel_borrows - .safe_add(user_stats.fuel_borrows.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_borrows as u128)? + .into(); self.fuel_positions = self .fuel_positions - .safe_add(user_stats.fuel_positions.cast()?)?; - self.fuel_taker = self.fuel_taker.safe_add(user_stats.fuel_taker.cast()?)?; - self.fuel_maker = self.fuel_maker.safe_add(user_stats.fuel_maker.cast()?)?; + .as_u128() + .safe_add(user_stats.fuel_positions as u128)? + .into(); + self.fuel_taker = self + .fuel_taker + .as_u128() + .safe_add(user_stats.fuel_taker as u128)? + .into(); + self.fuel_maker = self + .fuel_maker + .as_u128() + .safe_add(user_stats.fuel_maker as u128)? + .into(); self.last_fuel_sweep_ts = now; Ok(()) } pub fn reset_fuel(&mut self, now: u32) { - self.fuel_insurance = 0; - self.fuel_deposits = 0; - self.fuel_borrows = 0; - self.fuel_positions = 0; - self.fuel_taker = 0; - self.fuel_maker = 0; + self.fuel_insurance = Zero::zero(); + self.fuel_deposits = Zero::zero(); + self.fuel_borrows = Zero::zero(); + self.fuel_positions = Zero::zero(); + self.fuel_taker = Zero::zero(); + self.fuel_maker = Zero::zero(); self.last_reset_ts = now; } pub fn total_fuel(&self) -> DriftResult { self.fuel_insurance - .safe_add(self.fuel_deposits)? - .safe_add(self.fuel_borrows)? - .safe_add(self.fuel_positions)? - .safe_add(self.fuel_taker)? - .safe_add(self.fuel_maker) + .as_u128() + .safe_add(self.fuel_deposits.as_u128())? + .safe_add(self.fuel_borrows.as_u128())? + .safe_add(self.fuel_positions.as_u128())? + .safe_add(self.fuel_taker.as_u128())? + .safe_add(self.fuel_maker.as_u128()) } } diff --git a/programs/drift/src/state/user/tests.rs b/programs/drift/src/state/user/tests.rs index 4b2392d1ba..335bbfd24a 100644 --- a/programs/drift/src/state/user/tests.rs +++ b/programs/drift/src/state/user/tests.rs @@ -214,30 +214,30 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; let perp_market = PerpMarket { amm: AMM { - base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 150_000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION_I128, + base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 150_000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION_I128).into(), curve_update_intensity: 100, - base_asset_amount_with_amm: AMM_RESERVE_PRECISION as i128, - quote_asset_amount: -100 * QUOTE_PRECISION_I128, + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128).into(), + quote_asset_amount: (-100 * QUOTE_PRECISION_I128).into(), ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (10 * SPOT_BALANCE_PRECISION), + scaled_balance: (10 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -280,7 +280,7 @@ mod get_claimable_pnl { let oracle_price = 150 * PRICE_PRECISION_I64; let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), &usdc_market, perp_market.pnl_pool.balance_type(), ) @@ -320,30 +320,30 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; let mut perp_market = PerpMarket { amm: AMM { - base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 150_000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION_I128, + base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 150_000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION_I128).into(), curve_update_intensity: 100, - base_asset_amount_with_amm: AMM_RESERVE_PRECISION as i128, - quote_asset_amount: -99 * QUOTE_PRECISION_I128, + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128).into(), + quote_asset_amount: (-99 * QUOTE_PRECISION_I128).into(), ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (60 * SPOT_BALANCE_PRECISION), + scaled_balance: (60 * SPOT_BALANCE_PRECISION).into(), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -386,7 +386,7 @@ mod get_claimable_pnl { let oracle_price = 150 * PRICE_PRECISION_I64; let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), &usdc_market, perp_market.pnl_pool.balance_type(), ) @@ -440,7 +440,9 @@ mod get_claimable_pnl { ); assert_eq!(unsettled_pnl3, 9_000_000); - perp_market.amm.quote_asset_amount = -100 * QUOTE_PRECISION_I128; + perp_market + .amm + .set_quote_asset_amount(-100 * QUOTE_PRECISION_I128); let net_user_pnl = calculate_net_user_pnl(&perp_market.amm, oracle_price).unwrap(); assert_eq!(net_user_pnl, 50000000); let max_pnl_pool_excess = if net_user_pnl < pnl_pool_token_amount { @@ -471,30 +473,30 @@ mod get_claimable_pnl { let usdc_market = SpotMarket { market_index: 0, oracle_source: OracleSource::QuoteAsset, - cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION, + cumulative_deposit_interest: SPOT_CUMULATIVE_INTEREST_PRECISION.into(), decimals: 6, initial_asset_weight: SPOT_WEIGHT_PRECISION, maintenance_asset_weight: SPOT_WEIGHT_PRECISION, - deposit_balance: 1000 * SPOT_BALANCE_PRECISION, + deposit_balance: (1000 * SPOT_BALANCE_PRECISION).into(), liquidator_fee: 0, ..SpotMarket::default() }; let perp_market = PerpMarket { amm: AMM { - base_asset_reserve: 99 * AMM_RESERVE_PRECISION, - quote_asset_reserve: 101 * AMM_RESERVE_PRECISION, - sqrt_k: 100 * AMM_RESERVE_PRECISION, - peg_multiplier: 150_000, - concentration_coef: MAX_CONCENTRATION_COEFFICIENT, - total_fee_minus_distributions: 1000 * QUOTE_PRECISION_I128, + base_asset_reserve: (99 * AMM_RESERVE_PRECISION).into(), + quote_asset_reserve: (101 * AMM_RESERVE_PRECISION).into(), + sqrt_k: (100 * AMM_RESERVE_PRECISION).into(), + peg_multiplier: 150_000.into(), + concentration_coef: MAX_CONCENTRATION_COEFFICIENT.into(), + total_fee_minus_distributions: (1000 * QUOTE_PRECISION_I128).into(), curve_update_intensity: 100, - base_asset_amount_with_amm: AMM_RESERVE_PRECISION as i128, - quote_asset_amount: -100 * QUOTE_PRECISION_I128, + base_asset_amount_with_amm: (AMM_RESERVE_PRECISION as i128).into(), + quote_asset_amount: (-100 * QUOTE_PRECISION_I128).into(), ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION), + scaled_balance: (1000 * SPOT_BALANCE_PRECISION).into(), market_index: 0, ..PoolBalance::default() }, @@ -537,7 +539,7 @@ mod get_claimable_pnl { let oracle_price = 160 * PRICE_PRECISION_I64; let pnl_pool_token_amount = get_token_amount( - perp_market.pnl_pool.scaled_balance, + perp_market.pnl_pool.scaled_balance(), &usdc_market, perp_market.pnl_pool.balance_type(), ) diff --git a/programs/drift/src/state/user_map.rs b/programs/drift/src/state/user_map.rs index 4da2a79b69..b5a850955e 100644 --- a/programs/drift/src/state/user_map.rs +++ b/programs/drift/src/state/user_map.rs @@ -21,7 +21,7 @@ pub struct UserMap<'a>(pub BTreeMap>); impl<'a> UserMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref(&self, user: &Pubkey) -> DriftResult> { + pub fn get_ref(&self, user: &Pubkey) -> DriftResult> { let loader = match self.0.get(user) { Some(loader) => loader, None => { @@ -54,7 +54,7 @@ impl<'a> UserMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref_mut(&self, user: &Pubkey) -> DriftResult> { + pub fn get_ref_mut(&self, user: &Pubkey) -> DriftResult> { let loader = match self.0.get(user) { Some(loader) => loader, None => { @@ -108,8 +108,6 @@ impl<'a> UserMap<'a> { pub fn load_one<'b: 'a>(account_info: &'b AccountInfo<'a>) -> DriftResult> { let mut user_map = UserMap(BTreeMap::new()); - let user_discriminator: [u8; 8] = User::discriminator(); - let user_key = account_info.key; let data = account_info @@ -121,8 +119,8 @@ impl<'a> UserMap<'a> { return Err(ErrorCode::CouldNotLoadUserData); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != User::DISCRIMINATOR { return Err(ErrorCode::CouldNotLoadUserData); } @@ -145,7 +143,7 @@ pub struct UserStatsMap<'a>(pub BTreeMap>); impl<'a> UserStatsMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref(&self, authority: &Pubkey) -> DriftResult> { + pub fn get_ref(&self, authority: &Pubkey) -> DriftResult> { let loader = match self.0.get(authority) { Some(loader) => loader, None => { @@ -178,7 +176,7 @@ impl<'a> UserStatsMap<'a> { #[track_caller] #[inline(always)] - pub fn get_ref_mut(&self, authority: &Pubkey) -> DriftResult> { + pub fn get_ref_mut(&self, authority: &Pubkey) -> DriftResult> { let loader = match self.0.get(authority) { Some(loader) => loader, None => { @@ -236,8 +234,6 @@ impl<'a> UserStatsMap<'a> { pub fn load_one<'b: 'a>(account_info: &'b AccountInfo<'a>) -> DriftResult> { let mut user_stats_map = UserStatsMap(BTreeMap::new()); - let user_stats_discriminator: [u8; 8] = UserStats::discriminator(); - let _user_stats_key = account_info.key; let data = account_info @@ -249,8 +245,8 @@ impl<'a> UserStatsMap<'a> { return Err(ErrorCode::DefaultError); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_stats_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != UserStats::DISCRIMINATOR { return Err(ErrorCode::DefaultError); } @@ -280,8 +276,6 @@ pub fn load_user_maps<'a: 'b, 'b>( let mut user_map = UserMap::empty(); let mut user_stats_map = UserStatsMap::empty(); - let user_discriminator: [u8; 8] = User::discriminator(); - let user_stats_discriminator: [u8; 8] = UserStats::discriminator(); while let Some(user_account_info) = account_info_iter.peek() { let user_key = user_account_info.key; @@ -294,8 +288,8 @@ pub fn load_user_maps<'a: 'b, 'b>( break; } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != User::DISCRIMINATOR { break; } @@ -327,8 +321,8 @@ pub fn load_user_maps<'a: 'b, 'b>( return Err(ErrorCode::InvalidUserStatsAccount); } - let account_discriminator = array_ref![data, 0, 8]; - if account_discriminator != &user_stats_discriminator { + let account_discriminator = &data[..8]; + if account_discriminator != UserStats::DISCRIMINATOR { return Err(ErrorCode::InvalidUserStatsAccount); } @@ -362,8 +356,6 @@ pub fn load_user_map<'a: 'b, 'b>( ) -> DriftResult> { let mut user_map = UserMap::empty(); - let user_discriminator: [u8; 8] = User::discriminator(); - let user_stats_discriminator: [u8; 8] = UserStats::discriminator(); while let Some(user_account_info) = account_info_iter.peek() { let user_key = user_account_info.key; @@ -377,15 +369,15 @@ pub fn load_user_map<'a: 'b, 'b>( break; } - let account_discriminator = array_ref![data, 0, 8]; + let account_discriminator = &data[..8]; - // if it is user stats, for backwards compatability, just move iter forward - if account_discriminator == &user_stats_discriminator { + // if it is user stats, for backwards compatibility, just move iter forward + if account_discriminator == UserStats::DISCRIMINATOR { account_info_iter.next().safe_unwrap()?; continue; } - if account_discriminator != &user_discriminator { + if account_discriminator != User::DISCRIMINATOR { break; } diff --git a/programs/drift/src/state/zero_copy.rs b/programs/drift/src/state/zero_copy.rs index b6a11a383f..d20e1af04e 100644 --- a/programs/drift/src/state/zero_copy.rs +++ b/programs/drift/src/state/zero_copy.rs @@ -79,7 +79,7 @@ pub trait ZeroCopyLoader<'a, T, F> { pub fn load_generic<'a, 'info, F, T>( acct: &'a AccountInfo<'info>, - expected_disc: [u8; 8], + expected_disc: &[u8], program_id: Pubkey, ) -> DriftResult> where @@ -98,7 +98,7 @@ where let (disc, rest) = Ref::map_split(data, |d| d.split_at(8)); validate!( - *disc == expected_disc, + disc.as_ref() == expected_disc, ErrorCode::DefaultError, "invalid discriminator", )?; @@ -115,7 +115,7 @@ where pub fn load_generic_mut<'a, 'info, F, T>( acct: &'a AccountInfo<'info>, - expected_disc: [u8; 8], + expected_disc: &[u8], program_id: Pubkey, ) -> DriftResult> where @@ -132,7 +132,7 @@ where let (disc, rest) = RefMut::map_split(data, |d| d.split_at_mut(8)); validate!( - *disc == expected_disc, + disc.as_ref() == expected_disc, ErrorCode::DefaultError, "invalid discriminator", )?; @@ -160,7 +160,7 @@ macro_rules! impl_zero_copy_loader { > { crate::state::zero_copy::load_generic::<$Fixed, $Elem>( self, - <$Acc as anchor_lang::Discriminator>::discriminator(), + <$Acc as anchor_lang::Discriminator>::DISCRIMINATOR, $ID(), ) } @@ -172,7 +172,7 @@ macro_rules! impl_zero_copy_loader { > { crate::state::zero_copy::load_generic_mut::<$Fixed, $Elem>( self, - <$Acc as anchor_lang::Discriminator>::discriminator(), + <$Acc as anchor_lang::Discriminator>::DISCRIMINATOR, $ID(), ) } diff --git a/programs/drift/src/test_utils.rs b/programs/drift/src/test_utils.rs index f031f6af9d..516d62dbf7 100644 --- a/programs/drift/src/test_utils.rs +++ b/programs/drift/src/test_utils.rs @@ -52,7 +52,7 @@ pub fn get_account_bytes(account: &mut T) -> BytesMut { pub fn get_anchor_account_bytes(account: &mut T) -> BytesMut { let mut bytes = BytesMut::new(); - bytes.extend_from_slice(&T::discriminator()); + bytes.extend_from_slice(&T::DISCRIMINATOR); let data = bytemuck::bytes_of_mut(account); bytes.extend_from_slice(data); bytes diff --git a/programs/drift/src/validation/perp_market.rs b/programs/drift/src/validation/perp_market.rs index 30bce4dedd..7945136ce4 100644 --- a/programs/drift/src/validation/perp_market.rs +++ b/programs/drift/src/validation/perp_market.rs @@ -12,13 +12,13 @@ use crate::validate; pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { let (_, remainder_base_asset_amount_long) = crate::math::orders::standardize_base_asset_amount_with_remainder_i128( - market.amm.base_asset_amount_long, + market.amm.base_asset_amount_long(), market.amm.order_step_size.cast()?, )?; let (_, remainder_base_asset_amount_short) = crate::math::orders::standardize_base_asset_amount_with_remainder_i128( - market.amm.base_asset_amount_short, + market.amm.base_asset_amount_short(), market.amm.order_step_size.cast()?, )?; @@ -31,29 +31,29 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { market.amm.order_step_size )?; validate!( - (market.amm.base_asset_amount_long + market.amm.base_asset_amount_short) - == market.amm.base_asset_amount_with_amm, + (market.amm.base_asset_amount_long() + market.amm.base_asset_amount_short()) + == market.amm.base_asset_amount_with_amm(), ErrorCode::InvalidAmmDetected, "Market NET_BAA Error: market.amm.base_asset_amount_long={}, + market.amm.base_asset_amount_short={} != market.amm.base_asset_amount_with_amm={}", - market.amm.base_asset_amount_long, - market.amm.base_asset_amount_short, - market.amm.base_asset_amount_with_amm, + market.amm.base_asset_amount_long(), + market.amm.base_asset_amount_short(), + market.amm.base_asset_amount_with_amm(), )?; validate!( - market.amm.base_asset_amount_with_amm <= (MAX_BASE_ASSET_AMOUNT_WITH_AMM as i128), + market.amm.base_asset_amount_with_amm() <= (MAX_BASE_ASSET_AMOUNT_WITH_AMM as i128), ErrorCode::InvalidAmmDetected, "market {} market.amm.base_asset_amount_with_amm={} is too large", market.market_index, - market.amm.base_asset_amount_with_amm + market.amm.base_asset_amount_with_amm() )?; validate!( - market.amm.peg_multiplier > 0, + market.amm.peg_multiplier() > 0, ErrorCode::InvalidAmmDetected, "market {} peg_multiplier out of wack", market.market_index, @@ -61,35 +61,35 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { if market.status != MarketStatus::ReduceOnly { validate!( - market.amm.sqrt_k > market.amm.base_asset_amount_with_amm.unsigned_abs(), + market.amm.sqrt_k() > market.amm.base_asset_amount_with_amm().unsigned_abs(), ErrorCode::InvalidAmmDetected, "market {} k out of wack: k={}, net_baa={}", market.market_index, - market.amm.sqrt_k, - market.amm.base_asset_amount_with_amm + market.amm.sqrt_k(), + market.amm.base_asset_amount_with_amm() )?; } validate!( - market.amm.sqrt_k >= market.amm.base_asset_reserve - || market.amm.sqrt_k >= market.amm.quote_asset_reserve, + market.amm.sqrt_k() >= market.amm.base_asset_reserve() + || market.amm.sqrt_k() >= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} k out of wack: k={}, bar={}, qar={}", market.market_index, - market.amm.sqrt_k, - market.amm.base_asset_reserve, - market.amm.quote_asset_reserve + market.amm.sqrt_k(), + market.amm.base_asset_reserve(), + market.amm.quote_asset_reserve() )?; - let invariant_sqrt_u192 = crate::math::bn::U192::from(market.amm.sqrt_k); + let invariant_sqrt_u192 = crate::math::bn::U192::from(market.amm.sqrt_k()); let invariant = invariant_sqrt_u192.safe_mul(invariant_sqrt_u192)?; let quote_asset_reserve = invariant - .safe_div(crate::math::bn::U192::from(market.amm.base_asset_reserve))? + .safe_div(crate::math::bn::U192::from(market.amm.base_asset_reserve()))? .try_to_u128()?; let rounding_diff = quote_asset_reserve .cast::()? - .safe_sub(market.amm.quote_asset_reserve.cast()?)? + .safe_sub(market.amm.quote_asset_reserve().cast()?)? .abs(); validate!( @@ -98,8 +98,8 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { "market {} amm qar/bar/k invalid: k={}, bar={}, qar={}, qar'={} (rounding: {})", market.market_index, invariant, - market.amm.base_asset_reserve, - market.amm.quote_asset_reserve, + market.amm.base_asset_reserve(), + market.amm.quote_asset_reserve(), quote_asset_reserve, rounding_diff )?; @@ -109,30 +109,30 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { // bid quote/base < reserve q/b if market.amm.reference_price_offset <= 0 { validate!( - market.amm.bid_base_asset_reserve >= market.amm.base_asset_reserve - && market.amm.bid_quote_asset_reserve <= market.amm.quote_asset_reserve, + market.amm.bid_base_asset_reserve() >= market.amm.base_asset_reserve() + && market.amm.bid_quote_asset_reserve() <= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} amm bid reserves invalid: {} -> {}, quote: {} -> {}", market.market_index, - market.amm.bid_base_asset_reserve, - market.amm.base_asset_reserve, - market.amm.bid_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.bid_base_asset_reserve(), + market.amm.base_asset_reserve(), + market.amm.bid_quote_asset_reserve(), + market.amm.quote_asset_reserve() )?; } if market.amm.reference_price_offset >= 0 { // ask quote/base > reserve q/b validate!( - market.amm.ask_base_asset_reserve <= market.amm.base_asset_reserve - && market.amm.ask_quote_asset_reserve >= market.amm.quote_asset_reserve, + market.amm.ask_base_asset_reserve() <= market.amm.base_asset_reserve() + && market.amm.ask_quote_asset_reserve() >= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} amm ask reserves invalid: {} -> {}, quote: {} -> {}", market.market_index, - market.amm.ask_base_asset_reserve, - market.amm.base_asset_reserve, - market.amm.ask_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.ask_base_asset_reserve(), + market.amm.base_asset_reserve(), + market.amm.ask_quote_asset_reserve(), + market.amm.quote_asset_reserve() )?; } } @@ -164,32 +164,32 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { market.amm.max_spread, )?; - if market.amm.base_asset_amount_with_amm > 0 { + if market.amm.base_asset_amount_with_amm() > 0 { // users are long = removed base and added quote = qar increased // bid quote/base < reserve q/b validate!( - market.amm.terminal_quote_asset_reserve <= market.amm.quote_asset_reserve, + market.amm.terminal_quote_asset_reserve() <= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} terminal_quote_asset_reserve out of wack", market.market_index, )?; - } else if market.amm.base_asset_amount_with_amm < 0 { + } else if market.amm.base_asset_amount_with_amm() < 0 { validate!( - market.amm.terminal_quote_asset_reserve >= market.amm.quote_asset_reserve, + market.amm.terminal_quote_asset_reserve() >= market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} terminal_quote_asset_reserve out of wack (terminal <) {} > {}", market.market_index, - market.amm.terminal_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.terminal_quote_asset_reserve(), + market.amm.quote_asset_reserve() )?; } else { validate!( - market.amm.terminal_quote_asset_reserve == market.amm.quote_asset_reserve, + market.amm.terminal_quote_asset_reserve() == market.amm.quote_asset_reserve(), ErrorCode::InvalidAmmDetected, "market {} terminal_quote_asset_reserve out of wack {}!={}", market.market_index, - market.amm.terminal_quote_asset_reserve, - market.amm.quote_asset_reserve + market.amm.terminal_quote_asset_reserve(), + market.amm.quote_asset_reserve() )?; } @@ -224,17 +224,17 @@ pub fn validate_perp_market(market: &PerpMarket) -> DriftResult { pub fn validate_amm_account_for_fill(amm: &AMM, direction: PositionDirection) -> DriftResult { if direction == PositionDirection::Long { validate!( - amm.base_asset_reserve >= amm.min_base_asset_reserve, + amm.base_asset_reserve() >= amm.min_base_asset_reserve(), ErrorCode::InvalidAmmForFillDetected, "Market baa below min_base_asset_reserve: {} < {}", - amm.base_asset_reserve, - amm.min_base_asset_reserve, + amm.base_asset_reserve(), + amm.min_base_asset_reserve(), )?; } if direction == PositionDirection::Short { validate!( - amm.base_asset_reserve <= amm.max_base_asset_reserve, + amm.base_asset_reserve() <= amm.max_base_asset_reserve(), ErrorCode::InvalidAmmForFillDetected, "Market baa above max_base_asset_reserve" )?; diff --git a/programs/openbook_v2/Cargo.toml b/programs/openbook_v2/Cargo.toml index 7a7360a4f3..549662e2e2 100644 --- a/programs/openbook_v2/Cargo.toml +++ b/programs/openbook_v2/Cargo.toml @@ -15,9 +15,11 @@ no-entrypoint = [] no-idl = [] no-log-ix-name = [] cpi = ["no-entrypoint"] - +idl-build = [ + "anchor-lang/idl-build" +] [dependencies] -anchor-lang = { version = "0.29.0", features = ["derive"] } +anchor-lang = "0.32.1" borsh = {version = "0.10.3", features = ["const-generics", "default"]} -bytemuck = { version = "1.4.0" , features = ["derive", "min_const_generics"]} \ No newline at end of file +bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"]} \ No newline at end of file diff --git a/programs/openbook_v2/src/account.rs b/programs/openbook_v2/src/account.rs index edf6550f9b..01edb0e543 100644 --- a/programs/openbook_v2/src/account.rs +++ b/programs/openbook_v2/src/account.rs @@ -4,7 +4,7 @@ use crate::*; use bytemuck::Zeroable; #[zero_copy] -#[derive(AnchorDeserialize, AnchorSerialize, Debug)] +#[derive(AnchorDeserialize, Debug)] pub struct OracleConfig { pub conf_filter: f64, pub max_staleness_slots: i64, @@ -207,7 +207,6 @@ impl BookSide { } #[zero_copy] -#[derive(AnchorSerialize)] pub struct AnyNode { pub tag: u8, pub data: [u8; 79], @@ -221,7 +220,7 @@ pub struct OrderTreeNodes { pub padding: [u8; 3], pub bump_index: u32, pub free_list_len: u32, - pub free_list_head: NodeHandle, + pub free_list_head: u32, pub reserved: [u8; 512], pub nodes: [AnyNode; MAX_ORDERTREE_NODES], } @@ -231,7 +230,7 @@ pub type NodeHandle = u32; #[zero_copy] #[derive(Debug)] pub struct OrderTreeRoot { - pub maybe_node: NodeHandle, + pub maybe_node: u32, pub leaf_count: u32, } @@ -335,7 +334,7 @@ impl LeafNode { } #[zero_copy] -#[derive(AnchorSerialize, AnchorDeserialize, Debug, Default, PartialEq)] +#[derive(AnchorDeserialize, Debug, Default, PartialEq)] pub struct NonZeroPubkeyOption { key: Pubkey, } @@ -394,20 +393,20 @@ impl NonZeroPubkeyOption { } } -#[derive(BorshSerialize, BorshDeserialize, Debug)] +#[derive(AnchorDeserialize, Debug, AnchorSerialize)] pub enum Side { Bid, Ask, } -#[derive(BorshSerialize, BorshDeserialize, Debug)] +#[derive(AnchorDeserialize, Debug, AnchorSerialize)] pub enum SelfTradeBehavior { DecrementTake, CancelProvide, AbortTransaction, } -#[derive(BorshSerialize, BorshDeserialize, Debug)] +#[derive(AnchorDeserialize, Debug, AnchorSerialize)] pub enum PlaceOrderType { Limit, ImmediateOrCancel, diff --git a/programs/openbook_v2/src/lib.rs b/programs/openbook_v2/src/lib.rs index d6ea487c61..6d07ceb68b 100644 --- a/programs/openbook_v2/src/lib.rs +++ b/programs/openbook_v2/src/lib.rs @@ -1,9 +1,7 @@ #![allow(clippy::too_many_arguments)] +#![allow(unexpected_cfgs)] -use anchor_lang::prelude::{ - borsh::{BorshDeserialize, BorshSerialize}, - *, -}; +use anchor_lang::prelude::*; declare_id!("opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb"); diff --git a/programs/pyth/Cargo.toml b/programs/pyth/Cargo.toml index ed1b1b8e28..4e0c0ab36c 100644 --- a/programs/pyth/Cargo.toml +++ b/programs/pyth/Cargo.toml @@ -15,7 +15,10 @@ cpi = ["no-entrypoint"] default = ["mainnet-beta"] mainnet-beta=[] anchor-test= [] +idl-build = [ + "anchor-lang/idl-build" +] [dependencies] -anchor-lang = "0.29.0" -bytemuck = { version = "1.4.0" } +anchor-lang = "0.32.1" +bytemuck = "1.4.0" diff --git a/programs/pyth/src/lib.rs b/programs/pyth/src/lib.rs index 199249ce04..bf76a45ae4 100644 --- a/programs/pyth/src/lib.rs +++ b/programs/pyth/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(unexpected_cfgs)] use anchor_lang::prelude::*; pub mod pc; use pc::Price; diff --git a/programs/switchboard-on-demand/Cargo.toml b/programs/switchboard-on-demand/Cargo.toml index 0709be9058..4e36cd251e 100644 --- a/programs/switchboard-on-demand/Cargo.toml +++ b/programs/switchboard-on-demand/Cargo.toml @@ -14,11 +14,14 @@ cpi = ["no-entrypoint"] default = ["mainnet-beta"] mainnet-beta=[] anchor-test= [] +idl-build = [ + "anchor-lang/idl-build" +] [dependencies] -anchor-lang = "0.29.0" +anchor-lang = "0.32.1" bytemuck = { version = "1.4.0" } -solana-program = "1.16" +solana-program = "=2.2.1" [dev-dependencies] base64 = "0.13.0" diff --git a/programs/switchboard-on-demand/src/lib.rs b/programs/switchboard-on-demand/src/lib.rs index 80779e43a5..93d4712b3d 100644 --- a/programs/switchboard-on-demand/src/lib.rs +++ b/programs/switchboard-on-demand/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unexpected_cfgs)] + use anchor_lang::declare_id; use anchor_lang::prelude::*; use anchor_lang::program; @@ -14,7 +16,7 @@ pub mod switchboard_on_demand {} pub const SB_ON_DEMAND_PRECISION: u32 = 18; #[repr(C)] -#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize)] pub struct CompactResult { pub std_dev: f32, pub mean: f32, @@ -22,79 +24,79 @@ pub struct CompactResult { } #[repr(C)] -#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize)] pub struct CurrentResult { - /// The median value of the submissions needed for quorom size - pub value: i128, - /// The standard deviation of the submissions needed for quorom size - pub std_dev: i128, - /// The mean of the submissions needed for quorom size - pub mean: i128, - /// The range of the submissions needed for quorom size - pub range: i128, - /// The minimum value of the submissions needed for quorom size - pub min_value: i128, - /// The maximum value of the submissions needed for quorom size - pub max_value: i128, + /// The median value of the submissions needed for quorum size + value: [u8; 16], + /// The standard deviation of the submissions needed for quorum size + std_dev: [u8; 16], + /// The mean of the submissions needed for quorum size + mean: [u8; 16], + /// The range of the submissions needed for quorum size + range: [u8; 16], + /// The minimum value of the submissions needed for quorum size + min_value: [u8; 16], + /// The maximum value of the submissions needed for quorum size + max_value: [u8; 16], /// The number of samples used to calculate this result - pub num_samples: u8, + num_samples: u8, /// The index of the submission that was used to calculate this result - pub submission_idx: u8, - pub padding1: [u8; 6], + submission_idx: u8, + padding1: [u8; 6], /// The slot at which this value was signed. - pub slot: u64, + slot: u64, /// The slot at which the first considered submission was made - pub min_slot: u64, + min_slot: u64, /// The slot at which the last considered submission was made - pub max_slot: u64, + max_slot: u64, } impl CurrentResult { - /// The median value of the submissions needed for quorom size + /// The median value of the submissions needed for quorum size pub fn value(&self) -> Option { if self.slot == 0 { return None; } - Some(self.value) + Some(i128::from_le_bytes(self.value)) } - /// The standard deviation of the submissions needed for quorom size + /// The standard deviation of the submissions needed for quorum size pub fn std_dev(&self) -> Option { if self.slot == 0 { return None; } - Some(self.std_dev) + Some(i128::from_le_bytes(self.std_dev)) } - /// The mean of the submissions needed for quorom size + /// The mean of the submissions needed for quorum size pub fn mean(&self) -> Option { if self.slot == 0 { return None; } - Some(self.mean) + Some(i128::from_le_bytes(self.mean)) } - /// The range of the submissions needed for quorom size + /// The range of the submissions needed for quorum size pub fn range(&self) -> Option { if self.slot == 0 { return None; } - Some(self.range) + Some(i128::from_le_bytes(self.range)) } - /// The minimum value of the submissions needed for quorom size + /// The minimum value of the submissions needed for quorum size pub fn min_value(&self) -> Option { if self.slot == 0 { return None; } - Some(self.min_value) + Some(i128::from_le_bytes(self.min_value)) } - /// The maximum value of the submissions needed for quorom size + /// The maximum value of the submissions needed for quorum size pub fn max_value(&self) -> Option { if self.slot == 0 { return None; } - Some(self.max_value) + Some(i128::from_le_bytes(self.max_value)) } pub fn result_slot(&self) -> Option { @@ -120,7 +122,7 @@ impl CurrentResult { } #[repr(C)] -#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)] +#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable, AnchorSerialize)] pub struct OracleSubmission { /// The public key of the oracle that submitted this value. pub oracle: Pubkey, @@ -129,7 +131,7 @@ pub struct OracleSubmission { /// The slot at which this value was landed on chain. pub landed_at: u64, /// The value that was submitted. - pub value: i128, + value: [u8; 16], } impl OracleSubmission { @@ -138,7 +140,7 @@ impl OracleSubmission { } pub fn value(&self) -> i128 { - self.value + i128::from_le_bytes(self.value) } } @@ -179,36 +181,34 @@ pub struct PullFeedAccountData { } impl PullFeedAccountData { - pub fn discriminator() -> [u8; 8] { - [196, 27, 108, 196, 10, 215, 219, 40] - } + pub const DISCRIMINATOR: &[u8] = &[196, 27, 108, 196, 10, 215, 219, 40]; - /// The median value of the submissions needed for quorom size + /// The median value of the submissions needed for quorum size pub fn median_value(&self) -> Option { self.result.value() } - /// The standard deviation of the submissions needed for quorom size + /// The standard deviation of the submissions needed for quorum size pub fn std_dev(&self) -> Option { self.result.std_dev() } - /// The mean of the submissions needed for quorom size + /// The mean of the submissions needed for quorum size pub fn mean(&self) -> Option { self.result.mean() } - /// The range of the submissions needed for quorom size + /// The range of the submissions needed for quorum size pub fn range(&self) -> Option { self.result.range() } - /// The minimum value of the submissions needed for quorom size + /// The minimum value of the submissions needed for quorum size pub fn min_value(&self) -> Option { self.result.min_value() } - /// The maximum value of the submissions needed for quorom size + /// The maximum value of the submissions needed for quorum size pub fn max_value(&self) -> Option { self.result.max_value() } diff --git a/programs/switchboard/Cargo.toml b/programs/switchboard/Cargo.toml index 6c6cafb802..f49600dc00 100644 --- a/programs/switchboard/Cargo.toml +++ b/programs/switchboard/Cargo.toml @@ -14,9 +14,10 @@ cpi = ["no-entrypoint"] default = ["mainnet-beta"] mainnet-beta=[] anchor-test= [] +idl-build = ["anchor-lang/idl-build"] [dependencies] -anchor-lang = "0.29.0" +anchor-lang = "0.32.1" [dev-dependencies] base64 = "0.13.0" diff --git a/programs/switchboard/src/lib.rs b/programs/switchboard/src/lib.rs index f95c5969fe..7fc8682659 100644 --- a/programs/switchboard/src/lib.rs +++ b/programs/switchboard/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unexpected_cfgs)] + use anchor_lang::prelude::*; declare_id!("SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"); diff --git a/programs/token_faucet/Cargo.toml b/programs/token_faucet/Cargo.toml index d553fdc158..bf49663d0d 100644 --- a/programs/token_faucet/Cargo.toml +++ b/programs/token_faucet/Cargo.toml @@ -2,7 +2,7 @@ name = "token-faucet" version = "0.1.0" description = "Created with Anchor" -edition = "2018" +edition = "2021" [lib] crate-type = ["cdylib", "lib"] @@ -11,10 +11,14 @@ name = "token_faucet" [features] no-entrypoint = [] cpi = ["no-entrypoint"] -mainnet-beta=[] -anchor-test= [] +mainnet-beta = [] +anchor-test = [] +idl-build = [ + "anchor-lang/idl-build", + "anchor-spl/idl-build", +] [dependencies] -anchor-lang = "0.29.0" -anchor-spl = "0.29.0" -bytemuck = { version = "1.4.0" } \ No newline at end of file +anchor-lang = "0.32.1" +anchor-spl = "0.32.1" +bytemuck = "1.4.0" \ No newline at end of file diff --git a/programs/token_faucet/src/lib.rs b/programs/token_faucet/src/lib.rs index bd873ae03a..e3ade3135f 100644 --- a/programs/token_faucet/src/lib.rs +++ b/programs/token_faucet/src/lib.rs @@ -1,3 +1,5 @@ +#![allow(unexpected_cfgs)] + use anchor_lang::prelude::*; use anchor_spl::token::{self, Mint, Token, TokenAccount}; diff --git a/sdk/bun.lock b/sdk/bun.lock index d3d328c729..1c160496ec 100644 --- a/sdk/bun.lock +++ b/sdk/bun.lock @@ -4,8 +4,8 @@ "": { "name": "@drift-labs/sdk", "dependencies": { - "@coral-xyz/anchor": "0.29.0", - "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", + "@coral-xyz/anchor": "npm:@coral-xyz/anchor@0.31.1", + "@coral-xyz/anchor-29": "npm:@coral-xyz/anchor@0.29.0", "@ellipsis-labs/phoenix-sdk": "1.4.5", "@grpc/grpc-js": "1.14.0", "@msgpack/msgpack": "^3.1.2", @@ -16,11 +16,11 @@ "@pythnetwork/pyth-solana-receiver": "0.7.0", "@solana/spl-token": "0.4.13", "@solana/web3.js": "1.98.0", - "@switchboard-xyz/common": "3.0.14", - "@switchboard-xyz/on-demand": "2.4.1", + "@switchboard-xyz/common": "5.5.0", + "@switchboard-xyz/on-demand": "3.7.3", "@triton-one/yellowstone-grpc": "1.4.1", "anchor-bankrun": "0.3.0", - "gill": "^0.10.2", + "gill": "^0.10.3", "helius-laserstream": "0.1.8", "nanoid": "3.3.4", "node-cache": "5.1.2", @@ -60,24 +60,15 @@ }, }, "overrides": { + "debug": "<4.4.2", + "supports-color": "7.2.0", "ansi-regex": "5.0.1", + "color-convert": "<3.1.1", "ansi-styles": "4.3.0", - "backslash": "<0.2.1", + "wrap-ansi": "7.0.0", "chalk": "4.1.2", - "chalk-template": "<1.1.1", - "color-convert": "<3.1.1", - "color-name": "<2.0.1", - "color-string": "<2.1.1", - "debug": "<4.4.2", - "error-ex": "<1.3.3", - "has-ansi": "<6.0.1", - "is-arrayish": "<0.3.3", - "simple-swizzle": "<0.2.3", - "slice-ansi": "3.0.0", "strip-ansi": "6.0.1", - "supports-color": "7.2.0", - "supports-hyperlinks": "<4.1.1", - "wrap-ansi": "7.0.0", + "color-name": "<2.0.1", }, "packages": { "@babel/code-frame": ["@babel/code-frame@7.26.2", "", { "dependencies": { "@babel/helper-validator-identifier": "^7.25.9", "js-tokens": "^4.0.0", "picocolors": "^1.0.0" } }, "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ=="], @@ -92,13 +83,15 @@ "@babel/types": ["@babel/types@7.28.2", "", { "dependencies": { "@babel/helper-string-parser": "^7.27.1", "@babel/helper-validator-identifier": "^7.27.1" } }, "sha512-ruv7Ae4J5dUYULmeXw1gmb7rYRz57OWCPM57pHojnLq/3Z1CK2lNSLTCVjxVk1F/TZHwOZZrOWi0ur95BbLxNQ=="], - "@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@coral-xyz/anchor": ["@coral-xyz/anchor@0.31.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.31.1", "@coral-xyz/borsh": "^0.31.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.69.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA=="], - "@coral-xyz/anchor-30": ["@coral-xyz/anchor@0.30.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.30.1", "@coral-xyz/borsh": "^0.30.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ=="], + "@coral-xyz/anchor-29": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], - "@coral-xyz/anchor-errors": ["@coral-xyz/anchor-errors@0.30.1", "", {}, "sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ=="], + "@coral-xyz/anchor-31": ["@coral-xyz/anchor@0.31.1", "", { "dependencies": { "@coral-xyz/anchor-errors": "^0.31.1", "@coral-xyz/borsh": "^0.31.1", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.69.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA=="], - "@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + "@coral-xyz/anchor-errors": ["@coral-xyz/anchor-errors@0.31.1", "", {}, "sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ=="], + + "@coral-xyz/borsh": ["@coral-xyz/borsh@0.31.1", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.69.0" } }, "sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw=="], "@cspotcode/source-map-support": ["@cspotcode/source-map-support@0.8.1", "", { "dependencies": { "@jridgewell/trace-mapping": "0.3.9" } }, "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw=="], @@ -302,9 +295,9 @@ "@swc/helpers": ["@swc/helpers@0.5.15", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g=="], - "@switchboard-xyz/common": ["@switchboard-xyz/common@3.0.14", "", { "dependencies": { "@solana/web3.js": "^1.98.0", "axios": "^1.8.3", "big.js": "^6.2.2", "bn.js": "^5.2.1", "bs58": "^6.0.0", "buffer": "^6.0.3", "decimal.js": "^10.4.3", "js-sha256": "^0.11.0", "protobufjs": "^7.4.0", "yaml": "^2.6.1" } }, "sha512-LpxzEywO0DjPYIgPzQYkf32C7agwW4YRsPN6BcIvYrw0iJdDMtPZ3SQfIGHLSlD1fwvn2KLUYuGaKegeq4aBTw=="], + "@switchboard-xyz/common": ["@switchboard-xyz/common@5.5.0", "", { "dependencies": { "@solana/web3.js": "^1.98.2", "axios": "^1.9.0", "big.js": "^6.2.2", "bn.js": "^5.2.1", "bs58": "^6.0.0", "buffer": "^6.0.3", "decimal.js": "^10.4.3", "js-sha256": "^0.11.0", "protobufjs": "^7.4.0" } }, "sha512-Wvs9KJw+YSe8O2IOsMUvPE8aQHb0t2vi/9hEQC7Pc6279s7tTTI8eVgT/0Jb2z897OHgIZTD3oGQ8IEBqIgV0w=="], - "@switchboard-xyz/on-demand": ["@switchboard-xyz/on-demand@2.4.1", "", { "dependencies": { "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", "@isaacs/ttlcache": "^1.4.1", "@switchboard-xyz/common": ">=3.0.0", "axios": "^1.8.3", "bs58": "^6.0.0", "buffer": "^6.0.3", "js-yaml": "^4.1.0" } }, "sha512-eSlBp+c8lxpcSgh0/2xK8OaLHPziTSZlcs8V96gZGdiCJz1KgWJRNE1qnIJDOwaGdFecZdwcmajfQRtLRLED3w=="], + "@switchboard-xyz/on-demand": ["@switchboard-xyz/on-demand@3.7.3", "", { "dependencies": { "@coral-xyz/anchor-31": "npm:@coral-xyz/anchor@0.31.1", "@isaacs/ttlcache": "^1.4.1", "@solana/spl-token": "^0.4.14", "@solana/web3.js": "^1.98.4", "@switchboard-xyz/common": "^5.2.9", "axios": "^1.9", "bs58": "^6.0.0", "buffer": "^6.0.3", "events": "^3.3.0", "isomorphic-ws": "^5.0.0", "js-yaml": "^4.1.0", "tweetnacl": "^1.0.3", "ws": "^8.18.1" } }, "sha512-sG9errSwjYlQbIlQl0iptUQcbKrPe7QVxX20+qXuucG3qIWlA/w6sXGnITeYbt+BERyBYdfue0viBjmjOsCZrg=="], "@triton-one/yellowstone-grpc": ["@triton-one/yellowstone-grpc@1.4.1", "", { "dependencies": { "@grpc/grpc-js": "^1.8.0" } }, "sha512-ZN49vooxFbOqWttll8u7AOsIVnX+srqX9ddhZ9ttE+OcehUo8c2p2suK8Gr2puab49cgsV0VGjiTn9Gua/ntIw=="], @@ -632,6 +625,8 @@ "eventemitter3": ["eventemitter3@4.0.7", "", {}, "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="], + "events": ["events@3.3.0", "", {}, "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q=="], + "expect": ["expect@28.1.3", "", { "dependencies": { "@jest/expect-utils": "^28.1.3", "jest-get-type": "^28.0.2", "jest-matcher-utils": "^28.1.3", "jest-message-util": "^28.1.3", "jest-util": "^28.1.3" } }, "sha512-eEh0xn8HlsuOBxFgIss+2mX85VAS4Qy3OSkjV7rlBWljtA4oWH37glVGyOZSZvErDT/yBywZdPGwCXuTvSG85g=="], "eyes": ["eyes@0.1.8", "", {}, "sha512-GipyPsXO1anza0AOZdy69Im7hGFCNB7Y/NGjDlZGJ3GJJLtwNSb2vrzYrTYJRrRloVx7pl+bhUaTB8yiccPvFQ=="], @@ -696,7 +691,7 @@ "get-proto": ["get-proto@1.0.1", "", { "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" } }, "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g=="], - "gill": ["gill@0.10.2", "", { "dependencies": { "@solana-program/address-lookup-table": "^0.7.0", "@solana-program/compute-budget": "^0.8.0", "@solana-program/system": "^0.7.0", "@solana-program/token-2022": "^0.4.1", "@solana/assertions": "^2.1.1", "@solana/codecs": "^2.1.1", "@solana/kit": "^2.1.1", "@solana/transaction-confirmation": "^2.1.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-upWoY2dfOzKHOcX3UnD+B3h9WUunPv0oxeKzsIgKSaLyURpWK9oI+K2NHWbwrUFsXEK6ozu/sgkhuqyAcVTZCg=="], + "gill": ["gill@0.10.3", "", { "dependencies": { "@solana-program/address-lookup-table": "^0.7.0", "@solana-program/compute-budget": "^0.8.0", "@solana-program/system": "^0.7.0", "@solana-program/token-2022": "^0.4.2", "@solana/assertions": "^2.1.1", "@solana/codecs": "^2.1.1", "@solana/kit": "^2.3.0", "@solana/transaction-confirmation": "^2.1.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-4LIVA32lKcWoqU/dbwu+YpJbR59QQT6mvCtqkElBWF2aT9upmewjKN3/anhfTGy+o/RJykAV21i3RzCj9FR0Xg=="], "glob": ["glob@8.1.0", "", { "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", "inherits": "2", "minimatch": "^5.0.1", "once": "^1.3.0" } }, "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ=="], @@ -800,7 +795,7 @@ "isexe": ["isexe@2.0.0", "", {}, "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw=="], - "isomorphic-ws": ["isomorphic-ws@4.0.1", "", { "peerDependencies": { "ws": "*" } }, "sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w=="], + "isomorphic-ws": ["isomorphic-ws@5.0.0", "", { "peerDependencies": { "ws": "*" } }, "sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw=="], "jayson": ["jayson@4.1.3", "", { "dependencies": { "@types/connect": "^3.4.33", "@types/node": "^12.12.54", "@types/ws": "^7.4.4", "JSONStream": "^1.3.5", "commander": "^2.20.3", "delay": "^5.0.0", "es6-promisify": "^5.0.0", "eyes": "^0.1.8", "isomorphic-ws": "^4.0.1", "json-stringify-safe": "^5.0.1", "uuid": "^8.3.2", "ws": "^7.5.10" }, "bin": { "jayson": "bin/jayson.js" } }, "sha512-LtXh5aYZodBZ9Fc3j6f2w+MTNcnxteMOrb+QgIouguGOulWi0lieEkOUg+HkjjFs0DGoWDds6bi4E9hpNFLulQ=="], @@ -972,7 +967,7 @@ "pretty-ms": ["pretty-ms@7.0.1", "", { "dependencies": { "parse-ms": "^2.1.0" } }, "sha512-973driJZvxiGOQ5ONsFhOF/DtzPMOMtgC11kCpUrPGMTgqp2q/1gwzCquocrN33is0VZ5GFHXZYMM9l6h67v2Q=="], - "protobufjs": ["protobufjs@7.4.0", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw=="], + "protobufjs": ["protobufjs@7.5.4", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="], "proxy-from-env": ["proxy-from-env@1.1.0", "", {}, "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="], @@ -1162,8 +1157,6 @@ "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="], - "yaml": ["yaml@2.7.0", "", { "bin": { "yaml": "bin.mjs" } }, "sha512-+hSoy/QHluxmC9kCIJyL/uyFmLmc+e5CFR5Wa+bpIhIj85LVb9ZH2nVnqrHoSvKogwODv0ClqZkmiSSaIH5LTA=="], - "yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="], "yargs-parser": ["yargs-parser@20.2.9", "", {}, "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w=="], @@ -1180,7 +1173,7 @@ "@babel/types/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.27.1", "", {}, "sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow=="], - "@coral-xyz/anchor-30/@coral-xyz/borsh": ["@coral-xyz/borsh@0.30.1", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ=="], + "@coral-xyz/anchor-29/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], "@ellipsis-labs/phoenix-sdk/@solana/spl-token": ["@solana/spl-token@0.3.7", "", { "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", "buffer": "^6.0.3" }, "peerDependencies": { "@solana/web3.js": "^1.47.4" } }, "sha512-bKGxWTtIw6VDdCBngjtsGlKGLSmiu/8ghSt/IOYJV24BsymRbgq7r12GToeetpxmPaZYLddKwAz7+EwprLfkfg=="], @@ -1188,8 +1181,6 @@ "@ellipsis-labs/phoenix-sdk/bs58": ["bs58@5.0.0", "", { "dependencies": { "base-x": "^4.0.0" } }, "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ=="], - "@grpc/proto-loader/protobufjs": ["protobufjs@7.5.4", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="], - "@metaplex-foundation/beet-solana/bs58": ["bs58@5.0.0", "", { "dependencies": { "base-x": "^4.0.0" } }, "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ=="], "@metaplex-foundation/solita/@metaplex-foundation/beet": ["@metaplex-foundation/beet@0.4.0", "", { "dependencies": { "ansicolors": "^0.3.2", "bn.js": "^5.2.0", "debug": "^4.3.3" } }, "sha512-2OAKJnLatCc3mBXNL0QmWVQKAWK2C7XDfepgL0p/9+8oSx4bmRAFHFqptl1A/C0U5O3dxGwKfmKluW161OVGcA=="], @@ -1198,6 +1189,8 @@ "@metaplex-foundation/solita/prettier": ["prettier@2.8.8", "", { "bin": { "prettier": "bin-prettier.js" } }, "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q=="], + "@openbook-dex/openbook-v2/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@openbook-dex/openbook-v2/@solana/spl-token": ["@solana/spl-token@0.4.12", "", { "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", "@solana/spl-token-group": "^0.0.7", "@solana/spl-token-metadata": "^0.1.6", "buffer": "^6.0.3" }, "peerDependencies": { "@solana/web3.js": "^1.95.5" } }, "sha512-K6CxzSoO1vC+WBys25zlSDaW0w4UFZO/IvEZquEI35A/PjqXNQHeVigmDCZYEJfESvYarKwsr8tYr/29lPtvaw=="], "@project-serum/anchor/camelcase": ["camelcase@5.3.1", "", {}, "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="], @@ -1206,6 +1199,10 @@ "@project-serum/serum/@solana/spl-token": ["@solana/spl-token@0.1.8", "", { "dependencies": { "@babel/runtime": "^7.10.5", "@solana/web3.js": "^1.21.0", "bn.js": "^5.1.0", "buffer": "6.0.3", "buffer-layout": "^1.2.0", "dotenv": "10.0.0" } }, "sha512-LZmYCKcPQDtJgecvWOgT/cnoIQPWjdH+QVyzPcFvyDUiT0DiRjZaam4aqNUyvchLFhzgunv3d9xOoyE34ofdoQ=="], + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor": ["@coral-xyz/anchor@0.29.0", "", { "dependencies": { "@coral-xyz/borsh": "^0.29.0", "@noble/hashes": "^1.3.1", "@solana/web3.js": "^1.68.0", "bn.js": "^5.1.2", "bs58": "^4.0.1", "buffer-layout": "^1.2.2", "camelcase": "^6.3.0", "cross-fetch": "^3.1.5", "crypto-hash": "^1.3.0", "eventemitter3": "^4.0.7", "pako": "^2.0.3", "snake-case": "^3.0.4", "superstruct": "^0.15.4", "toml": "^3.0.0" } }, "sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA=="], + "@pythnetwork/solana-utils/bs58": ["bs58@5.0.0", "", { "dependencies": { "base-x": "^4.0.0" } }, "sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ=="], "@sinonjs/commons/type-detect": ["type-detect@4.0.8", "", {}, "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="], @@ -1222,11 +1219,15 @@ "@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@switchboard-xyz/common/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + "@switchboard-xyz/common/bs58": ["bs58@6.0.0", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="], - "@switchboard-xyz/on-demand/bs58": ["bs58@6.0.0", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="], + "@switchboard-xyz/on-demand/@solana/spl-token": ["@solana/spl-token@0.4.14", "", { "dependencies": { "@solana/buffer-layout": "^4.0.0", "@solana/buffer-layout-utils": "^0.2.0", "@solana/spl-token-group": "^0.0.7", "@solana/spl-token-metadata": "^0.1.6", "buffer": "^6.0.3" }, "peerDependencies": { "@solana/web3.js": "^1.95.5" } }, "sha512-u09zr96UBpX4U685MnvQsNzlvw9TiY005hk1vJmJr7gMJldoPG1eYU5/wNEyOA5lkMLiR/gOi9SFD4MefOYEsA=="], - "@types/protobufjs/protobufjs": ["protobufjs@7.5.4", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="], + "@switchboard-xyz/on-demand/@solana/web3.js": ["@solana/web3.js@1.98.4", "", { "dependencies": { "@babel/runtime": "^7.25.0", "@noble/curves": "^1.4.2", "@noble/hashes": "^1.4.0", "@solana/buffer-layout": "^4.0.1", "@solana/codecs-numbers": "^2.1.0", "agentkeepalive": "^4.5.0", "bn.js": "^5.2.1", "borsh": "^0.7.0", "bs58": "^4.0.1", "buffer": "6.0.3", "fast-stable-stringify": "^1.0.0", "jayson": "^4.1.1", "node-fetch": "^2.7.0", "rpc-websockets": "^9.0.2", "superstruct": "^2.0.2" } }, "sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw=="], + + "@switchboard-xyz/on-demand/bs58": ["bs58@6.0.0", "", { "dependencies": { "base-x": "^5.0.0" } }, "sha512-PD0wEnEYg6ijszw/u8s+iI3H17cTymlrwkKhDhPZq+Sokl3AU4htyBFTjAeNAlCCmg0f53g6ih3jATyCKftTfw=="], "@typescript-eslint/project-service/@typescript-eslint/types": ["@typescript-eslint/types@8.38.0", "", {}, "sha512-wzkUfX3plUqij4YwWaJyqhiPE5UCRVlFpKn1oCRn2O1bJ592XxWJj8ROQ3JD5MYXLORW84063z3tZTb/cs4Tyw=="], @@ -1254,12 +1255,12 @@ "glob/minimatch": ["minimatch@5.1.6", "", { "dependencies": { "brace-expansion": "^2.0.1" } }, "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g=="], - "helius-laserstream/protobufjs": ["protobufjs@7.5.4", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg=="], - "jayson/@types/node": ["@types/node@12.20.55", "", {}, "sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ=="], "jayson/commander": ["commander@2.20.3", "", {}, "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ=="], + "jayson/isomorphic-ws": ["isomorphic-ws@4.0.1", "", { "peerDependencies": { "ws": "*" } }, "sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w=="], + "jayson/ws": ["ws@7.5.10", "", { "peerDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" }, "optionalPeers": ["bufferutil", "utf-8-validate"] }, "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ=="], "jito-ts/@grpc/grpc-js": ["@grpc/grpc-js@1.12.6", "", { "dependencies": { "@grpc/proto-loader": "^0.7.13", "@js-sdsl/ordered-map": "^4.4.2" } }, "sha512-JXUj6PI0oqqzTGvKtzOkxtpsyPRNsrmhh41TtIz/zEB6J+AUiZZ0dxWzcMwO9Ns5rmSPuMdghlTbUuqIM48d3Q=="], @@ -1306,6 +1307,14 @@ "@metaplex-foundation/beet-solana/bs58/base-x": ["base-x@4.0.0", "", {}, "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw=="], + "@openbook-dex/openbook-v2/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/pyth-solana-receiver/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor/@coral-xyz/borsh": ["@coral-xyz/borsh@0.29.0", "", { "dependencies": { "bn.js": "^5.1.2", "buffer-layout": "^1.2.0" }, "peerDependencies": { "@solana/web3.js": "^1.68.0" } }, "sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ=="], + + "@pythnetwork/solana-utils/@coral-xyz/anchor/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], + "@pythnetwork/solana-utils/bs58/base-x": ["base-x@4.0.0", "", {}, "sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw=="], "@solana/spl-token-group/@solana/codecs/@solana/codecs-core": ["@solana/codecs-core@2.0.0-rc.1", "", { "dependencies": { "@solana/errors": "2.0.0-rc.1" }, "peerDependencies": { "typescript": ">=5" } }, "sha512-bauxqMfSs8EHD0JKESaNmNuNvkvHSuN3bbWAF5RjOfDu2PugxHrvRebmYauvSumZ3cTfQ4HJJX6PG5rN852qyQ=="], @@ -1332,8 +1341,20 @@ "@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + "@switchboard-xyz/common/@solana/web3.js/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], + + "@switchboard-xyz/common/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.1", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-1IXGM/TfPT6nfYMIXkJdzn+L4JEsmb0FL1O2OBjaH03V3yuUDdKFulGLMFG6ErV+8pZ5HVC0limve01RyO+saA=="], + + "@switchboard-xyz/common/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@switchboard-xyz/common/bs58/base-x": ["base-x@5.0.0", "", {}, "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ=="], + "@switchboard-xyz/on-demand/@solana/web3.js/bs58": ["bs58@4.0.1", "", { "dependencies": { "base-x": "^3.0.2" } }, "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/rpc-websockets": ["rpc-websockets@9.1.1", "", { "dependencies": { "@swc/helpers": "^0.5.11", "@types/uuid": "^8.3.4", "@types/ws": "^8.2.2", "buffer": "^6.0.3", "eventemitter3": "^5.0.1", "uuid": "^8.3.2", "ws": "^8.5.0" }, "optionalDependencies": { "bufferutil": "^4.0.1", "utf-8-validate": "^5.0.2" } }, "sha512-1IXGM/TfPT6nfYMIXkJdzn+L4JEsmb0FL1O2OBjaH03V3yuUDdKFulGLMFG6ErV+8pZ5HVC0limve01RyO+saA=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/superstruct": ["superstruct@2.0.2", "", {}, "sha512-uV+TFRZdXsqXTL2pRvujROjdZQ4RAlBUS5BTh9IGm+jTqQntYThciG/qu57Gs69yjnVUSqdxF9YLmSnpupBW9A=="], + "@switchboard-xyz/on-demand/bs58/base-x": ["base-x@5.0.0", "", {}, "sha512-sMW3VGSX1QWVFA6l8U62MLKz29rRfpTlYdCqLdpLo1/Yd4zZwSbnUaDfciIAowAqvq7YFnWq9hrhdg1KYgc1lQ=="], "@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="], @@ -1376,10 +1397,20 @@ "@solana/spl-token-metadata/@solana/codecs/@solana/options/@solana/errors": ["@solana/errors@2.0.0-rc.1", "", { "dependencies": { "chalk": "^5.3.0", "commander": "^12.1.0" }, "peerDependencies": { "typescript": ">=5" }, "bin": { "errors": "bin/cli.mjs" } }, "sha512-ejNvQ2oJ7+bcFAYWj225lyRkHnixuAeb7RQCixm+5mH4n1IA4Qya/9Bmfy5RAAHQzxK43clu3kZmL5eF9VGtYQ=="], + "@switchboard-xyz/common/@solana/web3.js/rpc-websockets/@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + + "@switchboard-xyz/common/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/rpc-websockets/@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="], + + "@switchboard-xyz/on-demand/@solana/web3.js/rpc-websockets/eventemitter3": ["eventemitter3@5.0.1", "", {}, "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA=="], + "detective-typescript/@typescript-eslint/typescript-estree/@typescript-eslint/visitor-keys/eslint-visitor-keys": ["eslint-visitor-keys@4.2.1", "", {}, "sha512-Uhdk5sfqcee/9H/rCOJikYz67o0a2Tw2hGRPOG2Y1R2dg7brRe1uG0yaNQDHu+TO/uQPF/5eCapvYSmHUjt7JQ=="], "detective-typescript/@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@2.0.1", "", { "dependencies": { "balanced-match": "^1.0.0" } }, "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA=="], + "jito-ts/@grpc/grpc-js/@grpc/proto-loader/protobufjs": ["protobufjs@7.4.0", "", { "dependencies": { "@protobufjs/aspromise": "^1.1.2", "@protobufjs/base64": "^1.1.2", "@protobufjs/codegen": "^2.0.4", "@protobufjs/eventemitter": "^1.1.0", "@protobufjs/fetch": "^1.1.0", "@protobufjs/float": "^1.0.2", "@protobufjs/inquire": "^1.1.0", "@protobufjs/path": "^1.1.2", "@protobufjs/pool": "^1.1.0", "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" } }, "sha512-mRUWCc3KUU4w1jU8sGxICXH/gNS94DvI1gxqDvBzhj1JpcsimQkYiOJfwsPUykUI5ZaspFbSgmBLER8IrQ3tqw=="], + "@solana/spl-token-group/@solana/codecs/@solana/codecs-core/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], "@solana/spl-token-group/@solana/codecs/@solana/codecs-data-structures/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], @@ -1400,4 +1431,4 @@ "@solana/spl-token-metadata/@solana/codecs/@solana/options/@solana/errors/commander": ["commander@12.1.0", "", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="], } -} \ No newline at end of file +} diff --git a/sdk/package.json b/sdk/package.json index abfe399039..f4113fa955 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -41,8 +41,8 @@ "access": "public" }, "dependencies": { - "@coral-xyz/anchor": "0.29.0", - "@coral-xyz/anchor-30": "npm:@coral-xyz/anchor@0.30.1", + "@coral-xyz/anchor": "npm:@coral-xyz/anchor@0.31.1", + "@coral-xyz/anchor-29": "npm:@coral-xyz/anchor@0.29.0", "@ellipsis-labs/phoenix-sdk": "1.4.5", "@grpc/grpc-js": "1.14.0", "@msgpack/msgpack": "^3.1.2", @@ -53,11 +53,11 @@ "@pythnetwork/pyth-solana-receiver": "0.7.0", "@solana/spl-token": "0.4.13", "@solana/web3.js": "1.98.0", - "@switchboard-xyz/common": "3.0.14", - "@switchboard-xyz/on-demand": "2.4.1", + "@switchboard-xyz/common": "5.5.0", + "@switchboard-xyz/on-demand": "3.7.3", "@triton-one/yellowstone-grpc": "1.4.1", "anchor-bankrun": "0.3.0", - "gill": "^0.10.2", + "gill": "^0.10.3", "helius-laserstream": "0.1.8", "nanoid": "3.3.4", "node-cache": "5.1.2", @@ -147,4 +147,4 @@ "@grpc/grpc-js": false, "zstddec": false } -} +} \ No newline at end of file diff --git a/sdk/src/accounts/fetch.ts b/sdk/src/accounts/fetch.ts index 63c7bfd7f0..53d5f9ff5e 100644 --- a/sdk/src/accounts/fetch.ts +++ b/sdk/src/accounts/fetch.ts @@ -12,10 +12,11 @@ import { getUserStatsAccountPublicKey, } from '../addresses/pda'; import { Program } from '@coral-xyz/anchor'; +import { Drift } from '../idl/drift'; export async function fetchUserAccounts( connection: Connection, - program: Program, + program: Program, authority: PublicKey, limit = 8 ): Promise<(UserAccount | undefined)[]> { @@ -31,7 +32,7 @@ export async function fetchUserAccounts( export async function fetchUserAccountsUsingKeys( connection: Connection, - program: Program, + program: Program, userAccountPublicKeys: PublicKey[] ): Promise<(UserAccount | undefined)[]> { const accountInfos = await connection.getMultipleAccountsInfo( @@ -52,7 +53,7 @@ export async function fetchUserAccountsUsingKeys( export async function fetchUserStatsAccount( connection: Connection, - program: Program, + program: Program, authority: PublicKey ): Promise { const userStatsPublicKey = getUserStatsAccountPublicKey( @@ -74,7 +75,7 @@ export async function fetchUserStatsAccount( export async function fetchRevenueShareAccount( connection: Connection, - program: Program, + program: Program, authority: PublicKey ): Promise { const revenueShareAccountPublicKey = getRevenueShareAccountPublicKey( @@ -93,7 +94,7 @@ export async function fetchRevenueShareAccount( export async function fetchRevenueShareEscrowAccount( connection: Connection, - program: Program, + program: Program, authority: PublicKey ): Promise { const revenueShareEscrowPubKey = getRevenueShareEscrowAccountPublicKey( diff --git a/sdk/src/accounts/grpcAccountSubscriber.ts b/sdk/src/accounts/grpcAccountSubscriber.ts index 50adb2f318..dd698fbf04 100644 --- a/sdk/src/accounts/grpcAccountSubscriber.ts +++ b/sdk/src/accounts/grpcAccountSubscriber.ts @@ -12,6 +12,7 @@ import { SubscribeRequest, SubscribeUpdate, } from '../isomorphic/grpc'; +import { Drift } from '../idl/drift'; export class grpcAccountSubscriber extends WebSocketAccountSubscriber { private client: Client; @@ -23,7 +24,7 @@ export class grpcAccountSubscriber extends WebSocketAccountSubscriber { client: Client, commitmentLevel: CommitmentLevel, accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubOpts?: ResubOpts @@ -36,7 +37,7 @@ export class grpcAccountSubscriber extends WebSocketAccountSubscriber { public static async create( grpcConfigs: GrpcConfigs, accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => U, resubOpts?: ResubOpts, diff --git a/sdk/src/accounts/grpcDriftClientAccountSubscriber.ts b/sdk/src/accounts/grpcDriftClientAccountSubscriber.ts index 31d34e32ca..c12ec8efb8 100644 --- a/sdk/src/accounts/grpcDriftClientAccountSubscriber.ts +++ b/sdk/src/accounts/grpcDriftClientAccountSubscriber.ts @@ -11,13 +11,14 @@ import { DelistedMarketSetting, GrpcConfigs, ResubOpts } from './types'; import { grpcAccountSubscriber } from './grpcAccountSubscriber'; import { PerpMarketAccount, SpotMarketAccount, StateAccount } from '../types'; import { getOracleId } from '../oracles/oracleId'; +import { Drift } from '../idl/drift'; export class grpcDriftClientAccountSubscriber extends WebSocketDriftClientAccountSubscriber { private grpcConfigs: GrpcConfigs; constructor( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], diff --git a/sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts b/sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts index d2770dc3c7..5ff0a15dd1 100644 --- a/sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts +++ b/sdk/src/accounts/grpcDriftClientAccountSubscriberV2.ts @@ -30,6 +30,7 @@ import { } from '../oracles/oracleId'; import { OracleClientCache } from '../oracles/oracleClientCache'; import { findDelistedPerpMarketsAndOracles } from './utils'; +import { Drift } from '../idl/drift'; export class grpcDriftClientAccountSubscriberV2 implements DriftClientAccountSubscriber @@ -51,7 +52,7 @@ export class grpcDriftClientAccountSubscriberV2 >; public isSubscribed: boolean; public isSubscribing: boolean; - public program: Program; + public program: Program; public perpMarketIndexes: number[]; public spotMarketIndexes: number[]; public shouldFindAllMarketsAndOracles: boolean; @@ -76,7 +77,7 @@ export class grpcDriftClientAccountSubscriberV2 constructor( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], diff --git a/sdk/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts b/sdk/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts index 56aa167b7e..89387ec46f 100644 --- a/sdk/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts +++ b/sdk/src/accounts/grpcInsuranceFundStakeAccountSubscriber.ts @@ -4,13 +4,14 @@ import { PublicKey } from '@solana/web3.js'; import { InsuranceFundStake } from '../types'; import { WebSocketInsuranceFundStakeAccountSubscriber } from './webSocketInsuranceFundStakeAccountSubscriber'; import { grpcAccountSubscriber } from './grpcAccountSubscriber'; +import { Drift } from '../idl/drift'; export class grpcInsuranceFundStakeAccountSubscriber extends WebSocketInsuranceFundStakeAccountSubscriber { private grpcConfigs: GrpcConfigs; public constructor( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, insuranceFundStakeAccountPublicKey: PublicKey, resubTimeoutMs?: number ) { diff --git a/sdk/src/accounts/grpcMultiAccountSubscriber.ts b/sdk/src/accounts/grpcMultiAccountSubscriber.ts index 7a442ac5cd..3bf465c8fb 100644 --- a/sdk/src/accounts/grpcMultiAccountSubscriber.ts +++ b/sdk/src/accounts/grpcMultiAccountSubscriber.ts @@ -12,6 +12,7 @@ import { createClient, } from '../isomorphic/grpc'; import { BufferAndSlot, DataAndSlot, GrpcConfigs, ResubOpts } from './types'; +import { Drift } from '../idl/drift'; interface AccountInfoLike { owner: PublicKey; @@ -40,7 +41,7 @@ export class grpcMultiAccountSubscriber { private client: Client; private stream: ClientDuplexStream; private commitmentLevel: CommitmentLevel; - private program: Program; + private program: Program; private accountName: string; private decodeBufferFn?: ( buffer: Buffer, @@ -69,7 +70,7 @@ export class grpcMultiAccountSubscriber { client: Client, commitmentLevel: CommitmentLevel, accountName: string, - program: Program, + program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string) => T, resubOpts?: ResubOpts, onUnsubscribe?: () => Promise, @@ -88,7 +89,7 @@ export class grpcMultiAccountSubscriber { public static async create( grpcConfigs: GrpcConfigs, accountName: string, - program: Program, + program: Program, decodeBuffer?: (buffer: Buffer, pubkey?: string, accountProps?: U) => T, resubOpts?: ResubOpts, clientProp?: Client, diff --git a/sdk/src/accounts/grpcMultiUserAccountSubscriber.ts b/sdk/src/accounts/grpcMultiUserAccountSubscriber.ts index 38ea46c78c..14d8c5435f 100644 --- a/sdk/src/accounts/grpcMultiUserAccountSubscriber.ts +++ b/sdk/src/accounts/grpcMultiUserAccountSubscriber.ts @@ -12,9 +12,10 @@ import { Context, PublicKey } from '@solana/web3.js'; import { Program } from '@coral-xyz/anchor'; import { UserAccount } from '../types'; import { grpcMultiAccountSubscriber } from './grpcMultiAccountSubscriber'; +import { Drift } from '../idl/drift'; export class grpcMultiUserAccountSubscriber { - private program: Program; + private program: Program; private multiSubscriber: grpcMultiAccountSubscriber; private userData = new Map>(); @@ -50,7 +51,7 @@ export class grpcMultiUserAccountSubscriber { }; public constructor( - program: Program, + program: Program, grpcConfigs: GrpcConfigs, resubOpts?: ResubOpts, multiSubscriber?: grpcMultiAccountSubscriber diff --git a/sdk/src/accounts/grpcProgramAccountSubscriber.ts b/sdk/src/accounts/grpcProgramAccountSubscriber.ts index f575c64229..4440597f96 100644 --- a/sdk/src/accounts/grpcProgramAccountSubscriber.ts +++ b/sdk/src/accounts/grpcProgramAccountSubscriber.ts @@ -12,6 +12,7 @@ import { SubscribeRequest, SubscribeUpdate, } from '../isomorphic/grpc'; +import { Drift } from '../idl/drift'; export class grpcProgramAccountSubscriber< T, @@ -26,7 +27,7 @@ export class grpcProgramAccountSubscriber< commitmentLevel: CommitmentLevel, subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options: { filters: MemcmpFilter[] } = { filters: [], @@ -49,7 +50,7 @@ export class grpcProgramAccountSubscriber< grpcConfigs: GrpcConfigs, subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options: { filters: MemcmpFilter[] } = { filters: [], diff --git a/sdk/src/accounts/grpcUserAccountSubscriber.ts b/sdk/src/accounts/grpcUserAccountSubscriber.ts index db3ad1225a..72dbbe8aac 100644 --- a/sdk/src/accounts/grpcUserAccountSubscriber.ts +++ b/sdk/src/accounts/grpcUserAccountSubscriber.ts @@ -4,13 +4,14 @@ import { PublicKey } from '@solana/web3.js'; import { UserAccount } from '../types'; import { WebSocketUserAccountSubscriber } from './webSocketUserAccountSubscriber'; import { grpcAccountSubscriber } from './grpcAccountSubscriber'; +import { Drift } from '../idl/drift'; export class grpcUserAccountSubscriber extends WebSocketUserAccountSubscriber { private grpcConfigs: GrpcConfigs; public constructor( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, userAccountPublicKey: PublicKey, resubOpts?: ResubOpts ) { diff --git a/sdk/src/accounts/grpcUserStatsAccountSubscriber.ts b/sdk/src/accounts/grpcUserStatsAccountSubscriber.ts index 2998e5884f..59bd837ffd 100644 --- a/sdk/src/accounts/grpcUserStatsAccountSubscriber.ts +++ b/sdk/src/accounts/grpcUserStatsAccountSubscriber.ts @@ -4,13 +4,14 @@ import { PublicKey } from '@solana/web3.js'; import { UserStatsAccount } from '../types'; import { WebSocketUserStatsAccountSubscriber } from './webSocketUserStatsAccountSubsriber'; import { grpcAccountSubscriber } from './grpcAccountSubscriber'; +import { Drift } from '../idl/drift'; export class grpcUserStatsAccountSubscriber extends WebSocketUserStatsAccountSubscriber { private grpcConfigs: GrpcConfigs; public constructor( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, userStatsAccountPublicKey: PublicKey, resubOpts?: ResubOpts ) { diff --git a/sdk/src/accounts/laserProgramAccountSubscriber.ts b/sdk/src/accounts/laserProgramAccountSubscriber.ts index a2315ad92f..059cb40f67 100644 --- a/sdk/src/accounts/laserProgramAccountSubscriber.ts +++ b/sdk/src/accounts/laserProgramAccountSubscriber.ts @@ -13,6 +13,7 @@ import { CompressionAlgorithms, CommitmentLevel, } from '../isomorphic/grpc'; +import { Drift } from '../idl/drift'; type LaserCommitment = (typeof LaserCommitmentLevel)[keyof typeof LaserCommitmentLevel]; @@ -38,7 +39,7 @@ export class LaserstreamProgramAccountSubscriber< commitmentLevel: CommitmentLevel, subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options: { filters: MemcmpFilter[] } = { filters: [] }, resubOpts?: ResubOpts @@ -59,7 +60,7 @@ export class LaserstreamProgramAccountSubscriber< grpcConfigs: GrpcConfigs, subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => U, options: { filters: MemcmpFilter[] } = { filters: [], diff --git a/sdk/src/accounts/oneShotUserAccountSubscriber.ts b/sdk/src/accounts/oneShotUserAccountSubscriber.ts index 263bfa03d6..73bdd136ab 100644 --- a/sdk/src/accounts/oneShotUserAccountSubscriber.ts +++ b/sdk/src/accounts/oneShotUserAccountSubscriber.ts @@ -3,6 +3,7 @@ import { UserAccount } from '../types'; import { BasicUserAccountSubscriber } from './basicUserAccountSubscriber'; import { Program } from '@coral-xyz/anchor'; import { UserAccountSubscriber } from './types'; +import { Drift } from '../idl/drift'; /** * Simple implementation of UserAccountSubscriber. It will fetch the UserAccount @@ -13,11 +14,11 @@ export class OneShotUserAccountSubscriber extends BasicUserAccountSubscriber implements UserAccountSubscriber { - program: Program; + program: Program; commitment: Commitment; public constructor( - program: Program, + program: Program, userAccountPublicKey: PublicKey, data?: UserAccount, slot?: number, diff --git a/sdk/src/accounts/oneShotUserStatsAccountSubscriber.ts b/sdk/src/accounts/oneShotUserStatsAccountSubscriber.ts index a464063f6c..e4e9c0c2aa 100644 --- a/sdk/src/accounts/oneShotUserStatsAccountSubscriber.ts +++ b/sdk/src/accounts/oneShotUserStatsAccountSubscriber.ts @@ -1,8 +1,9 @@ import { Commitment, PublicKey } from '@solana/web3.js'; -import { UserStatsAccount } from '../types'; +import { parseUserStatsAccount, UserStatsAccount } from '../types'; import { BasicUserStatsAccountSubscriber } from './basicUserStatsAccountSubscriber'; import { Program } from '@coral-xyz/anchor'; import { UserStatsAccountSubscriber } from './types'; +import { Drift } from '../idl/drift'; /** * Simple implementation of UserStatsAccountSubscriber. It will fetch the UserStatsAccount @@ -13,11 +14,11 @@ export class OneShotUserStatsAccountSubscriber extends BasicUserStatsAccountSubscriber implements UserStatsAccountSubscriber { - program: Program; + program: Program; commitment: Commitment; public constructor( - program: Program, + program: Program, userStatsAccountPublicKey: PublicKey, data?: UserStatsAccount, slot?: number, @@ -56,7 +57,7 @@ export class OneShotUserStatsAccountSubscriber ); if (dataAndContext.context.slot > (this.userStats?.slot ?? 0)) { this.userStats = { - data: dataAndContext.data as UserStatsAccount, + data: parseUserStatsAccount(dataAndContext.data), slot: dataAndContext.context.slot, }; } diff --git a/sdk/src/accounts/pollingDriftClientAccountSubscriber.ts b/sdk/src/accounts/pollingDriftClientAccountSubscriber.ts index 18da8df653..d386ded475 100644 --- a/sdk/src/accounts/pollingDriftClientAccountSubscriber.ts +++ b/sdk/src/accounts/pollingDriftClientAccountSubscriber.ts @@ -30,6 +30,7 @@ import { OracleClientCache } from '../oracles/oracleClientCache'; import { QUOTE_ORACLE_PRICE_DATA } from '../oracles/quoteAssetOracleClient'; import { findAllMarketAndOracles } from '../config'; import { getOracleId } from '../oracles/oracleId'; +import { Drift } from '../idl/drift'; const ORACLE_DEFAULT_ID = getOracleId( PublicKey.default, @@ -40,7 +41,7 @@ export class PollingDriftClientAccountSubscriber implements DriftClientAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; perpMarketIndexes: number[]; spotMarketIndexes: number[]; oracleInfos: OracleInfo[]; @@ -71,7 +72,7 @@ export class PollingDriftClientAccountSubscriber private subscriptionPromiseResolver: (val: boolean) => void; public constructor( - program: Program, + program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: number[], spotMarketIndexes: number[], diff --git a/sdk/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts b/sdk/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts index 6b7f2a0f65..c06955dced 100644 --- a/sdk/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts +++ b/sdk/src/accounts/pollingHighLeverageModeConfigAccountSubscriber.ts @@ -10,12 +10,13 @@ import { EventEmitter } from 'events'; import { PublicKey } from '@solana/web3.js'; import { BulkAccountLoader } from './bulkAccountLoader'; import { HighLeverageModeConfig } from '../types'; +import { Drift } from '../idl/drift'; export class PollingHighLeverageModeConfigAccountSubscriber implements HighLeverageModeConfigAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; eventEmitter: StrictEventEmitter< EventEmitter, HighLeverageModeConfigAccountEvents @@ -29,7 +30,7 @@ export class PollingHighLeverageModeConfigAccountSubscriber highLeverageModeConfigAccountAndSlot?: DataAndSlot; public constructor( - program: Program, + program: Program, publicKey: PublicKey, accountLoader: BulkAccountLoader ) { @@ -118,7 +119,11 @@ export class PollingHighLeverageModeConfigAccountSubscriber (this.highLeverageModeConfigAccountAndSlot?.slot ?? 0) ) { this.highLeverageModeConfigAccountAndSlot = { - data: dataAndContext.data as HighLeverageModeConfig, + data: { + maxUsers: dataAndContext.data.maxUsers, + currentUsers: dataAndContext.data.currentUsers, + reduceOnly: dataAndContext.data.reduceOnly > 0, + }, slot: dataAndContext.context.slot, }; } diff --git a/sdk/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts b/sdk/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts index bca1c04ac7..0134b1cfc1 100644 --- a/sdk/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts +++ b/sdk/src/accounts/pollingInsuranceFundStakeAccountSubscriber.ts @@ -10,12 +10,13 @@ import { EventEmitter } from 'events'; import { PublicKey } from '@solana/web3.js'; import { BulkAccountLoader } from './bulkAccountLoader'; import { InsuranceFundStake } from '../types'; +import { Drift } from '../idl/drift'; export class PollingInsuranceFundStakeAccountSubscriber implements InsuranceFundStakeAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; eventEmitter: StrictEventEmitter< EventEmitter, InsuranceFundStakeAccountEvents @@ -29,7 +30,7 @@ export class PollingInsuranceFundStakeAccountSubscriber insuranceFundStakeAccountAndSlot?: DataAndSlot; public constructor( - program: Program, + program: Program, publicKey: PublicKey, accountLoader: BulkAccountLoader ) { diff --git a/sdk/src/accounts/pollingUserStatsAccountSubscriber.ts b/sdk/src/accounts/pollingUserStatsAccountSubscriber.ts index d146c31dc8..faa2971fa1 100644 --- a/sdk/src/accounts/pollingUserStatsAccountSubscriber.ts +++ b/sdk/src/accounts/pollingUserStatsAccountSubscriber.ts @@ -8,14 +8,15 @@ import { Program } from '@coral-xyz/anchor'; import StrictEventEmitter from 'strict-event-emitter-types'; import { EventEmitter } from 'events'; import { PublicKey } from '@solana/web3.js'; -import { UserStatsAccount } from '../types'; +import { parseUserStatsAccount, UserStatsAccount } from '../types'; import { BulkAccountLoader } from './bulkAccountLoader'; +import { Drift } from '../idl/drift'; export class PollingUserStatsAccountSubscriber implements UserStatsAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; eventEmitter: StrictEventEmitter; userStatsAccountPublicKey: PublicKey; @@ -26,7 +27,7 @@ export class PollingUserStatsAccountSubscriber userStats?: DataAndSlot; public constructor( - program: Program, + program: Program, userStatsAccountPublicKey: PublicKey, accountLoader: BulkAccountLoader ) { @@ -105,7 +106,7 @@ export class PollingUserStatsAccountSubscriber ); if (dataAndContext.context.slot > (this.userStats?.slot ?? 0)) { this.userStats = { - data: dataAndContext.data as UserStatsAccount, + data: parseUserStatsAccount(dataAndContext.data), slot: dataAndContext.context.slot, }; } diff --git a/sdk/src/accounts/webSocketAccountSubscriber.ts b/sdk/src/accounts/webSocketAccountSubscriber.ts index deee456166..a994c37d7c 100644 --- a/sdk/src/accounts/webSocketAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketAccountSubscriber.ts @@ -8,13 +8,14 @@ import { AnchorProvider, Program } from '@coral-xyz/anchor'; import { AccountInfo, Commitment, Context, PublicKey } from '@solana/web3.js'; import { capitalize } from './utils'; import * as Buffer from 'buffer'; +import { Drift } from '../idl/drift'; export class WebSocketAccountSubscriber implements AccountSubscriber { dataAndSlot?: DataAndSlot; bufferAndSlot?: BufferAndSlot; accountName: string; logAccountName: string; - program: Program; + program: Program; accountPublicKey: PublicKey; decodeBufferFn: (buffer: Buffer) => T; onChange: (data: T) => void; @@ -31,7 +32,7 @@ export class WebSocketAccountSubscriber implements AccountSubscriber { public constructor( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubOpts?: ResubOpts, diff --git a/sdk/src/accounts/webSocketAccountSubscriberV2.ts b/sdk/src/accounts/webSocketAccountSubscriberV2.ts index c86f7bda06..d12c3064e5 100644 --- a/sdk/src/accounts/webSocketAccountSubscriberV2.ts +++ b/sdk/src/accounts/webSocketAccountSubscriberV2.ts @@ -20,6 +20,7 @@ import { } from 'gill'; import { PublicKey } from '@solana/web3.js'; import bs58 from 'bs58'; +import { Drift } from '../idl/drift'; /** * WebSocketAccountSubscriberV2 @@ -74,7 +75,7 @@ export class WebSocketAccountSubscriberV2 implements AccountSubscriber { bufferAndSlot?: BufferAndSlot; accountName: string; logAccountName: string; - program: Program; + program: Program; accountPublicKey: PublicKey; decodeBufferFn: (buffer: Buffer) => T; onChange: (data: T) => void; @@ -112,7 +113,7 @@ export class WebSocketAccountSubscriberV2 implements AccountSubscriber { */ public constructor( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => T, resubOpts?: ResubOpts, diff --git a/sdk/src/accounts/webSocketDriftClientAccountSubscriber.ts b/sdk/src/accounts/webSocketDriftClientAccountSubscriber.ts index 973e5ac007..fd91da4484 100644 --- a/sdk/src/accounts/webSocketDriftClientAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketDriftClientAccountSubscriber.ts @@ -29,6 +29,7 @@ import { findDelistedPerpMarketsAndOracles } from './utils'; import { getOracleId } from '../oracles/oracleId'; import { OracleSource } from '../types'; import { WebSocketAccountSubscriberV2 } from './webSocketAccountSubscriberV2'; +import { Drift } from '../idl/drift'; const ORACLE_DEFAULT_ID = getOracleId( PublicKey.default, @@ -39,7 +40,7 @@ export class WebSocketDriftClientAccountSubscriber implements DriftClientAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; commitment?: Commitment; perpMarketIndexes: number[]; spotMarketIndexes: number[]; @@ -71,7 +72,7 @@ export class WebSocketDriftClientAccountSubscriber initialOraclePriceData: Map; customPerpMarketAccountSubscriber?: new ( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, @@ -79,7 +80,7 @@ export class WebSocketDriftClientAccountSubscriber ) => AccountSubscriber; customOracleAccountSubscriber?: new ( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, @@ -91,7 +92,7 @@ export class WebSocketDriftClientAccountSubscriber protected subscriptionPromiseResolver: (val: boolean) => void; public constructor( - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], @@ -101,7 +102,7 @@ export class WebSocketDriftClientAccountSubscriber commitment?: Commitment, customPerpMarketAccountSubscriber?: new ( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, @@ -109,7 +110,7 @@ export class WebSocketDriftClientAccountSubscriber ) => WebSocketAccountSubscriberV2 | WebSocketAccountSubscriber, customOracleAccountSubscriber?: new ( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, diff --git a/sdk/src/accounts/webSocketDriftClientAccountSubscriberV2.ts b/sdk/src/accounts/webSocketDriftClientAccountSubscriberV2.ts index 0a37b53d81..502dd0ce6c 100644 --- a/sdk/src/accounts/webSocketDriftClientAccountSubscriberV2.ts +++ b/sdk/src/accounts/webSocketDriftClientAccountSubscriberV2.ts @@ -45,6 +45,7 @@ import { } from '../memcmp'; import { WebSocketProgramAccountsSubscriberV2 } from './webSocketProgramAccountsSubscriberV2'; import { WebSocketAccountSubscriberV2 } from './webSocketAccountSubscriberV2'; +import { Drift } from '../idl/drift'; const ORACLE_DEFAULT_ID = getOracleId( PublicKey.default, OracleSource.QUOTE_ASSET @@ -54,7 +55,7 @@ export class WebSocketDriftClientAccountSubscriberV2 implements DriftClientAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; commitment?: Commitment; perpMarketIndexes: number[]; spotMarketIndexes: number[]; @@ -97,7 +98,7 @@ export class WebSocketDriftClientAccountSubscriberV2 string; public constructor( - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], diff --git a/sdk/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts b/sdk/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts index 0742f6b1fa..17f19913ce 100644 --- a/sdk/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketHighLeverageModeConfigAccountSubscriber.ts @@ -11,6 +11,7 @@ import { EventEmitter } from 'events'; import { Commitment, PublicKey } from '@solana/web3.js'; import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber'; import { HighLeverageModeConfig } from '../types'; +import { Drift } from '../idl/drift'; export class WebSocketHighLeverageModeConfigAccountSubscriber implements HighLeverageModeConfigAccountSubscriber @@ -18,7 +19,7 @@ export class WebSocketHighLeverageModeConfigAccountSubscriber isSubscribed: boolean; resubTimeoutMs?: number; commitment?: Commitment; - program: Program; + program: Program; eventEmitter: StrictEventEmitter< EventEmitter, HighLeverageModeConfigAccountEvents @@ -28,7 +29,7 @@ export class WebSocketHighLeverageModeConfigAccountSubscriber highLeverageModeConfigDataAccountSubscriber: AccountSubscriber; public constructor( - program: Program, + program: Program, highLeverageModeConfigAccountPublicKey: PublicKey, resubTimeoutMs?: number, commitment?: Commitment diff --git a/sdk/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts b/sdk/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts index bc8042a7ae..f2a731ed39 100644 --- a/sdk/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketInsuranceFundStakeAccountSubscriber.ts @@ -11,6 +11,7 @@ import { EventEmitter } from 'events'; import { Commitment, PublicKey } from '@solana/web3.js'; import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber'; import { InsuranceFundStake } from '../types'; +import { Drift } from '../idl/drift'; export class WebSocketInsuranceFundStakeAccountSubscriber implements InsuranceFundStakeAccountSubscriber @@ -18,7 +19,7 @@ export class WebSocketInsuranceFundStakeAccountSubscriber isSubscribed: boolean; resubTimeoutMs?: number; commitment?: Commitment; - program: Program; + program: Program; eventEmitter: StrictEventEmitter< EventEmitter, InsuranceFundStakeAccountEvents @@ -28,7 +29,7 @@ export class WebSocketInsuranceFundStakeAccountSubscriber insuranceFundStakeDataAccountSubscriber: AccountSubscriber; public constructor( - program: Program, + program: Program, insuranceFundStakeAccountPublicKey: PublicKey, resubTimeoutMs?: number, commitment?: Commitment diff --git a/sdk/src/accounts/webSocketProgramAccountSubscriber.ts b/sdk/src/accounts/webSocketProgramAccountSubscriber.ts index d860477583..85a0e8fe95 100644 --- a/sdk/src/accounts/webSocketProgramAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketProgramAccountSubscriber.ts @@ -8,6 +8,7 @@ import { PublicKey, } from '@solana/web3.js'; import * as Buffer from 'buffer'; +import { Drift } from '../idl/drift'; export class WebSocketProgramAccountSubscriber implements ProgramAccountSubscriber @@ -16,7 +17,7 @@ export class WebSocketProgramAccountSubscriber accountDiscriminator: string; bufferAndSlot?: BufferAndSlot; bufferAndSlotMap: Map = new Map(); - program: Program; + program: Program; decodeBuffer: (accountName: string, ix: Buffer) => T; onChange: ( accountId: PublicKey, @@ -35,7 +36,7 @@ export class WebSocketProgramAccountSubscriber public constructor( subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options: { filters: MemcmpFilter[]; commitment?: Commitment } = { filters: [], diff --git a/sdk/src/accounts/webSocketProgramAccountsSubscriberV2.ts b/sdk/src/accounts/webSocketProgramAccountsSubscriberV2.ts index 31a68ce02e..02508638a4 100644 --- a/sdk/src/accounts/webSocketProgramAccountsSubscriberV2.ts +++ b/sdk/src/accounts/webSocketProgramAccountsSubscriberV2.ts @@ -13,6 +13,7 @@ import { Commitment as GillCommitment, } from 'gill'; import bs58 from 'bs58'; +import { Drift } from '../idl/drift'; type ProgramAccountSubscriptionAsyncIterable = AsyncIterable< Readonly<{ @@ -98,7 +99,7 @@ export class WebSocketProgramAccountsSubscriberV2 subscriptionName: string; accountDiscriminator: string; bufferAndSlotMap: Map = new Map(); - program: Program; + program: Program; decodeBuffer: (accountName: string, ix: Buffer) => T; onChange: ( accountId: PublicKey, @@ -142,7 +143,7 @@ export class WebSocketProgramAccountsSubscriberV2 public constructor( subscriptionName: string, accountDiscriminator: string, - program: Program, + program: Program, decodeBufferFn: (accountName: string, ix: Buffer) => T, options: { filters: MemcmpFilter[]; commitment?: Commitment } = { filters: [], diff --git a/sdk/src/accounts/webSocketUserAccountSubscriber.ts b/sdk/src/accounts/webSocketUserAccountSubscriber.ts index 79d6f9401f..766f3c2db7 100644 --- a/sdk/src/accounts/webSocketUserAccountSubscriber.ts +++ b/sdk/src/accounts/webSocketUserAccountSubscriber.ts @@ -12,19 +12,20 @@ import { EventEmitter } from 'events'; import { Commitment, PublicKey } from '@solana/web3.js'; import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber'; import { UserAccount } from '../types'; +import { Drift } from '../idl/drift'; export class WebSocketUserAccountSubscriber implements UserAccountSubscriber { isSubscribed: boolean; resubOpts?: ResubOpts; commitment?: Commitment; - program: Program; + program: Program; eventEmitter: StrictEventEmitter; userAccountPublicKey: PublicKey; userDataAccountSubscriber: AccountSubscriber; public constructor( - program: Program, + program: Program, userAccountPublicKey: PublicKey, resubOpts?: ResubOpts, commitment?: Commitment diff --git a/sdk/src/accounts/webSocketUserStatsAccountSubsriber.ts b/sdk/src/accounts/webSocketUserStatsAccountSubsriber.ts index fdc0be5507..b15d91bc31 100644 --- a/sdk/src/accounts/webSocketUserStatsAccountSubsriber.ts +++ b/sdk/src/accounts/webSocketUserStatsAccountSubsriber.ts @@ -12,6 +12,7 @@ import { EventEmitter } from 'events'; import { Commitment, PublicKey } from '@solana/web3.js'; import { WebSocketAccountSubscriber } from './webSocketAccountSubscriber'; import { UserStatsAccount } from '../types'; +import { Drift } from '../idl/drift'; export class WebSocketUserStatsAccountSubscriber implements UserStatsAccountSubscriber @@ -19,14 +20,14 @@ export class WebSocketUserStatsAccountSubscriber isSubscribed: boolean; resubOpts?: ResubOpts; commitment?: Commitment; - program: Program; + program: Program; eventEmitter: StrictEventEmitter; userStatsAccountPublicKey: PublicKey; userStatsAccountSubscriber: AccountSubscriber; public constructor( - program: Program, + program: Program, userStatsAccountPublicKey: PublicKey, resubOpts?: ResubOpts, commitment?: Commitment diff --git a/sdk/src/accounts/websocketProgramUserAccountSubscriber.ts b/sdk/src/accounts/websocketProgramUserAccountSubscriber.ts index 6c95afe2d0..74e6e7fd1b 100644 --- a/sdk/src/accounts/websocketProgramUserAccountSubscriber.ts +++ b/sdk/src/accounts/websocketProgramUserAccountSubscriber.ts @@ -10,6 +10,7 @@ import { EventEmitter } from 'events'; import { Context, PublicKey } from '@solana/web3.js'; import { WebSocketProgramAccountSubscriber } from './webSocketProgramAccountSubscriber'; import { UserAccount } from '../types'; +import { Drift } from '../idl/drift'; export class WebSocketProgramUserAccountSubscriber implements UserAccountSubscriber @@ -18,12 +19,12 @@ export class WebSocketProgramUserAccountSubscriber eventEmitter: StrictEventEmitter; private userAccountPublicKey: PublicKey; - private program: Program; + private program: Program; private programSubscriber: WebSocketProgramAccountSubscriber; private userAccountAndSlot?: DataAndSlot; public constructor( - program: Program, + program: Program, userAccountPublicKey: PublicKey, programSubscriber: WebSocketProgramAccountSubscriber ) { diff --git a/sdk/src/adminClient.ts b/sdk/src/adminClient.ts index e6533d5a41..89366d77f7 100644 --- a/sdk/src/adminClient.ts +++ b/sdk/src/adminClient.ts @@ -37,7 +37,6 @@ import { getSerumOpenOrdersPublicKey, getSerumFulfillmentConfigPublicKey, getPhoenixFulfillmentConfigPublicKey, - getProtocolIfSharesTransferConfigPublicKey, getPrelaunchOraclePublicKey, getOpenbookV2FulfillmentConfigPublicKey, getPythPullOraclePublicKey, @@ -48,7 +47,6 @@ import { getFuelOverflowAccountPublicKey, getTokenProgramForSpotMarket, getIfRebalanceConfigPublicKey, - getInsuranceFundStakeAccountPublicKey, getLpPoolPublicKey, getAmmConstituentMappingPublicKey, getConstituentTargetBasePublicKey, @@ -76,14 +74,12 @@ import { ONE, BASE_PRECISION, PRICE_PRECISION, - GOV_SPOT_MARKET_INDEX, } from './constants/numericConstants'; import { calculateTargetPriceTrade } from './math/trade'; import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm'; import { PROGRAM_ID as PHOENIX_PROGRAM_ID } from '@ellipsis-labs/phoenix-sdk'; import { DRIFT_ORACLE_RECEIVER_ID } from './config'; import { getFeedIdUint8Array } from './util/pythOracleUtils'; -import { FUEL_RESET_LOG_ACCOUNT } from './constants/txConstants'; import { JupiterClient, QuoteResponse } from './jupiter/jupiterClient'; import { SwapMode } from './swap/UnifiedSwapClient'; @@ -812,30 +808,6 @@ export class AdminClient extends DriftClient { ); } - public async resetAmmCache( - txParams?: TxParams - ): Promise { - const initializeAmmCacheIx = await this.getResetAmmCacheIx(); - const tx = await this.buildTransaction(initializeAmmCacheIx, txParams); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getResetAmmCacheIx(): Promise { - return this.program.instruction.resetAmmCache({ - accounts: { - state: await this.getStatePublicKey(), - admin: this.useHotWalletAdmin - ? this.wallet.publicKey - : this.getStateAccount().admin, - ammCache: getAmmCachePublicKey(this.program.programId), - systemProgram: anchor.web3.SystemProgram.programId, - }, - }); - } - public async initializePredictionMarket( perpMarketIndex: number ): Promise { @@ -1584,26 +1556,6 @@ export class AdminClient extends DriftClient { } ); } - - public async updatePerpMarketTargetBaseAssetAmountPerLp( - perpMarketIndex: number, - targetBaseAssetAmountPerLP: number - ): Promise { - const updatePerpMarketTargetBaseAssetAmountPerLpIx = - await this.getUpdatePerpMarketTargetBaseAssetAmountPerLpIx( - perpMarketIndex, - targetBaseAssetAmountPerLP - ); - - const tx = await this.buildTransaction( - updatePerpMarketTargetBaseAssetAmountPerLpIx - ); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - public async updatePerpMarketAmmSummaryStats( perpMarketIndex: number, updateAmmSummaryStats?: boolean, @@ -1662,27 +1614,6 @@ export class AdminClient extends DriftClient { ); } - public async getUpdatePerpMarketTargetBaseAssetAmountPerLpIx( - perpMarketIndex: number, - targetBaseAssetAmountPerLP: number - ): Promise { - return await this.program.instruction.updatePerpMarketTargetBaseAssetAmountPerLp( - targetBaseAssetAmountPerLP, - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - perpMarket: await getPerpMarketPublicKey( - this.program.programId, - perpMarketIndex - ), - }, - } - ); - } - public async updatePerpMarketMarginRatio( perpMarketIndex: number, marginRatioInitial: number, @@ -1987,40 +1918,6 @@ export class AdminClient extends DriftClient { }); } - public async updatePerpMarketPerLpBase( - perpMarketIndex: number, - perLpBase: number - ): Promise { - const updatePerpMarketPerLpBaseIx = - await this.getUpdatePerpMarketPerLpBaseIx(perpMarketIndex, perLpBase); - - const tx = await this.buildTransaction(updatePerpMarketPerLpBaseIx); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdatePerpMarketPerLpBaseIx( - perpMarketIndex: number, - perLpBase: number - ): Promise { - const perpMarketPublicKey = await getPerpMarketPublicKey( - this.program.programId, - perpMarketIndex - ); - - return await this.program.instruction.updatePerpMarketPerLpBase(perLpBase, { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - perpMarket: perpMarketPublicKey, - }, - }); - } - public async updatePerpMarketMaxSpread( perpMarketIndex: number, maxSpread: number @@ -2593,33 +2490,6 @@ export class AdminClient extends DriftClient { ); } - public async updateLpCooldownTime( - cooldownTime: BN - ): Promise { - const updateLpCooldownTimeIx = await this.getUpdateLpCooldownTimeIx( - cooldownTime - ); - - const tx = await this.buildTransaction(updateLpCooldownTimeIx); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateLpCooldownTimeIx( - cooldownTime: BN - ): Promise { - return await this.program.instruction.updateLpCooldownTime(cooldownTime, { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - }, - }); - } - public async updatePerpMarketOracle( perpMarketIndex: number, oracle: PublicKey, @@ -3106,33 +2976,6 @@ export class AdminClient extends DriftClient { }); } - public async updateWhitelistMint( - whitelistMint?: PublicKey - ): Promise { - const updateWhitelistMintIx = await this.getUpdateWhitelistMintIx( - whitelistMint - ); - - const tx = await this.buildTransaction(updateWhitelistMintIx); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateWhitelistMintIx( - whitelistMint?: PublicKey - ): Promise { - return await this.program.instruction.updateWhitelistMint(whitelistMint, { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - }, - }); - } - public async updateDiscountMint( discountMint: PublicKey ): Promise { @@ -3473,7 +3316,6 @@ export class AdminClient extends DriftClient { this.program.programId, perpMarketIndex ), - ammCache: getAmmCachePublicKey(this.program.programId), }, } ); @@ -3604,40 +3446,6 @@ export class AdminClient extends DriftClient { ); } - public async updateMaxSlippageRatio( - perpMarketIndex: number, - maxSlippageRatio: number - ): Promise { - const updateMaxSlippageRatioIx = await this.getUpdateMaxSlippageRatioIx( - perpMarketIndex, - maxSlippageRatio - ); - - const tx = await this.buildTransaction(updateMaxSlippageRatioIx); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateMaxSlippageRatioIx( - perpMarketIndex: number, - maxSlippageRatio: number - ): Promise { - return await this.program.instruction.updateMaxSlippageRatio( - maxSlippageRatio, - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - perpMarket: this.getPerpMarketAccount(perpMarketIndex).pubkey, - }, - } - ); - } - public async updatePerpMarketUnrealizedAssetWeight( perpMarketIndex: number, unrealizedInitialAssetWeight: number, @@ -3884,32 +3692,6 @@ export class AdminClient extends DriftClient { ); } - public async updateSerumVault( - srmVault: PublicKey - ): Promise { - const updateSerumVaultIx = await this.getUpdateSerumVaultIx(srmVault); - - const tx = await this.buildTransaction(updateSerumVaultIx); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateSerumVaultIx( - srmVault: PublicKey - ): Promise { - return await this.program.instruction.updateSerumVault(srmVault, { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - srmVault: srmVault, - }, - }); - } - public async updatePerpMarketLiquidationFee( perpMarketIndex: number, liquidatorFee: number, @@ -3994,75 +3776,6 @@ export class AdminClient extends DriftClient { ); } - public async initializeProtocolIfSharesTransferConfig(): Promise { - const initializeProtocolIfSharesTransferConfigIx = - await this.getInitializeProtocolIfSharesTransferConfigIx(); - - const tx = await this.buildTransaction( - initializeProtocolIfSharesTransferConfigIx - ); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getInitializeProtocolIfSharesTransferConfigIx(): Promise { - return await this.program.instruction.initializeProtocolIfSharesTransferConfig( - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - rent: SYSVAR_RENT_PUBKEY, - systemProgram: anchor.web3.SystemProgram.programId, - protocolIfSharesTransferConfig: - getProtocolIfSharesTransferConfigPublicKey(this.program.programId), - }, - } - ); - } - - public async updateProtocolIfSharesTransferConfig( - whitelistedSigners?: PublicKey[], - maxTransferPerEpoch?: BN - ): Promise { - const updateProtocolIfSharesTransferConfigIx = - await this.getUpdateProtocolIfSharesTransferConfigIx( - whitelistedSigners, - maxTransferPerEpoch - ); - - const tx = await this.buildTransaction( - updateProtocolIfSharesTransferConfigIx - ); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateProtocolIfSharesTransferConfigIx( - whitelistedSigners?: PublicKey[], - maxTransferPerEpoch?: BN - ): Promise { - return await this.program.instruction.updateProtocolIfSharesTransferConfig( - whitelistedSigners || null, - maxTransferPerEpoch, - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - protocolIfSharesTransferConfig: - getProtocolIfSharesTransferConfigPublicKey(this.program.programId), - }, - } - ); - } - public async transferProtocolIfSharesToRevenuePool( outMarketIndex: number, inMarketIndex: number, @@ -4263,106 +3976,6 @@ export class AdminClient extends DriftClient { }); } - public async updateSpotMarketFuel( - spotMarketIndex: number, - fuelBoostDeposits?: number, - fuelBoostBorrows?: number, - fuelBoostTaker?: number, - fuelBoostMaker?: number, - fuelBoostInsurance?: number - ): Promise { - const updateSpotMarketFuelIx = await this.getUpdateSpotMarketFuelIx( - spotMarketIndex, - fuelBoostDeposits ?? null, - fuelBoostBorrows ?? null, - fuelBoostTaker ?? null, - fuelBoostMaker ?? null, - fuelBoostInsurance ?? null - ); - - const tx = await this.buildTransaction(updateSpotMarketFuelIx); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateSpotMarketFuelIx( - spotMarketIndex: number, - fuelBoostDeposits?: number, - fuelBoostBorrows?: number, - fuelBoostTaker?: number, - fuelBoostMaker?: number, - fuelBoostInsurance?: number - ): Promise { - const spotMarketPublicKey = await getSpotMarketPublicKey( - this.program.programId, - spotMarketIndex - ); - - return await this.program.instruction.updateSpotMarketFuel( - fuelBoostDeposits ?? null, - fuelBoostBorrows ?? null, - fuelBoostTaker ?? null, - fuelBoostMaker ?? null, - fuelBoostInsurance ?? null, - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - spotMarket: spotMarketPublicKey, - }, - } - ); - } - - public async updatePerpMarketFuel( - perpMarketIndex: number, - fuelBoostTaker?: number, - fuelBoostMaker?: number, - fuelBoostPosition?: number - ): Promise { - const updatePerpMarketFuelIx = await this.getUpdatePerpMarketFuelIx( - perpMarketIndex, - fuelBoostTaker ?? null, - fuelBoostMaker ?? null, - fuelBoostPosition ?? null - ); - - const tx = await this.buildTransaction(updatePerpMarketFuelIx); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdatePerpMarketFuelIx( - perpMarketIndex: number, - fuelBoostTaker?: number, - fuelBoostMaker?: number, - fuelBoostPosition?: number - ): Promise { - const perpMarketPublicKey = await getPerpMarketPublicKey( - this.program.programId, - perpMarketIndex - ); - - return await this.program.instruction.updatePerpMarketFuel( - fuelBoostTaker ?? null, - fuelBoostMaker ?? null, - fuelBoostPosition ?? null, - { - accounts: { - admin: this.isSubscribed - ? this.getStateAccount().admin - : this.wallet.publicKey, - state: await this.getStatePublicKey(), - perpMarket: perpMarketPublicKey, - }, - } - ); - } - public async updatePerpMarketOracleLowRiskSlotDelayOverride( perpMarketIndex: number, oracleLowRiskSlotDelayOverride: number @@ -4568,64 +4181,6 @@ export class AdminClient extends DriftClient { }); } - public async initUserFuel( - user: PublicKey, - authority: PublicKey, - fuelBonusDeposits?: number, - fuelBonusBorrows?: number, - fuelBonusTaker?: number, - fuelBonusMaker?: number, - fuelBonusInsurance?: number - ): Promise { - const updatePerpMarketFuelIx = await this.getInitUserFuelIx( - user, - authority, - fuelBonusDeposits, - fuelBonusBorrows, - fuelBonusTaker, - fuelBonusMaker, - fuelBonusInsurance - ); - - const tx = await this.buildTransaction(updatePerpMarketFuelIx); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getInitUserFuelIx( - user: PublicKey, - authority: PublicKey, - fuelBonusDeposits?: number, - fuelBonusBorrows?: number, - fuelBonusTaker?: number, - fuelBonusMaker?: number, - fuelBonusInsurance?: number - ): Promise { - const userStats = await getUserStatsAccountPublicKey( - this.program.programId, - authority - ); - - return await this.program.instruction.initUserFuel( - fuelBonusDeposits || null, - fuelBonusBorrows || null, - fuelBonusTaker || null, - fuelBonusMaker || null, - fuelBonusInsurance || null, - { - accounts: { - admin: this.useHotWalletAdmin - ? this.wallet.publicKey - : this.getStateAccount().admin, - state: await this.getStatePublicKey(), - user, - userStats, - }, - } - ); - } - /** * @param fuelSweepExists - whether the fuel sweep account exists, must provide this if the user has a FuelSweep account in order to properly reset the fuel season * @param authority - the authority to reset fuel for @@ -4670,7 +4225,6 @@ export class AdminClient extends DriftClient { admin: this.useHotWalletAdmin ? this.wallet.publicKey : this.getStateAccount().admin, - logAccount: FUEL_RESET_LOG_ACCOUNT, }, remainingAccounts, }); @@ -5033,36 +4587,6 @@ export class AdminClient extends DriftClient { }); } - public async updateFeatureBitFlagsBuilderReferral( - enable: boolean - ): Promise { - const updateFeatureBitFlagsBuilderReferralIx = - await this.getUpdateFeatureBitFlagsBuilderReferralIx(enable); - - const tx = await this.buildTransaction( - updateFeatureBitFlagsBuilderReferralIx - ); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateFeatureBitFlagsBuilderReferralIx( - enable: boolean - ): Promise { - return this.program.instruction.updateFeatureBitFlagsBuilderReferral( - enable, - { - accounts: { - admin: this.useHotWalletAdmin - ? this.wallet.publicKey - : this.getStateAccount().admin, - state: await this.getStatePublicKey(), - }, - } - ); - } - public async updateFeatureBitFlagsMedianTriggerPrice( enable: boolean ): Promise { @@ -5092,55 +4616,6 @@ export class AdminClient extends DriftClient { ); } - public async updateDelegateUserGovTokenInsuranceStake( - authority: PublicKey, - delegate: PublicKey - ): Promise { - const updateDelegateUserGovTokenInsuranceStakeIx = - await this.getUpdateDelegateUserGovTokenInsuranceStakeIx( - authority, - delegate - ); - - const tx = await this.buildTransaction( - updateDelegateUserGovTokenInsuranceStakeIx - ); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - - return txSig; - } - - public async getUpdateDelegateUserGovTokenInsuranceStakeIx( - authority: PublicKey, - delegate: PublicKey - ): Promise { - const marketIndex = GOV_SPOT_MARKET_INDEX; - const spotMarket = this.getSpotMarketAccount(marketIndex); - const ifStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey( - this.program.programId, - delegate, - marketIndex - ); - const userStatsPublicKey = getUserStatsAccountPublicKey( - this.program.programId, - authority - ); - - const ix = - this.program.instruction.getUpdateDelegateUserGovTokenInsuranceStakeIx({ - accounts: { - state: await this.getStatePublicKey(), - spotMarket: spotMarket.pubkey, - insuranceFundStake: ifStakeAccountPublicKey, - userStats: userStatsPublicKey, - signer: this.wallet.publicKey, - insuranceFundVault: spotMarket.insuranceFund.vault, - }, - }); - - return ix; - } - public async depositIntoInsuranceFundStake( marketIndex: number, amount: BN, @@ -5739,7 +5214,6 @@ export class AdminClient extends DriftClient { lpPool, ammConstituentMapping, constituentTargetBase, - rent: SYSVAR_RENT_PUBKEY, systemProgram: SystemProgram.programId, state: await this.getStatePublicKey(), }, diff --git a/sdk/src/config.ts b/sdk/src/config.ts index 0ff967b7ad..4c257d15e2 100644 --- a/sdk/src/config.ts +++ b/sdk/src/config.ts @@ -1,5 +1,10 @@ import { ConfirmOptions, PublicKey } from '@solana/web3.js'; -import { PerpMarketAccount, SpotMarketAccount } from './types'; +import { + PerpMarketAccount, + SpotMarketAccount, + parsePerpMarketAccount, + parseSpotMarketAccount, +} from './types'; import { DevnetPerpMarkets, MainnetPerpMarkets, @@ -19,6 +24,7 @@ import { ON_DEMAND_MAINNET_PID, } from '@switchboard-xyz/on-demand'; import { getOracleId } from './oracles/oracleId'; +import { Drift } from './idl/drift'; type DriftConfig = { ENV: DriftEnv; @@ -167,7 +173,9 @@ export function getMarketsAndOraclesForSubscription( }; } -export async function findAllMarketAndOracles(program: Program): Promise<{ +export async function findAllMarketAndOracles( + program: Program +): Promise<{ perpMarketIndexes: number[]; perpMarketAccounts: PerpMarketAccount[]; spotMarketIndexes: number[]; @@ -178,13 +186,24 @@ export async function findAllMarketAndOracles(program: Program): Promise<{ const spotMarketIndexes = []; const oracleInfos = new Map(); - const perpMarketProgramAccounts = - (await program.account.perpMarket.all()) as ProgramAccount[]; - const spotMarketProgramAccounts = - (await program.account.spotMarket.all()) as ProgramAccount[]; + //@ts-ignore TS2589 + const perpMarketProgramAccountsRaw = await program.account.perpMarket.all(); + //@ts-ignore TS2589 + const spotMarketProgramAccountsRaw = await program.account.spotMarket.all(); + + const perpMarketProgramAccounts: ProgramAccount[] = + perpMarketProgramAccountsRaw.map((account) => ({ + ...account, + account: parsePerpMarketAccount(account.account), + })); + const spotMarketProgramAccounts: ProgramAccount[] = + spotMarketProgramAccountsRaw.map((account) => ({ + ...account, + account: parseSpotMarketAccount(account.account), + })); for (const perpMarketProgramAccount of perpMarketProgramAccounts) { - const perpMarket = perpMarketProgramAccount.account as PerpMarketAccount; + const perpMarket = perpMarketProgramAccount.account; perpMarketIndexes.push(perpMarket.marketIndex); oracleInfos.set( getOracleId(perpMarket.amm.oracle, perpMarket.amm.oracleSource), @@ -196,7 +215,7 @@ export async function findAllMarketAndOracles(program: Program): Promise<{ } for (const spotMarketProgramAccount of spotMarketProgramAccounts) { - const spotMarket = spotMarketProgramAccount.account as SpotMarketAccount; + const spotMarket = spotMarketProgramAccount.account; spotMarketIndexes.push(spotMarket.marketIndex); oracleInfos.set(getOracleId(spotMarket.oracle, spotMarket.oracleSource), { publicKey: spotMarket.oracle, diff --git a/sdk/src/constituentMap/pollingConstituentAccountSubscriber.ts b/sdk/src/constituentMap/pollingConstituentAccountSubscriber.ts index e50b34df4b..8da5e168d0 100644 --- a/sdk/src/constituentMap/pollingConstituentAccountSubscriber.ts +++ b/sdk/src/constituentMap/pollingConstituentAccountSubscriber.ts @@ -8,12 +8,13 @@ import StrictEventEmitter from 'strict-event-emitter-types'; import { EventEmitter } from 'events'; import { Commitment, MemcmpFilter } from '@solana/web3.js'; import { ConstituentMap } from './constituentMap'; +import { Drift } from '../idl/drift'; export class PollingConstituentAccountSubscriber implements ConstituentAccountSubscriber { isSubscribed: boolean; - program: Program; + program: Program; frequency: number; commitment?: Commitment; additionalFilters?: MemcmpFilter[]; @@ -24,7 +25,7 @@ export class PollingConstituentAccountSubscriber public constructor( constituentMap: ConstituentMap, - program: Program, + program: Program, frequency: number, commitment?: Commitment, additionalFilters?: MemcmpFilter[] diff --git a/sdk/src/constituentMap/webSocketConstituentAccountSubscriber.ts b/sdk/src/constituentMap/webSocketConstituentAccountSubscriber.ts index 816acd6211..4502867621 100644 --- a/sdk/src/constituentMap/webSocketConstituentAccountSubscriber.ts +++ b/sdk/src/constituentMap/webSocketConstituentAccountSubscriber.ts @@ -11,6 +11,7 @@ import { ConstituentAccount } from '../types'; import { WebSocketProgramAccountSubscriber } from '../accounts/webSocketProgramAccountSubscriber'; import { getConstituentFilter } from '../memcmp'; import { ConstituentMap } from './constituentMap'; +import { Drift } from '../idl/drift'; export class WebSocketConstituentAccountSubscriber implements ConstituentAccountSubscriber @@ -18,7 +19,7 @@ export class WebSocketConstituentAccountSubscriber isSubscribed: boolean; resubTimeoutMs?: number; commitment?: Commitment; - program: Program; + program: Program; eventEmitter: StrictEventEmitter; constituentDataAccountSubscriber: WebSocketProgramAccountSubscriber; @@ -27,7 +28,7 @@ export class WebSocketConstituentAccountSubscriber public constructor( constituentMap: ConstituentMap, - program: Program, + program: Program, resubTimeoutMs?: number, commitment?: Commitment, additionalFilters?: MemcmpFilter[] diff --git a/sdk/src/decode/customCoder.ts b/sdk/src/decode/customCoder.ts index bf24f990a0..f39c7e5081 100644 --- a/sdk/src/decode/customCoder.ts +++ b/sdk/src/decode/customCoder.ts @@ -1,15 +1,15 @@ import { Buffer } from 'buffer'; import camelcase from 'camelcase'; -import { Idl, IdlTypeDef } from '@coral-xyz/anchor/dist/cjs/idl'; +import { Idl, IdlTypeDef } from '@coral-xyz/anchor-29/dist/cjs/idl'; import { AccountsCoder, BorshAccountsCoder, BorshEventCoder, BorshInstructionCoder, Coder, -} from '@coral-xyz/anchor/dist/cjs/coder'; -import { BorshTypesCoder } from '@coral-xyz/anchor/dist/cjs/coder/borsh/types'; -import { discriminator } from '@coral-xyz/anchor/dist/cjs/coder/borsh/discriminator'; +} from '@coral-xyz/anchor-29/dist/cjs/coder'; +import { BorshTypesCoder } from '@coral-xyz/anchor-29/dist/cjs/coder/borsh/types'; +import { discriminator } from '@coral-xyz/anchor-29/dist/cjs/coder/borsh/discriminator'; export class CustomBorshCoder< A extends string = string, diff --git a/sdk/src/decode/user.ts b/sdk/src/decode/user.ts index 31e365df2e..13d3b0939a 100644 --- a/sdk/src/decode/user.ts +++ b/sdk/src/decode/user.ts @@ -129,7 +129,6 @@ export function decodeUser(buffer: Buffer): UserAccount { openAsks, settledPnl, lpShares, - remainderBaseAssetAmount: 0, lastQuoteAssetAmountPerLp, marketIndex, openOrders, diff --git a/sdk/src/driftClient.ts b/sdk/src/driftClient.ts index eabb861885..9223cb77b2 100644 --- a/sdk/src/driftClient.ts +++ b/sdk/src/driftClient.ts @@ -6,7 +6,7 @@ import { Program, ProgramAccount, } from '@coral-xyz/anchor'; -import { Idl as Idl30, Program as Program30 } from '@coral-xyz/anchor-30'; +import { Program as Program20 } from '@coral-xyz/anchor-29'; import bs58 from 'bs58'; import { ASSOCIATED_TOKEN_PROGRAM_ID, @@ -61,6 +61,7 @@ import { TxParams, UserAccount, UserStatsAccount, + parseUserStatsAccount, ProtectedMakerModeConfig, SignedMsgOrderParamsDelegateMessage, TokenProgramFlag, @@ -161,7 +162,6 @@ import { configs, DRIFT_ORACLE_RECEIVER_ID, DEFAULT_CONFIRMATION_OPTS, - DRIFT_PROGRAM_ID, DriftEnv, PYTH_LAZER_STORAGE_ACCOUNT_KEY, } from './config'; @@ -204,7 +204,7 @@ import { MAX_TX_BYTE_SIZE, } from './tx/utils'; import pythSolanaReceiverIdl from './idl/pyth_solana_receiver.json'; -import { asV0Tx, PullFeed, AnchorUtils } from '@switchboard-xyz/on-demand'; +import { PullFeed } from '@switchboard-xyz/on-demand'; import { grpcDriftClientAccountSubscriber } from './accounts/grpcDriftClientAccountSubscriber'; import nacl from 'tweetnacl'; import { Slothash } from './slot/SlothashSubscriber'; @@ -221,6 +221,7 @@ import { } from './math/builder'; import { TitanClient, SwapMode as TitanSwapMode } from './titan/titanClient'; import { UnifiedSwapClient } from './swap/UnifiedSwapClient'; +import { Drift } from './idl/drift'; /** * Union type for swap clients (Titan and Jupiter) - Legacy type @@ -244,7 +245,7 @@ type RemainingAccountParams = { export class DriftClient { connection: Connection; wallet: IWallet; - public program: Program; + public program: Program; provider: AnchorProvider; env: DriftEnv; opts?: ConfirmOptions; @@ -285,10 +286,10 @@ export class DriftClient { txHandler: TxHandler; - receiverProgram?: Program; - wormholeProgram?: Program; + receiverProgram?: Program20; + wormholeProgram?: Program20; sbOnDemandProgramdId: PublicKey; - sbOnDemandProgram?: Program30; + sbOnDemandProgram?: Program; sbProgramFeedConfigs?: Map; public get isSubscribed() { @@ -318,12 +319,7 @@ export class DriftClient { config.wallet, this.opts ); - this.program = new Program( - driftIDL as Idl, - config.programID ?? new PublicKey(DRIFT_PROGRAM_ID), - this.provider, - config.coder - ); + this.program = new Program(driftIDL, this.provider, config.coder); this.authority = config.authority ?? this.wallet.publicKey; this.activeSubAccountId = config.activeSubAccountId ?? 0; @@ -823,11 +819,7 @@ export class DriftClient { newWallet, this.opts ); - const newProgram = new Program( - driftIDL as Idl, - this.program.programId, - newProvider - ); + const newProgram = new Program(driftIDL, newProvider); this.skipLoadUsers = false; // Update provider for txSender with new wallet details @@ -1339,37 +1331,6 @@ export class DriftClient { }); } - public async migrateReferrer( - authority: PublicKey, - txParams?: TxParams - ): Promise { - const ix = await this.getMigrateReferrerIx(authority); - const tx = await this.buildTransaction([ix], txParams); - const { txSig } = await this.sendTransaction(tx, [], this.opts); - return txSig; - } - - public async getMigrateReferrerIx( - authority: PublicKey - ): Promise { - const escrow = getRevenueShareEscrowAccountPublicKey( - this.program.programId, - authority - ); - return this.program.instruction.migrateReferrer({ - accounts: { - escrow, - authority, - userStats: getUserStatsAccountPublicKey( - this.program.programId, - authority - ), - state: await this.getStatePublicKey(), - payer: this.wallet.publicKey, - }, - }); - } - public async resizeRevenueShareEscrowOrders( authority: PublicKey, numOrders: number, @@ -1932,43 +1893,6 @@ export class DriftClient { return txSig; } - public async updateUserAdvancedLp( - updates: { advancedLp: boolean; subAccountId: number }[] - ): Promise { - const ixs = await Promise.all( - updates.map(async ({ advancedLp, subAccountId }) => { - return await this.getUpdateAdvancedDlpIx(advancedLp, subAccountId); - }) - ); - - const tx = await this.buildTransaction(ixs, this.txParams); - - const { txSig } = await this.sendTransaction(tx, [], this.opts); - return txSig; - } - - public async getUpdateAdvancedDlpIx( - advancedLp: boolean, - subAccountId: number - ) { - const ix = await this.program.instruction.updateUserAdvancedLp( - subAccountId, - advancedLp, - { - accounts: { - user: getUserAccountPublicKeySync( - this.program.programId, - this.wallet.publicKey, - subAccountId - ), - authority: this.wallet.publicKey, - }, - } - ); - - return ix; - } - public async updateUserReduceOnly( updates: { reduceOnly: boolean; subAccountId: number }[] ): Promise { @@ -2119,8 +2043,8 @@ export class DriftClient { }, ]); - return programAccounts.map( - (programAccount) => programAccount.account as UserStatsAccount + return programAccounts.map((programAccount) => + parseUserStatsAccount(programAccount.account) ); } @@ -2298,7 +2222,6 @@ export class DriftClient { public async getSignedMsgUserOrdersDeletionIx(authority: PublicKey) { const ix = await this.program.instruction.deleteSignedMsgUserOrders({ accounts: { - user: authority, signedMsgUserOrders: getSignedMsgUserAccountPublicKey( this.program.programId, authority @@ -3120,7 +3043,6 @@ export class DriftClient { { accounts: { state: await this.getStatePublicKey(), - spotMarket: spotMarketAccount.pubkey, spotMarketVault: spotMarketAccount.vault, user: userAccountPublicKey, userStats: this.getUserStatsAccountPublicKey(), @@ -3773,7 +3695,6 @@ export class DriftClient { { accounts: { state: await this.getStatePublicKey(), - spotMarket: spotMarketAccount.pubkey, spotMarketVault: spotMarketAccount.vault, driftSigner: this.getSignerPublicKey(), user, @@ -4111,197 +4032,6 @@ export class DriftClient { }); } - public async settleLP( - settleeUserAccountPublicKey: PublicKey, - marketIndex: number, - txParams?: TxParams - ): Promise { - const { txSig } = await this.sendTransaction( - await this.buildTransaction( - await this.settleLPIx(settleeUserAccountPublicKey, marketIndex), - txParams - ), - [], - this.opts - ); - return txSig; - } - - public async settleLPIx( - settleeUserAccountPublicKey: PublicKey, - marketIndex: number - ): Promise { - const settleeUserAccount = (await this.program.account.user.fetch( - settleeUserAccountPublicKey - )) as UserAccount; - - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [settleeUserAccount], - writablePerpMarketIndexes: [marketIndex], - }); - - return this.program.instruction.settleLp(marketIndex, { - accounts: { - state: await this.getStatePublicKey(), - user: settleeUserAccountPublicKey, - }, - remainingAccounts: remainingAccounts, - }); - } - - public async removePerpLpShares( - marketIndex: number, - sharesToBurn?: BN, - txParams?: TxParams, - subAccountId?: number - ): Promise { - const { txSig } = await this.sendTransaction( - await this.buildTransaction( - await this.getRemovePerpLpSharesIx( - marketIndex, - sharesToBurn, - subAccountId - ), - txParams - ), - [], - this.opts - ); - return txSig; - } - - public async removePerpLpSharesInExpiringMarket( - marketIndex: number, - userAccountPublicKey: PublicKey, - sharesToBurn?: BN, - txParams?: TxParams - ): Promise { - const { txSig } = await this.sendTransaction( - await this.buildTransaction( - await this.getRemovePerpLpSharesInExpiringMarket( - marketIndex, - userAccountPublicKey, - sharesToBurn - ), - txParams - ), - [], - this.opts - ); - return txSig; - } - - public async getRemovePerpLpSharesInExpiringMarket( - marketIndex: number, - userAccountPublicKey: PublicKey, - sharesToBurn?: BN - ): Promise { - const userAccount = (await this.program.account.user.fetch( - userAccountPublicKey - )) as UserAccount; - - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [userAccount], - writablePerpMarketIndexes: [marketIndex], - }); - - if (sharesToBurn == undefined) { - const perpPosition = userAccount.perpPositions.filter( - (position) => position.marketIndex === marketIndex - )[0]; - sharesToBurn = perpPosition.lpShares; - console.log('burning lp shares:', sharesToBurn.toString()); - } - - return this.program.instruction.removePerpLpSharesInExpiringMarket( - sharesToBurn, - marketIndex, - { - accounts: { - state: await this.getStatePublicKey(), - user: userAccountPublicKey, - }, - remainingAccounts: remainingAccounts, - } - ); - } - - public async getRemovePerpLpSharesIx( - marketIndex: number, - sharesToBurn?: BN, - subAccountId?: number - ): Promise { - const user = await this.getUserAccountPublicKey(subAccountId); - - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [this.getUserAccount(subAccountId)], - useMarketLastSlotCache: true, - writablePerpMarketIndexes: [marketIndex], - }); - - if (sharesToBurn == undefined) { - const userAccount = this.getUserAccount(subAccountId); - const perpPosition = userAccount.perpPositions.filter( - (position) => position.marketIndex === marketIndex - )[0]; - sharesToBurn = perpPosition.lpShares; - console.log('burning lp shares:', sharesToBurn.toString()); - } - - return this.program.instruction.removePerpLpShares( - sharesToBurn, - marketIndex, - { - accounts: { - state: await this.getStatePublicKey(), - user, - authority: this.wallet.publicKey, - }, - remainingAccounts: remainingAccounts, - } - ); - } - - public async addPerpLpShares( - amount: BN, - marketIndex: number, - txParams?: TxParams, - subAccountId?: number - ): Promise { - const { txSig, slot } = await this.sendTransaction( - await this.buildTransaction( - await this.getAddPerpLpSharesIx(amount, marketIndex, subAccountId), - txParams - ), - [], - this.opts - ); - this.perpMarketLastSlotCache.set(marketIndex, slot); - return txSig; - } - - public async getAddPerpLpSharesIx( - amount: BN, - marketIndex: number, - subAccountId?: number - ): Promise { - const user = await this.getUserAccountPublicKey(subAccountId); - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [this.getUserAccount(subAccountId)], - useMarketLastSlotCache: true, - writablePerpMarketIndexes: [marketIndex], - }); - - return this.program.instruction.addPerpLpShares(amount, marketIndex, { - accounts: { - state: await this.getStatePublicKey(), - user, - authority: this.wallet.publicKey, - }, - remainingAccounts: remainingAccounts, - }); - } - public getQuoteValuePerLpShare(marketIndex: number): BN { const perpMarketAccount = this.getPerpMarketAccount(marketIndex); @@ -4596,7 +4326,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user, - userStats: this.getUserStatsAccountPublicKey(), authority: this.wallet.publicKey, }, remainingAccounts, @@ -4787,10 +4516,6 @@ export class DriftClient { subAccountId?: number ): Promise { const user = await this.getUserAccountPublicKey(subAccountId); - - const order = this.getOrderByUserId(userOrderId); - const oracle = this.getPerpMarketAccount(order.marketIndex).amm.oracle; - const remainingAccounts = this.getRemainingAccounts({ userAccounts: [this.getUserAccount(subAccountId)], useMarketLastSlotCache: true, @@ -4801,7 +4526,6 @@ export class DriftClient { state: await this.getStatePublicKey(), user, authority: this.wallet.publicKey, - oracle, }, remainingAccounts, }); @@ -5059,7 +4783,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user, - userStats: this.getUserStatsAccountPublicKey(), authority, }, remainingAccounts, @@ -5111,7 +4834,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user, - userStats: this.getUserStatsAccountPublicKey(), authority: this.wallet.publicKey, }, remainingAccounts, @@ -5370,7 +5092,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user: userAccountPublicKey, - userStats: this.getUserStatsAccountPublicKey(), authority: this.wallet.publicKey, }, remainingAccounts, @@ -6690,54 +6411,6 @@ export class DriftClient { }); } - /* Deprecated */ - public async updateUserFuelBonus( - userAccountPublicKey: PublicKey, - user: UserAccount, - userAuthority: PublicKey, - txParams?: TxParams - ): Promise { - const { txSig } = await this.sendTransaction( - await this.buildTransaction( - await this.getUpdateUserFuelBonusIx( - userAccountPublicKey, - user, - userAuthority - ), - txParams - ), - [], - this.opts - ); - return txSig; - } - - /* Deprecated */ - public async getUpdateUserFuelBonusIx( - userAccountPublicKey: PublicKey, - userAccount: UserAccount, - userAuthority: PublicKey - ): Promise { - const userStatsAccountPublicKey = getUserStatsAccountPublicKey( - this.program.programId, - userAuthority - ); - - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [userAccount], - }); - - return await this.program.instruction.updateUserFuelBonus({ - accounts: { - state: await this.getStatePublicKey(), - user: userAccountPublicKey, - userStats: userStatsAccountPublicKey, - authority: this.wallet.publicKey, - }, - remainingAccounts, - }); - } - public async updateUserStatsReferrerStatus( userAuthority: PublicKey, txParams?: TxParams @@ -6770,49 +6443,6 @@ export class DriftClient { }); } - public async updateUserOpenOrdersCount( - userAccountPublicKey: PublicKey, - user: UserAccount, - txParams?: TxParams, - fillerPublicKey?: PublicKey - ): Promise { - const { txSig } = await this.sendTransaction( - await this.buildTransaction( - await this.getUpdateUserOpenOrdersCountIx( - userAccountPublicKey, - user, - fillerPublicKey - ), - txParams - ), - [], - this.opts - ); - return txSig; - } - - public async getUpdateUserOpenOrdersCountIx( - userAccountPublicKey: PublicKey, - userAccount: UserAccount, - fillerPublicKey?: PublicKey - ): Promise { - const filler = fillerPublicKey ?? (await this.getUserAccountPublicKey()); - - const remainingAccounts = this.getRemainingAccounts({ - userAccounts: [userAccount], - }); - - return await this.program.instruction.updateUserOpenOrdersCount({ - accounts: { - state: await this.getStatePublicKey(), - filler, - user: userAccountPublicKey, - authority: this.wallet.publicKey, - }, - remainingAccounts, - }); - } - public async placeAndTakePerpOrder( orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[], @@ -8076,7 +7706,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user: userPubKey, - userStats: this.getUserStatsAccountPublicKey(), authority, }, remainingAccounts, @@ -8201,7 +7830,6 @@ export class DriftClient { accounts: { state: await this.getStatePublicKey(), user, - userStats: this.getUserStatsAccountPublicKey(), authority: this.wallet.publicKey, }, remainingAccounts, @@ -10076,7 +9704,6 @@ export class DriftClient { amount, { accounts: { - state: await this.getStatePublicKey(), spotMarket: spotMarketAccount.pubkey, insuranceFundStake: ifStakeAccountPublicKey, userStats: getUserStatsAccountPublicKey( @@ -10111,7 +9738,6 @@ export class DriftClient { marketIndex, { accounts: { - state: await this.getStatePublicKey(), spotMarket: spotMarketAccount.pubkey, insuranceFundStake: ifStakeAccountPublicKey, userStats: getUserStatsAccountPublicKey( @@ -10562,9 +10188,9 @@ export class DriftClient { return undefined; } - public getReceiverProgram(): Program { + public getReceiverProgram(): Program20 { if (this.receiverProgram === undefined) { - this.receiverProgram = new Program( + this.receiverProgram = new Program20( pythSolanaReceiverIdl as PythSolanaReceiver, DEFAULT_RECEIVER_PROGRAM_ID, this.provider @@ -10573,10 +10199,11 @@ export class DriftClient { return this.receiverProgram; } - public async getSwitchboardOnDemandProgram(): Promise> { + public async getSwitchboardOnDemandProgram(): Promise> { if (this.sbOnDemandProgram === undefined) { - this.sbOnDemandProgram = await AnchorUtils.loadProgramFromConnection( - this.connection + this.sbOnDemandProgram = await Program.at( + this.sbOnDemandProgramdId, + this.provider ); } return this.sbOnDemandProgram; @@ -10853,9 +10480,12 @@ export class DriftClient { numSignatures = 3 ): Promise { const program = await this.getSwitchboardOnDemandProgram(); + const pullFeeds = feeds.map((f) => { + return new PullFeed(program, f); + }); const [pullIxs, _luts, _rawResponse] = await PullFeed.fetchUpdateManyLightIx(program, { - feeds, + feeds: pullFeeds, numSignatures, recentSlothashes: recentSlothash ? [[new BN(recentSlothash.slot), recentSlothash.hash]] @@ -10869,65 +10499,6 @@ export class DriftClient { return pullIxs; } - // @deprecated use getPostManySwitchboardOnDemandUpdatesAtomicIxs instead. This function no longer returns the required ixs due to upstream sdk changes. - public async getPostSwitchboardOnDemandUpdateAtomicIx( - feed: PublicKey, - recentSlothash?: Slothash, - numSignatures = 3 - ): Promise { - const program = await this.getSwitchboardOnDemandProgram(); - const feedAccount = new PullFeed(program, feed); - if (!this.sbProgramFeedConfigs) { - this.sbProgramFeedConfigs = new Map(); - } - if (!this.sbProgramFeedConfigs.has(feedAccount.pubkey.toString())) { - const feedConfig = await feedAccount.loadConfigs(); - this.sbProgramFeedConfigs.set(feed.toString(), feedConfig); - } - const [pullIx, _responses, success] = await PullFeed.fetchUpdateManyIx( - program, - { - feeds: [feed], - numSignatures, - recentSlothashes: recentSlothash - ? [[new BN(recentSlothash.slot), recentSlothash.hash]] - : undefined, - } - ); - if (!success) { - return undefined; - } - return pullIx[0]; - } - - public async postSwitchboardOnDemandUpdate( - feed: PublicKey, - recentSlothash?: Slothash, - numSignatures = 3 - ): Promise { - const pullIx = await this.getPostSwitchboardOnDemandUpdateAtomicIx( - feed, - recentSlothash, - numSignatures - ); - if (!pullIx) { - return undefined; - } - const tx = await asV0Tx({ - connection: this.connection, - ixs: [pullIx], - payer: this.wallet.publicKey, - computeUnitLimitMultiple: 1.3, - lookupTables: await this.fetchAllLookupTableAccounts(), - }); - const { txSig } = await this.sendTransaction(tx, [], { - commitment: 'processed', - skipPreflight: true, - maxRetries: 0, - }); - return txSig; - } - private async getBuildEncodedVaaIxs( vaa: Buffer, guardianSet: PublicKey @@ -10935,7 +10506,7 @@ export class DriftClient { const postIxs: TransactionInstruction[] = []; if (this.wormholeProgram === undefined) { - this.wormholeProgram = new Program( + this.wormholeProgram = new Program20( wormholeCoreBridgeIdl, DEFAULT_WORMHOLE_PROGRAM_ID, this.provider @@ -11115,14 +10686,22 @@ export class DriftClient { const config = await this.program.account.highLeverageModeConfig.fetch( getHighLeverageModeConfigPublicKey(this.program.programId) ); - return config as HighLeverageModeConfig; + return { + maxUsers: config.maxUsers, + currentUsers: config.currentUsers, + reduceOnly: config.reduceOnly > 0, + }; } public async fetchProtectedMakerModeConfig(): Promise { const config = await this.program.account.protectedMakerModeConfig.fetch( getProtectedMakerModeConfigPublicKey(this.program.programId) ); - return config as ProtectedMakerModeConfig; + return { + maxUsers: config.maxUsers, + currentUsers: config.currentUsers, + reduceOnly: config.reduceOnly > 0, + }; } public async updateUserProtectedMakerOrders( @@ -11309,9 +10888,38 @@ export class DriftClient { } public async getLpPoolAccount(lpPoolId: number): Promise { - return (await this.program.account.lpPool.fetch( + const lpPool = await this.program.account.lpPool.fetch( getLpPoolPublicKey(this.program.programId, lpPoolId) - )) as LPPoolAccount; + ); + + return { + lpPoolId: lpPool.lpPoolId, + pubkey: lpPool.pubkey, + mint: lpPool.mint, + whitelistMint: lpPool.whitelistMint, + constituentTargetBase: lpPool.constituentTargetBase, + constituentCorrelations: lpPool.constituentCorrelations, + maxAum: new BN(lpPool.maxAum[0]), + lastAum: new BN(lpPool.lastAum[0]), + cumulativeQuoteSentToPerpMarkets: new BN( + lpPool.cumulativeQuoteSentToPerpMarkets[0] + ), + cumulativeQuoteReceivedFromPerpMarkets: new BN( + lpPool.cumulativeQuoteReceivedFromPerpMarkets[0] + ), + totalMintRedeemFeesPaid: new BN(lpPool.totalMintRedeemFeesPaid[0]), + lastAumSlot: new BN(lpPool.lastAumSlot), + maxSettleQuoteAmount: new BN(lpPool.maxSettleQuoteAmount), + mintRedeemId: new BN(lpPool.mintRedeemId), + settleId: new BN(lpPool.settleId), + minMintFee: new BN(lpPool.minMintFee), + tokenSupply: new BN(lpPool.tokenSupply), + volatility: new BN(lpPool.volatility), + constituents: lpPool.constituents, + bump: lpPool.bump, + gammaExecution: lpPool.gammaExecution, + xi: lpPool.xi, + }; } public async getConstituentTargetBaseAccount( diff --git a/sdk/src/driftClientConfig.ts b/sdk/src/driftClientConfig.ts index 4ca3a8a9eb..17869defe6 100644 --- a/sdk/src/driftClientConfig.ts +++ b/sdk/src/driftClientConfig.ts @@ -25,6 +25,7 @@ import { grpcMultiUserAccountSubscriber } from './accounts/grpcMultiUserAccountS import { WebSocketProgramAccountSubscriber } from './accounts/webSocketProgramAccountSubscriber'; import { WebSocketDriftClientAccountSubscriber } from './accounts/webSocketDriftClientAccountSubscriber'; import { WebSocketDriftClientAccountSubscriberV2 } from './accounts/webSocketDriftClientAccountSubscriberV2'; +import { Drift } from './idl/drift'; export type DriftClientConfig = { connection: Connection; @@ -65,7 +66,7 @@ export type DriftClientSubscriptionConfig = logResubMessages?: boolean; driftClientAccountSubscriber?: new ( grpcConfigs: GrpcConfigs, - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], @@ -84,7 +85,7 @@ export type DriftClientSubscriptionConfig = programUserAccountSubscriber?: WebSocketProgramAccountSubscriber; perpMarketAccountSubscriber?: new ( accountName: string, - program: Program, + program: Program, accountPublicKey: PublicKey, decodeBuffer?: (buffer: Buffer) => any, resubOpts?: ResubOpts, @@ -92,7 +93,7 @@ export type DriftClientSubscriptionConfig = ) => WebSocketAccountSubscriberV2 | WebSocketAccountSubscriber; /** If you use V2 here, whatever you pass for perpMarketAccountSubscriber will be ignored and it will use v2 under the hood regardless */ driftClientAccountSubscriber?: new ( - program: Program, + program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[], diff --git a/sdk/src/events/fetchLogs.ts b/sdk/src/events/fetchLogs.ts index fa01d645ce..d8d7980fce 100644 --- a/sdk/src/events/fetchLogs.ts +++ b/sdk/src/events/fetchLogs.ts @@ -1,4 +1,4 @@ -import { Program } from '@coral-xyz/anchor'; +import { Program } from '@coral-xyz/anchor-29'; import { Connection, Finality, diff --git a/sdk/src/events/parse.ts b/sdk/src/events/parse.ts index 96223134e3..9bc4849e6b 100644 --- a/sdk/src/events/parse.ts +++ b/sdk/src/events/parse.ts @@ -1,4 +1,4 @@ -import { Program, Event } from '@coral-xyz/anchor'; +import { Program, Event } from '@coral-xyz/anchor-29'; import { CuUsageEvent } from './types'; const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH'; diff --git a/sdk/src/factory/oracleClient.ts b/sdk/src/factory/oracleClient.ts index c1e777c6bb..492edcfcfc 100644 --- a/sdk/src/factory/oracleClient.ts +++ b/sdk/src/factory/oracleClient.ts @@ -10,11 +10,12 @@ import { SwitchboardClient } from '../oracles/switchboardClient'; import { PythPullClient } from '../oracles/pythPullClient'; import { SwitchboardOnDemandClient } from '../oracles/switchboardOnDemandClient'; import { PythLazerClient } from '../oracles/pythLazerClient'; +import { Drift } from '../idl/drift'; export function getOracleClient( oracleSource: OracleSource, connection: Connection, - program: Program + program: Program ): OracleClient { if (isVariant(oracleSource, 'pyth')) { return new PythClient(connection); diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index fcd488872b..41ed94abba 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -1,1801 +1,2693 @@ { - "version": "2.150.0", - "name": "drift", + "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH", + "metadata": { + "name": "drift", + "version": "2.151.0", + "spec": "0.1.0", + "description": "Created with Anchor" + }, "instructions": [ { - "name": "initializeUser", + "name": "add_amm_constituent_mapping_data", + "discriminator": [ + 164, + 236, + 130, + 40, + 118, + 179, + 46, + 235 + ], "accounts": [ { - "name": "user", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "amm_constituent_mapping", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 65, + 77, + 77, + 95, + 77, + 65, + 80 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "constituent_target_base", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "subAccountId", - "type": "u16" - }, - { - "name": "name", + "name": "amm_constituent_mapping_data", "type": { - "array": [ - "u8", - 32 - ] + "vec": { + "defined": { + "name": "AddAmmConstituentMappingDatum" + } + } } } ] }, { - "name": "initializeUserStats", + "name": "add_insurance_fund_stake", + "discriminator": [ + 251, + 144, + 115, + 11, + 222, + 47, + 62, + 236 + ], "accounts": [ { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "insurance_fund_stake", + "writable": true }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "user_stats", + "writable": true }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true, + "relations": [ + "insurance_fund_stake", + "user_stats" + ] }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "initializeSignedMsgUserOrders", - "accounts": [ - { - "name": "signedMsgUserOrders", - "isMut": true, - "isSigner": false + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "drift_signer" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "user_token_account", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "numOrders", + "name": "market_index", "type": "u16" + }, + { + "name": "amount", + "type": "u64" } ] }, { - "name": "resizeSignedMsgUserOrders", + "name": "add_market_to_amm_cache", + "discriminator": [ + 112, + 149, + 195, + 222, + 124, + 7, + 87, + 237 + ], "accounts": [ { - "name": "signedMsgUserOrders", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": false, - "isSigner": false + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "perp_market" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" + }, { - "name": "numOrders", - "type": "u16" + "name": "system_program", + "address": "11111111111111111111111111111111" } - ] + ], + "args": [] }, { - "name": "initializeSignedMsgWsDelegates", + "name": "admin_deposit", + "discriminator": [ + 210, + 66, + 65, + 182, + 102, + 214, + 176, + 30 + ], "accounts": [ { - "name": "signedMsgWsDelegates", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "authority", - "isMut": true, - "isSigner": true + "name": "user", + "writable": true }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "admin_token_account", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "delegates", - "type": { - "vec": "publicKey" - } + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", + "type": "u64" } ] }, { - "name": "changeSignedMsgWsDelegateStatus", + "name": "admin_update_user_stats_paused_operations", + "discriminator": [ + 183, + 104, + 63, + 150, + 240, + 199, + 3, + 10 + ], "accounts": [ { - "name": "signedMsgWsDelegates", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true }, { - "name": "authority", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "delegate", - "type": "publicKey" - }, - { - "name": "add", - "type": "bool" + "name": "paused_operations", + "type": "u8" } ] }, { - "name": "initializeFuelOverflow", + "name": "begin_insurance_fund_swap", + "discriminator": [ + 176, + 69, + 143, + 205, + 32, + 132, + 163, + 0 + ], "accounts": [ { - "name": "fuelOverflow", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "authority", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "out_insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "in_insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "out_token_account", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "sweepFuel", - "accounts": [ + "name": "in_token_account", + "writable": true + }, { - "name": "fuelOverflow", - "isMut": true, - "isSigner": false + "name": "if_rebalance_config", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "token_program" }, { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "drift_signer" }, { - "name": "signer", - "isMut": false, - "isSigner": true + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], - "args": [] - }, - { - "name": "resetFuelSeason", - "accounts": [ - { - "name": "userStats", - "isMut": true, - "isSigner": false - }, + "args": [ { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "in_market_index", + "type": "u16" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "out_market_index", + "type": "u16" }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "amount_in", + "type": "u64" } - ], - "args": [] + ] }, { - "name": "initializeReferrerName", + "name": "begin_lp_swap", + "discriminator": [ + 64, + 44, + 24, + 199, + 48, + 125, + 67, + 91 + ], "accounts": [ { - "name": "referrerName", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "signer_out_token_account", + "docs": [ + "Signer token accounts" + ], + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "signer_in_token_account", + "writable": true }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "constituent_out_token_account", + "docs": [ + "Constituent token accounts" + ], + "writable": true }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "constituent_in_token_account", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ - { - "name": "name", - "type": { - "array": [ - "u8", - 32 + "name": "out_constituent", + "docs": [ + "Constituents" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } ] } - } - ] - }, - { - "name": "deposit", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "user", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "in_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "marketIndex", + "name": "in_market_index", "type": "u16" }, { - "name": "amount", - "type": "u64" + "name": "out_market_index", + "type": "u16" }, { - "name": "reduceOnly", - "type": "bool" + "name": "amount_in", + "type": "u64" } ] }, { - "name": "withdraw", + "name": "begin_swap", + "discriminator": [ + 174, + 109, + 228, + 1, + 242, + 105, + 232, + 105 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true + }, + { + "name": "out_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } + }, + { + "name": "in_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } + }, + { + "name": "out_token_account", + "writable": true }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "in_token_account", + "writable": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "token_program" }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "in_market_index", "type": "u16" }, { - "name": "amount", - "type": "u64" + "name": "out_market_index", + "type": "u16" }, { - "name": "reduceOnly", - "type": "bool" + "name": "amount_in", + "type": "u64" } ] }, { - "name": "transferDeposit", + "name": "cancel_order", + "discriminator": [ + 95, + 129, + 237, + 240, + 8, + 49, + 223, + 132 + ], "accounts": [ { - "name": "fromUser", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "toUser", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarketVault", - "isMut": false, - "isSigner": false + "signer": true } ], "args": [ { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "amount", - "type": "u64" + "name": "order_id", + "type": { + "option": "u32" + } } ] }, { - "name": "transferPools", + "name": "cancel_order_by_user_id", + "discriminator": [ + 107, + 211, + 250, + 133, + 18, + 37, + 57, + 100 + ], "accounts": [ { - "name": "fromUser", - "isMut": true, - "isSigner": false - }, - { - "name": "toUser", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "depositFromSpotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "depositToSpotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "borrowFromSpotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "borrowToSpotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "signer": true } ], "args": [ { - "name": "depositFromMarketIndex", - "type": "u16" - }, - { - "name": "depositToMarketIndex", - "type": "u16" - }, - { - "name": "borrowFromMarketIndex", - "type": "u16" - }, - { - "name": "borrowToMarketIndex", - "type": "u16" - }, - { - "name": "depositAmount", - "type": { - "option": "u64" - } - }, - { - "name": "borrowAmount", - "type": { - "option": "u64" - } + "name": "user_order_id", + "type": "u8" } ] }, { - "name": "transferPerpPosition", + "name": "cancel_orders", + "discriminator": [ + 238, + 225, + 95, + 158, + 227, + 103, + 8, + 194 + ], "accounts": [ { - "name": "fromUser", - "isMut": true, - "isSigner": false - }, - { - "name": "toUser", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "signer": true } ], "args": [ { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "amount", + "name": "market_type", "type": { - "option": "i64" + "option": { + "defined": { + "name": "MarketType" + } + } } - } - ] - }, - { - "name": "placePerpOrder", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "market_index", + "type": { + "option": "u16" + } }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "params", + "name": "direction", "type": { - "defined": "OrderParams" + "option": { + "defined": { + "name": "PositionDirection" + } + } } } ] }, { - "name": "cancelOrder", + "name": "cancel_orders_by_ids", + "discriminator": [ + 134, + 19, + 144, + 165, + 94, + 240, + 210, + 94 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true } ], "args": [ { - "name": "orderId", + "name": "order_ids", "type": { - "option": "u32" + "vec": "u32" } } ] }, { - "name": "cancelOrderByUserId", + "name": "cancel_request_remove_insurance_fund_stake", + "discriminator": [ + 97, + 235, + 78, + 62, + 212, + 42, + 241, + 127 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "insurance_fund_stake", + "writable": true + }, + { + "name": "user_stats", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "insurance_fund_stake", + "user_stats" + ] + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } } ], "args": [ { - "name": "userOrderId", - "type": "u8" + "name": "market_index", + "type": "u16" } ] }, { - "name": "cancelOrders", + "name": "change_approved_builder", + "discriminator": [ + 179, + 134, + 211, + 45, + 195, + 5, + 189, + 173 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "escrow", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 82, + 69, + 86, + 95, + 69, + 83, + 67, + 82, + 79, + 87 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true, + "relations": [ + "escrow" + ] }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketType", - "type": { - "option": { - "defined": "MarketType" - } - } + "name": "builder", + "type": "pubkey" }, { - "name": "marketIndex", - "type": { - "option": "u16" - } + "name": "max_fee_bps", + "type": "u16" }, { - "name": "direction", - "type": { - "option": { - "defined": "PositionDirection" - } - } + "name": "add", + "type": "bool" } ] }, { - "name": "cancelOrdersByIds", + "name": "change_signed_msg_ws_delegate_status", + "discriminator": [ + 252, + 202, + 252, + 219, + 179, + 27, + 84, + 138 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "signed_msg_ws_delegates", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71, + 95, + 87, + 83 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "authority", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "orderIds", - "type": { - "vec": "u32" - } + "name": "delegate", + "type": "pubkey" + }, + { + "name": "add", + "type": "bool" } ] }, { - "name": "modifyOrder", + "name": "delete_amm_cache", + "discriminator": [ + 216, + 130, + 215, + 206, + 233, + 232, + 191, + 88 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "user", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "orderId", - "type": { - "option": "u32" - } + "name": "state" }, { - "name": "modifyOrderParams", - "type": { - "defined": "ModifyOrderParams" + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] } } - ] + ], + "args": [] }, { - "name": "modifyOrderByUserId", + "name": "delete_initialized_perp_market", + "discriminator": [ + 91, + 154, + 24, + 87, + 106, + 59, + 190, + 66 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "userOrderId", - "type": "u8" - }, - { - "name": "modifyOrderParams", - "type": { - "defined": "ModifyOrderParams" - } + "name": "market_index", + "type": "u16" } ] }, { - "name": "placeAndTakePerpOrder", + "name": "delete_initialized_spot_market", + "discriminator": [ + 31, + 140, + 67, + 191, + 189, + 20, + 101, + 221 + ], "accounts": [ + { + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] + }, { "name": "state", - "isMut": false, - "isSigner": false + "writable": true }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "token_program" } ], "args": [ { - "name": "params", - "type": { - "defined": "OrderParams" - } - }, - { - "name": "successCondition", - "type": { - "option": "u32" - } + "name": "market_index", + "type": "u16" } ] }, { - "name": "placeAndMakePerpOrder", + "name": "delete_prelaunch_oracle", + "discriminator": [ + 59, + 169, + 100, + 49, + 69, + 17, + 173, + 253 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "user", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "taker", - "isMut": true, - "isSigner": false + "name": "prelaunch_oracle", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101 + ] + }, + { + "kind": "arg", + "path": "perp_market_index" + } + ] + } }, { - "name": "takerStats", - "isMut": true, - "isSigner": false + "name": "perp_market" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state" } ], "args": [ { - "name": "params", - "type": { - "defined": "OrderParams" - } - }, - { - "name": "takerOrderId", - "type": "u32" + "name": "perp_market_index", + "type": "u16" } ] }, { - "name": "placeAndMakeSignedMsgPerpOrder", + "name": "delete_signed_msg_user_orders", + "discriminator": [ + 221, + 247, + 128, + 253, + 212, + 254, + 46, + 153 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "signed_msg_user_orders", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false - }, + "name": "authority", + "signer": true + } + ], + "args": [] + }, + { + "name": "delete_user", + "discriminator": [ + 186, + 85, + 17, + 249, + 219, + 231, + 98, + 251 + ], + "accounts": [ { - "name": "taker", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "takerStats", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "takerSignedMsgUserOrders", - "isMut": false, - "isSigner": false + "name": "state", + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true, + "relations": [ + "user", + "user_stats" + ] } ], - "args": [ - { - "name": "params", - "type": { - "defined": "OrderParams" - } - }, - { - "name": "signedMsgOrderUuid", - "type": { - "array": [ - "u8", - 8 - ] - } - } - ] + "args": [] }, { - "name": "placeSignedMsgTakerOrder", + "name": "deposit", + "discriminator": [ + 242, + 35, + 198, + 137, + 82, + 225, + 242, + 182 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "signedMsgUserOrders", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "ixSysvar", - "isMut": false, - "isSigner": false, - "docs": [ - "the supplied Sysvar could be anything else.", - "The Instruction Sysvar has not been implemented", - "in the Anchor framework yet, so this is the safe approach." - ] + "name": "user_token_account", + "writable": true + }, + { + "name": "token_program" } ], "args": [ { - "name": "signedMsgOrderParamsMessageBytes", - "type": "bytes" + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", + "type": "u64" }, { - "name": "isDelegateSigner", + "name": "reduce_only", "type": "bool" } ] }, { - "name": "placeSpotOrder", + "name": "deposit_into_insurance_fund_stake", + "discriminator": [ + 4, + 22, + 226, + 201, + 124, + 44, + 82, + 230 + ], "accounts": [ + { + "name": "signer", + "signer": true + }, { "name": "state", - "isMut": false, - "isSigner": false + "writable": true }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ + "name": "insurance_fund_stake", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 115, + 116, + 97, + 107, + 101 + ] + }, + { + "kind": "account", + "path": "user_stats" + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, { - "name": "params", - "type": { - "defined": "OrderParams" + "name": "user_stats", + "writable": true + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] } - } - ] - }, - { - "name": "placeAndTakeSpotOrder", - "accounts": [ + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "user_token_account", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "token_program" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "drift_signer" } ], "args": [ { - "name": "params", - "type": { - "defined": "OrderParams" - } - }, - { - "name": "fulfillmentType", - "type": { - "option": { - "defined": "SpotFulfillmentType" - } - } + "name": "market_index", + "type": "u16" }, { - "name": "makerOrderId", - "type": { - "option": "u32" - } + "name": "amount", + "type": "u64" } ] }, { - "name": "placeAndMakeSpotOrder", + "name": "deposit_into_perp_market_fee_pool", + "discriminator": [ + 34, + 58, + 57, + 68, + 97, + 80, + 244, + 6 + ], "accounts": [ { "name": "state", - "isMut": false, - "isSigner": false + "writable": true }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "taker", - "isMut": true, - "isSigner": false + "name": "source_vault", + "writable": true }, { - "name": "takerStats", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "params", - "type": { - "defined": "OrderParams" + "name": "quote_spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] } }, { - "name": "takerOrderId", - "type": "u32" - }, - { - "name": "fulfillmentType", - "type": { - "option": { - "defined": "SpotFulfillmentType" - } + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] } - } - ] - }, - { - "name": "placeOrders", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false }, { - "name": "user", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "token_program" } ], "args": [ { - "name": "params", - "type": { - "vec": { - "defined": "OrderParams" - } - } + "name": "amount", + "type": "u64" } ] }, { - "name": "beginSwap", + "name": "deposit_into_spot_market_revenue_pool", + "discriminator": [ + 92, + 40, + 151, + 42, + 122, + 254, + 139, + 246 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "authority", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "spot_market" + } + ] + } }, { - "name": "outSpotMarketVault", - "isMut": true, - "isSigner": false + "name": "user_token_account", + "writable": true }, { - "name": "inSpotMarketVault", - "isMut": true, - "isSigner": false + "name": "token_program" + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "deposit_into_spot_market_vault", + "discriminator": [ + 48, + 252, + 119, + 73, + 255, + 205, + 174, + 247 + ], + "accounts": [ + { + "name": "state" }, { - "name": "outTokenAccount", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true }, { - "name": "inTokenAccount", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "source_vault", + "writable": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "spot_market_vault", + "writable": true }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] + "name": "token_program" } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, - { - "name": "outMarketIndex", - "type": "u16" - }, - { - "name": "amountIn", + "name": "amount", "type": "u64" } ] }, { - "name": "endSwap", + "name": "deposit_to_program_vault", + "discriminator": [ + 235, + 171, + 121, + 80, + 57, + 239, + 147, + 220 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userStats", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "admin", + "writable": true, + "signer": true }, { - "name": "outSpotMarketVault", - "isMut": true, - "isSigner": false + "name": "constituent", + "writable": true }, { - "name": "inSpotMarketVault", - "isMut": true, - "isSigner": false + "name": "constituent_token_account", + "writable": true }, { - "name": "outTokenAccount", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true }, { - "name": "inTokenAccount", - "isMut": true, - "isSigner": false + "name": "spot_market_vault", + "writable": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "token_program" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "mint" }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] + "name": "oracle" } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "disable_user_high_leverage_mode", + "discriminator": [ + 183, + 155, + 45, + 0, + 226, + 85, + 213, + 69 + ], + "accounts": [ + { + "name": "state" }, { - "name": "outMarketIndex", - "type": "u16" + "name": "authority", + "signer": true }, { - "name": "limitPrice", - "type": { - "option": "u64" - } + "name": "user", + "writable": true }, { - "name": "reduceOnly", - "type": { - "option": { - "defined": "SwapReduceOnly" - } - } + "name": "high_leverage_mode_config", + "writable": true + } + ], + "args": [ + { + "name": "disable_maintenance", + "type": "bool" } ] }, { - "name": "updateUserName", + "name": "enable_user_high_leverage_mode", + "discriminator": [ + 231, + 24, + 230, + 112, + 201, + 173, + 73, + 184 + ], "accounts": [ + { + "name": "state" + }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true + }, + { + "name": "high_leverage_mode_config", + "writable": true } ], "args": [ { - "name": "subAccountId", + "name": "sub_account_id", "type": "u16" - }, - { - "name": "name", - "type": { - "array": [ - "u8", - 32 - ] - } } ] }, { - "name": "updateUserCustomMarginRatio", + "name": "end_insurance_fund_swap", + "discriminator": [ + 206, + 230, + 98, + 8, + 249, + 158, + 169, + 167 + ], "accounts": [ { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state" }, { "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "subAccountId", - "type": "u16" + "writable": true, + "signer": true }, { - "name": "marginRatio", - "type": "u32" - } - ] - }, - { - "name": "updateUserPerpPositionCustomMarginRatio", - "accounts": [ - { - "name": "user", - "isMut": true, - "isSigner": false + "name": "out_insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "subAccountId", - "type": "u16" + "name": "in_insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "perpMarketIndex", - "type": "u16" + "name": "out_token_account", + "writable": true }, { - "name": "marginRatio", - "type": "u16" - } - ] - }, - { - "name": "updateUserMarginTradingEnabled", - "accounts": [ - { - "name": "user", - "isMut": true, - "isSigner": false + "name": "in_token_account", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "subAccountId", - "type": "u16" + "name": "if_rebalance_config", + "writable": true }, { - "name": "marginTradingEnabled", - "type": "bool" - } - ] - }, - { - "name": "updateUserPoolId", - "accounts": [ + "name": "token_program" + }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], "args": [ { - "name": "subAccountId", + "name": "in_market_index", "type": "u16" }, { - "name": "poolId", - "type": "u8" + "name": "out_market_index", + "type": "u16" } ] }, { - "name": "updateUserDelegate", + "name": "end_lp_swap", + "discriminator": [ + 99, + 125, + 214, + 165, + 129, + 175, + 253, + 135 + ], "accounts": [ { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ - { - "name": "subAccountId", - "type": "u16" + "name": "admin", + "writable": true, + "signer": true }, { - "name": "delegate", - "type": "publicKey" - } - ] - }, - { - "name": "updateUserReduceOnly", - "accounts": [ + "name": "signer_out_token_account", + "docs": [ + "Signer token accounts" + ], + "writable": true + }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "signer_in_token_account", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [ + "name": "constituent_out_token_account", + "docs": [ + "Constituent token accounts" + ], + "writable": true + }, { - "name": "subAccountId", - "type": "u16" + "name": "constituent_in_token_account", + "writable": true }, { - "name": "reduceOnly", - "type": "bool" - } - ] - }, - { - "name": "updateUserProtectedMakerOrders", - "accounts": [ + "name": "out_constituent", + "docs": [ + "Constituents" + ], + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "in_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" }, { - "name": "protectedMakerModeConfig", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "subAccountId", + "name": "_in_market_index", "type": "u16" }, { - "name": "protectedMakerOrders", - "type": "bool" + "name": "_out_market_index", + "type": "u16" } ] }, { - "name": "deleteUser", - "accounts": [ - { - "name": "user", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false - }, - { - "name": "state", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": true, - "isSigner": true - } + "name": "end_swap", + "discriminator": [ + 177, + 184, + 27, + 193, + 34, + 13, + 210, + 145 ], - "args": [] - }, - { - "name": "forceDeleteUser", "accounts": [ { - "name": "user", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { "name": "authority", - "isMut": true, - "isSigner": false + "signer": true }, { - "name": "keeper", - "isMut": true, - "isSigner": true - }, - { - "name": "driftSigner", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "deleteSignedMsgUserOrders", - "accounts": [ - { - "name": "signedMsgUserOrders", - "isMut": true, - "isSigner": false + "name": "out_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "in_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [] - }, - { - "name": "reclaimRent", - "accounts": [ - { - "name": "user", - "isMut": true, - "isSigner": false + "name": "out_token_account", + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "in_token_account", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "token_program" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "drift_signer" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], - "args": [] - }, - { - "name": "enableUserHighLeverageMode", - "accounts": [ + "args": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "in_market_index", + "type": "u16" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "out_market_index", + "type": "u16" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "limit_price", + "type": { + "option": "u64" + } }, { - "name": "highLeverageModeConfig", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "subAccountId", - "type": "u16" + "name": "reduce_only", + "type": { + "option": { + "defined": { + "name": "SwapReduceOnly" + } + } + } } ] }, { - "name": "fillPerpOrder", + "name": "fill_perp_order", + "discriminator": [ + 13, + 188, + 248, + 103, + 134, + 217, + 106, + 240 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "filler", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "fillerStats", - "isMut": true, - "isSigner": false + "name": "filler_stats", + "writable": true }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "orderId", + "name": "order_id", "type": { "option": "u32" } }, { - "name": "makerOrderId", + "name": "_maker_order_id", "type": { "option": "u32" } @@ -1803,82 +2695,61 @@ ] }, { - "name": "revertFill", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "filler", - "isMut": true, - "isSigner": false - }, - { - "name": "fillerStats", - "isMut": true, - "isSigner": false - } + "name": "fill_spot_order", + "discriminator": [ + 212, + 206, + 130, + 173, + 21, + 34, + 199, + 40 ], - "args": [] - }, - { - "name": "fillSpotOrder", "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "filler", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "fillerStats", - "isMut": true, - "isSigner": false + "name": "filler_stats", + "writable": true }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "orderId", + "name": "order_id", "type": { "option": "u32" } }, { - "name": "fulfillmentType", + "name": "fulfillment_type", "type": { "option": { - "defined": "SpotFulfillmentType" + "defined": { + "name": "SpotFulfillmentType" + } } } }, { - "name": "makerOrderId", + "name": "maker_order_id", "type": { "option": "u32" } @@ -1886,8476 +2757,13848 @@ ] }, { - "name": "triggerOrder", + "name": "force_cancel_orders", + "discriminator": [ + 64, + 181, + 196, + 63, + 222, + 72, + 64, + 232 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "authority", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "filler", - "isMut": true, - "isSigner": false + "writable": true }, { "name": "user", - "isMut": true, - "isSigner": false + "writable": true } ], - "args": [ - { - "name": "orderId", - "type": "u32" - } - ] + "args": [] }, { - "name": "forceCancelOrders", + "name": "force_delete_user", + "discriminator": [ + 2, + 241, + 195, + 172, + 227, + 24, + 254, + 158 + ], "accounts": [ + { + "name": "user", + "writable": true + }, + { + "name": "user_stats", + "writable": true + }, { "name": "state", - "isMut": false, - "isSigner": false + "writable": true }, { "name": "authority", - "isMut": false, - "isSigner": true + "writable": true, + "relations": [ + "user", + "user_stats" + ] }, { - "name": "filler", - "isMut": true, - "isSigner": false + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "drift_signer" } ], "args": [] }, { - "name": "updateUserIdle", + "name": "initialize", + "discriminator": [ + 175, + 175, + 109, + 31, + 13, + 152, + 155, + 237 + ], "accounts": [ + { + "name": "admin", + "writable": true, + "signer": true + }, { "name": "state", - "isMut": false, - "isSigner": false + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 100, + 114, + 105, + 102, + 116, + 95, + 115, + 116, + 97, + 116, + 101 + ] + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "quote_asset_mint" }, { - "name": "filler", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "user", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "logUserBalances", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "system_program", + "address": "11111111111111111111111111111111" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [] }, { - "name": "disableUserHighLeverageMode", + "name": "initialize_amm_cache", + "discriminator": [ + 38, + 60, + 171, + 158, + 203, + 58, + 137, + 8 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } }, { - "name": "highLeverageModeConfig", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" + }, { - "name": "disableMaintenance", - "type": "bool" + "name": "system_program", + "address": "11111111111111111111111111111111" } - ] + ], + "args": [] }, { - "name": "updateUserStatsReferrerStatus", + "name": "initialize_constituent", + "discriminator": [ + 12, + 196, + 45, + 218, + 93, + 89, + 0, + 33 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "admin", + "writable": true, + "signer": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "adminUpdateUserStatsPausedOperations", - "accounts": [ + "name": "lp_pool", + "writable": true + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "constituent_target_base", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "constituent_correlations", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } + }, { - "name": "pausedOperations", - "type": "u8" - } - ] - }, - { - "name": "settlePnl", - "accounts": [ + "name": "spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market_mint" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "constituent_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" }, { - "name": "spotMarketVault", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "marketIndex", + "name": "spot_market_index", "type": "u16" - } - ] - }, - { - "name": "settleMultiplePnls", - "accounts": [ + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "decimals", + "type": "u8" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "max_weight_deviation", + "type": "i64" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "swap_fee_min", + "type": "i64" }, { - "name": "spotMarketVault", - "isMut": false, - "isSigner": false - } - ], - "args": [ + "name": "swap_fee_max", + "type": "i64" + }, { - "name": "marketIndexes", - "type": { - "vec": "u16" - } + "name": "max_borrow_token_amount", + "type": "u64" }, { - "name": "mode", + "name": "oracle_staleness_threshold", + "type": "u64" + }, + { + "name": "cost_to_trade", + "type": "i32" + }, + { + "name": "constituent_derivative_index", "type": { - "defined": "SettlePnlMode" + "option": "i16" } - } - ] - }, - { - "name": "settleFundingPayment", - "accounts": [ + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "constituent_derivative_depeg_threshold", + "type": "u64" }, { - "name": "user", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "settleExpiredMarket", - "accounts": [ + "name": "derivative_weight", + "type": "u64" + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "volatility", + "type": "u64" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "gamma_execution", + "type": "u8" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "gamma_inventory", + "type": "u8" + }, { - "name": "marketIndex", - "type": "u16" + "name": "xi", + "type": "u8" + }, + { + "name": "new_constituent_correlations", + "type": { + "vec": "i64" + } } ] }, { - "name": "liquidatePerp", + "name": "initialize_fuel_overflow", + "discriminator": [ + 88, + 223, + 132, + 161, + 208, + 88, + 142, + 42 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "fuel_overflow", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 102, + 117, + 101, + 108, + 95, + 111, + 118, + 101, + 114, + 102, + 108, + 111, + 119 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "user_stats", + "writable": true }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "authority", + "relations": [ + "user_stats" + ] }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], - "args": [ - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "liquidatorMaxBaseAssetAmount", - "type": "u64" - }, - { - "name": "limitPrice", - "type": { - "option": "u64" - } - } - ] + "args": [] }, { - "name": "liquidatePerpWithFill", + "name": "initialize_high_leverage_mode_config", + "discriminator": [ + 213, + 167, + 93, + 246, + 208, + 130, + 90, + 248 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "high_leverage_mode_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 104, + 105, + 103, + 104, + 95, + 108, + 101, + 118, + 101, + 114, + 97, + 103, + 101, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + } + ] + } }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "max_users", + "type": "u32" } ] }, { - "name": "liquidateSpot", + "name": "initialize_if_rebalance_config", + "discriminator": [ + 8, + 85, + 184, + 167, + 176, + 61, + 173, + 226 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "if_rebalance_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 102, + 95, + 114, + 101, + 98, + 97, + 108, + 97, + 110, + 99, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + }, + { + "kind": "arg", + "path": "params.in_market_index" + }, + { + "kind": "arg", + "path": "params.out_market_index" + } + ] + } }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "assetMarketIndex", - "type": "u16" - }, - { - "name": "liabilityMarketIndex", - "type": "u16" - }, - { - "name": "liquidatorMaxLiabilityTransfer", - "type": "u128" - }, - { - "name": "limitPrice", + "name": "params", "type": { - "option": "u64" + "defined": { + "name": "IfRebalanceConfigParams" + } } } ] }, { - "name": "liquidateSpotWithSwapBegin", + "name": "initialize_insurance_fund_stake", + "discriminator": [ + 187, + 179, + 243, + 70, + 248, + 90, + 92, + 147 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "insurance_fund_stake", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 115, + 116, + 97, + 107, + 101 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true, + "relations": [ + "user_stats" + ] }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true }, { - "name": "liabilitySpotMarketVault", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "assetSpotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "liabilityTokenAccount", - "isMut": true, - "isSigner": false - }, - { - "name": "assetTokenAccount", - "isMut": true, - "isSigner": false - }, - { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - }, - { - "name": "driftSigner", - "isMut": false, - "isSigner": false - }, - { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "assetMarketIndex", - "type": "u16" - }, - { - "name": "liabilityMarketIndex", + "name": "market_index", "type": "u16" - }, - { - "name": "swapAmount", - "type": "u64" } ] }, { - "name": "liquidateSpotWithSwapEnd", + "name": "initialize_lp_pool", + "discriminator": [ + 242, + 64, + 1, + 222, + 142, + 46, + 204, + 227 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "lp_pool", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 108, + 112, + 95, + 112, + 111, + 111, + 108 + ] + }, + { + "kind": "arg", + "path": "id" + } + ] + } }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "mint" }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "lp_pool_token_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "amm_constituent_mapping", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 65, + 77, + 77, + 95, + 77, + 65, + 80 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "constituent_target_base", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "liabilitySpotMarketVault", - "isMut": true, - "isSigner": false + "name": "constituent_correlations", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "assetSpotMarketVault", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "liabilityTokenAccount", - "isMut": true, - "isSigner": false + "name": "token_program", + "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" }, { - "name": "assetTokenAccount", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "lp_pool_id", + "type": "u8" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "min_mint_fee", + "type": "i64" }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] - } - ], - "args": [ + "name": "max_aum", + "type": "u128" + }, { - "name": "assetMarketIndex", - "type": "u16" + "name": "max_settle_quote_amount_per_market", + "type": "u64" }, { - "name": "liabilityMarketIndex", - "type": "u16" + "name": "whitelist_mint", + "type": "pubkey" } ] }, { - "name": "liquidateBorrowForPerpPnl", + "name": "initialize_openbook_v2_fulfillment_config", + "discriminator": [ + 7, + 221, + 103, + 153, + 107, + 57, + 27, + 197 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "base_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "quote_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "openbook_v2_program" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "openbook_v2_market" }, { - "name": "userStats", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "drift_signer" + }, { - "name": "perpMarketIndex", - "type": "u16" + "name": "openbook_v2_fulfillment_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 111, + 112, + 101, + 110, + 98, + 111, + 111, + 107, + 95, + 118, + 50, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + }, + { + "kind": "account", + "path": "openbook_v2_market" + } + ] + } }, { - "name": "spotMarketIndex", - "type": "u16" + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "liquidatorMaxLiabilityTransfer", - "type": "u128" + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "limitPrice", - "type": { - "option": "u64" - } + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [ + { + "name": "market_index", + "type": "u16" } ] }, { - "name": "liquidatePerpPnlForDeposit", + "name": "initialize_perp_market", + "discriminator": [ + 132, + 9, + 229, + 118, + 117, + 118, + 117, + 62 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state", + "writable": true }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 101, + 114, + 112, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "account", + "path": "state.number_of_markets", + "account": "State" + } + ] + } }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "oracle" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "perpMarketIndex", + "name": "market_index", "type": "u16" }, { - "name": "spotMarketIndex", - "type": "u16" + "name": "amm_base_asset_reserve", + "type": "u128" }, { - "name": "liquidatorMaxPnlTransfer", + "name": "amm_quote_asset_reserve", "type": "u128" }, { - "name": "limitPrice", - "type": { - "option": "u64" - } - } - ] - }, - { - "name": "setUserStatusToBeingLiquidated", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "amm_periodicity", + "type": "i64" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "amm_peg_multiplier", + "type": "u128" }, { - "name": "authority", - "isMut": false, - "isSigner": true - } - ], - "args": [] - }, - { - "name": "resolvePerpPnlDeficit", - "accounts": [ + "name": "oracle_source", + "type": { + "defined": { + "name": "OracleSource" + } + } + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "contract_tier", + "type": { + "defined": { + "name": "ContractTier" + } + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "margin_ratio_initial", + "type": "u32" }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "margin_ratio_maintenance", + "type": "u32" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "liquidator_fee", + "type": "u32" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "if_liquidation_fee", + "type": "u32" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ + "name": "imf_factor", + "type": "u32" + }, { - "name": "spotMarketIndex", - "type": "u16" + "name": "active_status", + "type": "bool" }, { - "name": "perpMarketIndex", - "type": "u16" - } - ] - }, - { - "name": "resolvePerpBankruptcy", - "accounts": [ + "name": "base_spread", + "type": "u32" + }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "max_spread", + "type": "u32" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "max_open_interest", + "type": "u128" }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "max_revenue_withdraw_per_period", + "type": "u64" }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "quote_max_insurance", + "type": "u64" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "order_step_size", + "type": "u64" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "order_tick_size", + "type": "u64" }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "min_order_size", + "type": "u64" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "concentration_coef_scale", + "type": "u128" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "curve_update_intensity", + "type": "u8" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ + "name": "amm_jit_intensity", + "type": "u8" + }, { - "name": "quoteSpotMarketIndex", - "type": "u16" + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } }, { - "name": "marketIndex", - "type": "u16" + "name": "lp_pool_id", + "type": "u8" } ] }, { - "name": "resolveSpotBankruptcy", + "name": "initialize_phoenix_fulfillment_config", + "discriminator": [ + 135, + 132, + 110, + 107, + 185, + 160, + 169, + 154 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "base_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "quote_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "liquidator", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "liquidatorStats", - "isMut": true, - "isSigner": false + "name": "phoenix_program" }, { - "name": "user", - "isMut": true, - "isSigner": false + "name": "phoenix_market" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "phoenix_fulfillment_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 104, + 111, + 101, + 110, + 105, + 120, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + }, + { + "kind": "account", + "path": "phoenix_market" + } + ] + } }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "market_index", "type": "u16" } ] }, { - "name": "settleRevenueToInsuranceFund", + "name": "initialize_prediction_market", + "discriminator": [ + 248, + 70, + 198, + 224, + 224, + 105, + 125, + 195 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false - }, - { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], - "args": [ - { - "name": "spotMarketIndex", - "type": "u16" - } - ] + "args": [] }, { - "name": "updateFundingRate", + "name": "initialize_prelaunch_oracle", + "discriminator": [ + 169, + 178, + 84, + 25, + 175, + 62, + 29, + 247 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - }, + "name": "prelaunch_oracle", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101 + ] + }, + { + "kind": "arg", + "path": "params.perp_market_index" + } + ] + } + }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "state" + }, + { + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "params", + "type": { + "defined": { + "name": "PrelaunchOracleParams" + } + } } ] }, { - "name": "updatePrelaunchOracle", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": false, - "isSigner": false - }, - { - "name": "oracle", - "isMut": true, - "isSigner": false - } + "name": "initialize_protected_maker_mode_config", + "discriminator": [ + 67, + 103, + 220, + 67, + 88, + 32, + 252, + 8 ], - "args": [] - }, - { - "name": "updatePerpBidAskTwap", "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "protected_maker_mode_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 114, + 111, + 116, + 101, + 99, + 116, + 101, + 100, + 95, + 109, + 97, + 107, + 101, + 114, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + } + ] + } }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "keeperStats", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "system_program", + "address": "11111111111111111111111111111111" } ], - "args": [] + "args": [ + { + "name": "max_users", + "type": "u32" + } + ] }, { - "name": "updateSpotMarketCumulativeInterest", + "name": "initialize_pyth_lazer_oracle", + "discriminator": [ + 140, + 107, + 33, + 214, + 235, + 219, + 103, + 20 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "lazer_oracle", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 121, + 116, + 104, + 95, + 108, + 97, + 122, + 101, + 114 + ] + }, + { + "kind": "arg", + "path": "feed_id" + } + ] + } }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "spotMarketVault", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "updateAmms", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndexes", - "type": { - "vec": "u16" - } + "name": "feed_id", + "type": "u32" } ] }, { - "name": "updateSpotMarketExpiry", + "name": "initialize_pyth_pull_oracle", + "discriminator": [ + 249, + 140, + 253, + 243, + 248, + 74, + 240, + 238 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "pyth_solana_receiver", + "address": "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha" + }, + { + "name": "price_feed", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 121, + 116, + 104, + 95, + 112, + 117, + 108, + 108 + ] + }, + { + "kind": "arg", + "path": "feed_id" + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" + }, + { + "name": "state" } ], "args": [ { - "name": "expiryTs", - "type": "i64" + "name": "feed_id", + "type": { + "array": [ + "u8", + 32 + ] + } } ] }, { - "name": "updateUserQuoteAssetInsuranceStake", + "name": "initialize_referrer_name", + "discriminator": [ + 235, + 126, + 231, + 10, + 42, + 164, + 26, + 61 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false - }, - { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false - }, - { - "name": "userStats", - "isMut": true, - "isSigner": false - }, - { - "name": "signer", - "isMut": false, - "isSigner": true + "name": "referrer_name", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 114, + 101, + 102, + 101, + 114, + 114, + 101, + 114, + 95, + 110, + 97, + 109, + 101 + ] + }, + { + "kind": "arg", + "path": "name" + } + ] + } }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "updateUserGovTokenInsuranceStake", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true }, { - "name": "signer", - "isMut": false, - "isSigner": true + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], - "args": [] + "args": [ + { + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } + } + ] }, { - "name": "updateDelegateUserGovTokenInsuranceStake", + "name": "initialize_revenue_share", + "discriminator": [ + 57, + 9, + 123, + 131, + 82, + 52, + 50, + 13 + ], "accounts": [ { - "name": "spotMarket", - "isMut": true, - "isSigner": false - }, - { - "name": "insuranceFundStake", - "isMut": false, - "isSigner": false + "name": "revenue_share", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 82, + 69, + 86, + 95, + 83, + 72, + 65, + 82, + 69 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "authority" }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "payer", + "writable": true, + "signer": true }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [] }, { - "name": "initializeInsuranceFundStake", + "name": "initialize_revenue_share_escrow", + "discriminator": [ + 187, + 18, + 123, + 88, + 238, + 104, + 84, + 154 + ], "accounts": [ { - "name": "spotMarket", - "isMut": false, - "isSigner": false - }, - { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "escrow", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 82, + 69, + 86, + 95, + 69, + 83, + 67, + 82, + 79, + 87 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "authority", + "relations": [ + "user_stats" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state" }, { "name": "payer", - "isMut": true, - "isSigner": true + "writable": true, + "signer": true }, { "name": "rent", - "isMut": false, - "isSigner": false + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "num_orders", "type": "u16" } ] }, { - "name": "addInsuranceFundStake", + "name": "initialize_serum_fulfillment_config", + "discriminator": [ + 193, + 211, + 132, + 172, + 70, + 171, + 7, + 94 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "base_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "quote_spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "serum_program" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "serum_market" }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "serum_open_orders", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 101, + 114, + 117, + 109, + 95, + 111, + 112, + 101, + 110, + 95, + 111, + 114, + 100, + 101, + 114, + 115 + ] + }, + { + "kind": "account", + "path": "serum_market" + } + ] + } }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "serum_fulfillment_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 101, + 114, + 117, + 109, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + }, + { + "kind": "account", + "path": "serum_market" + } + ] + } }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "market_index", "type": "u16" - }, - { - "name": "amount", - "type": "u64" } ] }, { - "name": "requestRemoveInsuranceFundStake", + "name": "initialize_signed_msg_user_orders", + "discriminator": [ + 164, + 99, + 156, + 126, + 156, + 57, + 99, + 180 + ], "accounts": [ { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "signed_msg_user_orders", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "authority" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "num_orders", "type": "u16" - }, - { - "name": "amount", - "type": "u64" } ] }, { - "name": "cancelRequestRemoveInsuranceFundStake", + "name": "initialize_signed_msg_ws_delegates", + "discriminator": [ + 40, + 132, + 96, + 219, + 184, + 193, + 80, + 8 + ], "accounts": [ { - "name": "spotMarket", - "isMut": true, - "isSigner": false - }, - { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "signed_msg_ws_delegates", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71, + 95, + 87, + 83 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "authority", + "writable": true, + "signer": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "delegates", + "type": { + "vec": "pubkey" + } } ] }, { - "name": "removeInsuranceFundStake", + "name": "initialize_spot_market", + "discriminator": [ + 234, + 196, + 128, + 44, + 94, + 15, + 48, + 201 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "account", + "path": "state.number_of_spot_markets", + "account": "State" + } + ] + } + }, + { + "name": "spot_market_mint" + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "state.number_of_spot_markets", + "account": "State" + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "state.number_of_spot_markets", + "account": "State" + } + ] + } }, { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "oracle" }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "marketIndex", - "type": "u16" - } - ] - }, - { - "name": "beginInsuranceFundSwap", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": true, - "isSigner": true - }, - { - "name": "outInsuranceFundVault", - "isMut": true, - "isSigner": false - }, - { - "name": "inInsuranceFundVault", - "isMut": true, - "isSigner": false + "name": "optimal_utilization", + "type": "u32" }, { - "name": "outTokenAccount", - "isMut": true, - "isSigner": false + "name": "optimal_borrow_rate", + "type": "u32" }, { - "name": "inTokenAccount", - "isMut": true, - "isSigner": false + "name": "max_borrow_rate", + "type": "u32" }, { - "name": "ifRebalanceConfig", - "isMut": true, - "isSigner": false + "name": "oracle_source", + "type": { + "defined": { + "name": "OracleSource" + } + } }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "initial_asset_weight", + "type": "u32" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "maintenance_asset_weight", + "type": "u32" }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] - } - ], - "args": [ - { - "name": "inMarketIndex", - "type": "u16" + "name": "initial_liability_weight", + "type": "u32" }, { - "name": "outMarketIndex", - "type": "u16" + "name": "maintenance_liability_weight", + "type": "u32" }, { - "name": "amountIn", - "type": "u64" - } - ] - }, - { - "name": "endInsuranceFundSwap", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "imf_factor", + "type": "u32" }, { - "name": "authority", - "isMut": true, - "isSigner": true + "name": "liquidator_fee", + "type": "u32" }, { - "name": "outInsuranceFundVault", - "isMut": true, - "isSigner": false + "name": "if_liquidation_fee", + "type": "u32" }, { - "name": "inInsuranceFundVault", - "isMut": true, - "isSigner": false + "name": "active_status", + "type": "bool" }, { - "name": "outTokenAccount", - "isMut": true, - "isSigner": false + "name": "asset_tier", + "type": { + "defined": { + "name": "AssetTier" + } + } }, { - "name": "inTokenAccount", - "isMut": true, - "isSigner": false + "name": "scale_initial_asset_weight_start", + "type": "u64" }, { - "name": "ifRebalanceConfig", - "isMut": true, - "isSigner": false + "name": "withdraw_guard_threshold", + "type": "u64" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "order_tick_size", + "type": "u64" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "order_step_size", + "type": "u64" }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] - } - ], - "args": [ - { - "name": "inMarketIndex", - "type": "u16" + "name": "if_total_factor", + "type": "u32" }, { - "name": "outMarketIndex", - "type": "u16" + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } } ] }, { - "name": "transferProtocolIfSharesToRevenuePool", + "name": "initialize_user", + "discriminator": [ + 111, + 17, + 185, + 250, + 60, + 122, + 38, + 254 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } }, { - "name": "authority", - "isMut": true, - "isSigner": true + "name": "user_stats", + "writable": true }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "state", + "writable": true }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true, + "relations": [ + "user_stats" + ] }, { - "name": "ifRebalanceConfig", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marketIndex", + "name": "sub_account_id", "type": "u16" }, { - "name": "amount", - "type": "u64" + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } } ] }, { - "name": "depositIntoInsuranceFundStake", + "name": "initialize_user_stats", + "discriminator": [ + 254, + 243, + 72, + 98, + 251, + 130, + 168, + 213 + ], "accounts": [ { - "name": "signer", - "isMut": false, - "isSigner": true + "name": "user_stats", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114, + 95, + 115, + 116, + 97, + 116, + 115 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true + }, + { + "name": "payer", + "writable": true, + "signer": true }, { - "name": "insuranceFundStake", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" + } + ], + "args": [] + }, + { + "name": "liquidate_borrow_for_perp_pnl", + "discriminator": [ + 169, + 17, + 32, + 90, + 207, + 148, + 209, + 27 + ], + "accounts": [ + { + "name": "state" }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "liquidator", + "writable": true }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "liquidator_stats", + "writable": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "marketIndex", + "name": "perp_market_index", "type": "u16" }, { - "name": "amount", - "type": "u64" + "name": "spot_market_index", + "type": "u16" + }, + { + "name": "liquidator_max_liability_transfer", + "type": "u128" + }, + { + "name": "limit_price", + "type": { + "option": "u64" + } } ] }, { - "name": "updatePythPullOracle", + "name": "liquidate_perp", + "discriminator": [ + 75, + 35, + 119, + 247, + 191, + 18, + 139, + 2 + ], "accounts": [ { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "state" + }, + { + "name": "authority", + "signer": true }, { - "name": "pythSolanaReceiver", - "isMut": false, - "isSigner": false + "name": "liquidator", + "writable": true + }, + { + "name": "liquidator_stats", + "writable": true }, { - "name": "encodedVaa", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "priceFeed", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "feedId", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "market_index", + "type": "u16" }, { - "name": "params", - "type": "bytes" + "name": "liquidator_max_base_asset_amount", + "type": "u64" + }, + { + "name": "limit_price", + "type": { + "option": "u64" + } } ] }, { - "name": "postPythPullOracleUpdateAtomic", + "name": "liquidate_perp_pnl_for_deposit", + "discriminator": [ + 237, + 75, + 198, + 235, + 233, + 186, + 75, + 35 + ], "accounts": [ { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "state" + }, + { + "name": "authority", + "signer": true }, { - "name": "pythSolanaReceiver", - "isMut": false, - "isSigner": false + "name": "liquidator", + "writable": true + }, + { + "name": "liquidator_stats", + "writable": true }, { - "name": "guardianSet", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "priceFeed", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "feedId", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "perp_market_index", + "type": "u16" }, { - "name": "params", - "type": "bytes" + "name": "spot_market_index", + "type": "u16" + }, + { + "name": "liquidator_max_pnl_transfer", + "type": "u128" + }, + { + "name": "limit_price", + "type": { + "option": "u64" + } } ] }, { - "name": "postMultiPythPullOracleUpdatesAtomic", + "name": "liquidate_perp_with_fill", + "discriminator": [ + 95, + 111, + 124, + 105, + 86, + 169, + 187, + 34 + ], "accounts": [ { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "state" + }, + { + "name": "authority", + "signer": true + }, + { + "name": "liquidator", + "writable": true + }, + { + "name": "liquidator_stats", + "writable": true }, { - "name": "pythSolanaReceiver", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "guardianSet", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true } ], "args": [ { - "name": "params", - "type": "bytes" + "name": "market_index", + "type": "u16" } ] }, { - "name": "pauseSpotMarketDepositWithdraw", + "name": "liquidate_spot", + "discriminator": [ + 107, + 0, + 128, + 41, + 35, + 229, + 251, + 18 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "keeper", - "isMut": false, - "isSigner": true + "name": "authority", + "signer": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "liquidator", + "writable": true }, { - "name": "spotMarketVault", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "initialize", - "accounts": [ - { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "liquidator_stats", + "writable": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "quoteAssetMint", - "isMut": false, - "isSigner": false - }, + "name": "user_stats", + "writable": true + } + ], + "args": [ { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "asset_market_index", + "type": "u16" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "liability_market_index", + "type": "u16" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "liquidator_max_liability_transfer", + "type": "u128" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "limit_price", + "type": { + "option": "u64" + } } - ], - "args": [] + ] }, { - "name": "initializeSpotMarket", + "name": "liquidate_spot_with_swap_begin", + "discriminator": [ + 12, + 43, + 176, + 83, + 156, + 251, + 117, + 13 + ], "accounts": [ { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "spotMarketMint", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "liquidator", + "writable": true }, { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "liquidator_stats", + "writable": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "liability_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "liability_market_index" + } + ] + } }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "asset_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "asset_market_index" + } + ] + } }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "liability_token_account", + "writable": true + }, + { + "name": "asset_token_account", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "token_program" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "drift_signer" + }, + { + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], "args": [ { - "name": "optimalUtilization", - "type": "u32" + "name": "asset_market_index", + "type": "u16" }, { - "name": "optimalBorrowRate", - "type": "u32" - }, - { - "name": "maxBorrowRate", - "type": "u32" - }, - { - "name": "oracleSource", - "type": { - "defined": "OracleSource" - } + "name": "liability_market_index", + "type": "u16" }, { - "name": "initialAssetWeight", - "type": "u32" - }, + "name": "swap_amount", + "type": "u64" + } + ] + }, + { + "name": "liquidate_spot_with_swap_end", + "discriminator": [ + 142, + 88, + 163, + 160, + 223, + 75, + 55, + 225 + ], + "accounts": [ { - "name": "maintenanceAssetWeight", - "type": "u32" + "name": "state" }, { - "name": "initialLiabilityWeight", - "type": "u32" + "name": "authority", + "signer": true }, { - "name": "maintenanceLiabilityWeight", - "type": "u32" + "name": "liquidator", + "writable": true }, { - "name": "imfFactor", - "type": "u32" + "name": "liquidator_stats", + "writable": true }, { - "name": "liquidatorFee", - "type": "u32" + "name": "user", + "writable": true }, { - "name": "ifLiquidationFee", - "type": "u32" + "name": "user_stats", + "writable": true }, { - "name": "activeStatus", - "type": "bool" + "name": "liability_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "liability_market_index" + } + ] + } }, { - "name": "assetTier", - "type": { - "defined": "AssetTier" + "name": "asset_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "asset_market_index" + } + ] } }, { - "name": "scaleInitialAssetWeightStart", - "type": "u64" + "name": "liability_token_account", + "writable": true }, { - "name": "withdrawGuardThreshold", - "type": "u64" + "name": "asset_token_account", + "writable": true }, { - "name": "orderTickSize", - "type": "u64" + "name": "token_program" }, { - "name": "orderStepSize", - "type": "u64" + "name": "drift_signer" }, { - "name": "ifTotalFactor", - "type": "u32" + "name": "instructions", + "docs": [ + "Instructions Sysvar for instruction introspection" + ], + "address": "Sysvar1nstructions1111111111111111111111111" + } + ], + "args": [ + { + "name": "asset_market_index", + "type": "u16" }, { - "name": "name", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "liability_market_index", + "type": "u16" } ] }, { - "name": "deleteInitializedSpotMarket", + "name": "log_user_balances", + "discriminator": [ + 162, + 21, + 35, + 251, + 32, + 57, + 161, + 210 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "state", - "isMut": true, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false - }, - { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false - }, - { - "name": "insuranceFundVault", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true } ], - "args": [ - { - "name": "marketIndex", - "type": "u16" - } - ] + "args": [] }, { - "name": "initializeSerumFulfillmentConfig", + "name": "lp_pool_add_liquidity", + "discriminator": [ + 49, + 135, + 246, + 103, + 93, + 146, + 220, + 141 + ], "accounts": [ { - "name": "baseSpotMarket", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "quoteSpotMarket", - "isMut": false, - "isSigner": false + "name": "lp_pool", + "writable": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true + }, + { + "name": "in_market_mint" }, { - "name": "serumProgram", - "isMut": false, - "isSigner": false + "name": "in_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "serumMarket", - "isMut": false, - "isSigner": false + "name": "user_in_token_account", + "writable": true }, { - "name": "serumOpenOrders", - "isMut": true, - "isSigner": false + "name": "constituent_in_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "user_lp_token_account", + "writable": true }, { - "name": "serumFulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "lp_mint", + "writable": true }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "constituent_target_base" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "lp_pool_token_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "marketIndex", + "name": "in_market_index", "type": "u16" + }, + { + "name": "in_amount", + "type": "u128" + }, + { + "name": "min_mint_amount", + "type": "u64" } ] }, { - "name": "updateSerumFulfillmentConfigStatus", + "name": "lp_pool_remove_liquidity", + "discriminator": [ + 164, + 36, + 193, + 252, + 196, + 157, + 138, + 43 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "serumFulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "admin", - "isMut": true, - "isSigner": true - } - ], - "args": [ + "name": "lp_pool", + "writable": true + }, { - "name": "status", - "type": { - "defined": "SpotFulfillmentConfigStatus" - } - } - ] - }, - { - "name": "initializeOpenbookV2FulfillmentConfig", - "accounts": [ + "name": "authority", + "signer": true + }, { - "name": "baseSpotMarket", - "isMut": false, - "isSigner": false + "name": "out_market_mint" }, { - "name": "quoteSpotMarket", - "isMut": false, - "isSigner": false + "name": "out_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user_out_token_account", + "writable": true }, { - "name": "openbookV2Program", - "isMut": false, - "isSigner": false + "name": "constituent_out_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "openbookV2Market", - "isMut": false, - "isSigner": false + "name": "user_lp_token_account", + "writable": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "spot_market_token_account", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "openbookV2FulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "lp_mint", + "writable": true }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "constituent_target_base" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "lp_pool_token_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } + }, + { + "name": "token_program" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "amm_cache", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } } ], "args": [ { - "name": "marketIndex", + "name": "in_market_index", "type": "u16" + }, + { + "name": "in_amount", + "type": "u64" + }, + { + "name": "min_out_amount", + "type": "u128" } ] }, { - "name": "openbookV2FulfillmentConfigStatus", + "name": "lp_pool_swap", + "discriminator": [ + 36, + 161, + 39, + 49, + 227, + 1, + 35, + 226 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "openbookV2FulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "admin", - "isMut": true, - "isSigner": true - } - ], - "args": [ + "name": "constituent_target_base" + }, { - "name": "status", - "type": { - "defined": "SpotFulfillmentConfigStatus" - } - } - ] - }, - { - "name": "initializePhoenixFulfillmentConfig", - "accounts": [ + "name": "constituent_correlations" + }, { - "name": "baseSpotMarket", - "isMut": false, - "isSigner": false + "name": "constituent_in_token_account", + "writable": true }, { - "name": "quoteSpotMarket", - "isMut": false, - "isSigner": false + "name": "constituent_out_token_account", + "writable": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user_in_token_account", + "writable": true }, { - "name": "phoenixProgram", - "isMut": false, - "isSigner": false + "name": "user_out_token_account", + "writable": true }, { - "name": "phoenixMarket", - "isMut": false, - "isSigner": false + "name": "in_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "out_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } }, { - "name": "phoenixFulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "in_market_mint" }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "out_market_mint" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "marketIndex", + "name": "in_market_index", + "type": "u16" + }, + { + "name": "out_market_index", "type": "u16" + }, + { + "name": "in_amount", + "type": "u64" + }, + { + "name": "min_out_amount", + "type": "u64" } ] }, { - "name": "phoenixFulfillmentConfigStatus", + "name": "modify_order", + "discriminator": [ + 47, + 124, + 117, + 255, + 201, + 197, + 130, + 94 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "phoenixFulfillmentConfig", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "authority", + "signer": true } ], "args": [ { - "name": "status", + "name": "order_id", + "type": { + "option": "u32" + } + }, + { + "name": "modify_order_params", "type": { - "defined": "SpotFulfillmentConfigStatus" + "defined": { + "name": "ModifyOrderParams" + } } } ] }, { - "name": "initializePerpMarket", + "name": "modify_order_by_user_id", + "discriminator": [ + 158, + 77, + 4, + 253, + 252, + 194, + 161, + 179 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true + } + ], + "args": [ + { + "name": "user_order_id", + "type": "u8" }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "modify_order_params", + "type": { + "defined": { + "name": "ModifyOrderParams" + } + } + } + ] + }, + { + "name": "move_amm_price", + "discriminator": [ + 235, + 109, + 2, + 82, + 219, + 118, + 6, + 159 + ], + "accounts": [ + { + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "base_asset_reserve", + "type": "u128" }, { - "name": "ammBaseAssetReserve", + "name": "quote_asset_reserve", "type": "u128" }, { - "name": "ammQuoteAssetReserve", + "name": "sqrt_k", "type": "u128" - }, + } + ] + }, + { + "name": "openbook_v2_fulfillment_config_status", + "discriminator": [ + 25, + 173, + 19, + 189, + 4, + 211, + 64, + 238 + ], + "accounts": [ { - "name": "ammPeriodicity", - "type": "i64" + "name": "state" }, { - "name": "ammPegMultiplier", - "type": "u128" + "name": "openbook_v2_fulfillment_config", + "writable": true }, { - "name": "oracleSource", - "type": { - "defined": "OracleSource" - } - }, + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] + } + ], + "args": [ { - "name": "contractTier", + "name": "status", "type": { - "defined": "ContractTier" + "defined": { + "name": "SpotFulfillmentConfigStatus" + } } - }, + } + ] + }, + { + "name": "override_amm_cache_info", + "discriminator": [ + 189, + 198, + 128, + 9, + 49, + 145, + 201, + 115 + ], + "accounts": [ { - "name": "marginRatioInitial", - "type": "u32" + "name": "state", + "writable": true }, { - "name": "marginRatioMaintenance", - "type": "u32" + "name": "admin", + "signer": true }, { - "name": "liquidatorFee", - "type": "u32" - }, + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } + } + ], + "args": [ { - "name": "ifLiquidationFee", - "type": "u32" + "name": "market_index", + "type": "u16" }, { - "name": "imfFactor", - "type": "u32" - }, + "name": "override_params", + "type": { + "defined": { + "name": "OverrideAmmCacheParams" + } + } + } + ] + }, + { + "name": "pause_spot_market_deposit_withdraw", + "discriminator": [ + 183, + 119, + 59, + 170, + 137, + 35, + 242, + 86 + ], + "accounts": [ { - "name": "activeStatus", - "type": "bool" + "name": "state" }, { - "name": "baseSpread", - "type": "u32" + "name": "keeper", + "signer": true }, { - "name": "maxSpread", - "type": "u32" + "name": "spot_market", + "writable": true }, { - "name": "maxOpenInterest", - "type": "u128" - }, + "name": "spot_market_vault", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "spot_market" + } + ] + } + } + ], + "args": [] + }, + { + "name": "phoenix_fulfillment_config_status", + "discriminator": [ + 96, + 31, + 113, + 32, + 12, + 203, + 7, + 154 + ], + "accounts": [ { - "name": "maxRevenueWithdrawPerPeriod", - "type": "u64" + "name": "state" }, { - "name": "quoteMaxInsurance", - "type": "u64" + "name": "phoenix_fulfillment_config", + "writable": true }, { - "name": "orderStepSize", - "type": "u64" - }, + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] + } + ], + "args": [ { - "name": "orderTickSize", - "type": "u64" + "name": "status", + "type": { + "defined": { + "name": "SpotFulfillmentConfigStatus" + } + } + } + ] + }, + { + "name": "place_and_make_perp_order", + "discriminator": [ + 149, + 117, + 11, + 237, + 47, + 95, + 89, + 237 + ], + "accounts": [ + { + "name": "state" }, { - "name": "minOrderSize", - "type": "u64" + "name": "user", + "writable": true }, { - "name": "concentrationCoefScale", - "type": "u128" + "name": "user_stats", + "writable": true }, { - "name": "curveUpdateIntensity", - "type": "u8" + "name": "taker", + "writable": true }, { - "name": "ammJitIntensity", - "type": "u8" + "name": "taker_stats", + "writable": true }, { - "name": "name", + "name": "authority", + "signer": true + } + ], + "args": [ + { + "name": "params", "type": { - "array": [ - "u8", - 32 - ] + "defined": { + "name": "OrderParams" + } } }, { - "name": "lpPoolId", - "type": "u8" + "name": "taker_order_id", + "type": "u32" } ] }, { - "name": "initializeAmmCache", + "name": "place_and_make_signed_msg_perp_order", + "discriminator": [ + 16, + 26, + 123, + 131, + 94, + 29, + 175, + 98 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "addMarketToAmmCache", - "accounts": [ - { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "taker", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "taker_stats", + "writable": true }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "taker_signed_msg_user_orders", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71 + ] + }, + { + "kind": "account", + "path": "taker" + } + ] + } }, { - "name": "perpMarket", - "isMut": false, - "isSigner": false - }, + "name": "authority", + "signer": true + } + ], + "args": [ { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "params", + "type": { + "defined": { + "name": "OrderParams" + } + } }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "signed_msg_order_uuid", + "type": { + "array": [ + "u8", + 8 + ] + } } - ], - "args": [] + ] }, { - "name": "deleteAmmCache", + "name": "place_and_make_spot_order", + "discriminator": [ + 149, + 158, + 85, + 66, + 239, + 9, + 243, + 98 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "ammCache", - "isMut": true, - "isSigner": false - } - ], - "args": [] - }, - { - "name": "updateInitialAmmCacheInfo", - "accounts": [ + "name": "user_stats", + "writable": true + }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "taker", + "writable": true }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "taker_stats", + "writable": true }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], - "args": [] - }, - { - "name": "initializePredictionMarket", - "accounts": [ + "args": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "params", + "type": { + "defined": { + "name": "OrderParams" + } + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "taker_order_id", + "type": "u32" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "fulfillment_type", + "type": { + "option": { + "defined": { + "name": "SpotFulfillmentType" + } + } + } } - ], - "args": [] + ] }, { - "name": "deleteInitializedPerpMarket", + "name": "place_and_take_perp_order", + "discriminator": [ + 213, + 51, + 1, + 187, + 108, + 220, + 230, + 224 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true + }, + { + "name": "user_stats", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "params", + "type": { + "defined": { + "name": "OrderParams" + } + } + }, + { + "name": "success_condition", + "type": { + "option": "u32" + } } ] }, { - "name": "moveAmmPrice", + "name": "place_and_take_spot_order", + "discriminator": [ + 191, + 3, + 138, + 71, + 114, + 198, + 202, + 100 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true + }, + { + "name": "user_stats", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "baseAssetReserve", - "type": "u128" + "name": "params", + "type": { + "defined": { + "name": "OrderParams" + } + } }, { - "name": "quoteAssetReserve", - "type": "u128" + "name": "fulfillment_type", + "type": { + "option": { + "defined": { + "name": "SpotFulfillmentType" + } + } + } }, { - "name": "sqrtK", - "type": "u128" + "name": "maker_order_id", + "type": { + "option": "u32" + } } ] }, { - "name": "recenterPerpMarketAmm", + "name": "place_orders", + "discriminator": [ + 60, + 63, + 50, + 123, + 12, + 197, + 60, + 190 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "pegMultiplier", - "type": "u128" - }, - { - "name": "sqrtK", - "type": "u128" + "name": "params", + "type": { + "vec": { + "defined": { + "name": "OrderParams" + } + } + } } ] }, { - "name": "recenterPerpMarketAmmCrank", + "name": "place_perp_order", + "discriminator": [ + 69, + 161, + 93, + 202, + 120, + 126, + 76, + 185 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "spotMarket", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "depth", + "name": "params", "type": { - "option": "u128" + "defined": { + "name": "OrderParams" + } } } ] }, { - "name": "updatePerpMarketAmmSummaryStats", + "name": "place_signed_msg_taker_order", + "discriminator": [ + 32, + 79, + 101, + 139, + 25, + 6, + 98, + 15 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true + }, + { + "name": "user_stats", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "signed_msg_user_orders", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71 + ] + }, + { + "kind": "account", + "path": "user" + } + ] + } }, { - "name": "spotMarket", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "ix_sysvar", + "docs": [ + "the supplied Sysvar could be anything else.", + "The Instruction Sysvar has not been implemented", + "in the Anchor framework yet, so this is the safe approach." + ], + "address": "Sysvar1nstructions1111111111111111111111111" } ], "args": [ { - "name": "params", - "type": { - "defined": "UpdatePerpMarketSummaryStatsParams" - } + "name": "signed_msg_order_params_message_bytes", + "type": "bytes" + }, + { + "name": "is_delegate_signer", + "type": "bool" } ] }, { - "name": "updatePerpMarketExpiry", + "name": "place_spot_order", + "discriminator": [ + 45, + 79, + 81, + 160, + 248, + 90, + 91, + 220 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "expiryTs", - "type": "i64" + "name": "params", + "type": { + "defined": { + "name": "OrderParams" + } + } } ] }, { - "name": "updatePerpMarketLpPoolPausedOperations", + "name": "post_multi_pyth_pull_oracle_updates_atomic", + "discriminator": [ + 243, + 79, + 204, + 228, + 227, + 208, + 100, + 244 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "pyth_solana_receiver", + "address": "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "guardian_set" } ], "args": [ { - "name": "lpPausedOperations", - "type": "u8" + "name": "params", + "type": "bytes" } ] }, { - "name": "updatePerpMarketLpPoolStatus", + "name": "post_pyth_lazer_oracle_update", + "discriminator": [ + 218, + 237, + 170, + 245, + 39, + 143, + 166, + 33 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "pyth_lazer_storage", + "address": "3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL" }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "ix_sysvar", + "address": "Sysvar1nstructions1111111111111111111111111" } ], "args": [ { - "name": "lpStatus", - "type": "u8" + "name": "pyth_message", + "type": "bytes" } ] }, { - "name": "updatePerpMarketLpPoolFeeTransferScalar", + "name": "post_pyth_pull_oracle_update_atomic", + "discriminator": [ + 116, + 122, + 137, + 158, + 224, + 195, + 173, + 119 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "pyth_solana_receiver", + "address": "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "guardian_set" + }, + { + "name": "price_feed", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 121, + 116, + 104, + 95, + 112, + 117, + 108, + 108 + ] + }, + { + "kind": "arg", + "path": "feed_id" + } + ] + } } ], "args": [ { - "name": "optionalLpFeeTransferScalar", + "name": "feed_id", "type": { - "option": "u8" + "array": [ + "u8", + 32 + ] } }, { - "name": "optionalLpNetPnlTransferScalar", - "type": { - "option": "u8" - } + "name": "params", + "type": "bytes" } ] }, { - "name": "settleExpiredMarketPoolsToRevenuePool", + "name": "recenter_perp_market_amm", + "discriminator": [ + 24, + 87, + 10, + 115, + 165, + 190, + 80, + 139 + ], "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], - "args": [] - }, - { - "name": "depositIntoPerpMarketFeePool", - "accounts": [ + "args": [ { - "name": "state", - "isMut": true, - "isSigner": false + "name": "peg_multiplier", + "type": "u128" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - }, + "name": "sqrt_k", + "type": "u128" + } + ] + }, + { + "name": "recenter_perp_market_amm_crank", + "discriminator": [ + 166, + 19, + 64, + 10, + 14, + 51, + 101, + 122 + ], + "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "sourceVault", - "isMut": true, - "isSigner": false + "signer": true }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "quoteSpotMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "account", + "path": "perp_market" + } + ] + } }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "oracle" } ], "args": [ { - "name": "amount", - "type": "u64" + "name": "depth", + "type": { + "option": "u128" + } } ] }, { - "name": "updatePerpMarketPnlPool", + "name": "reclaim_rent", + "discriminator": [ + 218, + 200, + 19, + 197, + 227, + 89, + 192, + 22 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "user_stats", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true, + "relations": [ + "user", + "user_stats" + ] }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "rent", + "address": "SysvarRent111111111111111111111111111111111" } ], - "args": [ - { - "name": "amount", - "type": "u64" - } - ] + "args": [] }, { - "name": "depositIntoSpotMarketVault", + "name": "remove_amm_constituent_mapping_data", + "discriminator": [ + 20, + 183, + 211, + 162, + 16, + 52, + 229, + 115 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "lp_pool" }, { - "name": "sourceVault", - "isMut": true, - "isSigner": false + "name": "amm_constituent_mapping", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 65, + 77, + 77, + 95, + 77, + 65, + 80 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "amount", - "type": "u64" + "name": "perp_market_index", + "type": "u16" + }, + { + "name": "constituent_index", + "type": "u16" } ] }, { - "name": "depositIntoSpotMarketRevenuePool", + "name": "remove_insurance_fund_stake", + "discriminator": [ + 128, + 166, + 142, + 9, + 254, + 187, + 143, + 174 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" + }, + { + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "insurance_fund_stake", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { "name": "authority", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "insurance_fund_stake", + "user_stats" + ] + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "drift_signer" }, { - "name": "userTokenAccount", - "isMut": true, - "isSigner": false + "name": "user_token_account", + "writable": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "amount", - "type": "u64" + "name": "market_index", + "type": "u16" } ] }, { - "name": "repegAmmCurve", + "name": "repeg_amm_curve", + "discriminator": [ + 3, + 36, + 102, + 89, + 180, + 128, + 120, + 213 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "oracle" }, { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] } ], "args": [ { - "name": "newPegCandidate", + "name": "new_peg_candidate", "type": "u128" } ] }, { - "name": "updatePerpMarketAmmOracleTwap", + "name": "request_remove_insurance_fund_stake", + "discriminator": [ + 142, + 70, + 204, + 92, + 73, + 106, + 180, + 52 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "insurance_fund_stake", + "writable": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "authority", + "signer": true, + "relations": [ + "insurance_fund_stake", + "user_stats" + ] + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } } ], - "args": [] + "args": [ + { + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", + "type": "u64" + } + ] }, { - "name": "resetPerpMarketAmmOracleTwap", + "name": "reset_fuel_season", + "discriminator": [ + 199, + 122, + 192, + 255, + 32, + 99, + 63, + 200 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "relations": [ + "user_stats" + ] }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "state" }, { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true } ], "args": [] }, { - "name": "updateK", + "name": "reset_perp_market_amm_oracle_twap", + "discriminator": [ + 127, + 10, + 55, + 164, + 123, + 226, + 47, + 24 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "oracle" }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] } ], - "args": [ - { - "name": "sqrtK", - "type": "u128" - } - ] + "args": [] }, { - "name": "updatePerpMarketMarginRatio", + "name": "resize_revenue_share_escrow_orders", + "discriminator": [ + 32, + 124, + 247, + 225, + 151, + 213, + 225, + 38 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "escrow", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 82, + 69, + 86, + 95, + 69, + 83, + 67, + 82, + 79, + 87 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "relations": [ + "escrow" + ] + }, + { + "name": "payer", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marginRatioInitial", - "type": "u32" - }, - { - "name": "marginRatioMaintenance", - "type": "u32" + "name": "num_orders", + "type": "u16" } ] }, { - "name": "updatePerpMarketHighLeverageMarginRatio", + "name": "resize_signed_msg_user_orders", + "discriminator": [ + 137, + 10, + 87, + 150, + 18, + 115, + 79, + 168 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "signed_msg_user_orders", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 83, + 73, + 71, + 78, + 69, + 68, + 95, + 77, + 83, + 71 + ] + }, + { + "kind": "account", + "path": "authority" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "relations": [ + "user" + ] + }, + { + "name": "user" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "system_program", + "address": "11111111111111111111111111111111" } ], "args": [ { - "name": "marginRatioInitial", - "type": "u16" - }, - { - "name": "marginRatioMaintenance", + "name": "num_orders", "type": "u16" } ] }, { - "name": "updatePerpMarketFundingPeriod", + "name": "resolve_perp_bankruptcy", + "discriminator": [ + 224, + 16, + 176, + 214, + 162, + 213, + 183, + 222 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "fundingPeriod", - "type": "i64" - } - ] - }, - { - "name": "updatePerpMarketMaxImbalances", - "accounts": [ - { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "liquidator", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "liquidator_stats", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "unrealizedMaxImbalance", - "type": "u64" + "name": "user", + "writable": true }, { - "name": "maxRevenueWithdrawPerPeriod", - "type": "u64" + "name": "user_stats", + "writable": true }, { - "name": "quoteMaxInsurance", - "type": "u64" - } - ] - }, - { - "name": "updatePerpMarketLiquidationFee", - "accounts": [ + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "drift_signer" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "liquidatorFee", - "type": "u32" + "name": "quote_spot_market_index", + "type": "u16" }, { - "name": "ifLiquidationFee", - "type": "u32" + "name": "market_index", + "type": "u16" } ] }, { - "name": "updatePerpMarketLpPoolId", + "name": "resolve_perp_pnl_deficit", + "discriminator": [ + 168, + 204, + 68, + 150, + 159, + 126, + 95, + 148 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "lpPoolId", - "type": "u8" - } - ] - }, - { - "name": "updateInsuranceFundUnstakingPeriod", - "accounts": [ + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "drift_signer" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "insuranceFundUnstakingPeriod", - "type": "i64" + "name": "spot_market_index", + "type": "u16" + }, + { + "name": "perp_market_index", + "type": "u16" } ] }, { - "name": "updateSpotMarketPoolId", + "name": "resolve_spot_bankruptcy", + "discriminator": [ + 124, + 194, + 240, + 254, + 198, + 213, + 52, + 122 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "poolId", - "type": "u8" - } - ] - }, - { - "name": "updateSpotMarketLiquidationFee", - "accounts": [ - { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "liquidator", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "liquidator_stats", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "user", + "writable": true + }, { - "name": "liquidatorFee", - "type": "u32" + "name": "user_stats", + "writable": true }, { - "name": "ifLiquidationFee", - "type": "u32" - } - ] - }, - { - "name": "updateWithdrawGuardThreshold", - "accounts": [ + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "spot_market_index" + } + ] + } }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "drift_signer" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "withdrawGuardThreshold", - "type": "u64" + "name": "market_index", + "type": "u16" } ] }, { - "name": "updateSpotMarketIfFactor", + "name": "revert_fill", + "discriminator": [ + 236, + 238, + 176, + 69, + 239, + 10, + 181, + 193 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true + }, + { + "name": "filler", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "filler_stats", + "writable": true } ], - "args": [ + "args": [] + }, + { + "name": "set_user_status_to_being_liquidated", + "discriminator": [ + 106, + 133, + 160, + 206, + 193, + 171, + 192, + 194 + ], + "accounts": [ { - "name": "spotMarketIndex", - "type": "u16" + "name": "state" }, { - "name": "userIfFactor", - "type": "u32" + "name": "user", + "writable": true }, { - "name": "totalIfFactor", - "type": "u32" + "name": "authority", + "signer": true } - ] + ], + "args": [] }, { - "name": "updateSpotMarketRevenueSettlePeriod", + "name": "settle_expired_market", + "discriminator": [ + 120, + 89, + 11, + 25, + 122, + 77, + 72, + 193 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "revenueSettlePeriod", - "type": "i64" + "name": "market_index", + "type": "u16" } ] }, { - "name": "updateSpotMarketStatus", + "name": "settle_expired_market_pools_to_revenue_pool", + "discriminator": [ + 55, + 19, + 238, + 169, + 227, + 90, + 200, + 184 + ], "accounts": [ + { + "name": "state" + }, { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], - "args": [ - { - "name": "status", - "type": { - "defined": "MarketStatus" - } - } - ] + "args": [] }, { - "name": "updateSpotMarketPausedOperations", + "name": "settle_funding_payment", + "discriminator": [ + 222, + 90, + 202, + 94, + 28, + 45, + 115, + 183 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true } ], - "args": [ - { - "name": "pausedOperations", - "type": "u8" - } - ] + "args": [] }, { - "name": "updateSpotMarketAssetTier", + "name": "settle_multiple_pnls", + "discriminator": [ + 127, + 66, + 117, + 57, + 40, + 50, + 152, + 127 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true + }, + { + "name": "authority", + "signer": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "spot_market_vault", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } } ], "args": [ { - "name": "assetTier", + "name": "market_indexes", + "type": { + "vec": "u16" + } + }, + { + "name": "mode", "type": { - "defined": "AssetTier" + "defined": { + "name": "SettlePnlMode" + } } } ] }, { - "name": "updateSpotMarketMarginWeights", + "name": "settle_perp_to_lp_pool", + "discriminator": [ + 5, + 98, + 46, + 188, + 10, + 59, + 2, + 249 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "lp_pool", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ - { - "name": "initialAssetWeight", - "type": "u32" + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "maintenanceAssetWeight", - "type": "u32" + "name": "amm_cache", + "writable": true }, { - "name": "initialLiabilityWeight", - "type": "u32" + "name": "quote_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "maintenanceLiabilityWeight", - "type": "u32" + "name": "constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "imfFactor", - "type": "u32" - } - ] - }, - { - "name": "updateSpotMarketBorrowRate", - "accounts": [ + "name": "constituent_quote_token_account", + "writable": true + }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "quote_token_vault", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "token_program" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "drift_signer" } ], - "args": [ + "args": [] + }, + { + "name": "settle_pnl", + "discriminator": [ + 43, + 61, + 234, + 45, + 15, + 95, + 152, + 153 + ], + "accounts": [ { - "name": "optimalUtilization", - "type": "u32" + "name": "state" }, { - "name": "optimalBorrowRate", - "type": "u32" + "name": "user", + "writable": true }, { - "name": "maxBorrowRate", - "type": "u32" + "name": "authority", + "signer": true }, { - "name": "minBorrowRate", - "type": { - "option": "u8" - } + "name": "spot_market_vault", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } + } + ], + "args": [ + { + "name": "market_index", + "type": "u16" } ] }, { - "name": "updateSpotMarketMaxTokenDeposits", + "name": "settle_revenue_to_insurance_fund", + "discriminator": [ + 200, + 120, + 93, + 136, + 69, + 38, + 199, + 159 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "drift_signer" + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "token_program" } ], "args": [ { - "name": "maxTokenDeposits", - "type": "u64" + "name": "spot_market_index", + "type": "u16" } ] }, { - "name": "updateSpotMarketMaxTokenBorrows", + "name": "sweep_fuel", + "discriminator": [ + 175, + 107, + 19, + 56, + 165, + 241, + 43, + 69 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "fuel_overflow", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "authority", + "relations": [ + "fuel_overflow", + "user_stats" + ] + }, { - "name": "maxTokenBorrowsFraction", - "type": "u16" + "name": "signer", + "signer": true } - ] + ], + "args": [] }, { - "name": "updateSpotMarketScaleInitialAssetWeightStart", + "name": "transfer_deposit", + "discriminator": [ + 20, + 20, + 147, + 223, + 41, + 63, + 204, + 111 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "from_user", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "to_user", + "writable": true + }, + { + "name": "user_stats", + "writable": true + }, + { + "name": "authority", + "signer": true, + "relations": [ + "from_user", + "to_user", + "user_stats" + ] + }, + { + "name": "state" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "spot_market_vault", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } } ], "args": [ { - "name": "scaleInitialAssetWeightStart", + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", "type": "u64" } ] }, { - "name": "updateSpotMarketOracle", + "name": "transfer_perp_position", + "discriminator": [ + 23, + 172, + 188, + 168, + 134, + 210, + 3, + 108 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "from_user", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "to_user", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "oldOracle", - "isMut": false, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "oracle", - "type": "publicKey" + "name": "market_index", + "type": "u16" }, { - "name": "oracleSource", + "name": "amount", "type": { - "defined": "OracleSource" + "option": "i64" } - }, - { - "name": "skipInvariantCheck", - "type": "bool" } ] }, { - "name": "updateSpotMarketStepSizeAndTickSize", + "name": "transfer_pools", + "discriminator": [ + 197, + 103, + 154, + 25, + 107, + 90, + 60, + 94 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "from_user", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "to_user", + "writable": true + }, + { + "name": "user_stats", + "writable": true + }, + { + "name": "authority", + "signer": true, + "relations": [ + "from_user", + "to_user", + "user_stats" + ] + }, + { + "name": "state" + }, + { + "name": "deposit_from_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "deposit_from_market_index" + } + ] + } + }, + { + "name": "deposit_to_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "deposit_to_market_index" + } + ] + } + }, + { + "name": "borrow_from_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "borrow_from_market_index" + } + ] + } + }, + { + "name": "borrow_to_spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "borrow_to_market_index" + } + ] + } }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "drift_signer" } ], "args": [ { - "name": "stepSize", - "type": "u64" + "name": "deposit_from_market_index", + "type": "u16" }, { - "name": "tickSize", - "type": "u64" + "name": "deposit_to_market_index", + "type": "u16" + }, + { + "name": "borrow_from_market_index", + "type": "u16" + }, + { + "name": "borrow_to_market_index", + "type": "u16" + }, + { + "name": "deposit_amount", + "type": { + "option": "u64" + } + }, + { + "name": "borrow_amount", + "type": { + "option": "u64" + } } ] }, { - "name": "updateSpotMarketMinOrderSize", + "name": "transfer_protocol_if_shares_to_revenue_pool", + "discriminator": [ + 236, + 136, + 147, + 153, + 146, + 205, + 104, + 29 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "writable": true, + "signer": true + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] + } + }, + { + "name": "if_rebalance_config", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "token_program" + }, + { + "name": "drift_signer" } ], "args": [ { - "name": "orderSize", + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", "type": "u64" } ] }, { - "name": "updateSpotMarketOrdersEnabled", + "name": "trigger_order", + "discriminator": [ + 63, + 112, + 51, + 233, + 232, + 47, + 240, + 199 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true + }, + { + "name": "filler", + "writable": true }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true } ], "args": [ { - "name": "ordersEnabled", - "type": "bool" + "name": "order_id", + "type": "u32" } ] }, { - "name": "updateSpotMarketIfPausedOperations", + "name": "update_admin", + "discriminator": [ + 161, + 176, + 40, + 213, + 60, + 184, + 179, + 228 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "pausedOperations", - "type": "u8" + "name": "admin", + "type": "pubkey" } ] }, { - "name": "updateSpotMarketName", + "name": "update_amm_cache", + "discriminator": [ + 88, + 4, + 63, + 94, + 83, + 224, + 255, + 130 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "amm_cache", + "writable": true + }, { - "name": "name", - "type": { - "array": [ - "u8", - 32 + "name": "quote_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } ] } } - ] + ], + "args": [] }, { - "name": "updatePerpMarketStatus", + "name": "update_amm_constituent_mapping_data", + "discriminator": [ + 84, + 70, + 33, + 167, + 133, + 107, + 59, + 24 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "lp_pool" + }, + { + "name": "amm_constituent_mapping", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 65, + 77, + 77, + 95, + 77, + 65, + 80 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "system_program", + "address": "11111111111111111111111111111111" + }, + { + "name": "state" } ], "args": [ { - "name": "status", + "name": "amm_constituent_mapping_data", "type": { - "defined": "MarketStatus" + "vec": { + "defined": { + "name": "AddAmmConstituentMappingDatum" + } + } } } ] }, { - "name": "updatePerpMarketPausedOperations", + "name": "update_amm_jit_intensity", + "discriminator": [ + 181, + 191, + 53, + 109, + 166, + 249, + 55, + 142 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "pausedOperations", + "name": "amm_jit_intensity", "type": "u8" } ] }, { - "name": "updatePerpMarketContractTier", + "name": "update_amms", + "discriminator": [ + 201, + 106, + 217, + 253, + 4, + 175, + 228, + 97 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "contractTier", + "name": "market_indexes", "type": { - "defined": "ContractTier" + "vec": "u16" } } ] }, { - "name": "updatePerpMarketImfFactor", + "name": "update_constituent_correlation_data", + "discriminator": [ + 79, + 14, + 19, + 73, + 221, + 106, + 62, + 109 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "lp_pool" + }, + { + "name": "constituent_correlations", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "imfFactor", - "type": "u32" + "name": "index1", + "type": "u16" }, { - "name": "unrealizedPnlImfFactor", - "type": "u32" - } - ] - }, + "name": "index2", + "type": "u16" + }, + { + "name": "correlation", + "type": "i64" + } + ] + }, { - "name": "updatePerpMarketUnrealizedAssetWeight", + "name": "update_constituent_oracle_info", + "discriminator": [ + 198, + 117, + 231, + 250, + 147, + 33, + 127, + 161 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "constituent", + "writable": true + }, { - "name": "unrealizedInitialAssetWeight", - "type": "u32" + "name": "spot_market" }, { - "name": "unrealizedMaintenanceAssetWeight", - "type": "u32" + "name": "oracle" } - ] + ], + "args": [] }, { - "name": "updatePerpMarketConcentrationCoef", + "name": "update_constituent_params", + "discriminator": [ + 238, + 130, + 122, + 31, + 12, + 104, + 192, + 122 + ], "accounts": [ + { + "name": "lp_pool" + }, + { + "name": "constituent_target_base", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100 + ] + }, + { + "kind": "account", + "path": "lp_pool" + } + ] + } + }, { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "constituent", + "writable": true } ], "args": [ { - "name": "concentrationScale", - "type": "u128" + "name": "constituent_params", + "type": { + "defined": { + "name": "ConstituentParams" + } + } } ] }, { - "name": "updatePerpMarketCurveUpdateIntensity", + "name": "update_constituent_paused_operations", + "discriminator": [ + 185, + 122, + 153, + 191, + 131, + 177, + 132, + 208 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "constituent", + "writable": true } ], "args": [ { - "name": "curveUpdateIntensity", + "name": "paused_operations", "type": "u8" } ] }, { - "name": "updatePerpMarketReferencePriceOffsetDeadbandPct", + "name": "update_constituent_status", + "discriminator": [ + 76, + 159, + 211, + 239, + 182, + 214, + 6, + 15 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "constituent", + "writable": true } ], "args": [ { - "name": "referencePriceOffsetDeadbandPct", + "name": "new_status", "type": "u8" } ] }, { - "name": "updatePerpFeeStructure", + "name": "update_delegate_user_gov_token_insurance_stake", + "discriminator": [ + 241, + 29, + 215, + 228, + 142, + 116, + 22, + 160 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 15, + 0 + ] + } + ] + } }, { - "name": "state", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "insurance_fund_stake" + }, { - "name": "feeStructure", - "type": { - "defined": "FeeStructure" + "name": "user_stats", + "writable": true + }, + { + "name": "admin", + "signer": true, + "relations": [ + "state" + ] + }, + { + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 15, + 0 + ] + } + ] } + }, + { + "name": "state" } - ] + ], + "args": [] }, { - "name": "updateSpotFeeStructure", + "name": "update_discount_mint", + "discriminator": [ + 32, + 252, + 122, + 211, + 66, + 31, + 47, + 241 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "feeStructure", - "type": { - "defined": "FeeStructure" - } + "name": "discount_mint", + "type": "pubkey" } ] }, { - "name": "updateInitialPctToLiquidate", + "name": "update_exchange_status", + "discriminator": [ + 83, + 160, + 252, + 250, + 129, + 116, + 49, + 223 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "initialPctToLiquidate", - "type": "u16" + "name": "exchange_status", + "type": "u8" } ] }, { - "name": "updateLiquidationDuration", + "name": "update_feature_bit_flags_builder_codes", + "discriminator": [ + 1, + 128, + 177, + 51, + 173, + 45, + 11, + 102 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "liquidationDuration", - "type": "u8" + "name": "enable", + "type": "bool" } ] }, { - "name": "updateLiquidationMarginBufferRatio", + "name": "update_feature_bit_flags_median_trigger_price", + "discriminator": [ + 64, + 185, + 221, + 45, + 87, + 147, + 12, + 19 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "liquidationMarginBufferRatio", - "type": "u32" + "name": "enable", + "type": "bool" } ] }, { - "name": "updateOracleGuardRails", + "name": "update_feature_bit_flags_mint_redeem_lp_pool", + "discriminator": [ + 26, + 11, + 142, + 122, + 206, + 159, + 9, + 45 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "oracleGuardRails", - "type": { - "defined": "OracleGuardRails" - } + "name": "enable", + "type": "bool" } ] }, { - "name": "updateStateSettlementDuration", + "name": "update_feature_bit_flags_mm_oracle", + "discriminator": [ + 218, + 134, + 33, + 186, + 231, + 59, + 130, + 149 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "settlementDuration", - "type": "u16" + "name": "enable", + "type": "bool" } ] }, { - "name": "updateStateMaxNumberOfSubAccounts", + "name": "update_feature_bit_flags_settle_lp_pool", + "discriminator": [ + 186, + 28, + 78, + 230, + 155, + 83, + 242, + 26 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "maxNumberOfSubAccounts", - "type": "u16" + "name": "enable", + "type": "bool" } ] }, { - "name": "updateStateMaxInitializeUserFee", + "name": "update_feature_bit_flags_swap_lp_pool", + "discriminator": [ + 83, + 16, + 150, + 12, + 102, + 3, + 22, + 58 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { "name": "state", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "maxInitializeUserFee", - "type": "u16" + "name": "enable", + "type": "bool" } ] }, { - "name": "updatePerpMarketOracle", + "name": "update_funding_rate", + "discriminator": [ + 201, + 178, + 116, + 212, + 166, + 144, + 72, + 238 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "oracle", - "isMut": false, - "isSigner": false - }, - { - "name": "oldOracle", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "oracle" } ], "args": [ { - "name": "oracle", - "type": "publicKey" - }, - { - "name": "oracleSource", - "type": { - "defined": "OracleSource" - } - }, - { - "name": "skipInvariantCheck", - "type": "bool" + "name": "market_index", + "type": "u16" } ] }, { - "name": "updatePerpMarketBaseSpread", + "name": "update_high_leverage_mode_config", + "discriminator": [ + 64, + 122, + 212, + 93, + 141, + 217, + 202, + 55 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "high_leverage_mode_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 104, + 105, + 103, + 104, + 95, + 108, + 101, + 118, + 101, + 114, + 97, + 103, + 101, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + } + ] + } }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "baseSpread", + "name": "max_users", "type": "u32" + }, + { + "name": "reduce_only", + "type": "bool" + }, + { + "name": "current_users", + "type": { + "option": "u32" + } } ] }, { - "name": "updateAmmJitIntensity", + "name": "update_if_rebalance_config", + "discriminator": [ + 142, + 245, + 249, + 66, + 249, + 181, + 22, + 83 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "if_rebalance_config", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "ammJitIntensity", - "type": "u8" + "name": "params", + "type": { + "defined": { + "name": "IfRebalanceConfigParams" + } + } } ] }, { - "name": "updatePerpMarketMaxSpread", + "name": "update_initial_amm_cache_info", + "discriminator": [ + 157, + 210, + 109, + 67, + 212, + 170, + 12, + 107 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } } ], - "args": [ - { - "name": "maxSpread", - "type": "u32" - } - ] + "args": [] }, { - "name": "updatePerpMarketStepSizeAndTickSize", + "name": "update_initial_pct_to_liquidate", + "discriminator": [ + 210, + 133, + 225, + 128, + 194, + 50, + 13, + 109 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "stepSize", - "type": "u64" - }, - { - "name": "tickSize", - "type": "u64" + "name": "initial_pct_to_liquidate", + "type": "u16" } ] }, { - "name": "updatePerpMarketName", + "name": "update_insurance_fund_unstaking_period", + "discriminator": [ + 44, + 69, + 43, + 226, + 204, + 223, + 202, + 52 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "name", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "insurance_fund_unstaking_period", + "type": "i64" } ] }, { - "name": "updatePerpMarketMinOrderSize", + "name": "update_k", + "discriminator": [ + 72, + 98, + 9, + 139, + 129, + 229, + 172, + 56 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "oracle" } ], "args": [ { - "name": "orderSize", - "type": "u64" + "name": "sqrt_k", + "type": "u128" } ] }, { - "name": "updatePerpMarketMaxSlippageRatio", + "name": "update_liquidation_duration", + "discriminator": [ + 28, + 154, + 20, + 249, + 102, + 192, + 73, + 71 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "maxSlippageRatio", - "type": "u16" + "name": "liquidation_duration", + "type": "u8" } ] }, { - "name": "updatePerpMarketMaxFillReserveFraction", + "name": "update_liquidation_margin_buffer_ratio", + "discriminator": [ + 132, + 224, + 243, + 160, + 154, + 82, + 97, + 215 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "maxFillReserveFraction", - "type": "u16" + "name": "liquidation_margin_buffer_ratio", + "type": "u32" } ] }, { - "name": "updatePerpMarketMaxOpenInterest", + "name": "update_lp_constituent_target_base", + "discriminator": [ + 157, + 65, + 50, + 207, + 59, + 236, + 161, + 110 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "amm_constituent_mapping" + }, { - "name": "maxOpenInterest", - "type": "u128" + "name": "constituent_target_base", + "writable": true + }, + { + "name": "amm_cache" + }, + { + "name": "lp_pool" } - ] + ], + "args": [] }, { - "name": "updatePerpMarketNumberOfUsers", + "name": "update_lp_pool_aum", + "discriminator": [ + 88, + 113, + 137, + 206, + 246, + 247, + 171, + 142 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false - } - ], - "args": [ + "name": "lp_pool", + "writable": true + }, { - "name": "numberOfUsers", - "type": { - "option": "u32" - } + "name": "constituent_target_base", + "writable": true }, { - "name": "numberOfUsersWithBase", - "type": { - "option": "u32" - } + "name": "amm_cache", + "writable": true } - ] + ], + "args": [] }, { - "name": "updatePerpMarketFeeAdjustment", + "name": "update_lp_pool_params", + "discriminator": [ + 217, + 92, + 2, + 255, + 27, + 167, + 178, + 81 + ], "accounts": [ { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "lp_pool", + "writable": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "feeAdjustment", - "type": "i16" + "name": "lp_pool_params", + "type": { + "defined": { + "name": "LpPoolParams" + } + } } ] }, { - "name": "updateSpotMarketFeeAdjustment", + "name": "update_oracle_guard_rails", + "discriminator": [ + 131, + 112, + 10, + 59, + 32, + 54, + 40, + 164 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "feeAdjustment", - "type": "i16" + "name": "oracle_guard_rails", + "type": { + "defined": { + "name": "OracleGuardRails" + } + } } ] }, { - "name": "updatePerpMarketProtectedMakerParams", + "name": "update_perp_auction_duration", + "discriminator": [ + 126, + 110, + 52, + 174, + 30, + 206, + 215, + 90 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "protectedMakerLimitPriceDivisor", - "type": { - "option": "u8" - } + "name": "min_perp_auction_duration", + "type": "u8" + } + ] + }, + { + "name": "update_perp_bid_ask_twap", + "discriminator": [ + 247, + 23, + 255, + 65, + 212, + 90, + 221, + 194 + ], + "accounts": [ + { + "name": "state" }, { - "name": "protectedMakerDynamicDivisor", - "type": { - "option": "u8" - } + "name": "perp_market", + "writable": true + }, + { + "name": "oracle" + }, + { + "name": "keeper_stats" + }, + { + "name": "authority", + "signer": true } - ] + ], + "args": [] }, { - "name": "updatePerpMarketOracleLowRiskSlotDelayOverride", + "name": "update_perp_fee_structure", + "discriminator": [ + 23, + 178, + 111, + 203, + 73, + 22, + 140, + 75 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "oracleLowRiskSlotDelayOverride", - "type": "i8" + "name": "fee_structure", + "type": { + "defined": { + "name": "FeeStructure" + } + } } ] }, { - "name": "updatePerpMarketAmmSpreadAdjustment", + "name": "update_perp_market_amm_oracle_twap", + "discriminator": [ + 241, + 74, + 114, + 123, + 206, + 153, + 24, + 202 + ], + "accounts": [ + { + "name": "state" + }, + { + "name": "perp_market", + "writable": true + }, + { + "name": "oracle" + }, + { + "name": "admin", + "signer": true, + "relations": [ + "state" + ] + } + ], + "args": [] + }, + { + "name": "update_perp_market_amm_spread_adjustment", + "discriminator": [ + 155, + 195, + 149, + 43, + 220, + 82, + 173, + 205 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "ammSpreadAdjustment", + "name": "amm_spread_adjustment", "type": "i8" }, { - "name": "ammInventorySpreadAdjustment", + "name": "amm_inventory_spread_adjustment", "type": "i8" }, { - "name": "referencePriceOffset", + "name": "reference_price_offset", "type": "i32" } ] }, { - "name": "updatePerpMarketOracleSlotDelayOverride", + "name": "update_perp_market_amm_summary_stats", + "discriminator": [ + 122, + 101, + 249, + 238, + 209, + 9, + 241, + 245 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true + }, + { + "name": "spot_market", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "account", + "path": "perp_market" + } + ] + } }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "oracle" } ], "args": [ { - "name": "oracleSlotDelayOverride", - "type": "i8" + "name": "params", + "type": { + "defined": { + "name": "UpdatePerpMarketSummaryStatsParams" + } + } } ] }, { - "name": "updateAdmin", + "name": "update_perp_market_base_spread", + "discriminator": [ + 71, + 95, + 84, + 168, + 9, + 157, + 198, + 65 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "admin", - "type": "publicKey" + "name": "base_spread", + "type": "u32" } ] }, { - "name": "updateDiscountMint", + "name": "update_perp_market_concentration_coef", + "discriminator": [ + 24, + 78, + 232, + 126, + 169, + 176, + 230, + 16 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "discountMint", - "type": "publicKey" + "name": "concentration_scale", + "type": "u128" } ] }, { - "name": "updateExchangeStatus", + "name": "update_perp_market_contract_tier", + "discriminator": [ + 236, + 128, + 15, + 95, + 203, + 214, + 68, + 117 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "exchangeStatus", - "type": "u8" + "name": "contract_tier", + "type": { + "defined": { + "name": "ContractTier" + } + } } ] }, { - "name": "updatePerpAuctionDuration", + "name": "update_perp_market_curve_update_intensity", + "discriminator": [ + 50, + 131, + 6, + 156, + 226, + 231, + 189, + 72 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "minPerpAuctionDuration", + "name": "curve_update_intensity", "type": "u8" } ] }, { - "name": "updateSpotAuctionDuration", + "name": "update_perp_market_expiry", + "discriminator": [ + 44, + 221, + 227, + 151, + 131, + 140, + 22, + 110 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "defaultSpotAuctionDuration", - "type": "u8" + "name": "expiry_ts", + "type": "i64" } ] }, { - "name": "initializePrelaunchOracle", + "name": "update_perp_market_fee_adjustment", + "discriminator": [ + 194, + 174, + 87, + 102, + 43, + 148, + 32, + 112 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "prelaunchOracle", - "isMut": true, - "isSigner": false - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "params", - "type": { - "defined": "PrelaunchOracleParams" - } + "name": "fee_adjustment", + "type": "i16" } ] }, { - "name": "updatePrelaunchOracleParams", + "name": "update_perp_market_funding_period", + "discriminator": [ + 171, + 161, + 69, + 91, + 129, + 139, + 161, + 28 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "prelaunchOracle", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "params", - "type": { - "defined": "PrelaunchOracleParams" - } + "name": "funding_period", + "type": "i64" } ] }, { - "name": "deletePrelaunchOracle", + "name": "update_perp_market_high_leverage_margin_ratio", + "discriminator": [ + 88, + 112, + 86, + 49, + 24, + 116, + 74, + 157 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "prelaunchOracle", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "perpMarket", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "perpMarketIndex", + "name": "margin_ratio_initial", + "type": "u16" + }, + { + "name": "margin_ratio_maintenance", "type": "u16" } ] }, { - "name": "initializePythPullOracle", + "name": "update_perp_market_imf_factor", + "discriminator": [ + 207, + 194, + 56, + 132, + 35, + 67, + 71, + 244 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "pythSolanaReceiver", - "isMut": false, - "isSigner": false - }, - { - "name": "priceFeed", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "feedId", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "imf_factor", + "type": "u32" + }, + { + "name": "unrealized_pnl_imf_factor", + "type": "u32" } ] }, { - "name": "initializePythLazerOracle", + "name": "update_perp_market_liquidation_fee", + "discriminator": [ + 90, + 137, + 9, + 145, + 41, + 8, + 148, + 117 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "lazerOracle", - "isMut": true, - "isSigner": false - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "feedId", + "name": "liquidator_fee", + "type": "u32" + }, + { + "name": "if_liquidation_fee", "type": "u32" } ] }, { - "name": "postPythLazerOracleUpdate", + "name": "update_perp_market_lp_pool_fee_transfer_scalar", + "discriminator": [ + 94, + 228, + 237, + 109, + 100, + 185, + 4, + 81 + ], "accounts": [ { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "admin", + "signer": true }, { - "name": "pythLazerStorage", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "ixSysvar", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "pythMessage", - "type": "bytes" + "name": "optional_lp_fee_transfer_scalar", + "type": { + "option": "u8" + } + }, + { + "name": "optional_lp_net_pnl_transfer_scalar", + "type": { + "option": "u8" + } } ] }, { - "name": "initializeHighLeverageModeConfig", + "name": "update_perp_market_lp_pool_id", + "discriminator": [ + 119, + 208, + 154, + 88, + 165, + 92, + 21, + 188 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "highLeverageModeConfig", - "isMut": true, - "isSigner": false - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "maxUsers", - "type": "u32" + "name": "lp_pool_id", + "type": "u8" } ] }, { - "name": "updateHighLeverageModeConfig", + "name": "update_perp_market_lp_pool_paused_operations", + "discriminator": [ + 181, + 94, + 93, + 146, + 51, + 89, + 32, + 135 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "highLeverageModeConfig", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "maxUsers", - "type": "u32" - }, - { - "name": "reduceOnly", - "type": "bool" - }, - { - "name": "currentUsers", - "type": { - "option": "u32" - } + "name": "lp_paused_operations", + "type": "u8" } ] }, { - "name": "initializeProtectedMakerModeConfig", + "name": "update_perp_market_lp_pool_status", + "discriminator": [ + 67, + 6, + 252, + 61, + 54, + 88, + 89, + 233 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "protectedMakerModeConfig", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } } ], "args": [ { - "name": "maxUsers", - "type": "u32" + "name": "lp_status", + "type": "u8" } ] }, { - "name": "updateProtectedMakerModeConfig", + "name": "update_perp_market_margin_ratio", + "discriminator": [ + 130, + 173, + 107, + 45, + 119, + 105, + 26, + 113 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "protectedMakerModeConfig", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "maxUsers", + "name": "margin_ratio_initial", "type": "u32" }, { - "name": "reduceOnly", - "type": "bool" - }, - { - "name": "currentUsers", - "type": { - "option": "u32" - } + "name": "margin_ratio_maintenance", + "type": "u32" } ] }, { - "name": "adminDeposit", + "name": "update_perp_market_max_fill_reserve_fraction", + "discriminator": [ + 19, + 172, + 114, + 154, + 42, + 135, + 161, + 133 + ], "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "user", - "isMut": true, - "isSigner": false - }, { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "adminTokenAccount", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "marketIndex", + "name": "max_fill_reserve_fraction", "type": "u16" - }, - { - "name": "amount", - "type": "u64" } ] }, { - "name": "initializeIfRebalanceConfig", + "name": "update_perp_market_max_imbalances", + "discriminator": [ + 15, + 206, + 73, + 133, + 60, + 8, + 86, + 89 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "ifRebalanceConfig", - "isMut": true, - "isSigner": false - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "params", - "type": { - "defined": "IfRebalanceConfigParams" - } + "name": "unrealized_max_imbalance", + "type": "u64" + }, + { + "name": "max_revenue_withdraw_per_period", + "type": "u64" + }, + { + "name": "quote_max_insurance", + "type": "u64" } ] }, { - "name": "updateIfRebalanceConfig", + "name": "update_perp_market_max_open_interest", + "discriminator": [ + 194, + 79, + 149, + 224, + 246, + 102, + 186, + 140 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "ifRebalanceConfig", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "params", - "type": { - "defined": "IfRebalanceConfigParams" - } + "name": "max_open_interest", + "type": "u128" } ] }, { - "name": "updateFeatureBitFlagsMmOracle", + "name": "update_perp_market_max_slippage_ratio", + "discriminator": [ + 235, + 37, + 40, + 196, + 70, + 146, + 54, + 201 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "max_slippage_ratio", + "type": "u16" } ] }, { - "name": "zeroMmOracleFields", + "name": "update_perp_market_max_spread", + "discriminator": [ + 80, + 252, + 122, + 62, + 40, + 218, + 91, + 100 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "perpMarket", - "isMut": true, - "isSigner": false + "name": "perp_market", + "writable": true } ], - "args": [] + "args": [ + { + "name": "max_spread", + "type": "u32" + } + ] }, { - "name": "updateFeatureBitFlagsMedianTriggerPrice", + "name": "update_perp_market_min_order_size", + "discriminator": [ + 226, + 74, + 5, + 89, + 108, + 223, + 46, + 141 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "order_size", + "type": "u64" } ] }, { - "name": "updateFeatureBitFlagsBuilderCodes", + "name": "update_perp_market_name", + "discriminator": [ + 211, + 31, + 21, + 210, + 64, + 108, + 66, + 201 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } } ] }, { - "name": "initializeRevenueShare", + "name": "update_perp_market_number_of_users", + "discriminator": [ + 35, + 62, + 144, + 177, + 180, + 62, + 215, + 196 + ], "accounts": [ { - "name": "revenueShare", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "payer", - "isMut": true, - "isSigner": true - }, + "name": "perp_market", + "writable": true + } + ], + "args": [ { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "number_of_users", + "type": { + "option": "u32" + } }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "number_of_users_with_base", + "type": { + "option": "u32" + } } - ], - "args": [] + ] }, { - "name": "initializeRevenueShareEscrow", + "name": "update_perp_market_oracle", + "discriminator": [ + 182, + 113, + 111, + 160, + 67, + 174, + 89, + 191 + ], "accounts": [ { - "name": "escrow", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "userStats", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "oracle" }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "old_oracle" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "amm_cache", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100 + ] + } + ] + } } ], "args": [ { - "name": "numOrders", - "type": "u16" + "name": "oracle", + "type": "pubkey" + }, + { + "name": "oracle_source", + "type": { + "defined": { + "name": "OracleSource" + } + } + }, + { + "name": "skip_invariant_check", + "type": "bool" } ] }, { - "name": "resizeRevenueShareEscrowOrders", + "name": "update_perp_market_oracle_low_risk_slot_delay_override", + "discriminator": [ + 124, + 108, + 147, + 229, + 109, + 117, + 123, + 3 + ], "accounts": [ { - "name": "escrow", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "numOrders", - "type": "u16" + "name": "oracle_low_risk_slot_delay_override", + "type": "i8" } ] }, { - "name": "changeApprovedBuilder", + "name": "update_perp_market_oracle_slot_delay_override", + "discriminator": [ + 165, + 91, + 239, + 227, + 63, + 172, + 227, + 8 + ], "accounts": [ { - "name": "escrow", - "isMut": true, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "admin", + "signer": true }, { - "name": "payer", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "builder", - "type": "publicKey" - }, - { - "name": "maxFeeBps", - "type": "u16" - }, - { - "name": "add", - "type": "bool" + "name": "oracle_slot_delay_override", + "type": "i8" } ] }, { - "name": "initializeLpPool", + "name": "update_perp_market_paused_operations", + "discriminator": [ + 53, + 16, + 136, + 132, + 30, + 220, + 121, + 85 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "lpPool", - "isMut": true, - "isSigner": false + "signer": true }, { - "name": "mint", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "lpPoolTokenVault", - "isMut": true, - "isSigner": false - }, - { - "name": "ammConstituentMapping", - "isMut": true, - "isSigner": false - }, + "name": "perp_market", + "writable": true + } + ], + "args": [ { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false - }, + "name": "paused_operations", + "type": "u8" + } + ] + }, + { + "name": "update_perp_market_pnl_pool", + "discriminator": [ + 50, + 202, + 249, + 224, + 166, + 184, + 13, + 143 + ], + "accounts": [ { - "name": "constituentCorrelations", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "lpPoolId", - "type": "u8" - }, + "name": "amount", + "type": "u64" + } + ] + }, + { + "name": "update_perp_market_protected_maker_params", + "discriminator": [ + 249, + 213, + 115, + 34, + 253, + 239, + 75, + 173 + ], + "accounts": [ { - "name": "minMintFee", - "type": "i64" + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "maxAum", - "type": "u128" + "name": "state" }, { - "name": "maxSettleQuoteAmountPerMarket", - "type": "u64" + "name": "perp_market", + "writable": true + } + ], + "args": [ + { + "name": "protected_maker_limit_price_divisor", + "type": { + "option": "u8" + } }, { - "name": "whitelistMint", - "type": "publicKey" + "name": "protected_maker_dynamic_divisor", + "type": { + "option": "u8" + } } ] }, { - "name": "updateFeatureBitFlagsSettleLpPool", + "name": "update_perp_market_reference_price_offset_deadband_pct", + "discriminator": [ + 214, + 73, + 166, + 11, + 218, + 76, + 110, + 163 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "reference_price_offset_deadband_pct", + "type": "u8" } ] }, { - "name": "updateFeatureBitFlagsSwapLpPool", + "name": "update_perp_market_status", + "discriminator": [ + 71, + 201, + 175, + 122, + 255, + 207, + 196, + 207 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "status", + "type": { + "defined": { + "name": "MarketStatus" + } + } } ] }, { - "name": "updateFeatureBitFlagsMintRedeemLpPool", + "name": "update_perp_market_step_size_and_tick_size", + "discriminator": [ + 231, + 255, + 97, + 25, + 146, + 139, + 174, + 4 + ], "accounts": [ { "name": "admin", - "isMut": false, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": true, - "isSigner": false + "name": "state" + }, + { + "name": "perp_market", + "writable": true } ], "args": [ { - "name": "enable", - "type": "bool" + "name": "step_size", + "type": "u64" + }, + { + "name": "tick_size", + "type": "u64" } ] }, { - "name": "initializeConstituent", + "name": "update_perp_market_unrealized_asset_weight", + "discriminator": [ + 135, + 132, + 205, + 165, + 109, + 150, + 166, + 106 + ], "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "lpPool", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false - }, + "name": "perp_market", + "writable": true + } + ], + "args": [ { - "name": "constituentCorrelations", - "isMut": true, - "isSigner": false + "name": "unrealized_initial_asset_weight", + "type": "u32" }, { - "name": "constituent", - "isMut": true, - "isSigner": false - }, + "name": "unrealized_maintenance_asset_weight", + "type": "u32" + } + ] + }, + { + "name": "update_prelaunch_oracle", + "discriminator": [ + 220, + 132, + 27, + 27, + 233, + 220, + 61, + 219 + ], + "accounts": [ { - "name": "spotMarket", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "spotMarketMint", - "isMut": false, - "isSigner": false + "name": "perp_market" }, { - "name": "constituentVault", - "isMut": true, - "isSigner": false + "name": "oracle", + "writable": true + } + ], + "args": [] + }, + { + "name": "update_prelaunch_oracle_params", + "discriminator": [ + 98, + 205, + 147, + 243, + 18, + 75, + 83, + 207 + ], + "accounts": [ + { + "name": "admin", + "writable": true, + "signer": true }, { - "name": "rent", - "isMut": false, - "isSigner": false + "name": "prelaunch_oracle", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101 + ] + }, + { + "kind": "arg", + "path": "params.perp_market_index" + } + ] + } }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "perp_market", + "writable": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "state" } ], "args": [ { - "name": "spotMarketIndex", - "type": "u16" - }, + "name": "params", + "type": { + "defined": { + "name": "PrelaunchOracleParams" + } + } + } + ] + }, + { + "name": "update_protected_maker_mode_config", + "discriminator": [ + 86, + 166, + 235, + 253, + 67, + 202, + 223, + 17 + ], + "accounts": [ { - "name": "decimals", - "type": "u8" + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] }, { - "name": "maxWeightDeviation", - "type": "i64" + "name": "protected_maker_mode_config", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 114, + 111, + 116, + 101, + 99, + 116, + 101, + 100, + 95, + 109, + 97, + 107, + 101, + 114, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103 + ] + } + ] + } }, { - "name": "swapFeeMin", - "type": "i64" - }, + "name": "state" + } + ], + "args": [ { - "name": "swapFeeMax", - "type": "i64" + "name": "max_users", + "type": "u32" }, { - "name": "maxBorrowTokenAmount", - "type": "u64" - }, - { - "name": "oracleStalenessThreshold", - "type": "u64" - }, - { - "name": "costToTrade", - "type": "i32" + "name": "reduce_only", + "type": "bool" }, { - "name": "constituentDerivativeIndex", + "name": "current_users", "type": { - "option": "i16" + "option": "u32" } - }, - { - "name": "constituentDerivativeDepegThreshold", - "type": "u64" - }, - { - "name": "derivativeWeight", - "type": "u64" - }, + } + ] + }, + { + "name": "update_pyth_pull_oracle", + "discriminator": [ + 230, + 191, + 189, + 94, + 108, + 59, + 74, + 197 + ], + "accounts": [ { - "name": "volatility", - "type": "u64" + "name": "keeper", + "writable": true, + "signer": true }, { - "name": "gammaExecution", - "type": "u8" + "name": "pyth_solana_receiver", + "address": "G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha" }, { - "name": "gammaInventory", - "type": "u8" + "name": "encoded_vaa" }, { - "name": "xi", - "type": "u8" - }, + "name": "price_feed", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 112, + 121, + 116, + 104, + 95, + 112, + 117, + 108, + 108 + ] + }, + { + "kind": "arg", + "path": "feed_id" + } + ] + } + } + ], + "args": [ { - "name": "newConstituentCorrelations", + "name": "feed_id", "type": { - "vec": "i64" + "array": [ + "u8", + 32 + ] } + }, + { + "name": "params", + "type": "bytes" } ] }, { - "name": "updateConstituentStatus", + "name": "update_serum_fulfillment_config_status", + "discriminator": [ + 171, + 109, + 240, + 251, + 95, + 1, + 149, + 89 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "serum_fulfillment_config", + "writable": true }, { - "name": "constituent", - "isMut": true, - "isSigner": false + "name": "admin", + "writable": true, + "signer": true, + "relations": [ + "state" + ] } ], "args": [ { - "name": "newStatus", - "type": "u8" + "name": "status", + "type": { + "defined": { + "name": "SpotFulfillmentConfigStatus" + } + } } ] }, { - "name": "updateConstituentPausedOperations", + "name": "update_spot_auction_duration", + "discriminator": [ + 182, + 178, + 203, + 72, + 187, + 143, + 157, + 107 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "constituent", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "pausedOperations", + "name": "default_spot_auction_duration", "type": "u8" } ] }, { - "name": "updateConstituentParams", + "name": "update_spot_fee_structure", + "discriminator": [ + 97, + 216, + 105, + 131, + 113, + 246, + 142, + 141 + ], "accounts": [ - { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, - { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false - }, { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "constituent", - "isMut": true, - "isSigner": false + "writable": true } ], "args": [ { - "name": "constituentParams", + "name": "fee_structure", "type": { - "defined": "ConstituentParams" + "defined": { + "name": "FeeStructure" + } } } ] }, { - "name": "updateLpPoolParams", + "name": "update_spot_market_asset_tier", + "discriminator": [ + 253, + 209, + 231, + 14, + 242, + 208, + 243, + 130 + ], "accounts": [ { - "name": "lpPool", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "lpPoolParams", + "name": "asset_tier", "type": { - "defined": "LpPoolParams" + "defined": { + "name": "AssetTier" + } } } ] }, { - "name": "addAmmConstituentMappingData", + "name": "update_spot_market_borrow_rate", + "discriminator": [ + 71, + 239, + 236, + 153, + 210, + 62, + 254, + 76 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "lpPool", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "ammConstituentMapping", - "isMut": true, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false + "name": "optimal_utilization", + "type": "u32" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "optimal_borrow_rate", + "type": "u32" }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false - } - ], - "args": [ + "name": "max_borrow_rate", + "type": "u32" + }, { - "name": "ammConstituentMappingData", + "name": "min_borrow_rate", "type": { - "vec": { - "defined": "AddAmmConstituentMappingDatum" - } + "option": "u8" } } ] }, { - "name": "updateAmmConstituentMappingData", + "name": "update_spot_market_cumulative_interest", + "discriminator": [ + 39, + 166, + 139, + 243, + 158, + 165, + 155, + 225 + ], "accounts": [ { - "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "lpPool", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "ammConstituentMapping", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "oracle" }, { - "name": "state", - "isMut": false, - "isSigner": false - } - ], - "args": [ - { - "name": "ammConstituentMappingData", - "type": { - "vec": { - "defined": "AddAmmConstituentMappingDatum" - } + "name": "spot_market_vault", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "account", + "path": "spot_market" + } + ] } } - ] + ], + "args": [] }, { - "name": "removeAmmConstituentMappingData", + "name": "update_spot_market_expiry", + "discriminator": [ + 208, + 11, + 211, + 159, + 226, + 24, + 11, + 247 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, - { - "name": "ammConstituentMapping", - "isMut": true, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "systemProgram", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "constituentIndex", - "type": "u16" + "name": "expiry_ts", + "type": "i64" } ] }, { - "name": "updateConstituentCorrelationData", + "name": "update_spot_market_fee_adjustment", + "discriminator": [ + 148, + 182, + 3, + 126, + 157, + 114, + 220, + 99 + ], "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "lpPool", - "isMut": false, - "isSigner": false + "signer": true, + "relations": [ + "state" + ] }, { - "name": "constituentCorrelations", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "index1", - "type": "u16" - }, - { - "name": "index2", - "type": "u16" - }, - { - "name": "correlation", - "type": "i64" + "name": "fee_adjustment", + "type": "i16" } ] }, { - "name": "updateLpConstituentTargetBase", + "name": "update_spot_market_if_factor", + "discriminator": [ + 147, + 30, + 224, + 34, + 18, + 230, + 105, + 4 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "keeper", - "isMut": true, - "isSigner": true - }, - { - "name": "ammConstituentMapping", - "isMut": false, - "isSigner": false - }, - { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "ammCache", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "lpPool", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], - "args": [] - }, - { - "name": "updateLpPoolAum", - "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "keeper", - "isMut": true, - "isSigner": true - }, + "args": [ { - "name": "lpPool", - "isMut": true, - "isSigner": false + "name": "spot_market_index", + "type": "u16" }, { - "name": "constituentTargetBase", - "isMut": true, - "isSigner": false + "name": "user_if_factor", + "type": "u32" }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "total_if_factor", + "type": "u32" } - ], - "args": [] + ] }, { - "name": "updateAmmCache", + "name": "update_spot_market_if_paused_operations", + "discriminator": [ + 101, + 215, + 79, + 74, + 59, + 41, + 79, + 12 + ], "accounts": [ { - "name": "keeper", - "isMut": true, - "isSigner": true - }, - { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "quoteMarket", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], - "args": [] + "args": [ + { + "name": "paused_operations", + "type": "u8" + } + ] }, { - "name": "overrideAmmCacheInfo", + "name": "update_spot_market_liquidation_fee", + "discriminator": [ + 11, + 13, + 255, + 53, + 56, + 136, + 104, + 177 + ], "accounts": [ { - "name": "state", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "admin", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "marketIndex", - "type": "u16" + "name": "liquidator_fee", + "type": "u32" }, { - "name": "overrideParams", - "type": { - "defined": "OverrideAmmCacheParams" - } + "name": "if_liquidation_fee", + "type": "u32" } ] }, { - "name": "lpPoolSwap", + "name": "update_spot_market_margin_weights", + "discriminator": [ + 109, + 33, + 87, + 195, + 255, + 36, + 6, + 81 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "lpPool", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "constituentCorrelations", - "isMut": false, - "isSigner": false + "name": "initial_asset_weight", + "type": "u32" }, { - "name": "constituentInTokenAccount", - "isMut": true, - "isSigner": false + "name": "maintenance_asset_weight", + "type": "u32" }, { - "name": "constituentOutTokenAccount", - "isMut": true, - "isSigner": false + "name": "initial_liability_weight", + "type": "u32" }, { - "name": "userInTokenAccount", - "isMut": true, - "isSigner": false + "name": "maintenance_liability_weight", + "type": "u32" }, { - "name": "userOutTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "imf_factor", + "type": "u32" + } + ] + }, + { + "name": "update_spot_market_max_token_borrows", + "discriminator": [ + 57, + 102, + 204, + 212, + 253, + 95, + 13, + 199 + ], + "accounts": [ { - "name": "inConstituent", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "outConstituent", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "inMarketMint", - "isMut": false, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ + { + "name": "max_token_borrows_fraction", + "type": "u16" + } + ] + }, + { + "name": "update_spot_market_max_token_deposits", + "discriminator": [ + 56, + 191, + 79, + 18, + 26, + 121, + 80, + 208 + ], + "accounts": [ { - "name": "outMarketMint", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, + "name": "max_token_deposits", + "type": "u64" + } + ] + }, + { + "name": "update_spot_market_min_order_size", + "discriminator": [ + 93, + 128, + 11, + 119, + 26, + 20, + 181, + 50 + ], + "accounts": [ { - "name": "outMarketIndex", - "type": "u16" + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "inAmount", - "type": "u64" + "name": "state" }, { - "name": "minOutAmount", + "name": "spot_market", + "writable": true + } + ], + "args": [ + { + "name": "order_size", "type": "u64" } ] }, { - "name": "viewLpPoolSwapFees", + "name": "update_spot_market_name", + "discriminator": [ + 17, + 208, + 1, + 1, + 162, + 211, + 188, + 224 + ], "accounts": [ { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, - { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false - }, - { - "name": "constituentCorrelations", - "isMut": false, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "constituentInTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } + } + ] + }, + { + "name": "update_spot_market_oracle", + "discriminator": [ + 114, + 184, + 102, + 37, + 246, + 186, + 180, + 99 + ], + "accounts": [ { - "name": "constituentOutTokenAccount", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "inConstituent", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "outConstituent", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "oracle" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "old_oracle" } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, - { - "name": "outMarketIndex", - "type": "u16" - }, - { - "name": "inAmount", - "type": "u64" + "name": "oracle", + "type": "pubkey" }, { - "name": "inTargetWeight", - "type": "i64" + "name": "oracle_source", + "type": { + "defined": { + "name": "OracleSource" + } + } }, { - "name": "outTargetWeight", - "type": "i64" + "name": "skip_invariant_check", + "type": "bool" } ] }, { - "name": "lpPoolAddLiquidity", + "name": "update_spot_market_orders_enabled", + "discriminator": [ + 190, + 79, + 206, + 15, + 26, + 229, + 229, + 43 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "lpPool", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "authority", - "isMut": false, - "isSigner": true + "name": "state" }, { - "name": "inMarketMint", - "isMut": false, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "inConstituent", - "isMut": true, - "isSigner": false - }, + "name": "orders_enabled", + "type": "bool" + } + ] + }, + { + "name": "update_spot_market_paused_operations", + "discriminator": [ + 100, + 61, + 153, + 81, + 180, + 12, + 6, + 248 + ], + "accounts": [ { - "name": "userInTokenAccount", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "constituentInTokenAccount", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userLpTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "lpMint", - "isMut": true, - "isSigner": false - }, + "name": "paused_operations", + "type": "u8" + } + ] + }, + { + "name": "update_spot_market_pool_id", + "discriminator": [ + 22, + 213, + 197, + 160, + 139, + 193, + 81, + 149 + ], + "accounts": [ { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "lpPoolTokenVault", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, - { - "name": "inAmount", - "type": "u128" - }, - { - "name": "minMintAmount", - "type": "u64" + "name": "pool_id", + "type": "u8" } ] }, { - "name": "lpPoolRemoveLiquidity", + "name": "update_spot_market_revenue_settle_period", + "discriminator": [ + 81, + 92, + 126, + 41, + 250, + 225, + 156, + 219 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "lpPool", - "isMut": true, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "authority", - "isMut": false, - "isSigner": true - }, + "name": "revenue_settle_period", + "type": "i64" + } + ] + }, + { + "name": "update_spot_market_scale_initial_asset_weight_start", + "discriminator": [ + 217, + 204, + 204, + 118, + 204, + 130, + 225, + 147 + ], + "accounts": [ { - "name": "outMarketMint", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "outConstituent", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "userOutTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "constituentOutTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "scale_initial_asset_weight_start", + "type": "u64" + } + ] + }, + { + "name": "update_spot_market_status", + "discriminator": [ + 78, + 94, + 16, + 188, + 193, + 110, + 231, + 31 + ], + "accounts": [ { - "name": "userLpTokenAccount", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "spotMarketTokenAccount", - "isMut": true, - "isSigner": false + "name": "state" }, { - "name": "lpMint", - "isMut": true, - "isSigner": false - }, + "name": "spot_market", + "writable": true + } + ], + "args": [ { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false - }, + "name": "status", + "type": { + "defined": { + "name": "MarketStatus" + } + } + } + ] + }, + { + "name": "update_spot_market_step_size_and_tick_size", + "discriminator": [ + 238, + 153, + 137, + 80, + 206, + 59, + 250, + 61 + ], + "accounts": [ { - "name": "lpPoolTokenVault", - "isMut": true, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "ammCache", - "isMut": false, - "isSigner": false + "name": "spot_market", + "writable": true } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, - { - "name": "inAmount", + "name": "step_size", "type": "u64" }, { - "name": "minOutAmount", - "type": "u128" + "name": "tick_size", + "type": "u64" } ] }, { - "name": "viewLpPoolAddLiquidityFees", + "name": "update_state_max_initialize_user_fee", + "discriminator": [ + 237, + 225, + 25, + 237, + 193, + 45, + 77, + 97 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "inMarketMint", - "isMut": false, - "isSigner": false - }, - { - "name": "inConstituent", - "isMut": false, - "isSigner": false - }, - { - "name": "lpMint", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false + "name": "state", + "writable": true } ], "args": [ { - "name": "inMarketIndex", + "name": "max_initialize_user_fee", "type": "u16" - }, - { - "name": "inAmount", - "type": "u128" } ] }, { - "name": "viewLpPoolRemoveLiquidityFees", + "name": "update_state_max_number_of_sub_accounts", + "discriminator": [ + 155, + 123, + 214, + 2, + 221, + 166, + 204, + 85 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false - }, - { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, - { - "name": "authority", - "isMut": false, - "isSigner": true - }, - { - "name": "outMarketMint", - "isMut": false, - "isSigner": false - }, - { - "name": "outConstituent", - "isMut": false, - "isSigner": false - }, - { - "name": "lpMint", - "isMut": false, - "isSigner": false + "name": "admin", + "signer": true, + "relations": [ + "state" + ] }, { - "name": "constituentTargetBase", - "isMut": false, - "isSigner": false + "name": "state", + "writable": true } ], "args": [ { - "name": "inMarketIndex", + "name": "max_number_of_sub_accounts", "type": "u16" - }, - { - "name": "inAmount", - "type": "u64" } ] }, { - "name": "beginLpSwap", + "name": "update_state_settlement_duration", + "discriminator": [ + 97, + 68, + 199, + 235, + 131, + 80, + 61, + 173 + ], "accounts": [ - { - "name": "state", - "isMut": false, - "isSigner": false - }, { "name": "admin", - "isMut": true, - "isSigner": true - }, - { - "name": "signerOutTokenAccount", - "isMut": true, - "isSigner": false, - "docs": [ - "Signer token accounts" + "signer": true, + "relations": [ + "state" ] }, { - "name": "signerInTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "state", + "writable": true + } + ], + "args": [ { - "name": "constituentOutTokenAccount", - "isMut": true, - "isSigner": false, - "docs": [ - "Constituent token accounts" - ] - }, + "name": "settlement_duration", + "type": "u16" + } + ] + }, + { + "name": "update_user_custom_margin_ratio", + "discriminator": [ + 21, + 221, + 140, + 187, + 32, + 129, + 11, + 123 + ], + "accounts": [ { - "name": "constituentInTokenAccount", - "isMut": true, - "isSigner": false + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } }, { - "name": "outConstituent", - "isMut": true, - "isSigner": false, - "docs": [ - "Constituents" - ] - }, + "name": "authority", + "signer": true + } + ], + "args": [ { - "name": "inConstituent", - "isMut": true, - "isSigner": false + "name": "_sub_account_id", + "type": "u16" }, { - "name": "lpPool", - "isMut": false, - "isSigner": false - }, + "name": "margin_ratio", + "type": "u32" + } + ] + }, + { + "name": "update_user_delegate", + "discriminator": [ + 139, + 205, + 141, + 141, + 113, + 36, + 94, + 187 + ], + "accounts": [ { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "inMarketIndex", - "type": "u16" - }, - { - "name": "outMarketIndex", + "name": "_sub_account_id", "type": "u16" }, { - "name": "amountIn", - "type": "u64" + "name": "delegate", + "type": "pubkey" } ] }, { - "name": "endLpSwap", + "name": "update_user_gov_token_insurance_stake", + "discriminator": [ + 143, + 99, + 235, + 187, + 20, + 159, + 184, + 84 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 15, + 0 + ] + } + ] + } }, { - "name": "signerOutTokenAccount", - "isMut": true, - "isSigner": false, - "docs": [ - "Signer token accounts" - ] + "name": "insurance_fund_stake", + "writable": true }, { - "name": "signerInTokenAccount", - "isMut": true, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "constituentOutTokenAccount", - "isMut": true, - "isSigner": false, - "docs": [ - "Constituent token accounts" - ] + "name": "signer", + "signer": true }, { - "name": "constituentInTokenAccount", - "isMut": true, - "isSigner": false - }, + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 15, + 0 + ] + } + ] + } + } + ], + "args": [] + }, + { + "name": "update_user_idle", + "discriminator": [ + 253, + 133, + 67, + 22, + 103, + 161, + 20, + 100 + ], + "accounts": [ { - "name": "outConstituent", - "isMut": true, - "isSigner": false, - "docs": [ - "Constituents" - ] + "name": "state" }, { - "name": "inConstituent", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "lpPool", - "isMut": false, - "isSigner": false + "name": "filler", + "writable": true }, { - "name": "instructions", - "isMut": false, - "isSigner": false, - "docs": [ - "Instructions Sysvar for instruction introspection" - ] + "name": "user", + "writable": true + } + ], + "args": [] + }, + { + "name": "update_user_margin_trading_enabled", + "discriminator": [ + 194, + 92, + 204, + 223, + 246, + 188, + 31, + 203 + ], + "accounts": [ + { + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true } ], "args": [ { - "name": "inMarketIndex", + "name": "_sub_account_id", "type": "u16" }, { - "name": "outMarketIndex", + "name": "margin_trading_enabled", + "type": "bool" + } + ] + }, + { + "name": "update_user_name", + "discriminator": [ + 135, + 25, + 185, + 56, + 165, + 53, + 34, + 136 + ], + "accounts": [ + { + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } + }, + { + "name": "authority", + "signer": true + } + ], + "args": [ + { + "name": "_sub_account_id", "type": "u16" + }, + { + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } } ] }, { - "name": "updateConstituentOracleInfo", + "name": "update_user_perp_position_custom_margin_ratio", + "discriminator": [ + 121, + 137, + 157, + 155, + 89, + 186, + 145, + 113 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "user", + "writable": true }, { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "authority", + "signer": true + } + ], + "args": [ + { + "name": "_sub_account_id", + "type": "u16" }, { - "name": "constituent", - "isMut": true, - "isSigner": false + "name": "perp_market_index", + "type": "u16" }, { - "name": "spotMarket", - "isMut": false, - "isSigner": false + "name": "margin_ratio", + "type": "u16" + } + ] + }, + { + "name": "update_user_pool_id", + "discriminator": [ + 219, + 86, + 73, + 106, + 56, + 218, + 128, + 109 + ], + "accounts": [ + { + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "authority", + "signer": true } ], - "args": [] + "args": [ + { + "name": "_sub_account_id", + "type": "u16" + }, + { + "name": "pool_id", + "type": "u8" + } + ] }, { - "name": "depositToProgramVault", + "name": "update_user_protected_maker_orders", + "discriminator": [ + 114, + 39, + 123, + 198, + 187, + 25, + 90, + 219 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "admin", - "isMut": true, - "isSigner": true + "name": "user", + "writable": true }, { - "name": "constituent", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true + }, + { + "name": "protected_maker_mode_config", + "writable": true + } + ], + "args": [ + { + "name": "_sub_account_id", + "type": "u16" }, { - "name": "constituentTokenAccount", - "isMut": true, - "isSigner": false + "name": "protected_maker_orders", + "type": "bool" + } + ] + }, + { + "name": "update_user_quote_asset_insurance_stake", + "discriminator": [ + 251, + 101, + 156, + 7, + 2, + 63, + 30, + 23 + ], + "accounts": [ + { + "name": "state" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "insurance_fund_stake", + "writable": true }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "user_stats", + "writable": true }, { - "name": "mint", - "isMut": false, - "isSigner": false + "name": "signer", + "signer": true }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "insurance_fund_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "const", + "value": [ + 0, + 0 + ] + } + ] + } + } + ], + "args": [] + }, + { + "name": "update_user_reduce_only", + "discriminator": [ + 199, + 71, + 42, + 67, + 144, + 19, + 86, + 109 + ], + "accounts": [ + { + "name": "user", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 117, + 115, + 101, + 114 + ] + }, + { + "kind": "account", + "path": "authority" + }, + { + "kind": "arg", + "path": "sub_account_id" + } + ] + } + }, + { + "name": "authority", + "signer": true } ], "args": [ { - "name": "amount", - "type": "u64" + "name": "_sub_account_id", + "type": "u16" + }, + { + "name": "reduce_only", + "type": "bool" } ] }, { - "name": "withdrawFromProgramVault", + "name": "update_user_stats_referrer_status", + "discriminator": [ + 174, + 154, + 72, + 42, + 191, + 148, + 145, + 205 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" + }, + { + "name": "authority", + "signer": true }, + { + "name": "user_stats", + "writable": true + } + ], + "args": [] + }, + { + "name": "update_withdraw_guard_threshold", + "discriminator": [ + 56, + 18, + 39, + 61, + 155, + 211, + 44, + 133 + ], + "accounts": [ { "name": "admin", - "isMut": true, - "isSigner": true + "signer": true, + "relations": [ + "state" + ] }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "constituent", - "isMut": true, - "isSigner": false + "name": "spot_market", + "writable": true + } + ], + "args": [ + { + "name": "withdraw_guard_threshold", + "type": "u64" + } + ] + }, + { + "name": "view_lp_pool_add_liquidity_fees", + "discriminator": [ + 80, + 66, + 226, + 161, + 70, + 142, + 119, + 84 + ], + "accounts": [ + { + "name": "state" }, { - "name": "constituentTokenAccount", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "spotMarket", - "isMut": true, - "isSigner": false + "name": "authority", + "signer": true }, { - "name": "spotMarketVault", - "isMut": true, - "isSigner": false + "name": "in_market_mint" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "in_constituent", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "mint", - "isMut": false, - "isSigner": false + "name": "lp_mint" }, { - "name": "oracle", - "isMut": false, - "isSigner": false + "name": "constituent_target_base" } ], "args": [ { - "name": "amount", - "type": "u64" + "name": "in_market_index", + "type": "u16" + }, + { + "name": "in_amount", + "type": "u128" } ] }, { - "name": "settlePerpToLpPool", + "name": "view_lp_pool_remove_liquidity_fees", + "discriminator": [ + 47, + 12, + 9, + 102, + 12, + 226, + 197, + 89 + ], "accounts": [ { - "name": "state", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "lpPool", - "isMut": true, - "isSigner": false + "name": "lp_pool" }, { - "name": "keeper", - "isMut": true, - "isSigner": true + "name": "authority", + "signer": true }, { - "name": "ammCache", - "isMut": true, - "isSigner": false + "name": "out_market_mint" }, { - "name": "quoteMarket", - "isMut": true, - "isSigner": false + "name": "out_constituent", + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" + } + ] + } }, { - "name": "constituent", - "isMut": true, - "isSigner": false + "name": "lp_mint" }, { - "name": "constituentQuoteTokenAccount", - "isMut": true, - "isSigner": false + "name": "constituent_target_base" + } + ], + "args": [ + { + "name": "in_market_index", + "type": "u16" }, { - "name": "quoteTokenVault", - "isMut": true, - "isSigner": false + "name": "in_amount", + "type": "u64" + } + ] + }, + { + "name": "view_lp_pool_swap_fees", + "discriminator": [ + 126, + 189, + 109, + 189, + 170, + 156, + 3, + 46 + ], + "accounts": [ + { + "name": "drift_signer" }, { - "name": "tokenProgram", - "isMut": false, - "isSigner": false + "name": "state" }, { - "name": "driftSigner", - "isMut": false, - "isSigner": false - } - ], - "args": [] - } - ], - "accounts": [ - { - "name": "AmmCache", - "type": { - "kind": "struct", - "fields": [ - { - "name": "bump", - "type": "u8" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 3 - ] - } - }, - { - "name": "cache", - "type": { - "vec": { - "defined": "CacheInfo" + "name": "lp_pool" + }, + { + "name": "constituent_target_base" + }, + { + "name": "constituent_correlations" + }, + { + "name": "constituent_in_token_account", + "writable": true + }, + { + "name": "constituent_out_token_account", + "writable": true + }, + { + "name": "in_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "in_market_index" } - } + ] } - ] - } + }, + { + "name": "out_constituent", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84 + ] + }, + { + "kind": "account", + "path": "lp_pool" + }, + { + "kind": "arg", + "path": "out_market_index" + } + ] + } + }, + { + "name": "authority", + "signer": true + }, + { + "name": "token_program" + } + ], + "args": [ + { + "name": "in_market_index", + "type": "u16" + }, + { + "name": "out_market_index", + "type": "u16" + }, + { + "name": "in_amount", + "type": "u64" + }, + { + "name": "in_target_weight", + "type": "i64" + }, + { + "name": "out_target_weight", + "type": "i64" + } + ] }, { - "name": "OpenbookV2FulfillmentConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "pubkey", - "type": "publicKey" - }, - { - "name": "openbookV2ProgramId", - "type": "publicKey" - }, - { - "name": "openbookV2Market", - "type": "publicKey" - }, - { - "name": "openbookV2MarketAuthority", - "type": "publicKey" - }, - { - "name": "openbookV2EventHeap", - "type": "publicKey" - }, - { - "name": "openbookV2Bids", - "type": "publicKey" - }, - { - "name": "openbookV2Asks", - "type": "publicKey" - }, - { - "name": "openbookV2BaseVault", - "type": "publicKey" - }, - { - "name": "openbookV2QuoteVault", - "type": "publicKey" - }, - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "fulfillmentType", - "type": { - "defined": "SpotFulfillmentType" - } - }, - { - "name": "status", - "type": { - "defined": "SpotFulfillmentConfigStatus" - } - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 4 - ] - } + "name": "withdraw", + "discriminator": [ + 183, + 18, + 70, + 156, + 148, + 109, + 161, + 34 + ], + "accounts": [ + { + "name": "state" + }, + { + "name": "user", + "writable": true + }, + { + "name": "user_stats", + "writable": true + }, + { + "name": "authority", + "signer": true, + "relations": [ + "user", + "user_stats" + ] + }, + { + "name": "spot_market_vault", + "writable": true, + "pda": { + "seeds": [ + { + "kind": "const", + "value": [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116 + ] + }, + { + "kind": "arg", + "path": "market_index" + } + ] } - ] - } + }, + { + "name": "drift_signer" + }, + { + "name": "user_token_account", + "writable": true + }, + { + "name": "token_program" + } + ], + "args": [ + { + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", + "type": "u64" + }, + { + "name": "reduce_only", + "type": "bool" + } + ] }, { - "name": "PhoenixV1FulfillmentConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "pubkey", - "type": "publicKey" - }, - { - "name": "phoenixProgramId", - "type": "publicKey" - }, - { - "name": "phoenixLogAuthority", - "type": "publicKey" - }, - { - "name": "phoenixMarket", - "type": "publicKey" - }, - { - "name": "phoenixBaseVault", - "type": "publicKey" - }, - { - "name": "phoenixQuoteVault", - "type": "publicKey" - }, - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "fulfillmentType", - "type": { - "defined": "SpotFulfillmentType" - } - }, - { - "name": "status", - "type": { - "defined": "SpotFulfillmentConfigStatus" - } - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 4 - ] - } - } - ] - } + "name": "withdraw_from_program_vault", + "discriminator": [ + 120, + 40, + 183, + 149, + 232, + 18, + 224, + 151 + ], + "accounts": [ + { + "name": "state" + }, + { + "name": "admin", + "writable": true, + "signer": true + }, + { + "name": "drift_signer" + }, + { + "name": "constituent", + "writable": true + }, + { + "name": "constituent_token_account", + "writable": true + }, + { + "name": "spot_market", + "writable": true + }, + { + "name": "spot_market_vault", + "writable": true + }, + { + "name": "token_program" + }, + { + "name": "mint" + }, + { + "name": "oracle" + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + } + ] }, { - "name": "SerumV3FulfillmentConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "pubkey", - "type": "publicKey" - }, - { - "name": "serumProgramId", - "type": "publicKey" - }, - { - "name": "serumMarket", - "type": "publicKey" - }, - { - "name": "serumRequestQueue", - "type": "publicKey" - }, - { - "name": "serumEventQueue", - "type": "publicKey" - }, - { - "name": "serumBids", - "type": "publicKey" - }, - { - "name": "serumAsks", - "type": "publicKey" - }, - { - "name": "serumBaseVault", - "type": "publicKey" - }, - { - "name": "serumQuoteVault", - "type": "publicKey" - }, - { - "name": "serumOpenOrders", - "type": "publicKey" - }, - { - "name": "serumSignerNonce", - "type": "u64" - }, - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "fulfillmentType", - "type": { - "defined": "SpotFulfillmentType" - } - }, - { - "name": "status", - "type": { - "defined": "SpotFulfillmentConfigStatus" - } - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 4 - ] - } - } - ] - } + "name": "zero_mm_oracle_fields", + "discriminator": [ + 192, + 226, + 39, + 204, + 207, + 120, + 148, + 250 + ], + "accounts": [ + { + "name": "admin", + "signer": true + }, + { + "name": "state" + }, + { + "name": "perp_market", + "writable": true + } + ], + "args": [] + } + ], + "accounts": [ + { + "name": "AmmCache", + "discriminator": [ + 213, + 114, + 161, + 56, + 20, + 22, + 2, + 59 + ] + }, + { + "name": "AmmConstituentMapping", + "discriminator": [ + 254, + 89, + 5, + 173, + 66, + 54, + 214, + 247 + ] + }, + { + "name": "Constituent", + "discriminator": [ + 0, + 61, + 36, + 35, + 177, + 76, + 216, + 205 + ] + }, + { + "name": "ConstituentCorrelations", + "discriminator": [ + 124, + 203, + 115, + 33, + 18, + 162, + 67, + 216 + ] + }, + { + "name": "ConstituentTargetBase", + "discriminator": [ + 255, + 142, + 134, + 71, + 125, + 66, + 198, + 99 + ] + }, + { + "name": "FuelOverflow", + "discriminator": [ + 182, + 64, + 231, + 177, + 226, + 142, + 69, + 58 + ] }, { "name": "HighLeverageModeConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "maxUsers", - "type": "u32" - }, - { - "name": "currentUsers", - "type": "u32" - }, - { - "name": "reduceOnly", - "type": "u8" - }, - { - "name": "padding1", - "type": { - "array": [ - "u8", - 3 - ] - } - }, - { - "name": "currentMaintenanceUsers", - "type": "u32" - }, - { - "name": "padding2", - "type": { - "array": [ - "u8", - 24 - ] - } - } - ] - } + "discriminator": [ + 3, + 196, + 90, + 189, + 193, + 64, + 228, + 234 + ] }, { "name": "IfRebalanceConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "pubkey", - "type": "publicKey" - }, - { - "name": "totalInAmount", - "docs": [ - "total amount to be sold" - ], - "type": "u64" - }, - { - "name": "currentInAmount", - "docs": [ - "amount already sold" - ], - "type": "u64" - }, - { - "name": "currentOutAmount", - "docs": [ - "amount already bought" - ], - "type": "u64" - }, - { - "name": "currentOutAmountTransferred", - "docs": [ - "amount already transferred to revenue pool" - ], - "type": "u64" - }, - { - "name": "currentInAmountSinceLastTransfer", - "docs": [ - "amount already bought in epoch" - ], - "type": "u64" - }, - { - "name": "epochStartTs", - "docs": [ - "start time of epoch" - ], - "type": "i64" - }, - { - "name": "epochInAmount", - "docs": [ - "amount already bought in epoch" - ], - "type": "u64" - }, - { - "name": "epochMaxInAmount", - "docs": [ - "max amount to swap in epoch" - ], - "type": "u64" - }, - { - "name": "epochDuration", - "docs": [ - "duration of epoch" - ], - "type": "i64" - }, - { - "name": "outMarketIndex", - "docs": [ - "market index to sell" - ], - "type": "u16" - }, - { - "name": "inMarketIndex", - "docs": [ - "market index to buy" - ], - "type": "u16" - }, - { - "name": "maxSlippageBps", - "type": "u16" - }, - { - "name": "swapMode", - "type": "u8" - }, - { - "name": "status", - "type": "u8" - }, - { - "name": "padding2", - "type": { - "array": [ - "u8", - 32 - ] - } - } - ] - } + "discriminator": [ + 214, + 84, + 40, + 251, + 107, + 144, + 173, + 239 + ] }, { "name": "InsuranceFundStake", - "type": { - "kind": "struct", - "fields": [ - { - "name": "authority", - "type": "publicKey" - }, - { - "name": "ifShares", - "type": "u128" - }, - { - "name": "lastWithdrawRequestShares", - "type": "u128" - }, - { - "name": "ifBase", - "type": "u128" - }, - { - "name": "lastValidTs", - "type": "i64" - }, - { - "name": "lastWithdrawRequestValue", - "type": "u64" - }, - { - "name": "lastWithdrawRequestTs", - "type": "i64" - }, - { - "name": "costBasis", - "type": "i64" - }, - { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 14 - ] - } - } - ] - } + "discriminator": [ + 110, + 202, + 14, + 42, + 95, + 73, + 90, + 95 + ] }, { - "name": "ProtocolIfSharesTransferConfig", - "type": { - "kind": "struct", - "fields": [ - { - "name": "whitelistedSigners", - "type": { - "array": [ - "publicKey", - 4 - ] - } - }, - { - "name": "maxTransferPerEpoch", - "type": "u128" - }, - { - "name": "currentEpochTransfer", - "type": "u128" - }, - { - "name": "nextEpochTs", - "type": "i64" - }, - { - "name": "padding", - "type": { - "array": [ - "u128", - 8 - ] - } - } - ] - } + "name": "LPPool", + "discriminator": [ + 228, + 152, + 141, + 224, + 161, + 170, + 11, + 89 + ] }, { - "name": "LPPool", + "name": "OpenbookV2FulfillmentConfig", + "discriminator": [ + 3, + 43, + 58, + 106, + 131, + 132, + 199, + 171 + ] + }, + { + "name": "PerpMarket", + "discriminator": [ + 10, + 223, + 12, + 44, + 107, + 245, + 55, + 247 + ] + }, + { + "name": "PhoenixV1FulfillmentConfig", + "discriminator": [ + 233, + 45, + 62, + 40, + 35, + 129, + 48, + 72 + ] + }, + { + "name": "PrelaunchOracle", + "discriminator": [ + 92, + 14, + 139, + 234, + 72, + 244, + 68, + 26 + ] + }, + { + "name": "ProtectedMakerModeConfig", + "discriminator": [ + 47, + 86, + 90, + 9, + 224, + 255, + 10, + 69 + ] + }, + { + "name": "PythLazerOracle", + "discriminator": [ + 159, + 7, + 161, + 249, + 34, + 81, + 121, + 133 + ] + }, + { + "name": "ReferrerName", + "discriminator": [ + 105, + 133, + 170, + 110, + 52, + 42, + 28, + 182 + ] + }, + { + "name": "RevenueShare", + "discriminator": [ + 55, + 40, + 228, + 7, + 139, + 52, + 180, + 110 + ] + }, + { + "name": "RevenueShareEscrow", + "discriminator": [ + 98, + 167, + 3, + 46, + 74, + 177, + 173, + 252 + ] + }, + { + "name": "SerumV3FulfillmentConfig", + "discriminator": [ + 65, + 160, + 197, + 112, + 239, + 168, + 103, + 185 + ] + }, + { + "name": "SignedMsgUserOrders", + "discriminator": [ + 70, + 6, + 50, + 248, + 222, + 1, + 143, + 49 + ] + }, + { + "name": "SignedMsgWsDelegates", + "discriminator": [ + 190, + 115, + 111, + 44, + 216, + 252, + 108, + 85 + ] + }, + { + "name": "SpotMarket", + "discriminator": [ + 100, + 177, + 8, + 107, + 168, + 65, + 65, + 39 + ] + }, + { + "name": "State", + "discriminator": [ + 216, + 146, + 107, + 94, + 104, + 75, + 182, + 177 + ] + }, + { + "name": "User", + "discriminator": [ + 159, + 117, + 95, + 227, + 239, + 151, + 58, + 236 + ] + }, + { + "name": "UserStats", + "discriminator": [ + 176, + 223, + 136, + 27, + 122, + 79, + 32, + 227 + ] + } + ], + "events": [ + { + "name": "CurveRecord", + "discriminator": [ + 101, + 238, + 40, + 228, + 70, + 46, + 61, + 117 + ] + }, + { + "name": "DeleteUserRecord", + "discriminator": [ + 71, + 111, + 190, + 118, + 7, + 3, + 132, + 222 + ] + }, + { + "name": "DepositRecord", + "discriminator": [ + 180, + 241, + 218, + 207, + 102, + 135, + 44, + 134 + ] + }, + { + "name": "FuelSeasonRecord", + "discriminator": [ + 19, + 137, + 119, + 33, + 224, + 249, + 6, + 87 + ] + }, + { + "name": "FuelSweepRecord", + "discriminator": [ + 41, + 84, + 37, + 246, + 132, + 240, + 131, + 8 + ] + }, + { + "name": "FundingPaymentRecord", + "discriminator": [ + 8, + 59, + 96, + 20, + 137, + 201, + 56, + 95 + ] + }, + { + "name": "FundingRateRecord", + "discriminator": [ + 68, + 3, + 255, + 26, + 133, + 91, + 147, + 254 + ] + }, + { + "name": "InsuranceFundRecord", + "discriminator": [ + 56, + 222, + 215, + 235, + 78, + 197, + 99, + 146 + ] + }, + { + "name": "InsuranceFundStakeRecord", + "discriminator": [ + 68, + 66, + 156, + 7, + 216, + 148, + 250, + 114 + ] + }, + { + "name": "InsuranceFundSwapRecord", + "discriminator": [ + 85, + 190, + 99, + 203, + 237, + 33, + 227, + 100 + ] + }, + { + "name": "LPBorrowLendDepositRecord", + "discriminator": [ + 242, + 181, + 11, + 56, + 243, + 61, + 79, + 210 + ] + }, + { + "name": "LPMintRedeemRecord", + "discriminator": [ + 53, + 178, + 142, + 73, + 78, + 91, + 91, + 8 + ] + }, + { + "name": "LPRecord", + "discriminator": [ + 101, + 22, + 54, + 38, + 178, + 13, + 142, + 111 + ] + }, + { + "name": "LPSettleRecord", + "discriminator": [ + 208, + 191, + 131, + 110, + 173, + 48, + 7, + 2 + ] + }, + { + "name": "LPSwapRecord", + "discriminator": [ + 159, + 62, + 130, + 196, + 96, + 79, + 176, + 254 + ] + }, + { + "name": "LiquidationRecord", + "discriminator": [ + 127, + 17, + 0, + 108, + 182, + 13, + 231, + 53 + ] + }, + { + "name": "NewUserRecord", + "discriminator": [ + 236, + 186, + 113, + 219, + 42, + 51, + 149, + 249 + ] + }, + { + "name": "OrderActionRecord", + "discriminator": [ + 224, + 52, + 67, + 71, + 194, + 237, + 109, + 1 + ] + }, + { + "name": "OrderRecord", + "discriminator": [ + 104, + 19, + 64, + 56, + 89, + 21, + 2, + 90 + ] + }, + { + "name": "RevenueShareSettleRecord", + "discriminator": [ + 61, + 162, + 89, + 10, + 24, + 20, + 59, + 45 + ] + }, + { + "name": "SettlePnlRecord", + "discriminator": [ + 57, + 68, + 105, + 26, + 119, + 198, + 213, + 89 + ] + }, + { + "name": "SignedMsgOrderRecord", + "discriminator": [ + 211, + 197, + 25, + 18, + 142, + 86, + 113, + 27 + ] + }, + { + "name": "SpotInterestRecord", + "discriminator": [ + 183, + 186, + 203, + 186, + 225, + 187, + 95, + 130 + ] + }, + { + "name": "SpotMarketVaultDepositRecord", + "discriminator": [ + 178, + 217, + 23, + 188, + 127, + 190, + 32, + 73 + ] + }, + { + "name": "SwapRecord", + "discriminator": [ + 162, + 187, + 123, + 194, + 138, + 56, + 250, + 241 + ] + }, + { + "name": "TransferProtocolIfSharesToRevenuePoolRecord", + "discriminator": [ + 209, + 118, + 142, + 167, + 130, + 46, + 164, + 151 + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "InvalidEd25519InstructionProgramId", + "msg": "invalid ed25519 instruction program" + }, + { + "code": 6001, + "name": "InvalidEd25519InstructionDataLength", + "msg": "invalid ed25519 instruction data length" + }, + { + "code": 6002, + "name": "InvalidSignatureIndex", + "msg": "invalid signature index" + }, + { + "code": 6003, + "name": "InvalidSignatureOffset", + "msg": "invalid signature offset" + }, + { + "code": 6004, + "name": "InvalidPublicKeyOffset", + "msg": "invalid public key offset" + }, + { + "code": 6005, + "name": "InvalidMessageOffset", + "msg": "invalid message offset" + }, + { + "code": 6006, + "name": "InvalidMessageDataSize", + "msg": "invalid message data size" + }, + { + "code": 6007, + "name": "InvalidInstructionIndex", + "msg": "invalid instruction index" + }, + { + "code": 6008, + "name": "MessageOffsetOverflow", + "msg": "message offset overflow" + }, + { + "code": 6009, + "name": "InvalidMessageHex", + "msg": "invalid message hex" + }, + { + "code": 6010, + "name": "InvalidMessageData", + "msg": "invalid message data" + }, + { + "code": 6011, + "name": "LoadInstructionAtFailed", + "msg": "loading custom ix at index failed" + } + ], + "types": [ + { + "name": "AMM", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "pubkey", + "name": "oracle", "docs": [ - "address of the vault." + "oracle price data public key" ], - "type": "publicKey" - }, - { - "name": "mint", - "type": "publicKey" - }, - { - "name": "whitelistMint", - "type": "publicKey" - }, - { - "name": "constituentTargetBase", - "type": "publicKey" + "type": "pubkey" }, { - "name": "constituentCorrelations", - "type": "publicKey" + "name": "historical_oracle_data", + "docs": [ + "stores historically witnessed oracle data" + ], + "type": { + "defined": { + "name": "HistoricalOracleData" + } + } }, { - "name": "maxAum", + "name": "base_asset_amount_per_lp", "docs": [ - "The current number of VaultConstituents in the vault, each constituent is pda(LPPool.address, constituent_index)", - "which constituent is the quote, receives revenue pool distributions. (maybe this should just be implied idx 0)", - "pub quote_constituent_index: u16,", - "QUOTE_PRECISION: Max AUM, Prohibit minting new DLP beyond this" + "accumulated base asset amount since inception per lp share", + "precision: QUOTE_PRECISION" ], - "type": "u128" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "lastAum", + "name": "quote_asset_amount_per_lp", "docs": [ - "QUOTE_PRECISION: AUM of the vault in USD, updated lazily" + "accumulated quote asset amount since inception per lp share", + "precision: QUOTE_PRECISION" ], - "type": "u128" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "cumulativeQuoteSentToPerpMarkets", + "name": "fee_pool", "docs": [ - "QUOTE PRECISION: Cumulative quotes from settles" + "partition of fees from perp market trading moved from pnl settlements" ], - "type": "u128" - }, - { - "name": "cumulativeQuoteReceivedFromPerpMarkets", - "type": "u128" + "type": { + "defined": { + "name": "PoolBalance" + } + } }, { - "name": "totalMintRedeemFeesPaid", + "name": "base_asset_reserve", "docs": [ - "QUOTE_PRECISION: Total fees paid for minting and redeeming LP tokens" + "`x` reserves for constant product mm formula (x * y = k)", + "precision: AMM_RESERVE_PRECISION" ], - "type": "i128" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "lastAumSlot", + "name": "quote_asset_reserve", "docs": [ - "timestamp of last AUM slot" + "`y` reserves for constant product mm formula (x * y = k)", + "precision: AMM_RESERVE_PRECISION" ], - "type": "u64" - }, - { - "name": "maxSettleQuoteAmount", - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "padding", + "name": "concentration_coef", "docs": [ - "timestamp of last vAMM revenue rebalance" + "determines how close the min/max base asset reserve sit vs base reserves", + "allow for decreasing slippage without increasing liquidity and v.v.", + "precision: PERCENTAGE_PRECISION" ], - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "mintRedeemId", + "name": "min_base_asset_reserve", "docs": [ - "Every mint/redeem has a monotonically increasing id. This is the next id to use" + "minimum base_asset_reserve allowed before AMM is unavailable", + "precision: AMM_RESERVE_PRECISION" ], - "type": "u64" - }, - { - "name": "settleId", - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "minMintFee", + "name": "max_base_asset_reserve", "docs": [ - "PERCENTAGE_PRECISION" + "maximum base_asset_reserve allowed before AMM is unavailable", + "precision: AMM_RESERVE_PRECISION" ], - "type": "i64" - }, - { - "name": "tokenSupply", - "type": "u64" - }, - { - "name": "volatility", - "type": "u64" - }, - { - "name": "constituents", - "type": "u16" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "quoteConsituentIndex", - "type": "u16" + "name": "sqrt_k", + "docs": [ + "`sqrt(k)` in constant product mm formula (x * y = k). stored to avoid drift caused by integer math issues", + "precision: AMM_RESERVE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "bump", - "type": "u8" + "name": "peg_multiplier", + "docs": [ + "normalizing numerical factor for y, its use offers lowest slippage in cp-curve when market is balanced", + "precision: PEG_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "gammaExecution", - "type": "u8" + "name": "terminal_quote_asset_reserve", + "docs": [ + "y when market is balanced. stored to save computation", + "precision: AMM_RESERVE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "xi", - "type": "u8" + "name": "base_asset_amount_long", + "docs": [ + "always non-negative. tracks number of total longs in market (regardless of counterparty)", + "precision: BASE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "targetOracleDelayFeeBpsPer10Slots", - "type": "u8" + "name": "base_asset_amount_short", + "docs": [ + "always non-positive. tracks number of total shorts in market (regardless of counterparty)", + "precision: BASE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "targetPositionDelayFeeBpsPer10Slots", - "type": "u8" + "name": "base_asset_amount_with_amm", + "docs": [ + "tracks net position (longs-shorts) in market with AMM as counterparty", + "precision: BASE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "lpPoolId", - "type": "u8" + "name": "base_asset_amount_with_unsettled_lp", + "docs": [ + "tracks net position (longs-shorts) in market with LPs as counterparty", + "precision: BASE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "padding", + "name": "max_open_interest", + "docs": [ + "max allowed open interest, blocks trades that breach this value", + "precision: BASE_PRECISION" + ], "type": { - "array": [ - "u8", - 174 - ] + "defined": { + "name": "u128" + } } - } - ] - } - }, - { - "name": "Constituent", - "type": { - "kind": "struct", - "fields": [ + }, { - "name": "pubkey", + "name": "quote_asset_amount", "docs": [ - "address of the constituent" + "sum of all user's perp quote_asset_amount in market", + "precision: QUOTE_PRECISION" ], - "type": "publicKey" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "mint", - "type": "publicKey" + "name": "quote_entry_amount_long", + "docs": [ + "sum of all long user's quote_entry_amount in market", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "lpPool", - "type": "publicKey" + "name": "quote_entry_amount_short", + "docs": [ + "sum of all short user's quote_entry_amount in market", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "vault", - "type": "publicKey" + "name": "quote_break_even_amount_long", + "docs": [ + "sum of all long user's quote_break_even_amount in market", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "totalSwapFees", + "name": "quote_break_even_amount_short", "docs": [ - "total fees received by the constituent. Positive = fees received, Negative = fees paid" + "sum of all short user's quote_break_even_amount in market", + "precision: QUOTE_PRECISION" ], - "type": "i128" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "spotBalance", + "name": "user_lp_shares", "docs": [ - "spot borrow-lend balance for constituent" + "total user lp shares of sqrt_k (protocol owned liquidity = sqrt_k - last_funding_rate)", + "precision: AMM_RESERVE_PRECISION" ], "type": { - "defined": "ConstituentSpotBalance" + "defined": { + "name": "u128" + } } }, { - "name": "lastSpotBalanceTokenAmount", + "name": "last_funding_rate", + "docs": [ + "last funding rate in this perp market (unit is quote per base)", + "precision: FUNDING_RATE_PRECISION" + ], "type": "i64" }, { - "name": "cumulativeSpotInterestAccruedTokenAmount", + "name": "last_funding_rate_long", + "docs": [ + "last funding rate for longs in this perp market (unit is quote per base)", + "precision: FUNDING_RATE_PRECISION" + ], "type": "i64" }, { - "name": "maxWeightDeviation", + "name": "last_funding_rate_short", "docs": [ - "max deviation from target_weight allowed for the constituent", - "precision: PERCENTAGE_PRECISION" + "last funding rate for shorts in this perp market (unit is quote per base)", + "precision: QUOTE_PRECISION" ], "type": "i64" }, { - "name": "swapFeeMin", + "name": "last_24h_avg_funding_rate", "docs": [ - "min fee charged on swaps to/from this constituent", - "precision: PERCENTAGE_PRECISION" + "estimate of last 24h of funding rate perp market (unit is quote per base)", + "precision: QUOTE_PRECISION" ], "type": "i64" }, { - "name": "swapFeeMax", + "name": "total_fee", "docs": [ - "max fee charged on swaps to/from this constituent", - "precision: PERCENTAGE_PRECISION" + "total fees collected by this perp market", + "precision: QUOTE_PRECISION" ], - "type": "i64" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "maxBorrowTokenAmount", + "name": "total_mm_fee", "docs": [ - "Max Borrow amount:", - "precision: token precision" + "total fees collected by the vAMM's bid/ask spread", + "precision: QUOTE_PRECISION" ], - "type": "u64" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "vaultTokenBalance", + "name": "total_exchange_fee", "docs": [ - "ata token balance in token precision" + "total fees collected by exchange fee schedule", + "precision: QUOTE_PRECISION" ], - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "lastOraclePrice", - "type": "i64" + "name": "total_fee_minus_distributions", + "docs": [ + "total fees minus any recognized upnl and pool withdraws", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "lastOracleSlot", - "type": "u64" + "name": "total_fee_withdrawn", + "docs": [ + "sum of all fees from fee pool withdrawn to revenue pool", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "oracleStalenessThreshold", + "name": "total_liquidation_fee", "docs": [ - "Delay allowed for valid AUM calculation" + "all fees collected by market for liquidations", + "precision: QUOTE_PRECISION" ], - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "flashLoanInitialTokenAmount", - "type": "u64" + "name": "cumulative_funding_rate_long", + "docs": [ + "accumulated funding rate for longs since inception in market" + ], + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "nextSwapId", + "name": "cumulative_funding_rate_short", "docs": [ - "Every swap to/from this constituent has a monotonically increasing id. This is the next id to use" + "accumulated funding rate for shorts since inception in market" ], - "type": "u64" + "type": { + "defined": { + "name": "i128" + } + } }, { - "name": "derivativeWeight", + "name": "total_social_loss", "docs": [ - "percentable of derivatve weight to go to this specific derivative PERCENTAGE_PRECISION. Zero if no derivative weight" - ], - "type": "u64" - }, - { - "name": "volatility", - "type": "u64" - }, - { - "name": "constituentDerivativeDepegThreshold", - "type": "u64" - }, - { - "name": "constituentDerivativeIndex", - "docs": [ - "The `constituent_index` of the parent constituent. -1 if it is a parent index", - "Example: if in a pool with SOL (parent) and dSOL (derivative),", - "SOL.constituent_index = 1, SOL.constituent_derivative_index = -1,", - "dSOL.constituent_index = 2, dSOL.constituent_derivative_index = 1" + "accumulated social loss paid by users since inception in market" ], - "type": "i16" - }, - { - "name": "spotMarketIndex", - "type": "u16" - }, - { - "name": "constituentIndex", - "type": "u16" - }, - { - "name": "decimals", - "type": "u8" - }, - { - "name": "bump", - "type": "u8" - }, - { - "name": "vaultBump", - "type": "u8" - }, - { - "name": "gammaInventory", - "type": "u8" - }, - { - "name": "gammaExecution", - "type": "u8" - }, - { - "name": "xi", - "type": "u8" - }, - { - "name": "status", - "type": "u8" - }, - { - "name": "pausedOperations", - "type": "u8" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 162 - ] - } - } - ] - } - }, - { - "name": "AmmConstituentMapping", - "type": { - "kind": "struct", - "fields": [ - { - "name": "lpPool", - "type": "publicKey" - }, - { - "name": "bump", - "type": "u8" - }, - { - "name": "padding", "type": { - "array": [ - "u8", - 3 - ] + "defined": { + "name": "u128" + } } }, { - "name": "weights", + "name": "ask_base_asset_reserve", + "docs": [ + "transformed base_asset_reserve for users going long", + "precision: AMM_RESERVE_PRECISION" + ], "type": { - "vec": { - "defined": "AmmConstituentDatum" + "defined": { + "name": "u128" } } - } - ] - } - }, - { - "name": "ConstituentTargetBase", - "type": { - "kind": "struct", - "fields": [ - { - "name": "lpPool", - "type": "publicKey" - }, - { - "name": "bump", - "type": "u8" }, { - "name": "padding", + "name": "ask_quote_asset_reserve", + "docs": [ + "transformed quote_asset_reserve for users going long", + "precision: AMM_RESERVE_PRECISION" + ], "type": { - "array": [ - "u8", - 3 - ] + "defined": { + "name": "u128" + } } }, { - "name": "targets", + "name": "bid_base_asset_reserve", + "docs": [ + "transformed base_asset_reserve for users going short", + "precision: AMM_RESERVE_PRECISION" + ], "type": { - "vec": { - "defined": "TargetsDatum" + "defined": { + "name": "u128" } } - } - ] - } - }, - { - "name": "ConstituentCorrelations", - "type": { - "kind": "struct", - "fields": [ - { - "name": "lpPool", - "type": "publicKey" - }, - { - "name": "bump", - "type": "u8" }, { - "name": "padding", + "name": "bid_quote_asset_reserve", + "docs": [ + "transformed quote_asset_reserve for users going short", + "precision: AMM_RESERVE_PRECISION" + ], "type": { - "array": [ - "u8", - 3 - ] + "defined": { + "name": "u128" + } } }, { - "name": "correlations", - "type": { - "vec": "i64" - } - } - ] - } - }, - { - "name": "PrelaunchOracle", - "type": { - "kind": "struct", - "fields": [ - { - "name": "price", + "name": "last_oracle_normalised_price", + "docs": [ + "the last seen oracle price partially shrunk toward the amm reserve price", + "precision: PRICE_PRECISION" + ], "type": "i64" }, { - "name": "maxPrice", + "name": "last_oracle_reserve_price_spread_pct", + "docs": [ + "the gap between the oracle price and the reserve price = y * peg_multiplier / x" + ], "type": "i64" }, { - "name": "confidence", - "type": "u64" - }, - { - "name": "lastUpdateSlot", + "name": "last_bid_price_twap", + "docs": [ + "average estimate of bid price over funding_period", + "precision: PRICE_PRECISION" + ], "type": "u64" }, { - "name": "ammLastUpdateSlot", + "name": "last_ask_price_twap", + "docs": [ + "average estimate of ask price over funding_period", + "precision: PRICE_PRECISION" + ], "type": "u64" }, { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "padding", - "type": { - "array": [ - "u8", - 70 - ] - } - } - ] - } - }, - { - "name": "PerpMarket", - "type": { - "kind": "struct", - "fields": [ - { - "name": "pubkey", + "name": "last_mark_price_twap", "docs": [ - "The perp market's address. It is a pda of the market index" + "average estimate of (bid+ask)/2 price over funding_period", + "precision: PRICE_PRECISION" ], - "type": "publicKey" + "type": "u64" }, { - "name": "amm", + "name": "last_mark_price_twap_5min", "docs": [ - "The automated market maker" + "average estimate of (bid+ask)/2 price over FIVE_MINUTES" ], - "type": { - "defined": "AMM" - } + "type": "u64" }, { - "name": "pnlPool", + "name": "last_update_slot", "docs": [ - "The market's pnl pool. When users settle negative pnl, the balance increases.", - "When users settle positive pnl, the balance decreases. Can not go negative." + "the last blockchain slot the amm was updated" ], - "type": { - "defined": "PoolBalance" - } + "type": "u64" }, { - "name": "name", + "name": "last_oracle_conf_pct", "docs": [ - "Encoded display name for the perp market e.g. SOL-PERP" + "the pct size of the oracle confidence interval", + "precision: PERCENTAGE_PRECISION" ], - "type": { - "array": [ - "u8", - 32 - ] - } + "type": "u64" }, { - "name": "insuranceClaim", + "name": "net_revenue_since_last_funding", "docs": [ - "The perp market's claim on the insurance fund" + "the total_fee_minus_distribution change since the last funding update", + "precision: QUOTE_PRECISION" ], - "type": { - "defined": "InsuranceClaim" - } + "type": "i64" }, { - "name": "unrealizedPnlMaxImbalance", + "name": "last_funding_rate_ts", "docs": [ - "The max pnl imbalance before positive pnl asset weight is discounted", - "pnl imbalance is the difference between long and short pnl. When it's greater than 0,", - "the amm has negative pnl and the initial asset weight for positive pnl is discounted", - "precision = QUOTE_PRECISION" + "the last funding rate update unix_timestamp" ], - "type": "u64" + "type": "i64" }, { - "name": "expiryTs", + "name": "funding_period", "docs": [ - "The ts when the market will be expired. Only set if market is in reduce only mode" + "the periodicity of the funding rate updates" ], "type": "i64" }, { - "name": "expiryPrice", + "name": "order_step_size", "docs": [ - "The price at which positions will be settled. Only set if market is expired", - "precision = PRICE_PRECISION" + "the base step size (increment) of orders", + "precision: BASE_PRECISION" ], - "type": "i64" + "type": "u64" }, { - "name": "nextFillRecordId", + "name": "order_tick_size", "docs": [ - "Every trade has a fill record id. This is the next id to be used" + "the price tick size of orders", + "precision: PRICE_PRECISION" ], "type": "u64" }, { - "name": "nextFundingRateRecordId", + "name": "min_order_size", "docs": [ - "Every funding rate update has a record id. This is the next id to be used" + "the minimum base size of an order", + "precision: BASE_PRECISION" ], "type": "u64" }, { - "name": "nextCurveRecordId", + "name": "mm_oracle_slot", "docs": [ - "Every amm k updated has a record id. This is the next id to be used" + "the max base size a single user can have", + "precision: BASE_PRECISION" ], "type": "u64" }, { - "name": "imfFactor", + "name": "volume_24h", "docs": [ - "The initial margin fraction factor. Used to increase margin ratio for large positions", - "precision: MARGIN_PRECISION" + "estimated total of volume in market", + "QUOTE_PRECISION" ], - "type": "u32" + "type": "u64" }, { - "name": "unrealizedPnlImfFactor", + "name": "long_intensity_volume", "docs": [ - "The imf factor for unrealized pnl. Used to discount asset weight for large positive pnl", - "precision: MARGIN_PRECISION" + "the volume intensity of long fills against AMM" ], - "type": "u32" + "type": "u64" }, { - "name": "liquidatorFee", + "name": "short_intensity_volume", "docs": [ - "The fee the liquidator is paid for taking over perp position", - "precision: LIQUIDATOR_FEE_PRECISION" + "the volume intensity of short fills against AMM" ], - "type": "u32" + "type": "u64" }, { - "name": "ifLiquidationFee", + "name": "last_trade_ts", "docs": [ - "The fee the insurance fund receives from liquidation", - "precision: LIQUIDATOR_FEE_PRECISION" + "the blockchain unix timestamp at the time of the last trade" ], - "type": "u32" + "type": "i64" }, { - "name": "marginRatioInitial", + "name": "mark_std", "docs": [ - "The margin ratio which determines how much collateral is required to open a position", - "e.g. margin ratio of .1 means a user must have $100 of total collateral to open a $1000 position", - "precision: MARGIN_PRECISION" + "estimate of standard deviation of the fill (mark) prices", + "precision: PRICE_PRECISION" ], - "type": "u32" + "type": "u64" }, { - "name": "marginRatioMaintenance", + "name": "oracle_std", "docs": [ - "The margin ratio which determines when a user will be liquidated", - "e.g. margin ratio of .05 means a user must have $50 of total collateral to maintain a $1000 position", - "else they will be liquidated", - "precision: MARGIN_PRECISION" + "estimate of standard deviation of the oracle price at each update", + "precision: PRICE_PRECISION" ], - "type": "u32" + "type": "u64" }, { - "name": "unrealizedPnlInitialAssetWeight", + "name": "last_mark_price_twap_ts", "docs": [ - "The initial asset weight for positive pnl. Negative pnl always has an asset weight of 1", - "precision: SPOT_WEIGHT_PRECISION" + "the last unix_timestamp the mark twap was updated" ], - "type": "u32" + "type": "i64" }, { - "name": "unrealizedPnlMaintenanceAssetWeight", + "name": "base_spread", "docs": [ - "The maintenance asset weight for positive pnl. Negative pnl always has an asset weight of 1", - "precision: SPOT_WEIGHT_PRECISION" + "the minimum spread the AMM can quote. also used as step size for some spread logic increases." ], "type": "u32" }, { - "name": "numberOfUsersWithBase", + "name": "max_spread", "docs": [ - "number of users in a position (base)" + "the maximum spread the AMM can quote" ], "type": "u32" }, { - "name": "numberOfUsers", + "name": "long_spread", "docs": [ - "number of users in a position (pnl) or pnl (quote)" + "the spread for asks vs the reserve price" ], "type": "u32" }, { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "status", + "name": "short_spread", "docs": [ - "Whether a market is active, reduce only, expired, etc", - "Affects whether users can open/close positions" + "the spread for bids vs the reserve price" ], - "type": { - "defined": "MarketStatus" - } + "type": "u32" }, { - "name": "contractType", + "name": "mm_oracle_price", "docs": [ - "Currently only Perpetual markets are supported" + "MM oracle price" ], - "type": { - "defined": "ContractType" - } + "type": "i64" }, { - "name": "contractTier", + "name": "max_fill_reserve_fraction", "docs": [ - "The contract tier determines how much insurance a market can receive, with more speculative markets receiving less insurance", - "It also influences the order perp markets can be liquidated, with less speculative markets being liquidated first" + "the fraction of total available liquidity a single fill on the AMM can consume" ], - "type": { - "defined": "ContractTier" - } - }, - { - "name": "pausedOperations", - "type": "u8" + "type": "u16" }, { - "name": "quoteSpotMarketIndex", + "name": "max_slippage_ratio", "docs": [ - "The spot market that pnl is settled in" + "the maximum slippage a single fill on the AMM can push" ], "type": "u16" }, { - "name": "feeAdjustment", + "name": "curve_update_intensity", "docs": [ - "Between -100 and 100, represents what % to increase/decrease the fee by", - "E.g. if this is -50 and the fee is 5bps, the new fee will be 2.5bps", - "if this is 50 and the fee is 5bps, the new fee will be 7.5bps" + "the update intensity of AMM formulaic updates (adjusting k). 0-100" ], - "type": "i16" + "type": "u8" }, { - "name": "fuelBoostPosition", + "name": "amm_jit_intensity", "docs": [ - "fuel multiplier for perp funding", - "precision: 10" + "the jit intensity of AMM. larger intensity means larger participation in jit. 0 means no jit participation.", + "(0, 100] is intensity for protocol-owned AMM. (100, 200] is intensity for user LP-owned AMM." ], "type": "u8" }, { - "name": "fuelBoostTaker", + "name": "oracle_source", "docs": [ - "fuel multiplier for perp taker", - "precision: 10" + "the oracle provider information. used to decode/scale the oracle public key" ], - "type": "u8" + "type": { + "defined": { + "name": "OracleSource" + } + } }, { - "name": "fuelBoostMaker", + "name": "last_oracle_valid", "docs": [ - "fuel multiplier for perp maker", - "precision: 10" + "tracks whether the oracle was considered valid at the last AMM update" ], - "type": "u8" + "type": "bool" }, { - "name": "poolId", - "type": "u8" + "name": "target_base_asset_amount_per_lp", + "docs": [ + "the target value for `base_asset_amount_per_lp`, used during AMM JIT with LP split", + "precision: BASE_PRECISION" + ], + "type": "i32" }, { - "name": "highLeverageMarginRatioInitial", - "type": "u16" + "name": "per_lp_base", + "docs": [ + "expo for unit of per_lp, base 10 (if per_lp_base=X, then per_lp unit is 10^X)" + ], + "type": "i8" }, { - "name": "highLeverageMarginRatioMaintenance", - "type": "u16" + "name": "oracle_low_risk_slot_delay_override", + "docs": [ + "the override for the state.min_perp_auction_duration", + "0 is no override, -1 is disable speed bump, 1-100 is literal speed bump" + ], + "type": "i8" }, { - "name": "protectedMakerLimitPriceDivisor", - "type": "u8" + "name": "amm_spread_adjustment", + "docs": [ + "signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)" + ], + "type": "i8" }, { - "name": "protectedMakerDynamicDivisor", - "type": "u8" + "name": "oracle_slot_delay_override", + "type": "i8" }, { - "name": "lpFeeTransferScalar", - "type": "u8" + "name": "mm_oracle_sequence_id", + "type": "u64" }, { - "name": "lpStatus", - "type": "u8" + "name": "net_unsettled_funding_pnl", + "type": "i64" }, { - "name": "lpPausedOperations", - "type": "u8" + "name": "quote_asset_amount_with_unsettled_lp", + "type": "i64" }, { - "name": "lpExchangeFeeExcluscionScalar", - "type": "u8" + "name": "reference_price_offset", + "type": "i32" }, { - "name": "lastFillPrice", - "type": "u64" + "name": "amm_inventory_spread_adjustment", + "docs": [ + "signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)" + ], + "type": "i8" }, { - "name": "lpPoolId", + "name": "reference_price_offset_deadband_pct", "type": "u8" }, { @@ -10363,65 +16606,90 @@ "type": { "array": [ "u8", - 23 + 2 ] } + }, + { + "name": "last_funding_oracle_twap", + "type": "i64" } ] } }, { - "name": "ProtectedMakerModeConfig", + "name": "AddAmmConstituentMappingDatum", "type": { "kind": "struct", "fields": [ { - "name": "maxUsers", - "type": "u32" + "name": "constituent_index", + "type": "u16" }, { - "name": "currentUsers", - "type": "u32" + "name": "perp_market_index", + "type": "u16" }, { - "name": "reduceOnly", + "name": "weight", + "type": "i64" + } + ] + } + }, + { + "name": "AmmCache", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", "type": "u8" }, { - "name": "padding", + "name": "_padding", "type": { "array": [ "u8", - 31 + 3 ] } + }, + { + "name": "cache", + "type": { + "vec": { + "defined": { + "name": "CacheInfo" + } + } + } } ] } }, { - "name": "PythLazerOracle", + "name": "AmmConstituentDatum", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "price", - "type": "i64" - }, - { - "name": "publishTime", - "type": "u64" - }, - { - "name": "postedSlot", - "type": "u64" + "name": "perp_market_index", + "type": "u16" }, { - "name": "exponent", - "type": "i32" + "name": "constituent_index", + "type": "u16" }, { - "name": "padding", + "name": "_padding", "type": { "array": [ "u8", @@ -10430,656 +16698,581 @@ } }, { - "name": "conf", + "name": "last_slot", "type": "u64" + }, + { + "name": "weight", + "docs": [ + "PERCENTAGE_PRECISION. The weight this constituent has on the perp market" + ], + "type": "i64" } ] } }, { - "name": "RevenueShare", + "name": "AmmConstituentMapping", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "authority", - "docs": [ - "the owner of this account, a builder or referrer" - ], - "type": "publicKey" + "name": "lp_pool", + "type": "pubkey" }, { - "name": "totalReferrerRewards", - "type": "u64" - }, - { - "name": "totalBuilderRewards", - "type": "u64" + "name": "bump", + "type": "u8" }, { - "name": "padding", + "name": "_padding", "type": { "array": [ "u8", - 18 + 3 ] } + }, + { + "name": "weights", + "type": { + "vec": { + "defined": { + "name": "AmmConstituentDatum" + } + } + } } ] } }, { - "name": "RevenueShareEscrow", + "name": "AssetTier", "type": { - "kind": "struct", - "fields": [ + "kind": "enum", + "variants": [ { - "name": "authority", - "docs": [ - "the owner of this account, a user" - ], - "type": "publicKey" + "name": "Collateral" }, { - "name": "referrer", - "type": "publicKey" + "name": "Protected" }, { - "name": "referrerBoostExpireTs", - "type": "u32" + "name": "Cross" }, { - "name": "referrerRewardOffset", - "type": "i8" + "name": "Isolated" }, { - "name": "refereeFeeNumeratorOffset", - "type": "i8" + "name": "Unlisted" + } + ] + } + }, + { + "name": "BuilderInfo", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "authority", + "type": "pubkey" }, { - "name": "referrerBoostNumerator", - "type": "i8" + "name": "max_fee_tenth_bps", + "type": "u16" }, { - "name": "reservedFixed", + "name": "padding", "type": { "array": [ "u8", - 17 + 6 ] } - }, - { - "name": "padding0", - "type": "u32" - }, - { - "name": "orders", - "type": { - "vec": { - "defined": "RevenueShareOrder" - } - } - }, - { - "name": "padding1", - "type": "u32" - }, - { - "name": "approvedBuilders", - "type": { - "vec": { - "defined": "BuilderInfo" - } - } } ] } }, { - "name": "SignedMsgUserOrders", - "docs": [ - "* This struct is a duplicate of SignedMsgUserOrdersZeroCopy\n * It is used to give anchor an struct to generate the idl for clients\n * The struct SignedMsgUserOrdersZeroCopy is used to load the data in efficiently" - ], + "name": "CacheInfo", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "authorityPubkey", - "type": "publicKey" + "name": "oracle", + "type": "pubkey" }, { - "name": "padding", - "type": "u32" + "name": "last_fee_pool_token_amount", + "type": "u128" }, { - "name": "signedMsgOrderData", - "type": { - "vec": { - "defined": "SignedMsgOrderId" - } - } - } - ] - } - }, - { - "name": "SignedMsgWsDelegates", - "docs": [ - "* Used to store authenticated delegates for swift-like ws connections" - ], - "type": { - "kind": "struct", - "fields": [ + "name": "last_net_pnl_pool_token_amount", + "type": "i128" + }, { - "name": "delegates", + "name": "last_exchange_fees", + "type": "u128" + }, + { + "name": "last_settle_amm_ex_fees", + "type": "u128" + }, + { + "name": "last_settle_amm_pnl", + "type": "i128" + }, + { + "name": "position", + "docs": [ + "BASE PRECISION" + ], + "type": "i64" + }, + { + "name": "slot", + "type": "u64" + }, + { + "name": "last_settle_amount", + "type": "u64" + }, + { + "name": "last_settle_slot", + "type": "u64" + }, + { + "name": "last_settle_ts", + "type": "i64" + }, + { + "name": "quote_owed_from_lp_pool", + "type": "i64" + }, + { + "name": "amm_inventory_limit", + "type": "i64" + }, + { + "name": "oracle_price", + "type": "i64" + }, + { + "name": "oracle_slot", + "type": "u64" + }, + { + "name": "market_index", + "type": "u16" + }, + { + "name": "oracle_source", + "type": "u8" + }, + { + "name": "oracle_validity", + "type": "u8" + }, + { + "name": "lp_status_for_perp_market", + "type": "u8" + }, + { + "name": "amm_position_scalar", + "type": "u8" + }, + { + "name": "_padding", "type": { - "vec": "publicKey" + "array": [ + "u8", + 34 + ] } } ] } }, { - "name": "SpotMarket", + "name": "Constituent", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { "name": "pubkey", "docs": [ - "The address of the spot market. It is a pda of the market index" + "address of the constituent" ], - "type": "publicKey" + "type": "pubkey" }, { - "name": "oracle", - "docs": [ - "The oracle used to price the markets deposits/borrows" - ], - "type": "publicKey" + "name": "mint", + "type": "pubkey" }, { - "name": "mint", - "docs": [ - "The token mint of the market" - ], - "type": "publicKey" + "name": "lp_pool", + "type": "pubkey" }, { "name": "vault", - "docs": [ - "The vault used to store the market's deposits", - "The amount in the vault should be equal to or greater than deposits - borrows" - ], - "type": "publicKey" + "type": "pubkey" }, { - "name": "name", + "name": "total_swap_fees", "docs": [ - "The encoded display name for the market e.g. SOL" + "total fees received by the constituent. Positive = fees received, Negative = fees paid" ], "type": { - "array": [ - "u8", - 32 - ] - } - }, - { - "name": "historicalOracleData", - "type": { - "defined": "HistoricalOracleData" - } - }, - { - "name": "historicalIndexData", - "type": { - "defined": "HistoricalIndexData" + "defined": { + "name": "i128" + } } }, { - "name": "revenuePool", + "name": "spot_balance", "docs": [ - "Revenue the protocol has collected in this markets token", - "e.g. for SOL-PERP, funds can be settled in usdc and will flow into the USDC revenue pool" + "spot borrow-lend balance for constituent" ], "type": { - "defined": "PoolBalance" + "defined": { + "name": "ConstituentSpotBalance" + } } }, { - "name": "spotFeePool", - "docs": [ - "The fees collected from swaps between this market and the quote market", - "Is settled to the quote markets revenue pool" - ], - "type": { - "defined": "PoolBalance" - } + "name": "last_spot_balance_token_amount", + "type": "i64" }, { - "name": "insuranceFund", - "docs": [ - "Details on the insurance fund covering bankruptcies in this markets token", - "Covers bankruptcies for borrows with this markets token and perps settling in this markets token" - ], - "type": { - "defined": "InsuranceFund" - } + "name": "cumulative_spot_interest_accrued_token_amount", + "type": "i64" }, { - "name": "totalSpotFee", + "name": "max_weight_deviation", "docs": [ - "The total spot fees collected for this market", - "precision: QUOTE_PRECISION" + "max deviation from target_weight allowed for the constituent", + "precision: PERCENTAGE_PRECISION" ], - "type": "u128" + "type": "i64" }, { - "name": "depositBalance", + "name": "swap_fee_min", "docs": [ - "The sum of the scaled balances for deposits across users and pool balances", - "To convert to the deposit token amount, multiply by the cumulative deposit interest", - "precision: SPOT_BALANCE_PRECISION" + "min fee charged on swaps to/from this constituent", + "precision: PERCENTAGE_PRECISION" ], - "type": "u128" + "type": "i64" }, { - "name": "borrowBalance", + "name": "swap_fee_max", "docs": [ - "The sum of the scaled balances for borrows across users and pool balances", - "To convert to the borrow token amount, multiply by the cumulative borrow interest", - "precision: SPOT_BALANCE_PRECISION" + "max fee charged on swaps to/from this constituent", + "precision: PERCENTAGE_PRECISION" ], - "type": "u128" + "type": "i64" }, { - "name": "cumulativeDepositInterest", + "name": "max_borrow_token_amount", "docs": [ - "The cumulative interest earned by depositors", - "Used to calculate the deposit token amount from the deposit balance", - "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + "Max Borrow amount:", + "precision: token precision" ], - "type": "u128" + "type": "u64" }, { - "name": "cumulativeBorrowInterest", + "name": "vault_token_balance", "docs": [ - "The cumulative interest earned by borrowers", - "Used to calculate the borrow token amount from the borrow balance", - "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + "ata token balance in token precision" ], - "type": "u128" + "type": "u64" }, { - "name": "totalSocialLoss", - "docs": [ - "The total socialized loss from borrows, in the mint's token", - "precision: token mint precision" - ], - "type": "u128" + "name": "last_oracle_price", + "type": "i64" }, { - "name": "totalQuoteSocialLoss", - "docs": [ - "The total socialized loss from borrows, in the quote market's token", - "preicision: QUOTE_PRECISION" - ], - "type": "u128" + "name": "last_oracle_slot", + "type": "u64" }, { - "name": "withdrawGuardThreshold", + "name": "oracle_staleness_threshold", "docs": [ - "no withdraw limits/guards when deposits below this threshold", - "precision: token mint precision" + "Delay allowed for valid AUM calculation" ], "type": "u64" }, { - "name": "maxTokenDeposits", - "docs": [ - "The max amount of token deposits in this market", - "0 if there is no limit", - "precision: token mint precision" - ], + "name": "flash_loan_initial_token_amount", "type": "u64" }, { - "name": "depositTokenTwap", + "name": "next_swap_id", "docs": [ - "24hr average of deposit token amount", - "precision: token mint precision" + "Every swap to/from this constituent has a monotonically increasing id. This is the next id to use" ], "type": "u64" }, { - "name": "borrowTokenTwap", + "name": "derivative_weight", "docs": [ - "24hr average of borrow token amount", - "precision: token mint precision" + "percentable of derivatve weight to go to this specific derivative PERCENTAGE_PRECISION. Zero if no derivative weight" ], "type": "u64" }, { - "name": "utilizationTwap", - "docs": [ - "24hr average of utilization", - "which is borrow amount over token amount", - "precision: SPOT_UTILIZATION_PRECISION" - ], + "name": "volatility", "type": "u64" }, { - "name": "lastInterestTs", - "docs": [ - "Last time the cumulative deposit and borrow interest was updated" - ], + "name": "constituent_derivative_depeg_threshold", "type": "u64" }, { - "name": "lastTwapTs", + "name": "constituent_derivative_index", "docs": [ - "Last time the deposit/borrow/utilization averages were updated" + "The `constituent_index` of the parent constituent. -1 if it is a parent index", + "Example: if in a pool with SOL (parent) and dSOL (derivative),", + "SOL.constituent_index = 1, SOL.constituent_derivative_index = -1,", + "dSOL.constituent_index = 2, dSOL.constituent_derivative_index = 1" ], - "type": "u64" + "type": "i16" }, { - "name": "expiryTs", - "docs": [ - "The time the market is set to expire. Only set if market is in reduce only mode" - ], - "type": "i64" + "name": "spot_market_index", + "type": "u16" }, { - "name": "orderStepSize", - "docs": [ - "Spot orders must be a multiple of the step size", - "precision: token mint precision" - ], - "type": "u64" + "name": "constituent_index", + "type": "u16" }, { - "name": "orderTickSize", - "docs": [ - "Spot orders must be a multiple of the tick size", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "decimals", + "type": "u8" }, { - "name": "minOrderSize", - "docs": [ - "The minimum order size", - "precision: token mint precision" - ], - "type": "u64" + "name": "bump", + "type": "u8" }, { - "name": "maxPositionSize", - "docs": [ - "The maximum spot position size", - "if the limit is 0, there is no limit", - "precision: token mint precision" - ], - "type": "u64" - }, - { - "name": "nextFillRecordId", - "docs": [ - "Every spot trade has a fill record id. This is the next id to use" - ], - "type": "u64" + "name": "vault_bump", + "type": "u8" }, { - "name": "nextDepositRecordId", - "docs": [ - "Every deposit has a deposit record id. This is the next id to use" - ], - "type": "u64" + "name": "gamma_inventory", + "type": "u8" }, { - "name": "initialAssetWeight", - "docs": [ - "The initial asset weight used to calculate a deposits contribution to a users initial total collateral", - "e.g. if the asset weight is .8, $100 of deposits contributes $80 to the users initial total collateral", - "precision: SPOT_WEIGHT_PRECISION" - ], - "type": "u32" + "name": "gamma_execution", + "type": "u8" }, { - "name": "maintenanceAssetWeight", - "docs": [ - "The maintenance asset weight used to calculate a deposits contribution to a users maintenance total collateral", - "e.g. if the asset weight is .9, $100 of deposits contributes $90 to the users maintenance total collateral", - "precision: SPOT_WEIGHT_PRECISION" - ], - "type": "u32" + "name": "xi", + "type": "u8" }, { - "name": "initialLiabilityWeight", - "docs": [ - "The initial liability weight used to calculate a borrows contribution to a users initial margin requirement", - "e.g. if the liability weight is .9, $100 of borrows contributes $90 to the users initial margin requirement", - "precision: SPOT_WEIGHT_PRECISION" - ], - "type": "u32" + "name": "status", + "type": "u8" }, { - "name": "maintenanceLiabilityWeight", - "docs": [ - "The maintenance liability weight used to calculate a borrows contribution to a users maintenance margin requirement", - "e.g. if the liability weight is .8, $100 of borrows contributes $80 to the users maintenance margin requirement", - "precision: SPOT_WEIGHT_PRECISION" - ], - "type": "u32" + "name": "paused_operations", + "type": "u8" }, { - "name": "imfFactor", - "docs": [ - "The initial margin fraction factor. Used to increase liability weight/decrease asset weight for large positions", - "precision: MARGIN_PRECISION" - ], - "type": "u32" - }, + "name": "_padding", + "type": { + "array": [ + "u8", + 162 + ] + } + } + ] + } + }, + { + "name": "ConstituentCorrelations", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ { - "name": "liquidatorFee", - "docs": [ - "The fee the liquidator is paid for taking over borrow/deposit", - "precision: LIQUIDATOR_FEE_PRECISION" - ], - "type": "u32" + "name": "lp_pool", + "type": "pubkey" }, { - "name": "ifLiquidationFee", - "docs": [ - "The fee the insurance fund receives from liquidation", - "precision: LIQUIDATOR_FEE_PRECISION" - ], - "type": "u32" + "name": "bump", + "type": "u8" }, { - "name": "optimalUtilization", - "docs": [ - "The optimal utilization rate for this market.", - "Used to determine the markets borrow rate", - "precision: SPOT_UTILIZATION_PRECISION" - ], - "type": "u32" + "name": "_padding", + "type": { + "array": [ + "u8", + 3 + ] + } }, { - "name": "optimalBorrowRate", - "docs": [ - "The borrow rate for this market when the market has optimal utilization", - "precision: SPOT_RATE_PRECISION" - ], - "type": "u32" - }, + "name": "correlations", + "type": { + "vec": "i64" + } + } + ] + } + }, + { + "name": "ConstituentParams", + "type": { + "kind": "struct", + "fields": [ { - "name": "maxBorrowRate", - "docs": [ - "The borrow rate for this market when the market has 1000 utilization", - "precision: SPOT_RATE_PRECISION" - ], - "type": "u32" + "name": "max_weight_deviation", + "type": { + "option": "i64" + } }, { - "name": "decimals", - "docs": [ - "The market's token mint's decimals. To from decimals to a precision, 10^decimals" - ], - "type": "u32" + "name": "swap_fee_min", + "type": { + "option": "i64" + } }, { - "name": "marketIndex", - "type": "u16" + "name": "swap_fee_max", + "type": { + "option": "i64" + } }, { - "name": "ordersEnabled", - "docs": [ - "Whether or not spot trading is enabled" - ], - "type": "bool" + "name": "max_borrow_token_amount", + "type": { + "option": "u64" + } }, { - "name": "oracleSource", + "name": "oracle_staleness_threshold", "type": { - "defined": "OracleSource" + "option": "u64" } }, { - "name": "status", + "name": "cost_to_trade_bps", "type": { - "defined": "MarketStatus" + "option": "i32" } }, { - "name": "assetTier", - "docs": [ - "The asset tier affects how a deposit can be used as collateral and the priority for a borrow being liquidated" - ], + "name": "constituent_derivative_index", "type": { - "defined": "AssetTier" + "option": "i16" } }, { - "name": "pausedOperations", - "type": "u8" + "name": "derivative_weight", + "type": { + "option": "u64" + } }, { - "name": "ifPausedOperations", - "type": "u8" + "name": "volatility", + "type": { + "option": "u64" + } }, { - "name": "feeAdjustment", - "type": "i16" + "name": "gamma_execution", + "type": { + "option": "u8" + } }, { - "name": "maxTokenBorrowsFraction", - "docs": [ - "What fraction of max_token_deposits", - "disabled when 0, 1 => 1/10000 => .01% of max_token_deposits", - "precision: X/10000" - ], - "type": "u16" + "name": "gamma_inventory", + "type": { + "option": "u8" + } }, { - "name": "flashLoanAmount", - "docs": [ - "For swaps, the amount of token loaned out in the begin_swap ix", - "precision: token mint precision" - ], - "type": "u64" - }, + "name": "xi", + "type": { + "option": "u8" + } + } + ] + } + }, + { + "name": "ConstituentSpotBalance", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ { - "name": "flashLoanInitialTokenAmount", + "name": "scaled_balance", "docs": [ - "For swaps, the amount in the users token account in the begin_swap ix", - "Used to calculate how much of the token left the system in end_swap ix", - "precision: token mint precision" + "The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow", + "interest of corresponding market.", + "precision: token precision" ], - "type": "u64" + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "totalSwapFee", + "name": "cumulative_deposits", "docs": [ - "The total fees received from swaps", + "The cumulative deposits/borrows a user has made into a market", "precision: token mint precision" ], - "type": "u64" - }, - { - "name": "scaleInitialAssetWeightStart", - "docs": [ - "When to begin scaling down the initial asset weight", - "disabled when 0", - "precision: QUOTE_PRECISION" - ], - "type": "u64" - }, - { - "name": "minBorrowRate", - "docs": [ - "The min borrow rate for this market when the market regardless of utilization", - "1 => 1/200 => .5%", - "precision: X/200" - ], - "type": "u8" - }, - { - "name": "fuelBoostDeposits", - "docs": [ - "fuel multiplier for spot deposits", - "precision: 10" - ], - "type": "u8" - }, - { - "name": "fuelBoostBorrows", - "docs": [ - "fuel multiplier for spot borrows", - "precision: 10" - ], - "type": "u8" - }, - { - "name": "fuelBoostTaker", - "docs": [ - "fuel multiplier for spot taker", - "precision: 10" - ], - "type": "u8" + "type": "i64" }, { - "name": "fuelBoostMaker", + "name": "market_index", "docs": [ - "fuel multiplier for spot maker", - "precision: 10" + "The market index of the corresponding spot market" ], - "type": "u8" + "type": "u16" }, { - "name": "fuelBoostInsurance", + "name": "balance_type", "docs": [ - "fuel multiplier for spot insurance stake", - "precision: 10" + "Whether the position is deposit or borrow" ], - "type": "u8" - }, - { - "name": "tokenProgramFlag", - "type": "u8" - }, - { - "name": "poolId", - "type": "u8" + "type": { + "defined": { + "name": "SpotBalanceType" + } + } }, { "name": "padding", "type": { "array": [ "u8", - 40 + 5 ] } } @@ -11087,985 +17280,1058 @@ } }, { - "name": "State", + "name": "ConstituentTargetBase", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "admin", - "type": "publicKey" + "name": "lp_pool", + "type": "pubkey" }, { - "name": "whitelistMint", - "type": "publicKey" + "name": "bump", + "type": "u8" }, { - "name": "discountMint", - "type": "publicKey" + "name": "_padding", + "type": { + "array": [ + "u8", + 3 + ] + } }, { - "name": "signer", - "type": "publicKey" + "name": "targets", + "type": { + "vec": { + "defined": { + "name": "TargetsDatum" + } + } + } + } + ] + } + }, + { + "name": "ContractTier", + "type": { + "kind": "enum", + "variants": [ + { + "name": "A" }, { - "name": "srmVault", - "type": "publicKey" + "name": "B" }, { - "name": "perpFeeStructure", - "type": { - "defined": "FeeStructure" - } + "name": "C" }, { - "name": "spotFeeStructure", - "type": { - "defined": "FeeStructure" - } + "name": "Speculative" }, { - "name": "oracleGuardRails", - "type": { - "defined": "OracleGuardRails" - } + "name": "HighlySpeculative" }, { - "name": "numberOfAuthorities", - "type": "u64" + "name": "Isolated" + } + ] + } + }, + { + "name": "ContractType", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Perpetual" }, { - "name": "numberOfSubAccounts", - "type": "u64" + "name": "Future" + }, + { + "name": "Prediction" + } + ] + } + }, + { + "name": "CurveRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" }, { - "name": "lpCooldownTime", + "name": "record_id", "type": "u64" }, { - "name": "liquidationMarginBufferRatio", - "type": "u32" + "name": "peg_multiplier_before", + "type": "u128" }, { - "name": "settlementDuration", - "type": "u16" + "name": "base_asset_reserve_before", + "type": "u128" }, { - "name": "numberOfMarkets", - "type": "u16" + "name": "quote_asset_reserve_before", + "type": "u128" }, { - "name": "numberOfSpotMarkets", - "type": "u16" + "name": "sqrt_k_before", + "type": "u128" }, { - "name": "signerNonce", - "type": "u8" + "name": "peg_multiplier_after", + "type": "u128" }, { - "name": "minPerpAuctionDuration", - "type": "u8" + "name": "base_asset_reserve_after", + "type": "u128" }, { - "name": "defaultMarketOrderTimeInForce", - "type": "u8" + "name": "quote_asset_reserve_after", + "type": "u128" }, { - "name": "defaultSpotAuctionDuration", - "type": "u8" + "name": "sqrt_k_after", + "type": "u128" }, { - "name": "exchangeStatus", - "type": "u8" + "name": "base_asset_amount_long", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "u128" }, { - "name": "liquidationDuration", - "type": "u8" + "name": "base_asset_amount_short", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "u128" }, { - "name": "initialPctToLiquidate", - "type": "u16" + "name": "base_asset_amount_with_amm", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "i128" }, { - "name": "maxNumberOfSubAccounts", - "type": "u16" + "name": "total_fee", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i128" }, { - "name": "maxInitializeUserFee", - "type": "u16" + "name": "total_fee_minus_distributions", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i128" }, { - "name": "featureBitFlags", - "type": "u8" + "name": "adjustment_cost", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i128" }, { - "name": "lpPoolFeatureBitFlags", - "type": "u8" + "name": "oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 8 - ] - } + "name": "fill_record", + "type": "u128" + }, + { + "name": "number_of_users", + "type": "u32" + }, + { + "name": "market_index", + "type": "u16" } ] } }, { - "name": "User", + "name": "DeleteUserRecord", "type": { "kind": "struct", "fields": [ { - "name": "authority", + "name": "ts", "docs": [ - "The owner/authority of the account" + "unix_timestamp of action" ], - "type": "publicKey" + "type": "i64" }, { - "name": "delegate", - "docs": [ - "An addresses that can control the account on the authority's behalf. Has limited power, cant withdraw" - ], - "type": "publicKey" + "name": "user_authority", + "type": "pubkey" }, { - "name": "name", - "docs": [ - "Encoded display name e.g. \"toly\"" - ], - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "user", + "type": "pubkey" }, { - "name": "spotPositions", - "docs": [ - "The user's spot positions" - ], - "type": { - "array": [ - { - "defined": "SpotPosition" - }, - 8 - ] - } + "name": "sub_account_id", + "type": "u16" }, { - "name": "perpPositions", - "docs": [ - "The user's perp positions" - ], + "name": "keeper", "type": { - "array": [ - { - "defined": "PerpPosition" - }, - 8 - ] + "option": "pubkey" } + } + ] + } + }, + { + "name": "DepositDirection", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Deposit" }, { - "name": "orders", - "docs": [ - "The user's orders" - ], - "type": { - "array": [ - { - "defined": "Order" - }, - 32 - ] - } + "name": "Withdraw" + } + ] + } + }, + { + "name": "DepositExplanation", + "type": { + "kind": "enum", + "variants": [ + { + "name": "None" + }, + { + "name": "Transfer" + }, + { + "name": "Borrow" + }, + { + "name": "RepayBorrow" }, { - "name": "lastAddPerpLpSharesTs", + "name": "Reward" + } + ] + } + }, + { + "name": "DepositRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", "docs": [ - "The last time the user added perp lp positions" + "unix_timestamp of action" ], "type": "i64" }, { - "name": "totalDeposits", - "docs": [ - "The total values of deposits the user has made", - "precision: QUOTE_PRECISION" - ], - "type": "u64" + "name": "user_authority", + "type": "pubkey" }, { - "name": "totalWithdraws", + "name": "user", "docs": [ - "The total values of withdrawals the user has made", - "precision: QUOTE_PRECISION" + "user account public key" ], + "type": "pubkey" + }, + { + "name": "direction", + "type": { + "defined": { + "name": "DepositDirection" + } + } + }, + { + "name": "deposit_record_id", "type": "u64" }, { - "name": "totalSocialLoss", + "name": "amount", "docs": [ - "The total socialized loss the users has incurred upon the protocol", - "precision: QUOTE_PRECISION" + "precision: token mint precision" ], "type": "u64" }, { - "name": "settledPerpPnl", + "name": "market_index", "docs": [ - "Fees (taker fees, maker rebate, referrer reward, filler reward) and pnl for perps", - "precision: QUOTE_PRECISION" + "spot market index" ], - "type": "i64" + "type": "u16" }, { - "name": "cumulativeSpotFees", + "name": "oracle_price", "docs": [ - "Fees (taker fees, maker rebate, filler reward) for spot", - "precision: QUOTE_PRECISION" + "precision: PRICE_PRECISION" ], "type": "i64" }, { - "name": "cumulativePerpFunding", + "name": "market_deposit_balance", "docs": [ - "Cumulative funding paid/received for perps", - "precision: QUOTE_PRECISION" + "precision: SPOT_BALANCE_PRECISION" ], - "type": "i64" + "type": "u128" }, { - "name": "liquidationMarginFreed", + "name": "market_withdraw_balance", "docs": [ - "The amount of margin freed during liquidation. Used to force the liquidation to occur over a period of time", - "Defaults to zero when not being liquidated", - "precision: QUOTE_PRECISION" + "precision: SPOT_BALANCE_PRECISION" ], - "type": "u64" + "type": "u128" }, { - "name": "lastActiveSlot", + "name": "market_cumulative_deposit_interest", "docs": [ - "The last slot a user was active. Used to determine if a user is idle" + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" ], - "type": "u64" + "type": "u128" }, { - "name": "nextOrderId", + "name": "market_cumulative_borrow_interest", "docs": [ - "Every user order has an order id. This is the next order id to be used" + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" ], - "type": "u32" + "type": "u128" }, { - "name": "maxMarginRatio", + "name": "total_deposits_after", "docs": [ - "Custom max initial margin ratio for the user" + "precision: QUOTE_PRECISION" ], - "type": "u32" + "type": "u64" }, { - "name": "nextLiquidationId", + "name": "total_withdraws_after", "docs": [ - "The next liquidation id to be used for user" + "precision: QUOTE_PRECISION" ], - "type": "u16" + "type": "u64" }, { - "name": "subAccountId", - "docs": [ - "The sub account id for this user" - ], - "type": "u16" + "name": "explanation", + "type": { + "defined": { + "name": "DepositExplanation" + } + } }, { - "name": "status", - "docs": [ - "Whether the user is active, being liquidated or bankrupt" - ], - "type": "u8" + "name": "transfer_user", + "type": { + "option": "pubkey" + } }, { - "name": "isMarginTradingEnabled", - "docs": [ - "Whether the user has enabled margin trading" - ], - "type": "bool" + "name": "signer", + "type": { + "option": "pubkey" + } }, { - "name": "idle", + "name": "user_token_amount_after", "docs": [ - "User is idle if they haven't interacted with the protocol in 1 week and they have no orders, perp positions or borrows", - "Off-chain keeper bots can ignore users that are idle" + "precision: token mint precision" ], - "type": "bool" + "type": "i128" + } + ] + } + }, + { + "name": "FeeStructure", + "type": { + "kind": "struct", + "fields": [ + { + "name": "fee_tiers", + "type": { + "array": [ + { + "defined": { + "name": "FeeTier" + } + }, + 10 + ] + } }, { - "name": "openOrders", - "docs": [ - "number of open orders" - ], - "type": "u8" + "name": "filler_reward_structure", + "type": { + "defined": { + "name": "OrderFillerRewardStructure" + } + } }, { - "name": "hasOpenOrder", - "docs": [ - "Whether or not user has open order" - ], - "type": "bool" + "name": "referrer_reward_epoch_upper_bound", + "type": "u64" }, { - "name": "openAuctions", - "docs": [ - "number of open orders with auction" - ], - "type": "u8" + "name": "flat_filler_fee", + "type": "u64" + } + ] + } + }, + { + "name": "FeeTier", + "type": { + "kind": "struct", + "fields": [ + { + "name": "fee_numerator", + "type": "u32" }, { - "name": "hasOpenAuction", - "docs": [ - "Whether or not user has open order with auction" - ], - "type": "bool" + "name": "fee_denominator", + "type": "u32" }, { - "name": "marginMode", - "type": { - "defined": "MarginMode" - } + "name": "maker_rebate_numerator", + "type": "u32" }, { - "name": "poolId", - "type": "u8" + "name": "maker_rebate_denominator", + "type": "u32" }, { - "name": "padding1", - "type": { - "array": [ - "u8", - 3 - ] - } + "name": "referrer_reward_numerator", + "type": "u32" }, { - "name": "lastFuelBonusUpdateTs", + "name": "referrer_reward_denominator", "type": "u32" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 12 - ] - } + "name": "referee_fee_numerator", + "type": "u32" + }, + { + "name": "referee_fee_denominator", + "type": "u32" } ] } }, { - "name": "UserStats", + "name": "FuelOverflow", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { "name": "authority", "docs": [ - "The authority for all of a users sub accounts" + "The authority of this overflow account" ], - "type": "publicKey" + "type": "pubkey" }, { - "name": "referrer", - "docs": [ - "The address that referred this user" - ], - "type": "publicKey" + "name": "fuel_insurance", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "fees", - "docs": [ - "Stats on the fees paid by the user" - ], + "name": "fuel_deposits", "type": { - "defined": "UserFees" + "defined": { + "name": "u128" + } } }, { - "name": "nextEpochTs", - "docs": [ - "The timestamp of the next epoch", - "Epoch is used to limit referrer rewards earned in single epoch" - ], - "type": "i64" + "name": "fuel_borrows", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "makerVolume30d", - "docs": [ - "Rolling 30day maker volume for user", - "precision: QUOTE_PRECISION" - ], - "type": "u64" + "name": "fuel_positions", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "takerVolume30d", - "docs": [ - "Rolling 30day taker volume for user", - "precision: QUOTE_PRECISION" - ], - "type": "u64" + "name": "fuel_taker", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "fillerVolume30d", - "docs": [ - "Rolling 30day filler volume for user", - "precision: QUOTE_PRECISION" - ], - "type": "u64" + "name": "fuel_maker", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "lastMakerVolume30dTs", - "docs": [ - "last time the maker volume was updated" - ], - "type": "i64" + "name": "last_fuel_sweep_ts", + "type": "u32" }, { - "name": "lastTakerVolume30dTs", - "docs": [ - "last time the taker volume was updated" - ], - "type": "i64" + "name": "last_reset_ts", + "type": "u32" }, { - "name": "lastFillerVolume30dTs", - "docs": [ - "last time the filler volume was updated" - ], + "name": "padding", + "type": { + "array": [ + "u128", + 6 + ] + } + } + ] + } + }, + { + "name": "FuelSeasonRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", "type": "i64" }, { - "name": "ifStakedQuoteAssetAmount", - "docs": [ - "The amount of tokens staked in the quote spot markets if" - ], - "type": "u64" + "name": "authority", + "type": "pubkey" }, { - "name": "numberOfSubAccounts", - "docs": [ - "The current number of sub accounts" - ], - "type": "u16" + "name": "fuel_insurance", + "type": "u128" }, { - "name": "numberOfSubAccountsCreated", - "docs": [ - "The number of sub accounts created. Can be greater than the number of sub accounts if user", - "has deleted sub accounts" - ], - "type": "u16" + "name": "fuel_deposits", + "type": "u128" }, { - "name": "referrerStatus", - "docs": [ - "Flags for referrer status:", - "First bit (LSB): 1 if user is a referrer, 0 otherwise", - "Second bit: 1 if user was referred, 0 otherwise" - ], - "type": "u8" + "name": "fuel_borrows", + "type": "u128" }, { - "name": "disableUpdatePerpBidAskTwap", - "type": "bool" + "name": "fuel_positions", + "type": "u128" }, { - "name": "pausedOperations", - "type": "u8" + "name": "fuel_taker", + "type": "u128" }, { - "name": "fuelOverflowStatus", - "docs": [ - "whether the user has a FuelOverflow account" - ], - "type": "u8" + "name": "fuel_maker", + "type": "u128" }, { - "name": "fuelInsurance", - "docs": [ - "accumulated fuel for token amounts of insurance" - ], - "type": "u32" + "name": "fuel_total", + "type": "u128" + } + ] + } + }, + { + "name": "FuelSweepRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" }, { - "name": "fuelDeposits", - "docs": [ - "accumulated fuel for notional of deposits" - ], + "name": "authority", + "type": "pubkey" + }, + { + "name": "user_stats_fuel_insurance", "type": "u32" }, { - "name": "fuelBorrows", - "docs": [ - "accumulate fuel bonus for notional of borrows" - ], + "name": "user_stats_fuel_deposits", "type": "u32" }, { - "name": "fuelPositions", - "docs": [ - "accumulated fuel for perp open interest" - ], + "name": "user_stats_fuel_borrows", "type": "u32" }, { - "name": "fuelTaker", - "docs": [ - "accumulate fuel bonus for taker volume" - ], + "name": "user_stats_fuel_positions", "type": "u32" }, { - "name": "fuelMaker", - "docs": [ - "accumulate fuel bonus for maker volume" - ], + "name": "user_stats_fuel_taker", "type": "u32" }, { - "name": "ifStakedGovTokenAmount", - "docs": [ - "The amount of tokens staked in the governance spot markets if" - ], - "type": "u64" + "name": "user_stats_fuel_maker", + "type": "u32" }, { - "name": "lastFuelIfBonusUpdateTs", - "docs": [ - "last unix ts user stats data was used to update if fuel (u32 to save space)" - ], - "type": "u32" + "name": "fuel_overflow_fuel_insurance", + "type": "u128" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 12 - ] - } - } - ] - } - }, - { - "name": "ReferrerName", - "type": { - "kind": "struct", - "fields": [ + "name": "fuel_overflow_fuel_deposits", + "type": "u128" + }, { - "name": "authority", - "type": "publicKey" + "name": "fuel_overflow_fuel_borrows", + "type": "u128" }, { - "name": "user", - "type": "publicKey" + "name": "fuel_overflow_fuel_positions", + "type": "u128" }, { - "name": "userStats", - "type": "publicKey" + "name": "fuel_overflow_fuel_taker", + "type": "u128" }, { - "name": "name", - "type": { - "array": [ - "u8", - 32 - ] - } + "name": "fuel_overflow_fuel_maker", + "type": "u128" } ] } }, { - "name": "FuelOverflow", + "name": "FundingPaymentRecord", "type": { "kind": "struct", "fields": [ { - "name": "authority", - "docs": [ - "The authority of this overflow account" - ], - "type": "publicKey" - }, - { - "name": "fuelInsurance", - "type": "u128" + "name": "ts", + "type": "i64" }, { - "name": "fuelDeposits", - "type": "u128" + "name": "user_authority", + "type": "pubkey" }, { - "name": "fuelBorrows", - "type": "u128" + "name": "user", + "type": "pubkey" }, { - "name": "fuelPositions", - "type": "u128" + "name": "market_index", + "type": "u16" }, { - "name": "fuelTaker", - "type": "u128" + "name": "funding_payment", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "fuelMaker", - "type": "u128" + "name": "base_asset_amount", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "i64" }, { - "name": "lastFuelSweepTs", - "type": "u32" + "name": "user_last_cumulative_funding", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i64" }, { - "name": "lastResetTs", - "type": "u32" + "name": "amm_cumulative_funding_long", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" }, { - "name": "padding", - "type": { - "array": [ - "u128", - 6 - ] - } + "name": "amm_cumulative_funding_short", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" } ] } - } - ], - "types": [ + }, { - "name": "UpdatePerpMarketSummaryStatsParams", + "name": "FundingRateRecord", "type": { "kind": "struct", "fields": [ { - "name": "quoteAssetAmountWithUnsettledLp", - "type": { - "option": "i64" - } - }, - { - "name": "netUnsettledFundingPnl", - "type": { - "option": "i64" - } - }, - { - "name": "updateAmmSummaryStats", - "type": { - "option": "bool" - } + "name": "ts", + "type": "i64" }, { - "name": "excludeTotalLiqFee", - "type": { - "option": "bool" - } - } - ] - } - }, - { - "name": "ConstituentParams", - "type": { - "kind": "struct", - "fields": [ - { - "name": "maxWeightDeviation", - "type": { - "option": "i64" - } + "name": "record_id", + "type": "u64" }, { - "name": "swapFeeMin", - "type": { - "option": "i64" - } + "name": "market_index", + "type": "u16" }, { - "name": "swapFeeMax", - "type": { - "option": "i64" - } + "name": "funding_rate", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i64" }, { - "name": "maxBorrowTokenAmount", - "type": { - "option": "u64" - } + "name": "funding_rate_long", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" }, { - "name": "oracleStalenessThreshold", - "type": { - "option": "u64" - } + "name": "funding_rate_short", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" }, { - "name": "costToTradeBps", - "type": { - "option": "i32" - } + "name": "cumulative_funding_rate_long", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" }, { - "name": "constituentDerivativeIndex", - "type": { - "option": "i16" - } + "name": "cumulative_funding_rate_short", + "docs": [ + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i128" }, { - "name": "derivativeWeight", - "type": { - "option": "u64" - } + "name": "oracle_price_twap", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "volatility", - "type": { - "option": "u64" - } + "name": "mark_price_twap", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "gammaExecution", - "type": { - "option": "u8" - } + "name": "period_revenue", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "gammaInventory", - "type": { - "option": "u8" - } + "name": "base_asset_amount_with_amm", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "i128" }, { - "name": "xi", - "type": { - "option": "u8" - } + "name": "base_asset_amount_with_unsettled_lp", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "i128" } ] } }, { - "name": "LpPoolParams", + "name": "HighLeverageModeConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "maxSettleQuoteAmount", - "type": { - "option": "u64" - } + "name": "max_users", + "type": "u32" }, { - "name": "volatility", - "type": { - "option": "u64" - } + "name": "current_users", + "type": "u32" }, { - "name": "gammaExecution", - "type": { - "option": "u8" - } + "name": "reduce_only", + "type": "u8" }, { - "name": "xi", + "name": "padding1", "type": { - "option": "u8" + "array": [ + "u8", + 3 + ] } }, { - "name": "maxAum", - "type": { - "option": "u128" - } + "name": "current_maintenance_users", + "type": "u32" }, { - "name": "whitelistMint", + "name": "padding2", "type": { - "option": "publicKey" + "array": [ + "u8", + 24 + ] } } ] } }, { - "name": "OverrideAmmCacheParams", + "name": "HistoricalIndexData", "type": { "kind": "struct", "fields": [ { - "name": "quoteOwedFromLpPool", - "type": { - "option": "i64" - } + "name": "last_index_bid_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "lastSettleSlot", - "type": { - "option": "u64" - } - }, - { - "name": "lastFeePoolTokenAmount", - "type": { - "option": "u128" - } + "name": "last_index_ask_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "lastNetPnlPoolTokenAmount", - "type": { - "option": "i128" - } + "name": "last_index_price_twap", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "ammPositionScalar", - "type": { - "option": "u8" - } + "name": "last_index_price_twap_5min", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "ammInventoryLimit", - "type": { - "option": "i64" - } + "name": "last_index_price_twap_ts", + "docs": [ + "unix_timestamp of last snapshot" + ], + "type": "i64" } ] } }, { - "name": "AddAmmConstituentMappingDatum", + "name": "HistoricalOracleData", "type": { "kind": "struct", "fields": [ { - "name": "constituentIndex", - "type": "u16" + "name": "last_oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "perpMarketIndex", - "type": "u16" + "name": "last_oracle_conf", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "weight", + "name": "last_oracle_delay", + "docs": [ + "number of slots since last update" + ], + "type": "i64" + }, + { + "name": "last_oracle_price_twap", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" + }, + { + "name": "last_oracle_price_twap_5min", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" + }, + { + "name": "last_oracle_price_twap_ts", + "docs": [ + "unix_timestamp of last snapshot" + ], "type": "i64" } ] } }, { - "name": "CacheInfo", + "name": "IfRebalanceConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "oracle", - "type": "publicKey" - }, - { - "name": "lastFeePoolTokenAmount", - "type": "u128" - }, - { - "name": "lastNetPnlPoolTokenAmount", - "type": "i128" - }, - { - "name": "lastExchangeFees", - "type": "u128" - }, - { - "name": "lastSettleAmmExFees", - "type": "u128" + "name": "pubkey", + "type": "pubkey" }, { - "name": "lastSettleAmmPnl", - "type": "i128" + "name": "total_in_amount", + "docs": [ + "total amount to be sold" + ], + "type": "u64" }, { - "name": "position", + "name": "current_in_amount", "docs": [ - "BASE PRECISION" + "amount already sold" ], - "type": "i64" + "type": "u64" }, { - "name": "slot", + "name": "current_out_amount", + "docs": [ + "amount already bought" + ], "type": "u64" }, { - "name": "lastSettleAmount", + "name": "current_out_amount_transferred", + "docs": [ + "amount already transferred to revenue pool" + ], "type": "u64" }, { - "name": "lastSettleSlot", + "name": "current_in_amount_since_last_transfer", + "docs": [ + "amount already bought in epoch" + ], "type": "u64" }, { - "name": "lastSettleTs", + "name": "epoch_start_ts", + "docs": [ + "start time of epoch" + ], "type": "i64" }, { - "name": "quoteOwedFromLpPool", - "type": "i64" + "name": "epoch_in_amount", + "docs": [ + "amount already bought in epoch" + ], + "type": "u64" }, { - "name": "ammInventoryLimit", - "type": "i64" + "name": "epoch_max_in_amount", + "docs": [ + "max amount to swap in epoch" + ], + "type": "u64" }, { - "name": "oraclePrice", + "name": "epoch_duration", + "docs": [ + "duration of epoch" + ], "type": "i64" }, { - "name": "oracleSlot", - "type": "u64" - }, - { - "name": "marketIndex", + "name": "out_market_index", + "docs": [ + "market index to sell" + ], "type": "u16" }, { - "name": "oracleSource", - "type": "u8" + "name": "in_market_index", + "docs": [ + "market index to buy" + ], + "type": "u16" }, { - "name": "oracleValidity", - "type": "u8" + "name": "max_slippage_bps", + "type": "u16" }, { - "name": "lpStatusForPerpMarket", + "name": "swap_mode", "type": "u8" }, { - "name": "ammPositionScalar", + "name": "status", "type": "u8" }, { - "name": "padding", + "name": "padding2", "type": { "array": [ "u8", - 34 + 32 ] } } @@ -12073,1803 +18339,1652 @@ } }, { - "name": "AmmCacheFixed", + "name": "IfRebalanceConfigParams", "type": { "kind": "struct", "fields": [ { - "name": "bump", - "type": "u8" + "name": "total_in_amount", + "type": "u64" }, { - "name": "pad", - "type": { - "array": [ - "u8", - 3 - ] - } + "name": "epoch_max_in_amount", + "type": "u64" }, { - "name": "len", - "type": "u32" + "name": "epoch_duration", + "type": "i64" + }, + { + "name": "out_market_index", + "type": "u16" + }, + { + "name": "in_market_index", + "type": "u16" + }, + { + "name": "max_slippage_bps", + "type": "u16" + }, + { + "name": "swap_mode", + "type": "u8" + }, + { + "name": "status", + "type": "u8" } ] } }, { - "name": "LiquidatePerpRecord", + "name": "InsuranceClaim", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "oraclePrice", - "type": "i64" - }, - { - "name": "baseAssetAmount", - "type": "i64" - }, - { - "name": "quoteAssetAmount", + "name": "revenue_withdraw_since_last_settle", + "docs": [ + "The amount of revenue last settled", + "Positive if funds left the perp market,", + "negative if funds were pulled into the perp market", + "precision: QUOTE_PRECISION" + ], "type": "i64" }, { - "name": "lpShares", + "name": "max_revenue_withdraw_per_period", "docs": [ - "precision: AMM_RESERVE_PRECISION" + "The max amount of revenue that can be withdrawn per period", + "precision: QUOTE_PRECISION" ], "type": "u64" }, { - "name": "fillRecordId", + "name": "quote_max_insurance", + "docs": [ + "The max amount of insurance that perp market can use to resolve bankruptcy and pnl deficits", + "precision: QUOTE_PRECISION" + ], "type": "u64" }, { - "name": "userOrderId", - "type": "u32" - }, - { - "name": "liquidatorOrderId", - "type": "u32" - }, - { - "name": "liquidatorFee", + "name": "quote_settled_insurance", "docs": [ + "The amount of insurance that has been used to resolve bankruptcy and pnl deficits", "precision: QUOTE_PRECISION" ], "type": "u64" }, { - "name": "ifFee", + "name": "last_revenue_withdraw_ts", "docs": [ - "precision: QUOTE_PRECISION" + "The last time revenue was settled in/out of market" ], - "type": "u64" + "type": "i64" } ] } }, { - "name": "LiquidateSpotRecord", + "name": "InsuranceFund", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "assetMarketIndex", - "type": "u16" + "name": "vault", + "type": "pubkey" }, { - "name": "assetPrice", - "type": "i64" + "name": "total_shares", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "assetTransfer", - "type": "u128" + "name": "user_shares", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "liabilityMarketIndex", - "type": "u16" + "name": "shares_base", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "liabilityPrice", + "name": "unstaking_period", "type": "i64" }, { - "name": "liabilityTransfer", - "docs": [ - "precision: token mint precision" - ], - "type": "u128" - }, - { - "name": "ifFee", - "docs": [ - "precision: token mint precision" - ], - "type": "u64" - } - ] - } - }, - { - "name": "LiquidateBorrowForPerpPnlRecord", - "type": { - "kind": "struct", - "fields": [ - { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "marketOraclePrice", + "name": "last_revenue_settle_ts", "type": "i64" }, { - "name": "pnlTransfer", - "type": "u128" - }, - { - "name": "liabilityMarketIndex", - "type": "u16" + "name": "revenue_settle_period", + "type": "i64" }, { - "name": "liabilityPrice", - "type": "i64" + "name": "total_factor", + "type": "u32" }, { - "name": "liabilityTransfer", - "type": "u128" + "name": "user_factor", + "type": "u32" } ] } }, { - "name": "LiquidatePerpPnlForDepositRecord", + "name": "InsuranceFundRecord", "type": { "kind": "struct", "fields": [ { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "marketOraclePrice", + "name": "ts", "type": "i64" }, { - "name": "pnlTransfer", - "type": "u128" - }, - { - "name": "assetMarketIndex", + "name": "spot_market_index", "type": "u16" }, { - "name": "assetPrice", - "type": "i64" + "name": "perp_market_index", + "type": "u16" }, { - "name": "assetTransfer", - "type": "u128" + "name": "user_if_factor", + "docs": [ + "precision: PERCENTAGE_PRECISION" + ], + "type": "u32" + }, + { + "name": "total_if_factor", + "docs": [ + "precision: PERCENTAGE_PRECISION" + ], + "type": "u32" + }, + { + "name": "vault_amount_before", + "docs": [ + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "insurance_vault_amount_before", + "docs": [ + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "total_if_shares_before", + "type": "u128" + }, + { + "name": "total_if_shares_after", + "type": "u128" + }, + { + "name": "amount", + "docs": [ + "precision: token mint precision" + ], + "type": "i64" } ] } }, { - "name": "PerpBankruptcyRecord", + "name": "InsuranceFundStake", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "marketIndex", - "type": "u16" - }, - { - "name": "pnl", - "type": "i128" + "name": "authority", + "type": "pubkey" }, { - "name": "ifPayment", - "type": "u128" + "name": "if_shares", + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "clawbackUser", + "name": "last_withdraw_request_shares", "type": { - "option": "publicKey" + "defined": { + "name": "u128" + } } }, { - "name": "clawbackUserPayment", + "name": "if_base", "type": { - "option": "u128" + "defined": { + "name": "u128" + } } }, { - "name": "cumulativeFundingRateDelta", - "type": "i128" + "name": "last_valid_ts", + "type": "i64" + }, + { + "name": "last_withdraw_request_value", + "type": "u64" + }, + { + "name": "last_withdraw_request_ts", + "type": "i64" + }, + { + "name": "cost_basis", + "type": "i64" + }, + { + "name": "market_index", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 14 + ] + } } ] } }, { - "name": "SpotBankruptcyRecord", + "name": "InsuranceFundStakeRecord", "type": { "kind": "struct", "fields": [ { - "name": "marketIndex", + "name": "ts", + "type": "i64" + }, + { + "name": "user_authority", + "type": "pubkey" + }, + { + "name": "action", + "type": { + "defined": { + "name": "StakeAction" + } + } + }, + { + "name": "amount", + "docs": [ + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "market_index", "type": "u16" }, { - "name": "borrowAmount", + "name": "insurance_vault_amount_before", + "docs": [ + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "if_shares_before", "type": "u128" }, { - "name": "ifPayment", + "name": "user_if_shares_before", "type": "u128" }, { - "name": "cumulativeDepositInterestDelta", + "name": "total_if_shares_before", + "type": "u128" + }, + { + "name": "if_shares_after", + "type": "u128" + }, + { + "name": "user_if_shares_after", + "type": "u128" + }, + { + "name": "total_if_shares_after", "type": "u128" } ] } }, { - "name": "IfRebalanceConfigParams", + "name": "InsuranceFundSwapRecord", "type": { "kind": "struct", "fields": [ { - "name": "totalInAmount", - "type": "u64" + "name": "rebalance_config", + "type": "pubkey" }, { - "name": "epochMaxInAmount", - "type": "u64" + "name": "in_if_total_shares_before", + "type": "u128" }, { - "name": "epochDuration", - "type": "i64" + "name": "out_if_total_shares_before", + "type": "u128" }, { - "name": "outMarketIndex", - "type": "u16" + "name": "in_if_user_shares_before", + "type": "u128" }, { - "name": "inMarketIndex", - "type": "u16" + "name": "out_if_user_shares_before", + "type": "u128" }, { - "name": "maxSlippageBps", - "type": "u16" + "name": "in_if_total_shares_after", + "type": "u128" }, { - "name": "swapMode", - "type": "u8" + "name": "out_if_total_shares_after", + "type": "u128" }, { - "name": "status", - "type": "u8" - } - ] - } - }, - { - "name": "ConstituentSpotBalance", - "type": { - "kind": "struct", - "fields": [ + "name": "in_if_user_shares_after", + "type": "u128" + }, { - "name": "scaledBalance", - "docs": [ - "The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow", - "interest of corresponding market.", - "precision: token precision" - ], + "name": "out_if_user_shares_after", "type": "u128" }, { - "name": "cumulativeDeposits", - "docs": [ - "The cumulative deposits/borrows a user has made into a market", - "precision: token mint precision" - ], + "name": "ts", "type": "i64" }, { - "name": "marketIndex", - "docs": [ - "The market index of the corresponding spot market" - ], - "type": "u16" + "name": "in_amount", + "type": "u64" }, { - "name": "balanceType", - "docs": [ - "Whether the position is deposit or borrow" - ], - "type": { - "defined": "SpotBalanceType" - } + "name": "out_amount", + "type": "u64" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 5 - ] - } - } - ] - } - }, - { - "name": "AmmConstituentDatum", - "type": { - "kind": "struct", - "fields": [ + "name": "out_oracle_price", + "type": "u64" + }, { - "name": "perpMarketIndex", - "type": "u16" + "name": "out_oracle_price_twap", + "type": "i64" }, { - "name": "constituentIndex", - "type": "u16" + "name": "in_vault_amount_before", + "type": "u64" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 4 - ] - } + "name": "out_vault_amount_before", + "type": "u64" }, { - "name": "lastSlot", + "name": "in_fund_vault_amount_after", "type": "u64" }, { - "name": "weight", - "docs": [ - "PERCENTAGE_PRECISION. The weight this constituent has on the perp market" - ], - "type": "i64" + "name": "out_fund_vault_amount_after", + "type": "u64" + }, + { + "name": "in_market_index", + "type": "u16" + }, + { + "name": "out_market_index", + "type": "u16" } ] } }, { - "name": "AmmConstituentMappingFixed", + "name": "LPAction", "type": { - "kind": "struct", - "fields": [ + "kind": "enum", + "variants": [ { - "name": "lpPool", - "type": "publicKey" + "name": "AddLiquidity" }, { - "name": "bump", - "type": "u8" + "name": "RemoveLiquidity" }, { - "name": "pad", - "type": { - "array": [ - "u8", - 3 - ] - } + "name": "SettleLiquidity" }, { - "name": "len", - "type": "u32" + "name": "RemoveLiquidityDerisk" } ] } }, { - "name": "TargetsDatum", + "name": "LPBorrowLendDepositRecord", "type": { "kind": "struct", "fields": [ { - "name": "costToTradeBps", - "type": "i32" + "name": "ts", + "type": "i64" }, { - "name": "padding", + "name": "slot", + "type": "u64" + }, + { + "name": "spot_market_index", + "type": "u16" + }, + { + "name": "constituent_index", + "type": "u16" + }, + { + "name": "direction", "type": { - "array": [ - "u8", - 4 - ] + "defined": { + "name": "DepositDirection" + } } }, { - "name": "targetBase", + "name": "token_balance", "type": "i64" }, { - "name": "lastOracleSlot", - "type": "u64" + "name": "last_token_balance", + "type": "i64" }, { - "name": "lastPositionSlot", + "name": "interest_accrued_token_amount", + "type": "i64" + }, + { + "name": "amount_deposit_withdraw", "type": "u64" + }, + { + "name": "lp_pool", + "type": "pubkey" } ] } }, { - "name": "ConstituentTargetBaseFixed", + "name": "LPMintRedeemRecord", "type": { "kind": "struct", "fields": [ { - "name": "lpPool", - "type": "publicKey" + "name": "ts", + "type": "i64" }, { - "name": "bump", - "type": "u8" + "name": "slot", + "type": "u64" }, { - "name": "pad", - "type": { - "array": [ - "u8", - 3 - ] - } + "name": "authority", + "type": "pubkey" }, { - "name": "len", - "docs": [ - "total elements in the flattened `data` vec" - ], - "type": "u32" - } - ] - } - }, - { - "name": "ConstituentCorrelationsFixed", - "type": { - "kind": "struct", - "fields": [ - { - "name": "lpPool", - "type": "publicKey" - }, - { - "name": "bump", + "name": "description", "type": "u8" }, { - "name": "pad", - "type": { - "array": [ - "u8", - 3 - ] - } + "name": "amount", + "docs": [ + "precision: continutent mint precision, gross fees" + ], + "type": "u128" }, { - "name": "len", + "name": "fee", "docs": [ - "total elements in the flattened `data` vec" + "precision: fee on amount, constituent market mint precision" ], - "type": "u32" - } - ] - } - }, - { - "name": "MarketIdentifier", - "type": { - "kind": "struct", - "fields": [ + "type": "i128" + }, { - "name": "marketType", - "type": { - "defined": "MarketType" - } + "name": "spot_market_index", + "type": "u16" }, { - "name": "marketIndex", + "name": "constituent_index", "type": "u16" - } - ] - } - }, - { - "name": "HistoricalOracleData", - "type": { - "kind": "struct", - "fields": [ + }, { - "name": "lastOraclePrice", + "name": "oracle_price", "docs": [ "precision: PRICE_PRECISION" ], "type": "i64" }, { - "name": "lastOracleConf", + "name": "mint", "docs": [ - "precision: PRICE_PRECISION" + "token mint" ], - "type": "u64" + "type": "pubkey" }, { - "name": "lastOracleDelay", + "name": "lp_amount", "docs": [ - "number of slots since last update" + "lp amount, lp mint precision" ], - "type": "i64" + "type": "u64" }, { - "name": "lastOraclePriceTwap", + "name": "lp_fee", "docs": [ - "precision: PRICE_PRECISION" + "lp fee, lp mint precision" ], "type": "i64" }, { - "name": "lastOraclePriceTwap5min", + "name": "lp_price", "docs": [ - "precision: PRICE_PRECISION" + "the fair price of the lp token, PRICE_PRECISION" ], - "type": "i64" + "type": "u128" }, { - "name": "lastOraclePriceTwapTs", - "docs": [ - "unix_timestamp of last snapshot" - ], - "type": "i64" - } - ] - } - }, - { - "name": "HistoricalIndexData", - "type": { - "kind": "struct", - "fields": [ - { - "name": "lastIndexBidPrice", - "docs": [ - "precision: PRICE_PRECISION" - ], + "name": "mint_redeem_id", "type": "u64" }, { - "name": "lastIndexAskPrice", + "name": "last_aum", "docs": [ - "precision: PRICE_PRECISION" + "LPPool last_aum" ], - "type": "u64" + "type": "u128" }, { - "name": "lastIndexPriceTwap", - "docs": [ - "precision: PRICE_PRECISION" - ], + "name": "last_aum_slot", "type": "u64" }, { - "name": "lastIndexPriceTwap5min", + "name": "in_market_current_weight", "docs": [ - "precision: PRICE_PRECISION" + "PERCENTAGE_PRECISION" ], - "type": "u64" + "type": "i64" }, { - "name": "lastIndexPriceTwapTs", - "docs": [ - "unix_timestamp of last snapshot" - ], + "name": "in_market_target_weight", "type": "i64" + }, + { + "name": "lp_pool", + "type": "pubkey" } ] } }, { - "name": "PrelaunchOracleParams", + "name": "LPPool", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "perpMarketIndex", - "type": "u16" + "name": "pubkey", + "docs": [ + "address of the vault." + ], + "type": "pubkey" }, { - "name": "price", + "name": "mint", + "type": "pubkey" + }, + { + "name": "whitelist_mint", + "type": "pubkey" + }, + { + "name": "constituent_target_base", + "type": "pubkey" + }, + { + "name": "constituent_correlations", + "type": "pubkey" + }, + { + "name": "max_aum", + "docs": [ + "The current number of VaultConstituents in the vault, each constituent is pda(LPPool.address, constituent_index)", + "which constituent is the quote, receives revenue pool distributions. (maybe this should just be implied idx 0)", + "pub quote_constituent_index: u16,", + "QUOTE_PRECISION: Max AUM, Prohibit minting new DLP beyond this" + ], "type": { - "option": "i64" + "defined": { + "name": "u128" + } } }, { - "name": "maxPrice", + "name": "last_aum", + "docs": [ + "QUOTE_PRECISION: AUM of the vault in USD, updated lazily" + ], "type": { - "option": "i64" + "defined": { + "name": "u128" + } } - } - ] - } - }, - { - "name": "OrderParams", - "type": { - "kind": "struct", - "fields": [ + }, { - "name": "orderType", + "name": "cumulative_quote_sent_to_perp_markets", + "docs": [ + "QUOTE PRECISION: Cumulative quotes from settles" + ], "type": { - "defined": "OrderType" + "defined": { + "name": "u128" + } } }, { - "name": "marketType", + "name": "cumulative_quote_received_from_perp_markets", "type": { - "defined": "MarketType" + "defined": { + "name": "u128" + } } }, { - "name": "direction", + "name": "total_mint_redeem_fees_paid", + "docs": [ + "QUOTE_PRECISION: Total fees paid for minting and redeeming LP tokens" + ], "type": { - "defined": "PositionDirection" + "defined": { + "name": "i128" + } } }, { - "name": "userOrderId", - "type": "u8" + "name": "last_aum_slot", + "docs": [ + "timestamp of last AUM slot" + ], + "type": "u64" }, { - "name": "baseAssetAmount", + "name": "max_settle_quote_amount", "type": "u64" }, { - "name": "price", + "name": "_padding", + "docs": [ + "timestamp of last vAMM revenue rebalance" + ], "type": "u64" }, { - "name": "marketIndex", - "type": "u16" + "name": "mint_redeem_id", + "docs": [ + "Every mint/redeem has a monotonically increasing id. This is the next id to use" + ], + "type": "u64" }, { - "name": "reduceOnly", - "type": "bool" + "name": "settle_id", + "type": "u64" }, { - "name": "postOnly", - "type": { - "defined": "PostOnlyParam" - } + "name": "min_mint_fee", + "docs": [ + "PERCENTAGE_PRECISION" + ], + "type": "i64" }, { - "name": "bitFlags", - "type": "u8" + "name": "token_supply", + "type": "u64" }, { - "name": "maxTs", - "type": { - "option": "i64" - } + "name": "volatility", + "type": "u64" }, { - "name": "triggerPrice", - "type": { - "option": "u64" - } + "name": "constituents", + "type": "u16" }, { - "name": "triggerCondition", - "type": { - "defined": "OrderTriggerCondition" - } + "name": "quote_consituent_index", + "type": "u16" }, { - "name": "oraclePriceOffset", - "type": { - "option": "i32" - } + "name": "bump", + "type": "u8" }, { - "name": "auctionDuration", - "type": { - "option": "u8" - } + "name": "gamma_execution", + "type": "u8" }, { - "name": "auctionStartPrice", - "type": { - "option": "i64" - } + "name": "xi", + "type": "u8" + }, + { + "name": "target_oracle_delay_fee_bps_per_10_slots", + "type": "u8" }, { - "name": "auctionEndPrice", + "name": "target_position_delay_fee_bps_per_10_slots", + "type": "u8" + }, + { + "name": "lp_pool_id", + "type": "u8" + }, + { + "name": "padding", "type": { - "option": "i64" + "array": [ + "u8", + 174 + ] } } ] } }, { - "name": "SignedMsgOrderParamsMessage", + "name": "LPRecord", "type": { "kind": "struct", "fields": [ { - "name": "signedMsgOrderParams", - "type": { - "defined": "OrderParams" - } - }, - { - "name": "subAccountId", - "type": "u16" - }, - { - "name": "slot", - "type": "u64" + "name": "ts", + "type": "i64" }, { - "name": "uuid", - "type": { - "array": [ - "u8", - 8 - ] - } + "name": "user", + "type": "pubkey" }, { - "name": "takeProfitOrderParams", + "name": "action", "type": { - "option": { - "defined": "SignedMsgTriggerOrderParams" + "defined": { + "name": "LPAction" } } }, { - "name": "stopLossOrderParams", - "type": { - "option": { - "defined": "SignedMsgTriggerOrderParams" - } - } + "name": "n_shares", + "docs": [ + "precision: AMM_RESERVE_PRECISION" + ], + "type": "u64" }, { - "name": "maxMarginRatio", - "type": { - "option": "u16" - } + "name": "market_index", + "type": "u16" }, { - "name": "builderIdx", - "type": { - "option": "u8" - } + "name": "delta_base_asset_amount", + "docs": [ + "precision: BASE_PRECISION" + ], + "type": "i64" }, { - "name": "builderFeeTenthBps", - "type": { - "option": "u16" - } + "name": "delta_quote_asset_amount", + "docs": [ + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "isolatedPositionDeposit", - "type": { - "option": "u64" - } + "name": "pnl", + "docs": [ + "realized pnl of the position settlement", + "precision: QUOTE_PRECISION" + ], + "type": "i64" } ] } }, { - "name": "SignedMsgOrderParamsDelegateMessage", + "name": "LPSettleRecord", "type": { "kind": "struct", "fields": [ { - "name": "signedMsgOrderParams", - "type": { - "defined": "OrderParams" - } + "name": "record_id", + "type": "u64" + }, + { + "name": "last_ts", + "type": "i64" + }, + { + "name": "last_slot", + "type": "u64" }, { - "name": "takerPubkey", - "type": "publicKey" + "name": "ts", + "type": "i64" }, { "name": "slot", "type": "u64" }, { - "name": "uuid", - "type": { - "array": [ - "u8", - 8 - ] - } + "name": "perp_market_index", + "type": "u16" }, { - "name": "takeProfitOrderParams", - "type": { - "option": { - "defined": "SignedMsgTriggerOrderParams" - } - } + "name": "settle_to_lp_amount", + "type": "i64" }, { - "name": "stopLossOrderParams", - "type": { - "option": { - "defined": "SignedMsgTriggerOrderParams" - } - } + "name": "perp_amm_pnl_delta", + "type": "i64" }, { - "name": "maxMarginRatio", - "type": { - "option": "u16" - } + "name": "perp_amm_ex_fee_delta", + "type": "i64" }, { - "name": "builderIdx", - "type": { - "option": "u8" - } + "name": "lp_aum", + "type": "u128" }, { - "name": "builderFeeTenthBps", - "type": { - "option": "u16" - } + "name": "lp_price", + "type": "u128" }, { - "name": "isolatedPositionDeposit", - "type": { - "option": "u64" - } + "name": "lp_pool", + "type": "pubkey" } ] } }, { - "name": "SignedMsgTriggerOrderParams", + "name": "LPSwapRecord", "type": { "kind": "struct", "fields": [ { - "name": "triggerPrice", - "type": "u64" + "name": "ts", + "type": "i64" }, { - "name": "baseAssetAmount", + "name": "slot", "type": "u64" - } - ] - } - }, - { - "name": "ModifyOrderParams", - "type": { - "kind": "struct", - "fields": [ - { - "name": "direction", - "type": { - "option": { - "defined": "PositionDirection" - } - } }, { - "name": "baseAssetAmount", - "type": { - "option": "u64" - } + "name": "authority", + "type": "pubkey" }, { - "name": "price", - "type": { - "option": "u64" - } + "name": "out_amount", + "docs": [ + "precision: out market mint precision, gross fees" + ], + "type": "u128" }, { - "name": "reduceOnly", - "type": { - "option": "bool" - } + "name": "in_amount", + "docs": [ + "precision: in market mint precision, gross fees" + ], + "type": "u128" }, { - "name": "postOnly", - "type": { - "option": { - "defined": "PostOnlyParam" - } - } + "name": "out_fee", + "docs": [ + "precision: fee on amount_out, in market mint precision" + ], + "type": "i128" }, { - "name": "bitFlags", - "type": { - "option": "u8" - } + "name": "in_fee", + "docs": [ + "precision: fee on amount_in, out market mint precision" + ], + "type": "i128" }, { - "name": "maxTs", - "type": { - "option": "i64" - } + "name": "out_spot_market_index", + "type": "u16" }, { - "name": "triggerPrice", - "type": { - "option": "u64" - } + "name": "in_spot_market_index", + "type": "u16" }, { - "name": "triggerCondition", - "type": { - "option": { - "defined": "OrderTriggerCondition" - } - } + "name": "out_constituent_index", + "type": "u16" }, { - "name": "oraclePriceOffset", - "type": { - "option": "i32" - } + "name": "in_constituent_index", + "type": "u16" }, { - "name": "auctionDuration", - "type": { - "option": "u8" - } + "name": "out_oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "auctionStartPrice", - "type": { - "option": "i64" - } + "name": "in_oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "auctionEndPrice", - "type": { - "option": "i64" - } + "name": "last_aum", + "docs": [ + "LPPool last_aum, QUOTE_PRECISION" + ], + "type": "u128" }, { - "name": "policy", - "type": { - "option": "u8" - } - } - ] - } - }, - { - "name": "InsuranceClaim", - "type": { - "kind": "struct", - "fields": [ + "name": "last_aum_slot", + "type": "u64" + }, { - "name": "revenueWithdrawSinceLastSettle", + "name": "in_market_current_weight", "docs": [ - "The amount of revenue last settled", - "Positive if funds left the perp market,", - "negative if funds were pulled into the perp market", - "precision: QUOTE_PRECISION" + "PERCENTAGE_PRECISION" ], "type": "i64" }, { - "name": "maxRevenueWithdrawPerPeriod", + "name": "out_market_current_weight", "docs": [ - "The max amount of revenue that can be withdrawn per period", - "precision: QUOTE_PRECISION" + "PERCENTAGE_PRECISION" ], - "type": "u64" + "type": "i64" }, { - "name": "quoteMaxInsurance", + "name": "in_market_target_weight", "docs": [ - "The max amount of insurance that perp market can use to resolve bankruptcy and pnl deficits", - "precision: QUOTE_PRECISION" + "PERCENTAGE_PRECISION" ], - "type": "u64" + "type": "i64" }, { - "name": "quoteSettledInsurance", + "name": "out_market_target_weight", "docs": [ - "The amount of insurance that has been used to resolve bankruptcy and pnl deficits", - "precision: QUOTE_PRECISION" + "PERCENTAGE_PRECISION" ], + "type": "i64" + }, + { + "name": "in_swap_id", "type": "u64" }, { - "name": "lastRevenueWithdrawTs", - "docs": [ - "The last time revenue was settled in/out of market" - ], - "type": "i64" + "name": "out_swap_id", + "type": "u64" + }, + { + "name": "lp_pool", + "type": "pubkey" } ] } }, { - "name": "PoolBalance", + "name": "LiquidateBorrowForPerpPnlRecord", "type": { "kind": "struct", "fields": [ { - "name": "scaledBalance", - "docs": [ - "To get the pool's token amount, you must multiply the scaled balance by the market's cumulative", - "deposit interest", - "precision: SPOT_BALANCE_PRECISION" - ], + "name": "perp_market_index", + "type": "u16" + }, + { + "name": "market_oracle_price", + "type": "i64" + }, + { + "name": "pnl_transfer", "type": "u128" }, { - "name": "marketIndex", - "docs": [ - "The spot market the pool is for" - ], + "name": "liability_market_index", "type": "u16" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 6 - ] - } + "name": "liability_price", + "type": "i64" + }, + { + "name": "liability_transfer", + "type": "u128" } ] } }, { - "name": "AMM", + "name": "LiquidatePerpPnlForDepositRecord", "type": { "kind": "struct", "fields": [ { - "name": "oracle", - "docs": [ - "oracle price data public key" - ], - "type": "publicKey" + "name": "perp_market_index", + "type": "u16" }, { - "name": "historicalOracleData", - "docs": [ - "stores historically witnessed oracle data" - ], - "type": { - "defined": "HistoricalOracleData" - } + "name": "market_oracle_price", + "type": "i64" }, { - "name": "baseAssetAmountPerLp", - "docs": [ - "accumulated base asset amount since inception per lp share", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "pnl_transfer", + "type": "u128" }, { - "name": "quoteAssetAmountPerLp", - "docs": [ - "accumulated quote asset amount since inception per lp share", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "asset_market_index", + "type": "u16" }, { - "name": "feePool", - "docs": [ - "partition of fees from perp market trading moved from pnl settlements" - ], - "type": { - "defined": "PoolBalance" - } + "name": "asset_price", + "type": "i64" }, { - "name": "baseAssetReserve", - "docs": [ - "`x` reserves for constant product mm formula (x * y = k)", - "precision: AMM_RESERVE_PRECISION" - ], + "name": "asset_transfer", "type": "u128" + } + ] + } + }, + { + "name": "LiquidatePerpRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "market_index", + "type": "u16" + }, + { + "name": "oracle_price", + "type": "i64" + }, + { + "name": "base_asset_amount", + "type": "i64" + }, + { + "name": "quote_asset_amount", + "type": "i64" }, { - "name": "quoteAssetReserve", + "name": "lp_shares", "docs": [ - "`y` reserves for constant product mm formula (x * y = k)", "precision: AMM_RESERVE_PRECISION" ], - "type": "u128" + "type": "u64" }, { - "name": "concentrationCoef", - "docs": [ - "determines how close the min/max base asset reserve sit vs base reserves", - "allow for decreasing slippage without increasing liquidity and v.v.", - "precision: PERCENTAGE_PRECISION" - ], - "type": "u128" + "name": "fill_record_id", + "type": "u64" }, { - "name": "minBaseAssetReserve", - "docs": [ - "minimum base_asset_reserve allowed before AMM is unavailable", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "user_order_id", + "type": "u32" }, { - "name": "maxBaseAssetReserve", - "docs": [ - "maximum base_asset_reserve allowed before AMM is unavailable", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "liquidator_order_id", + "type": "u32" }, { - "name": "sqrtK", + "name": "liquidator_fee", "docs": [ - "`sqrt(k)` in constant product mm formula (x * y = k). stored to avoid drift caused by integer math issues", - "precision: AMM_RESERVE_PRECISION" + "precision: QUOTE_PRECISION" ], - "type": "u128" + "type": "u64" }, { - "name": "pegMultiplier", + "name": "if_fee", "docs": [ - "normalizing numerical factor for y, its use offers lowest slippage in cp-curve when market is balanced", - "precision: PEG_PRECISION" + "precision: QUOTE_PRECISION" ], - "type": "u128" - }, + "type": "u64" + } + ] + } + }, + { + "name": "LiquidateSpotRecord", + "type": { + "kind": "struct", + "fields": [ { - "name": "terminalQuoteAssetReserve", - "docs": [ - "y when market is balanced. stored to save computation", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "asset_market_index", + "type": "u16" }, { - "name": "baseAssetAmountLong", - "docs": [ - "always non-negative. tracks number of total longs in market (regardless of counterparty)", - "precision: BASE_PRECISION" - ], - "type": "i128" + "name": "asset_price", + "type": "i64" }, { - "name": "baseAssetAmountShort", - "docs": [ - "always non-positive. tracks number of total shorts in market (regardless of counterparty)", - "precision: BASE_PRECISION" - ], - "type": "i128" + "name": "asset_transfer", + "type": "u128" }, { - "name": "baseAssetAmountWithAmm", - "docs": [ - "tracks net position (longs-shorts) in market with AMM as counterparty", - "precision: BASE_PRECISION" - ], - "type": "i128" + "name": "liability_market_index", + "type": "u16" }, { - "name": "baseAssetAmountWithUnsettledLp", - "docs": [ - "tracks net position (longs-shorts) in market with LPs as counterparty", - "precision: BASE_PRECISION" - ], - "type": "i128" + "name": "liability_price", + "type": "i64" }, { - "name": "maxOpenInterest", + "name": "liability_transfer", "docs": [ - "max allowed open interest, blocks trades that breach this value", - "precision: BASE_PRECISION" + "precision: token mint precision" ], "type": "u128" }, { - "name": "quoteAssetAmount", + "name": "if_fee", "docs": [ - "sum of all user's perp quote_asset_amount in market", - "precision: QUOTE_PRECISION" + "precision: token mint precision" ], - "type": "i128" - }, + "type": "u64" + } + ] + } + }, + { + "name": "LiquidationRecord", + "type": { + "kind": "struct", + "fields": [ { - "name": "quoteEntryAmountLong", - "docs": [ - "sum of all long user's quote_entry_amount in market", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "ts", + "type": "i64" }, { - "name": "quoteEntryAmountShort", - "docs": [ - "sum of all short user's quote_entry_amount in market", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "liquidation_type", + "type": { + "defined": { + "name": "LiquidationType" + } + } }, { - "name": "quoteBreakEvenAmountLong", - "docs": [ - "sum of all long user's quote_break_even_amount in market", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "user", + "type": "pubkey" }, { - "name": "quoteBreakEvenAmountShort", - "docs": [ - "sum of all short user's quote_break_even_amount in market", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "liquidator", + "type": "pubkey" }, { - "name": "userLpShares", - "docs": [ - "total user lp shares of sqrt_k (protocol owned liquidity = sqrt_k - last_funding_rate)", - "precision: AMM_RESERVE_PRECISION" - ], + "name": "margin_requirement", "type": "u128" }, { - "name": "lastFundingRate", - "docs": [ - "last funding rate in this perp market (unit is quote per base)", - "precision: FUNDING_RATE_PRECISION" - ], - "type": "i64" + "name": "total_collateral", + "type": "i128" }, { - "name": "lastFundingRateLong", - "docs": [ - "last funding rate for longs in this perp market (unit is quote per base)", - "precision: FUNDING_RATE_PRECISION" - ], - "type": "i64" + "name": "margin_freed", + "type": "u64" }, { - "name": "lastFundingRateShort", - "docs": [ - "last funding rate for shorts in this perp market (unit is quote per base)", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "liquidation_id", + "type": "u16" }, { - "name": "last24hAvgFundingRate", - "docs": [ - "estimate of last 24h of funding rate perp market (unit is quote per base)", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "bankrupt", + "type": "bool" }, { - "name": "totalFee", - "docs": [ - "total fees collected by this perp market", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "canceled_order_ids", + "type": { + "vec": "u32" + } }, { - "name": "totalMmFee", - "docs": [ - "total fees collected by the vAMM's bid/ask spread", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "liquidate_perp", + "type": { + "defined": { + "name": "LiquidatePerpRecord" + } + } }, { - "name": "totalExchangeFee", - "docs": [ - "total fees collected by exchange fee schedule", - "precision: QUOTE_PRECISION" - ], - "type": "u128" + "name": "liquidate_spot", + "type": { + "defined": { + "name": "LiquidateSpotRecord" + } + } }, { - "name": "totalFeeMinusDistributions", - "docs": [ - "total fees minus any recognized upnl and pool withdraws", - "precision: QUOTE_PRECISION" - ], - "type": "i128" + "name": "liquidate_borrow_for_perp_pnl", + "type": { + "defined": { + "name": "LiquidateBorrowForPerpPnlRecord" + } + } }, { - "name": "totalFeeWithdrawn", - "docs": [ - "sum of all fees from fee pool withdrawn to revenue pool", - "precision: QUOTE_PRECISION" - ], - "type": "u128" + "name": "liquidate_perp_pnl_for_deposit", + "type": { + "defined": { + "name": "LiquidatePerpPnlForDepositRecord" + } + } }, { - "name": "totalLiquidationFee", - "docs": [ - "all fees collected by market for liquidations", - "precision: QUOTE_PRECISION" - ], - "type": "u128" + "name": "perp_bankruptcy", + "type": { + "defined": { + "name": "PerpBankruptcyRecord" + } + } }, { - "name": "cumulativeFundingRateLong", - "docs": [ - "accumulated funding rate for longs since inception in market" - ], - "type": "i128" - }, + "name": "spot_bankruptcy", + "type": { + "defined": { + "name": "SpotBankruptcyRecord" + } + } + } + ] + } + }, + { + "name": "LiquidationType", + "type": { + "kind": "enum", + "variants": [ { - "name": "cumulativeFundingRateShort", - "docs": [ - "accumulated funding rate for shorts since inception in market" - ], - "type": "i128" + "name": "LiquidatePerp" }, { - "name": "totalSocialLoss", - "docs": [ - "accumulated social loss paid by users since inception in market" - ], - "type": "u128" + "name": "LiquidateSpot" }, { - "name": "askBaseAssetReserve", - "docs": [ - "transformed base_asset_reserve for users going long", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "LiquidateBorrowForPerpPnl" }, { - "name": "askQuoteAssetReserve", - "docs": [ - "transformed quote_asset_reserve for users going long", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "LiquidatePerpPnlForDeposit" }, { - "name": "bidBaseAssetReserve", - "docs": [ - "transformed base_asset_reserve for users going short", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" + "name": "PerpBankruptcy" }, { - "name": "bidQuoteAssetReserve", - "docs": [ - "transformed quote_asset_reserve for users going short", - "precision: AMM_RESERVE_PRECISION" - ], - "type": "u128" - }, + "name": "SpotBankruptcy" + } + ] + } + }, + { + "name": "LpPoolParams", + "type": { + "kind": "struct", + "fields": [ { - "name": "lastOracleNormalisedPrice", - "docs": [ - "the last seen oracle price partially shrunk toward the amm reserve price", - "precision: PRICE_PRECISION" - ], - "type": "i64" + "name": "max_settle_quote_amount", + "type": { + "option": "u64" + } }, { - "name": "lastOracleReservePriceSpreadPct", - "docs": [ - "the gap between the oracle price and the reserve price = y * peg_multiplier / x" - ], - "type": "i64" + "name": "volatility", + "type": { + "option": "u64" + } }, { - "name": "lastBidPriceTwap", - "docs": [ - "average estimate of bid price over funding_period", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "gamma_execution", + "type": { + "option": "u8" + } }, { - "name": "lastAskPriceTwap", - "docs": [ - "average estimate of ask price over funding_period", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "xi", + "type": { + "option": "u8" + } }, { - "name": "lastMarkPriceTwap", - "docs": [ - "average estimate of (bid+ask)/2 price over funding_period", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "max_aum", + "type": { + "option": "u128" + } }, { - "name": "lastMarkPriceTwap5min", - "docs": [ - "average estimate of (bid+ask)/2 price over FIVE_MINUTES" - ], - "type": "u64" - }, + "name": "whitelist_mint", + "type": { + "option": "pubkey" + } + } + ] + } + }, + { + "name": "MarginMode", + "type": { + "kind": "enum", + "variants": [ { - "name": "lastUpdateSlot", - "docs": [ - "the last blockchain slot the amm was updated" - ], - "type": "u64" + "name": "Default" }, { - "name": "lastOracleConfPct", - "docs": [ - "the pct size of the oracle confidence interval", - "precision: PERCENTAGE_PRECISION" - ], - "type": "u64" + "name": "HighLeverage" }, { - "name": "netRevenueSinceLastFunding", - "docs": [ - "the total_fee_minus_distribution change since the last funding update", - "precision: QUOTE_PRECISION" - ], - "type": "i64" - }, + "name": "HighLeverageMaintenance" + } + ] + } + }, + { + "name": "MarketStatus", + "type": { + "kind": "enum", + "variants": [ { - "name": "lastFundingRateTs", - "docs": [ - "the last funding rate update unix_timestamp" - ], - "type": "i64" + "name": "Initialized" }, { - "name": "fundingPeriod", - "docs": [ - "the peridocity of the funding rate updates" - ], - "type": "i64" + "name": "Active" }, { - "name": "orderStepSize", - "docs": [ - "the base step size (increment) of orders", - "precision: BASE_PRECISION" - ], - "type": "u64" + "name": "FundingPaused" }, { - "name": "orderTickSize", - "docs": [ - "the price tick size of orders", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "AmmPaused" }, { - "name": "minOrderSize", - "docs": [ - "the minimum base size of an order", - "precision: BASE_PRECISION" - ], - "type": "u64" + "name": "FillPaused" }, { - "name": "mmOracleSlot", - "docs": [ - "the max base size a single user can have", - "precision: BASE_PRECISION" - ], - "type": "u64" + "name": "WithdrawPaused" }, { - "name": "volume24h", - "docs": [ - "estimated total of volume in market", - "QUOTE_PRECISION" - ], - "type": "u64" + "name": "ReduceOnly" }, { - "name": "longIntensityVolume", - "docs": [ - "the volume intensity of long fills against AMM" - ], - "type": "u64" + "name": "Settlement" }, { - "name": "shortIntensityVolume", - "docs": [ - "the volume intensity of short fills against AMM" - ], - "type": "u64" - }, + "name": "Delisted" + } + ] + } + }, + { + "name": "MarketType", + "type": { + "kind": "enum", + "variants": [ { - "name": "lastTradeTs", - "docs": [ - "the blockchain unix timestamp at the time of the last trade" - ], - "type": "i64" + "name": "Spot" }, { - "name": "markStd", - "docs": [ - "estimate of standard deviation of the fill (mark) prices", - "precision: PRICE_PRECISION" - ], - "type": "u64" - }, + "name": "Perp" + } + ] + } + }, + { + "name": "ModifyOrderParams", + "type": { + "kind": "struct", + "fields": [ { - "name": "oracleStd", - "docs": [ - "estimate of standard deviation of the oracle price at each update", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "direction", + "type": { + "option": { + "defined": { + "name": "PositionDirection" + } + } + } }, { - "name": "lastMarkPriceTwapTs", - "docs": [ - "the last unix_timestamp the mark twap was updated" - ], - "type": "i64" + "name": "base_asset_amount", + "type": { + "option": "u64" + } }, { - "name": "baseSpread", - "docs": [ - "the minimum spread the AMM can quote. also used as step size for some spread logic increases." - ], - "type": "u32" + "name": "price", + "type": { + "option": "u64" + } }, { - "name": "maxSpread", - "docs": [ - "the maximum spread the AMM can quote" - ], - "type": "u32" + "name": "reduce_only", + "type": { + "option": "bool" + } }, { - "name": "longSpread", - "docs": [ - "the spread for asks vs the reserve price" - ], - "type": "u32" + "name": "post_only", + "type": { + "option": { + "defined": { + "name": "PostOnlyParam" + } + } + } }, { - "name": "shortSpread", - "docs": [ - "the spread for bids vs the reserve price" - ], - "type": "u32" + "name": "bit_flags", + "type": { + "option": "u8" + } }, { - "name": "mmOraclePrice", - "docs": [ - "MM oracle price" - ], - "type": "i64" + "name": "max_ts", + "type": { + "option": "i64" + } }, { - "name": "maxFillReserveFraction", - "docs": [ - "the fraction of total available liquidity a single fill on the AMM can consume" - ], - "type": "u16" + "name": "trigger_price", + "type": { + "option": "u64" + } }, { - "name": "maxSlippageRatio", - "docs": [ - "the maximum slippage a single fill on the AMM can push" - ], - "type": "u16" + "name": "trigger_condition", + "type": { + "option": { + "defined": { + "name": "OrderTriggerCondition" + } + } + } }, { - "name": "curveUpdateIntensity", - "docs": [ - "the update intensity of AMM formulaic updates (adjusting k). 0-100" - ], - "type": "u8" + "name": "oracle_price_offset", + "type": { + "option": "i32" + } }, { - "name": "ammJitIntensity", - "docs": [ - "the jit intensity of AMM. larger intensity means larger participation in jit. 0 means no jit participation.", - "(0, 100] is intensity for protocol-owned AMM. (100, 200] is intensity for user LP-owned AMM." - ], - "type": "u8" + "name": "auction_duration", + "type": { + "option": "u8" + } }, { - "name": "oracleSource", - "docs": [ - "the oracle provider information. used to decode/scale the oracle public key" - ], + "name": "auction_start_price", "type": { - "defined": "OracleSource" + "option": "i64" } }, { - "name": "lastOracleValid", - "docs": [ - "tracks whether the oracle was considered valid at the last AMM update" - ], - "type": "bool" + "name": "auction_end_price", + "type": { + "option": "i64" + } }, { - "name": "targetBaseAssetAmountPerLp", - "docs": [ - "the target value for `base_asset_amount_per_lp`, used during AMM JIT with LP split", - "precision: BASE_PRECISION" - ], - "type": "i32" - }, - { - "name": "perLpBase", - "docs": [ - "expo for unit of per_lp, base 10 (if per_lp_base=X, then per_lp unit is 10^X)" - ], - "type": "i8" - }, - { - "name": "oracleLowRiskSlotDelayOverride", - "docs": [ - "the override for the state.min_perp_auction_duration", - "0 is no override, -1 is disable speed bump, 1-100 is literal speed bump" - ], - "type": "i8" - }, + "name": "policy", + "type": { + "option": "u8" + } + } + ] + } + }, + { + "name": "NewUserRecord", + "type": { + "kind": "struct", + "fields": [ { - "name": "ammSpreadAdjustment", + "name": "ts", "docs": [ - "signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)" + "unix_timestamp of action" ], - "type": "i8" - }, - { - "name": "oracleSlotDelayOverride", - "type": "i8" - }, - { - "name": "mmOracleSequenceId", - "type": "u64" - }, - { - "name": "netUnsettledFundingPnl", "type": "i64" }, { - "name": "quoteAssetAmountWithUnsettledLp", - "type": "i64" - }, - { - "name": "referencePriceOffset", - "type": "i32" + "name": "user_authority", + "type": "pubkey" }, { - "name": "ammInventorySpreadAdjustment", - "docs": [ - "signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)" - ], - "type": "i8" + "name": "user", + "type": "pubkey" }, { - "name": "referencePriceOffsetDeadbandPct", - "type": "u8" + "name": "sub_account_id", + "type": "u16" }, { - "name": "padding", + "name": "name", "type": { "array": [ "u8", - 2 + 32 ] } }, { - "name": "lastFundingOracleTwap", - "type": "i64" + "name": "referrer", + "type": "pubkey" } ] } }, { - "name": "RevenueShareOrder", + "name": "OpenbookV2FulfillmentConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "feesAccrued", - "docs": [ - "fees accrued so far for this order slot. This is not exclusively fees from this order_id", - "and may include fees from other orders in the same market. This may be swept to the", - "builder's SpotPosition during settle_pnl." - ], - "type": "u64" + "name": "pubkey", + "type": "pubkey" }, { - "name": "orderId", - "docs": [ - "the order_id of the current active order in this slot. It's only relevant while bit_flag = Open" - ], - "type": "u32" + "name": "openbook_v2_program_id", + "type": "pubkey" }, { - "name": "feeTenthBps", - "docs": [ - "the builder fee on this order, in tenths of a bps, e.g. 100 = 0.01%" - ], - "type": "u16" + "name": "openbook_v2_market", + "type": "pubkey" }, { - "name": "marketIndex", - "type": "u16" + "name": "openbook_v2_market_authority", + "type": "pubkey" }, { - "name": "subAccountId", - "docs": [ - "the subaccount_id of the user who created this order. It's only relevant while bit_flag = Open" - ], - "type": "u16" + "name": "openbook_v2_event_heap", + "type": "pubkey" }, { - "name": "builderIdx", - "docs": [ - "the index of the RevenueShareEscrow.approved_builders list, that this order's fee will settle to. Ignored", - "if bit_flag = Referral." - ], - "type": "u8" + "name": "openbook_v2_bids", + "type": "pubkey" }, { - "name": "bitFlags", - "docs": [ - "bitflags that describe the state of the order.", - "[`RevenueShareOrderBitFlag::Init`]: this order slot is available for use.", - "[`RevenueShareOrderBitFlag::Open`]: this order slot is occupied, `order_id` is the `sub_account_id`'s active order.", - "[`RevenueShareOrderBitFlag::Completed`]: this order has been filled or canceled, and is waiting to be settled into.", - "the builder's account order_id and sub_account_id are no longer relevant, it may be merged with other orders.", - "[`RevenueShareOrderBitFlag::Referral`]: this order stores referral rewards waiting to be settled for this market.", - "If it is set, no other bitflag should be set." - ], - "type": "u8" + "name": "openbook_v2_asks", + "type": "pubkey" }, { - "name": "userOrderIndex", - "docs": [ - "the index into the User's orders list when this RevenueShareOrder was created, make sure to verify that order_id matches." - ], - "type": "u8" + "name": "openbook_v2_base_vault", + "type": "pubkey" + }, + { + "name": "openbook_v2_quote_vault", + "type": "pubkey" + }, + { + "name": "market_index", + "type": "u16" + }, + { + "name": "fulfillment_type", + "type": { + "defined": { + "name": "SpotFulfillmentType" + } + } }, { - "name": "marketType", + "name": "status", "type": { - "defined": "MarketType" + "defined": { + "name": "SpotFulfillmentConfigStatus" + } } }, { @@ -13877,7 +19992,7 @@ "type": { "array": [ "u8", - 10 + 4 ] } } @@ -13885,431 +20000,302 @@ } }, { - "name": "BuilderInfo", + "name": "OracleGuardRails", "type": { "kind": "struct", "fields": [ { - "name": "authority", - "type": "publicKey" - }, - { - "name": "maxFeeTenthBps", - "type": "u16" + "name": "price_divergence", + "type": { + "defined": { + "name": "PriceDivergenceGuardRails" + } + } }, { - "name": "padding", + "name": "validity", "type": { - "array": [ - "u8", - 6 - ] + "defined": { + "name": "ValidityGuardRails" + } } } ] } }, { - "name": "RevenueShareEscrowFixed", + "name": "OracleSource", "type": { - "kind": "struct", - "fields": [ + "kind": "enum", + "variants": [ { - "name": "authority", - "type": "publicKey" + "name": "Pyth" }, { - "name": "referrer", - "type": "publicKey" + "name": "Switchboard" }, { - "name": "referrerBoostExpireTs", - "type": "u32" + "name": "QuoteAsset" }, { - "name": "referrerRewardOffset", - "type": "i8" + "name": "Pyth1K" }, { - "name": "refereeFeeNumeratorOffset", - "type": "i8" + "name": "Pyth1M" }, { - "name": "referrerBoostNumerator", - "type": "i8" + "name": "PythStableCoin" }, { - "name": "reservedFixed", - "type": { - "array": [ - "u8", - 17 - ] - } - } - ] - } - }, - { - "name": "SignedMsgOrderId", - "type": { - "kind": "struct", - "fields": [ + "name": "Prelaunch" + }, { - "name": "uuid", - "type": { - "array": [ - "u8", - 8 - ] - } + "name": "PythPull" }, { - "name": "maxSlot", - "type": "u64" + "name": "Pyth1KPull" }, { - "name": "orderId", - "type": "u32" + "name": "Pyth1MPull" }, { - "name": "padding", - "type": "u32" - } - ] - } - }, - { - "name": "SignedMsgUserOrdersFixed", - "type": { - "kind": "struct", - "fields": [ + "name": "PythStableCoinPull" + }, { - "name": "userPubkey", - "type": "publicKey" + "name": "SwitchboardOnDemand" }, { - "name": "padding", - "type": "u32" + "name": "PythLazer" }, { - "name": "len", - "type": "u32" + "name": "PythLazer1K" + }, + { + "name": "PythLazer1M" + }, + { + "name": "PythLazerStableCoin" } ] } }, { - "name": "InsuranceFund", + "name": "Order", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { "kind": "struct", "fields": [ { - "name": "vault", - "type": "publicKey" + "name": "slot", + "docs": [ + "The slot the order was placed" + ], + "type": "u64" }, { - "name": "totalShares", - "type": "u128" + "name": "price", + "docs": [ + "The limit price for the order (can be 0 for market orders)", + "For orders with an auction, this price isn't used until the auction is complete", + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "userShares", - "type": "u128" + "name": "base_asset_amount", + "docs": [ + "The size of the order", + "precision for perps: BASE_PRECISION", + "precision for spot: token mint precision" + ], + "type": "u64" }, { - "name": "sharesBase", - "type": "u128" + "name": "base_asset_amount_filled", + "docs": [ + "The amount of the order filled", + "precision for perps: BASE_PRECISION", + "precision for spot: token mint precision" + ], + "type": "u64" }, { - "name": "unstakingPeriod", - "type": "i64" + "name": "quote_asset_amount_filled", + "docs": [ + "The amount of quote filled for the order", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "trigger_price", + "docs": [ + "At what price the order will be triggered. Only relevant for trigger orders", + "precision: PRICE_PRECISION" + ], + "type": "u64" }, { - "name": "lastRevenueSettleTs", + "name": "auction_start_price", + "docs": [ + "The start price for the auction. Only relevant for market/oracle orders", + "precision: PRICE_PRECISION" + ], "type": "i64" }, { - "name": "revenueSettlePeriod", + "name": "auction_end_price", + "docs": [ + "The end price for the auction. Only relevant for market/oracle orders", + "precision: PRICE_PRECISION" + ], "type": "i64" }, { - "name": "totalFactor", - "type": "u32" + "name": "max_ts", + "docs": [ + "The time when the order will expire" + ], + "type": "i64" }, { - "name": "userFactor", - "type": "u32" - } - ] - } - }, - { - "name": "OracleGuardRails", - "type": { - "kind": "struct", - "fields": [ - { - "name": "priceDivergence", - "type": { - "defined": "PriceDivergenceGuardRails" - } - }, - { - "name": "validity", - "type": { - "defined": "ValidityGuardRails" - } - } - ] - } - }, - { - "name": "PriceDivergenceGuardRails", - "type": { - "kind": "struct", - "fields": [ - { - "name": "markOraclePercentDivergence", - "type": "u64" - }, - { - "name": "oracleTwap5minPercentDivergence", - "type": "u64" - } - ] - } - }, - { - "name": "ValidityGuardRails", - "type": { - "kind": "struct", - "fields": [ - { - "name": "slotsBeforeStaleForAmm", - "type": "i64" - }, - { - "name": "slotsBeforeStaleForMargin", - "type": "i64" - }, - { - "name": "confidenceIntervalMaxSize", - "type": "u64" - }, - { - "name": "tooVolatileRatio", - "type": "i64" - } - ] - } - }, - { - "name": "FeeStructure", - "type": { - "kind": "struct", - "fields": [ - { - "name": "feeTiers", - "type": { - "array": [ - { - "defined": "FeeTier" - }, - 10 - ] - } - }, - { - "name": "fillerRewardStructure", - "type": { - "defined": "OrderFillerRewardStructure" - } - }, - { - "name": "referrerRewardEpochUpperBound", - "type": "u64" - }, - { - "name": "flatFillerFee", - "type": "u64" - } - ] - } - }, - { - "name": "FeeTier", - "type": { - "kind": "struct", - "fields": [ - { - "name": "feeNumerator", - "type": "u32" - }, - { - "name": "feeDenominator", - "type": "u32" - }, - { - "name": "makerRebateNumerator", - "type": "u32" - }, - { - "name": "makerRebateDenominator", - "type": "u32" - }, - { - "name": "referrerRewardNumerator", - "type": "u32" - }, - { - "name": "referrerRewardDenominator", - "type": "u32" - }, - { - "name": "refereeFeeNumerator", - "type": "u32" + "name": "oracle_price_offset", + "docs": [ + "If set, the order limit price is the oracle price + this offset", + "precision: PRICE_PRECISION" + ], + "type": "i32" }, { - "name": "refereeFeeDenominator", - "type": "u32" - } - ] - } - }, - { - "name": "OrderFillerRewardStructure", - "type": { - "kind": "struct", - "fields": [ - { - "name": "rewardNumerator", + "name": "order_id", + "docs": [ + "The id for the order. Each users has their own order id space" + ], "type": "u32" }, { - "name": "rewardDenominator", - "type": "u32" + "name": "market_index", + "docs": [ + "The perp/spot market index" + ], + "type": "u16" }, { - "name": "timeBasedRewardLowerBound", - "type": "u128" - } - ] - } - }, - { - "name": "UserFees", - "type": { - "kind": "struct", - "fields": [ - { - "name": "totalFeePaid", + "name": "status", "docs": [ - "Total taker fee paid", - "precision: QUOTE_PRECISION" + "Whether the order is open or unused" ], - "type": "u64" + "type": { + "defined": { + "name": "OrderStatus" + } + } }, { - "name": "totalFeeRebate", + "name": "order_type", "docs": [ - "Total maker fee rebate", - "precision: QUOTE_PRECISION" + "The type of order" ], - "type": "u64" + "type": { + "defined": { + "name": "OrderType" + } + } }, { - "name": "totalTokenDiscount", + "name": "market_type", "docs": [ - "Total discount from holding token", - "precision: QUOTE_PRECISION" + "Whether market is spot or perp" ], - "type": "u64" + "type": { + "defined": { + "name": "MarketType" + } + } }, { - "name": "totalRefereeDiscount", + "name": "user_order_id", "docs": [ - "Total discount from being referred", - "precision: QUOTE_PRECISION" + "User generated order id. Can make it easier to place/cancel orders" ], - "type": "u64" + "type": "u8" }, { - "name": "totalReferrerReward", + "name": "existing_position_direction", "docs": [ - "Total reward to referrer", - "precision: QUOTE_PRECISION" + "What the users position was when the order was placed" ], - "type": "u64" + "type": { + "defined": { + "name": "PositionDirection" + } + } }, { - "name": "currentEpochReferrerReward", + "name": "direction", "docs": [ - "Total reward to referrer this epoch", - "precision: QUOTE_PRECISION" + "Whether the user is going long or short. LONG = bid, SHORT = ask" ], - "type": "u64" - } - ] - } - }, - { - "name": "SpotPosition", - "type": { - "kind": "struct", - "fields": [ + "type": { + "defined": { + "name": "PositionDirection" + } + } + }, { - "name": "scaledBalance", + "name": "reduce_only", "docs": [ - "The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow", - "interest of corresponding market.", - "precision: SPOT_BALANCE_PRECISION" + "Whether the order is allowed to only reduce position size" ], - "type": "u64" + "type": "bool" }, { - "name": "openBids", + "name": "post_only", "docs": [ - "How many spot non reduce only trigger orders the user has open", - "precision: token mint precision" + "Whether the order must be a maker" ], - "type": "i64" + "type": "bool" }, { - "name": "openAsks", + "name": "immediate_or_cancel", "docs": [ - "How many spot non reduce only trigger orders the user has open", - "precision: token mint precision" + "Whether the order must be canceled the same slot it is placed" ], - "type": "i64" + "type": "bool" }, { - "name": "cumulativeDeposits", + "name": "trigger_condition", "docs": [ - "The cumulative deposits/borrows a user has made into a market", - "precision: token mint precision" + "Whether the order is triggered above or below the trigger price. Only relevant for trigger orders" ], - "type": "i64" + "type": { + "defined": { + "name": "OrderTriggerCondition" + } + } }, { - "name": "marketIndex", + "name": "auction_duration", "docs": [ - "The market index of the corresponding spot market" + "How many slots the auction lasts" ], - "type": "u16" + "type": "u8" }, { - "name": "balanceType", + "name": "posted_slot_tail", "docs": [ - "Whether the position is deposit or borrow" + "Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)" ], - "type": { - "defined": "SpotBalanceType" - } + "type": "u8" }, { - "name": "openOrders", + "name": "bit_flags", "docs": [ - "Number of open orders" + "Bitflags for further classification", + "0: is_signed_message" ], "type": "u8" }, @@ -14318,7 +20304,7 @@ "type": { "array": [ "u8", - 4 + 1 ] } } @@ -14326,5274 +20312,3784 @@ } }, { - "name": "PerpPosition", + "name": "OrderAction", "type": { - "kind": "struct", - "fields": [ + "kind": "enum", + "variants": [ { - "name": "lastCumulativeFundingRate", - "docs": [ - "The perp market's last cumulative funding rate. Used to calculate the funding payment owed to user", - "precision: FUNDING_RATE_PRECISION" - ], - "type": "i64" + "name": "Place" }, { - "name": "baseAssetAmount", - "docs": [ - "the size of the users perp position", - "precision: BASE_PRECISION" - ], - "type": "i64" + "name": "Cancel" }, { - "name": "quoteAssetAmount", - "docs": [ - "Used to calculate the users pnl. Upon entry, is equal to base_asset_amount * avg entry price - fees", - "Updated when the user open/closes position or settles pnl. Includes fees/funding", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "Fill" }, { - "name": "quoteBreakEvenAmount", - "docs": [ - "The amount of quote the user would need to exit their position at to break even", - "Updated when the user open/closes position or settles pnl. Includes fees/funding", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "Trigger" }, { - "name": "quoteEntryAmount", - "docs": [ - "The amount quote the user entered the position with. Equal to base asset amount * avg entry price", - "Updated when the user open/closes position. Excludes fees/funding", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "Expire" + } + ] + } + }, + { + "name": "OrderActionExplanation", + "type": { + "kind": "enum", + "variants": [ + { + "name": "None" }, { - "name": "openBids", - "docs": [ - "The amount of non reduce only trigger orders the user has open", - "precision: BASE_PRECISION" - ], - "type": "i64" + "name": "InsufficientFreeCollateral" }, { - "name": "openAsks", - "docs": [ - "The amount of non reduce only trigger orders the user has open", - "precision: BASE_PRECISION" - ], - "type": "i64" + "name": "OraclePriceBreachedLimitPrice" }, { - "name": "settledPnl", - "docs": [ - "The amount of pnl settled in this market since opening the position", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "MarketOrderFilledToLimitPrice" }, { - "name": "lpShares", - "docs": [ - "The number of lp (liquidity provider) shares the user has in this perp market", - "LP shares allow users to provide liquidity via the AMM", - "precision: BASE_PRECISION" - ], - "type": "u64" + "name": "OrderExpired" }, { - "name": "lastBaseAssetAmountPerLp", - "docs": [ - "The last base asset amount per lp the amm had", - "Used to settle the users lp position", - "precision: BASE_PRECISION" - ], - "type": "i64" + "name": "Liquidation" }, { - "name": "lastQuoteAssetAmountPerLp", - "docs": [ - "The last quote asset amount per lp the amm had", - "Used to settle the users lp position", - "precision: QUOTE_PRECISION" - ], - "type": "i64" + "name": "OrderFilledWithAMM" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 2 - ] - } + "name": "OrderFilledWithAMMJit" }, { - "name": "maxMarginRatio", - "type": "u16" + "name": "OrderFilledWithMatch" }, { - "name": "marketIndex", - "docs": [ - "The market index for the perp market" - ], - "type": "u16" + "name": "OrderFilledWithMatchJit" }, { - "name": "openOrders", - "docs": [ - "The number of open orders" - ], - "type": "u8" + "name": "MarketExpired" }, { - "name": "perLpBase", - "type": "i8" + "name": "RiskingIncreasingOrder" + }, + { + "name": "ReduceOnlyOrderIncreasedPosition" + }, + { + "name": "OrderFillWithSerum" + }, + { + "name": "NoBorrowLiquidity" + }, + { + "name": "OrderFillWithPhoenix" + }, + { + "name": "OrderFilledWithAMMJitLPSplit" + }, + { + "name": "OrderFilledWithLPJit" + }, + { + "name": "DeriskLp" + }, + { + "name": "OrderFilledWithOpenbookV2" + }, + { + "name": "TransferPerpPosition" } ] } }, { - "name": "Order", + "name": "OrderActionRecord", "type": { "kind": "struct", "fields": [ { - "name": "slot", - "docs": [ - "The slot the order was placed" - ], - "type": "u64" + "name": "ts", + "type": "i64" }, { - "name": "price", - "docs": [ - "The limit price for the order (can be 0 for market orders)", - "For orders with an auction, this price isn't used until the auction is complete", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "action", + "type": { + "defined": { + "name": "OrderAction" + } + } }, { - "name": "baseAssetAmount", - "docs": [ - "The size of the order", - "precision for perps: BASE_PRECISION", - "precision for spot: token mint precision" - ], - "type": "u64" + "name": "action_explanation", + "type": { + "defined": { + "name": "OrderActionExplanation" + } + } }, { - "name": "baseAssetAmountFilled", - "docs": [ - "The amount of the order filled", - "precision for perps: BASE_PRECISION", - "precision for spot: token mint precision" - ], - "type": "u64" + "name": "market_index", + "type": "u16" + }, + { + "name": "market_type", + "type": { + "defined": { + "name": "MarketType" + } + } + }, + { + "name": "filler", + "type": { + "option": "pubkey" + } }, { - "name": "quoteAssetAmountFilled", + "name": "filler_reward", "docs": [ - "The amount of quote filled for the order", "precision: QUOTE_PRECISION" ], - "type": "u64" + "type": { + "option": "u64" + } }, { - "name": "triggerPrice", - "docs": [ - "At what price the order will be triggered. Only relevant for trigger orders", - "precision: PRICE_PRECISION" - ], - "type": "u64" + "name": "fill_record_id", + "type": { + "option": "u64" + } }, { - "name": "auctionStartPrice", + "name": "base_asset_amount_filled", "docs": [ - "The start price for the auction. Only relevant for market/oracle orders", - "precision: PRICE_PRECISION" + "precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)" ], - "type": "i64" + "type": { + "option": "u64" + } }, { - "name": "auctionEndPrice", + "name": "quote_asset_amount_filled", "docs": [ - "The end price for the auction. Only relevant for market/oracle orders", - "precision: PRICE_PRECISION" + "precision: QUOTE_PRECISION" ], - "type": "i64" + "type": { + "option": "u64" + } }, { - "name": "maxTs", + "name": "taker_fee", "docs": [ - "The time when the order will expire" + "precision: QUOTE_PRECISION" ], - "type": "i64" + "type": { + "option": "u64" + } }, { - "name": "oraclePriceOffset", + "name": "maker_fee", "docs": [ - "If set, the order limit price is the oracle price + this offset", - "precision: PRICE_PRECISION" + "precision: QUOTE_PRECISION" ], - "type": "i32" + "type": { + "option": "i64" + } }, { - "name": "orderId", + "name": "referrer_reward", "docs": [ - "The id for the order. Each users has their own order id space" + "precision: QUOTE_PRECISION" ], - "type": "u32" + "type": { + "option": "u32" + } }, { - "name": "marketIndex", + "name": "quote_asset_amount_surplus", "docs": [ - "The perp/spot market index" + "precision: QUOTE_PRECISION" ], - "type": "u16" + "type": { + "option": "i64" + } }, { - "name": "status", + "name": "spot_fulfillment_method_fee", "docs": [ - "Whether the order is open or unused" + "precision: QUOTE_PRECISION" ], "type": { - "defined": "OrderStatus" + "option": "u64" } }, { - "name": "orderType", - "docs": [ - "The type of order" - ], + "name": "taker", "type": { - "defined": "OrderType" + "option": "pubkey" } }, { - "name": "marketType", - "docs": [ - "Whether market is spot or perp" - ], + "name": "taker_order_id", "type": { - "defined": "MarketType" + "option": "u32" } }, { - "name": "userOrderId", - "docs": [ - "User generated order id. Can make it easier to place/cancel orders" - ], - "type": "u8" + "name": "taker_order_direction", + "type": { + "option": { + "defined": { + "name": "PositionDirection" + } + } + } }, { - "name": "existingPositionDirection", + "name": "taker_order_base_asset_amount", "docs": [ - "What the users position was when the order was placed" + "precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)" ], "type": { - "defined": "PositionDirection" + "option": "u64" } }, { - "name": "direction", + "name": "taker_order_cumulative_base_asset_amount_filled", "docs": [ - "Whether the user is going long or short. LONG = bid, SHORT = ask" + "precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)" ], "type": { - "defined": "PositionDirection" + "option": "u64" } }, { - "name": "reduceOnly", + "name": "taker_order_cumulative_quote_asset_amount_filled", "docs": [ - "Whether the order is allowed to only reduce position size" + "precision: QUOTE_PRECISION" ], - "type": "bool" + "type": { + "option": "u64" + } }, { - "name": "postOnly", - "docs": [ - "Whether the order must be a maker" - ], - "type": "bool" + "name": "maker", + "type": { + "option": "pubkey" + } }, { - "name": "immediateOrCancel", - "docs": [ - "Whether the order must be canceled the same slot it is placed" - ], - "type": "bool" + "name": "maker_order_id", + "type": { + "option": "u32" + } + }, + { + "name": "maker_order_direction", + "type": { + "option": { + "defined": { + "name": "PositionDirection" + } + } + } }, { - "name": "triggerCondition", + "name": "maker_order_base_asset_amount", "docs": [ - "Whether the order is triggered above or below the trigger price. Only relevant for trigger orders" + "precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)" ], "type": { - "defined": "OrderTriggerCondition" + "option": "u64" } }, { - "name": "auctionDuration", + "name": "maker_order_cumulative_base_asset_amount_filled", "docs": [ - "How many slots the auction lasts" + "precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)" ], - "type": "u8" + "type": { + "option": "u64" + } }, { - "name": "postedSlotTail", + "name": "maker_order_cumulative_quote_asset_amount_filled", "docs": [ - "Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)" + "precision: QUOTE_PRECISION" ], - "type": "u8" + "type": { + "option": "u64" + } }, { - "name": "bitFlags", + "name": "oracle_price", "docs": [ - "Bitflags for further classification", + "precision: PRICE_PRECISION" + ], + "type": "i64" + }, + { + "name": "bit_flags", + "docs": [ + "Bit flags:", "0: is_signed_message" ], "type": "u8" }, { - "name": "padding", + "name": "taker_existing_quote_entry_amount", + "docs": [ + "precision: QUOTE_PRECISION", + "Only Some if the taker reduced position" + ], "type": { - "array": [ - "u8", - 1 - ] + "option": "u64" } - } - ] - } - }, - { - "name": "SwapDirection", - "type": { - "kind": "enum", - "variants": [ + }, { - "name": "Add" + "name": "taker_existing_base_asset_amount", + "docs": [ + "precision: BASE_PRECISION", + "Only Some if the taker flipped position direction" + ], + "type": { + "option": "u64" + } }, { - "name": "Remove" - } - ] - } - }, - { - "name": "ModifyOrderId", - "type": { - "kind": "enum", - "variants": [ + "name": "maker_existing_quote_entry_amount", + "docs": [ + "precision: QUOTE_PRECISION", + "Only Some if the maker reduced position" + ], + "type": { + "option": "u64" + } + }, { - "name": "UserOrderId", - "fields": [ - "u8" - ] + "name": "maker_existing_base_asset_amount", + "docs": [ + "precision: BASE_PRECISION", + "Only Some if the maker flipped position direction" + ], + "type": { + "option": "u64" + } }, { - "name": "OrderId", - "fields": [ - "u32" - ] + "name": "trigger_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": { + "option": "u64" + } + }, + { + "name": "builder_idx", + "docs": [ + "the idx of the builder in the taker's [`RevenueShareEscrow`] account" + ], + "type": { + "option": "u8" + } + }, + { + "name": "builder_fee", + "docs": [ + "precision: QUOTE_PRECISION builder fee paid by the taker" + ], + "type": { + "option": "u64" + } } ] } }, { - "name": "PositionDirection", + "name": "OrderFillerRewardStructure", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Long" + "name": "reward_numerator", + "type": "u32" }, { - "name": "Short" + "name": "reward_denominator", + "type": "u32" + }, + { + "name": "time_based_reward_lower_bound", + "type": { + "defined": { + "name": "u128" + } + } } ] } }, { - "name": "SpotFulfillmentType", + "name": "OrderParams", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "SerumV3" + "name": "order_type", + "type": { + "defined": { + "name": "OrderType" + } + } }, { - "name": "Match" + "name": "market_type", + "type": { + "defined": { + "name": "MarketType" + } + } }, { - "name": "PhoenixV1" + "name": "direction", + "type": { + "defined": { + "name": "PositionDirection" + } + } }, { - "name": "OpenbookV2" - } - ] - } - }, - { - "name": "SwapReduceOnly", - "type": { - "kind": "enum", - "variants": [ + "name": "user_order_id", + "type": "u8" + }, { - "name": "In" + "name": "base_asset_amount", + "type": "u64" }, { - "name": "Out" - } - ] - } - }, - { - "name": "TwapPeriod", - "type": { - "kind": "enum", - "variants": [ + "name": "price", + "type": "u64" + }, { - "name": "FundingPeriod" + "name": "market_index", + "type": "u16" }, { - "name": "FiveMin" - } - ] - } - }, - { - "name": "LiquidationMultiplierType", - "type": { - "kind": "enum", - "variants": [ + "name": "reduce_only", + "type": "bool" + }, { - "name": "Discount" + "name": "post_only", + "type": { + "defined": { + "name": "PostOnlyParam" + } + } }, { - "name": "Premium" - } - ] - } - }, - { - "name": "SettlementDirection", - "type": { - "kind": "enum", - "variants": [ + "name": "bit_flags", + "type": "u8" + }, { - "name": "ToLpPool" + "name": "max_ts", + "type": { + "option": "i64" + } }, { - "name": "FromLpPool" + "name": "trigger_price", + "type": { + "option": "u64" + } }, { - "name": "None" + "name": "trigger_condition", + "type": { + "defined": { + "name": "OrderTriggerCondition" + } + } + }, + { + "name": "oracle_price_offset", + "type": { + "option": "i32" + } + }, + { + "name": "auction_duration", + "type": { + "option": "u8" + } + }, + { + "name": "auction_start_price", + "type": { + "option": "i64" + } + }, + { + "name": "auction_end_price", + "type": { + "option": "i64" + } } ] } }, { - "name": "MarginRequirementType", + "name": "OrderRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Initial" + "name": "ts", + "type": "i64" }, { - "name": "Fill" + "name": "user", + "type": "pubkey" }, { - "name": "Maintenance" + "name": "order", + "type": { + "defined": { + "name": "Order" + } + } } ] } }, { - "name": "OracleValidity", + "name": "OrderStatus", "type": { "kind": "enum", "variants": [ { - "name": "NonPositive" - }, - { - "name": "TooVolatile" - }, - { - "name": "TooUncertain" - }, - { - "name": "StaleForMargin" + "name": "Init" }, { - "name": "InsufficientDataPoints" + "name": "Open" }, { - "name": "StaleForAMM", - "fields": [ - { - "name": "immediate", - "type": "bool" - }, - { - "name": "lowRisk", - "type": "bool" - } - ] + "name": "Filled" }, { - "name": "Valid" + "name": "Canceled" } ] } }, { - "name": "DriftAction", + "name": "OrderTriggerCondition", "type": { "kind": "enum", "variants": [ { - "name": "UpdateFunding" - }, - { - "name": "SettlePnl" - }, - { - "name": "TriggerOrder" - }, - { - "name": "FillOrderMatch" - }, - { - "name": "FillOrderAmmLowRisk" - }, - { - "name": "FillOrderAmmImmediate" - }, - { - "name": "Liquidate" - }, - { - "name": "MarginCalc" - }, - { - "name": "UpdateTwap" - }, - { - "name": "UpdateAMMCurve" - }, - { - "name": "OracleOrderPrice" - }, - { - "name": "UseMMOraclePrice" + "name": "Above" }, { - "name": "UpdateAmmCache" + "name": "Below" }, { - "name": "UpdateLpPoolAum" + "name": "TriggeredAbove" }, { - "name": "LpPoolSwap" + "name": "TriggeredBelow" } ] } }, { - "name": "LogMode", + "name": "OrderType", "type": { "kind": "enum", "variants": [ { - "name": "None" + "name": "Market" }, { - "name": "ExchangeOracle" + "name": "Limit" }, { - "name": "MMOracle" + "name": "TriggerMarket" }, { - "name": "SafeMMOracle" + "name": "TriggerLimit" }, { - "name": "Margin" + "name": "Oracle" } ] } }, { - "name": "PositionUpdateType", + "name": "OverrideAmmCacheParams", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Open" + "name": "quote_owed_from_lp_pool", + "type": { + "option": "i64" + } + }, + { + "name": "last_settle_slot", + "type": { + "option": "u64" + } }, { - "name": "Increase" + "name": "last_fee_pool_token_amount", + "type": { + "option": "u128" + } }, { - "name": "Reduce" + "name": "last_net_pnl_pool_token_amount", + "type": { + "option": "i128" + } }, { - "name": "Close" + "name": "amm_position_scalar", + "type": { + "option": "u8" + } }, { - "name": "Flip" + "name": "amm_inventory_limit", + "type": { + "option": "i64" + } } ] } }, { - "name": "DepositExplanation", + "name": "PerpBankruptcyRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "None" + "name": "market_index", + "type": "u16" }, { - "name": "Transfer" + "name": "pnl", + "type": "i128" }, { - "name": "Borrow" + "name": "if_payment", + "type": "u128" }, { - "name": "RepayBorrow" + "name": "clawback_user", + "type": { + "option": "pubkey" + } }, { - "name": "Reward" - } - ] - } - }, - { - "name": "DepositDirection", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Deposit" + "name": "clawback_user_payment", + "type": { + "option": "u128" + } }, { - "name": "Withdraw" + "name": "cumulative_funding_rate_delta", + "type": "i128" } ] } }, { - "name": "OrderAction", + "name": "PerpMarket", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Place" + "name": "pubkey", + "docs": [ + "The perp market's address. It is a pda of the market index" + ], + "type": "pubkey" }, { - "name": "Cancel" + "name": "amm", + "docs": [ + "The automated market maker" + ], + "type": { + "defined": { + "name": "AMM" + } + } }, { - "name": "Fill" + "name": "pnl_pool", + "docs": [ + "The market's pnl pool. When users settle negative pnl, the balance increases.", + "When users settle positive pnl, the balance decreases. Can not go negative." + ], + "type": { + "defined": { + "name": "PoolBalance" + } + } }, { - "name": "Trigger" + "name": "name", + "docs": [ + "Encoded display name for the perp market e.g. SOL-PERP" + ], + "type": { + "array": [ + "u8", + 32 + ] + } }, { - "name": "Expire" - } - ] - } - }, - { - "name": "OrderActionExplanation", - "type": { - "kind": "enum", - "variants": [ - { - "name": "None" + "name": "insurance_claim", + "docs": [ + "The perp market's claim on the insurance fund" + ], + "type": { + "defined": { + "name": "InsuranceClaim" + } + } }, { - "name": "InsufficientFreeCollateral" + "name": "unrealized_pnl_max_imbalance", + "docs": [ + "The max pnl imbalance before positive pnl asset weight is discounted", + "pnl imbalance is the difference between long and short pnl. When it's greater than 0,", + "the amm has negative pnl and the initial asset weight for positive pnl is discounted", + "precision = QUOTE_PRECISION" + ], + "type": "u64" }, { - "name": "OraclePriceBreachedLimitPrice" + "name": "expiry_ts", + "docs": [ + "The ts when the market will be expired. Only set if market is in reduce only mode" + ], + "type": "i64" }, { - "name": "MarketOrderFilledToLimitPrice" + "name": "expiry_price", + "docs": [ + "The price at which positions will be settled. Only set if market is expired", + "precision = PRICE_PRECISION" + ], + "type": "i64" }, { - "name": "OrderExpired" + "name": "next_fill_record_id", + "docs": [ + "Every trade has a fill record id. This is the next id to be used" + ], + "type": "u64" }, { - "name": "Liquidation" + "name": "next_funding_rate_record_id", + "docs": [ + "Every funding rate update has a record id. This is the next id to be used" + ], + "type": "u64" }, { - "name": "OrderFilledWithAMM" + "name": "next_curve_record_id", + "docs": [ + "Every amm k updated has a record id. This is the next id to be used" + ], + "type": "u64" }, { - "name": "OrderFilledWithAMMJit" + "name": "imf_factor", + "docs": [ + "The initial margin fraction factor. Used to increase margin ratio for large positions", + "precision: MARGIN_PRECISION" + ], + "type": "u32" }, { - "name": "OrderFilledWithMatch" + "name": "unrealized_pnl_imf_factor", + "docs": [ + "The imf factor for unrealized pnl. Used to discount asset weight for large positive pnl", + "precision: MARGIN_PRECISION" + ], + "type": "u32" }, { - "name": "OrderFilledWithMatchJit" + "name": "liquidator_fee", + "docs": [ + "The fee the liquidator is paid for taking over perp position", + "precision: LIQUIDATOR_FEE_PRECISION" + ], + "type": "u32" }, { - "name": "MarketExpired" + "name": "if_liquidation_fee", + "docs": [ + "The fee the insurance fund receives from liquidation", + "precision: LIQUIDATOR_FEE_PRECISION" + ], + "type": "u32" }, { - "name": "RiskingIncreasingOrder" + "name": "margin_ratio_initial", + "docs": [ + "The margin ratio which determines how much collateral is required to open a position", + "e.g. margin ratio of .1 means a user must have $100 of total collateral to open a $1000 position", + "precision: MARGIN_PRECISION" + ], + "type": "u32" }, { - "name": "ReduceOnlyOrderIncreasedPosition" + "name": "margin_ratio_maintenance", + "docs": [ + "The margin ratio which determines when a user will be liquidated", + "e.g. margin ratio of .05 means a user must have $50 of total collateral to maintain a $1000 position", + "else they will be liquidated", + "precision: MARGIN_PRECISION" + ], + "type": "u32" }, { - "name": "OrderFillWithSerum" + "name": "unrealized_pnl_initial_asset_weight", + "docs": [ + "The initial asset weight for positive pnl. Negative pnl always has an asset weight of 1", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, { - "name": "NoBorrowLiquidity" + "name": "unrealized_pnl_maintenance_asset_weight", + "docs": [ + "The maintenance asset weight for positive pnl. Negative pnl always has an asset weight of 1", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, { - "name": "OrderFillWithPhoenix" + "name": "number_of_users_with_base", + "docs": [ + "number of users in a position (base)" + ], + "type": "u32" }, { - "name": "OrderFilledWithAMMJitLPSplit" + "name": "number_of_users", + "docs": [ + "number of users in a position (pnl) or pnl (quote)" + ], + "type": "u32" }, { - "name": "OrderFilledWithLPJit" + "name": "market_index", + "type": "u16" }, { - "name": "DeriskLp" + "name": "status", + "docs": [ + "Whether a market is active, reduce only, expired, etc", + "Affects whether users can open/close positions" + ], + "type": { + "defined": { + "name": "MarketStatus" + } + } }, { - "name": "OrderFilledWithOpenbookV2" + "name": "contract_type", + "docs": [ + "Currently only Perpetual markets are supported" + ], + "type": { + "defined": { + "name": "ContractType" + } + } }, { - "name": "TransferPerpPosition" - } - ] - } - }, - { - "name": "LPAction", - "type": { - "kind": "enum", - "variants": [ - { - "name": "AddLiquidity" + "name": "contract_tier", + "docs": [ + "The contract tier determines how much insurance a market can receive, with more speculative markets receiving less insurance", + "It also influences the order perp markets can be liquidated, with less speculative markets being liquidated first" + ], + "type": { + "defined": { + "name": "ContractTier" + } + } }, { - "name": "RemoveLiquidity" + "name": "paused_operations", + "type": "u8" }, { - "name": "SettleLiquidity" + "name": "quote_spot_market_index", + "docs": [ + "The spot market that pnl is settled in" + ], + "type": "u16" }, { - "name": "RemoveLiquidityDerisk" - } - ] - } - }, - { - "name": "LiquidationType", - "type": { - "kind": "enum", - "variants": [ - { - "name": "LiquidatePerp" + "name": "fee_adjustment", + "docs": [ + "Between -100 and 100, represents what % to increase/decrease the fee by", + "E.g. if this is -50 and the fee is 5bps, the new fee will be 2.5bps", + "if this is 50 and the fee is 5bps, the new fee will be 7.5bps" + ], + "type": "i16" }, { - "name": "LiquidateSpot" + "name": "fuel_boost_position", + "docs": [ + "fuel multiplier for perp funding", + "precision: 10" + ], + "type": "u8" }, { - "name": "LiquidateBorrowForPerpPnl" + "name": "fuel_boost_taker", + "docs": [ + "fuel multiplier for perp taker", + "precision: 10" + ], + "type": "u8" }, { - "name": "LiquidatePerpPnlForDeposit" + "name": "fuel_boost_maker", + "docs": [ + "fuel multiplier for perp maker", + "precision: 10" + ], + "type": "u8" }, { - "name": "PerpBankruptcy" + "name": "pool_id", + "type": "u8" }, { - "name": "SpotBankruptcy" - } - ] - } - }, - { - "name": "SettlePnlExplanation", - "type": { - "kind": "enum", - "variants": [ - { - "name": "None" + "name": "high_leverage_margin_ratio_initial", + "type": "u16" }, { - "name": "ExpiredPosition" - } - ] - } - }, - { - "name": "StakeAction", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Stake" + "name": "high_leverage_margin_ratio_maintenance", + "type": "u16" }, { - "name": "UnstakeRequest" + "name": "protected_maker_limit_price_divisor", + "type": "u8" }, { - "name": "UnstakeCancelRequest" + "name": "protected_maker_dynamic_divisor", + "type": "u8" }, { - "name": "Unstake" + "name": "lp_fee_transfer_scalar", + "type": "u8" }, { - "name": "UnstakeTransfer" + "name": "lp_status", + "type": "u8" }, { - "name": "StakeTransfer" + "name": "lp_paused_operations", + "type": "u8" }, { - "name": "AdminDeposit" - } - ] - } - }, - { - "name": "FillMode", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Fill" + "name": "lp_exchange_fee_excluscion_scalar", + "type": "u8" }, { - "name": "PlaceAndMake" + "name": "last_fill_price", + "type": "u64" }, { - "name": "PlaceAndTake", - "fields": [ - "bool", - "u8" - ] + "name": "lp_pool_id", + "type": "u8" }, { - "name": "Liquidation" + "name": "padding", + "type": { + "array": [ + "u8", + 23 + ] + } } ] } }, { - "name": "PerpFulfillmentMethod", + "name": "PerpPosition", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "AMM", - "fields": [ - { - "option": "u64" - } - ] + "name": "last_cumulative_funding_rate", + "docs": [ + "The perp market's last cumulative funding rate. Used to calculate the funding payment owed to user", + "precision: FUNDING_RATE_PRECISION" + ], + "type": "i64" }, { - "name": "Match", - "fields": [ - "publicKey", - "u16", - "u64" - ] - } - ] - } - }, - { - "name": "SpotFulfillmentMethod", - "type": { - "kind": "enum", - "variants": [ - { - "name": "ExternalMarket" + "name": "base_asset_amount", + "docs": [ + "the size of the users perp position", + "precision: BASE_PRECISION" + ], + "type": "i64" }, { - "name": "Match", - "fields": [ - "publicKey", - "u16" - ] - } - ] - } - }, - { - "name": "ConstituentStatus", - "type": { - "kind": "enum", - "variants": [ + "name": "quote_asset_amount", + "docs": [ + "Used to calculate the users pnl. Upon entry, is equal to base_asset_amount * avg entry price - fees", + "Updated when the user open/closes position or settles pnl. Includes fees/funding", + "precision: QUOTE_PRECISION" + ], + "type": "i64" + }, { - "name": "ReduceOnly" + "name": "quote_break_even_amount", + "docs": [ + "The amount of quote the user would need to exit their position at to break even", + "Updated when the user open/closes position or settles pnl. Includes fees/funding", + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "Decommissioned" - } - ] - } - }, - { - "name": "MarginCalculationMode", - "type": { - "kind": "enum", - "variants": [ + "name": "quote_entry_amount", + "docs": [ + "The amount quote the user entered the position with. Equal to base asset amount * avg entry price", + "Updated when the user open/closes position. Excludes fees/funding", + "precision: QUOTE_PRECISION" + ], + "type": "i64" + }, { - "name": "Standard", - "fields": [ - { - "name": "trackOpenOrdersFraction", - "type": "bool" - } - ] + "name": "open_bids", + "docs": [ + "The amount of non reduce only trigger orders the user has open", + "precision: BASE_PRECISION" + ], + "type": "i64" }, { - "name": "Liquidation", - "fields": [ - { - "name": "marketToTrackMarginRequirement", - "type": { - "option": { - "defined": "MarketIdentifier" - } - } - } - ] - } - ] - } - }, - { - "name": "OracleSource", - "type": { - "kind": "enum", - "variants": [ + "name": "open_asks", + "docs": [ + "The amount of non reduce only trigger orders the user has open", + "precision: BASE_PRECISION" + ], + "type": "i64" + }, { - "name": "Pyth" + "name": "settled_pnl", + "docs": [ + "The amount of pnl settled in this market since opening the position", + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "Switchboard" + "name": "lp_shares", + "docs": [ + "The number of lp (liquidity provider) shares the user has in this perp market", + "LP shares allow users to provide liquidity via the AMM", + "precision: BASE_PRECISION" + ], + "type": "u64" }, { - "name": "QuoteAsset" + "name": "last_base_asset_amount_per_lp", + "docs": [ + "The last base asset amount per lp the amm had", + "Used to settle the users lp position", + "precision: BASE_PRECISION" + ], + "type": "i64" }, { - "name": "Pyth1K" + "name": "last_quote_asset_amount_per_lp", + "docs": [ + "The last quote asset amount per lp the amm had", + "Used to settle the users lp position", + "precision: QUOTE_PRECISION" + ], + "type": "i64" }, { - "name": "Pyth1M" + "name": "padding", + "type": { + "array": [ + "u8", + 2 + ] + } }, { - "name": "PythStableCoin" + "name": "max_margin_ratio", + "type": "u16" }, { - "name": "Prelaunch" + "name": "market_index", + "docs": [ + "The market index for the perp market" + ], + "type": "u16" }, { - "name": "PythPull" + "name": "open_orders", + "docs": [ + "The number of open orders" + ], + "type": "u8" }, { - "name": "Pyth1KPull" + "name": "per_lp_base", + "type": "i8" + } + ] + } + }, + { + "name": "PhoenixV1FulfillmentConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pubkey", + "type": "pubkey" }, { - "name": "Pyth1MPull" + "name": "phoenix_program_id", + "type": "pubkey" }, { - "name": "PythStableCoinPull" + "name": "phoenix_log_authority", + "type": "pubkey" }, { - "name": "SwitchboardOnDemand" + "name": "phoenix_market", + "type": "pubkey" }, { - "name": "PythLazer" + "name": "phoenix_base_vault", + "type": "pubkey" }, { - "name": "PythLazer1K" + "name": "phoenix_quote_vault", + "type": "pubkey" }, { - "name": "PythLazer1M" + "name": "market_index", + "type": "u16" }, { - "name": "PythLazerStableCoin" - } - ] - } - }, - { - "name": "OrderParamsBitFlag", - "type": { - "kind": "enum", - "variants": [ + "name": "fulfillment_type", + "type": { + "defined": { + "name": "SpotFulfillmentType" + } + } + }, { - "name": "ImmediateOrCancel" + "name": "status", + "type": { + "defined": { + "name": "SpotFulfillmentConfigStatus" + } + } }, { - "name": "UpdateHighLeverageMode" + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } } ] } }, { - "name": "PostOnlyParam", + "name": "PoolBalance", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ - { - "name": "None" - }, + "kind": "struct", + "fields": [ { - "name": "MustPostOnly" + "name": "scaled_balance", + "docs": [ + "To get the pool's token amount, you must multiply the scaled balance by the market's cumulative", + "deposit interest", + "precision: SPOT_BALANCE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, { - "name": "TryPostOnly" + "name": "market_index", + "docs": [ + "The spot market the pool is for" + ], + "type": "u16" }, { - "name": "Slide" + "name": "padding", + "type": { + "array": [ + "u8", + 6 + ] + } } ] } }, { - "name": "ModifyOrderPolicy", + "name": "PositionDirection", "type": { "kind": "enum", "variants": [ { - "name": "MustModify" + "name": "Long" }, { - "name": "ExcludePreviousFill" + "name": "Short" } ] } }, { - "name": "PlaceAndTakeOrderSuccessCondition", + "name": "PostOnlyParam", "type": { "kind": "enum", "variants": [ { - "name": "PartialFill" + "name": "None" + }, + { + "name": "MustPostOnly" + }, + { + "name": "TryPostOnly" }, { - "name": "FullFill" + "name": "Slide" } ] } }, { - "name": "PerpOperation", + "name": "PrelaunchOracle", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ - { - "name": "UpdateFunding" - }, + "kind": "struct", + "fields": [ { - "name": "AmmFill" + "name": "price", + "type": "i64" }, { - "name": "Fill" + "name": "max_price", + "type": "i64" }, { - "name": "SettlePnl" + "name": "confidence", + "type": "u64" }, { - "name": "SettlePnlWithPosition" + "name": "last_update_slot", + "type": "u64" }, { - "name": "Liquidation" + "name": "amm_last_update_slot", + "type": "u64" }, { - "name": "AmmImmediateFill" + "name": "perp_market_index", + "type": "u16" }, { - "name": "SettleRevPool" + "name": "padding", + "type": { + "array": [ + "u8", + 70 + ] + } } ] } }, { - "name": "SpotOperation", + "name": "PrelaunchOracleParams", "type": { - "kind": "enum", - "variants": [ - { - "name": "UpdateCumulativeInterest" - }, - { - "name": "Fill" - }, + "kind": "struct", + "fields": [ { - "name": "Deposit" + "name": "perp_market_index", + "type": "u16" }, { - "name": "Withdraw" + "name": "price", + "type": { + "option": "i64" + } }, { - "name": "Liquidation" + "name": "max_price", + "type": { + "option": "i64" + } } ] } }, { - "name": "InsuranceFundOperation", + "name": "PriceDivergenceGuardRails", "type": { - "kind": "enum", - "variants": [ - { - "name": "Init" - }, - { - "name": "Add" - }, + "kind": "struct", + "fields": [ { - "name": "RequestRemove" + "name": "mark_oracle_percent_divergence", + "type": "u64" }, { - "name": "Remove" + "name": "oracle_twap_5min_percent_divergence", + "type": "u64" } ] } }, { - "name": "PerpLpOperation", + "name": "ProtectedMakerModeConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "TrackAmmRevenue" + "name": "max_users", + "type": "u32" }, { - "name": "SettleQuoteOwed" - } - ] - } - }, - { - "name": "ConstituentLpOperation", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Swap" + "name": "current_users", + "type": "u32" }, { - "name": "Deposit" + "name": "reduce_only", + "type": "u8" }, { - "name": "Withdraw" + "name": "padding", + "type": { + "array": [ + "u8", + 31 + ] + } } ] } }, { - "name": "MarketStatus", + "name": "PythLazerOracle", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ - { - "name": "Initialized" - }, - { - "name": "Active" - }, - { - "name": "FundingPaused" - }, + "kind": "struct", + "fields": [ { - "name": "AmmPaused" + "name": "price", + "type": "i64" }, { - "name": "FillPaused" + "name": "publish_time", + "type": "u64" }, { - "name": "WithdrawPaused" + "name": "posted_slot", + "type": "u64" }, { - "name": "ReduceOnly" + "name": "exponent", + "type": "i32" }, { - "name": "Settlement" + "name": "_padding", + "type": { + "array": [ + "u8", + 4 + ] + } }, { - "name": "Delisted" + "name": "conf", + "type": "u64" } ] } }, { - "name": "LpStatus", + "name": "ReferrerName", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Uncollateralized" + "name": "authority", + "type": "pubkey" }, { - "name": "Active" + "name": "user", + "type": "pubkey" + }, + { + "name": "user_stats", + "type": "pubkey" }, { - "name": "Decommissioning" + "name": "name", + "type": { + "array": [ + "u8", + 32 + ] + } } ] } }, { - "name": "ContractType", + "name": "RevenueShare", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "rust", + "packed": true + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Perpetual" + "name": "authority", + "docs": [ + "the owner of this account, a builder or referrer" + ], + "type": "pubkey" }, { - "name": "Future" + "name": "total_referrer_rewards", + "type": "u64" }, { - "name": "Prediction" + "name": "total_builder_rewards", + "type": "u64" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 18 + ] + } } ] } }, { - "name": "ContractTier", + "name": "RevenueShareEscrow", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "A" + "name": "authority", + "docs": [ + "the owner of this account, a user" + ], + "type": "pubkey" }, { - "name": "B" + "name": "referrer", + "type": "pubkey" }, { - "name": "C" + "name": "referrer_boost_expire_ts", + "type": "u32" }, { - "name": "Speculative" + "name": "referrer_reward_offset", + "type": "i8" }, { - "name": "HighlySpeculative" + "name": "referee_fee_numerator_offset", + "type": "i8" }, { - "name": "Isolated" - } - ] - } - }, - { - "name": "RevenueShareOrderBitFlag", - "type": { - "kind": "enum", - "variants": [ + "name": "referrer_boost_numerator", + "type": "i8" + }, { - "name": "Init" + "name": "reserved_fixed", + "type": { + "array": [ + "u8", + 17 + ] + } }, { - "name": "Open" + "name": "padding0", + "type": "u32" }, { - "name": "Completed" + "name": "orders", + "type": { + "vec": { + "defined": { + "name": "RevenueShareOrder" + } + } + } }, { - "name": "Referral" - } - ] - } - }, - { - "name": "SettlePnlMode", - "type": { - "kind": "enum", - "variants": [ - { - "name": "MustSettle" + "name": "padding1", + "type": "u32" }, { - "name": "TrySettle" + "name": "approved_builders", + "type": { + "vec": { + "defined": { + "name": "BuilderInfo" + } + } + } } ] } }, { - "name": "SpotBalanceType", + "name": "RevenueShareOrder", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Deposit" + "name": "fees_accrued", + "docs": [ + "fees accrued so far for this order slot. This is not exclusively fees from this order_id", + "and may include fees from other orders in the same market. This may be swept to the", + "builder's SpotPosition during settle_pnl." + ], + "type": "u64" }, { - "name": "Borrow" - } - ] - } - }, - { - "name": "SpotFulfillmentConfigStatus", - "type": { - "kind": "enum", - "variants": [ - { - "name": "Enabled" + "name": "order_id", + "docs": [ + "the order_id of the current active order in this slot. It's only relevant while bit_flag = Open" + ], + "type": "u32" }, { - "name": "Disabled" - } - ] - } - }, - { - "name": "AssetTier", - "type": { - "kind": "enum", - "variants": [ + "name": "fee_tenth_bps", + "docs": [ + "the builder fee on this order, in tenths of a bps, e.g. 100 = 0.01%" + ], + "type": "u16" + }, { - "name": "Collateral" + "name": "market_index", + "type": "u16" }, { - "name": "Protected" + "name": "sub_account_id", + "docs": [ + "the subaccount_id of the user who created this order. It's only relevant while bit_flag = Open" + ], + "type": "u16" }, { - "name": "Cross" + "name": "builder_idx", + "docs": [ + "the index of the RevenueShareEscrow.approved_builders list, that this order's fee will settle to. Ignored", + "if bit_flag = Referral." + ], + "type": "u8" }, { - "name": "Isolated" + "name": "bit_flags", + "docs": [ + "bitflags that describe the state of the order.", + "[`RevenueShareOrderBitFlag::Init`]: this order slot is available for use.", + "[`RevenueShareOrderBitFlag::Open`]: this order slot is occupied, `order_id` is the `sub_account_id`'s active order.", + "[`RevenueShareOrderBitFlag::Completed`]: this order has been filled or canceled, and is waiting to be settled into.", + "the builder's account order_id and sub_account_id are no longer relevant, it may be merged with other orders.", + "[`RevenueShareOrderBitFlag::Referral`]: this order stores referral rewards waiting to be settled for this market.", + "If it is set, no other bitflag should be set." + ], + "type": "u8" }, { - "name": "Unlisted" - } - ] - } - }, - { - "name": "TokenProgramFlag", - "type": { - "kind": "enum", - "variants": [ + "name": "user_order_index", + "docs": [ + "the index into the User's orders list when this RevenueShareOrder was created, make sure to verify that order_id matches." + ], + "type": "u8" + }, { - "name": "Token2022" + "name": "market_type", + "type": { + "defined": { + "name": "MarketType" + } + } }, { - "name": "TransferHook" + "name": "padding", + "type": { + "array": [ + "u8", + 10 + ] + } } ] } }, { - "name": "ExchangeStatus", + "name": "RevenueShareSettleRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "DepositPaused" + "name": "ts", + "type": "i64" }, { - "name": "WithdrawPaused" + "name": "builder", + "type": { + "option": "pubkey" + } }, { - "name": "AmmPaused" + "name": "referrer", + "type": { + "option": "pubkey" + } }, { - "name": "FillPaused" + "name": "fee_settled", + "type": "u64" }, { - "name": "LiqPaused" + "name": "market_index", + "type": "u16" }, { - "name": "FundingPaused" + "name": "market_type", + "type": { + "defined": { + "name": "MarketType" + } + } + }, + { + "name": "builder_sub_account_id", + "type": "u16" }, { - "name": "SettlePnlPaused" + "name": "builder_total_referrer_rewards", + "type": "u64" }, { - "name": "AmmImmediateFillPaused" + "name": "builder_total_builder_rewards", + "type": "u64" } ] } }, { - "name": "FeatureBitFlags", + "name": "SerumV3FulfillmentConfig", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "MmOracleUpdate" + "name": "pubkey", + "type": "pubkey" }, { - "name": "MedianTriggerPrice" + "name": "serum_program_id", + "type": "pubkey" }, { - "name": "BuilderCodes" + "name": "serum_market", + "type": "pubkey" }, { - "name": "BuilderReferral" - } - ] - } - }, - { - "name": "LpPoolFeatureBitFlags", - "type": { - "kind": "enum", - "variants": [ + "name": "serum_request_queue", + "type": "pubkey" + }, { - "name": "SettleLpPool" + "name": "serum_event_queue", + "type": "pubkey" }, { - "name": "SwapLpPool" + "name": "serum_bids", + "type": "pubkey" }, { - "name": "MintRedeemLpPool" - } - ] - } - }, - { - "name": "UserStatus", - "type": { - "kind": "enum", - "variants": [ + "name": "serum_asks", + "type": "pubkey" + }, { - "name": "BeingLiquidated" + "name": "serum_base_vault", + "type": "pubkey" }, { - "name": "Bankrupt" + "name": "serum_quote_vault", + "type": "pubkey" }, { - "name": "ReduceOnly" + "name": "serum_open_orders", + "type": "pubkey" + }, + { + "name": "serum_signer_nonce", + "type": "u64" + }, + { + "name": "market_index", + "type": "u16" + }, + { + "name": "fulfillment_type", + "type": { + "defined": { + "name": "SpotFulfillmentType" + } + } }, { - "name": "AdvancedLp" + "name": "status", + "type": { + "defined": { + "name": "SpotFulfillmentConfigStatus" + } + } }, { - "name": "ProtectedMakerOrders" + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } } ] } }, { - "name": "AssetType", + "name": "SettlePnlExplanation", "type": { "kind": "enum", "variants": [ { - "name": "Base" + "name": "None" }, { - "name": "Quote" + "name": "ExpiredPosition" } ] } }, { - "name": "OrderStatus", + "name": "SettlePnlMode", "type": { "kind": "enum", "variants": [ { - "name": "Init" - }, - { - "name": "Open" - }, - { - "name": "Filled" + "name": "MustSettle" }, { - "name": "Canceled" + "name": "TrySettle" } ] } }, { - "name": "OrderType", + "name": "SettlePnlRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "Market" + "name": "ts", + "type": "i64" }, { - "name": "Limit" + "name": "user", + "type": "pubkey" }, { - "name": "TriggerMarket" + "name": "market_index", + "type": "u16" }, { - "name": "TriggerLimit" + "name": "pnl", + "type": "i128" }, { - "name": "Oracle" - } - ] - } - }, - { - "name": "OrderTriggerCondition", - "type": { - "kind": "enum", - "variants": [ + "name": "base_asset_amount", + "type": "i64" + }, { - "name": "Above" + "name": "quote_asset_amount_after", + "type": "i64" }, { - "name": "Below" + "name": "quote_entry_amount", + "type": "i64" }, { - "name": "TriggeredAbove" + "name": "settle_price", + "type": "i64" }, { - "name": "TriggeredBelow" + "name": "explanation", + "type": { + "defined": { + "name": "SettlePnlExplanation" + } + } } ] } }, { - "name": "MarketType", + "name": "SignedMsgOrderId", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ - { - "name": "Spot" + "kind": "struct", + "fields": [ + { + "name": "uuid", + "type": { + "array": [ + "u8", + 8 + ] + } }, { - "name": "Perp" + "name": "max_slot", + "type": "u64" + }, + { + "name": "order_id", + "type": "u32" + }, + { + "name": "padding", + "type": "u32" } ] } }, { - "name": "OrderBitFlag", + "name": "SignedMsgOrderRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ + { + "name": "user", + "type": "pubkey" + }, { - "name": "SignedMessage" + "name": "hash", + "type": "string" + }, + { + "name": "matching_order_params", + "type": { + "defined": { + "name": "OrderParams" + } + } }, { - "name": "OracleTriggerMarket" + "name": "user_order_id", + "type": "u32" }, { - "name": "SafeTriggerOrder" + "name": "signed_msg_order_max_slot", + "type": "u64" }, { - "name": "NewTriggerReduceOnly" + "name": "signed_msg_order_uuid", + "type": { + "array": [ + "u8", + 8 + ] + } }, { - "name": "HasBuilder" + "name": "ts", + "type": "i64" } ] } }, { - "name": "ReferrerStatus", + "name": "SignedMsgUserOrders", + "docs": [ + "* This struct is a duplicate of SignedMsgUserOrdersZeroCopy\n * It is used to give anchor an struct to generate the idl for clients\n * The struct SignedMsgUserOrdersZeroCopy is used to load the data in efficiently" + ], + "repr": { + "kind": "c" + }, "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ { - "name": "IsReferrer" + "name": "authority_pubkey", + "type": "pubkey" }, { - "name": "IsReferred" + "name": "padding", + "type": "u32" }, { - "name": "BuilderReferral" + "name": "signed_msg_order_data", + "type": { + "vec": { + "defined": { + "name": "SignedMsgOrderId" + } + } + } } ] } }, { - "name": "MarginMode", + "name": "SignedMsgWsDelegates", + "docs": [ + "* Used to store authenticated delegates for swift-like ws connections" + ], + "type": { + "kind": "struct", + "fields": [ + { + "name": "delegates", + "type": { + "vec": "pubkey" + } + } + ] + } + }, + { + "name": "SpotBalanceType", "type": { "kind": "enum", "variants": [ { - "name": "Default" - }, - { - "name": "HighLeverage" + "name": "Deposit" }, { - "name": "HighLeverageMaintenance" + "name": "Borrow" } ] } }, { - "name": "FuelOverflowStatus", + "name": "SpotBankruptcyRecord", "type": { - "kind": "enum", - "variants": [ + "kind": "struct", + "fields": [ + { + "name": "market_index", + "type": "u16" + }, + { + "name": "borrow_amount", + "type": "u128" + }, + { + "name": "if_payment", + "type": "u128" + }, { - "name": "Exists" + "name": "cumulative_deposit_interest_delta", + "type": "u128" } ] } }, { - "name": "UserStatsPausedOperations", + "name": "SpotFulfillmentConfigStatus", "type": { "kind": "enum", "variants": [ { - "name": "UpdateBidAskTwap" - }, - { - "name": "AmmAtomicFill" + "name": "Enabled" }, { - "name": "AmmAtomicRiskIncreasingFill" + "name": "Disabled" } ] } }, { - "name": "SignatureVerificationError", + "name": "SpotFulfillmentType", "type": { "kind": "enum", "variants": [ { - "name": "InvalidEd25519InstructionProgramId" + "name": "SerumV3" }, { - "name": "InvalidEd25519InstructionDataLength" + "name": "Match" }, { - "name": "InvalidSignatureIndex" + "name": "PhoenixV1" }, { - "name": "InvalidSignatureOffset" + "name": "OpenbookV2" + } + ] + } + }, + { + "name": "SpotInterestRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" }, { - "name": "InvalidPublicKeyOffset" + "name": "market_index", + "type": "u16" }, { - "name": "InvalidMessageOffset" + "name": "deposit_balance", + "docs": [ + "precision: SPOT_BALANCE_PRECISION" + ], + "type": "u128" }, { - "name": "InvalidMessageDataSize" + "name": "cumulative_deposit_interest", + "docs": [ + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": "u128" }, { - "name": "InvalidInstructionIndex" + "name": "borrow_balance", + "docs": [ + "precision: SPOT_BALANCE_PRECISION" + ], + "type": "u128" }, { - "name": "MessageOffsetOverflow" + "name": "cumulative_borrow_interest", + "docs": [ + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": "u128" }, { - "name": "InvalidMessageHex" + "name": "optimal_utilization", + "docs": [ + "precision: PERCENTAGE_PRECISION" + ], + "type": "u32" }, { - "name": "InvalidMessageData" + "name": "optimal_borrow_rate", + "docs": [ + "precision: PERCENTAGE_PRECISION" + ], + "type": "u32" }, { - "name": "LoadInstructionAtFailed" + "name": "max_borrow_rate", + "docs": [ + "precision: PERCENTAGE_PRECISION" + ], + "type": "u32" } ] } - } - ], - "events": [ - { - "name": "NewUserRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "userAuthority", - "type": "publicKey", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "subAccountId", - "type": "u16", - "index": false - }, - { - "name": "name", - "type": { - "array": [ - "u8", - 32 - ] - }, - "index": false - }, - { - "name": "referrer", - "type": "publicKey", - "index": false - } - ] }, { - "name": "DepositRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "userAuthority", - "type": "publicKey", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "direction", - "type": { - "defined": "DepositDirection" + "name": "SpotMarket", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "pubkey", + "docs": [ + "The address of the spot market. It is a pda of the market index" + ], + "type": "pubkey" }, - "index": false - }, - { - "name": "depositRecordId", - "type": "u64", - "index": false - }, - { - "name": "amount", - "type": "u64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "oraclePrice", - "type": "i64", - "index": false - }, - { - "name": "marketDepositBalance", - "type": "u128", - "index": false - }, - { - "name": "marketWithdrawBalance", - "type": "u128", - "index": false - }, - { - "name": "marketCumulativeDepositInterest", - "type": "u128", - "index": false - }, - { - "name": "marketCumulativeBorrowInterest", - "type": "u128", - "index": false - }, - { - "name": "totalDepositsAfter", - "type": "u64", - "index": false - }, - { - "name": "totalWithdrawsAfter", - "type": "u64", - "index": false - }, - { - "name": "explanation", - "type": { - "defined": "DepositExplanation" + { + "name": "oracle", + "docs": [ + "The oracle used to price the markets deposits/borrows" + ], + "type": "pubkey" }, - "index": false - }, - { - "name": "transferUser", - "type": { - "option": "publicKey" + { + "name": "mint", + "docs": [ + "The token mint of the market" + ], + "type": "pubkey" }, - "index": false - }, - { - "name": "signer", - "type": { - "option": "publicKey" + { + "name": "vault", + "docs": [ + "The vault used to store the market's deposits", + "The amount in the vault should be equal to or greater than deposits - borrows" + ], + "type": "pubkey" }, - "index": false - }, - { - "name": "userTokenAmountAfter", - "type": "i128", - "index": false - } - ] - }, - { - "name": "SpotInterestRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "depositBalance", - "type": "u128", - "index": false - }, - { - "name": "cumulativeDepositInterest", - "type": "u128", - "index": false - }, - { - "name": "borrowBalance", - "type": "u128", - "index": false - }, - { - "name": "cumulativeBorrowInterest", - "type": "u128", - "index": false - }, - { - "name": "optimalUtilization", - "type": "u32", - "index": false - }, - { - "name": "optimalBorrowRate", - "type": "u32", - "index": false - }, - { - "name": "maxBorrowRate", - "type": "u32", - "index": false - } - ] - }, - { - "name": "FundingPaymentRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "userAuthority", - "type": "publicKey", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "fundingPayment", - "type": "i64", - "index": false - }, - { - "name": "baseAssetAmount", - "type": "i64", - "index": false - }, - { - "name": "userLastCumulativeFunding", - "type": "i64", - "index": false - }, - { - "name": "ammCumulativeFundingLong", - "type": "i128", - "index": false - }, - { - "name": "ammCumulativeFundingShort", - "type": "i128", - "index": false - } - ] - }, - { - "name": "FundingRateRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "recordId", - "type": "u64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "fundingRate", - "type": "i64", - "index": false - }, - { - "name": "fundingRateLong", - "type": "i128", - "index": false - }, - { - "name": "fundingRateShort", - "type": "i128", - "index": false - }, - { - "name": "cumulativeFundingRateLong", - "type": "i128", - "index": false - }, - { - "name": "cumulativeFundingRateShort", - "type": "i128", - "index": false - }, - { - "name": "oraclePriceTwap", - "type": "i64", - "index": false - }, - { - "name": "markPriceTwap", - "type": "u64", - "index": false - }, - { - "name": "periodRevenue", - "type": "i64", - "index": false - }, - { - "name": "baseAssetAmountWithAmm", - "type": "i128", - "index": false - }, - { - "name": "baseAssetAmountWithUnsettledLp", - "type": "i128", - "index": false - } - ] - }, - { - "name": "CurveRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "recordId", - "type": "u64", - "index": false - }, - { - "name": "pegMultiplierBefore", - "type": "u128", - "index": false - }, - { - "name": "baseAssetReserveBefore", - "type": "u128", - "index": false - }, - { - "name": "quoteAssetReserveBefore", - "type": "u128", - "index": false - }, - { - "name": "sqrtKBefore", - "type": "u128", - "index": false - }, - { - "name": "pegMultiplierAfter", - "type": "u128", - "index": false - }, - { - "name": "baseAssetReserveAfter", - "type": "u128", - "index": false - }, - { - "name": "quoteAssetReserveAfter", - "type": "u128", - "index": false - }, - { - "name": "sqrtKAfter", - "type": "u128", - "index": false - }, - { - "name": "baseAssetAmountLong", - "type": "u128", - "index": false - }, - { - "name": "baseAssetAmountShort", - "type": "u128", - "index": false - }, - { - "name": "baseAssetAmountWithAmm", - "type": "i128", - "index": false - }, - { - "name": "totalFee", - "type": "i128", - "index": false - }, - { - "name": "totalFeeMinusDistributions", - "type": "i128", - "index": false - }, - { - "name": "adjustmentCost", - "type": "i128", - "index": false - }, - { - "name": "oraclePrice", - "type": "i64", - "index": false - }, - { - "name": "fillRecord", - "type": "u128", - "index": false - }, - { - "name": "numberOfUsers", - "type": "u32", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - } - ] - }, - { - "name": "SignedMsgOrderRecord", - "fields": [ - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "hash", - "type": "string", - "index": false - }, - { - "name": "matchingOrderParams", - "type": { - "defined": "OrderParams" + { + "name": "name", + "docs": [ + "The encoded display name for the market e.g. SOL" + ], + "type": { + "array": [ + "u8", + 32 + ] + } }, - "index": false - }, - { - "name": "userOrderId", - "type": "u32", - "index": false - }, - { - "name": "signedMsgOrderMaxSlot", - "type": "u64", - "index": false - }, - { - "name": "signedMsgOrderUuid", - "type": { - "array": [ - "u8", - 8 - ] + { + "name": "historical_oracle_data", + "type": { + "defined": { + "name": "HistoricalOracleData" + } + } }, - "index": false - }, - { - "name": "ts", - "type": "i64", - "index": false - } - ] - }, - { - "name": "OrderRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "order", - "type": { - "defined": "Order" + { + "name": "historical_index_data", + "type": { + "defined": { + "name": "HistoricalIndexData" + } + } }, - "index": false - } - ] - }, - { - "name": "OrderActionRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "action", - "type": { - "defined": "OrderAction" + { + "name": "revenue_pool", + "docs": [ + "Revenue the protocol has collected in this markets token", + "e.g. for SOL-PERP, funds can be settled in usdc and will flow into the USDC revenue pool" + ], + "type": { + "defined": { + "name": "PoolBalance" + } + } }, - "index": false - }, - { - "name": "actionExplanation", - "type": { - "defined": "OrderActionExplanation" + { + "name": "spot_fee_pool", + "docs": [ + "The fees collected from swaps between this market and the quote market", + "Is settled to the quote markets revenue pool" + ], + "type": { + "defined": { + "name": "PoolBalance" + } + } }, - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "marketType", - "type": { - "defined": "MarketType" + { + "name": "insurance_fund", + "docs": [ + "Details on the insurance fund covering bankruptcies in this markets token", + "Covers bankruptcies for borrows with this markets token and perps settling in this markets token" + ], + "type": { + "defined": { + "name": "InsuranceFund" + } + } }, - "index": false - }, - { - "name": "filler", - "type": { - "option": "publicKey" + { + "name": "total_spot_fee", + "docs": [ + "The total spot fees collected for this market", + "precision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "fillerReward", - "type": { - "option": "u64" + { + "name": "deposit_balance", + "docs": [ + "The sum of the scaled balances for deposits across users and pool balances", + "To convert to the deposit token amount, multiply by the cumulative deposit interest", + "precision: SPOT_BALANCE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "fillRecordId", - "type": { - "option": "u64" + { + "name": "borrow_balance", + "docs": [ + "The sum of the scaled balances for borrows across users and pool balances", + "To convert to the borrow token amount, multiply by the cumulative borrow interest", + "precision: SPOT_BALANCE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "baseAssetAmountFilled", - "type": { - "option": "u64" + { + "name": "cumulative_deposit_interest", + "docs": [ + "The cumulative interest earned by depositors", + "Used to calculate the deposit token amount from the deposit balance", + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "quoteAssetAmountFilled", - "type": { - "option": "u64" - }, - "index": false - }, - { - "name": "takerFee", - "type": { - "option": "u64" + { + "name": "cumulative_borrow_interest", + "docs": [ + "The cumulative interest earned by borrowers", + "Used to calculate the borrow token amount from the borrow balance", + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "makerFee", - "type": { - "option": "i64" + { + "name": "total_social_loss", + "docs": [ + "The total socialized loss from borrows, in the mint's token", + "precision: token mint precision" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "referrerReward", - "type": { - "option": "u32" + { + "name": "total_quote_social_loss", + "docs": [ + "The total socialized loss from borrows, in the quote market's token", + "preicision: QUOTE_PRECISION" + ], + "type": { + "defined": { + "name": "u128" + } + } }, - "index": false - }, - { - "name": "quoteAssetAmountSurplus", - "type": { - "option": "i64" + { + "name": "withdraw_guard_threshold", + "docs": [ + "no withdraw limits/guards when deposits below this threshold", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "spotFulfillmentMethodFee", - "type": { - "option": "u64" + { + "name": "max_token_deposits", + "docs": [ + "The max amount of token deposits in this market", + "0 if there is no limit", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "taker", - "type": { - "option": "publicKey" + { + "name": "deposit_token_twap", + "docs": [ + "24hr average of deposit token amount", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "takerOrderId", - "type": { - "option": "u32" + { + "name": "borrow_token_twap", + "docs": [ + "24hr average of borrow token amount", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "takerOrderDirection", - "type": { - "option": { - "defined": "PositionDirection" - } + { + "name": "utilization_twap", + "docs": [ + "24hr average of utilization", + "which is borrow amount over token amount", + "precision: SPOT_UTILIZATION_PRECISION" + ], + "type": "u64" }, - "index": false - }, - { - "name": "takerOrderBaseAssetAmount", - "type": { - "option": "u64" + { + "name": "last_interest_ts", + "docs": [ + "Last time the cumulative deposit and borrow interest was updated" + ], + "type": "u64" }, - "index": false - }, - { - "name": "takerOrderCumulativeBaseAssetAmountFilled", - "type": { - "option": "u64" + { + "name": "last_twap_ts", + "docs": [ + "Last time the deposit/borrow/utilization averages were updated" + ], + "type": "u64" }, - "index": false - }, - { - "name": "takerOrderCumulativeQuoteAssetAmountFilled", - "type": { - "option": "u64" + { + "name": "expiry_ts", + "docs": [ + "The time the market is set to expire. Only set if market is in reduce only mode" + ], + "type": "i64" }, - "index": false - }, - { - "name": "maker", - "type": { - "option": "publicKey" + { + "name": "order_step_size", + "docs": [ + "Spot orders must be a multiple of the step size", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "makerOrderId", - "type": { - "option": "u32" + { + "name": "order_tick_size", + "docs": [ + "Spot orders must be a multiple of the tick size", + "precision: PRICE_PRECISION" + ], + "type": "u64" }, - "index": false - }, - { - "name": "makerOrderDirection", - "type": { - "option": { - "defined": "PositionDirection" - } + { + "name": "min_order_size", + "docs": [ + "The minimum order size", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "makerOrderBaseAssetAmount", - "type": { - "option": "u64" + { + "name": "max_position_size", + "docs": [ + "The maximum spot position size", + "if the limit is 0, there is no limit", + "precision: token mint precision" + ], + "type": "u64" }, - "index": false - }, - { - "name": "makerOrderCumulativeBaseAssetAmountFilled", - "type": { - "option": "u64" + { + "name": "next_fill_record_id", + "docs": [ + "Every spot trade has a fill record id. This is the next id to use" + ], + "type": "u64" }, - "index": false - }, - { - "name": "makerOrderCumulativeQuoteAssetAmountFilled", - "type": { - "option": "u64" + { + "name": "next_deposit_record_id", + "docs": [ + "Every deposit has a deposit record id. This is the next id to use" + ], + "type": "u64" }, - "index": false - }, - { - "name": "oraclePrice", - "type": "i64", - "index": false - }, - { - "name": "bitFlags", - "type": "u8", - "index": false - }, - { - "name": "takerExistingQuoteEntryAmount", - "type": { - "option": "u64" + { + "name": "initial_asset_weight", + "docs": [ + "The initial asset weight used to calculate a deposits contribution to a users initial total collateral", + "e.g. if the asset weight is .8, $100 of deposits contributes $80 to the users initial total collateral", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "takerExistingBaseAssetAmount", - "type": { - "option": "u64" + { + "name": "maintenance_asset_weight", + "docs": [ + "The maintenance asset weight used to calculate a deposits contribution to a users maintenance total collateral", + "e.g. if the asset weight is .9, $100 of deposits contributes $90 to the users maintenance total collateral", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "makerExistingQuoteEntryAmount", - "type": { - "option": "u64" + { + "name": "initial_liability_weight", + "docs": [ + "The initial liability weight used to calculate a borrows contribution to a users initial margin requirement", + "e.g. if the liability weight is .9, $100 of borrows contributes $90 to the users initial margin requirement", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "makerExistingBaseAssetAmount", - "type": { - "option": "u64" + { + "name": "maintenance_liability_weight", + "docs": [ + "The maintenance liability weight used to calculate a borrows contribution to a users maintenance margin requirement", + "e.g. if the liability weight is .8, $100 of borrows contributes $80 to the users maintenance margin requirement", + "precision: SPOT_WEIGHT_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "triggerPrice", - "type": { - "option": "u64" + { + "name": "imf_factor", + "docs": [ + "The initial margin fraction factor. Used to increase liability weight/decrease asset weight for large positions", + "precision: MARGIN_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "builderIdx", - "type": { - "option": "u8" + { + "name": "liquidator_fee", + "docs": [ + "The fee the liquidator is paid for taking over borrow/deposit", + "precision: LIQUIDATOR_FEE_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "builderFee", - "type": { - "option": "u64" + { + "name": "if_liquidation_fee", + "docs": [ + "The fee the insurance fund receives from liquidation", + "precision: LIQUIDATOR_FEE_PRECISION" + ], + "type": "u32" }, - "index": false - } - ] - }, - { - "name": "LPRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "action", - "type": { - "defined": "LPAction" + { + "name": "optimal_utilization", + "docs": [ + "The optimal utilization rate for this market.", + "Used to determine the markets borrow rate", + "precision: SPOT_UTILIZATION_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "nShares", - "type": "u64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "deltaBaseAssetAmount", - "type": "i64", - "index": false - }, - { - "name": "deltaQuoteAssetAmount", - "type": "i64", - "index": false - }, - { - "name": "pnl", - "type": "i64", - "index": false - } - ] - }, - { - "name": "LiquidationRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "liquidationType", - "type": { - "defined": "LiquidationType" + { + "name": "optimal_borrow_rate", + "docs": [ + "The borrow rate for this market when the market has optimal utilization", + "precision: SPOT_RATE_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "liquidator", - "type": "publicKey", - "index": false - }, - { - "name": "marginRequirement", - "type": "u128", - "index": false - }, - { - "name": "totalCollateral", - "type": "i128", - "index": false - }, - { - "name": "marginFreed", - "type": "u64", - "index": false - }, - { - "name": "liquidationId", - "type": "u16", - "index": false - }, - { - "name": "bankrupt", - "type": "bool", - "index": false - }, - { - "name": "canceledOrderIds", - "type": { - "vec": "u32" + { + "name": "max_borrow_rate", + "docs": [ + "The borrow rate for this market when the market has 1000 utilization", + "precision: SPOT_RATE_PRECISION" + ], + "type": "u32" }, - "index": false - }, - { - "name": "liquidatePerp", - "type": { - "defined": "LiquidatePerpRecord" + { + "name": "decimals", + "docs": [ + "The market's token mint's decimals. To from decimals to a precision, 10^decimals" + ], + "type": "u32" }, - "index": false - }, - { - "name": "liquidateSpot", - "type": { - "defined": "LiquidateSpotRecord" + { + "name": "market_index", + "type": "u16" }, - "index": false - }, - { - "name": "liquidateBorrowForPerpPnl", - "type": { - "defined": "LiquidateBorrowForPerpPnlRecord" + { + "name": "orders_enabled", + "docs": [ + "Whether or not spot trading is enabled" + ], + "type": "bool" }, - "index": false - }, - { - "name": "liquidatePerpPnlForDeposit", - "type": { - "defined": "LiquidatePerpPnlForDepositRecord" + { + "name": "oracle_source", + "type": { + "defined": { + "name": "OracleSource" + } + } }, - "index": false - }, - { - "name": "perpBankruptcy", - "type": { - "defined": "PerpBankruptcyRecord" + { + "name": "status", + "type": { + "defined": { + "name": "MarketStatus" + } + } }, - "index": false - }, - { - "name": "spotBankruptcy", - "type": { - "defined": "SpotBankruptcyRecord" + { + "name": "asset_tier", + "docs": [ + "The asset tier affects how a deposit can be used as collateral and the priority for a borrow being liquidated" + ], + "type": { + "defined": { + "name": "AssetTier" + } + } }, - "index": false - } - ] - }, - { - "name": "SettlePnlRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "pnl", - "type": "i128", - "index": false - }, - { - "name": "baseAssetAmount", - "type": "i64", - "index": false - }, - { - "name": "quoteAssetAmountAfter", - "type": "i64", - "index": false - }, - { - "name": "quoteEntryAmount", - "type": "i64", - "index": false - }, - { - "name": "settlePrice", - "type": "i64", - "index": false - }, - { - "name": "explanation", - "type": { - "defined": "SettlePnlExplanation" + { + "name": "paused_operations", + "type": "u8" }, - "index": false - } - ] + { + "name": "if_paused_operations", + "type": "u8" + }, + { + "name": "fee_adjustment", + "type": "i16" + }, + { + "name": "max_token_borrows_fraction", + "docs": [ + "What fraction of max_token_deposits", + "disabled when 0, 1 => 1/10000 => .01% of max_token_deposits", + "precision: X/10000" + ], + "type": "u16" + }, + { + "name": "flash_loan_amount", + "docs": [ + "For swaps, the amount of token loaned out in the begin_swap ix", + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "flash_loan_initial_token_amount", + "docs": [ + "For swaps, the amount in the users token account in the begin_swap ix", + "Used to calculate how much of the token left the system in end_swap ix", + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "total_swap_fee", + "docs": [ + "The total fees received from swaps", + "precision: token mint precision" + ], + "type": "u64" + }, + { + "name": "scale_initial_asset_weight_start", + "docs": [ + "When to begin scaling down the initial asset weight", + "disabled when 0", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "min_borrow_rate", + "docs": [ + "The min borrow rate for this market when the market regardless of utilization", + "1 => 1/200 => .5%", + "precision: X/200" + ], + "type": "u8" + }, + { + "name": "fuel_boost_deposits", + "docs": [ + "fuel multiplier for spot deposits", + "precision: 10" + ], + "type": "u8" + }, + { + "name": "fuel_boost_borrows", + "docs": [ + "fuel multiplier for spot borrows", + "precision: 10" + ], + "type": "u8" + }, + { + "name": "fuel_boost_taker", + "docs": [ + "fuel multiplier for spot taker", + "precision: 10" + ], + "type": "u8" + }, + { + "name": "fuel_boost_maker", + "docs": [ + "fuel multiplier for spot maker", + "precision: 10" + ], + "type": "u8" + }, + { + "name": "fuel_boost_insurance", + "docs": [ + "fuel multiplier for spot insurance stake", + "precision: 10" + ], + "type": "u8" + }, + { + "name": "token_program_flag", + "type": "u8" + }, + { + "name": "pool_id", + "type": "u8" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 40 + ] + } + } + ] + } }, { - "name": "InsuranceFundRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "spotMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "perpMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "userIfFactor", - "type": "u32", - "index": false - }, - { - "name": "totalIfFactor", - "type": "u32", - "index": false - }, - { - "name": "vaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "insuranceVaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "totalIfSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "totalIfSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "amount", - "type": "i64", - "index": false - } - ] - }, - { - "name": "InsuranceFundStakeRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "userAuthority", - "type": "publicKey", - "index": false - }, - { - "name": "action", - "type": { - "defined": "StakeAction" + "name": "SpotMarketVaultDepositRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" }, - "index": false - }, - { - "name": "amount", - "type": "u64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "insuranceVaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "ifSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "userIfSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "totalIfSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "ifSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "userIfSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "totalIfSharesAfter", - "type": "u128", - "index": false - } - ] - }, - { - "name": "InsuranceFundSwapRecord", - "fields": [ - { - "name": "rebalanceConfig", - "type": "publicKey", - "index": false - }, - { - "name": "inIfTotalSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "outIfTotalSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "inIfUserSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "outIfUserSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "inIfTotalSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "outIfTotalSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "inIfUserSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "outIfUserSharesAfter", - "type": "u128", - "index": false - }, - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "inAmount", - "type": "u64", - "index": false - }, - { - "name": "outAmount", - "type": "u64", - "index": false - }, - { - "name": "outOraclePrice", - "type": "u64", - "index": false - }, - { - "name": "outOraclePriceTwap", - "type": "i64", - "index": false - }, - { - "name": "inVaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "outVaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "inFundVaultAmountAfter", - "type": "u64", - "index": false - }, - { - "name": "outFundVaultAmountAfter", - "type": "u64", - "index": false - }, - { - "name": "inMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "outMarketIndex", - "type": "u16", - "index": false - } - ] + { + "name": "market_index", + "type": "u16" + }, + { + "name": "deposit_balance", + "docs": [ + "precision: SPOT_BALANCE_PRECISION" + ], + "type": "u128" + }, + { + "name": "cumulative_deposit_interest_before", + "docs": [ + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": "u128" + }, + { + "name": "cumulative_deposit_interest_after", + "docs": [ + "precision: SPOT_CUMULATIVE_INTEREST_PRECISION" + ], + "type": "u128" + }, + { + "name": "deposit_token_amount_before", + "type": "u64" + }, + { + "name": "amount", + "type": "u64" + } + ] + } }, { - "name": "TransferProtocolIfSharesToRevenuePoolRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "amount", - "type": "u64", - "index": false - }, - { - "name": "shares", - "type": "u128", - "index": false - }, - { - "name": "ifVaultAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "protocolSharesBefore", - "type": "u128", - "index": false - }, - { - "name": "transferAmount", - "type": "u64", - "index": false - } - ] + "name": "SpotPosition", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "scaled_balance", + "docs": [ + "The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow", + "interest of corresponding market.", + "precision: SPOT_BALANCE_PRECISION" + ], + "type": "u64" + }, + { + "name": "open_bids", + "docs": [ + "How many spot non reduce only trigger orders the user has open", + "precision: token mint precision" + ], + "type": "i64" + }, + { + "name": "open_asks", + "docs": [ + "How many spot non reduce only trigger orders the user has open", + "precision: token mint precision" + ], + "type": "i64" + }, + { + "name": "cumulative_deposits", + "docs": [ + "The cumulative deposits/borrows a user has made into a market", + "precision: token mint precision" + ], + "type": "i64" + }, + { + "name": "market_index", + "docs": [ + "The market index of the corresponding spot market" + ], + "type": "u16" + }, + { + "name": "balance_type", + "docs": [ + "Whether the position is deposit or borrow" + ], + "type": { + "defined": { + "name": "SpotBalanceType" + } + } + }, + { + "name": "open_orders", + "docs": [ + "Number of open orders" + ], + "type": "u8" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + } + ] + } }, { - "name": "SwapRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "amountOut", - "type": "u64", - "index": false - }, - { - "name": "amountIn", - "type": "u64", - "index": false - }, - { - "name": "outMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "inMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "outOraclePrice", - "type": "i64", - "index": false - }, - { - "name": "inOraclePrice", - "type": "i64", - "index": false - }, - { - "name": "fee", - "type": "u64", - "index": false - } - ] + "name": "StakeAction", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Stake" + }, + { + "name": "UnstakeRequest" + }, + { + "name": "UnstakeCancelRequest" + }, + { + "name": "Unstake" + }, + { + "name": "UnstakeTransfer" + }, + { + "name": "StakeTransfer" + }, + { + "name": "AdminDeposit" + } + ] + } }, { - "name": "SpotMarketVaultDepositRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "depositBalance", - "type": "u128", - "index": false - }, - { - "name": "cumulativeDepositInterestBefore", - "type": "u128", - "index": false - }, - { - "name": "cumulativeDepositInterestAfter", - "type": "u128", - "index": false - }, - { - "name": "depositTokenAmountBefore", - "type": "u64", - "index": false - }, - { - "name": "amount", - "type": "u64", - "index": false - } - ] - }, - { - "name": "DeleteUserRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "userAuthority", - "type": "publicKey", - "index": false - }, - { - "name": "user", - "type": "publicKey", - "index": false - }, - { - "name": "subAccountId", - "type": "u16", - "index": false - }, - { - "name": "keeper", - "type": { - "option": "publicKey" + "name": "State", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "admin", + "type": "pubkey" }, - "index": false - } - ] + { + "name": "whitelist_mint", + "type": "pubkey" + }, + { + "name": "discount_mint", + "type": "pubkey" + }, + { + "name": "signer", + "type": "pubkey" + }, + { + "name": "srm_vault", + "type": "pubkey" + }, + { + "name": "perp_fee_structure", + "type": { + "defined": { + "name": "FeeStructure" + } + } + }, + { + "name": "spot_fee_structure", + "type": { + "defined": { + "name": "FeeStructure" + } + } + }, + { + "name": "oracle_guard_rails", + "type": { + "defined": { + "name": "OracleGuardRails" + } + } + }, + { + "name": "number_of_authorities", + "type": "u64" + }, + { + "name": "number_of_sub_accounts", + "type": "u64" + }, + { + "name": "lp_cooldown_time", + "type": "u64" + }, + { + "name": "liquidation_margin_buffer_ratio", + "type": "u32" + }, + { + "name": "settlement_duration", + "type": "u16" + }, + { + "name": "number_of_markets", + "type": "u16" + }, + { + "name": "number_of_spot_markets", + "type": "u16" + }, + { + "name": "signer_nonce", + "type": "u8" + }, + { + "name": "min_perp_auction_duration", + "type": "u8" + }, + { + "name": "default_market_order_time_in_force", + "type": "u8" + }, + { + "name": "default_spot_auction_duration", + "type": "u8" + }, + { + "name": "exchange_status", + "type": "u8" + }, + { + "name": "liquidation_duration", + "type": "u8" + }, + { + "name": "initial_pct_to_liquidate", + "type": "u16" + }, + { + "name": "max_number_of_sub_accounts", + "type": "u16" + }, + { + "name": "max_initialize_user_fee", + "type": "u16" + }, + { + "name": "feature_bit_flags", + "type": "u8" + }, + { + "name": "lp_pool_feature_bit_flags", + "type": "u8" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 8 + ] + } + } + ] + } }, { - "name": "FuelSweepRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "authority", - "type": "publicKey", - "index": false - }, - { - "name": "userStatsFuelInsurance", - "type": "u32", - "index": false - }, - { - "name": "userStatsFuelDeposits", - "type": "u32", - "index": false - }, - { - "name": "userStatsFuelBorrows", - "type": "u32", - "index": false - }, - { - "name": "userStatsFuelPositions", - "type": "u32", - "index": false - }, - { - "name": "userStatsFuelTaker", - "type": "u32", - "index": false - }, - { - "name": "userStatsFuelMaker", - "type": "u32", - "index": false - }, - { - "name": "fuelOverflowFuelInsurance", - "type": "u128", - "index": false - }, - { - "name": "fuelOverflowFuelDeposits", - "type": "u128", - "index": false - }, - { - "name": "fuelOverflowFuelBorrows", - "type": "u128", - "index": false - }, - { - "name": "fuelOverflowFuelPositions", - "type": "u128", - "index": false - }, - { - "name": "fuelOverflowFuelTaker", - "type": "u128", - "index": false - }, - { - "name": "fuelOverflowFuelMaker", - "type": "u128", - "index": false - } - ] + "name": "SwapRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" + }, + { + "name": "user", + "type": "pubkey" + }, + { + "name": "amount_out", + "docs": [ + "precision: out market mint precision" + ], + "type": "u64" + }, + { + "name": "amount_in", + "docs": [ + "precision: in market mint precision" + ], + "type": "u64" + }, + { + "name": "out_market_index", + "type": "u16" + }, + { + "name": "in_market_index", + "type": "u16" + }, + { + "name": "out_oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" + }, + { + "name": "in_oracle_price", + "docs": [ + "precision: PRICE_PRECISION" + ], + "type": "i64" + }, + { + "name": "fee", + "type": "u64" + } + ] + } }, { - "name": "FuelSeasonRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "authority", - "type": "publicKey", - "index": false - }, - { - "name": "fuelInsurance", - "type": "u128", - "index": false - }, - { - "name": "fuelDeposits", - "type": "u128", - "index": false - }, - { - "name": "fuelBorrows", - "type": "u128", - "index": false - }, - { - "name": "fuelPositions", - "type": "u128", - "index": false - }, - { - "name": "fuelTaker", - "type": "u128", - "index": false - }, - { - "name": "fuelMaker", - "type": "u128", - "index": false - }, - { - "name": "fuelTotal", - "type": "u128", - "index": false - } - ] + "name": "SwapReduceOnly", + "type": { + "kind": "enum", + "variants": [ + { + "name": "In" + }, + { + "name": "Out" + } + ] + } }, { - "name": "RevenueShareSettleRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "builder", - "type": { - "option": "publicKey" + "name": "TargetsDatum", + "serialization": "bytemuck", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "cost_to_trade_bps", + "type": "i32" }, - "index": false - }, - { - "name": "referrer", - "type": { - "option": "publicKey" + { + "name": "_padding", + "type": { + "array": [ + "u8", + 4 + ] + } }, - "index": false - }, - { - "name": "feeSettled", - "type": "u64", - "index": false - }, - { - "name": "marketIndex", - "type": "u16", - "index": false - }, - { - "name": "marketType", - "type": { - "defined": "MarketType" + { + "name": "target_base", + "type": "i64" }, - "index": false - }, - { - "name": "builderSubAccountId", - "type": "u16", - "index": false - }, - { - "name": "builderTotalReferrerRewards", - "type": "u64", - "index": false - }, - { - "name": "builderTotalBuilderRewards", - "type": "u64", - "index": false - } - ] - }, - { - "name": "LPSettleRecord", - "fields": [ - { - "name": "recordId", - "type": "u64", - "index": false - }, - { - "name": "lastTs", - "type": "i64", - "index": false - }, - { - "name": "lastSlot", - "type": "u64", - "index": false - }, - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "slot", - "type": "u64", - "index": false - }, - { - "name": "perpMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "settleToLpAmount", - "type": "i64", - "index": false - }, - { - "name": "perpAmmPnlDelta", - "type": "i64", - "index": false - }, - { - "name": "perpAmmExFeeDelta", - "type": "i64", - "index": false - }, - { - "name": "lpAum", - "type": "u128", - "index": false - }, - { - "name": "lpPrice", - "type": "u128", - "index": false - }, - { - "name": "lpPool", - "type": "publicKey", - "index": false - } - ] - }, - { - "name": "LPSwapRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "slot", - "type": "u64", - "index": false - }, - { - "name": "authority", - "type": "publicKey", - "index": false - }, - { - "name": "outAmount", - "type": "u128", - "index": false - }, - { - "name": "inAmount", - "type": "u128", - "index": false - }, - { - "name": "outFee", - "type": "i128", - "index": false - }, - { - "name": "inFee", - "type": "i128", - "index": false - }, - { - "name": "outSpotMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "inSpotMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "outConstituentIndex", - "type": "u16", - "index": false - }, - { - "name": "inConstituentIndex", - "type": "u16", - "index": false - }, - { - "name": "outOraclePrice", - "type": "i64", - "index": false - }, - { - "name": "inOraclePrice", - "type": "i64", - "index": false - }, - { - "name": "lastAum", - "type": "u128", - "index": false - }, - { - "name": "lastAumSlot", - "type": "u64", - "index": false - }, - { - "name": "inMarketCurrentWeight", - "type": "i64", - "index": false - }, - { - "name": "outMarketCurrentWeight", - "type": "i64", - "index": false - }, - { - "name": "inMarketTargetWeight", - "type": "i64", - "index": false - }, - { - "name": "outMarketTargetWeight", - "type": "i64", - "index": false - }, - { - "name": "inSwapId", - "type": "u64", - "index": false - }, - { - "name": "outSwapId", - "type": "u64", - "index": false - }, - { - "name": "lpPool", - "type": "publicKey", - "index": false - } - ] - }, - { - "name": "LPMintRedeemRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "slot", - "type": "u64", - "index": false - }, - { - "name": "authority", - "type": "publicKey", - "index": false - }, - { - "name": "description", - "type": "u8", - "index": false - }, - { - "name": "amount", - "type": "u128", - "index": false - }, - { - "name": "fee", - "type": "i128", - "index": false - }, - { - "name": "spotMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "constituentIndex", - "type": "u16", - "index": false - }, - { - "name": "oraclePrice", - "type": "i64", - "index": false - }, - { - "name": "mint", - "type": "publicKey", - "index": false - }, - { - "name": "lpAmount", - "type": "u64", - "index": false - }, - { - "name": "lpFee", - "type": "i64", - "index": false - }, - { - "name": "lpPrice", - "type": "u128", - "index": false - }, - { - "name": "mintRedeemId", - "type": "u64", - "index": false - }, - { - "name": "lastAum", - "type": "u128", - "index": false - }, - { - "name": "lastAumSlot", - "type": "u64", - "index": false - }, - { - "name": "inMarketCurrentWeight", - "type": "i64", - "index": false - }, - { - "name": "inMarketTargetWeight", - "type": "i64", - "index": false - }, - { - "name": "lpPool", - "type": "publicKey", - "index": false - } - ] - }, - { - "name": "LPBorrowLendDepositRecord", - "fields": [ - { - "name": "ts", - "type": "i64", - "index": false - }, - { - "name": "slot", - "type": "u64", - "index": false - }, - { - "name": "spotMarketIndex", - "type": "u16", - "index": false - }, - { - "name": "constituentIndex", - "type": "u16", - "index": false - }, - { - "name": "direction", - "type": { - "defined": "DepositDirection" + { + "name": "last_oracle_slot", + "type": "u64" }, - "index": false - }, - { - "name": "tokenBalance", - "type": "i64", - "index": false - }, - { - "name": "lastTokenBalance", - "type": "i64", - "index": false - }, - { - "name": "interestAccruedTokenAmount", - "type": "i64", - "index": false - }, - { - "name": "amountDepositWithdraw", - "type": "u64", - "index": false - }, - { - "name": "lpPool", - "type": "publicKey", - "index": false - } - ] - } - ], - "errors": [ - { - "code": 6000, - "name": "InvalidSpotMarketAuthority", - "msg": "Invalid Spot Market Authority" - }, - { - "code": 6001, - "name": "InvalidInsuranceFundAuthority", - "msg": "Clearing house not insurance fund authority" - }, - { - "code": 6002, - "name": "InsufficientDeposit", - "msg": "Insufficient deposit" - }, - { - "code": 6003, - "name": "InsufficientCollateral", - "msg": "Insufficient collateral" - }, - { - "code": 6004, - "name": "SufficientCollateral", - "msg": "Sufficient collateral" - }, - { - "code": 6005, - "name": "MaxNumberOfPositions", - "msg": "Max number of positions taken" - }, - { - "code": 6006, - "name": "AdminControlsPricesDisabled", - "msg": "Admin Controls Prices Disabled" - }, - { - "code": 6007, - "name": "MarketDelisted", - "msg": "Market Delisted" - }, - { - "code": 6008, - "name": "MarketIndexAlreadyInitialized", - "msg": "Market Index Already Initialized" + { + "name": "last_position_slot", + "type": "u64" + } + ] + } }, { - "code": 6009, - "name": "UserAccountAndUserPositionsAccountMismatch", - "msg": "User Account And User Positions Account Mismatch" + "name": "TransferProtocolIfSharesToRevenuePoolRecord", + "type": { + "kind": "struct", + "fields": [ + { + "name": "ts", + "type": "i64" + }, + { + "name": "market_index", + "type": "u16" + }, + { + "name": "amount", + "type": "u64" + }, + { + "name": "shares", + "type": "u128" + }, + { + "name": "if_vault_amount_before", + "type": "u64" + }, + { + "name": "protocol_shares_before", + "type": "u128" + }, + { + "name": "transfer_amount", + "type": "u64" + } + ] + } }, { - "code": 6010, - "name": "UserHasNoPositionInMarket", - "msg": "User Has No Position In Market" + "name": "UpdatePerpMarketSummaryStatsParams", + "type": { + "kind": "struct", + "fields": [ + { + "name": "quote_asset_amount_with_unsettled_lp", + "type": { + "option": "i64" + } + }, + { + "name": "net_unsettled_funding_pnl", + "type": { + "option": "i64" + } + }, + { + "name": "update_amm_summary_stats", + "type": { + "option": "bool" + } + }, + { + "name": "exclude_total_liq_fee", + "type": { + "option": "bool" + } + } + ] + } }, { - "code": 6011, - "name": "InvalidInitialPeg", - "msg": "Invalid Initial Peg" - }, - { - "code": 6012, - "name": "InvalidRepegRedundant", - "msg": "AMM repeg already configured with amt given" - }, - { - "code": 6013, - "name": "InvalidRepegDirection", - "msg": "AMM repeg incorrect repeg direction" - }, - { - "code": 6014, - "name": "InvalidRepegProfitability", - "msg": "AMM repeg out of bounds pnl" - }, - { - "code": 6015, - "name": "SlippageOutsideLimit", - "msg": "Slippage Outside Limit Price" - }, - { - "code": 6016, - "name": "OrderSizeTooSmall", - "msg": "Order Size Too Small" - }, - { - "code": 6017, - "name": "InvalidUpdateK", - "msg": "Price change too large when updating K" - }, - { - "code": 6018, - "name": "AdminWithdrawTooLarge", - "msg": "Admin tried to withdraw amount larger than fees collected" - }, - { - "code": 6019, - "name": "MathError", - "msg": "Math Error" - }, - { - "code": 6020, - "name": "BnConversionError", - "msg": "Conversion to u128/u64 failed with an overflow or underflow" - }, - { - "code": 6021, - "name": "ClockUnavailable", - "msg": "Clock unavailable" - }, - { - "code": 6022, - "name": "UnableToLoadOracle", - "msg": "Unable To Load Oracles" - }, - { - "code": 6023, - "name": "PriceBandsBreached", - "msg": "Price Bands Breached" - }, - { - "code": 6024, - "name": "ExchangePaused", - "msg": "Exchange is paused" - }, - { - "code": 6025, - "name": "InvalidWhitelistToken", - "msg": "Invalid whitelist token" - }, - { - "code": 6026, - "name": "WhitelistTokenNotFound", - "msg": "Whitelist token not found" - }, - { - "code": 6027, - "name": "InvalidDiscountToken", - "msg": "Invalid discount token" - }, - { - "code": 6028, - "name": "DiscountTokenNotFound", - "msg": "Discount token not found" - }, - { - "code": 6029, - "name": "ReferrerNotFound", - "msg": "Referrer not found" - }, - { - "code": 6030, - "name": "ReferrerStatsNotFound", - "msg": "ReferrerNotFound" - }, - { - "code": 6031, - "name": "ReferrerMustBeWritable", - "msg": "ReferrerMustBeWritable" - }, - { - "code": 6032, - "name": "ReferrerStatsMustBeWritable", - "msg": "ReferrerMustBeWritable" - }, - { - "code": 6033, - "name": "ReferrerAndReferrerStatsAuthorityUnequal", - "msg": "ReferrerAndReferrerStatsAuthorityUnequal" - }, - { - "code": 6034, - "name": "InvalidReferrer", - "msg": "InvalidReferrer" - }, - { - "code": 6035, - "name": "InvalidOracle", - "msg": "InvalidOracle" - }, - { - "code": 6036, - "name": "OracleNotFound", - "msg": "OracleNotFound" - }, - { - "code": 6037, - "name": "LiquidationsBlockedByOracle", - "msg": "Liquidations Blocked By Oracle" - }, - { - "code": 6038, - "name": "MaxDeposit", - "msg": "Can not deposit more than max deposit" - }, - { - "code": 6039, - "name": "CantDeleteUserWithCollateral", - "msg": "Can not delete user that still has collateral" - }, - { - "code": 6040, - "name": "InvalidFundingProfitability", - "msg": "AMM funding out of bounds pnl" - }, - { - "code": 6041, - "name": "CastingFailure", - "msg": "Casting Failure" - }, - { - "code": 6042, - "name": "InvalidOrder", - "msg": "InvalidOrder" - }, - { - "code": 6043, - "name": "InvalidOrderMaxTs", - "msg": "InvalidOrderMaxTs" - }, - { - "code": 6044, - "name": "InvalidOrderMarketType", - "msg": "InvalidOrderMarketType" - }, - { - "code": 6045, - "name": "InvalidOrderForInitialMarginReq", - "msg": "InvalidOrderForInitialMarginReq" - }, - { - "code": 6046, - "name": "InvalidOrderNotRiskReducing", - "msg": "InvalidOrderNotRiskReducing" - }, - { - "code": 6047, - "name": "InvalidOrderSizeTooSmall", - "msg": "InvalidOrderSizeTooSmall" - }, - { - "code": 6048, - "name": "InvalidOrderNotStepSizeMultiple", - "msg": "InvalidOrderNotStepSizeMultiple" - }, - { - "code": 6049, - "name": "InvalidOrderBaseQuoteAsset", - "msg": "InvalidOrderBaseQuoteAsset" - }, - { - "code": 6050, - "name": "InvalidOrderIOC", - "msg": "InvalidOrderIOC" - }, - { - "code": 6051, - "name": "InvalidOrderPostOnly", - "msg": "InvalidOrderPostOnly" - }, - { - "code": 6052, - "name": "InvalidOrderIOCPostOnly", - "msg": "InvalidOrderIOCPostOnly" - }, - { - "code": 6053, - "name": "InvalidOrderTrigger", - "msg": "InvalidOrderTrigger" - }, - { - "code": 6054, - "name": "InvalidOrderAuction", - "msg": "InvalidOrderAuction" - }, - { - "code": 6055, - "name": "InvalidOrderOracleOffset", - "msg": "InvalidOrderOracleOffset" - }, - { - "code": 6056, - "name": "InvalidOrderMinOrderSize", - "msg": "InvalidOrderMinOrderSize" - }, - { - "code": 6057, - "name": "PlacePostOnlyLimitFailure", - "msg": "Failed to Place Post-Only Limit Order" - }, - { - "code": 6058, - "name": "UserHasNoOrder", - "msg": "User has no order" - }, - { - "code": 6059, - "name": "OrderAmountTooSmall", - "msg": "Order Amount Too Small" - }, - { - "code": 6060, - "name": "MaxNumberOfOrders", - "msg": "Max number of orders taken" - }, - { - "code": 6061, - "name": "OrderDoesNotExist", - "msg": "Order does not exist" - }, - { - "code": 6062, - "name": "OrderNotOpen", - "msg": "Order not open" - }, - { - "code": 6063, - "name": "FillOrderDidNotUpdateState", - "msg": "FillOrderDidNotUpdateState" - }, - { - "code": 6064, - "name": "ReduceOnlyOrderIncreasedRisk", - "msg": "Reduce only order increased risk" - }, - { - "code": 6065, - "name": "UnableToLoadAccountLoader", - "msg": "Unable to load AccountLoader" - }, - { - "code": 6066, - "name": "TradeSizeTooLarge", - "msg": "Trade Size Too Large" - }, - { - "code": 6067, - "name": "UserCantReferThemselves", - "msg": "User cant refer themselves" - }, - { - "code": 6068, - "name": "DidNotReceiveExpectedReferrer", - "msg": "Did not receive expected referrer" - }, - { - "code": 6069, - "name": "CouldNotDeserializeReferrer", - "msg": "Could not deserialize referrer" - }, - { - "code": 6070, - "name": "CouldNotDeserializeReferrerStats", - "msg": "Could not deserialize referrer stats" - }, - { - "code": 6071, - "name": "UserOrderIdAlreadyInUse", - "msg": "User Order Id Already In Use" - }, - { - "code": 6072, - "name": "NoPositionsLiquidatable", - "msg": "No positions liquidatable" - }, - { - "code": 6073, - "name": "InvalidMarginRatio", - "msg": "Invalid Margin Ratio" - }, - { - "code": 6074, - "name": "CantCancelPostOnlyOrder", - "msg": "Cant Cancel Post Only Order" - }, - { - "code": 6075, - "name": "InvalidOracleOffset", - "msg": "InvalidOracleOffset" - }, - { - "code": 6076, - "name": "CantExpireOrders", - "msg": "CantExpireOrders" - }, - { - "code": 6077, - "name": "CouldNotLoadMarketData", - "msg": "CouldNotLoadMarketData" - }, - { - "code": 6078, - "name": "PerpMarketNotFound", - "msg": "PerpMarketNotFound" - }, - { - "code": 6079, - "name": "InvalidMarketAccount", - "msg": "InvalidMarketAccount" - }, - { - "code": 6080, - "name": "UnableToLoadPerpMarketAccount", - "msg": "UnableToLoadMarketAccount" - }, - { - "code": 6081, - "name": "MarketWrongMutability", - "msg": "MarketWrongMutability" - }, - { - "code": 6082, - "name": "UnableToCastUnixTime", - "msg": "UnableToCastUnixTime" - }, - { - "code": 6083, - "name": "CouldNotFindSpotPosition", - "msg": "CouldNotFindSpotPosition" - }, - { - "code": 6084, - "name": "NoSpotPositionAvailable", - "msg": "NoSpotPositionAvailable" - }, - { - "code": 6085, - "name": "InvalidSpotMarketInitialization", - "msg": "InvalidSpotMarketInitialization" - }, - { - "code": 6086, - "name": "CouldNotLoadSpotMarketData", - "msg": "CouldNotLoadSpotMarketData" - }, - { - "code": 6087, - "name": "SpotMarketNotFound", - "msg": "SpotMarketNotFound" - }, - { - "code": 6088, - "name": "InvalidSpotMarketAccount", - "msg": "InvalidSpotMarketAccount" - }, - { - "code": 6089, - "name": "UnableToLoadSpotMarketAccount", - "msg": "UnableToLoadSpotMarketAccount" - }, - { - "code": 6090, - "name": "SpotMarketWrongMutability", - "msg": "SpotMarketWrongMutability" - }, - { - "code": 6091, - "name": "SpotMarketInterestNotUpToDate", - "msg": "SpotInterestNotUpToDate" - }, - { - "code": 6092, - "name": "SpotMarketInsufficientDeposits", - "msg": "SpotMarketInsufficientDeposits" - }, - { - "code": 6093, - "name": "UserMustSettleTheirOwnPositiveUnsettledPNL", - "msg": "UserMustSettleTheirOwnPositiveUnsettledPNL" - }, - { - "code": 6094, - "name": "CantUpdatePoolBalanceType", - "msg": "CantUpdatePoolBalanceType" - }, - { - "code": 6095, - "name": "InsufficientCollateralForSettlingPNL", - "msg": "InsufficientCollateralForSettlingPNL" - }, - { - "code": 6096, - "name": "AMMNotUpdatedInSameSlot", - "msg": "AMMNotUpdatedInSameSlot" - }, - { - "code": 6097, - "name": "AuctionNotComplete", - "msg": "AuctionNotComplete" - }, - { - "code": 6098, - "name": "MakerNotFound", - "msg": "MakerNotFound" - }, - { - "code": 6099, - "name": "MakerStatsNotFound", - "msg": "MakerNotFound" - }, - { - "code": 6100, - "name": "MakerMustBeWritable", - "msg": "MakerMustBeWritable" - }, - { - "code": 6101, - "name": "MakerStatsMustBeWritable", - "msg": "MakerMustBeWritable" - }, - { - "code": 6102, - "name": "MakerOrderNotFound", - "msg": "MakerOrderNotFound" - }, - { - "code": 6103, - "name": "CouldNotDeserializeMaker", - "msg": "CouldNotDeserializeMaker" - }, - { - "code": 6104, - "name": "CouldNotDeserializeMakerStats", - "msg": "CouldNotDeserializeMaker" - }, - { - "code": 6105, - "name": "AuctionPriceDoesNotSatisfyMaker", - "msg": "AuctionPriceDoesNotSatisfyMaker" - }, - { - "code": 6106, - "name": "MakerCantFulfillOwnOrder", - "msg": "MakerCantFulfillOwnOrder" - }, - { - "code": 6107, - "name": "MakerOrderMustBePostOnly", - "msg": "MakerOrderMustBePostOnly" - }, - { - "code": 6108, - "name": "CantMatchTwoPostOnlys", - "msg": "CantMatchTwoPostOnlys" - }, - { - "code": 6109, - "name": "OrderBreachesOraclePriceLimits", - "msg": "OrderBreachesOraclePriceLimits" - }, - { - "code": 6110, - "name": "OrderMustBeTriggeredFirst", - "msg": "OrderMustBeTriggeredFirst" - }, - { - "code": 6111, - "name": "OrderNotTriggerable", - "msg": "OrderNotTriggerable" - }, - { - "code": 6112, - "name": "OrderDidNotSatisfyTriggerCondition", - "msg": "OrderDidNotSatisfyTriggerCondition" - }, - { - "code": 6113, - "name": "PositionAlreadyBeingLiquidated", - "msg": "PositionAlreadyBeingLiquidated" - }, - { - "code": 6114, - "name": "PositionDoesntHaveOpenPositionOrOrders", - "msg": "PositionDoesntHaveOpenPositionOrOrders" - }, - { - "code": 6115, - "name": "AllOrdersAreAlreadyLiquidations", - "msg": "AllOrdersAreAlreadyLiquidations" - }, - { - "code": 6116, - "name": "CantCancelLiquidationOrder", - "msg": "CantCancelLiquidationOrder" - }, - { - "code": 6117, - "name": "UserIsBeingLiquidated", - "msg": "UserIsBeingLiquidated" - }, - { - "code": 6118, - "name": "LiquidationsOngoing", - "msg": "LiquidationsOngoing" - }, - { - "code": 6119, - "name": "WrongSpotBalanceType", - "msg": "WrongSpotBalanceType" - }, - { - "code": 6120, - "name": "UserCantLiquidateThemself", - "msg": "UserCantLiquidateThemself" - }, - { - "code": 6121, - "name": "InvalidPerpPositionToLiquidate", - "msg": "InvalidPerpPositionToLiquidate" - }, - { - "code": 6122, - "name": "InvalidBaseAssetAmountForLiquidatePerp", - "msg": "InvalidBaseAssetAmountForLiquidatePerp" - }, - { - "code": 6123, - "name": "InvalidPositionLastFundingRate", - "msg": "InvalidPositionLastFundingRate" - }, - { - "code": 6124, - "name": "InvalidPositionDelta", - "msg": "InvalidPositionDelta" - }, - { - "code": 6125, - "name": "UserBankrupt", - "msg": "UserBankrupt" - }, - { - "code": 6126, - "name": "UserNotBankrupt", - "msg": "UserNotBankrupt" - }, - { - "code": 6127, - "name": "UserHasInvalidBorrow", - "msg": "UserHasInvalidBorrow" - }, - { - "code": 6128, - "name": "DailyWithdrawLimit", - "msg": "DailyWithdrawLimit" - }, - { - "code": 6129, - "name": "DefaultError", - "msg": "DefaultError" - }, - { - "code": 6130, - "name": "InsufficientLPTokens", - "msg": "Insufficient LP tokens" - }, - { - "code": 6131, - "name": "CantLPWithPerpPosition", - "msg": "Cant LP with a market position" - }, - { - "code": 6132, - "name": "UnableToBurnLPTokens", - "msg": "Unable to burn LP tokens" - }, - { - "code": 6133, - "name": "TryingToRemoveLiquidityTooFast", - "msg": "Trying to remove liqudity too fast after adding it" - }, - { - "code": 6134, - "name": "InvalidSpotMarketVault", - "msg": "Invalid Spot Market Vault" - }, - { - "code": 6135, - "name": "InvalidSpotMarketState", - "msg": "Invalid Spot Market State" - }, - { - "code": 6136, - "name": "InvalidSerumProgram", - "msg": "InvalidSerumProgram" - }, - { - "code": 6137, - "name": "InvalidSerumMarket", - "msg": "InvalidSerumMarket" - }, - { - "code": 6138, - "name": "InvalidSerumBids", - "msg": "InvalidSerumBids" - }, - { - "code": 6139, - "name": "InvalidSerumAsks", - "msg": "InvalidSerumAsks" - }, - { - "code": 6140, - "name": "InvalidSerumOpenOrders", - "msg": "InvalidSerumOpenOrders" - }, - { - "code": 6141, - "name": "FailedSerumCPI", - "msg": "FailedSerumCPI" - }, - { - "code": 6142, - "name": "FailedToFillOnExternalMarket", - "msg": "FailedToFillOnExternalMarket" - }, - { - "code": 6143, - "name": "InvalidFulfillmentConfig", - "msg": "InvalidFulfillmentConfig" - }, - { - "code": 6144, - "name": "InvalidFeeStructure", - "msg": "InvalidFeeStructure" - }, - { - "code": 6145, - "name": "InsufficientIFShares", - "msg": "Insufficient IF shares" - }, - { - "code": 6146, - "name": "MarketActionPaused", - "msg": "the Market has paused this action" - }, - { - "code": 6147, - "name": "MarketPlaceOrderPaused", - "msg": "the Market status doesnt allow placing orders" - }, - { - "code": 6148, - "name": "MarketFillOrderPaused", - "msg": "the Market status doesnt allow filling orders" - }, - { - "code": 6149, - "name": "MarketWithdrawPaused", - "msg": "the Market status doesnt allow withdraws" - }, - { - "code": 6150, - "name": "ProtectedAssetTierViolation", - "msg": "Action violates the Protected Asset Tier rules" - }, - { - "code": 6151, - "name": "IsolatedAssetTierViolation", - "msg": "Action violates the Isolated Asset Tier rules" - }, - { - "code": 6152, - "name": "UserCantBeDeleted", - "msg": "User Cant Be Deleted" - }, - { - "code": 6153, - "name": "ReduceOnlyWithdrawIncreasedRisk", - "msg": "Reduce Only Withdraw Increased Risk" - }, - { - "code": 6154, - "name": "MaxOpenInterest", - "msg": "Max Open Interest" - }, - { - "code": 6155, - "name": "CantResolvePerpBankruptcy", - "msg": "Cant Resolve Perp Bankruptcy" - }, - { - "code": 6156, - "name": "LiquidationDoesntSatisfyLimitPrice", - "msg": "Liquidation Doesnt Satisfy Limit Price" - }, - { - "code": 6157, - "name": "MarginTradingDisabled", - "msg": "Margin Trading Disabled" - }, - { - "code": 6158, - "name": "InvalidMarketStatusToSettlePnl", - "msg": "Invalid Market Status to Settle Perp Pnl" - }, - { - "code": 6159, - "name": "PerpMarketNotInSettlement", - "msg": "PerpMarketNotInSettlement" - }, - { - "code": 6160, - "name": "PerpMarketNotInReduceOnly", - "msg": "PerpMarketNotInReduceOnly" - }, - { - "code": 6161, - "name": "PerpMarketSettlementBufferNotReached", - "msg": "PerpMarketSettlementBufferNotReached" - }, - { - "code": 6162, - "name": "PerpMarketSettlementUserHasOpenOrders", - "msg": "PerpMarketSettlementUserHasOpenOrders" - }, - { - "code": 6163, - "name": "PerpMarketSettlementUserHasActiveLP", - "msg": "PerpMarketSettlementUserHasActiveLP" - }, - { - "code": 6164, - "name": "UnableToSettleExpiredUserPosition", - "msg": "UnableToSettleExpiredUserPosition" - }, - { - "code": 6165, - "name": "UnequalMarketIndexForSpotTransfer", - "msg": "UnequalMarketIndexForSpotTransfer" - }, - { - "code": 6166, - "name": "InvalidPerpPositionDetected", - "msg": "InvalidPerpPositionDetected" - }, - { - "code": 6167, - "name": "InvalidSpotPositionDetected", - "msg": "InvalidSpotPositionDetected" - }, - { - "code": 6168, - "name": "InvalidAmmDetected", - "msg": "InvalidAmmDetected" - }, - { - "code": 6169, - "name": "InvalidAmmForFillDetected", - "msg": "InvalidAmmForFillDetected" - }, - { - "code": 6170, - "name": "InvalidAmmLimitPriceOverride", - "msg": "InvalidAmmLimitPriceOverride" - }, - { - "code": 6171, - "name": "InvalidOrderFillPrice", - "msg": "InvalidOrderFillPrice" - }, - { - "code": 6172, - "name": "SpotMarketBalanceInvariantViolated", - "msg": "SpotMarketBalanceInvariantViolated" - }, - { - "code": 6173, - "name": "SpotMarketVaultInvariantViolated", - "msg": "SpotMarketVaultInvariantViolated" - }, - { - "code": 6174, - "name": "InvalidPDA", - "msg": "InvalidPDA" - }, - { - "code": 6175, - "name": "InvalidPDASigner", - "msg": "InvalidPDASigner" - }, - { - "code": 6176, - "name": "RevenueSettingsCannotSettleToIF", - "msg": "RevenueSettingsCannotSettleToIF" - }, - { - "code": 6177, - "name": "NoRevenueToSettleToIF", - "msg": "NoRevenueToSettleToIF" - }, - { - "code": 6178, - "name": "NoAmmPerpPnlDeficit", - "msg": "NoAmmPerpPnlDeficit" - }, - { - "code": 6179, - "name": "SufficientPerpPnlPool", - "msg": "SufficientPerpPnlPool" - }, - { - "code": 6180, - "name": "InsufficientPerpPnlPool", - "msg": "InsufficientPerpPnlPool" - }, - { - "code": 6181, - "name": "PerpPnlDeficitBelowThreshold", - "msg": "PerpPnlDeficitBelowThreshold" - }, - { - "code": 6182, - "name": "MaxRevenueWithdrawPerPeriodReached", - "msg": "MaxRevenueWithdrawPerPeriodReached" - }, - { - "code": 6183, - "name": "MaxIFWithdrawReached", - "msg": "InvalidSpotPositionDetected" - }, - { - "code": 6184, - "name": "NoIFWithdrawAvailable", - "msg": "NoIFWithdrawAvailable" - }, - { - "code": 6185, - "name": "InvalidIFUnstake", - "msg": "InvalidIFUnstake" - }, - { - "code": 6186, - "name": "InvalidIFUnstakeSize", - "msg": "InvalidIFUnstakeSize" - }, - { - "code": 6187, - "name": "InvalidIFUnstakeCancel", - "msg": "InvalidIFUnstakeCancel" - }, - { - "code": 6188, - "name": "InvalidIFForNewStakes", - "msg": "InvalidIFForNewStakes" - }, - { - "code": 6189, - "name": "InvalidIFRebase", - "msg": "InvalidIFRebase" - }, - { - "code": 6190, - "name": "InvalidInsuranceUnstakeSize", - "msg": "InvalidInsuranceUnstakeSize" - }, - { - "code": 6191, - "name": "InvalidOrderLimitPrice", - "msg": "InvalidOrderLimitPrice" - }, - { - "code": 6192, - "name": "InvalidIFDetected", - "msg": "InvalidIFDetected" - }, - { - "code": 6193, - "name": "InvalidAmmMaxSpreadDetected", - "msg": "InvalidAmmMaxSpreadDetected" - }, - { - "code": 6194, - "name": "InvalidConcentrationCoef", - "msg": "InvalidConcentrationCoef" - }, - { - "code": 6195, - "name": "InvalidSrmVault", - "msg": "InvalidSrmVault" - }, - { - "code": 6196, - "name": "InvalidVaultOwner", - "msg": "InvalidVaultOwner" - }, - { - "code": 6197, - "name": "InvalidMarketStatusForFills", - "msg": "InvalidMarketStatusForFills" - }, - { - "code": 6198, - "name": "IFWithdrawRequestInProgress", - "msg": "IFWithdrawRequestInProgress" - }, - { - "code": 6199, - "name": "NoIFWithdrawRequestInProgress", - "msg": "NoIFWithdrawRequestInProgress" - }, - { - "code": 6200, - "name": "IFWithdrawRequestTooSmall", - "msg": "IFWithdrawRequestTooSmall" - }, - { - "code": 6201, - "name": "IncorrectSpotMarketAccountPassed", - "msg": "IncorrectSpotMarketAccountPassed" - }, - { - "code": 6202, - "name": "BlockchainClockInconsistency", - "msg": "BlockchainClockInconsistency" - }, - { - "code": 6203, - "name": "InvalidIFSharesDetected", - "msg": "InvalidIFSharesDetected" - }, - { - "code": 6204, - "name": "NewLPSizeTooSmall", - "msg": "NewLPSizeTooSmall" - }, - { - "code": 6205, - "name": "MarketStatusInvalidForNewLP", - "msg": "MarketStatusInvalidForNewLP" - }, - { - "code": 6206, - "name": "InvalidMarkTwapUpdateDetected", - "msg": "InvalidMarkTwapUpdateDetected" - }, - { - "code": 6207, - "name": "MarketSettlementAttemptOnActiveMarket", - "msg": "MarketSettlementAttemptOnActiveMarket" - }, - { - "code": 6208, - "name": "MarketSettlementRequiresSettledLP", - "msg": "MarketSettlementRequiresSettledLP" - }, - { - "code": 6209, - "name": "MarketSettlementAttemptTooEarly", - "msg": "MarketSettlementAttemptTooEarly" - }, - { - "code": 6210, - "name": "MarketSettlementTargetPriceInvalid", - "msg": "MarketSettlementTargetPriceInvalid" - }, - { - "code": 6211, - "name": "UnsupportedSpotMarket", - "msg": "UnsupportedSpotMarket" - }, - { - "code": 6212, - "name": "SpotOrdersDisabled", - "msg": "SpotOrdersDisabled" - }, - { - "code": 6213, - "name": "MarketBeingInitialized", - "msg": "Market Being Initialized" - }, - { - "code": 6214, - "name": "InvalidUserSubAccountId", - "msg": "Invalid Sub Account Id" - }, - { - "code": 6215, - "name": "InvalidTriggerOrderCondition", - "msg": "Invalid Trigger Order Condition" - }, - { - "code": 6216, - "name": "InvalidSpotPosition", - "msg": "Invalid Spot Position" - }, - { - "code": 6217, - "name": "CantTransferBetweenSameUserAccount", - "msg": "Cant transfer between same user account" - }, - { - "code": 6218, - "name": "InvalidPerpPosition", - "msg": "Invalid Perp Position" - }, - { - "code": 6219, - "name": "UnableToGetLimitPrice", - "msg": "Unable To Get Limit Price" - }, - { - "code": 6220, - "name": "InvalidLiquidation", - "msg": "Invalid Liquidation" - }, - { - "code": 6221, - "name": "SpotFulfillmentConfigDisabled", - "msg": "Spot Fulfillment Config Disabled" - }, - { - "code": 6222, - "name": "InvalidMaker", - "msg": "Invalid Maker" - }, - { - "code": 6223, - "name": "FailedUnwrap", - "msg": "Failed Unwrap" - }, - { - "code": 6224, - "name": "MaxNumberOfUsers", - "msg": "Max Number Of Users" - }, - { - "code": 6225, - "name": "InvalidOracleForSettlePnl", - "msg": "InvalidOracleForSettlePnl" - }, - { - "code": 6226, - "name": "MarginOrdersOpen", - "msg": "MarginOrdersOpen" - }, - { - "code": 6227, - "name": "TierViolationLiquidatingPerpPnl", - "msg": "TierViolationLiquidatingPerpPnl" - }, - { - "code": 6228, - "name": "CouldNotLoadUserData", - "msg": "CouldNotLoadUserData" - }, - { - "code": 6229, - "name": "UserWrongMutability", - "msg": "UserWrongMutability" - }, - { - "code": 6230, - "name": "InvalidUserAccount", - "msg": "InvalidUserAccount" - }, - { - "code": 6231, - "name": "CouldNotLoadUserStatsData", - "msg": "CouldNotLoadUserData" - }, - { - "code": 6232, - "name": "UserStatsWrongMutability", - "msg": "UserWrongMutability" - }, - { - "code": 6233, - "name": "InvalidUserStatsAccount", - "msg": "InvalidUserAccount" - }, - { - "code": 6234, - "name": "UserNotFound", - "msg": "UserNotFound" - }, - { - "code": 6235, - "name": "UnableToLoadUserAccount", - "msg": "UnableToLoadUserAccount" - }, - { - "code": 6236, - "name": "UserStatsNotFound", - "msg": "UserStatsNotFound" - }, - { - "code": 6237, - "name": "UnableToLoadUserStatsAccount", - "msg": "UnableToLoadUserStatsAccount" - }, - { - "code": 6238, - "name": "UserNotInactive", - "msg": "User Not Inactive" - }, - { - "code": 6239, - "name": "RevertFill", - "msg": "RevertFill" - }, - { - "code": 6240, - "name": "InvalidMarketAccountforDeletion", - "msg": "Invalid MarketAccount for Deletion" - }, - { - "code": 6241, - "name": "InvalidSpotFulfillmentParams", - "msg": "Invalid Spot Fulfillment Params" - }, - { - "code": 6242, - "name": "FailedToGetMint", - "msg": "Failed to Get Mint" - }, - { - "code": 6243, - "name": "FailedPhoenixCPI", - "msg": "FailedPhoenixCPI" - }, - { - "code": 6244, - "name": "FailedToDeserializePhoenixMarket", - "msg": "FailedToDeserializePhoenixMarket" - }, - { - "code": 6245, - "name": "InvalidPricePrecision", - "msg": "InvalidPricePrecision" - }, - { - "code": 6246, - "name": "InvalidPhoenixProgram", - "msg": "InvalidPhoenixProgram" - }, - { - "code": 6247, - "name": "InvalidPhoenixMarket", - "msg": "InvalidPhoenixMarket" - }, - { - "code": 6248, - "name": "InvalidSwap", - "msg": "InvalidSwap" - }, - { - "code": 6249, - "name": "SwapLimitPriceBreached", - "msg": "SwapLimitPriceBreached" - }, - { - "code": 6250, - "name": "SpotMarketReduceOnly", - "msg": "SpotMarketReduceOnly" - }, - { - "code": 6251, - "name": "FundingWasNotUpdated", - "msg": "FundingWasNotUpdated" - }, - { - "code": 6252, - "name": "ImpossibleFill", - "msg": "ImpossibleFill" - }, - { - "code": 6253, - "name": "CantUpdatePerpBidAskTwap", - "msg": "CantUpdatePerpBidAskTwap" - }, - { - "code": 6254, - "name": "UserReduceOnly", - "msg": "UserReduceOnly" - }, - { - "code": 6255, - "name": "InvalidMarginCalculation", - "msg": "InvalidMarginCalculation" - }, - { - "code": 6256, - "name": "CantPayUserInitFee", - "msg": "CantPayUserInitFee" - }, - { - "code": 6257, - "name": "CantReclaimRent", - "msg": "CantReclaimRent" - }, - { - "code": 6258, - "name": "InsuranceFundOperationPaused", - "msg": "InsuranceFundOperationPaused" - }, - { - "code": 6259, - "name": "NoUnsettledPnl", - "msg": "NoUnsettledPnl" - }, - { - "code": 6260, - "name": "PnlPoolCantSettleUser", - "msg": "PnlPoolCantSettleUser" - }, - { - "code": 6261, - "name": "OracleNonPositive", - "msg": "OracleInvalid" - }, - { - "code": 6262, - "name": "OracleTooVolatile", - "msg": "OracleTooVolatile" - }, - { - "code": 6263, - "name": "OracleTooUncertain", - "msg": "OracleTooUncertain" - }, - { - "code": 6264, - "name": "OracleStaleForMargin", - "msg": "OracleStaleForMargin" - }, - { - "code": 6265, - "name": "OracleInsufficientDataPoints", - "msg": "OracleInsufficientDataPoints" - }, - { - "code": 6266, - "name": "OracleStaleForAMM", - "msg": "OracleStaleForAMM" - }, - { - "code": 6267, - "name": "UnableToParsePullOracleMessage", - "msg": "Unable to parse pull oracle message" - }, - { - "code": 6268, - "name": "MaxBorrows", - "msg": "Can not borow more than max borrows" - }, - { - "code": 6269, - "name": "OracleUpdatesNotMonotonic", - "msg": "Updates must be monotonically increasing" - }, - { - "code": 6270, - "name": "OraclePriceFeedMessageMismatch", - "msg": "Trying to update price feed with the wrong feed id" - }, - { - "code": 6271, - "name": "OracleUnsupportedMessageType", - "msg": "The message in the update must be a PriceFeedMessage" - }, - { - "code": 6272, - "name": "OracleDeserializeMessageFailed", - "msg": "Could not deserialize the message in the update" - }, - { - "code": 6273, - "name": "OracleWrongGuardianSetOwner", - "msg": "Wrong guardian set owner in update price atomic" - }, - { - "code": 6274, - "name": "OracleWrongWriteAuthority", - "msg": "Oracle post update atomic price feed account must be drift program" - }, - { - "code": 6275, - "name": "OracleWrongVaaOwner", - "msg": "Oracle vaa owner must be wormhole program" - }, - { - "code": 6276, - "name": "OracleTooManyPriceAccountUpdates", - "msg": "Multi updates must have 2 or fewer accounts passed in remaining accounts" - }, - { - "code": 6277, - "name": "OracleMismatchedVaaAndPriceUpdates", - "msg": "Don't have the same remaining accounts number and pyth updates left" - }, - { - "code": 6278, - "name": "OracleBadRemainingAccountPublicKey", - "msg": "Remaining account passed does not match oracle update derived pda" - }, - { - "code": 6279, - "name": "FailedOpenbookV2CPI", - "msg": "FailedOpenbookV2CPI" - }, - { - "code": 6280, - "name": "InvalidOpenbookV2Program", - "msg": "InvalidOpenbookV2Program" - }, - { - "code": 6281, - "name": "InvalidOpenbookV2Market", - "msg": "InvalidOpenbookV2Market" - }, - { - "code": 6282, - "name": "NonZeroTransferFee", - "msg": "Non zero transfer fee" - }, - { - "code": 6283, - "name": "LiquidationOrderFailedToFill", - "msg": "Liquidation order failed to fill" - }, - { - "code": 6284, - "name": "InvalidPredictionMarketOrder", - "msg": "Invalid prediction market order" - }, - { - "code": 6285, - "name": "InvalidVerificationIxIndex", - "msg": "Ed25519 Ix must be before place and make SignedMsg order ix" - }, - { - "code": 6286, - "name": "SigVerificationFailed", - "msg": "SignedMsg message verificaiton failed" - }, - { - "code": 6287, - "name": "MismatchedSignedMsgOrderParamsMarketIndex", - "msg": "Market index mismatched b/w taker and maker SignedMsg order params" - }, - { - "code": 6288, - "name": "InvalidSignedMsgOrderParam", - "msg": "Invalid SignedMsg order param" - }, - { - "code": 6289, - "name": "PlaceAndTakeOrderSuccessConditionFailed", - "msg": "Place and take order success condition failed" - }, - { - "code": 6290, - "name": "InvalidHighLeverageModeConfig", - "msg": "Invalid High Leverage Mode Config" - }, - { - "code": 6291, - "name": "InvalidRFQUserAccount", - "msg": "Invalid RFQ User Account" - }, - { - "code": 6292, - "name": "RFQUserAccountWrongMutability", - "msg": "RFQUserAccount should be mutable" - }, - { - "code": 6293, - "name": "RFQUserAccountFull", - "msg": "RFQUserAccount has too many active RFQs" - }, - { - "code": 6294, - "name": "RFQOrderNotFilled", - "msg": "RFQ order not filled as expected" - }, - { - "code": 6295, - "name": "InvalidRFQOrder", - "msg": "RFQ orders must be jit makers" - }, - { - "code": 6296, - "name": "InvalidRFQMatch", - "msg": "RFQ matches must be valid" - }, - { - "code": 6297, - "name": "InvalidSignedMsgUserAccount", - "msg": "Invalid SignedMsg user account" - }, - { - "code": 6298, - "name": "SignedMsgUserAccountWrongMutability", - "msg": "SignedMsg account wrong mutability" - }, - { - "code": 6299, - "name": "SignedMsgUserOrdersAccountFull", - "msg": "SignedMsgUserAccount has too many active orders" - }, - { - "code": 6300, - "name": "SignedMsgOrderDoesNotExist", - "msg": "Order with SignedMsg uuid does not exist" - }, - { - "code": 6301, - "name": "InvalidSignedMsgOrderId", - "msg": "SignedMsg order id cannot be 0s" - }, - { - "code": 6302, - "name": "InvalidPoolId", - "msg": "Invalid pool id" - }, - { - "code": 6303, - "name": "InvalidProtectedMakerModeConfig", - "msg": "Invalid Protected Maker Mode Config" - }, - { - "code": 6304, - "name": "InvalidPythLazerStorageOwner", - "msg": "Invalid pyth lazer storage owner" - }, - { - "code": 6305, - "name": "UnverifiedPythLazerMessage", - "msg": "Verification of pyth lazer message failed" - }, - { - "code": 6306, - "name": "InvalidPythLazerMessage", - "msg": "Invalid pyth lazer message" - }, - { - "code": 6307, - "name": "PythLazerMessagePriceFeedMismatch", - "msg": "Pyth lazer message does not correspond to correct fed id" - }, - { - "code": 6308, - "name": "InvalidLiquidateSpotWithSwap", - "msg": "InvalidLiquidateSpotWithSwap" - }, - { - "code": 6309, - "name": "SignedMsgUserContextUserMismatch", - "msg": "User in SignedMsg message does not match user in ix context" - }, - { - "code": 6310, - "name": "UserFuelOverflowThresholdNotMet", - "msg": "User fuel overflow threshold not met" - }, - { - "code": 6311, - "name": "FuelOverflowAccountNotFound", - "msg": "FuelOverflow account not found" - }, - { - "code": 6312, - "name": "InvalidTransferPerpPosition", - "msg": "Invalid Transfer Perp Position" - }, - { - "code": 6313, - "name": "InvalidSignedMsgUserOrdersResize", - "msg": "Invalid SignedMsgUserOrders resize" - }, - { - "code": 6314, - "name": "CouldNotDeserializeHighLeverageModeConfig", - "msg": "Could not deserialize high leverage mode config" - }, - { - "code": 6315, - "name": "InvalidIfRebalanceConfig", - "msg": "Invalid If Rebalance Config" - }, - { - "code": 6316, - "name": "InvalidIfRebalanceSwap", - "msg": "Invalid If Rebalance Swap" - }, - { - "code": 6317, - "name": "InvalidRevenueShareResize", - "msg": "Invalid RevenueShare resize" - }, - { - "code": 6318, - "name": "BuilderRevoked", - "msg": "Builder has been revoked" - }, - { - "code": 6319, - "name": "InvalidBuilderFee", - "msg": "Builder fee is greater than max fee bps" - }, - { - "code": 6320, - "name": "RevenueShareEscrowAuthorityMismatch", - "msg": "RevenueShareEscrow authority mismatch" - }, - { - "code": 6321, - "name": "RevenueShareEscrowOrdersAccountFull", - "msg": "RevenueShareEscrow has too many active orders" - }, - { - "code": 6322, - "name": "InvalidRevenueShareAccount", - "msg": "Invalid RevenueShareAccount" - }, - { - "code": 6323, - "name": "CannotRevokeBuilderWithOpenOrders", - "msg": "Cannot revoke builder with open orders" - }, - { - "code": 6324, - "name": "UnableToLoadRevenueShareAccount", - "msg": "Unable to load builder account" - }, - { - "code": 6325, - "name": "InvalidConstituent", - "msg": "Invalid Constituent" - }, - { - "code": 6326, - "name": "InvalidAmmConstituentMappingArgument", - "msg": "Invalid Amm Constituent Mapping argument" - }, - { - "code": 6327, - "name": "ConstituentNotFound", - "msg": "Constituent not found" - }, - { - "code": 6328, - "name": "ConstituentCouldNotLoad", - "msg": "Constituent could not load" - }, - { - "code": 6329, - "name": "ConstituentWrongMutability", - "msg": "Constituent wrong mutability" - }, - { - "code": 6330, - "name": "WrongNumberOfConstituents", - "msg": "Wrong number of constituents passed to instruction" - }, - { - "code": 6331, - "name": "InsufficientConstituentTokenBalance", - "msg": "Insufficient constituent token balance" - }, - { - "code": 6332, - "name": "AMMCacheStale", - "msg": "Amm Cache data too stale" - }, - { - "code": 6333, - "name": "LpPoolAumDelayed", - "msg": "LP Pool AUM not updated recently" - }, - { - "code": 6334, - "name": "ConstituentOracleStale", - "msg": "Constituent oracle is stale" - }, - { - "code": 6335, - "name": "LpInvariantFailed", - "msg": "LP Invariant failed" - }, - { - "code": 6336, - "name": "InvalidConstituentDerivativeWeights", - "msg": "Invalid constituent derivative weights" - }, - { - "code": 6337, - "name": "MaxDlpAumBreached", - "msg": "Max DLP AUM Breached" - }, - { - "code": 6338, - "name": "SettleLpPoolDisabled", - "msg": "Settle Lp Pool Disabled" - }, - { - "code": 6339, - "name": "MintRedeemLpPoolDisabled", - "msg": "Mint/Redeem Lp Pool Disabled" + "name": "User", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "authority", + "docs": [ + "The owner/authority of the account" + ], + "type": "pubkey" + }, + { + "name": "delegate", + "docs": [ + "An addresses that can control the account on the authority's behalf. Has limited power, cant withdraw" + ], + "type": "pubkey" + }, + { + "name": "name", + "docs": [ + "Encoded display name e.g. \"toly\"" + ], + "type": { + "array": [ + "u8", + 32 + ] + } + }, + { + "name": "spot_positions", + "docs": [ + "The user's spot positions" + ], + "type": { + "array": [ + { + "defined": { + "name": "SpotPosition" + } + }, + 8 + ] + } + }, + { + "name": "perp_positions", + "docs": [ + "The user's perp positions" + ], + "type": { + "array": [ + { + "defined": { + "name": "PerpPosition" + } + }, + 8 + ] + } + }, + { + "name": "orders", + "docs": [ + "The user's orders" + ], + "type": { + "array": [ + { + "defined": { + "name": "Order" + } + }, + 32 + ] + } + }, + { + "name": "last_add_perp_lp_shares_ts", + "docs": [ + "The last time the user added perp lp positions" + ], + "type": "i64" + }, + { + "name": "total_deposits", + "docs": [ + "The total values of deposits the user has made", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_withdraws", + "docs": [ + "The total values of withdrawals the user has made", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_social_loss", + "docs": [ + "The total socialized loss the users has incurred upon the protocol", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "settled_perp_pnl", + "docs": [ + "Fees (taker fees, maker rebate, referrer reward, filler reward) and pnl for perps", + "precision: QUOTE_PRECISION" + ], + "type": "i64" + }, + { + "name": "cumulative_spot_fees", + "docs": [ + "Fees (taker fees, maker rebate, filler reward) for spot", + "precision: QUOTE_PRECISION" + ], + "type": "i64" + }, + { + "name": "cumulative_perp_funding", + "docs": [ + "Cumulative funding paid/received for perps", + "precision: QUOTE_PRECISION" + ], + "type": "i64" + }, + { + "name": "liquidation_margin_freed", + "docs": [ + "The amount of margin freed during liquidation. Used to force the liquidation to occur over a period of time", + "Defaults to zero when not being liquidated", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "last_active_slot", + "docs": [ + "The last slot a user was active. Used to determine if a user is idle" + ], + "type": "u64" + }, + { + "name": "next_order_id", + "docs": [ + "Every user order has an order id. This is the next order id to be used" + ], + "type": "u32" + }, + { + "name": "max_margin_ratio", + "docs": [ + "Custom max initial margin ratio for the user" + ], + "type": "u32" + }, + { + "name": "next_liquidation_id", + "docs": [ + "The next liquidation id to be used for user" + ], + "type": "u16" + }, + { + "name": "sub_account_id", + "docs": [ + "The sub account id for this user" + ], + "type": "u16" + }, + { + "name": "status", + "docs": [ + "Whether the user is active, being liquidated or bankrupt" + ], + "type": "u8" + }, + { + "name": "is_margin_trading_enabled", + "docs": [ + "Whether the user has enabled margin trading" + ], + "type": "bool" + }, + { + "name": "idle", + "docs": [ + "User is idle if they haven't interacted with the protocol in 1 week and they have no orders, perp positions or borrows", + "Off-chain keeper bots can ignore users that are idle" + ], + "type": "bool" + }, + { + "name": "open_orders", + "docs": [ + "number of open orders" + ], + "type": "u8" + }, + { + "name": "has_open_order", + "docs": [ + "Whether or not user has open order" + ], + "type": "bool" + }, + { + "name": "open_auctions", + "docs": [ + "number of open orders with auction" + ], + "type": "u8" + }, + { + "name": "has_open_auction", + "docs": [ + "Whether or not user has open order with auction" + ], + "type": "bool" + }, + { + "name": "margin_mode", + "type": { + "defined": { + "name": "MarginMode" + } + } + }, + { + "name": "pool_id", + "type": "u8" + }, + { + "name": "padding1", + "type": { + "array": [ + "u8", + 3 + ] + } + }, + { + "name": "last_fuel_bonus_update_ts", + "type": "u32" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 12 + ] + } + } + ] + } }, { - "code": 6340, - "name": "LpPoolSettleInvariantBreached", - "msg": "Settlement amount exceeded" + "name": "UserFees", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "total_fee_paid", + "docs": [ + "Total taker fee paid", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_fee_rebate", + "docs": [ + "Total maker fee rebate", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_token_discount", + "docs": [ + "Total discount from holding token", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_referee_discount", + "docs": [ + "Total discount from being referred", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "total_referrer_reward", + "docs": [ + "Total reward to referrer", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "current_epoch_referrer_reward", + "docs": [ + "Total reward to referrer this epoch", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + } + ] + } }, { - "code": 6341, - "name": "InvalidConstituentOperation", - "msg": "Invalid constituent operation" + "name": "UserStats", + "serialization": "bytemuckunsafe", + "repr": { + "kind": "c" + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "authority", + "docs": [ + "The authority for all of a users sub accounts" + ], + "type": "pubkey" + }, + { + "name": "referrer", + "docs": [ + "The address that referred this user" + ], + "type": "pubkey" + }, + { + "name": "fees", + "docs": [ + "Stats on the fees paid by the user" + ], + "type": { + "defined": { + "name": "UserFees" + } + } + }, + { + "name": "next_epoch_ts", + "docs": [ + "The timestamp of the next epoch", + "Epoch is used to limit referrer rewards earned in single epoch" + ], + "type": "i64" + }, + { + "name": "maker_volume_30d", + "docs": [ + "Rolling 30day maker volume for user", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "taker_volume_30d", + "docs": [ + "Rolling 30day taker volume for user", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "filler_volume_30d", + "docs": [ + "Rolling 30day filler volume for user", + "precision: QUOTE_PRECISION" + ], + "type": "u64" + }, + { + "name": "last_maker_volume_30d_ts", + "docs": [ + "last time the maker volume was updated" + ], + "type": "i64" + }, + { + "name": "last_taker_volume_30d_ts", + "docs": [ + "last time the taker volume was updated" + ], + "type": "i64" + }, + { + "name": "last_filler_volume_30d_ts", + "docs": [ + "last time the filler volume was updated" + ], + "type": "i64" + }, + { + "name": "if_staked_quote_asset_amount", + "docs": [ + "The amount of tokens staked in the quote spot markets if" + ], + "type": "u64" + }, + { + "name": "number_of_sub_accounts", + "docs": [ + "The current number of sub accounts" + ], + "type": "u16" + }, + { + "name": "number_of_sub_accounts_created", + "docs": [ + "The number of sub accounts created. Can be greater than the number of sub accounts if user", + "has deleted sub accounts" + ], + "type": "u16" + }, + { + "name": "referrer_status", + "docs": [ + "Flags for referrer status:", + "First bit (LSB): 1 if user is a referrer, 0 otherwise", + "Second bit: 1 if user was referred, 0 otherwise" + ], + "type": "u8" + }, + { + "name": "disable_update_perp_bid_ask_twap", + "type": "u8" + }, + { + "name": "paused_operations", + "type": "u8" + }, + { + "name": "fuel_overflow_status", + "docs": [ + "whether the user has a FuelOverflow account" + ], + "type": "u8" + }, + { + "name": "fuel_insurance", + "docs": [ + "accumulated fuel for token amounts of insurance" + ], + "type": "u32" + }, + { + "name": "fuel_deposits", + "docs": [ + "accumulated fuel for notional of deposits" + ], + "type": "u32" + }, + { + "name": "fuel_borrows", + "docs": [ + "accumulate fuel bonus for notional of borrows" + ], + "type": "u32" + }, + { + "name": "fuel_positions", + "docs": [ + "accumulated fuel for perp open interest" + ], + "type": "u32" + }, + { + "name": "fuel_taker", + "docs": [ + "accumulate fuel bonus for taker volume" + ], + "type": "u32" + }, + { + "name": "fuel_maker", + "docs": [ + "accumulate fuel bonus for maker volume" + ], + "type": "u32" + }, + { + "name": "if_staked_gov_token_amount", + "docs": [ + "The amount of tokens staked in the governance spot markets if" + ], + "type": "u64" + }, + { + "name": "last_fuel_if_bonus_update_ts", + "docs": [ + "last unix ts user stats data was used to update if fuel (u32 to save space)" + ], + "type": "u32" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 12 + ] + } + } + ] + } }, { - "code": 6342, - "name": "Unauthorized", - "msg": "Unauthorized for operation" + "name": "ValidityGuardRails", + "type": { + "kind": "struct", + "fields": [ + { + "name": "slots_before_stale_for_amm", + "type": "i64" + }, + { + "name": "slots_before_stale_for_margin", + "type": "i64" + }, + { + "name": "confidence_interval_max_size", + "type": "u64" + }, + { + "name": "too_volatile_ratio", + "type": "i64" + } + ] + } }, { - "code": 6343, - "name": "InvalidLpPoolId", - "msg": "Invalid Lp Pool Id for Operation" + "name": "i128", + "docs": [ + "`i128` with legacy bit layout" + ], + "type": { + "kind": "struct", + "fields": [ + { + "array": [ + "u8", + 16 + ] + } + ] + } }, { - "code": 6344, - "name": "MarketIndexNotFoundAmmCache", - "msg": "MarketIndexNotFoundAmmCache" + "name": "u128", + "docs": [ + "`u128` with legacy bit layout" + ], + "type": { + "kind": "struct", + "fields": [ + { + "array": [ + "u8", + 16 + ] + } + ] + } } - ], - "metadata": { - "address": "dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH" - } + ] } \ No newline at end of file diff --git a/sdk/src/idl/drift.ts b/sdk/src/idl/drift.ts new file mode 100644 index 0000000000..73f3277476 --- /dev/null +++ b/sdk/src/idl/drift.ts @@ -0,0 +1,19766 @@ +/** + * Program IDL in camelCase format in order to be used in JS/TS. + * + * Note that this is only a type helper and is not the actual IDL. The original + * IDL can be found at `target/idl/drift.json`. + */ +export type Drift = { + address: 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH'; + metadata: { + name: 'drift'; + version: '2.151.0'; + spec: '0.1.0'; + description: 'Created with Anchor'; + }; + instructions: [ + { + name: 'addAmmConstituentMappingData'; + discriminator: [164, 236, 130, 40, 118, 179, 46, 235]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + }, + { + name: 'ammConstituentMapping'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [65, 77, 77, 95, 77, 65, 80]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'constituentTargetBase'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'ammConstituentMappingData'; + type: { + vec: { + defined: { + name: 'addAmmConstituentMappingDatum'; + }; + }; + }; + }, + ]; + }, + { + name: 'addInsuranceFundStake'; + discriminator: [251, 144, 115, 11, 222, 47, 62, 236]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['insuranceFundStake', 'userStats']; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'addMarketToAmmCache'; + discriminator: [112, 149, 195, 222, 124, 7, 87, 237]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + { + name: 'perpMarket'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'adminDeposit'; + discriminator: [210, 66, 65, 182, 102, 214, 176, 30]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'adminTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'adminUpdateUserStatsPausedOperations'; + discriminator: [183, 104, 63, 150, 240, 199, 3, 10]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'pausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'beginInsuranceFundSwap'; + discriminator: [176, 69, 143, 205, 32, 132, 163, 0]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'outInsuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inInsuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outTokenAccount'; + writable: true; + }, + { + name: 'inTokenAccount'; + writable: true; + }, + { + name: 'ifRebalanceConfig'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'amountIn'; + type: 'u64'; + }, + ]; + }, + { + name: 'beginLpSwap'; + discriminator: [64, 44, 24, 199, 48, 125, 67, 91]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'signerOutTokenAccount'; + docs: ['Signer token accounts']; + writable: true; + }, + { + name: 'signerInTokenAccount'; + writable: true; + }, + { + name: 'constituentOutTokenAccount'; + docs: ['Constituent token accounts']; + writable: true; + }, + { + name: 'constituentInTokenAccount'; + writable: true; + }, + { + name: 'outConstituent'; + docs: ['Constituents']; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'lpPool'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'amountIn'; + type: 'u64'; + }, + ]; + }, + { + name: 'beginSwap'; + discriminator: [174, 109, 228, 1, 242, 105, 232, 105]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'outSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outTokenAccount'; + writable: true; + }, + { + name: 'inTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'amountIn'; + type: 'u64'; + }, + ]; + }, + { + name: 'cancelOrder'; + discriminator: [95, 129, 237, 240, 8, 49, 223, 132]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'orderId'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'cancelOrderByUserId'; + discriminator: [107, 211, 250, 133, 18, 37, 57, 100]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'userOrderId'; + type: 'u8'; + }, + ]; + }, + { + name: 'cancelOrders'; + discriminator: [238, 225, 95, 158, 227, 103, 8, 194]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'marketType'; + type: { + option: { + defined: { + name: 'marketType'; + }; + }; + }; + }, + { + name: 'marketIndex'; + type: { + option: 'u16'; + }; + }, + { + name: 'direction'; + type: { + option: { + defined: { + name: 'positionDirection'; + }; + }; + }; + }, + ]; + }, + { + name: 'cancelOrdersByIds'; + discriminator: [134, 19, 144, 165, 94, 240, 210, 94]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'orderIds'; + type: { + vec: 'u32'; + }; + }, + ]; + }, + { + name: 'cancelRequestRemoveInsuranceFundStake'; + discriminator: [97, 235, 78, 62, 212, 42, 241, 127]; + accounts: [ + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['insuranceFundStake', 'userStats']; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'changeApprovedBuilder'; + discriminator: [179, 134, 211, 45, 195, 5, 189, 173]; + accounts: [ + { + name: 'escrow'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [82, 69, 86, 95, 69, 83, 67, 82, 79, 87]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + relations: ['escrow']; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'builder'; + type: 'pubkey'; + }, + { + name: 'maxFeeBps'; + type: 'u16'; + }, + { + name: 'add'; + type: 'bool'; + }, + ]; + }, + { + name: 'changeSignedMsgWsDelegateStatus'; + discriminator: [252, 202, 252, 219, 179, 27, 84, 138]; + accounts: [ + { + name: 'signedMsgWsDelegates'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71, 95, 87, 83]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'delegate'; + type: 'pubkey'; + }, + { + name: 'add'; + type: 'bool'; + }, + ]; + }, + { + name: 'deleteAmmCache'; + discriminator: [216, 130, 215, 206, 233, 232, 191, 88]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'deleteInitializedPerpMarket'; + discriminator: [91, 154, 24, 87, 106, 59, 190, 66]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'deleteInitializedSpotMarket'; + discriminator: [31, 140, 67, 191, 189, 20, 101, 221]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'deletePrelaunchOracle'; + discriminator: [59, 169, 100, 49, 69, 17, 173, 253]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'prelaunchOracle'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101, + ]; + }, + { + kind: 'arg'; + path: 'perpMarketIndex'; + }, + ]; + }; + }, + { + name: 'perpMarket'; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'deleteSignedMsgUserOrders'; + discriminator: [221, 247, 128, 253, 212, 254, 46, 153]; + accounts: [ + { + name: 'signedMsgUserOrders'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: []; + }, + { + name: 'deleteUser'; + discriminator: [186, 85, 17, 249, 219, 231, 98, 251]; + accounts: [ + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'authority'; + writable: true; + signer: true; + relations: ['user', 'userStats']; + }, + ]; + args: []; + }, + { + name: 'deposit'; + discriminator: [242, 35, 198, 137, 82, 225, 242, 182]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + ]; + }, + { + name: 'depositIntoInsuranceFundStake'; + discriminator: [4, 22, 226, 201, 124, 44, 82, 230]; + accounts: [ + { + name: 'signer'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 115, + 116, + 97, + 107, + 101, + ]; + }, + { + kind: 'account'; + path: 'userStats'; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'depositIntoPerpMarketFeePool'; + discriminator: [34, 58, 57, 68, 97, 80, 244, 6]; + accounts: [ + { + name: 'state'; + writable: true; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'sourceVault'; + writable: true; + }, + { + name: 'driftSigner'; + }, + { + name: 'quoteSpotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'depositIntoSpotMarketRevenuePool'; + discriminator: [92, 40, 151, 42, 122, 254, 139, 246]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'account'; + path: 'spotMarket'; + }, + ]; + }; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'depositIntoSpotMarketVault'; + discriminator: [48, 252, 119, 73, 255, 205, 174, 247]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'admin'; + signer: true; + }, + { + name: 'sourceVault'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'depositToProgramVault'; + discriminator: [235, 171, 121, 80, 57, 239, 147, 220]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'constituent'; + writable: true; + }, + { + name: 'constituentTokenAccount'; + writable: true; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'mint'; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'disableUserHighLeverageMode'; + discriminator: [183, 155, 45, 0, 226, 85, 213, 69]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'highLeverageModeConfig'; + writable: true; + }, + ]; + args: [ + { + name: 'disableMaintenance'; + type: 'bool'; + }, + ]; + }, + { + name: 'enableUserHighLeverageMode'; + discriminator: [231, 24, 230, 112, 201, 173, 73, 184]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'highLeverageModeConfig'; + writable: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + ]; + }, + { + name: 'endInsuranceFundSwap'; + discriminator: [206, 230, 98, 8, 249, 158, 169, 167]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'outInsuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inInsuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outTokenAccount'; + writable: true; + }, + { + name: 'inTokenAccount'; + writable: true; + }, + { + name: 'ifRebalanceConfig'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'endLpSwap'; + discriminator: [99, 125, 214, 165, 129, 175, 253, 135]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'signerOutTokenAccount'; + docs: ['Signer token accounts']; + writable: true; + }, + { + name: 'signerInTokenAccount'; + writable: true; + }, + { + name: 'constituentOutTokenAccount'; + docs: ['Constituent token accounts']; + writable: true; + }, + { + name: 'constituentInTokenAccount'; + writable: true; + }, + { + name: 'outConstituent'; + docs: ['Constituents']; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'lpPool'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'endSwap'; + discriminator: [177, 184, 27, 193, 34, 13, 210, 145]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'outSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outTokenAccount'; + writable: true; + }, + { + name: 'inTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'limitPrice'; + type: { + option: 'u64'; + }; + }, + { + name: 'reduceOnly'; + type: { + option: { + defined: { + name: 'swapReduceOnly'; + }; + }; + }; + }, + ]; + }, + { + name: 'fillPerpOrder'; + discriminator: [13, 188, 248, 103, 134, 217, 106, 240]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'fillerStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'orderId'; + type: { + option: 'u32'; + }; + }, + { + name: 'makerOrderId'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'fillSpotOrder'; + discriminator: [212, 206, 130, 173, 21, 34, 199, 40]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'fillerStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'orderId'; + type: { + option: 'u32'; + }; + }, + { + name: 'fulfillmentType'; + type: { + option: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }; + }, + { + name: 'makerOrderId'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'forceCancelOrders'; + discriminator: [64, 181, 196, 63, 222, 72, 64, 232]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'forceDeleteUser'; + discriminator: [2, 241, 195, 172, 227, 24, 254, 158]; + accounts: [ + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'authority'; + writable: true; + relations: ['user', 'userStats']; + }, + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'driftSigner'; + }, + ]; + args: []; + }, + { + name: 'initialize'; + discriminator: [175, 175, 109, 31, 13, 152, 155, 237]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [100, 114, 105, 102, 116, 95, 115, 116, 97, 116, 101]; + }, + ]; + }; + }, + { + name: 'quoteAssetMint'; + }, + { + name: 'driftSigner'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: []; + }, + { + name: 'initializeAmmCache'; + discriminator: [38, 60, 171, 158, 203, 58, 137, 8]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'initializeConstituent'; + discriminator: [12, 196, 45, 218, 93, 89, 0, 33]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + writable: true; + }, + { + name: 'constituentTargetBase'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'constituentCorrelations'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'constituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'spotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'spotMarketMint'; + }, + { + name: 'constituentVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'decimals'; + type: 'u8'; + }, + { + name: 'maxWeightDeviation'; + type: 'i64'; + }, + { + name: 'swapFeeMin'; + type: 'i64'; + }, + { + name: 'swapFeeMax'; + type: 'i64'; + }, + { + name: 'maxBorrowTokenAmount'; + type: 'u64'; + }, + { + name: 'oracleStalenessThreshold'; + type: 'u64'; + }, + { + name: 'costToTrade'; + type: 'i32'; + }, + { + name: 'constituentDerivativeIndex'; + type: { + option: 'i16'; + }; + }, + { + name: 'constituentDerivativeDepegThreshold'; + type: 'u64'; + }, + { + name: 'derivativeWeight'; + type: 'u64'; + }, + { + name: 'volatility'; + type: 'u64'; + }, + { + name: 'gammaExecution'; + type: 'u8'; + }, + { + name: 'gammaInventory'; + type: 'u8'; + }, + { + name: 'xi'; + type: 'u8'; + }, + { + name: 'newConstituentCorrelations'; + type: { + vec: 'i64'; + }; + }, + ]; + }, + { + name: 'initializeFuelOverflow'; + discriminator: [88, 223, 132, 161, 208, 88, 142, 42]; + accounts: [ + { + name: 'fuelOverflow'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 102, + 117, + 101, + 108, + 95, + 111, + 118, + 101, + 114, + 102, + 108, + 111, + 119, + ]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + relations: ['userStats']; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'initializeHighLeverageModeConfig'; + discriminator: [213, 167, 93, 246, 208, 130, 90, 248]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'highLeverageModeConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 104, + 105, + 103, + 104, + 95, + 108, + 101, + 118, + 101, + 114, + 97, + 103, + 101, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + ]; + }, + { + name: 'initializeIfRebalanceConfig'; + discriminator: [8, 85, 184, 167, 176, 61, 173, 226]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'ifRebalanceConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 102, + 95, + 114, + 101, + 98, + 97, + 108, + 97, + 110, + 99, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + { + kind: 'arg'; + path: 'params.in_market_index'; + }, + { + kind: 'arg'; + path: 'params.out_market_index'; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'ifRebalanceConfigParams'; + }; + }; + }, + ]; + }, + { + name: 'initializeInsuranceFundStake'; + discriminator: [187, 179, 243, 70, 248, 90, 92, 147]; + accounts: [ + { + name: 'spotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 115, + 116, + 97, + 107, + 101, + ]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + relations: ['userStats']; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializeLpPool'; + discriminator: [242, 64, 1, 222, 142, 46, 204, 227]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [108, 112, 95, 112, 111, 111, 108]; + }, + { + kind: 'arg'; + path: 'id'; + }, + ]; + }; + }, + { + name: 'mint'; + }, + { + name: 'lpPoolTokenVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'ammConstituentMapping'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [65, 77, 77, 95, 77, 65, 80]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'constituentTargetBase'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'constituentCorrelations'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'tokenProgram'; + address: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'lpPoolId'; + type: 'u8'; + }, + { + name: 'minMintFee'; + type: 'i64'; + }, + { + name: 'maxAum'; + type: 'u128'; + }, + { + name: 'maxSettleQuoteAmountPerMarket'; + type: 'u64'; + }, + { + name: 'whitelistMint'; + type: 'pubkey'; + }, + ]; + }, + { + name: 'initializeOpenbookV2FulfillmentConfig'; + discriminator: [7, 221, 103, 153, 107, 57, 27, 197]; + accounts: [ + { + name: 'baseSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'quoteSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'openbookV2Program'; + }, + { + name: 'openbookV2Market'; + }, + { + name: 'driftSigner'; + }, + { + name: 'openbookV2FulfillmentConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 111, + 112, + 101, + 110, + 98, + 111, + 111, + 107, + 95, + 118, + 50, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + { + kind: 'account'; + path: 'openbookV2Market'; + }, + ]; + }; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializePerpMarket'; + discriminator: [132, 9, 229, 118, 117, 118, 117, 62]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'perpMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [112, 101, 114, 112, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'account'; + path: 'state.number_of_markets'; + account: 'state'; + }, + ]; + }; + }, + { + name: 'oracle'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'ammBaseAssetReserve'; + type: 'u128'; + }, + { + name: 'ammQuoteAssetReserve'; + type: 'u128'; + }, + { + name: 'ammPeriodicity'; + type: 'i64'; + }, + { + name: 'ammPegMultiplier'; + type: 'u128'; + }, + { + name: 'oracleSource'; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'contractTier'; + type: { + defined: { + name: 'contractTier'; + }; + }; + }, + { + name: 'marginRatioInitial'; + type: 'u32'; + }, + { + name: 'marginRatioMaintenance'; + type: 'u32'; + }, + { + name: 'liquidatorFee'; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + type: 'u32'; + }, + { + name: 'imfFactor'; + type: 'u32'; + }, + { + name: 'activeStatus'; + type: 'bool'; + }, + { + name: 'baseSpread'; + type: 'u32'; + }, + { + name: 'maxSpread'; + type: 'u32'; + }, + { + name: 'maxOpenInterest'; + type: 'u128'; + }, + { + name: 'maxRevenueWithdrawPerPeriod'; + type: 'u64'; + }, + { + name: 'quoteMaxInsurance'; + type: 'u64'; + }, + { + name: 'orderStepSize'; + type: 'u64'; + }, + { + name: 'orderTickSize'; + type: 'u64'; + }, + { + name: 'minOrderSize'; + type: 'u64'; + }, + { + name: 'concentrationCoefScale'; + type: 'u128'; + }, + { + name: 'curveUpdateIntensity'; + type: 'u8'; + }, + { + name: 'ammJitIntensity'; + type: 'u8'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'lpPoolId'; + type: 'u8'; + }, + ]; + }, + { + name: 'initializePhoenixFulfillmentConfig'; + discriminator: [135, 132, 110, 107, 185, 160, 169, 154]; + accounts: [ + { + name: 'baseSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'quoteSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'phoenixProgram'; + }, + { + name: 'phoenixMarket'; + }, + { + name: 'driftSigner'; + }, + { + name: 'phoenixFulfillmentConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 104, + 111, + 101, + 110, + 105, + 120, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + { + kind: 'account'; + path: 'phoenixMarket'; + }, + ]; + }; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializePredictionMarket'; + discriminator: [248, 70, 198, 224, 224, 105, 125, 195]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'initializePrelaunchOracle'; + discriminator: [169, 178, 84, 25, 175, 62, 29, 247]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'prelaunchOracle'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101, + ]; + }, + { + kind: 'arg'; + path: 'params.perp_market_index'; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'prelaunchOracleParams'; + }; + }; + }, + ]; + }, + { + name: 'initializeProtectedMakerModeConfig'; + discriminator: [67, 103, 220, 67, 88, 32, 252, 8]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'protectedMakerModeConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 114, + 111, + 116, + 101, + 99, + 116, + 101, + 100, + 95, + 109, + 97, + 107, + 101, + 114, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + ]; + }, + { + name: 'initializePythLazerOracle'; + discriminator: [140, 107, 33, 214, 235, 219, 103, 20]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lazerOracle'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [112, 121, 116, 104, 95, 108, 97, 122, 101, 114]; + }, + { + kind: 'arg'; + path: 'feedId'; + }, + ]; + }; + }, + { + name: 'state'; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'feedId'; + type: 'u32'; + }, + ]; + }, + { + name: 'initializePythPullOracle'; + discriminator: [249, 140, 253, 243, 248, 74, 240, 238]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'pythSolanaReceiver'; + address: 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha'; + }, + { + name: 'priceFeed'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [112, 121, 116, 104, 95, 112, 117, 108, 108]; + }, + { + kind: 'arg'; + path: 'feedId'; + }, + ]; + }; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'feedId'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'initializeReferrerName'; + discriminator: [235, 126, 231, 10, 42, 164, 26, 61]; + accounts: [ + { + name: 'referrerName'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 114, + 101, + 102, + 101, + 114, + 114, + 101, + 114, + 95, + 110, + 97, + 109, + 101, + ]; + }, + { + kind: 'arg'; + path: 'name'; + }, + ]; + }; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'initializeRevenueShare'; + discriminator: [57, 9, 123, 131, 82, 52, 50, 13]; + accounts: [ + { + name: 'revenueShare'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [82, 69, 86, 95, 83, 72, 65, 82, 69]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'initializeRevenueShareEscrow'; + discriminator: [187, 18, 123, 88, 238, 104, 84, 154]; + accounts: [ + { + name: 'escrow'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [82, 69, 86, 95, 69, 83, 67, 82, 79, 87]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + relations: ['userStats']; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'numOrders'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializeSerumFulfillmentConfig'; + discriminator: [193, 211, 132, 172, 70, 171, 7, 94]; + accounts: [ + { + name: 'baseSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'quoteSpotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'serumProgram'; + }, + { + name: 'serumMarket'; + }, + { + name: 'serumOpenOrders'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 101, + 114, + 117, + 109, + 95, + 111, + 112, + 101, + 110, + 95, + 111, + 114, + 100, + 101, + 114, + 115, + ]; + }, + { + kind: 'account'; + path: 'serumMarket'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'serumFulfillmentConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 101, + 114, + 117, + 109, + 95, + 102, + 117, + 108, + 102, + 105, + 108, + 108, + 109, + 101, + 110, + 116, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + { + kind: 'account'; + path: 'serumMarket'; + }, + ]; + }; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializeSignedMsgUserOrders'; + discriminator: [164, 99, 156, 126, 156, 57, 99, 180]; + accounts: [ + { + name: 'signedMsgUserOrders'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'numOrders'; + type: 'u16'; + }, + ]; + }, + { + name: 'initializeSignedMsgWsDelegates'; + discriminator: [40, 132, 96, 219, 184, 193, 80, 8]; + accounts: [ + { + name: 'signedMsgWsDelegates'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71, 95, 87, 83]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'delegates'; + type: { + vec: 'pubkey'; + }; + }, + ]; + }, + { + name: 'initializeSpotMarket'; + discriminator: [234, 196, 128, 44, 94, 15, 48, 201]; + accounts: [ + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'account'; + path: 'state.number_of_spot_markets'; + account: 'state'; + }, + ]; + }; + }, + { + name: 'spotMarketMint'; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'account'; + path: 'state.number_of_spot_markets'; + account: 'state'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'account'; + path: 'state.number_of_spot_markets'; + account: 'state'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'optimalUtilization'; + type: 'u32'; + }, + { + name: 'optimalBorrowRate'; + type: 'u32'; + }, + { + name: 'maxBorrowRate'; + type: 'u32'; + }, + { + name: 'oracleSource'; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'initialAssetWeight'; + type: 'u32'; + }, + { + name: 'maintenanceAssetWeight'; + type: 'u32'; + }, + { + name: 'initialLiabilityWeight'; + type: 'u32'; + }, + { + name: 'maintenanceLiabilityWeight'; + type: 'u32'; + }, + { + name: 'imfFactor'; + type: 'u32'; + }, + { + name: 'liquidatorFee'; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + type: 'u32'; + }, + { + name: 'activeStatus'; + type: 'bool'; + }, + { + name: 'assetTier'; + type: { + defined: { + name: 'assetTier'; + }; + }; + }, + { + name: 'scaleInitialAssetWeightStart'; + type: 'u64'; + }, + { + name: 'withdrawGuardThreshold'; + type: 'u64'; + }, + { + name: 'orderTickSize'; + type: 'u64'; + }, + { + name: 'orderStepSize'; + type: 'u64'; + }, + { + name: 'ifTotalFactor'; + type: 'u32'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'initializeUser'; + discriminator: [111, 17, 185, 250, 60, 122, 38, 254]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['userStats']; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'initializeUserStats'; + discriminator: [254, 243, 72, 98, 251, 130, 168, 213]; + accounts: [ + { + name: 'userStats'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114, 95, 115, 116, 97, 116, 115]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'state'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'liquidateBorrowForPerpPnl'; + discriminator: [169, 17, 32, 90, 207, 148, 209, 27]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'liquidatorMaxLiabilityTransfer'; + type: 'u128'; + }, + { + name: 'limitPrice'; + type: { + option: 'u64'; + }; + }, + ]; + }, + { + name: 'liquidatePerp'; + discriminator: [75, 35, 119, 247, 191, 18, 139, 2]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'liquidatorMaxBaseAssetAmount'; + type: 'u64'; + }, + { + name: 'limitPrice'; + type: { + option: 'u64'; + }; + }, + ]; + }, + { + name: 'liquidatePerpPnlForDeposit'; + discriminator: [237, 75, 198, 235, 233, 186, 75, 35]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'liquidatorMaxPnlTransfer'; + type: 'u128'; + }, + { + name: 'limitPrice'; + type: { + option: 'u64'; + }; + }, + ]; + }, + { + name: 'liquidatePerpWithFill'; + discriminator: [95, 111, 124, 105, 86, 169, 187, 34]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'liquidateSpot'; + discriminator: [107, 0, 128, 41, 35, 229, 251, 18]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: [ + { + name: 'assetMarketIndex'; + type: 'u16'; + }, + { + name: 'liabilityMarketIndex'; + type: 'u16'; + }, + { + name: 'liquidatorMaxLiabilityTransfer'; + type: 'u128'; + }, + { + name: 'limitPrice'; + type: { + option: 'u64'; + }; + }, + ]; + }, + { + name: 'liquidateSpotWithSwapBegin'; + discriminator: [12, 43, 176, 83, 156, 251, 117, 13]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'liabilitySpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'liabilityMarketIndex'; + }, + ]; + }; + }, + { + name: 'assetSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'assetMarketIndex'; + }, + ]; + }; + }, + { + name: 'liabilityTokenAccount'; + writable: true; + }, + { + name: 'assetTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'assetMarketIndex'; + type: 'u16'; + }, + { + name: 'liabilityMarketIndex'; + type: 'u16'; + }, + { + name: 'swapAmount'; + type: 'u64'; + }, + ]; + }, + { + name: 'liquidateSpotWithSwapEnd'; + discriminator: [142, 88, 163, 160, 223, 75, 55, 225]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'liabilitySpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'liabilityMarketIndex'; + }, + ]; + }; + }, + { + name: 'assetSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'assetMarketIndex'; + }, + ]; + }; + }, + { + name: 'liabilityTokenAccount'; + writable: true; + }, + { + name: 'assetTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + { + name: 'instructions'; + docs: ['Instructions Sysvar for instruction introspection']; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'assetMarketIndex'; + type: 'u16'; + }, + { + name: 'liabilityMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'logUserBalances'; + discriminator: [162, 21, 35, 251, 32, 57, 161, 210]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'user'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'lpPoolAddLiquidity'; + discriminator: [49, 135, 246, 103, 93, 146, 220, 141]; + accounts: [ + { + name: 'state'; + }, + { + name: 'lpPool'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'inMarketMint'; + }, + { + name: 'inConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'userInTokenAccount'; + writable: true; + }, + { + name: 'constituentInTokenAccount'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'userLpTokenAccount'; + writable: true; + }, + { + name: 'lpMint'; + writable: true; + }, + { + name: 'constituentTargetBase'; + }, + { + name: 'lpPoolTokenVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u128'; + }, + { + name: 'minMintAmount'; + type: 'u64'; + }, + ]; + }, + { + name: 'lpPoolRemoveLiquidity'; + discriminator: [164, 36, 193, 252, 196, 157, 138, 43]; + accounts: [ + { + name: 'state'; + }, + { + name: 'driftSigner'; + }, + { + name: 'lpPool'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'outMarketMint'; + }, + { + name: 'outConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'userOutTokenAccount'; + writable: true; + }, + { + name: 'constituentOutTokenAccount'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 67, + 79, + 78, + 83, + 84, + 73, + 84, + 85, + 69, + 78, + 84, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'userLpTokenAccount'; + writable: true; + }, + { + name: 'spotMarketTokenAccount'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'lpMint'; + writable: true; + }, + { + name: 'constituentTargetBase'; + }, + { + name: 'lpPoolTokenVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 76, + 80, + 95, + 80, + 79, + 79, + 76, + 95, + 84, + 79, + 75, + 69, + 78, + 95, + 86, + 65, + 85, + 76, + 84, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'tokenProgram'; + }, + { + name: 'ammCache'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u64'; + }, + { + name: 'minOutAmount'; + type: 'u128'; + }, + ]; + }, + { + name: 'lpPoolSwap'; + discriminator: [36, 161, 39, 49, 227, 1, 35, 226]; + accounts: [ + { + name: 'state'; + }, + { + name: 'lpPool'; + }, + { + name: 'constituentTargetBase'; + }, + { + name: 'constituentCorrelations'; + }, + { + name: 'constituentInTokenAccount'; + writable: true; + }, + { + name: 'constituentOutTokenAccount'; + writable: true; + }, + { + name: 'userInTokenAccount'; + writable: true; + }, + { + name: 'userOutTokenAccount'; + writable: true; + }, + { + name: 'inConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'inMarketMint'; + }, + { + name: 'outMarketMint'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u64'; + }, + { + name: 'minOutAmount'; + type: 'u64'; + }, + ]; + }, + { + name: 'modifyOrder'; + discriminator: [47, 124, 117, 255, 201, 197, 130, 94]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'orderId'; + type: { + option: 'u32'; + }; + }, + { + name: 'modifyOrderParams'; + type: { + defined: { + name: 'modifyOrderParams'; + }; + }; + }, + ]; + }, + { + name: 'modifyOrderByUserId'; + discriminator: [158, 77, 4, 253, 252, 194, 161, 179]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'userOrderId'; + type: 'u8'; + }, + { + name: 'modifyOrderParams'; + type: { + defined: { + name: 'modifyOrderParams'; + }; + }; + }, + ]; + }, + { + name: 'moveAmmPrice'; + discriminator: [235, 109, 2, 82, 219, 118, 6, 159]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'baseAssetReserve'; + type: 'u128'; + }, + { + name: 'quoteAssetReserve'; + type: 'u128'; + }, + { + name: 'sqrtK'; + type: 'u128'; + }, + ]; + }, + { + name: 'openbookV2FulfillmentConfigStatus'; + discriminator: [25, 173, 19, 189, 4, 211, 64, 238]; + accounts: [ + { + name: 'state'; + }, + { + name: 'openbookV2FulfillmentConfig'; + writable: true; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + ]; + args: [ + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + ]; + }, + { + name: 'overrideAmmCacheInfo'; + discriminator: [189, 198, 128, 9, 49, 145, 201, 115]; + accounts: [ + { + name: 'state'; + writable: true; + }, + { + name: 'admin'; + signer: true; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'overrideParams'; + type: { + defined: { + name: 'overrideAmmCacheParams'; + }; + }; + }, + ]; + }, + { + name: 'pauseSpotMarketDepositWithdraw'; + discriminator: [183, 119, 59, 170, 137, 35, 242, 86]; + accounts: [ + { + name: 'state'; + }, + { + name: 'keeper'; + signer: true; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'spotMarketVault'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'account'; + path: 'spotMarket'; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'phoenixFulfillmentConfigStatus'; + discriminator: [96, 31, 113, 32, 12, 203, 7, 154]; + accounts: [ + { + name: 'state'; + }, + { + name: 'phoenixFulfillmentConfig'; + writable: true; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + ]; + args: [ + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + ]; + }, + { + name: 'placeAndMakePerpOrder'; + discriminator: [149, 117, 11, 237, 47, 95, 89, 237]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'taker'; + writable: true; + }, + { + name: 'takerStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'takerOrderId'; + type: 'u32'; + }, + ]; + }, + { + name: 'placeAndMakeSignedMsgPerpOrder'; + discriminator: [16, 26, 123, 131, 94, 29, 175, 98]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'taker'; + writable: true; + }, + { + name: 'takerStats'; + writable: true; + }, + { + name: 'takerSignedMsgUserOrders'; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71]; + }, + { + kind: 'account'; + path: 'taker'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'signedMsgOrderUuid'; + type: { + array: ['u8', 8]; + }; + }, + ]; + }, + { + name: 'placeAndMakeSpotOrder'; + discriminator: [149, 158, 85, 66, 239, 9, 243, 98]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'taker'; + writable: true; + }, + { + name: 'takerStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'takerOrderId'; + type: 'u32'; + }, + { + name: 'fulfillmentType'; + type: { + option: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }; + }, + ]; + }, + { + name: 'placeAndTakePerpOrder'; + discriminator: [213, 51, 1, 187, 108, 220, 230, 224]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'successCondition'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'placeAndTakeSpotOrder'; + discriminator: [191, 3, 138, 71, 114, 198, 202, 100]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'fulfillmentType'; + type: { + option: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }; + }, + { + name: 'makerOrderId'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'placeOrders'; + discriminator: [60, 63, 50, 123, 12, 197, 60, 190]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + vec: { + defined: { + name: 'orderParams'; + }; + }; + }; + }, + ]; + }, + { + name: 'placePerpOrder'; + discriminator: [69, 161, 93, 202, 120, 126, 76, 185]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + ]; + }, + { + name: 'placeSignedMsgTakerOrder'; + discriminator: [32, 79, 101, 139, 25, 6, 98, 15]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'signedMsgUserOrders'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71]; + }, + { + kind: 'account'; + path: 'user'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'ixSysvar'; + docs: [ + 'the supplied Sysvar could be anything else.', + 'The Instruction Sysvar has not been implemented', + 'in the Anchor framework yet, so this is the safe approach.', + ]; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'signedMsgOrderParamsMessageBytes'; + type: 'bytes'; + }, + { + name: 'isDelegateSigner'; + type: 'bool'; + }, + ]; + }, + { + name: 'placeSpotOrder'; + discriminator: [45, 79, 81, 160, 248, 90, 91, 220]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + ]; + }, + { + name: 'postMultiPythPullOracleUpdatesAtomic'; + discriminator: [243, 79, 204, 228, 227, 208, 100, 244]; + accounts: [ + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'pythSolanaReceiver'; + address: 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha'; + }, + { + name: 'guardianSet'; + }, + ]; + args: [ + { + name: 'params'; + type: 'bytes'; + }, + ]; + }, + { + name: 'postPythLazerOracleUpdate'; + discriminator: [218, 237, 170, 245, 39, 143, 166, 33]; + accounts: [ + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'pythLazerStorage'; + address: '3rdJbqfnagQ4yx9HXJViD4zc4xpiSqmFsKpPuSCQVyQL'; + }, + { + name: 'ixSysvar'; + address: 'Sysvar1nstructions1111111111111111111111111'; + }, + ]; + args: [ + { + name: 'pythMessage'; + type: 'bytes'; + }, + ]; + }, + { + name: 'postPythPullOracleUpdateAtomic'; + discriminator: [116, 122, 137, 158, 224, 195, 173, 119]; + accounts: [ + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'pythSolanaReceiver'; + address: 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha'; + }, + { + name: 'guardianSet'; + }, + { + name: 'priceFeed'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [112, 121, 116, 104, 95, 112, 117, 108, 108]; + }, + { + kind: 'arg'; + path: 'feedId'; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'feedId'; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'params'; + type: 'bytes'; + }, + ]; + }, + { + name: 'recenterPerpMarketAmm'; + discriminator: [24, 87, 10, 115, 165, 190, 80, 139]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'pegMultiplier'; + type: 'u128'; + }, + { + name: 'sqrtK'; + type: 'u128'; + }, + ]; + }, + { + name: 'recenterPerpMarketAmmCrank'; + discriminator: [166, 19, 64, 10, 14, 51, 101, 122]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'spotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'account'; + path: 'perpMarket'; + }, + ]; + }; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'depth'; + type: { + option: 'u128'; + }; + }, + ]; + }, + { + name: 'reclaimRent'; + discriminator: [218, 200, 19, 197, 227, 89, 192, 22]; + accounts: [ + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + relations: ['user', 'userStats']; + }, + { + name: 'rent'; + address: 'SysvarRent111111111111111111111111111111111'; + }, + ]; + args: []; + }, + { + name: 'removeAmmConstituentMappingData'; + discriminator: [20, 183, 211, 162, 16, 52, 229, 115]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + }, + { + name: 'ammConstituentMapping'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [65, 77, 77, 95, 77, 65, 80]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'constituentIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'removeInsuranceFundStake'; + discriminator: [128, 166, 142, 9, 254, 187, 143, 174]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['insuranceFundStake', 'userStats']; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'repegAmmCurve'; + discriminator: [3, 36, 102, 89, 180, 128, 120, 213]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + ]; + args: [ + { + name: 'newPegCandidate'; + type: 'u128'; + }, + ]; + }, + { + name: 'requestRemoveInsuranceFundStake'; + discriminator: [142, 70, 204, 92, 73, 106, 180, 52]; + accounts: [ + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['insuranceFundStake', 'userStats']; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'resetFuelSeason'; + discriminator: [199, 122, 192, 255, 32, 99, 63, 200]; + accounts: [ + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + relations: ['userStats']; + }, + { + name: 'state'; + }, + { + name: 'admin'; + signer: true; + }, + ]; + args: []; + }, + { + name: 'resetPerpMarketAmmOracleTwap'; + discriminator: [127, 10, 55, 164, 123, 226, 47, 24]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + ]; + args: []; + }, + { + name: 'resizeRevenueShareEscrowOrders'; + discriminator: [32, 124, 247, 225, 151, 213, 225, 38]; + accounts: [ + { + name: 'escrow'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [82, 69, 86, 95, 69, 83, 67, 82, 79, 87]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + relations: ['escrow']; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'numOrders'; + type: 'u16'; + }, + ]; + }, + { + name: 'resizeSignedMsgUserOrders'; + discriminator: [137, 10, 87, 150, 18, 115, 79, 168]; + accounts: [ + { + name: 'signedMsgUserOrders'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [83, 73, 71, 78, 69, 68, 95, 77, 83, 71]; + }, + { + kind: 'account'; + path: 'authority'; + }, + ]; + }; + }, + { + name: 'authority'; + relations: ['user']; + }, + { + name: 'user'; + }, + { + name: 'payer'; + writable: true; + signer: true; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + ]; + args: [ + { + name: 'numOrders'; + type: 'u16'; + }, + ]; + }, + { + name: 'resolvePerpBankruptcy'; + discriminator: [224, 16, 176, 214, 162, 213, 183, 222]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'quoteSpotMarketIndex'; + type: 'u16'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'resolvePerpPnlDeficit'; + discriminator: [168, 204, 68, 150, 159, 126, 95, 148]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'resolveSpotBankruptcy'; + discriminator: [124, 194, 240, 254, 198, 213, 52, 122]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'liquidator'; + writable: true; + }, + { + name: 'liquidatorStats'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'spotMarketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'revertFill'; + discriminator: [236, 238, 176, 69, 239, 10, 181, 193]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'fillerStats'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'setUserStatusToBeingLiquidated'; + discriminator: [106, 133, 160, 206, 193, 171, 192, 194]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: []; + }, + { + name: 'settleExpiredMarket'; + discriminator: [120, 89, 11, 25, 122, 77, 72, 193]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'settleExpiredMarketPoolsToRevenuePool'; + discriminator: [55, 19, 238, 169, 227, 90, 200, 184]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'settleFundingPayment'; + discriminator: [222, 90, 202, 94, 28, 45, 115, 183]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'settleMultiplePnls'; + discriminator: [127, 66, 117, 57, 40, 50, 152, 127]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'spotMarketVault'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndexes'; + type: { + vec: 'u16'; + }; + }, + { + name: 'mode'; + type: { + defined: { + name: 'settlePnlMode'; + }; + }; + }, + ]; + }, + { + name: 'settlePerpToLpPool'; + discriminator: [5, 98, 46, 188, 10, 59, 2, 249]; + accounts: [ + { + name: 'state'; + }, + { + name: 'lpPool'; + writable: true; + }, + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'ammCache'; + writable: true; + }, + { + name: 'quoteMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'constituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'constituentQuoteTokenAccount'; + writable: true; + }, + { + name: 'quoteTokenVault'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + ]; + args: []; + }, + { + name: 'settlePnl'; + discriminator: [43, 61, 234, 45, 15, 95, 152, 153]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'spotMarketVault'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'settleRevenueToInsuranceFund'; + discriminator: [200, 120, 93, 136, 69, 38, 199, 159]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'sweepFuel'; + discriminator: [175, 107, 19, 56, 165, 241, 43, 69]; + accounts: [ + { + name: 'fuelOverflow'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + relations: ['fuelOverflow', 'userStats']; + }, + { + name: 'signer'; + signer: true; + }, + ]; + args: []; + }, + { + name: 'transferDeposit'; + discriminator: [20, 20, 147, 223, 41, 63, 204, 111]; + accounts: [ + { + name: 'fromUser'; + writable: true; + }, + { + name: 'toUser'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['fromUser', 'toUser', 'userStats']; + }, + { + name: 'state'; + }, + { + name: 'spotMarketVault'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'transferPerpPosition'; + discriminator: [23, 172, 188, 168, 134, 210, 3, 108]; + accounts: [ + { + name: 'fromUser'; + writable: true; + }, + { + name: 'toUser'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: { + option: 'i64'; + }; + }, + ]; + }, + { + name: 'transferPools'; + discriminator: [197, 103, 154, 25, 107, 90, 60, 94]; + accounts: [ + { + name: 'fromUser'; + writable: true; + }, + { + name: 'toUser'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['fromUser', 'toUser', 'userStats']; + }, + { + name: 'state'; + }, + { + name: 'depositFromSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'depositFromMarketIndex'; + }, + ]; + }; + }, + { + name: 'depositToSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'depositToMarketIndex'; + }, + ]; + }; + }, + { + name: 'borrowFromSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'borrowFromMarketIndex'; + }, + ]; + }; + }, + { + name: 'borrowToSpotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'borrowToMarketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + ]; + args: [ + { + name: 'depositFromMarketIndex'; + type: 'u16'; + }, + { + name: 'depositToMarketIndex'; + type: 'u16'; + }, + { + name: 'borrowFromMarketIndex'; + type: 'u16'; + }, + { + name: 'borrowToMarketIndex'; + type: 'u16'; + }, + { + name: 'depositAmount'; + type: { + option: 'u64'; + }; + }, + { + name: 'borrowAmount'; + type: { + option: 'u64'; + }; + }, + ]; + }, + { + name: 'transferProtocolIfSharesToRevenuePool'; + discriminator: [236, 136, 147, 153, 146, 205, 104, 29]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + writable: true; + signer: true; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'ifRebalanceConfig'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'driftSigner'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'triggerOrder'; + discriminator: [63, 112, 51, 233, 232, 47, 240, 199]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + ]; + args: [ + { + name: 'orderId'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateAdmin'; + discriminator: [161, 176, 40, 213, 60, 184, 179, 228]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'admin'; + type: 'pubkey'; + }, + ]; + }, + { + name: 'updateAmmCache'; + discriminator: [88, 4, 63, 94, 83, 224, 255, 130]; + accounts: [ + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'ammCache'; + writable: true; + }, + { + name: 'quoteMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'updateAmmConstituentMappingData'; + discriminator: [84, 70, 33, 167, 133, 107, 59, 24]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + }, + { + name: 'ammConstituentMapping'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [65, 77, 77, 95, 77, 65, 80]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'systemProgram'; + address: '11111111111111111111111111111111'; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'ammConstituentMappingData'; + type: { + vec: { + defined: { + name: 'addAmmConstituentMappingDatum'; + }; + }; + }; + }, + ]; + }, + { + name: 'updateAmmJitIntensity'; + discriminator: [181, 191, 53, 109, 166, 249, 55, 142]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'ammJitIntensity'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateAmms'; + discriminator: [201, 106, 217, 253, 4, 175, 228, 97]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'marketIndexes'; + type: { + vec: 'u16'; + }; + }, + ]; + }, + { + name: 'updateConstituentCorrelationData'; + discriminator: [79, 14, 19, 73, 221, 106, 62, 109]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + }, + { + name: 'constituentCorrelations'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 99, + 111, + 114, + 114, + 101, + 108, + 97, + 116, + 105, + 111, + 110, + 115, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'index1'; + type: 'u16'; + }, + { + name: 'index2'; + type: 'u16'; + }, + { + name: 'correlation'; + type: 'i64'; + }, + ]; + }, + { + name: 'updateConstituentOracleInfo'; + discriminator: [198, 117, 231, 250, 147, 33, 127, 161]; + accounts: [ + { + name: 'state'; + }, + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'constituent'; + writable: true; + }, + { + name: 'spotMarket'; + }, + { + name: 'oracle'; + }, + ]; + args: []; + }, + { + name: 'updateConstituentParams'; + discriminator: [238, 130, 122, 31, 12, 104, 192, 122]; + accounts: [ + { + name: 'lpPool'; + }, + { + name: 'constituentTargetBase'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 99, + 111, + 110, + 115, + 116, + 105, + 116, + 117, + 101, + 110, + 116, + 95, + 116, + 97, + 114, + 103, + 101, + 116, + 95, + 98, + 97, + 115, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + ]; + }; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'constituent'; + writable: true; + }, + ]; + args: [ + { + name: 'constituentParams'; + type: { + defined: { + name: 'constituentParams'; + }; + }; + }, + ]; + }, + { + name: 'updateConstituentPausedOperations'; + discriminator: [185, 122, 153, 191, 131, 177, 132, 208]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'constituent'; + writable: true; + }, + ]; + args: [ + { + name: 'pausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateConstituentStatus'; + discriminator: [76, 159, 211, 239, 182, 214, 6, 15]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'constituent'; + writable: true; + }, + ]; + args: [ + { + name: 'newStatus'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateDelegateUserGovTokenInsuranceStake'; + discriminator: [241, 29, 215, 228, 142, 116, 22, 160]; + accounts: [ + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [15, 0]; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [15, 0]; + }, + ]; + }; + }, + { + name: 'state'; + }, + ]; + args: []; + }, + { + name: 'updateDiscountMint'; + discriminator: [32, 252, 122, 211, 66, 31, 47, 241]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'discountMint'; + type: 'pubkey'; + }, + ]; + }, + { + name: 'updateExchangeStatus'; + discriminator: [83, 160, 252, 250, 129, 116, 49, 223]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'exchangeStatus'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsBuilderCodes'; + discriminator: [1, 128, 177, 51, 173, 45, 11, 102]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsMedianTriggerPrice'; + discriminator: [64, 185, 221, 45, 87, 147, 12, 19]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsMintRedeemLpPool'; + discriminator: [26, 11, 142, 122, 206, 159, 9, 45]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsMmOracle'; + discriminator: [218, 134, 33, 186, 231, 59, 130, 149]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsSettleLpPool'; + discriminator: [186, 28, 78, 230, 155, 83, 242, 26]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFeatureBitFlagsSwapLpPool'; + discriminator: [83, 16, 150, 12, 102, 3, 22, 58]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'enable'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateFundingRate'; + discriminator: [201, 178, 116, 212, 166, 144, 72, 238]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateHighLeverageModeConfig'; + discriminator: [64, 122, 212, 93, 141, 217, 202, 55]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'highLeverageModeConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 104, + 105, + 103, + 104, + 95, + 108, + 101, + 118, + 101, + 114, + 97, + 103, + 101, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + ]; + }; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + { + name: 'currentUsers'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'updateIfRebalanceConfig'; + discriminator: [142, 245, 249, 66, 249, 181, 22, 83]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'ifRebalanceConfig'; + writable: true; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'ifRebalanceConfigParams'; + }; + }; + }, + ]; + }, + { + name: 'updateInitialAmmCacheInfo'; + discriminator: [157, 210, 109, 67, 212, 170, 12, 107]; + accounts: [ + { + name: 'state'; + writable: true; + }, + { + name: 'admin'; + signer: true; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'updateInitialPctToLiquidate'; + discriminator: [210, 133, 225, 128, 194, 50, 13, 109]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'initialPctToLiquidate'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateInsuranceFundUnstakingPeriod'; + discriminator: [44, 69, 43, 226, 204, 223, 202, 52]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'insuranceFundUnstakingPeriod'; + type: 'i64'; + }, + ]; + }, + { + name: 'updateK'; + discriminator: [72, 98, 9, 139, 129, 229, 172, 56]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'sqrtK'; + type: 'u128'; + }, + ]; + }, + { + name: 'updateLiquidationDuration'; + discriminator: [28, 154, 20, 249, 102, 192, 73, 71]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'liquidationDuration'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateLiquidationMarginBufferRatio'; + discriminator: [132, 224, 243, 160, 154, 82, 97, 215]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'liquidationMarginBufferRatio'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateLpConstituentTargetBase'; + discriminator: [157, 65, 50, 207, 59, 236, 161, 110]; + accounts: [ + { + name: 'state'; + }, + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'ammConstituentMapping'; + }, + { + name: 'constituentTargetBase'; + writable: true; + }, + { + name: 'ammCache'; + }, + { + name: 'lpPool'; + }, + ]; + args: []; + }, + { + name: 'updateLpPoolAum'; + discriminator: [88, 113, 137, 206, 246, 247, 171, 142]; + accounts: [ + { + name: 'state'; + }, + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'lpPool'; + writable: true; + }, + { + name: 'constituentTargetBase'; + writable: true; + }, + { + name: 'ammCache'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'updateLpPoolParams'; + discriminator: [217, 92, 2, 255, 27, 167, 178, 81]; + accounts: [ + { + name: 'lpPool'; + writable: true; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'lpPoolParams'; + type: { + defined: { + name: 'lpPoolParams'; + }; + }; + }, + ]; + }, + { + name: 'updateOracleGuardRails'; + discriminator: [131, 112, 10, 59, 32, 54, 40, 164]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'oracleGuardRails'; + type: { + defined: { + name: 'oracleGuardRails'; + }; + }; + }, + ]; + }, + { + name: 'updatePerpAuctionDuration'; + discriminator: [126, 110, 52, 174, 30, 206, 215, 90]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'minPerpAuctionDuration'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpBidAskTwap'; + discriminator: [247, 23, 255, 65, 212, 90, 221, 194]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'keeperStats'; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: []; + }, + { + name: 'updatePerpFeeStructure'; + discriminator: [23, 178, 111, 203, 73, 22, 140, 75]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'feeStructure'; + type: { + defined: { + name: 'feeStructure'; + }; + }; + }, + ]; + }, + { + name: 'updatePerpMarketAmmOracleTwap'; + discriminator: [241, 74, 114, 123, 206, 153, 24, 202]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + ]; + args: []; + }, + { + name: 'updatePerpMarketAmmSpreadAdjustment'; + discriminator: [155, 195, 149, 43, 220, 82, 173, 205]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'ammSpreadAdjustment'; + type: 'i8'; + }, + { + name: 'ammInventorySpreadAdjustment'; + type: 'i8'; + }, + { + name: 'referencePriceOffset'; + type: 'i32'; + }, + ]; + }, + { + name: 'updatePerpMarketAmmSummaryStats'; + discriminator: [122, 101, 249, 238, 209, 9, 241, 245]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'spotMarket'; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'account'; + path: 'perpMarket'; + }, + ]; + }; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'updatePerpMarketSummaryStatsParams'; + }; + }; + }, + ]; + }, + { + name: 'updatePerpMarketBaseSpread'; + discriminator: [71, 95, 84, 168, 9, 157, 198, 65]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'baseSpread'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePerpMarketConcentrationCoef'; + discriminator: [24, 78, 232, 126, 169, 176, 230, 16]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'concentrationScale'; + type: 'u128'; + }, + ]; + }, + { + name: 'updatePerpMarketContractTier'; + discriminator: [236, 128, 15, 95, 203, 214, 68, 117]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'contractTier'; + type: { + defined: { + name: 'contractTier'; + }; + }; + }, + ]; + }, + { + name: 'updatePerpMarketCurveUpdateIntensity'; + discriminator: [50, 131, 6, 156, 226, 231, 189, 72]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'curveUpdateIntensity'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketExpiry'; + discriminator: [44, 221, 227, 151, 131, 140, 22, 110]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'expiryTs'; + type: 'i64'; + }, + ]; + }, + { + name: 'updatePerpMarketFeeAdjustment'; + discriminator: [194, 174, 87, 102, 43, 148, 32, 112]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'feeAdjustment'; + type: 'i16'; + }, + ]; + }, + { + name: 'updatePerpMarketFundingPeriod'; + discriminator: [171, 161, 69, 91, 129, 139, 161, 28]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'fundingPeriod'; + type: 'i64'; + }, + ]; + }, + { + name: 'updatePerpMarketHighLeverageMarginRatio'; + discriminator: [88, 112, 86, 49, 24, 116, 74, 157]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'marginRatioInitial'; + type: 'u16'; + }, + { + name: 'marginRatioMaintenance'; + type: 'u16'; + }, + ]; + }, + { + name: 'updatePerpMarketImfFactor'; + discriminator: [207, 194, 56, 132, 35, 67, 71, 244]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'imfFactor'; + type: 'u32'; + }, + { + name: 'unrealizedPnlImfFactor'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePerpMarketLiquidationFee'; + discriminator: [90, 137, 9, 145, 41, 8, 148, 117]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'liquidatorFee'; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePerpMarketLpPoolFeeTransferScalar'; + discriminator: [94, 228, 237, 109, 100, 185, 4, 81]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'optionalLpFeeTransferScalar'; + type: { + option: 'u8'; + }; + }, + { + name: 'optionalLpNetPnlTransferScalar'; + type: { + option: 'u8'; + }; + }, + ]; + }, + { + name: 'updatePerpMarketLpPoolId'; + discriminator: [119, 208, 154, 88, 165, 92, 21, 188]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'lpPoolId'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketLpPoolPausedOperations'; + discriminator: [181, 94, 93, 146, 51, 89, 32, 135]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'lpPausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketLpPoolStatus'; + discriminator: [67, 6, 252, 61, 54, 88, 89, 233]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'lpStatus'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketMarginRatio'; + discriminator: [130, 173, 107, 45, 119, 105, 26, 113]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'marginRatioInitial'; + type: 'u32'; + }, + { + name: 'marginRatioMaintenance'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePerpMarketMaxFillReserveFraction'; + discriminator: [19, 172, 114, 154, 42, 135, 161, 133]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxFillReserveFraction'; + type: 'u16'; + }, + ]; + }, + { + name: 'updatePerpMarketMaxImbalances'; + discriminator: [15, 206, 73, 133, 60, 8, 86, 89]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'unrealizedMaxImbalance'; + type: 'u64'; + }, + { + name: 'maxRevenueWithdrawPerPeriod'; + type: 'u64'; + }, + { + name: 'quoteMaxInsurance'; + type: 'u64'; + }, + ]; + }, + { + name: 'updatePerpMarketMaxOpenInterest'; + discriminator: [194, 79, 149, 224, 246, 102, 186, 140]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxOpenInterest'; + type: 'u128'; + }, + ]; + }, + { + name: 'updatePerpMarketMaxSlippageRatio'; + discriminator: [235, 37, 40, 196, 70, 146, 54, 201]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxSlippageRatio'; + type: 'u16'; + }, + ]; + }, + { + name: 'updatePerpMarketMaxSpread'; + discriminator: [80, 252, 122, 62, 40, 218, 91, 100]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxSpread'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePerpMarketMinOrderSize'; + discriminator: [226, 74, 5, 89, 108, 223, 46, 141]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'orderSize'; + type: 'u64'; + }, + ]; + }, + { + name: 'updatePerpMarketName'; + discriminator: [211, 31, 21, 210, 64, 108, 66, 201]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'updatePerpMarketNumberOfUsers'; + discriminator: [35, 62, 144, 177, 180, 62, 215, 196]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'numberOfUsers'; + type: { + option: 'u32'; + }; + }, + { + name: 'numberOfUsersWithBase'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'updatePerpMarketOracle'; + discriminator: [182, 113, 111, 160, 67, 174, 89, 191]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'oldOracle'; + }, + { + name: 'ammCache'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 97, + 109, + 109, + 95, + 99, + 97, + 99, + 104, + 101, + 95, + 115, + 101, + 101, + 100, + ]; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'oracle'; + type: 'pubkey'; + }, + { + name: 'oracleSource'; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'skipInvariantCheck'; + type: 'bool'; + }, + ]; + }, + { + name: 'updatePerpMarketOracleLowRiskSlotDelayOverride'; + discriminator: [124, 108, 147, 229, 109, 117, 123, 3]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'oracleLowRiskSlotDelayOverride'; + type: 'i8'; + }, + ]; + }, + { + name: 'updatePerpMarketOracleSlotDelayOverride'; + discriminator: [165, 91, 239, 227, 63, 172, 227, 8]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'oracleSlotDelayOverride'; + type: 'i8'; + }, + ]; + }, + { + name: 'updatePerpMarketPausedOperations'; + discriminator: [53, 16, 136, 132, 30, 220, 121, 85]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'pausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketPnlPool'; + discriminator: [50, 202, 249, 224, 166, 184, 13, 143]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'updatePerpMarketProtectedMakerParams'; + discriminator: [249, 213, 115, 34, 253, 239, 75, 173]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'protectedMakerLimitPriceDivisor'; + type: { + option: 'u8'; + }; + }, + { + name: 'protectedMakerDynamicDivisor'; + type: { + option: 'u8'; + }; + }, + ]; + }, + { + name: 'updatePerpMarketReferencePriceOffsetDeadbandPct'; + discriminator: [214, 73, 166, 11, 218, 76, 110, 163]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'referencePriceOffsetDeadbandPct'; + type: 'u8'; + }, + ]; + }, + { + name: 'updatePerpMarketStatus'; + discriminator: [71, 201, 175, 122, 255, 207, 196, 207]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'status'; + type: { + defined: { + name: 'marketStatus'; + }; + }; + }, + ]; + }, + { + name: 'updatePerpMarketStepSizeAndTickSize'; + discriminator: [231, 255, 97, 25, 146, 139, 174, 4]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'stepSize'; + type: 'u64'; + }, + { + name: 'tickSize'; + type: 'u64'; + }, + ]; + }, + { + name: 'updatePerpMarketUnrealizedAssetWeight'; + discriminator: [135, 132, 205, 165, 109, 150, 166, 106]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'unrealizedInitialAssetWeight'; + type: 'u32'; + }, + { + name: 'unrealizedMaintenanceAssetWeight'; + type: 'u32'; + }, + ]; + }, + { + name: 'updatePrelaunchOracle'; + discriminator: [220, 132, 27, 27, 233, 220, 61, 219]; + accounts: [ + { + name: 'state'; + }, + { + name: 'perpMarket'; + }, + { + name: 'oracle'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'updatePrelaunchOracleParams'; + discriminator: [98, 205, 147, 243, 18, 75, 83, 207]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'prelaunchOracle'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 114, + 101, + 108, + 97, + 117, + 110, + 99, + 104, + 95, + 111, + 114, + 97, + 99, + 108, + 101, + ]; + }, + { + kind: 'arg'; + path: 'params.perp_market_index'; + }, + ]; + }; + }, + { + name: 'perpMarket'; + writable: true; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'params'; + type: { + defined: { + name: 'prelaunchOracleParams'; + }; + }; + }, + ]; + }, + { + name: 'updateProtectedMakerModeConfig'; + discriminator: [86, 166, 235, 253, 67, 202, 223, 17]; + accounts: [ + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + { + name: 'protectedMakerModeConfig'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 112, + 114, + 111, + 116, + 101, + 99, + 116, + 101, + 100, + 95, + 109, + 97, + 107, + 101, + 114, + 95, + 109, + 111, + 100, + 101, + 95, + 99, + 111, + 110, + 102, + 105, + 103, + ]; + }, + ]; + }; + }, + { + name: 'state'; + }, + ]; + args: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + { + name: 'currentUsers'; + type: { + option: 'u32'; + }; + }, + ]; + }, + { + name: 'updatePythPullOracle'; + discriminator: [230, 191, 189, 94, 108, 59, 74, 197]; + accounts: [ + { + name: 'keeper'; + writable: true; + signer: true; + }, + { + name: 'pythSolanaReceiver'; + address: 'G6EoTTTgpkNBtVXo96EQp2m6uwwVh2Kt6YidjkmQqoha'; + }, + { + name: 'encodedVaa'; + }, + { + name: 'priceFeed'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [112, 121, 116, 104, 95, 112, 117, 108, 108]; + }, + { + kind: 'arg'; + path: 'feedId'; + }, + ]; + }; + }, + ]; + args: [ + { + name: 'feedId'; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'params'; + type: 'bytes'; + }, + ]; + }, + { + name: 'updateSerumFulfillmentConfigStatus'; + discriminator: [171, 109, 240, 251, 95, 1, 149, 89]; + accounts: [ + { + name: 'state'; + }, + { + name: 'serumFulfillmentConfig'; + writable: true; + }, + { + name: 'admin'; + writable: true; + signer: true; + relations: ['state']; + }, + ]; + args: [ + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + ]; + }, + { + name: 'updateSpotAuctionDuration'; + discriminator: [182, 178, 203, 72, 187, 143, 157, 107]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'defaultSpotAuctionDuration'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateSpotFeeStructure'; + discriminator: [97, 216, 105, 131, 113, 246, 142, 141]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'feeStructure'; + type: { + defined: { + name: 'feeStructure'; + }; + }; + }, + ]; + }, + { + name: 'updateSpotMarketAssetTier'; + discriminator: [253, 209, 231, 14, 242, 208, 243, 130]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'assetTier'; + type: { + defined: { + name: 'assetTier'; + }; + }; + }, + ]; + }, + { + name: 'updateSpotMarketBorrowRate'; + discriminator: [71, 239, 236, 153, 210, 62, 254, 76]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'optimalUtilization'; + type: 'u32'; + }, + { + name: 'optimalBorrowRate'; + type: 'u32'; + }, + { + name: 'maxBorrowRate'; + type: 'u32'; + }, + { + name: 'minBorrowRate'; + type: { + option: 'u8'; + }; + }, + ]; + }, + { + name: 'updateSpotMarketCumulativeInterest'; + discriminator: [39, 166, 139, 243, 158, 165, 155, 225]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'spotMarketVault'; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'account'; + path: 'spotMarket'; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'updateSpotMarketExpiry'; + discriminator: [208, 11, 211, 159, 226, 24, 11, 247]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'expiryTs'; + type: 'i64'; + }, + ]; + }, + { + name: 'updateSpotMarketFeeAdjustment'; + discriminator: [148, 182, 3, 126, 157, 114, 220, 99]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'feeAdjustment'; + type: 'i16'; + }, + ]; + }, + { + name: 'updateSpotMarketIfFactor'; + discriminator: [147, 30, 224, 34, 18, 230, 105, 4]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'userIfFactor'; + type: 'u32'; + }, + { + name: 'totalIfFactor'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateSpotMarketIfPausedOperations'; + discriminator: [101, 215, 79, 74, 59, 41, 79, 12]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'pausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateSpotMarketLiquidationFee'; + discriminator: [11, 13, 255, 53, 56, 136, 104, 177]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'liquidatorFee'; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateSpotMarketMarginWeights'; + discriminator: [109, 33, 87, 195, 255, 36, 6, 81]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'initialAssetWeight'; + type: 'u32'; + }, + { + name: 'maintenanceAssetWeight'; + type: 'u32'; + }, + { + name: 'initialLiabilityWeight'; + type: 'u32'; + }, + { + name: 'maintenanceLiabilityWeight'; + type: 'u32'; + }, + { + name: 'imfFactor'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateSpotMarketMaxTokenBorrows'; + discriminator: [57, 102, 204, 212, 253, 95, 13, 199]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxTokenBorrowsFraction'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateSpotMarketMaxTokenDeposits'; + discriminator: [56, 191, 79, 18, 26, 121, 80, 208]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'maxTokenDeposits'; + type: 'u64'; + }, + ]; + }, + { + name: 'updateSpotMarketMinOrderSize'; + discriminator: [93, 128, 11, 119, 26, 20, 181, 50]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'orderSize'; + type: 'u64'; + }, + ]; + }, + { + name: 'updateSpotMarketName'; + discriminator: [17, 208, 1, 1, 162, 211, 188, 224]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'updateSpotMarketOracle'; + discriminator: [114, 184, 102, 37, 246, 186, 180, 99]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'oracle'; + }, + { + name: 'oldOracle'; + }, + ]; + args: [ + { + name: 'oracle'; + type: 'pubkey'; + }, + { + name: 'oracleSource'; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'skipInvariantCheck'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateSpotMarketOrdersEnabled'; + discriminator: [190, 79, 206, 15, 26, 229, 229, 43]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'ordersEnabled'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateSpotMarketPausedOperations'; + discriminator: [100, 61, 153, 81, 180, 12, 6, 248]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'pausedOperations'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateSpotMarketPoolId'; + discriminator: [22, 213, 197, 160, 139, 193, 81, 149]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'poolId'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateSpotMarketRevenueSettlePeriod'; + discriminator: [81, 92, 126, 41, 250, 225, 156, 219]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'revenueSettlePeriod'; + type: 'i64'; + }, + ]; + }, + { + name: 'updateSpotMarketScaleInitialAssetWeightStart'; + discriminator: [217, 204, 204, 118, 204, 130, 225, 147]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'scaleInitialAssetWeightStart'; + type: 'u64'; + }, + ]; + }, + { + name: 'updateSpotMarketStatus'; + discriminator: [78, 94, 16, 188, 193, 110, 231, 31]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'status'; + type: { + defined: { + name: 'marketStatus'; + }; + }; + }, + ]; + }, + { + name: 'updateSpotMarketStepSizeAndTickSize'; + discriminator: [238, 153, 137, 80, 206, 59, 250, 61]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'stepSize'; + type: 'u64'; + }, + { + name: 'tickSize'; + type: 'u64'; + }, + ]; + }, + { + name: 'updateStateMaxInitializeUserFee'; + discriminator: [237, 225, 25, 237, 193, 45, 77, 97]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'maxInitializeUserFee'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateStateMaxNumberOfSubAccounts'; + discriminator: [155, 123, 214, 2, 221, 166, 204, 85]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'maxNumberOfSubAccounts'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateStateSettlementDuration'; + discriminator: [97, 68, 199, 235, 131, 80, 61, 173]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + writable: true; + }, + ]; + args: [ + { + name: 'settlementDuration'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateUserCustomMarginRatio'; + discriminator: [21, 221, 140, 187, 32, 129, 11, 123]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'marginRatio'; + type: 'u32'; + }, + ]; + }, + { + name: 'updateUserDelegate'; + discriminator: [139, 205, 141, 141, 113, 36, 94, 187]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'delegate'; + type: 'pubkey'; + }, + ]; + }, + { + name: 'updateUserGovTokenInsuranceStake'; + discriminator: [143, 99, 235, 187, 20, 159, 184, 84]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [15, 0]; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'signer'; + signer: true; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [15, 0]; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'updateUserIdle'; + discriminator: [253, 133, 67, 22, 103, 161, 20, 100]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'filler'; + writable: true; + }, + { + name: 'user'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'updateUserMarginTradingEnabled'; + discriminator: [194, 92, 204, 223, 246, 188, 31, 203]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'marginTradingEnabled'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateUserName'; + discriminator: [135, 25, 185, 56, 165, 53, 34, 136]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }, + { + name: 'updateUserPerpPositionCustomMarginRatio'; + discriminator: [121, 137, 157, 155, 89, 186, 145, 113]; + accounts: [ + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'marginRatio'; + type: 'u16'; + }, + ]; + }, + { + name: 'updateUserPoolId'; + discriminator: [219, 86, 73, 106, 56, 218, 128, 109]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'poolId'; + type: 'u8'; + }, + ]; + }, + { + name: 'updateUserProtectedMakerOrders'; + discriminator: [114, 39, 123, 198, 187, 25, 90, 219]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'protectedMakerModeConfig'; + writable: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'protectedMakerOrders'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateUserQuoteAssetInsuranceStake'; + discriminator: [251, 101, 156, 7, 2, 63, 30, 23]; + accounts: [ + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [115, 112, 111, 116, 95, 109, 97, 114, 107, 101, 116]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'signer'; + signer: true; + }, + { + name: 'insuranceFundVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 105, + 110, + 115, + 117, + 114, + 97, + 110, + 99, + 101, + 95, + 102, + 117, + 110, + 100, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'const'; + value: [0, 0]; + }, + ]; + }; + }, + ]; + args: []; + }, + { + name: 'updateUserReduceOnly'; + discriminator: [199, 71, 42, 67, 144, 19, 86, 109]; + accounts: [ + { + name: 'user'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [117, 115, 101, 114]; + }, + { + kind: 'account'; + path: 'authority'; + }, + { + kind: 'arg'; + path: 'subAccountId'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + ]; + args: [ + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + ]; + }, + { + name: 'updateUserStatsReferrerStatus'; + discriminator: [174, 154, 72, 42, 191, 148, 145, 205]; + accounts: [ + { + name: 'state'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'userStats'; + writable: true; + }, + ]; + args: []; + }, + { + name: 'updateWithdrawGuardThreshold'; + discriminator: [56, 18, 39, 61, 155, 211, 44, 133]; + accounts: [ + { + name: 'admin'; + signer: true; + relations: ['state']; + }, + { + name: 'state'; + }, + { + name: 'spotMarket'; + writable: true; + }, + ]; + args: [ + { + name: 'withdrawGuardThreshold'; + type: 'u64'; + }, + ]; + }, + { + name: 'viewLpPoolAddLiquidityFees'; + discriminator: [80, 66, 226, 161, 70, 142, 119, 84]; + accounts: [ + { + name: 'state'; + }, + { + name: 'lpPool'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'inMarketMint'; + }, + { + name: 'inConstituent'; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'lpMint'; + }, + { + name: 'constituentTargetBase'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u128'; + }, + ]; + }, + { + name: 'viewLpPoolRemoveLiquidityFees'; + discriminator: [47, 12, 9, 102, 12, 226, 197, 89]; + accounts: [ + { + name: 'state'; + }, + { + name: 'lpPool'; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'outMarketMint'; + }, + { + name: 'outConstituent'; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'lpMint'; + }, + { + name: 'constituentTargetBase'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u64'; + }, + ]; + }, + { + name: 'viewLpPoolSwapFees'; + discriminator: [126, 189, 109, 189, 170, 156, 3, 46]; + accounts: [ + { + name: 'driftSigner'; + }, + { + name: 'state'; + }, + { + name: 'lpPool'; + }, + { + name: 'constituentTargetBase'; + }, + { + name: 'constituentCorrelations'; + }, + { + name: 'constituentInTokenAccount'; + writable: true; + }, + { + name: 'constituentOutTokenAccount'; + writable: true; + }, + { + name: 'inConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'inMarketIndex'; + }, + ]; + }; + }, + { + name: 'outConstituent'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [67, 79, 78, 83, 84, 73, 84, 85, 69, 78, 84]; + }, + { + kind: 'account'; + path: 'lpPool'; + }, + { + kind: 'arg'; + path: 'outMarketIndex'; + }, + ]; + }; + }, + { + name: 'authority'; + signer: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'inAmount'; + type: 'u64'; + }, + { + name: 'inTargetWeight'; + type: 'i64'; + }, + { + name: 'outTargetWeight'; + type: 'i64'; + }, + ]; + }, + { + name: 'withdraw'; + discriminator: [183, 18, 70, 156, 148, 109, 161, 34]; + accounts: [ + { + name: 'state'; + }, + { + name: 'user'; + writable: true; + }, + { + name: 'userStats'; + writable: true; + }, + { + name: 'authority'; + signer: true; + relations: ['user', 'userStats']; + }, + { + name: 'spotMarketVault'; + writable: true; + pda: { + seeds: [ + { + kind: 'const'; + value: [ + 115, + 112, + 111, + 116, + 95, + 109, + 97, + 114, + 107, + 101, + 116, + 95, + 118, + 97, + 117, + 108, + 116, + ]; + }, + { + kind: 'arg'; + path: 'marketIndex'; + }, + ]; + }; + }, + { + name: 'driftSigner'; + }, + { + name: 'userTokenAccount'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + ]; + args: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + ]; + }, + { + name: 'withdrawFromProgramVault'; + discriminator: [120, 40, 183, 149, 232, 18, 224, 151]; + accounts: [ + { + name: 'state'; + }, + { + name: 'admin'; + writable: true; + signer: true; + }, + { + name: 'driftSigner'; + }, + { + name: 'constituent'; + writable: true; + }, + { + name: 'constituentTokenAccount'; + writable: true; + }, + { + name: 'spotMarket'; + writable: true; + }, + { + name: 'spotMarketVault'; + writable: true; + }, + { + name: 'tokenProgram'; + }, + { + name: 'mint'; + }, + { + name: 'oracle'; + }, + ]; + args: [ + { + name: 'amount'; + type: 'u64'; + }, + ]; + }, + { + name: 'zeroMmOracleFields'; + discriminator: [192, 226, 39, 204, 207, 120, 148, 250]; + accounts: [ + { + name: 'admin'; + signer: true; + }, + { + name: 'state'; + }, + { + name: 'perpMarket'; + writable: true; + }, + ]; + args: []; + }, + ]; + accounts: [ + { + name: 'ammCache'; + discriminator: [213, 114, 161, 56, 20, 22, 2, 59]; + }, + { + name: 'ammConstituentMapping'; + discriminator: [254, 89, 5, 173, 66, 54, 214, 247]; + }, + { + name: 'constituent'; + discriminator: [0, 61, 36, 35, 177, 76, 216, 205]; + }, + { + name: 'constituentCorrelations'; + discriminator: [124, 203, 115, 33, 18, 162, 67, 216]; + }, + { + name: 'constituentTargetBase'; + discriminator: [255, 142, 134, 71, 125, 66, 198, 99]; + }, + { + name: 'fuelOverflow'; + discriminator: [182, 64, 231, 177, 226, 142, 69, 58]; + }, + { + name: 'highLeverageModeConfig'; + discriminator: [3, 196, 90, 189, 193, 64, 228, 234]; + }, + { + name: 'ifRebalanceConfig'; + discriminator: [214, 84, 40, 251, 107, 144, 173, 239]; + }, + { + name: 'insuranceFundStake'; + discriminator: [110, 202, 14, 42, 95, 73, 90, 95]; + }, + { + name: 'lpPool'; + discriminator: [228, 152, 141, 224, 161, 170, 11, 89]; + }, + { + name: 'openbookV2FulfillmentConfig'; + discriminator: [3, 43, 58, 106, 131, 132, 199, 171]; + }, + { + name: 'perpMarket'; + discriminator: [10, 223, 12, 44, 107, 245, 55, 247]; + }, + { + name: 'phoenixV1FulfillmentConfig'; + discriminator: [233, 45, 62, 40, 35, 129, 48, 72]; + }, + { + name: 'prelaunchOracle'; + discriminator: [92, 14, 139, 234, 72, 244, 68, 26]; + }, + { + name: 'protectedMakerModeConfig'; + discriminator: [47, 86, 90, 9, 224, 255, 10, 69]; + }, + { + name: 'pythLazerOracle'; + discriminator: [159, 7, 161, 249, 34, 81, 121, 133]; + }, + { + name: 'referrerName'; + discriminator: [105, 133, 170, 110, 52, 42, 28, 182]; + }, + { + name: 'revenueShare'; + discriminator: [55, 40, 228, 7, 139, 52, 180, 110]; + }, + { + name: 'revenueShareEscrow'; + discriminator: [98, 167, 3, 46, 74, 177, 173, 252]; + }, + { + name: 'serumV3FulfillmentConfig'; + discriminator: [65, 160, 197, 112, 239, 168, 103, 185]; + }, + { + name: 'signedMsgUserOrders'; + discriminator: [70, 6, 50, 248, 222, 1, 143, 49]; + }, + { + name: 'signedMsgWsDelegates'; + discriminator: [190, 115, 111, 44, 216, 252, 108, 85]; + }, + { + name: 'spotMarket'; + discriminator: [100, 177, 8, 107, 168, 65, 65, 39]; + }, + { + name: 'state'; + discriminator: [216, 146, 107, 94, 104, 75, 182, 177]; + }, + { + name: 'user'; + discriminator: [159, 117, 95, 227, 239, 151, 58, 236]; + }, + { + name: 'userStats'; + discriminator: [176, 223, 136, 27, 122, 79, 32, 227]; + }, + ]; + events: [ + { + name: 'curveRecord'; + discriminator: [101, 238, 40, 228, 70, 46, 61, 117]; + }, + { + name: 'deleteUserRecord'; + discriminator: [71, 111, 190, 118, 7, 3, 132, 222]; + }, + { + name: 'depositRecord'; + discriminator: [180, 241, 218, 207, 102, 135, 44, 134]; + }, + { + name: 'fuelSeasonRecord'; + discriminator: [19, 137, 119, 33, 224, 249, 6, 87]; + }, + { + name: 'fuelSweepRecord'; + discriminator: [41, 84, 37, 246, 132, 240, 131, 8]; + }, + { + name: 'fundingPaymentRecord'; + discriminator: [8, 59, 96, 20, 137, 201, 56, 95]; + }, + { + name: 'fundingRateRecord'; + discriminator: [68, 3, 255, 26, 133, 91, 147, 254]; + }, + { + name: 'insuranceFundRecord'; + discriminator: [56, 222, 215, 235, 78, 197, 99, 146]; + }, + { + name: 'insuranceFundStakeRecord'; + discriminator: [68, 66, 156, 7, 216, 148, 250, 114]; + }, + { + name: 'insuranceFundSwapRecord'; + discriminator: [85, 190, 99, 203, 237, 33, 227, 100]; + }, + { + name: 'lpBorrowLendDepositRecord'; + discriminator: [242, 181, 11, 56, 243, 61, 79, 210]; + }, + { + name: 'lpMintRedeemRecord'; + discriminator: [53, 178, 142, 73, 78, 91, 91, 8]; + }, + { + name: 'lpRecord'; + discriminator: [101, 22, 54, 38, 178, 13, 142, 111]; + }, + { + name: 'lpSettleRecord'; + discriminator: [208, 191, 131, 110, 173, 48, 7, 2]; + }, + { + name: 'lpSwapRecord'; + discriminator: [159, 62, 130, 196, 96, 79, 176, 254]; + }, + { + name: 'liquidationRecord'; + discriminator: [127, 17, 0, 108, 182, 13, 231, 53]; + }, + { + name: 'newUserRecord'; + discriminator: [236, 186, 113, 219, 42, 51, 149, 249]; + }, + { + name: 'orderActionRecord'; + discriminator: [224, 52, 67, 71, 194, 237, 109, 1]; + }, + { + name: 'orderRecord'; + discriminator: [104, 19, 64, 56, 89, 21, 2, 90]; + }, + { + name: 'revenueShareSettleRecord'; + discriminator: [61, 162, 89, 10, 24, 20, 59, 45]; + }, + { + name: 'settlePnlRecord'; + discriminator: [57, 68, 105, 26, 119, 198, 213, 89]; + }, + { + name: 'signedMsgOrderRecord'; + discriminator: [211, 197, 25, 18, 142, 86, 113, 27]; + }, + { + name: 'spotInterestRecord'; + discriminator: [183, 186, 203, 186, 225, 187, 95, 130]; + }, + { + name: 'spotMarketVaultDepositRecord'; + discriminator: [178, 217, 23, 188, 127, 190, 32, 73]; + }, + { + name: 'swapRecord'; + discriminator: [162, 187, 123, 194, 138, 56, 250, 241]; + }, + { + name: 'transferProtocolIfSharesToRevenuePoolRecord'; + discriminator: [209, 118, 142, 167, 130, 46, 164, 151]; + }, + ]; + errors: [ + { + code: 6000; + name: 'invalidEd25519InstructionProgramId'; + msg: 'invalid ed25519 instruction program'; + }, + { + code: 6001; + name: 'invalidEd25519InstructionDataLength'; + msg: 'invalid ed25519 instruction data length'; + }, + { + code: 6002; + name: 'invalidSignatureIndex'; + msg: 'invalid signature index'; + }, + { + code: 6003; + name: 'invalidSignatureOffset'; + msg: 'invalid signature offset'; + }, + { + code: 6004; + name: 'invalidPublicKeyOffset'; + msg: 'invalid public key offset'; + }, + { + code: 6005; + name: 'invalidMessageOffset'; + msg: 'invalid message offset'; + }, + { + code: 6006; + name: 'invalidMessageDataSize'; + msg: 'invalid message data size'; + }, + { + code: 6007; + name: 'invalidInstructionIndex'; + msg: 'invalid instruction index'; + }, + { + code: 6008; + name: 'messageOffsetOverflow'; + msg: 'message offset overflow'; + }, + { + code: 6009; + name: 'invalidMessageHex'; + msg: 'invalid message hex'; + }, + { + code: 6010; + name: 'invalidMessageData'; + msg: 'invalid message data'; + }, + { + code: 6011; + name: 'loadInstructionAtFailed'; + msg: 'loading custom ix at index failed'; + }, + ]; + types: [ + { + name: 'amm'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'oracle'; + docs: ['oracle price data public key']; + type: 'pubkey'; + }, + { + name: 'historicalOracleData'; + docs: ['stores historically witnessed oracle data']; + type: { + defined: { + name: 'historicalOracleData'; + }; + }; + }, + { + name: 'baseAssetAmountPerLp'; + docs: [ + 'accumulated base asset amount since inception per lp share', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'quoteAssetAmountPerLp'; + docs: [ + 'accumulated quote asset amount since inception per lp share', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'feePool'; + docs: [ + 'partition of fees from perp market trading moved from pnl settlements', + ]; + type: { + defined: { + name: 'poolBalance'; + }; + }; + }, + { + name: 'baseAssetReserve'; + docs: [ + '`x` reserves for constant product mm formula (x * y = k)', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'quoteAssetReserve'; + docs: [ + '`y` reserves for constant product mm formula (x * y = k)', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'concentrationCoef'; + docs: [ + 'determines how close the min/max base asset reserve sit vs base reserves', + 'allow for decreasing slippage without increasing liquidity and v.v.', + 'precision: PERCENTAGE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'minBaseAssetReserve'; + docs: [ + 'minimum base_asset_reserve allowed before AMM is unavailable', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'maxBaseAssetReserve'; + docs: [ + 'maximum base_asset_reserve allowed before AMM is unavailable', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'sqrtK'; + docs: [ + '`sqrt(k)` in constant product mm formula (x * y = k). stored to avoid drift caused by integer math issues', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'pegMultiplier'; + docs: [ + 'normalizing numerical factor for y, its use offers lowest slippage in cp-curve when market is balanced', + 'precision: PEG_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'terminalQuoteAssetReserve'; + docs: [ + 'y when market is balanced. stored to save computation', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'baseAssetAmountLong'; + docs: [ + 'always non-negative. tracks number of total longs in market (regardless of counterparty)', + 'precision: BASE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'baseAssetAmountShort'; + docs: [ + 'always non-positive. tracks number of total shorts in market (regardless of counterparty)', + 'precision: BASE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'baseAssetAmountWithAmm'; + docs: [ + 'tracks net position (longs-shorts) in market with AMM as counterparty', + 'precision: BASE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'baseAssetAmountWithUnsettledLp'; + docs: [ + 'tracks net position (longs-shorts) in market with LPs as counterparty', + 'precision: BASE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'maxOpenInterest'; + docs: [ + 'max allowed open interest, blocks trades that breach this value', + 'precision: BASE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'quoteAssetAmount'; + docs: [ + "sum of all user's perp quote_asset_amount in market", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'quoteEntryAmountLong'; + docs: [ + "sum of all long user's quote_entry_amount in market", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'quoteEntryAmountShort'; + docs: [ + "sum of all short user's quote_entry_amount in market", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'quoteBreakEvenAmountLong'; + docs: [ + "sum of all long user's quote_break_even_amount in market", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'quoteBreakEvenAmountShort'; + docs: [ + "sum of all short user's quote_break_even_amount in market", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'userLpShares'; + docs: [ + 'total user lp shares of sqrt_k (protocol owned liquidity = sqrt_k - last_funding_rate)', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastFundingRate'; + docs: [ + 'last funding rate in this perp market (unit is quote per base)', + 'precision: FUNDING_RATE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lastFundingRateLong'; + docs: [ + 'last funding rate for longs in this perp market (unit is quote per base)', + 'precision: FUNDING_RATE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lastFundingRateShort'; + docs: [ + 'last funding rate for shorts in this perp market (unit is quote per base)', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'last24hAvgFundingRate'; + docs: [ + 'estimate of last 24h of funding rate perp market (unit is quote per base)', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'totalFee'; + docs: [ + 'total fees collected by this perp market', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'totalMmFee'; + docs: [ + "total fees collected by the vAMM's bid/ask spread", + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'totalExchangeFee'; + docs: [ + 'total fees collected by exchange fee schedule', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'totalFeeMinusDistributions'; + docs: [ + 'total fees minus any recognized upnl and pool withdraws', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'totalFeeWithdrawn'; + docs: [ + 'sum of all fees from fee pool withdrawn to revenue pool', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'totalLiquidationFee'; + docs: [ + 'all fees collected by market for liquidations', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeFundingRateLong'; + docs: [ + 'accumulated funding rate for longs since inception in market', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'cumulativeFundingRateShort'; + docs: [ + 'accumulated funding rate for shorts since inception in market', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'totalSocialLoss'; + docs: [ + 'accumulated social loss paid by users since inception in market', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'askBaseAssetReserve'; + docs: [ + 'transformed base_asset_reserve for users going long', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'askQuoteAssetReserve'; + docs: [ + 'transformed quote_asset_reserve for users going long', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'bidBaseAssetReserve'; + docs: [ + 'transformed base_asset_reserve for users going short', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'bidQuoteAssetReserve'; + docs: [ + 'transformed quote_asset_reserve for users going short', + 'precision: AMM_RESERVE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastOracleNormalisedPrice'; + docs: [ + 'the last seen oracle price partially shrunk toward the amm reserve price', + 'precision: PRICE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lastOracleReservePriceSpreadPct'; + docs: [ + 'the gap between the oracle price and the reserve price = y * peg_multiplier / x', + ]; + type: 'i64'; + }, + { + name: 'lastBidPriceTwap'; + docs: [ + 'average estimate of bid price over funding_period', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastAskPriceTwap'; + docs: [ + 'average estimate of ask price over funding_period', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastMarkPriceTwap'; + docs: [ + 'average estimate of (bid+ask)/2 price over funding_period', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastMarkPriceTwap5min'; + docs: ['average estimate of (bid+ask)/2 price over FIVE_MINUTES']; + type: 'u64'; + }, + { + name: 'lastUpdateSlot'; + docs: ['the last blockchain slot the amm was updated']; + type: 'u64'; + }, + { + name: 'lastOracleConfPct'; + docs: [ + 'the pct size of the oracle confidence interval', + 'precision: PERCENTAGE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'netRevenueSinceLastFunding'; + docs: [ + 'the total_fee_minus_distribution change since the last funding update', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lastFundingRateTs'; + docs: ['the last funding rate update unix_timestamp']; + type: 'i64'; + }, + { + name: 'fundingPeriod'; + docs: ['the periodicity of the funding rate updates']; + type: 'i64'; + }, + { + name: 'orderStepSize'; + docs: [ + 'the base step size (increment) of orders', + 'precision: BASE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'orderTickSize'; + docs: [ + 'the price tick size of orders', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'minOrderSize'; + docs: [ + 'the minimum base size of an order', + 'precision: BASE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'mmOracleSlot'; + docs: [ + 'the max base size a single user can have', + 'precision: BASE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'volume24h'; + docs: ['estimated total of volume in market', 'QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'longIntensityVolume'; + docs: ['the volume intensity of long fills against AMM']; + type: 'u64'; + }, + { + name: 'shortIntensityVolume'; + docs: ['the volume intensity of short fills against AMM']; + type: 'u64'; + }, + { + name: 'lastTradeTs'; + docs: [ + 'the blockchain unix timestamp at the time of the last trade', + ]; + type: 'i64'; + }, + { + name: 'markStd'; + docs: [ + 'estimate of standard deviation of the fill (mark) prices', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'oracleStd'; + docs: [ + 'estimate of standard deviation of the oracle price at each update', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastMarkPriceTwapTs'; + docs: ['the last unix_timestamp the mark twap was updated']; + type: 'i64'; + }, + { + name: 'baseSpread'; + docs: [ + 'the minimum spread the AMM can quote. also used as step size for some spread logic increases.', + ]; + type: 'u32'; + }, + { + name: 'maxSpread'; + docs: ['the maximum spread the AMM can quote']; + type: 'u32'; + }, + { + name: 'longSpread'; + docs: ['the spread for asks vs the reserve price']; + type: 'u32'; + }, + { + name: 'shortSpread'; + docs: ['the spread for bids vs the reserve price']; + type: 'u32'; + }, + { + name: 'mmOraclePrice'; + docs: ['MM oracle price']; + type: 'i64'; + }, + { + name: 'maxFillReserveFraction'; + docs: [ + 'the fraction of total available liquidity a single fill on the AMM can consume', + ]; + type: 'u16'; + }, + { + name: 'maxSlippageRatio'; + docs: ['the maximum slippage a single fill on the AMM can push']; + type: 'u16'; + }, + { + name: 'curveUpdateIntensity'; + docs: [ + 'the update intensity of AMM formulaic updates (adjusting k). 0-100', + ]; + type: 'u8'; + }, + { + name: 'ammJitIntensity'; + docs: [ + 'the jit intensity of AMM. larger intensity means larger participation in jit. 0 means no jit participation.', + '(0, 100] is intensity for protocol-owned AMM. (100, 200] is intensity for user LP-owned AMM.', + ]; + type: 'u8'; + }, + { + name: 'oracleSource'; + docs: [ + 'the oracle provider information. used to decode/scale the oracle public key', + ]; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'lastOracleValid'; + docs: [ + 'tracks whether the oracle was considered valid at the last AMM update', + ]; + type: 'bool'; + }, + { + name: 'targetBaseAssetAmountPerLp'; + docs: [ + 'the target value for `base_asset_amount_per_lp`, used during AMM JIT with LP split', + 'precision: BASE_PRECISION', + ]; + type: 'i32'; + }, + { + name: 'perLpBase'; + docs: [ + 'expo for unit of per_lp, base 10 (if per_lp_base=X, then per_lp unit is 10^X)', + ]; + type: 'i8'; + }, + { + name: 'oracleLowRiskSlotDelayOverride'; + docs: [ + 'the override for the state.min_perp_auction_duration', + '0 is no override, -1 is disable speed bump, 1-100 is literal speed bump', + ]; + type: 'i8'; + }, + { + name: 'ammSpreadAdjustment'; + docs: [ + 'signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)', + ]; + type: 'i8'; + }, + { + name: 'oracleSlotDelayOverride'; + type: 'i8'; + }, + { + name: 'mmOracleSequenceId'; + type: 'u64'; + }, + { + name: 'netUnsettledFundingPnl'; + type: 'i64'; + }, + { + name: 'quoteAssetAmountWithUnsettledLp'; + type: 'i64'; + }, + { + name: 'referencePriceOffset'; + type: 'i32'; + }, + { + name: 'ammInventorySpreadAdjustment'; + docs: [ + 'signed scale amm_spread similar to fee_adjustment logic (-100 = 0, 100 = double)', + ]; + type: 'i8'; + }, + { + name: 'referencePriceOffsetDeadbandPct'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 2]; + }; + }, + { + name: 'lastFundingOracleTwap'; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'addAmmConstituentMappingDatum'; + type: { + kind: 'struct'; + fields: [ + { + name: 'constituentIndex'; + type: 'u16'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'weight'; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'ammCache'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'cache'; + type: { + vec: { + defined: { + name: 'cacheInfo'; + }; + }; + }; + }, + ]; + }; + }, + { + name: 'ammConstituentDatum'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'constituentIndex'; + type: 'u16'; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + { + name: 'lastSlot'; + type: 'u64'; + }, + { + name: 'weight'; + docs: [ + 'PERCENTAGE_PRECISION. The weight this constituent has on the perp market', + ]; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'ammConstituentMapping'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'lpPool'; + type: 'pubkey'; + }, + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'weights'; + type: { + vec: { + defined: { + name: 'ammConstituentDatum'; + }; + }; + }; + }, + ]; + }; + }, + { + name: 'assetTier'; + type: { + kind: 'enum'; + variants: [ + { + name: 'collateral'; + }, + { + name: 'protected'; + }, + { + name: 'cross'; + }, + { + name: 'isolated'; + }, + { + name: 'unlisted'; + }, + ]; + }; + }, + { + name: 'builderInfo'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'maxFeeTenthBps'; + type: 'u16'; + }, + { + name: 'padding'; + type: { + array: ['u8', 6]; + }; + }, + ]; + }; + }, + { + name: 'cacheInfo'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'oracle'; + type: 'pubkey'; + }, + { + name: 'lastFeePoolTokenAmount'; + type: 'u128'; + }, + { + name: 'lastNetPnlPoolTokenAmount'; + type: 'i128'; + }, + { + name: 'lastExchangeFees'; + type: 'u128'; + }, + { + name: 'lastSettleAmmExFees'; + type: 'u128'; + }, + { + name: 'lastSettleAmmPnl'; + type: 'i128'; + }, + { + name: 'position'; + docs: ['BASE PRECISION']; + type: 'i64'; + }, + { + name: 'slot'; + type: 'u64'; + }, + { + name: 'lastSettleAmount'; + type: 'u64'; + }, + { + name: 'lastSettleSlot'; + type: 'u64'; + }, + { + name: 'lastSettleTs'; + type: 'i64'; + }, + { + name: 'quoteOwedFromLpPool'; + type: 'i64'; + }, + { + name: 'ammInventoryLimit'; + type: 'i64'; + }, + { + name: 'oraclePrice'; + type: 'i64'; + }, + { + name: 'oracleSlot'; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'oracleSource'; + type: 'u8'; + }, + { + name: 'oracleValidity'; + type: 'u8'; + }, + { + name: 'lpStatusForPerpMarket'; + type: 'u8'; + }, + { + name: 'ammPositionScalar'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 34]; + }; + }, + ]; + }; + }, + { + name: 'constituent'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + docs: ['address of the constituent']; + type: 'pubkey'; + }, + { + name: 'mint'; + type: 'pubkey'; + }, + { + name: 'lpPool'; + type: 'pubkey'; + }, + { + name: 'vault'; + type: 'pubkey'; + }, + { + name: 'totalSwapFees'; + docs: [ + 'total fees received by the constituent. Positive = fees received, Negative = fees paid', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'spotBalance'; + docs: ['spot borrow-lend balance for constituent']; + type: { + defined: { + name: 'constituentSpotBalance'; + }; + }; + }, + { + name: 'lastSpotBalanceTokenAmount'; + type: 'i64'; + }, + { + name: 'cumulativeSpotInterestAccruedTokenAmount'; + type: 'i64'; + }, + { + name: 'maxWeightDeviation'; + docs: [ + 'max deviation from target_weight allowed for the constituent', + 'precision: PERCENTAGE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'swapFeeMin'; + docs: [ + 'min fee charged on swaps to/from this constituent', + 'precision: PERCENTAGE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'swapFeeMax'; + docs: [ + 'max fee charged on swaps to/from this constituent', + 'precision: PERCENTAGE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'maxBorrowTokenAmount'; + docs: ['Max Borrow amount:', 'precision: token precision']; + type: 'u64'; + }, + { + name: 'vaultTokenBalance'; + docs: ['ata token balance in token precision']; + type: 'u64'; + }, + { + name: 'lastOraclePrice'; + type: 'i64'; + }, + { + name: 'lastOracleSlot'; + type: 'u64'; + }, + { + name: 'oracleStalenessThreshold'; + docs: ['Delay allowed for valid AUM calculation']; + type: 'u64'; + }, + { + name: 'flashLoanInitialTokenAmount'; + type: 'u64'; + }, + { + name: 'nextSwapId'; + docs: [ + 'Every swap to/from this constituent has a monotonically increasing id. This is the next id to use', + ]; + type: 'u64'; + }, + { + name: 'derivativeWeight'; + docs: [ + 'percentable of derivatve weight to go to this specific derivative PERCENTAGE_PRECISION. Zero if no derivative weight', + ]; + type: 'u64'; + }, + { + name: 'volatility'; + type: 'u64'; + }, + { + name: 'constituentDerivativeDepegThreshold'; + type: 'u64'; + }, + { + name: 'constituentDerivativeIndex'; + docs: [ + 'The `constituent_index` of the parent constituent. -1 if it is a parent index', + 'Example: if in a pool with SOL (parent) and dSOL (derivative),', + 'SOL.constituent_index = 1, SOL.constituent_derivative_index = -1,', + 'dSOL.constituent_index = 2, dSOL.constituent_derivative_index = 1', + ]; + type: 'i16'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'constituentIndex'; + type: 'u16'; + }, + { + name: 'decimals'; + type: 'u8'; + }, + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'vaultBump'; + type: 'u8'; + }, + { + name: 'gammaInventory'; + type: 'u8'; + }, + { + name: 'gammaExecution'; + type: 'u8'; + }, + { + name: 'xi'; + type: 'u8'; + }, + { + name: 'status'; + type: 'u8'; + }, + { + name: 'pausedOperations'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 162]; + }; + }, + ]; + }; + }, + { + name: 'constituentCorrelations'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'lpPool'; + type: 'pubkey'; + }, + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'correlations'; + type: { + vec: 'i64'; + }; + }, + ]; + }; + }, + { + name: 'constituentParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'maxWeightDeviation'; + type: { + option: 'i64'; + }; + }, + { + name: 'swapFeeMin'; + type: { + option: 'i64'; + }; + }, + { + name: 'swapFeeMax'; + type: { + option: 'i64'; + }; + }, + { + name: 'maxBorrowTokenAmount'; + type: { + option: 'u64'; + }; + }, + { + name: 'oracleStalenessThreshold'; + type: { + option: 'u64'; + }; + }, + { + name: 'costToTradeBps'; + type: { + option: 'i32'; + }; + }, + { + name: 'constituentDerivativeIndex'; + type: { + option: 'i16'; + }; + }, + { + name: 'derivativeWeight'; + type: { + option: 'u64'; + }; + }, + { + name: 'volatility'; + type: { + option: 'u64'; + }; + }, + { + name: 'gammaExecution'; + type: { + option: 'u8'; + }; + }, + { + name: 'gammaInventory'; + type: { + option: 'u8'; + }; + }, + { + name: 'xi'; + type: { + option: 'u8'; + }; + }, + ]; + }; + }, + { + name: 'constituentSpotBalance'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'scaledBalance'; + docs: [ + 'The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow', + 'interest of corresponding market.', + 'precision: token precision', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeDeposits'; + docs: [ + 'The cumulative deposits/borrows a user has made into a market', + 'precision: token mint precision', + ]; + type: 'i64'; + }, + { + name: 'marketIndex'; + docs: ['The market index of the corresponding spot market']; + type: 'u16'; + }, + { + name: 'balanceType'; + docs: ['Whether the position is deposit or borrow']; + type: { + defined: { + name: 'spotBalanceType'; + }; + }; + }, + { + name: 'padding'; + type: { + array: ['u8', 5]; + }; + }, + ]; + }; + }, + { + name: 'constituentTargetBase'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'lpPool'; + type: 'pubkey'; + }, + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'targets'; + type: { + vec: { + defined: { + name: 'targetsDatum'; + }; + }; + }; + }, + ]; + }; + }, + { + name: 'contractTier'; + type: { + kind: 'enum'; + variants: [ + { + name: 'a'; + }, + { + name: 'b'; + }, + { + name: 'c'; + }, + { + name: 'speculative'; + }, + { + name: 'highlySpeculative'; + }, + { + name: 'isolated'; + }, + ]; + }; + }, + { + name: 'contractType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'perpetual'; + }, + { + name: 'future'; + }, + { + name: 'prediction'; + }, + ]; + }; + }, + { + name: 'curveRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'recordId'; + type: 'u64'; + }, + { + name: 'pegMultiplierBefore'; + type: 'u128'; + }, + { + name: 'baseAssetReserveBefore'; + type: 'u128'; + }, + { + name: 'quoteAssetReserveBefore'; + type: 'u128'; + }, + { + name: 'sqrtKBefore'; + type: 'u128'; + }, + { + name: 'pegMultiplierAfter'; + type: 'u128'; + }, + { + name: 'baseAssetReserveAfter'; + type: 'u128'; + }, + { + name: 'quoteAssetReserveAfter'; + type: 'u128'; + }, + { + name: 'sqrtKAfter'; + type: 'u128'; + }, + { + name: 'baseAssetAmountLong'; + docs: ['precision: BASE_PRECISION']; + type: 'u128'; + }, + { + name: 'baseAssetAmountShort'; + docs: ['precision: BASE_PRECISION']; + type: 'u128'; + }, + { + name: 'baseAssetAmountWithAmm'; + docs: ['precision: BASE_PRECISION']; + type: 'i128'; + }, + { + name: 'totalFee'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i128'; + }, + { + name: 'totalFeeMinusDistributions'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i128'; + }, + { + name: 'adjustmentCost'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i128'; + }, + { + name: 'oraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'fillRecord'; + type: 'u128'; + }, + { + name: 'numberOfUsers'; + type: 'u32'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + ]; + }; + }, + { + name: 'deleteUserRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + docs: ['unix_timestamp of action']; + type: 'i64'; + }, + { + name: 'userAuthority'; + type: 'pubkey'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'keeper'; + type: { + option: 'pubkey'; + }; + }, + ]; + }; + }, + { + name: 'depositDirection'; + type: { + kind: 'enum'; + variants: [ + { + name: 'deposit'; + }, + { + name: 'withdraw'; + }, + ]; + }; + }, + { + name: 'depositExplanation'; + type: { + kind: 'enum'; + variants: [ + { + name: 'none'; + }, + { + name: 'transfer'; + }, + { + name: 'borrow'; + }, + { + name: 'repayBorrow'; + }, + { + name: 'reward'; + }, + ]; + }; + }, + { + name: 'depositRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + docs: ['unix_timestamp of action']; + type: 'i64'; + }, + { + name: 'userAuthority'; + type: 'pubkey'; + }, + { + name: 'user'; + docs: ['user account public key']; + type: 'pubkey'; + }, + { + name: 'direction'; + type: { + defined: { + name: 'depositDirection'; + }; + }; + }, + { + name: 'depositRecordId'; + type: 'u64'; + }, + { + name: 'amount'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + { + name: 'marketIndex'; + docs: ['spot market index']; + type: 'u16'; + }, + { + name: 'oraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'marketDepositBalance'; + docs: ['precision: SPOT_BALANCE_PRECISION']; + type: 'u128'; + }, + { + name: 'marketWithdrawBalance'; + docs: ['precision: SPOT_BALANCE_PRECISION']; + type: 'u128'; + }, + { + name: 'marketCumulativeDepositInterest'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'marketCumulativeBorrowInterest'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'totalDepositsAfter'; + docs: ['precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'totalWithdrawsAfter'; + docs: ['precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'explanation'; + type: { + defined: { + name: 'depositExplanation'; + }; + }; + }, + { + name: 'transferUser'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'signer'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'userTokenAmountAfter'; + docs: ['precision: token mint precision']; + type: 'i128'; + }, + ]; + }; + }, + { + name: 'feeStructure'; + type: { + kind: 'struct'; + fields: [ + { + name: 'feeTiers'; + type: { + array: [ + { + defined: { + name: 'feeTier'; + }; + }, + 10, + ]; + }; + }, + { + name: 'fillerRewardStructure'; + type: { + defined: { + name: 'orderFillerRewardStructure'; + }; + }; + }, + { + name: 'referrerRewardEpochUpperBound'; + type: 'u64'; + }, + { + name: 'flatFillerFee'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'feeTier'; + type: { + kind: 'struct'; + fields: [ + { + name: 'feeNumerator'; + type: 'u32'; + }, + { + name: 'feeDenominator'; + type: 'u32'; + }, + { + name: 'makerRebateNumerator'; + type: 'u32'; + }, + { + name: 'makerRebateDenominator'; + type: 'u32'; + }, + { + name: 'referrerRewardNumerator'; + type: 'u32'; + }, + { + name: 'referrerRewardDenominator'; + type: 'u32'; + }, + { + name: 'refereeFeeNumerator'; + type: 'u32'; + }, + { + name: 'refereeFeeDenominator'; + type: 'u32'; + }, + ]; + }; + }, + { + name: 'fuelOverflow'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + docs: ['The authority of this overflow account']; + type: 'pubkey'; + }, + { + name: 'fuelInsurance'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'fuelDeposits'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'fuelBorrows'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'fuelPositions'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'fuelTaker'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'fuelMaker'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastFuelSweepTs'; + type: 'u32'; + }, + { + name: 'lastResetTs'; + type: 'u32'; + }, + { + name: 'padding'; + type: { + array: ['u128', 6]; + }; + }, + ]; + }; + }, + { + name: 'fuelSeasonRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'fuelInsurance'; + type: 'u128'; + }, + { + name: 'fuelDeposits'; + type: 'u128'; + }, + { + name: 'fuelBorrows'; + type: 'u128'; + }, + { + name: 'fuelPositions'; + type: 'u128'; + }, + { + name: 'fuelTaker'; + type: 'u128'; + }, + { + name: 'fuelMaker'; + type: 'u128'; + }, + { + name: 'fuelTotal'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'fuelSweepRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'userStatsFuelInsurance'; + type: 'u32'; + }, + { + name: 'userStatsFuelDeposits'; + type: 'u32'; + }, + { + name: 'userStatsFuelBorrows'; + type: 'u32'; + }, + { + name: 'userStatsFuelPositions'; + type: 'u32'; + }, + { + name: 'userStatsFuelTaker'; + type: 'u32'; + }, + { + name: 'userStatsFuelMaker'; + type: 'u32'; + }, + { + name: 'fuelOverflowFuelInsurance'; + type: 'u128'; + }, + { + name: 'fuelOverflowFuelDeposits'; + type: 'u128'; + }, + { + name: 'fuelOverflowFuelBorrows'; + type: 'u128'; + }, + { + name: 'fuelOverflowFuelPositions'; + type: 'u128'; + }, + { + name: 'fuelOverflowFuelTaker'; + type: 'u128'; + }, + { + name: 'fuelOverflowFuelMaker'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'fundingPaymentRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'userAuthority'; + type: 'pubkey'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'fundingPayment'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i64'; + }, + { + name: 'baseAssetAmount'; + docs: ['precision: BASE_PRECISION']; + type: 'i64'; + }, + { + name: 'userLastCumulativeFunding'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i64'; + }, + { + name: 'ammCumulativeFundingLong'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + { + name: 'ammCumulativeFundingShort'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + ]; + }; + }, + { + name: 'fundingRateRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'recordId'; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'fundingRate'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i64'; + }, + { + name: 'fundingRateLong'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + { + name: 'fundingRateShort'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + { + name: 'cumulativeFundingRateLong'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + { + name: 'cumulativeFundingRateShort'; + docs: ['precision: FUNDING_RATE_PRECISION']; + type: 'i128'; + }, + { + name: 'oraclePriceTwap'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'markPriceTwap'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'periodRevenue'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i64'; + }, + { + name: 'baseAssetAmountWithAmm'; + docs: ['precision: BASE_PRECISION']; + type: 'i128'; + }, + { + name: 'baseAssetAmountWithUnsettledLp'; + docs: ['precision: BASE_PRECISION']; + type: 'i128'; + }, + ]; + }; + }, + { + name: 'highLeverageModeConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + { + name: 'currentUsers'; + type: 'u32'; + }, + { + name: 'reduceOnly'; + type: 'u8'; + }, + { + name: 'padding1'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'currentMaintenanceUsers'; + type: 'u32'; + }, + { + name: 'padding2'; + type: { + array: ['u8', 24]; + }; + }, + ]; + }; + }, + { + name: 'historicalIndexData'; + type: { + kind: 'struct'; + fields: [ + { + name: 'lastIndexBidPrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'lastIndexAskPrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'lastIndexPriceTwap'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'lastIndexPriceTwap5min'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'lastIndexPriceTwapTs'; + docs: ['unix_timestamp of last snapshot']; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'historicalOracleData'; + type: { + kind: 'struct'; + fields: [ + { + name: 'lastOraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'lastOracleConf'; + docs: ['precision: PRICE_PRECISION']; + type: 'u64'; + }, + { + name: 'lastOracleDelay'; + docs: ['number of slots since last update']; + type: 'i64'; + }, + { + name: 'lastOraclePriceTwap'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'lastOraclePriceTwap5min'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'lastOraclePriceTwapTs'; + docs: ['unix_timestamp of last snapshot']; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'ifRebalanceConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + type: 'pubkey'; + }, + { + name: 'totalInAmount'; + docs: ['total amount to be sold']; + type: 'u64'; + }, + { + name: 'currentInAmount'; + docs: ['amount already sold']; + type: 'u64'; + }, + { + name: 'currentOutAmount'; + docs: ['amount already bought']; + type: 'u64'; + }, + { + name: 'currentOutAmountTransferred'; + docs: ['amount already transferred to revenue pool']; + type: 'u64'; + }, + { + name: 'currentInAmountSinceLastTransfer'; + docs: ['amount already bought in epoch']; + type: 'u64'; + }, + { + name: 'epochStartTs'; + docs: ['start time of epoch']; + type: 'i64'; + }, + { + name: 'epochInAmount'; + docs: ['amount already bought in epoch']; + type: 'u64'; + }, + { + name: 'epochMaxInAmount'; + docs: ['max amount to swap in epoch']; + type: 'u64'; + }, + { + name: 'epochDuration'; + docs: ['duration of epoch']; + type: 'i64'; + }, + { + name: 'outMarketIndex'; + docs: ['market index to sell']; + type: 'u16'; + }, + { + name: 'inMarketIndex'; + docs: ['market index to buy']; + type: 'u16'; + }, + { + name: 'maxSlippageBps'; + type: 'u16'; + }, + { + name: 'swapMode'; + type: 'u8'; + }, + { + name: 'status'; + type: 'u8'; + }, + { + name: 'padding2'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }; + }, + { + name: 'ifRebalanceConfigParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'totalInAmount'; + type: 'u64'; + }, + { + name: 'epochMaxInAmount'; + type: 'u64'; + }, + { + name: 'epochDuration'; + type: 'i64'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'maxSlippageBps'; + type: 'u16'; + }, + { + name: 'swapMode'; + type: 'u8'; + }, + { + name: 'status'; + type: 'u8'; + }, + ]; + }; + }, + { + name: 'insuranceClaim'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'revenueWithdrawSinceLastSettle'; + docs: [ + 'The amount of revenue last settled', + 'Positive if funds left the perp market,', + 'negative if funds were pulled into the perp market', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'maxRevenueWithdrawPerPeriod'; + docs: [ + 'The max amount of revenue that can be withdrawn per period', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'quoteMaxInsurance'; + docs: [ + 'The max amount of insurance that perp market can use to resolve bankruptcy and pnl deficits', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'quoteSettledInsurance'; + docs: [ + 'The amount of insurance that has been used to resolve bankruptcy and pnl deficits', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastRevenueWithdrawTs'; + docs: ['The last time revenue was settled in/out of market']; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'insuranceFund'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'vault'; + type: 'pubkey'; + }, + { + name: 'totalShares'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'userShares'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'sharesBase'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'unstakingPeriod'; + type: 'i64'; + }, + { + name: 'lastRevenueSettleTs'; + type: 'i64'; + }, + { + name: 'revenueSettlePeriod'; + type: 'i64'; + }, + { + name: 'totalFactor'; + type: 'u32'; + }, + { + name: 'userFactor'; + type: 'u32'; + }, + ]; + }; + }, + { + name: 'insuranceFundRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'userIfFactor'; + docs: ['precision: PERCENTAGE_PRECISION']; + type: 'u32'; + }, + { + name: 'totalIfFactor'; + docs: ['precision: PERCENTAGE_PRECISION']; + type: 'u32'; + }, + { + name: 'vaultAmountBefore'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + { + name: 'insuranceVaultAmountBefore'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + { + name: 'totalIfSharesBefore'; + type: 'u128'; + }, + { + name: 'totalIfSharesAfter'; + type: 'u128'; + }, + { + name: 'amount'; + docs: ['precision: token mint precision']; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'insuranceFundStake'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'ifShares'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastWithdrawRequestShares'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'ifBase'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastValidTs'; + type: 'i64'; + }, + { + name: 'lastWithdrawRequestValue'; + type: 'u64'; + }, + { + name: 'lastWithdrawRequestTs'; + type: 'i64'; + }, + { + name: 'costBasis'; + type: 'i64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'padding'; + type: { + array: ['u8', 14]; + }; + }, + ]; + }; + }, + { + name: 'insuranceFundStakeRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'userAuthority'; + type: 'pubkey'; + }, + { + name: 'action'; + type: { + defined: { + name: 'stakeAction'; + }; + }; + }, + { + name: 'amount'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'insuranceVaultAmountBefore'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + { + name: 'ifSharesBefore'; + type: 'u128'; + }, + { + name: 'userIfSharesBefore'; + type: 'u128'; + }, + { + name: 'totalIfSharesBefore'; + type: 'u128'; + }, + { + name: 'ifSharesAfter'; + type: 'u128'; + }, + { + name: 'userIfSharesAfter'; + type: 'u128'; + }, + { + name: 'totalIfSharesAfter'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'insuranceFundSwapRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'rebalanceConfig'; + type: 'pubkey'; + }, + { + name: 'inIfTotalSharesBefore'; + type: 'u128'; + }, + { + name: 'outIfTotalSharesBefore'; + type: 'u128'; + }, + { + name: 'inIfUserSharesBefore'; + type: 'u128'; + }, + { + name: 'outIfUserSharesBefore'; + type: 'u128'; + }, + { + name: 'inIfTotalSharesAfter'; + type: 'u128'; + }, + { + name: 'outIfTotalSharesAfter'; + type: 'u128'; + }, + { + name: 'inIfUserSharesAfter'; + type: 'u128'; + }, + { + name: 'outIfUserSharesAfter'; + type: 'u128'; + }, + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'inAmount'; + type: 'u64'; + }, + { + name: 'outAmount'; + type: 'u64'; + }, + { + name: 'outOraclePrice'; + type: 'u64'; + }, + { + name: 'outOraclePriceTwap'; + type: 'i64'; + }, + { + name: 'inVaultAmountBefore'; + type: 'u64'; + }, + { + name: 'outVaultAmountBefore'; + type: 'u64'; + }, + { + name: 'inFundVaultAmountAfter'; + type: 'u64'; + }, + { + name: 'outFundVaultAmountAfter'; + type: 'u64'; + }, + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + ]; + }; + }, + { + name: 'lpAction'; + type: { + kind: 'enum'; + variants: [ + { + name: 'addLiquidity'; + }, + { + name: 'removeLiquidity'; + }, + { + name: 'settleLiquidity'; + }, + { + name: 'removeLiquidityDerisk'; + }, + ]; + }; + }, + { + name: 'lpBorrowLendDepositRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'slot'; + type: 'u64'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'constituentIndex'; + type: 'u16'; + }, + { + name: 'direction'; + type: { + defined: { + name: 'depositDirection'; + }; + }; + }, + { + name: 'tokenBalance'; + type: 'i64'; + }, + { + name: 'lastTokenBalance'; + type: 'i64'; + }, + { + name: 'interestAccruedTokenAmount'; + type: 'i64'; + }, + { + name: 'amountDepositWithdraw'; + type: 'u64'; + }, + { + name: 'lpPool'; + type: 'pubkey'; + }, + ]; + }; + }, + { + name: 'lpMintRedeemRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'slot'; + type: 'u64'; + }, + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'description'; + type: 'u8'; + }, + { + name: 'amount'; + docs: ['precision: continutent mint precision, gross fees']; + type: 'u128'; + }, + { + name: 'fee'; + docs: [ + 'precision: fee on amount, constituent market mint precision', + ]; + type: 'i128'; + }, + { + name: 'spotMarketIndex'; + type: 'u16'; + }, + { + name: 'constituentIndex'; + type: 'u16'; + }, + { + name: 'oraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'mint'; + docs: ['token mint']; + type: 'pubkey'; + }, + { + name: 'lpAmount'; + docs: ['lp amount, lp mint precision']; + type: 'u64'; + }, + { + name: 'lpFee'; + docs: ['lp fee, lp mint precision']; + type: 'i64'; + }, + { + name: 'lpPrice'; + docs: ['the fair price of the lp token, PRICE_PRECISION']; + type: 'u128'; + }, + { + name: 'mintRedeemId'; + type: 'u64'; + }, + { + name: 'lastAum'; + docs: ['LPPool last_aum']; + type: 'u128'; + }, + { + name: 'lastAumSlot'; + type: 'u64'; + }, + { + name: 'inMarketCurrentWeight'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'inMarketTargetWeight'; + type: 'i64'; + }, + { + name: 'lpPool'; + type: 'pubkey'; + }, + ]; + }; + }, + { + name: 'lpPool'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + docs: ['address of the vault.']; + type: 'pubkey'; + }, + { + name: 'mint'; + type: 'pubkey'; + }, + { + name: 'whitelistMint'; + type: 'pubkey'; + }, + { + name: 'constituentTargetBase'; + type: 'pubkey'; + }, + { + name: 'constituentCorrelations'; + type: 'pubkey'; + }, + { + name: 'maxAum'; + docs: [ + 'The current number of VaultConstituents in the vault, each constituent is pda(LPPool.address, constituent_index)', + 'which constituent is the quote, receives revenue pool distributions. (maybe this should just be implied idx 0)', + 'pub quote_constituent_index: u16,', + 'QUOTE_PRECISION: Max AUM, Prohibit minting new DLP beyond this', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'lastAum'; + docs: ['QUOTE_PRECISION: AUM of the vault in USD, updated lazily']; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeQuoteSentToPerpMarkets'; + docs: ['QUOTE PRECISION: Cumulative quotes from settles']; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeQuoteReceivedFromPerpMarkets'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'totalMintRedeemFeesPaid'; + docs: [ + 'QUOTE_PRECISION: Total fees paid for minting and redeeming LP tokens', + ]; + type: { + defined: { + name: 'i128'; + }; + }; + }, + { + name: 'lastAumSlot'; + docs: ['timestamp of last AUM slot']; + type: 'u64'; + }, + { + name: 'maxSettleQuoteAmount'; + type: 'u64'; + }, + { + name: 'padding'; + docs: ['timestamp of last vAMM revenue rebalance']; + type: 'u64'; + }, + { + name: 'mintRedeemId'; + docs: [ + 'Every mint/redeem has a monotonically increasing id. This is the next id to use', + ]; + type: 'u64'; + }, + { + name: 'settleId'; + type: 'u64'; + }, + { + name: 'minMintFee'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'tokenSupply'; + type: 'u64'; + }, + { + name: 'volatility'; + type: 'u64'; + }, + { + name: 'constituents'; + type: 'u16'; + }, + { + name: 'quoteConsituentIndex'; + type: 'u16'; + }, + { + name: 'bump'; + type: 'u8'; + }, + { + name: 'gammaExecution'; + type: 'u8'; + }, + { + name: 'xi'; + type: 'u8'; + }, + { + name: 'targetOracleDelayFeeBpsPer10Slots'; + type: 'u8'; + }, + { + name: 'targetPositionDelayFeeBpsPer10Slots'; + type: 'u8'; + }, + { + name: 'lpPoolId'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 174]; + }; + }, + ]; + }; + }, + { + name: 'lpRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'action'; + type: { + defined: { + name: 'lpAction'; + }; + }; + }, + { + name: 'nShares'; + docs: ['precision: AMM_RESERVE_PRECISION']; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'deltaBaseAssetAmount'; + docs: ['precision: BASE_PRECISION']; + type: 'i64'; + }, + { + name: 'deltaQuoteAssetAmount'; + docs: ['precision: QUOTE_PRECISION']; + type: 'i64'; + }, + { + name: 'pnl'; + docs: [ + 'realized pnl of the position settlement', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'lpSettleRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'recordId'; + type: 'u64'; + }, + { + name: 'lastTs'; + type: 'i64'; + }, + { + name: 'lastSlot'; + type: 'u64'; + }, + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'slot'; + type: 'u64'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'settleToLpAmount'; + type: 'i64'; + }, + { + name: 'perpAmmPnlDelta'; + type: 'i64'; + }, + { + name: 'perpAmmExFeeDelta'; + type: 'i64'; + }, + { + name: 'lpAum'; + type: 'u128'; + }, + { + name: 'lpPrice'; + type: 'u128'; + }, + { + name: 'lpPool'; + type: 'pubkey'; + }, + ]; + }; + }, + { + name: 'lpSwapRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'slot'; + type: 'u64'; + }, + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'outAmount'; + docs: ['precision: out market mint precision, gross fees']; + type: 'u128'; + }, + { + name: 'inAmount'; + docs: ['precision: in market mint precision, gross fees']; + type: 'u128'; + }, + { + name: 'outFee'; + docs: ['precision: fee on amount_out, in market mint precision']; + type: 'i128'; + }, + { + name: 'inFee'; + docs: ['precision: fee on amount_in, out market mint precision']; + type: 'i128'; + }, + { + name: 'outSpotMarketIndex'; + type: 'u16'; + }, + { + name: 'inSpotMarketIndex'; + type: 'u16'; + }, + { + name: 'outConstituentIndex'; + type: 'u16'; + }, + { + name: 'inConstituentIndex'; + type: 'u16'; + }, + { + name: 'outOraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'inOraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'lastAum'; + docs: ['LPPool last_aum, QUOTE_PRECISION']; + type: 'u128'; + }, + { + name: 'lastAumSlot'; + type: 'u64'; + }, + { + name: 'inMarketCurrentWeight'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'outMarketCurrentWeight'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'inMarketTargetWeight'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'outMarketTargetWeight'; + docs: ['PERCENTAGE_PRECISION']; + type: 'i64'; + }, + { + name: 'inSwapId'; + type: 'u64'; + }, + { + name: 'outSwapId'; + type: 'u64'; + }, + { + name: 'lpPool'; + type: 'pubkey'; + }, + ]; + }; + }, + { + name: 'liquidateBorrowForPerpPnlRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'marketOraclePrice'; + type: 'i64'; + }, + { + name: 'pnlTransfer'; + type: 'u128'; + }, + { + name: 'liabilityMarketIndex'; + type: 'u16'; + }, + { + name: 'liabilityPrice'; + type: 'i64'; + }, + { + name: 'liabilityTransfer'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'liquidatePerpPnlForDepositRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'marketOraclePrice'; + type: 'i64'; + }, + { + name: 'pnlTransfer'; + type: 'u128'; + }, + { + name: 'assetMarketIndex'; + type: 'u16'; + }, + { + name: 'assetPrice'; + type: 'i64'; + }, + { + name: 'assetTransfer'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'liquidatePerpRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'oraclePrice'; + type: 'i64'; + }, + { + name: 'baseAssetAmount'; + type: 'i64'; + }, + { + name: 'quoteAssetAmount'; + type: 'i64'; + }, + { + name: 'lpShares'; + docs: ['precision: AMM_RESERVE_PRECISION']; + type: 'u64'; + }, + { + name: 'fillRecordId'; + type: 'u64'; + }, + { + name: 'userOrderId'; + type: 'u32'; + }, + { + name: 'liquidatorOrderId'; + type: 'u32'; + }, + { + name: 'liquidatorFee'; + docs: ['precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'ifFee'; + docs: ['precision: QUOTE_PRECISION']; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'liquidateSpotRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'assetMarketIndex'; + type: 'u16'; + }, + { + name: 'assetPrice'; + type: 'i64'; + }, + { + name: 'assetTransfer'; + type: 'u128'; + }, + { + name: 'liabilityMarketIndex'; + type: 'u16'; + }, + { + name: 'liabilityPrice'; + type: 'i64'; + }, + { + name: 'liabilityTransfer'; + docs: ['precision: token mint precision']; + type: 'u128'; + }, + { + name: 'ifFee'; + docs: ['precision: token mint precision']; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'liquidationRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'liquidationType'; + type: { + defined: { + name: 'liquidationType'; + }; + }; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'liquidator'; + type: 'pubkey'; + }, + { + name: 'marginRequirement'; + type: 'u128'; + }, + { + name: 'totalCollateral'; + type: 'i128'; + }, + { + name: 'marginFreed'; + type: 'u64'; + }, + { + name: 'liquidationId'; + type: 'u16'; + }, + { + name: 'bankrupt'; + type: 'bool'; + }, + { + name: 'canceledOrderIds'; + type: { + vec: 'u32'; + }; + }, + { + name: 'liquidatePerp'; + type: { + defined: { + name: 'liquidatePerpRecord'; + }; + }; + }, + { + name: 'liquidateSpot'; + type: { + defined: { + name: 'liquidateSpotRecord'; + }; + }; + }, + { + name: 'liquidateBorrowForPerpPnl'; + type: { + defined: { + name: 'liquidateBorrowForPerpPnlRecord'; + }; + }; + }, + { + name: 'liquidatePerpPnlForDeposit'; + type: { + defined: { + name: 'liquidatePerpPnlForDepositRecord'; + }; + }; + }, + { + name: 'perpBankruptcy'; + type: { + defined: { + name: 'perpBankruptcyRecord'; + }; + }; + }, + { + name: 'spotBankruptcy'; + type: { + defined: { + name: 'spotBankruptcyRecord'; + }; + }; + }, + ]; + }; + }, + { + name: 'liquidationType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'liquidatePerp'; + }, + { + name: 'liquidateSpot'; + }, + { + name: 'liquidateBorrowForPerpPnl'; + }, + { + name: 'liquidatePerpPnlForDeposit'; + }, + { + name: 'perpBankruptcy'; + }, + { + name: 'spotBankruptcy'; + }, + ]; + }; + }, + { + name: 'lpPoolParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'maxSettleQuoteAmount'; + type: { + option: 'u64'; + }; + }, + { + name: 'volatility'; + type: { + option: 'u64'; + }; + }, + { + name: 'gammaExecution'; + type: { + option: 'u8'; + }; + }, + { + name: 'xi'; + type: { + option: 'u8'; + }; + }, + { + name: 'maxAum'; + type: { + option: 'u128'; + }; + }, + { + name: 'whitelistMint'; + type: { + option: 'pubkey'; + }; + }, + ]; + }; + }, + { + name: 'marginMode'; + type: { + kind: 'enum'; + variants: [ + { + name: 'default'; + }, + { + name: 'highLeverage'; + }, + { + name: 'highLeverageMaintenance'; + }, + ]; + }; + }, + { + name: 'marketStatus'; + type: { + kind: 'enum'; + variants: [ + { + name: 'initialized'; + }, + { + name: 'active'; + }, + { + name: 'fundingPaused'; + }, + { + name: 'ammPaused'; + }, + { + name: 'fillPaused'; + }, + { + name: 'withdrawPaused'; + }, + { + name: 'reduceOnly'; + }, + { + name: 'settlement'; + }, + { + name: 'delisted'; + }, + ]; + }; + }, + { + name: 'marketType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'spot'; + }, + { + name: 'perp'; + }, + ]; + }; + }, + { + name: 'modifyOrderParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'direction'; + type: { + option: { + defined: { + name: 'positionDirection'; + }; + }; + }; + }, + { + name: 'baseAssetAmount'; + type: { + option: 'u64'; + }; + }, + { + name: 'price'; + type: { + option: 'u64'; + }; + }, + { + name: 'reduceOnly'; + type: { + option: 'bool'; + }; + }, + { + name: 'postOnly'; + type: { + option: { + defined: { + name: 'postOnlyParam'; + }; + }; + }; + }, + { + name: 'bitFlags'; + type: { + option: 'u8'; + }; + }, + { + name: 'maxTs'; + type: { + option: 'i64'; + }; + }, + { + name: 'triggerPrice'; + type: { + option: 'u64'; + }; + }, + { + name: 'triggerCondition'; + type: { + option: { + defined: { + name: 'orderTriggerCondition'; + }; + }; + }; + }, + { + name: 'oraclePriceOffset'; + type: { + option: 'i32'; + }; + }, + { + name: 'auctionDuration'; + type: { + option: 'u8'; + }; + }, + { + name: 'auctionStartPrice'; + type: { + option: 'i64'; + }; + }, + { + name: 'auctionEndPrice'; + type: { + option: 'i64'; + }; + }, + { + name: 'policy'; + type: { + option: 'u8'; + }; + }, + ]; + }; + }, + { + name: 'newUserRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + docs: ['unix_timestamp of action']; + type: 'i64'; + }, + { + name: 'userAuthority'; + type: 'pubkey'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'subAccountId'; + type: 'u16'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'referrer'; + type: 'pubkey'; + }, + ]; + }; + }, + { + name: 'openbookV2FulfillmentConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + type: 'pubkey'; + }, + { + name: 'openbookV2ProgramId'; + type: 'pubkey'; + }, + { + name: 'openbookV2Market'; + type: 'pubkey'; + }, + { + name: 'openbookV2MarketAuthority'; + type: 'pubkey'; + }, + { + name: 'openbookV2EventHeap'; + type: 'pubkey'; + }, + { + name: 'openbookV2Bids'; + type: 'pubkey'; + }, + { + name: 'openbookV2Asks'; + type: 'pubkey'; + }, + { + name: 'openbookV2BaseVault'; + type: 'pubkey'; + }, + { + name: 'openbookV2QuoteVault'; + type: 'pubkey'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'fulfillmentType'; + type: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }, + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + ]; + }; + }, + { + name: 'oracleGuardRails'; + type: { + kind: 'struct'; + fields: [ + { + name: 'priceDivergence'; + type: { + defined: { + name: 'priceDivergenceGuardRails'; + }; + }; + }, + { + name: 'validity'; + type: { + defined: { + name: 'validityGuardRails'; + }; + }; + }, + ]; + }; + }, + { + name: 'oracleSource'; + type: { + kind: 'enum'; + variants: [ + { + name: 'pyth'; + }, + { + name: 'switchboard'; + }, + { + name: 'quoteAsset'; + }, + { + name: 'pyth1K'; + }, + { + name: 'pyth1M'; + }, + { + name: 'pythStableCoin'; + }, + { + name: 'prelaunch'; + }, + { + name: 'pythPull'; + }, + { + name: 'pyth1KPull'; + }, + { + name: 'pyth1MPull'; + }, + { + name: 'pythStableCoinPull'; + }, + { + name: 'switchboardOnDemand'; + }, + { + name: 'pythLazer'; + }, + { + name: 'pythLazer1K'; + }, + { + name: 'pythLazer1M'; + }, + { + name: 'pythLazerStableCoin'; + }, + ]; + }; + }, + { + name: 'order'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'slot'; + docs: ['The slot the order was placed']; + type: 'u64'; + }, + { + name: 'price'; + docs: [ + 'The limit price for the order (can be 0 for market orders)', + "For orders with an auction, this price isn't used until the auction is complete", + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'baseAssetAmount'; + docs: [ + 'The size of the order', + 'precision for perps: BASE_PRECISION', + 'precision for spot: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'baseAssetAmountFilled'; + docs: [ + 'The amount of the order filled', + 'precision for perps: BASE_PRECISION', + 'precision for spot: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'quoteAssetAmountFilled'; + docs: [ + 'The amount of quote filled for the order', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'triggerPrice'; + docs: [ + 'At what price the order will be triggered. Only relevant for trigger orders', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'auctionStartPrice'; + docs: [ + 'The start price for the auction. Only relevant for market/oracle orders', + 'precision: PRICE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'auctionEndPrice'; + docs: [ + 'The end price for the auction. Only relevant for market/oracle orders', + 'precision: PRICE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'maxTs'; + docs: ['The time when the order will expire']; + type: 'i64'; + }, + { + name: 'oraclePriceOffset'; + docs: [ + 'If set, the order limit price is the oracle price + this offset', + 'precision: PRICE_PRECISION', + ]; + type: 'i32'; + }, + { + name: 'orderId'; + docs: [ + 'The id for the order. Each users has their own order id space', + ]; + type: 'u32'; + }, + { + name: 'marketIndex'; + docs: ['The perp/spot market index']; + type: 'u16'; + }, + { + name: 'status'; + docs: ['Whether the order is open or unused']; + type: { + defined: { + name: 'orderStatus'; + }; + }; + }, + { + name: 'orderType'; + docs: ['The type of order']; + type: { + defined: { + name: 'orderType'; + }; + }; + }, + { + name: 'marketType'; + docs: ['Whether market is spot or perp']; + type: { + defined: { + name: 'marketType'; + }; + }; + }, + { + name: 'userOrderId'; + docs: [ + 'User generated order id. Can make it easier to place/cancel orders', + ]; + type: 'u8'; + }, + { + name: 'existingPositionDirection'; + docs: ['What the users position was when the order was placed']; + type: { + defined: { + name: 'positionDirection'; + }; + }; + }, + { + name: 'direction'; + docs: [ + 'Whether the user is going long or short. LONG = bid, SHORT = ask', + ]; + type: { + defined: { + name: 'positionDirection'; + }; + }; + }, + { + name: 'reduceOnly'; + docs: ['Whether the order is allowed to only reduce position size']; + type: 'bool'; + }, + { + name: 'postOnly'; + docs: ['Whether the order must be a maker']; + type: 'bool'; + }, + { + name: 'immediateOrCancel'; + docs: [ + 'Whether the order must be canceled the same slot it is placed', + ]; + type: 'bool'; + }, + { + name: 'triggerCondition'; + docs: [ + 'Whether the order is triggered above or below the trigger price. Only relevant for trigger orders', + ]; + type: { + defined: { + name: 'orderTriggerCondition'; + }; + }; + }, + { + name: 'auctionDuration'; + docs: ['How many slots the auction lasts']; + type: 'u8'; + }, + { + name: 'postedSlotTail'; + docs: [ + 'Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)', + ]; + type: 'u8'; + }, + { + name: 'bitFlags'; + docs: [ + 'Bitflags for further classification', + '0: is_signed_message', + ]; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 1]; + }; + }, + ]; + }; + }, + { + name: 'orderAction'; + type: { + kind: 'enum'; + variants: [ + { + name: 'place'; + }, + { + name: 'cancel'; + }, + { + name: 'fill'; + }, + { + name: 'trigger'; + }, + { + name: 'expire'; + }, + ]; + }; + }, + { + name: 'orderActionExplanation'; + type: { + kind: 'enum'; + variants: [ + { + name: 'none'; + }, + { + name: 'insufficientFreeCollateral'; + }, + { + name: 'oraclePriceBreachedLimitPrice'; + }, + { + name: 'marketOrderFilledToLimitPrice'; + }, + { + name: 'orderExpired'; + }, + { + name: 'liquidation'; + }, + { + name: 'orderFilledWithAmm'; + }, + { + name: 'orderFilledWithAmmJit'; + }, + { + name: 'orderFilledWithMatch'; + }, + { + name: 'orderFilledWithMatchJit'; + }, + { + name: 'marketExpired'; + }, + { + name: 'riskingIncreasingOrder'; + }, + { + name: 'reduceOnlyOrderIncreasedPosition'; + }, + { + name: 'orderFillWithSerum'; + }, + { + name: 'noBorrowLiquidity'; + }, + { + name: 'orderFillWithPhoenix'; + }, + { + name: 'orderFilledWithAmmJitLpSplit'; + }, + { + name: 'orderFilledWithLpJit'; + }, + { + name: 'deriskLp'; + }, + { + name: 'orderFilledWithOpenbookV2'; + }, + { + name: 'transferPerpPosition'; + }, + ]; + }; + }, + { + name: 'orderActionRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'action'; + type: { + defined: { + name: 'orderAction'; + }; + }; + }, + { + name: 'actionExplanation'; + type: { + defined: { + name: 'orderActionExplanation'; + }; + }; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'marketType'; + type: { + defined: { + name: 'marketType'; + }; + }; + }, + { + name: 'filler'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'fillerReward'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'fillRecordId'; + type: { + option: 'u64'; + }; + }, + { + name: 'baseAssetAmountFilled'; + docs: ['precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)']; + type: { + option: 'u64'; + }; + }, + { + name: 'quoteAssetAmountFilled'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'takerFee'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'makerFee'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'i64'; + }; + }, + { + name: 'referrerReward'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u32'; + }; + }, + { + name: 'quoteAssetAmountSurplus'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'i64'; + }; + }, + { + name: 'spotFulfillmentMethodFee'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'taker'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'takerOrderId'; + type: { + option: 'u32'; + }; + }, + { + name: 'takerOrderDirection'; + type: { + option: { + defined: { + name: 'positionDirection'; + }; + }; + }; + }, + { + name: 'takerOrderBaseAssetAmount'; + docs: ['precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)']; + type: { + option: 'u64'; + }; + }, + { + name: 'takerOrderCumulativeBaseAssetAmountFilled'; + docs: ['precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)']; + type: { + option: 'u64'; + }; + }, + { + name: 'takerOrderCumulativeQuoteAssetAmountFilled'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'maker'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'makerOrderId'; + type: { + option: 'u32'; + }; + }, + { + name: 'makerOrderDirection'; + type: { + option: { + defined: { + name: 'positionDirection'; + }; + }; + }; + }, + { + name: 'makerOrderBaseAssetAmount'; + docs: ['precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)']; + type: { + option: 'u64'; + }; + }, + { + name: 'makerOrderCumulativeBaseAssetAmountFilled'; + docs: ['precision: BASE_PRECISION (perp) or MINT_PRECISION (spot)']; + type: { + option: 'u64'; + }; + }, + { + name: 'makerOrderCumulativeQuoteAssetAmountFilled'; + docs: ['precision: QUOTE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'oraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'bitFlags'; + docs: ['Bit flags:', '0: is_signed_message']; + type: 'u8'; + }, + { + name: 'takerExistingQuoteEntryAmount'; + docs: [ + 'precision: QUOTE_PRECISION', + 'Only Some if the taker reduced position', + ]; + type: { + option: 'u64'; + }; + }, + { + name: 'takerExistingBaseAssetAmount'; + docs: [ + 'precision: BASE_PRECISION', + 'Only Some if the taker flipped position direction', + ]; + type: { + option: 'u64'; + }; + }, + { + name: 'makerExistingQuoteEntryAmount'; + docs: [ + 'precision: QUOTE_PRECISION', + 'Only Some if the maker reduced position', + ]; + type: { + option: 'u64'; + }; + }, + { + name: 'makerExistingBaseAssetAmount'; + docs: [ + 'precision: BASE_PRECISION', + 'Only Some if the maker flipped position direction', + ]; + type: { + option: 'u64'; + }; + }, + { + name: 'triggerPrice'; + docs: ['precision: PRICE_PRECISION']; + type: { + option: 'u64'; + }; + }, + { + name: 'builderIdx'; + docs: [ + "the idx of the builder in the taker's [`RevenueShareEscrow`] account", + ]; + type: { + option: 'u8'; + }; + }, + { + name: 'builderFee'; + docs: ['precision: QUOTE_PRECISION builder fee paid by the taker']; + type: { + option: 'u64'; + }; + }, + ]; + }; + }, + { + name: 'orderFillerRewardStructure'; + type: { + kind: 'struct'; + fields: [ + { + name: 'rewardNumerator'; + type: 'u32'; + }, + { + name: 'rewardDenominator'; + type: 'u32'; + }, + { + name: 'timeBasedRewardLowerBound'; + type: { + defined: { + name: 'u128'; + }; + }; + }, + ]; + }; + }, + { + name: 'orderParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'orderType'; + type: { + defined: { + name: 'orderType'; + }; + }; + }, + { + name: 'marketType'; + type: { + defined: { + name: 'marketType'; + }; + }; + }, + { + name: 'direction'; + type: { + defined: { + name: 'positionDirection'; + }; + }; + }, + { + name: 'userOrderId'; + type: 'u8'; + }, + { + name: 'baseAssetAmount'; + type: 'u64'; + }, + { + name: 'price'; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'reduceOnly'; + type: 'bool'; + }, + { + name: 'postOnly'; + type: { + defined: { + name: 'postOnlyParam'; + }; + }; + }, + { + name: 'bitFlags'; + type: 'u8'; + }, + { + name: 'maxTs'; + type: { + option: 'i64'; + }; + }, + { + name: 'triggerPrice'; + type: { + option: 'u64'; + }; + }, + { + name: 'triggerCondition'; + type: { + defined: { + name: 'orderTriggerCondition'; + }; + }; + }, + { + name: 'oraclePriceOffset'; + type: { + option: 'i32'; + }; + }, + { + name: 'auctionDuration'; + type: { + option: 'u8'; + }; + }, + { + name: 'auctionStartPrice'; + type: { + option: 'i64'; + }; + }, + { + name: 'auctionEndPrice'; + type: { + option: 'i64'; + }; + }, + ]; + }; + }, + { + name: 'orderRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'order'; + type: { + defined: { + name: 'order'; + }; + }; + }, + ]; + }; + }, + { + name: 'orderStatus'; + type: { + kind: 'enum'; + variants: [ + { + name: 'init'; + }, + { + name: 'open'; + }, + { + name: 'filled'; + }, + { + name: 'canceled'; + }, + ]; + }; + }, + { + name: 'orderTriggerCondition'; + type: { + kind: 'enum'; + variants: [ + { + name: 'above'; + }, + { + name: 'below'; + }, + { + name: 'triggeredAbove'; + }, + { + name: 'triggeredBelow'; + }, + ]; + }; + }, + { + name: 'orderType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'market'; + }, + { + name: 'limit'; + }, + { + name: 'triggerMarket'; + }, + { + name: 'triggerLimit'; + }, + { + name: 'oracle'; + }, + ]; + }; + }, + { + name: 'overrideAmmCacheParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'quoteOwedFromLpPool'; + type: { + option: 'i64'; + }; + }, + { + name: 'lastSettleSlot'; + type: { + option: 'u64'; + }; + }, + { + name: 'lastFeePoolTokenAmount'; + type: { + option: 'u128'; + }; + }, + { + name: 'lastNetPnlPoolTokenAmount'; + type: { + option: 'i128'; + }; + }, + { + name: 'ammPositionScalar'; + type: { + option: 'u8'; + }; + }, + { + name: 'ammInventoryLimit'; + type: { + option: 'i64'; + }; + }, + ]; + }; + }, + { + name: 'perpBankruptcyRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'pnl'; + type: 'i128'; + }, + { + name: 'ifPayment'; + type: 'u128'; + }, + { + name: 'clawbackUser'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'clawbackUserPayment'; + type: { + option: 'u128'; + }; + }, + { + name: 'cumulativeFundingRateDelta'; + type: 'i128'; + }, + ]; + }; + }, + { + name: 'perpMarket'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + docs: [ + "The perp market's address. It is a pda of the market index", + ]; + type: 'pubkey'; + }, + { + name: 'amm'; + docs: ['The automated market maker']; + type: { + defined: { + name: 'amm'; + }; + }; + }, + { + name: 'pnlPool'; + docs: [ + "The market's pnl pool. When users settle negative pnl, the balance increases.", + 'When users settle positive pnl, the balance decreases. Can not go negative.', + ]; + type: { + defined: { + name: 'poolBalance'; + }; + }; + }, + { + name: 'name'; + docs: ['Encoded display name for the perp market e.g. SOL-PERP']; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'insuranceClaim'; + docs: ["The perp market's claim on the insurance fund"]; + type: { + defined: { + name: 'insuranceClaim'; + }; + }; + }, + { + name: 'unrealizedPnlMaxImbalance'; + docs: [ + 'The max pnl imbalance before positive pnl asset weight is discounted', + "pnl imbalance is the difference between long and short pnl. When it's greater than 0,", + 'the amm has negative pnl and the initial asset weight for positive pnl is discounted', + 'precision = QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'expiryTs'; + docs: [ + 'The ts when the market will be expired. Only set if market is in reduce only mode', + ]; + type: 'i64'; + }, + { + name: 'expiryPrice'; + docs: [ + 'The price at which positions will be settled. Only set if market is expired', + 'precision = PRICE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'nextFillRecordId'; + docs: [ + 'Every trade has a fill record id. This is the next id to be used', + ]; + type: 'u64'; + }, + { + name: 'nextFundingRateRecordId'; + docs: [ + 'Every funding rate update has a record id. This is the next id to be used', + ]; + type: 'u64'; + }, + { + name: 'nextCurveRecordId'; + docs: [ + 'Every amm k updated has a record id. This is the next id to be used', + ]; + type: 'u64'; + }, + { + name: 'imfFactor'; + docs: [ + 'The initial margin fraction factor. Used to increase margin ratio for large positions', + 'precision: MARGIN_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'unrealizedPnlImfFactor'; + docs: [ + 'The imf factor for unrealized pnl. Used to discount asset weight for large positive pnl', + 'precision: MARGIN_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'liquidatorFee'; + docs: [ + 'The fee the liquidator is paid for taking over perp position', + 'precision: LIQUIDATOR_FEE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + docs: [ + 'The fee the insurance fund receives from liquidation', + 'precision: LIQUIDATOR_FEE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'marginRatioInitial'; + docs: [ + 'The margin ratio which determines how much collateral is required to open a position', + 'e.g. margin ratio of .1 means a user must have $100 of total collateral to open a $1000 position', + 'precision: MARGIN_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'marginRatioMaintenance'; + docs: [ + 'The margin ratio which determines when a user will be liquidated', + 'e.g. margin ratio of .05 means a user must have $50 of total collateral to maintain a $1000 position', + 'else they will be liquidated', + 'precision: MARGIN_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'unrealizedPnlInitialAssetWeight'; + docs: [ + 'The initial asset weight for positive pnl. Negative pnl always has an asset weight of 1', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'unrealizedPnlMaintenanceAssetWeight'; + docs: [ + 'The maintenance asset weight for positive pnl. Negative pnl always has an asset weight of 1', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'numberOfUsersWithBase'; + docs: ['number of users in a position (base)']; + type: 'u32'; + }, + { + name: 'numberOfUsers'; + docs: ['number of users in a position (pnl) or pnl (quote)']; + type: 'u32'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'status'; + docs: [ + 'Whether a market is active, reduce only, expired, etc', + 'Affects whether users can open/close positions', + ]; + type: { + defined: { + name: 'marketStatus'; + }; + }; + }, + { + name: 'contractType'; + docs: ['Currently only Perpetual markets are supported']; + type: { + defined: { + name: 'contractType'; + }; + }; + }, + { + name: 'contractTier'; + docs: [ + 'The contract tier determines how much insurance a market can receive, with more speculative markets receiving less insurance', + 'It also influences the order perp markets can be liquidated, with less speculative markets being liquidated first', + ]; + type: { + defined: { + name: 'contractTier'; + }; + }; + }, + { + name: 'pausedOperations'; + type: 'u8'; + }, + { + name: 'quoteSpotMarketIndex'; + docs: ['The spot market that pnl is settled in']; + type: 'u16'; + }, + { + name: 'feeAdjustment'; + docs: [ + 'Between -100 and 100, represents what % to increase/decrease the fee by', + 'E.g. if this is -50 and the fee is 5bps, the new fee will be 2.5bps', + 'if this is 50 and the fee is 5bps, the new fee will be 7.5bps', + ]; + type: 'i16'; + }, + { + name: 'fuelBoostPosition'; + docs: ['fuel multiplier for perp funding', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostTaker'; + docs: ['fuel multiplier for perp taker', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostMaker'; + docs: ['fuel multiplier for perp maker', 'precision: 10']; + type: 'u8'; + }, + { + name: 'poolId'; + type: 'u8'; + }, + { + name: 'highLeverageMarginRatioInitial'; + type: 'u16'; + }, + { + name: 'highLeverageMarginRatioMaintenance'; + type: 'u16'; + }, + { + name: 'protectedMakerLimitPriceDivisor'; + type: 'u8'; + }, + { + name: 'protectedMakerDynamicDivisor'; + type: 'u8'; + }, + { + name: 'lpFeeTransferScalar'; + type: 'u8'; + }, + { + name: 'lpStatus'; + type: 'u8'; + }, + { + name: 'lpPausedOperations'; + type: 'u8'; + }, + { + name: 'lpExchangeFeeExcluscionScalar'; + type: 'u8'; + }, + { + name: 'lastFillPrice'; + type: 'u64'; + }, + { + name: 'lpPoolId'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 23]; + }; + }, + ]; + }; + }, + { + name: 'perpPosition'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'lastCumulativeFundingRate'; + docs: [ + "The perp market's last cumulative funding rate. Used to calculate the funding payment owed to user", + 'precision: FUNDING_RATE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'baseAssetAmount'; + docs: [ + 'the size of the users perp position', + 'precision: BASE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'quoteAssetAmount'; + docs: [ + 'Used to calculate the users pnl. Upon entry, is equal to base_asset_amount * avg entry price - fees', + 'Updated when the user open/closes position or settles pnl. Includes fees/funding', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'quoteBreakEvenAmount'; + docs: [ + 'The amount of quote the user would need to exit their position at to break even', + 'Updated when the user open/closes position or settles pnl. Includes fees/funding', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'quoteEntryAmount'; + docs: [ + 'The amount quote the user entered the position with. Equal to base asset amount * avg entry price', + 'Updated when the user open/closes position. Excludes fees/funding', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'openBids'; + docs: [ + 'The amount of non reduce only trigger orders the user has open', + 'precision: BASE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'openAsks'; + docs: [ + 'The amount of non reduce only trigger orders the user has open', + 'precision: BASE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'settledPnl'; + docs: [ + 'The amount of pnl settled in this market since opening the position', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lpShares'; + docs: [ + 'The number of lp (liquidity provider) shares the user has in this perp market', + 'LP shares allow users to provide liquidity via the AMM', + 'precision: BASE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastBaseAssetAmountPerLp'; + docs: [ + 'The last base asset amount per lp the amm had', + 'Used to settle the users lp position', + 'precision: BASE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'lastQuoteAssetAmountPerLp'; + docs: [ + 'The last quote asset amount per lp the amm had', + 'Used to settle the users lp position', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'padding'; + type: { + array: ['u8', 2]; + }; + }, + { + name: 'maxMarginRatio'; + type: 'u16'; + }, + { + name: 'marketIndex'; + docs: ['The market index for the perp market']; + type: 'u16'; + }, + { + name: 'openOrders'; + docs: ['The number of open orders']; + type: 'u8'; + }, + { + name: 'perLpBase'; + type: 'i8'; + }, + ]; + }; + }, + { + name: 'phoenixV1FulfillmentConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + type: 'pubkey'; + }, + { + name: 'phoenixProgramId'; + type: 'pubkey'; + }, + { + name: 'phoenixLogAuthority'; + type: 'pubkey'; + }, + { + name: 'phoenixMarket'; + type: 'pubkey'; + }, + { + name: 'phoenixBaseVault'; + type: 'pubkey'; + }, + { + name: 'phoenixQuoteVault'; + type: 'pubkey'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'fulfillmentType'; + type: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }, + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + ]; + }; + }, + { + name: 'poolBalance'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'scaledBalance'; + docs: [ + "To get the pool's token amount, you must multiply the scaled balance by the market's cumulative", + 'deposit interest', + 'precision: SPOT_BALANCE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'marketIndex'; + docs: ['The spot market the pool is for']; + type: 'u16'; + }, + { + name: 'padding'; + type: { + array: ['u8', 6]; + }; + }, + ]; + }; + }, + { + name: 'positionDirection'; + type: { + kind: 'enum'; + variants: [ + { + name: 'long'; + }, + { + name: 'short'; + }, + ]; + }; + }, + { + name: 'postOnlyParam'; + type: { + kind: 'enum'; + variants: [ + { + name: 'none'; + }, + { + name: 'mustPostOnly'; + }, + { + name: 'tryPostOnly'; + }, + { + name: 'slide'; + }, + ]; + }; + }, + { + name: 'prelaunchOracle'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'price'; + type: 'i64'; + }, + { + name: 'maxPrice'; + type: 'i64'; + }, + { + name: 'confidence'; + type: 'u64'; + }, + { + name: 'lastUpdateSlot'; + type: 'u64'; + }, + { + name: 'ammLastUpdateSlot'; + type: 'u64'; + }, + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'padding'; + type: { + array: ['u8', 70]; + }; + }, + ]; + }; + }, + { + name: 'prelaunchOracleParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'perpMarketIndex'; + type: 'u16'; + }, + { + name: 'price'; + type: { + option: 'i64'; + }; + }, + { + name: 'maxPrice'; + type: { + option: 'i64'; + }; + }, + ]; + }; + }, + { + name: 'priceDivergenceGuardRails'; + type: { + kind: 'struct'; + fields: [ + { + name: 'markOraclePercentDivergence'; + type: 'u64'; + }, + { + name: 'oracleTwap5minPercentDivergence'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'protectedMakerModeConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'maxUsers'; + type: 'u32'; + }, + { + name: 'currentUsers'; + type: 'u32'; + }, + { + name: 'reduceOnly'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 31]; + }; + }, + ]; + }; + }, + { + name: 'pythLazerOracle'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'price'; + type: 'i64'; + }, + { + name: 'publishTime'; + type: 'u64'; + }, + { + name: 'postedSlot'; + type: 'u64'; + }, + { + name: 'exponent'; + type: 'i32'; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + { + name: 'conf'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'referrerName'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + type: 'pubkey'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'userStats'; + type: 'pubkey'; + }, + { + name: 'name'; + type: { + array: ['u8', 32]; + }; + }, + ]; + }; + }, + { + name: 'revenueShare'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'rust'; + packed: true; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + docs: ['the owner of this account, a builder or referrer']; + type: 'pubkey'; + }, + { + name: 'totalReferrerRewards'; + type: 'u64'; + }, + { + name: 'totalBuilderRewards'; + type: 'u64'; + }, + { + name: 'padding'; + type: { + array: ['u8', 18]; + }; + }, + ]; + }; + }, + { + name: 'revenueShareEscrow'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + docs: ['the owner of this account, a user']; + type: 'pubkey'; + }, + { + name: 'referrer'; + type: 'pubkey'; + }, + { + name: 'referrerBoostExpireTs'; + type: 'u32'; + }, + { + name: 'referrerRewardOffset'; + type: 'i8'; + }, + { + name: 'refereeFeeNumeratorOffset'; + type: 'i8'; + }, + { + name: 'referrerBoostNumerator'; + type: 'i8'; + }, + { + name: 'reservedFixed'; + type: { + array: ['u8', 17]; + }; + }, + { + name: 'padding0'; + type: 'u32'; + }, + { + name: 'orders'; + type: { + vec: { + defined: { + name: 'revenueShareOrder'; + }; + }; + }; + }, + { + name: 'padding1'; + type: 'u32'; + }, + { + name: 'approvedBuilders'; + type: { + vec: { + defined: { + name: 'builderInfo'; + }; + }; + }; + }, + ]; + }; + }, + { + name: 'revenueShareOrder'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'feesAccrued'; + docs: [ + 'fees accrued so far for this order slot. This is not exclusively fees from this order_id', + 'and may include fees from other orders in the same market. This may be swept to the', + "builder's SpotPosition during settle_pnl.", + ]; + type: 'u64'; + }, + { + name: 'orderId'; + docs: [ + "the order_id of the current active order in this slot. It's only relevant while bit_flag = Open", + ]; + type: 'u32'; + }, + { + name: 'feeTenthBps'; + docs: [ + 'the builder fee on this order, in tenths of a bps, e.g. 100 = 0.01%', + ]; + type: 'u16'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'subAccountId'; + docs: [ + "the subaccount_id of the user who created this order. It's only relevant while bit_flag = Open", + ]; + type: 'u16'; + }, + { + name: 'builderIdx'; + docs: [ + "the index of the RevenueShareEscrow.approved_builders list, that this order's fee will settle to. Ignored", + 'if bit_flag = Referral.', + ]; + type: 'u8'; + }, + { + name: 'bitFlags'; + docs: [ + 'bitflags that describe the state of the order.', + '[`RevenueShareOrderBitFlag::Init`]: this order slot is available for use.', + "[`RevenueShareOrderBitFlag::Open`]: this order slot is occupied, `order_id` is the `sub_account_id`'s active order.", + '[`RevenueShareOrderBitFlag::Completed`]: this order has been filled or canceled, and is waiting to be settled into.', + "the builder's account order_id and sub_account_id are no longer relevant, it may be merged with other orders.", + '[`RevenueShareOrderBitFlag::Referral`]: this order stores referral rewards waiting to be settled for this market.', + 'If it is set, no other bitflag should be set.', + ]; + type: 'u8'; + }, + { + name: 'userOrderIndex'; + docs: [ + "the index into the User's orders list when this RevenueShareOrder was created, make sure to verify that order_id matches.", + ]; + type: 'u8'; + }, + { + name: 'marketType'; + type: { + defined: { + name: 'marketType'; + }; + }; + }, + { + name: 'padding'; + type: { + array: ['u8', 10]; + }; + }, + ]; + }; + }, + { + name: 'revenueShareSettleRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'builder'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'referrer'; + type: { + option: 'pubkey'; + }; + }, + { + name: 'feeSettled'; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'marketType'; + type: { + defined: { + name: 'marketType'; + }; + }; + }, + { + name: 'builderSubAccountId'; + type: 'u16'; + }, + { + name: 'builderTotalReferrerRewards'; + type: 'u64'; + }, + { + name: 'builderTotalBuilderRewards'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'serumV3FulfillmentConfig'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + type: 'pubkey'; + }, + { + name: 'serumProgramId'; + type: 'pubkey'; + }, + { + name: 'serumMarket'; + type: 'pubkey'; + }, + { + name: 'serumRequestQueue'; + type: 'pubkey'; + }, + { + name: 'serumEventQueue'; + type: 'pubkey'; + }, + { + name: 'serumBids'; + type: 'pubkey'; + }, + { + name: 'serumAsks'; + type: 'pubkey'; + }, + { + name: 'serumBaseVault'; + type: 'pubkey'; + }, + { + name: 'serumQuoteVault'; + type: 'pubkey'; + }, + { + name: 'serumOpenOrders'; + type: 'pubkey'; + }, + { + name: 'serumSignerNonce'; + type: 'u64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'fulfillmentType'; + type: { + defined: { + name: 'spotFulfillmentType'; + }; + }; + }, + { + name: 'status'; + type: { + defined: { + name: 'spotFulfillmentConfigStatus'; + }; + }; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + ]; + }; + }, + { + name: 'settlePnlExplanation'; + type: { + kind: 'enum'; + variants: [ + { + name: 'none'; + }, + { + name: 'expiredPosition'; + }, + ]; + }; + }, + { + name: 'settlePnlMode'; + type: { + kind: 'enum'; + variants: [ + { + name: 'mustSettle'; + }, + { + name: 'trySettle'; + }, + ]; + }; + }, + { + name: 'settlePnlRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'pnl'; + type: 'i128'; + }, + { + name: 'baseAssetAmount'; + type: 'i64'; + }, + { + name: 'quoteAssetAmountAfter'; + type: 'i64'; + }, + { + name: 'quoteEntryAmount'; + type: 'i64'; + }, + { + name: 'settlePrice'; + type: 'i64'; + }, + { + name: 'explanation'; + type: { + defined: { + name: 'settlePnlExplanation'; + }; + }; + }, + ]; + }; + }, + { + name: 'signedMsgOrderId'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'uuid'; + type: { + array: ['u8', 8]; + }; + }, + { + name: 'maxSlot'; + type: 'u64'; + }, + { + name: 'orderId'; + type: 'u32'; + }, + { + name: 'padding'; + type: 'u32'; + }, + ]; + }; + }, + { + name: 'signedMsgOrderRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'hash'; + type: 'string'; + }, + { + name: 'matchingOrderParams'; + type: { + defined: { + name: 'orderParams'; + }; + }; + }, + { + name: 'userOrderId'; + type: 'u32'; + }, + { + name: 'signedMsgOrderMaxSlot'; + type: 'u64'; + }, + { + name: 'signedMsgOrderUuid'; + type: { + array: ['u8', 8]; + }; + }, + { + name: 'ts'; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'signedMsgUserOrders'; + docs: [ + '* This struct is a duplicate of SignedMsgUserOrdersZeroCopy\n * It is used to give anchor an struct to generate the idl for clients\n * The struct SignedMsgUserOrdersZeroCopy is used to load the data in efficiently', + ]; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authorityPubkey'; + type: 'pubkey'; + }, + { + name: 'padding'; + type: 'u32'; + }, + { + name: 'signedMsgOrderData'; + type: { + vec: { + defined: { + name: 'signedMsgOrderId'; + }; + }; + }; + }, + ]; + }; + }, + { + name: 'signedMsgWsDelegates'; + docs: [ + '* Used to store authenticated delegates for swift-like ws connections', + ]; + type: { + kind: 'struct'; + fields: [ + { + name: 'delegates'; + type: { + vec: 'pubkey'; + }; + }, + ]; + }; + }, + { + name: 'spotBalanceType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'deposit'; + }, + { + name: 'borrow'; + }, + ]; + }; + }, + { + name: 'spotBankruptcyRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'borrowAmount'; + type: 'u128'; + }, + { + name: 'ifPayment'; + type: 'u128'; + }, + { + name: 'cumulativeDepositInterestDelta'; + type: 'u128'; + }, + ]; + }; + }, + { + name: 'spotFulfillmentConfigStatus'; + type: { + kind: 'enum'; + variants: [ + { + name: 'enabled'; + }, + { + name: 'disabled'; + }, + ]; + }; + }, + { + name: 'spotFulfillmentType'; + type: { + kind: 'enum'; + variants: [ + { + name: 'serumV3'; + }, + { + name: 'match'; + }, + { + name: 'phoenixV1'; + }, + { + name: 'openbookV2'; + }, + ]; + }; + }, + { + name: 'spotInterestRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'depositBalance'; + docs: ['precision: SPOT_BALANCE_PRECISION']; + type: 'u128'; + }, + { + name: 'cumulativeDepositInterest'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'borrowBalance'; + docs: ['precision: SPOT_BALANCE_PRECISION']; + type: 'u128'; + }, + { + name: 'cumulativeBorrowInterest'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'optimalUtilization'; + docs: ['precision: PERCENTAGE_PRECISION']; + type: 'u32'; + }, + { + name: 'optimalBorrowRate'; + docs: ['precision: PERCENTAGE_PRECISION']; + type: 'u32'; + }, + { + name: 'maxBorrowRate'; + docs: ['precision: PERCENTAGE_PRECISION']; + type: 'u32'; + }, + ]; + }; + }, + { + name: 'spotMarket'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'pubkey'; + docs: [ + 'The address of the spot market. It is a pda of the market index', + ]; + type: 'pubkey'; + }, + { + name: 'oracle'; + docs: ['The oracle used to price the markets deposits/borrows']; + type: 'pubkey'; + }, + { + name: 'mint'; + docs: ['The token mint of the market']; + type: 'pubkey'; + }, + { + name: 'vault'; + docs: [ + "The vault used to store the market's deposits", + 'The amount in the vault should be equal to or greater than deposits - borrows', + ]; + type: 'pubkey'; + }, + { + name: 'name'; + docs: ['The encoded display name for the market e.g. SOL']; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'historicalOracleData'; + type: { + defined: { + name: 'historicalOracleData'; + }; + }; + }, + { + name: 'historicalIndexData'; + type: { + defined: { + name: 'historicalIndexData'; + }; + }; + }, + { + name: 'revenuePool'; + docs: [ + 'Revenue the protocol has collected in this markets token', + 'e.g. for SOL-PERP, funds can be settled in usdc and will flow into the USDC revenue pool', + ]; + type: { + defined: { + name: 'poolBalance'; + }; + }; + }, + { + name: 'spotFeePool'; + docs: [ + 'The fees collected from swaps between this market and the quote market', + 'Is settled to the quote markets revenue pool', + ]; + type: { + defined: { + name: 'poolBalance'; + }; + }; + }, + { + name: 'insuranceFund'; + docs: [ + 'Details on the insurance fund covering bankruptcies in this markets token', + 'Covers bankruptcies for borrows with this markets token and perps settling in this markets token', + ]; + type: { + defined: { + name: 'insuranceFund'; + }; + }; + }, + { + name: 'totalSpotFee'; + docs: [ + 'The total spot fees collected for this market', + 'precision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'depositBalance'; + docs: [ + 'The sum of the scaled balances for deposits across users and pool balances', + 'To convert to the deposit token amount, multiply by the cumulative deposit interest', + 'precision: SPOT_BALANCE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'borrowBalance'; + docs: [ + 'The sum of the scaled balances for borrows across users and pool balances', + 'To convert to the borrow token amount, multiply by the cumulative borrow interest', + 'precision: SPOT_BALANCE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeDepositInterest'; + docs: [ + 'The cumulative interest earned by depositors', + 'Used to calculate the deposit token amount from the deposit balance', + 'precision: SPOT_CUMULATIVE_INTEREST_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'cumulativeBorrowInterest'; + docs: [ + 'The cumulative interest earned by borrowers', + 'Used to calculate the borrow token amount from the borrow balance', + 'precision: SPOT_CUMULATIVE_INTEREST_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'totalSocialLoss'; + docs: [ + "The total socialized loss from borrows, in the mint's token", + 'precision: token mint precision', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'totalQuoteSocialLoss'; + docs: [ + "The total socialized loss from borrows, in the quote market's token", + 'preicision: QUOTE_PRECISION', + ]; + type: { + defined: { + name: 'u128'; + }; + }; + }, + { + name: 'withdrawGuardThreshold'; + docs: [ + 'no withdraw limits/guards when deposits below this threshold', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'maxTokenDeposits'; + docs: [ + 'The max amount of token deposits in this market', + '0 if there is no limit', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'depositTokenTwap'; + docs: [ + '24hr average of deposit token amount', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'borrowTokenTwap'; + docs: [ + '24hr average of borrow token amount', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'utilizationTwap'; + docs: [ + '24hr average of utilization', + 'which is borrow amount over token amount', + 'precision: SPOT_UTILIZATION_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastInterestTs'; + docs: [ + 'Last time the cumulative deposit and borrow interest was updated', + ]; + type: 'u64'; + }, + { + name: 'lastTwapTs'; + docs: [ + 'Last time the deposit/borrow/utilization averages were updated', + ]; + type: 'u64'; + }, + { + name: 'expiryTs'; + docs: [ + 'The time the market is set to expire. Only set if market is in reduce only mode', + ]; + type: 'i64'; + }, + { + name: 'orderStepSize'; + docs: [ + 'Spot orders must be a multiple of the step size', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'orderTickSize'; + docs: [ + 'Spot orders must be a multiple of the tick size', + 'precision: PRICE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'minOrderSize'; + docs: ['The minimum order size', 'precision: token mint precision']; + type: 'u64'; + }, + { + name: 'maxPositionSize'; + docs: [ + 'The maximum spot position size', + 'if the limit is 0, there is no limit', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'nextFillRecordId'; + docs: [ + 'Every spot trade has a fill record id. This is the next id to use', + ]; + type: 'u64'; + }, + { + name: 'nextDepositRecordId'; + docs: [ + 'Every deposit has a deposit record id. This is the next id to use', + ]; + type: 'u64'; + }, + { + name: 'initialAssetWeight'; + docs: [ + 'The initial asset weight used to calculate a deposits contribution to a users initial total collateral', + 'e.g. if the asset weight is .8, $100 of deposits contributes $80 to the users initial total collateral', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'maintenanceAssetWeight'; + docs: [ + 'The maintenance asset weight used to calculate a deposits contribution to a users maintenance total collateral', + 'e.g. if the asset weight is .9, $100 of deposits contributes $90 to the users maintenance total collateral', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'initialLiabilityWeight'; + docs: [ + 'The initial liability weight used to calculate a borrows contribution to a users initial margin requirement', + 'e.g. if the liability weight is .9, $100 of borrows contributes $90 to the users initial margin requirement', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'maintenanceLiabilityWeight'; + docs: [ + 'The maintenance liability weight used to calculate a borrows contribution to a users maintenance margin requirement', + 'e.g. if the liability weight is .8, $100 of borrows contributes $80 to the users maintenance margin requirement', + 'precision: SPOT_WEIGHT_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'imfFactor'; + docs: [ + 'The initial margin fraction factor. Used to increase liability weight/decrease asset weight for large positions', + 'precision: MARGIN_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'liquidatorFee'; + docs: [ + 'The fee the liquidator is paid for taking over borrow/deposit', + 'precision: LIQUIDATOR_FEE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'ifLiquidationFee'; + docs: [ + 'The fee the insurance fund receives from liquidation', + 'precision: LIQUIDATOR_FEE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'optimalUtilization'; + docs: [ + 'The optimal utilization rate for this market.', + 'Used to determine the markets borrow rate', + 'precision: SPOT_UTILIZATION_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'optimalBorrowRate'; + docs: [ + 'The borrow rate for this market when the market has optimal utilization', + 'precision: SPOT_RATE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'maxBorrowRate'; + docs: [ + 'The borrow rate for this market when the market has 1000 utilization', + 'precision: SPOT_RATE_PRECISION', + ]; + type: 'u32'; + }, + { + name: 'decimals'; + docs: [ + "The market's token mint's decimals. To from decimals to a precision, 10^decimals", + ]; + type: 'u32'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'ordersEnabled'; + docs: ['Whether or not spot trading is enabled']; + type: 'bool'; + }, + { + name: 'oracleSource'; + type: { + defined: { + name: 'oracleSource'; + }; + }; + }, + { + name: 'status'; + type: { + defined: { + name: 'marketStatus'; + }; + }; + }, + { + name: 'assetTier'; + docs: [ + 'The asset tier affects how a deposit can be used as collateral and the priority for a borrow being liquidated', + ]; + type: { + defined: { + name: 'assetTier'; + }; + }; + }, + { + name: 'pausedOperations'; + type: 'u8'; + }, + { + name: 'ifPausedOperations'; + type: 'u8'; + }, + { + name: 'feeAdjustment'; + type: 'i16'; + }, + { + name: 'maxTokenBorrowsFraction'; + docs: [ + 'What fraction of max_token_deposits', + 'disabled when 0, 1 => 1/10000 => .01% of max_token_deposits', + 'precision: X/10000', + ]; + type: 'u16'; + }, + { + name: 'flashLoanAmount'; + docs: [ + 'For swaps, the amount of token loaned out in the begin_swap ix', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'flashLoanInitialTokenAmount'; + docs: [ + 'For swaps, the amount in the users token account in the begin_swap ix', + 'Used to calculate how much of the token left the system in end_swap ix', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'totalSwapFee'; + docs: [ + 'The total fees received from swaps', + 'precision: token mint precision', + ]; + type: 'u64'; + }, + { + name: 'scaleInitialAssetWeightStart'; + docs: [ + 'When to begin scaling down the initial asset weight', + 'disabled when 0', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'minBorrowRate'; + docs: [ + 'The min borrow rate for this market when the market regardless of utilization', + '1 => 1/200 => .5%', + 'precision: X/200', + ]; + type: 'u8'; + }, + { + name: 'fuelBoostDeposits'; + docs: ['fuel multiplier for spot deposits', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostBorrows'; + docs: ['fuel multiplier for spot borrows', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostTaker'; + docs: ['fuel multiplier for spot taker', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostMaker'; + docs: ['fuel multiplier for spot maker', 'precision: 10']; + type: 'u8'; + }, + { + name: 'fuelBoostInsurance'; + docs: ['fuel multiplier for spot insurance stake', 'precision: 10']; + type: 'u8'; + }, + { + name: 'tokenProgramFlag'; + type: 'u8'; + }, + { + name: 'poolId'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 40]; + }; + }, + ]; + }; + }, + { + name: 'spotMarketVaultDepositRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'depositBalance'; + docs: ['precision: SPOT_BALANCE_PRECISION']; + type: 'u128'; + }, + { + name: 'cumulativeDepositInterestBefore'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'cumulativeDepositInterestAfter'; + docs: ['precision: SPOT_CUMULATIVE_INTEREST_PRECISION']; + type: 'u128'; + }, + { + name: 'depositTokenAmountBefore'; + type: 'u64'; + }, + { + name: 'amount'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'spotPosition'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'scaledBalance'; + docs: [ + 'The scaled balance of the position. To get the token amount, multiply by the cumulative deposit/borrow', + 'interest of corresponding market.', + 'precision: SPOT_BALANCE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'openBids'; + docs: [ + 'How many spot non reduce only trigger orders the user has open', + 'precision: token mint precision', + ]; + type: 'i64'; + }, + { + name: 'openAsks'; + docs: [ + 'How many spot non reduce only trigger orders the user has open', + 'precision: token mint precision', + ]; + type: 'i64'; + }, + { + name: 'cumulativeDeposits'; + docs: [ + 'The cumulative deposits/borrows a user has made into a market', + 'precision: token mint precision', + ]; + type: 'i64'; + }, + { + name: 'marketIndex'; + docs: ['The market index of the corresponding spot market']; + type: 'u16'; + }, + { + name: 'balanceType'; + docs: ['Whether the position is deposit or borrow']; + type: { + defined: { + name: 'spotBalanceType'; + }; + }; + }, + { + name: 'openOrders'; + docs: ['Number of open orders']; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + ]; + }; + }, + { + name: 'stakeAction'; + type: { + kind: 'enum'; + variants: [ + { + name: 'stake'; + }, + { + name: 'unstakeRequest'; + }, + { + name: 'unstakeCancelRequest'; + }, + { + name: 'unstake'; + }, + { + name: 'unstakeTransfer'; + }, + { + name: 'stakeTransfer'; + }, + { + name: 'adminDeposit'; + }, + ]; + }; + }, + { + name: 'state'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'admin'; + type: 'pubkey'; + }, + { + name: 'whitelistMint'; + type: 'pubkey'; + }, + { + name: 'discountMint'; + type: 'pubkey'; + }, + { + name: 'signer'; + type: 'pubkey'; + }, + { + name: 'srmVault'; + type: 'pubkey'; + }, + { + name: 'perpFeeStructure'; + type: { + defined: { + name: 'feeStructure'; + }; + }; + }, + { + name: 'spotFeeStructure'; + type: { + defined: { + name: 'feeStructure'; + }; + }; + }, + { + name: 'oracleGuardRails'; + type: { + defined: { + name: 'oracleGuardRails'; + }; + }; + }, + { + name: 'numberOfAuthorities'; + type: 'u64'; + }, + { + name: 'numberOfSubAccounts'; + type: 'u64'; + }, + { + name: 'lpCooldownTime'; + type: 'u64'; + }, + { + name: 'liquidationMarginBufferRatio'; + type: 'u32'; + }, + { + name: 'settlementDuration'; + type: 'u16'; + }, + { + name: 'numberOfMarkets'; + type: 'u16'; + }, + { + name: 'numberOfSpotMarkets'; + type: 'u16'; + }, + { + name: 'signerNonce'; + type: 'u8'; + }, + { + name: 'minPerpAuctionDuration'; + type: 'u8'; + }, + { + name: 'defaultMarketOrderTimeInForce'; + type: 'u8'; + }, + { + name: 'defaultSpotAuctionDuration'; + type: 'u8'; + }, + { + name: 'exchangeStatus'; + type: 'u8'; + }, + { + name: 'liquidationDuration'; + type: 'u8'; + }, + { + name: 'initialPctToLiquidate'; + type: 'u16'; + }, + { + name: 'maxNumberOfSubAccounts'; + type: 'u16'; + }, + { + name: 'maxInitializeUserFee'; + type: 'u16'; + }, + { + name: 'featureBitFlags'; + type: 'u8'; + }, + { + name: 'lpPoolFeatureBitFlags'; + type: 'u8'; + }, + { + name: 'padding'; + type: { + array: ['u8', 8]; + }; + }, + ]; + }; + }, + { + name: 'swapRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'user'; + type: 'pubkey'; + }, + { + name: 'amountOut'; + docs: ['precision: out market mint precision']; + type: 'u64'; + }, + { + name: 'amountIn'; + docs: ['precision: in market mint precision']; + type: 'u64'; + }, + { + name: 'outMarketIndex'; + type: 'u16'; + }, + { + name: 'inMarketIndex'; + type: 'u16'; + }, + { + name: 'outOraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'inOraclePrice'; + docs: ['precision: PRICE_PRECISION']; + type: 'i64'; + }, + { + name: 'fee'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'swapReduceOnly'; + type: { + kind: 'enum'; + variants: [ + { + name: 'in'; + }, + { + name: 'out'; + }, + ]; + }; + }, + { + name: 'targetsDatum'; + serialization: 'bytemuck'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'costToTradeBps'; + type: 'i32'; + }, + { + name: 'padding'; + type: { + array: ['u8', 4]; + }; + }, + { + name: 'targetBase'; + type: 'i64'; + }, + { + name: 'lastOracleSlot'; + type: 'u64'; + }, + { + name: 'lastPositionSlot'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'transferProtocolIfSharesToRevenuePoolRecord'; + type: { + kind: 'struct'; + fields: [ + { + name: 'ts'; + type: 'i64'; + }, + { + name: 'marketIndex'; + type: 'u16'; + }, + { + name: 'amount'; + type: 'u64'; + }, + { + name: 'shares'; + type: 'u128'; + }, + { + name: 'ifVaultAmountBefore'; + type: 'u64'; + }, + { + name: 'protocolSharesBefore'; + type: 'u128'; + }, + { + name: 'transferAmount'; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'updatePerpMarketSummaryStatsParams'; + type: { + kind: 'struct'; + fields: [ + { + name: 'quoteAssetAmountWithUnsettledLp'; + type: { + option: 'i64'; + }; + }, + { + name: 'netUnsettledFundingPnl'; + type: { + option: 'i64'; + }; + }, + { + name: 'updateAmmSummaryStats'; + type: { + option: 'bool'; + }; + }, + { + name: 'excludeTotalLiqFee'; + type: { + option: 'bool'; + }; + }, + ]; + }; + }, + { + name: 'user'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + docs: ['The owner/authority of the account']; + type: 'pubkey'; + }, + { + name: 'delegate'; + docs: [ + "An addresses that can control the account on the authority's behalf. Has limited power, cant withdraw", + ]; + type: 'pubkey'; + }, + { + name: 'name'; + docs: ['Encoded display name e.g. "toly"']; + type: { + array: ['u8', 32]; + }; + }, + { + name: 'spotPositions'; + docs: ["The user's spot positions"]; + type: { + array: [ + { + defined: { + name: 'spotPosition'; + }; + }, + 8, + ]; + }; + }, + { + name: 'perpPositions'; + docs: ["The user's perp positions"]; + type: { + array: [ + { + defined: { + name: 'perpPosition'; + }; + }, + 8, + ]; + }; + }, + { + name: 'orders'; + docs: ["The user's orders"]; + type: { + array: [ + { + defined: { + name: 'order'; + }; + }, + 32, + ]; + }; + }, + { + name: 'lastAddPerpLpSharesTs'; + docs: ['The last time the user added perp lp positions']; + type: 'i64'; + }, + { + name: 'totalDeposits'; + docs: [ + 'The total values of deposits the user has made', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'totalWithdraws'; + docs: [ + 'The total values of withdrawals the user has made', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'totalSocialLoss'; + docs: [ + 'The total socialized loss the users has incurred upon the protocol', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'settledPerpPnl'; + docs: [ + 'Fees (taker fees, maker rebate, referrer reward, filler reward) and pnl for perps', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'cumulativeSpotFees'; + docs: [ + 'Fees (taker fees, maker rebate, filler reward) for spot', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'cumulativePerpFunding'; + docs: [ + 'Cumulative funding paid/received for perps', + 'precision: QUOTE_PRECISION', + ]; + type: 'i64'; + }, + { + name: 'liquidationMarginFreed'; + docs: [ + 'The amount of margin freed during liquidation. Used to force the liquidation to occur over a period of time', + 'Defaults to zero when not being liquidated', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastActiveSlot'; + docs: [ + 'The last slot a user was active. Used to determine if a user is idle', + ]; + type: 'u64'; + }, + { + name: 'nextOrderId'; + docs: [ + 'Every user order has an order id. This is the next order id to be used', + ]; + type: 'u32'; + }, + { + name: 'maxMarginRatio'; + docs: ['Custom max initial margin ratio for the user']; + type: 'u32'; + }, + { + name: 'nextLiquidationId'; + docs: ['The next liquidation id to be used for user']; + type: 'u16'; + }, + { + name: 'subAccountId'; + docs: ['The sub account id for this user']; + type: 'u16'; + }, + { + name: 'status'; + docs: ['Whether the user is active, being liquidated or bankrupt']; + type: 'u8'; + }, + { + name: 'isMarginTradingEnabled'; + docs: ['Whether the user has enabled margin trading']; + type: 'bool'; + }, + { + name: 'idle'; + docs: [ + "User is idle if they haven't interacted with the protocol in 1 week and they have no orders, perp positions or borrows", + 'Off-chain keeper bots can ignore users that are idle', + ]; + type: 'bool'; + }, + { + name: 'openOrders'; + docs: ['number of open orders']; + type: 'u8'; + }, + { + name: 'hasOpenOrder'; + docs: ['Whether or not user has open order']; + type: 'bool'; + }, + { + name: 'openAuctions'; + docs: ['number of open orders with auction']; + type: 'u8'; + }, + { + name: 'hasOpenAuction'; + docs: ['Whether or not user has open order with auction']; + type: 'bool'; + }, + { + name: 'marginMode'; + type: { + defined: { + name: 'marginMode'; + }; + }; + }, + { + name: 'poolId'; + type: 'u8'; + }, + { + name: 'padding1'; + type: { + array: ['u8', 3]; + }; + }, + { + name: 'lastFuelBonusUpdateTs'; + type: 'u32'; + }, + { + name: 'padding'; + type: { + array: ['u8', 12]; + }; + }, + ]; + }; + }, + { + name: 'userFees'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'totalFeePaid'; + docs: ['Total taker fee paid', 'precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'totalFeeRebate'; + docs: ['Total maker fee rebate', 'precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'totalTokenDiscount'; + docs: [ + 'Total discount from holding token', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'totalRefereeDiscount'; + docs: [ + 'Total discount from being referred', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'totalReferrerReward'; + docs: ['Total reward to referrer', 'precision: QUOTE_PRECISION']; + type: 'u64'; + }, + { + name: 'currentEpochReferrerReward'; + docs: [ + 'Total reward to referrer this epoch', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + ]; + }; + }, + { + name: 'userStats'; + serialization: 'bytemuckunsafe'; + repr: { + kind: 'c'; + }; + type: { + kind: 'struct'; + fields: [ + { + name: 'authority'; + docs: ['The authority for all of a users sub accounts']; + type: 'pubkey'; + }, + { + name: 'referrer'; + docs: ['The address that referred this user']; + type: 'pubkey'; + }, + { + name: 'fees'; + docs: ['Stats on the fees paid by the user']; + type: { + defined: { + name: 'userFees'; + }; + }; + }, + { + name: 'nextEpochTs'; + docs: [ + 'The timestamp of the next epoch', + 'Epoch is used to limit referrer rewards earned in single epoch', + ]; + type: 'i64'; + }, + { + name: 'makerVolume30d'; + docs: [ + 'Rolling 30day maker volume for user', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'takerVolume30d'; + docs: [ + 'Rolling 30day taker volume for user', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'fillerVolume30d'; + docs: [ + 'Rolling 30day filler volume for user', + 'precision: QUOTE_PRECISION', + ]; + type: 'u64'; + }, + { + name: 'lastMakerVolume30dTs'; + docs: ['last time the maker volume was updated']; + type: 'i64'; + }, + { + name: 'lastTakerVolume30dTs'; + docs: ['last time the taker volume was updated']; + type: 'i64'; + }, + { + name: 'lastFillerVolume30dTs'; + docs: ['last time the filler volume was updated']; + type: 'i64'; + }, + { + name: 'ifStakedQuoteAssetAmount'; + docs: ['The amount of tokens staked in the quote spot markets if']; + type: 'u64'; + }, + { + name: 'numberOfSubAccounts'; + docs: ['The current number of sub accounts']; + type: 'u16'; + }, + { + name: 'numberOfSubAccountsCreated'; + docs: [ + 'The number of sub accounts created. Can be greater than the number of sub accounts if user', + 'has deleted sub accounts', + ]; + type: 'u16'; + }, + { + name: 'referrerStatus'; + docs: [ + 'Flags for referrer status:', + 'First bit (LSB): 1 if user is a referrer, 0 otherwise', + 'Second bit: 1 if user was referred, 0 otherwise', + ]; + type: 'u8'; + }, + { + name: 'disableUpdatePerpBidAskTwap'; + type: 'u8'; + }, + { + name: 'pausedOperations'; + type: 'u8'; + }, + { + name: 'fuelOverflowStatus'; + docs: ['whether the user has a FuelOverflow account']; + type: 'u8'; + }, + { + name: 'fuelInsurance'; + docs: ['accumulated fuel for token amounts of insurance']; + type: 'u32'; + }, + { + name: 'fuelDeposits'; + docs: ['accumulated fuel for notional of deposits']; + type: 'u32'; + }, + { + name: 'fuelBorrows'; + docs: ['accumulate fuel bonus for notional of borrows']; + type: 'u32'; + }, + { + name: 'fuelPositions'; + docs: ['accumulated fuel for perp open interest']; + type: 'u32'; + }, + { + name: 'fuelTaker'; + docs: ['accumulate fuel bonus for taker volume']; + type: 'u32'; + }, + { + name: 'fuelMaker'; + docs: ['accumulate fuel bonus for maker volume']; + type: 'u32'; + }, + { + name: 'ifStakedGovTokenAmount'; + docs: [ + 'The amount of tokens staked in the governance spot markets if', + ]; + type: 'u64'; + }, + { + name: 'lastFuelIfBonusUpdateTs'; + docs: [ + 'last unix ts user stats data was used to update if fuel (u32 to save space)', + ]; + type: 'u32'; + }, + { + name: 'padding'; + type: { + array: ['u8', 12]; + }; + }, + ]; + }; + }, + { + name: 'validityGuardRails'; + type: { + kind: 'struct'; + fields: [ + { + name: 'slotsBeforeStaleForAmm'; + type: 'i64'; + }, + { + name: 'slotsBeforeStaleForMargin'; + type: 'i64'; + }, + { + name: 'confidenceIntervalMaxSize'; + type: 'u64'; + }, + { + name: 'tooVolatileRatio'; + type: 'i64'; + }, + ]; + }; + }, + { + name: 'i128'; + docs: ['`i128` with legacy bit layout']; + type: { + kind: 'struct'; + fields: [ + { + array: ['u8', 16]; + }, + ]; + }; + }, + { + name: 'u128'; + docs: ['`u128` with legacy bit layout']; + type: { + kind: 'struct'; + fields: [ + { + array: ['u8', 16]; + }, + ]; + }; + }, + ]; +}; diff --git a/sdk/src/marinade/index.ts b/sdk/src/marinade/index.ts index 3818408da3..7d0dac39bf 100644 --- a/sdk/src/marinade/index.ts +++ b/sdk/src/marinade/index.ts @@ -1,4 +1,4 @@ -import { AnchorProvider, BN, Program } from '@coral-xyz/anchor'; +import { AnchorProvider, BN, Program } from '@coral-xyz/anchor-29'; import { MarinadeFinance, IDL } from './types'; import { PublicKey, diff --git a/sdk/src/memcmp.ts b/sdk/src/memcmp.ts index c73d21efdb..d43d517156 100644 --- a/sdk/src/memcmp.ts +++ b/sdk/src/memcmp.ts @@ -1,6 +1,6 @@ import { MemcmpFilter, PublicKey } from '@solana/web3.js'; import bs58 from 'bs58'; -import { BorshAccountsCoder } from '@coral-xyz/anchor'; +import { BorshAccountsCoder } from '@coral-xyz/anchor-29'; import { encodeName } from './userName'; export function getUserFilter(): MemcmpFilter { diff --git a/sdk/src/openbook/openbookV2Subscriber.ts b/sdk/src/openbook/openbookV2Subscriber.ts index 39348252ca..37ea79cf4f 100644 --- a/sdk/src/openbook/openbookV2Subscriber.ts +++ b/sdk/src/openbook/openbookV2Subscriber.ts @@ -1,7 +1,7 @@ import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { BulkAccountLoader } from '../accounts/bulkAccountLoader'; import { PRICE_PRECISION } from '../constants/numericConstants'; -import { AnchorProvider, BN, Idl, Program, Wallet } from '@coral-xyz/anchor'; +import { AnchorProvider, BN, Idl, Program, Wallet } from '@coral-xyz/anchor-29'; import { L2Level, L2OrderBookGenerator } from '../dlob/orderBookLevels'; import { Market, OpenBookV2Client } from '@openbook-dex/openbook-v2'; import openbookV2Idl from '../idl/openbook.json'; diff --git a/sdk/src/oracles/oracleClientCache.ts b/sdk/src/oracles/oracleClientCache.ts index 96ee3c78b5..472e2beb2a 100644 --- a/sdk/src/oracles/oracleClientCache.ts +++ b/sdk/src/oracles/oracleClientCache.ts @@ -3,6 +3,7 @@ import { OracleSource } from '../types'; import { getOracleClient } from '../factory/oracleClient'; import { Connection } from '@solana/web3.js'; import { Program } from '@coral-xyz/anchor'; +import { Drift } from '../idl/drift'; export class OracleClientCache { cache = new Map(); @@ -11,7 +12,7 @@ export class OracleClientCache { public get( oracleSource: OracleSource, connection: Connection, - program: Program + program: Program ) { const key = Object.keys(oracleSource)[0]; if (this.cache.has(key)) { diff --git a/sdk/src/oracles/prelaunchOracleClient.ts b/sdk/src/oracles/prelaunchOracleClient.ts index e3147e9f82..3a55f9fc7d 100644 --- a/sdk/src/oracles/prelaunchOracleClient.ts +++ b/sdk/src/oracles/prelaunchOracleClient.ts @@ -2,12 +2,13 @@ import { Connection, PublicKey } from '@solana/web3.js'; import { OracleClient, OraclePriceData } from './types'; import { Program } from '@coral-xyz/anchor'; import { PrelaunchOracle } from '../types'; +import { Drift } from '../idl/drift'; export class PrelaunchOracleClient implements OracleClient { private connection: Connection; - private program: Program; + private program: Program; - public constructor(connection: Connection, program: Program) { + public constructor(connection: Connection, program: Program) { this.connection = connection; this.program = program; } diff --git a/sdk/src/oracles/pythLazerClient.ts b/sdk/src/oracles/pythLazerClient.ts index 9e341215db..bbf077092b 100644 --- a/sdk/src/oracles/pythLazerClient.ts +++ b/sdk/src/oracles/pythLazerClient.ts @@ -7,15 +7,15 @@ import { QUOTE_PRECISION, TEN, } from '../constants/numericConstants'; -import { DRIFT_PROGRAM_ID } from '../config'; import { Wallet } from '../wallet'; import driftIDL from '../idl/drift.json'; +import { Drift } from '../idl/drift'; export class PythLazerClient implements OracleClient { private connection: Connection; private multiple: BN; private stableCoin: boolean; - private program: Program; + private program: Program; readonly decodeFunc: (name: string, data: Buffer) => any; public constructor( @@ -34,11 +34,7 @@ export class PythLazerClient implements OracleClient { commitment: connection.commitment, } ); - this.program = new Program( - driftIDL as Idl, - new PublicKey(DRIFT_PROGRAM_ID), - provider - ); + this.program = new Program(driftIDL as Idl, provider); this.decodeFunc = this.program.account.pythLazerOracle.coder.accounts.decodeUnchecked.bind( this.program.account.pythLazerOracle.coder.accounts diff --git a/sdk/src/oracles/pythPullClient.ts b/sdk/src/oracles/pythPullClient.ts index 0359b35928..7ac96ac8b1 100644 --- a/sdk/src/oracles/pythPullClient.ts +++ b/sdk/src/oracles/pythPullClient.ts @@ -1,6 +1,6 @@ import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import { OracleClient, OraclePriceData } from './types'; -import { AnchorProvider, BN, Program } from '@coral-xyz/anchor'; +import { AnchorProvider, BN, Program } from '@coral-xyz/anchor-29'; import { ONE, PRICE_PRECISION, diff --git a/sdk/src/oracles/switchboardClient.ts b/sdk/src/oracles/switchboardClient.ts index 775bc74570..bd3036a3f1 100644 --- a/sdk/src/oracles/switchboardClient.ts +++ b/sdk/src/oracles/switchboardClient.ts @@ -2,7 +2,7 @@ import { Connection, PublicKey } from '@solana/web3.js'; import { PRICE_PRECISION, TEN } from '../constants/numericConstants'; import { OracleClient, OraclePriceData } from './types'; import switchboardV2Idl from '../idl/switchboard.json'; -import { BorshAccountsCoder, BN, Idl } from '@coral-xyz/anchor'; +import { BorshAccountsCoder, BN, Idl } from '@coral-xyz/anchor-29'; type SwitchboardDecimal = { scale: number; diff --git a/sdk/src/oracles/switchboardOnDemandClient.ts b/sdk/src/oracles/switchboardOnDemandClient.ts index aaeb6ac003..ff99740d60 100644 --- a/sdk/src/oracles/switchboardOnDemandClient.ts +++ b/sdk/src/oracles/switchboardOnDemandClient.ts @@ -1,12 +1,12 @@ import { Connection, PublicKey } from '@solana/web3.js'; import { OracleClient, OraclePriceData } from './types'; -import { BN } from '@coral-xyz/anchor'; import switchboardOnDemandIdl from '../idl/switchboard_on_demand_30.json'; import { PRICE_PRECISION_EXP } from '../constants/numericConstants'; import { + BN, BorshAccountsCoder as BorshAccountsCoder30, Idl as Idl30, -} from '@coral-xyz/anchor-30'; +} from '@coral-xyz/anchor'; const SB_PRECISION_EXP = new BN(18); const SB_PRECISION = new BN(10).pow(SB_PRECISION_EXP.sub(PRICE_PRECISION_EXP)); diff --git a/sdk/src/tokenFaucet.ts b/sdk/src/tokenFaucet.ts index f110283143..e8331a71f7 100644 --- a/sdk/src/tokenFaucet.ts +++ b/sdk/src/tokenFaucet.ts @@ -1,5 +1,5 @@ import * as anchor from '@coral-xyz/anchor'; -import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor'; +import { AnchorProvider, Idl, Program } from '@coral-xyz/anchor-29'; import { TOKEN_PROGRAM_ID, Account, diff --git a/sdk/src/types.ts b/sdk/src/types.ts index ea111ce0c5..1cc160d2d2 100644 --- a/sdk/src/types.ts +++ b/sdk/src/types.ts @@ -1137,13 +1137,11 @@ export type PerpPosition = { openAsks: BN; settledPnl: BN; lpShares: BN; - /** TODO: remove this field - it doesn't exist on chain */ - remainderBaseAssetAmount: number; + positionFlag: number; maxMarginRatio: number; lastQuoteAssetAmountPerLp: BN; perLpBase: number; isolatedPositionScaledBalance: BN; - positionFlag: number; }; export class PositionFlag { @@ -1167,7 +1165,7 @@ export type UserStatsAccount = { totalTokenDiscount: BN; totalRefereeDiscount: BN; totalReferrerReward: BN; - current_epoch_referrer_reward: BN; + currentEpochReferrerReward: BN; }; referrer: PublicKey; referrerStatus: number; @@ -1186,6 +1184,77 @@ export type UserStatsAccount = { ifStakedGovTokenAmount: BN; }; +export function parseUserStatsAccount(account: { + makerVolume30d: BN; + takerVolume30d: BN; + fillerVolume30d: BN; + lastMakerVolume30dTs: BN; + lastTakerVolume30dTs: BN; + lastFillerVolume30dTs: BN; + [key: string]: any; +}): UserStatsAccount { + return { + ...account, + makerVolume30D: account.makerVolume30d, + takerVolume30D: account.takerVolume30d, + fillerVolume30D: account.fillerVolume30d, + lastMakerVolume30DTs: account.lastMakerVolume30dTs, + lastTakerVolume30DTs: account.lastTakerVolume30dTs, + lastFillerVolume30DTs: account.lastFillerVolume30dTs, + } as unknown as UserStatsAccount; +} + +/** + * Parses an Anchor-generated AMM account to the SDK's AMM type. + * Handles field name mappings and provides defaults for missing fields. + */ +export function parseAMM(amm: { + last24hAvgFundingRate?: BN; + lastMarkPriceTwap5min?: BN; + volume24h?: BN; + cumulativeFundingRate?: BN; + cumulativeFundingRateLong?: BN; + cumulativeFundingRateShort?: BN; + [key: string]: any; +}): AMM { + return { + ...amm, + last24HAvgFundingRate: + amm.last24HAvgFundingRate ?? amm.last24hAvgFundingRate ?? ZERO, + lastMarkPriceTwap5Min: + amm.lastMarkPriceTwap5Min ?? amm.lastMarkPriceTwap5min ?? ZERO, + volume24H: amm.volume24H ?? amm.volume24h ?? ZERO, + // TODO: map to long/short + cumulativeFundingRate: ZERO, + } as unknown as AMM; +} + +/** + * Parses an Anchor-generated PerpMarket account to the SDK's PerpMarketAccount type. + * Handles field name mappings and provides defaults for missing fields. + */ +export function parsePerpMarketAccount(account: { + amm?: any; + [key: string]: any; +}): PerpMarketAccount { + return { + ...account, + amm: account.amm ? parseAMM(account.amm) : account.amm, + } as unknown as PerpMarketAccount; +} + +/** + * Parses an Anchor-generated SpotMarket account to the SDK's SpotMarketAccount type. + * Handles field name mappings and provides defaults for missing fields. + */ +export function parseSpotMarketAccount(account: { + [key: string]: any; +}): SpotMarketAccount { + return { + ...account, + } as unknown as SpotMarketAccount; +} + export type FuelOverflowAccount = { authority: PublicKey; fuelInsurance: BN; @@ -1805,7 +1874,6 @@ export type LPPoolAccount = { tokenSupply: BN; volatility: BN; constituents: number; - quoteConstituentIndex: number; bump: number; gammaExecution: number; xi: number; diff --git a/sdk/src/user.ts b/sdk/src/user.ts index 6872e10b5b..5fb3eee09f 100644 --- a/sdk/src/user.ts +++ b/sdk/src/user.ts @@ -333,7 +333,6 @@ export class User { public getEmptyPosition(marketIndex: number): PerpPosition { return { baseAssetAmount: ZERO, - remainderBaseAssetAmount: 0, lastCumulativeFundingRate: ZERO, marketIndex, quoteAssetAmount: ZERO, diff --git a/sdk/tests/dlob/helpers.ts b/sdk/tests/dlob/helpers.ts index 69ff661bc0..612fbddea0 100644 --- a/sdk/tests/dlob/helpers.ts +++ b/sdk/tests/dlob/helpers.ts @@ -40,7 +40,6 @@ export const mockPerpPosition: PerpPosition = { openAsks: new BN(0), settledPnl: new BN(0), lpShares: new BN(0), - remainderBaseAssetAmount: 0, lastBaseAssetAmountPerLp: new BN(0), lastQuoteAssetAmountPerLp: new BN(0), perLpBase: 0, diff --git a/test-scripts/run-anchor-local-validator-tests.sh b/test-scripts/run-anchor-local-validator-tests.sh index 8cacb1a6cb..4064876dca 100644 --- a/test-scripts/run-anchor-local-validator-tests.sh +++ b/test-scripts/run-anchor-local-validator-tests.sh @@ -1,6 +1,7 @@ if [ "$1" != "--skip-build" ]; then anchor build -- --features anchor-test && cp target/idl/drift.json sdk/src/idl/ + cp target/types/drift.ts sdk/src/idl/ fi export ANCHOR_WALLET=~/.config/solana/id.json diff --git a/test-scripts/run-anchor-tests.sh b/test-scripts/run-anchor-tests.sh index 19e5ca9625..dca4ddd545 100644 --- a/test-scripts/run-anchor-tests.sh +++ b/test-scripts/run-anchor-tests.sh @@ -6,6 +6,7 @@ trap 'echo -e "\nStopped by signal $? (SIGINT)"; exit 0' INT if [ "$1" != "--skip-build" ]; then anchor build -- --features anchor-test && anchor test --skip-build && cp target/idl/drift.json sdk/src/idl/ + cp target/types/drift.ts sdk/src/idl/ fi export ANCHOR_WALLET=~/.config/solana/id.json diff --git a/test-scripts/single-anchor-test.sh b/test-scripts/single-anchor-test.sh index f3fb157085..f7557dd199 100755 --- a/test-scripts/single-anchor-test.sh +++ b/test-scripts/single-anchor-test.sh @@ -2,6 +2,7 @@ if [ "$1" != "--skip-build" ] then anchor build -- --features anchor-test && anchor test --skip-build && cp target/idl/drift.json sdk/src/idl/ + cp target/idl/types.ts sdk/src/idl/ fi export ANCHOR_WALLET=~/.config/solana/id.json diff --git a/tests/delistMarket.ts b/tests/delistMarket.ts index 300a4ced63..82c50bd364 100644 --- a/tests/delistMarket.ts +++ b/tests/delistMarket.ts @@ -444,9 +444,6 @@ describe('delist market', () => { .getUserAccount() .perpPositions[0].baseAssetAmount.eq(ZERO) ); - // assert( - // liquidatorDriftClient.getUserAccount().perpPositions[0].remainderBaseAssetAmount != 0 - // ); console.log( 'liquidatorDriftClient perps:', liquidatorDriftClient.getUserAccount().perpPositions[0] @@ -478,10 +475,6 @@ describe('delist market', () => { .getUserAccount() .perpPositions[0].baseAssetAmount.eq(ZERO) ); - assert( - liquidatorDriftClient.getUserAccount().perpPositions[0] - .remainderBaseAssetAmount == 0 - ); assert(market001.numberOfUsersWithBase == 2); assert(market001.numberOfUsers == 3); diff --git a/yarn.lock b/yarn.lock index 2678bc1b59..2f449466ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,18 +2,22 @@ # yarn lockfile v1 -"@babel/runtime@^7.10.5", "@babel/runtime@^7.12.5", "@babel/runtime@^7.15.4", "@babel/runtime@^7.17.2", "@babel/runtime@^7.25.0": +"@babel/runtime@^7.10.5", "@babel/runtime@^7.12.5", "@babel/runtime@^7.15.4", "@babel/runtime@^7.17.2": version "7.27.6" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.6.tgz#ec4070a04d76bae8ddbb10770ba55714a417b7c6" integrity sha512-vbavdySgbTTrmFE+EsiqUTzlOr5bzlnJtUv9PynGCAKvfQqjIXbvFdumPM/GxMDfyuGMJaJAU6TO4zc1Jf1i8Q== -"@coral-xyz/anchor-30@npm:@coral-xyz/anchor@0.30.1": - version "0.30.1" - resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.30.1.tgz#17f3e9134c28cd0ea83574c6bab4e410bcecec5d" - integrity sha512-gDXFoF5oHgpriXAaLpxyWBHdCs8Awgf/gLHIo6crv7Aqm937CNdY+x+6hoj7QR5vaJV7MxWSQ0NGFzL3kPbWEQ== +"@babel/runtime@^7.25.0": + version "7.28.4" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.28.4.tgz#a70226016fabe25c5783b2f22d3e1c9bc5ca3326" + integrity sha512-Q/N6JNWvIvPnLDvjlE1OUBLPQHH6l3CltCEsHIujp45zQUSSh8K+gHnaEX45yAT1nyngnINhvWtzN+Nb9D8RAQ== + +"@coral-xyz/anchor-29@npm:@coral-xyz/anchor@0.29.0": + version "0.29.0" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.29.0.tgz#bd0be95bedfb30a381c3e676e5926124c310ff12" + integrity sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA== dependencies: - "@coral-xyz/anchor-errors" "^0.30.1" - "@coral-xyz/borsh" "^0.30.1" + "@coral-xyz/borsh" "^0.29.0" "@noble/hashes" "^1.3.1" "@solana/web3.js" "^1.68.0" bn.js "^5.1.2" @@ -28,12 +32,31 @@ superstruct "^0.15.4" toml "^3.0.0" -"@coral-xyz/anchor-errors@^0.30.1": - version "0.30.1" - resolved "https://registry.yarnpkg.com/@coral-xyz/anchor-errors/-/anchor-errors-0.30.1.tgz#bdfd3a353131345244546876eb4afc0e125bec30" - integrity sha512-9Mkradf5yS5xiLWrl9WrpjqOrAV+/W2RQHDlbnAZBivoGpOs1ECjoDCkVk4aRG8ZdiFiB8zQEVlxf+8fKkmSfQ== +"@coral-xyz/anchor-31@npm:@coral-xyz/anchor@0.31.1": + version "0.31.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.31.1.tgz#0fdeebf45a3cb2e47e8ebbb815ca98542152962c" + integrity sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA== + dependencies: + "@coral-xyz/anchor-errors" "^0.31.1" + "@coral-xyz/borsh" "^0.31.1" + "@noble/hashes" "^1.3.1" + "@solana/web3.js" "^1.69.0" + bn.js "^5.1.2" + bs58 "^4.0.1" + buffer-layout "^1.2.2" + camelcase "^6.3.0" + cross-fetch "^3.1.5" + eventemitter3 "^4.0.7" + pako "^2.0.3" + superstruct "^0.15.4" + toml "^3.0.0" + +"@coral-xyz/anchor-errors@^0.31.1": + version "0.31.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor-errors/-/anchor-errors-0.31.1.tgz#d635cbac2533973ae6bfb5d3ba1de89ce5aece2d" + integrity sha512-NhNEku4F3zzUSBtrYz84FzYWm48+9OvmT1Hhnwr6GnPQry2dsEqH/ti/7ASjjpoFTWRnPXrjAIT1qM6Isop+LQ== -"@coral-xyz/anchor@0.29.0", "@coral-xyz/anchor@^0.29.0": +"@coral-xyz/anchor@^0.29.0": version "0.29.0" resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.29.0.tgz#bd0be95bedfb30a381c3e676e5926124c310ff12" integrity sha512-eny6QNG0WOwqV0zQ7cs/b1tIuzZGmP7U7EcH+ogt4Gdbl8HDmIYVMh/9aTmYZPaFWjtUaI8qSn73uYEXWfATdA== @@ -53,6 +76,25 @@ superstruct "^0.15.4" toml "^3.0.0" +"@coral-xyz/anchor@npm:@coral-xyz/anchor@0.31.1": + version "0.31.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.31.1.tgz#0fdeebf45a3cb2e47e8ebbb815ca98542152962c" + integrity sha512-QUqpoEK+gi2S6nlYc2atgT2r41TT3caWr/cPUEL8n8Md9437trZ68STknq897b82p5mW0XrTBNOzRbmIRJtfsA== + dependencies: + "@coral-xyz/anchor-errors" "^0.31.1" + "@coral-xyz/borsh" "^0.31.1" + "@noble/hashes" "^1.3.1" + "@solana/web3.js" "^1.69.0" + bn.js "^5.1.2" + bs58 "^4.0.1" + buffer-layout "^1.2.2" + camelcase "^6.3.0" + cross-fetch "^3.1.5" + eventemitter3 "^4.0.7" + pako "^2.0.3" + superstruct "^0.15.4" + toml "^3.0.0" + "@coral-xyz/borsh@^0.28.0": version "0.28.0" resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.28.0.tgz#fa368a2f2475bbf6f828f4657f40a52102e02b6d" @@ -69,10 +111,10 @@ bn.js "^5.1.2" buffer-layout "^1.2.0" -"@coral-xyz/borsh@^0.30.1": - version "0.30.1" - resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.30.1.tgz#869d8833abe65685c72e9199b8688477a4f6b0e3" - integrity sha512-aaxswpPrCFKl8vZTbxLssA2RvwX2zmKLlRCIktJOwW+VpVwYtXRtlWiIP+c2pPRKneiTiWCN2GEMSH9j1zTlWQ== +"@coral-xyz/borsh@^0.31.1": + version "0.31.1" + resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.31.1.tgz#5328e1e0921b75d7f4a62dd3f61885a938bc7241" + integrity sha512-9N8AU9F0ubriKfNE3g1WF0/4dtlGXoBN/hd1PvbNBamBNwRgHxH4P+o3Zt7rSEloW1HUs6LfZEchlx9fW7POYw== dependencies: bn.js "^5.1.2" buffer-layout "^1.2.0" @@ -225,13 +267,20 @@ snake-case "^3.0.4" spok "^1.4.3" -"@noble/curves@^1.0.0", "@noble/curves@^1.4.2": +"@noble/curves@^1.0.0": version "1.9.2" resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.9.2.tgz#73388356ce733922396214a933ff7c95afcef911" integrity sha512-HxngEd2XUcg9xi20JkwlLCtYwfoFw4JGkuZpT+WlsPD4gB/cxkvTD8fSsoAnphGZhFdZYKeQIPCuFlWPm1uE0g== dependencies: "@noble/hashes" "1.8.0" +"@noble/curves@^1.4.2": + version "1.9.7" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.9.7.tgz#79d04b4758a43e4bca2cbdc62e7771352fa6b951" + integrity sha512-gbKGcRUYIjA3/zCCNaWDciTMFI0dCkvou3TL8Zmy5Nc7sJ47a0jtOeZoTaMxkuqRo9cRhjOdZJXegxYE5FN/xw== + dependencies: + "@noble/hashes" "1.8.0" + "@noble/ed25519@^1.7.0", "@noble/ed25519@^1.7.1": version "1.7.5" resolved "https://registry.yarnpkg.com/@noble/ed25519/-/ed25519-1.7.5.tgz#94df8bdb9fec9c4644a56007eecb57b0e9fbd0d7" @@ -570,6 +619,17 @@ "@solana/spl-token-metadata" "^0.1.2" buffer "^6.0.3" +"@solana/spl-token@^0.4.14": + version "0.4.14" + resolved "https://registry.yarnpkg.com/@solana/spl-token/-/spl-token-0.4.14.tgz#b86bc8a17f50e9680137b585eca5f5eb9d55c025" + integrity sha512-u09zr96UBpX4U685MnvQsNzlvw9TiY005hk1vJmJr7gMJldoPG1eYU5/wNEyOA5lkMLiR/gOi9SFD4MefOYEsA== + dependencies: + "@solana/buffer-layout" "^4.0.0" + "@solana/buffer-layout-utils" "^0.2.0" + "@solana/spl-token-group" "^0.0.7" + "@solana/spl-token-metadata" "^0.1.6" + buffer "^6.0.3" + "@solana/web3.js@1.73.2": version "1.73.2" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.73.2.tgz#4b30cd402b35733dae3a7d0b638be26a7742b395" @@ -592,7 +652,7 @@ rpc-websockets "^7.5.0" superstruct "^0.14.2" -"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.32.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.90.0", "@solana/web3.js@^1.98.0", "@solana/web3.js@^1.98.2": +"@solana/web3.js@^1.17.0", "@solana/web3.js@^1.21.0", "@solana/web3.js@^1.36.0", "@solana/web3.js@^1.56.2", "@solana/web3.js@^1.90.0": version "1.98.2" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.98.2.tgz#45167a5cfb64436944bf4dc1e8be8482bd6d4c14" integrity sha512-BqVwEG+TaG2yCkBMbD3C4hdpustR4FpuUFRPUmqRZYYlPI9Hg4XMWxHWOWRzHE9Lkc9NDjzXFX7lDXSgzC7R1A== @@ -613,6 +673,27 @@ rpc-websockets "^9.0.2" superstruct "^2.0.2" +"@solana/web3.js@^1.32.0", "@solana/web3.js@^1.68.0", "@solana/web3.js@^1.69.0", "@solana/web3.js@^1.98.2", "@solana/web3.js@^1.98.4": + version "1.98.4" + resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.98.4.tgz#df51d78be9d865181ec5138b4e699d48e6895bbe" + integrity sha512-vv9lfnvjUsRiq//+j5pBdXig0IQdtzA0BRZ3bXEP4KaIyF1CcaydWqgyzQgfZMNIsWNWmG+AUHwPy4AHOD6gpw== + dependencies: + "@babel/runtime" "^7.25.0" + "@noble/curves" "^1.4.2" + "@noble/hashes" "^1.4.0" + "@solana/buffer-layout" "^4.0.1" + "@solana/codecs-numbers" "^2.1.0" + agentkeepalive "^4.5.0" + bn.js "^5.2.1" + borsh "^0.7.0" + bs58 "^4.0.1" + buffer "6.0.3" + fast-stable-stringify "^1.0.0" + jayson "^4.1.1" + node-fetch "^2.7.0" + rpc-websockets "^9.0.2" + superstruct "^2.0.2" + "@solana/web3.js@~1.77.3": version "1.77.4" resolved "https://registry.yarnpkg.com/@solana/web3.js/-/web3.js-1.77.4.tgz#aad8c44a02ced319493308ef765a2b36a9e9fa8c" @@ -641,26 +722,10 @@ dependencies: tslib "^2.8.0" -"@switchboard-xyz/common@3.0.14": - version "3.0.14" - resolved "https://registry.yarnpkg.com/@switchboard-xyz/common/-/common-3.0.14.tgz#5b363995bd0fefa22198286992dbe54f3e544b08" - integrity sha512-LpxzEywO0DjPYIgPzQYkf32C7agwW4YRsPN6BcIvYrw0iJdDMtPZ3SQfIGHLSlD1fwvn2KLUYuGaKegeq4aBTw== - dependencies: - "@solana/web3.js" "^1.98.0" - axios "^1.8.3" - big.js "^6.2.2" - bn.js "^5.2.1" - bs58 "^6.0.0" - buffer "^6.0.3" - decimal.js "^10.4.3" - js-sha256 "^0.11.0" - protobufjs "^7.4.0" - yaml "^2.6.1" - -"@switchboard-xyz/common@>=3.0.0": - version "3.4.1" - resolved "https://registry.yarnpkg.com/@switchboard-xyz/common/-/common-3.4.1.tgz#3144c0730649e60129ea8c9b3c04062ceff35c6e" - integrity sha512-TropBlBYuDeBnmGHkPSmgC3clLqAxy51ZGbwk4ejAgadnszWOgYHcH7taRG4Ha17DYSCWw/LGMBKbunGo+Aoaw== +"@switchboard-xyz/common@5.5.0", "@switchboard-xyz/common@^5.2.9": + version "5.5.0" + resolved "https://registry.yarnpkg.com/@switchboard-xyz/common/-/common-5.5.0.tgz#b064eb911909cae2b2b732ec9fb8b5c073316eeb" + integrity sha512-Wvs9KJw+YSe8O2IOsMUvPE8aQHb0t2vi/9hEQC7Pc6279s7tTTI8eVgT/0Jb2z897OHgIZTD3oGQ8IEBqIgV0w== dependencies: "@solana/web3.js" "^1.98.2" axios "^1.9.0" @@ -671,21 +736,25 @@ decimal.js "^10.4.3" js-sha256 "^0.11.0" protobufjs "^7.4.0" - yaml "^2.6.1" - zod "4.0.0-beta.20250505T195954" -"@switchboard-xyz/on-demand@2.4.1": - version "2.4.1" - resolved "https://registry.yarnpkg.com/@switchboard-xyz/on-demand/-/on-demand-2.4.1.tgz#3db64b0596d9daa0b010ee44193d5512e0ba512d" - integrity sha512-eSlBp+c8lxpcSgh0/2xK8OaLHPziTSZlcs8V96gZGdiCJz1KgWJRNE1qnIJDOwaGdFecZdwcmajfQRtLRLED3w== +"@switchboard-xyz/on-demand@3.7.3": + version "3.7.3" + resolved "https://registry.yarnpkg.com/@switchboard-xyz/on-demand/-/on-demand-3.7.3.tgz#07e4df25e145e86e5c5dab496704056bda07c2bc" + integrity sha512-sG9errSwjYlQbIlQl0iptUQcbKrPe7QVxX20+qXuucG3qIWlA/w6sXGnITeYbt+BERyBYdfue0viBjmjOsCZrg== dependencies: - "@coral-xyz/anchor-30" "npm:@coral-xyz/anchor@0.30.1" + "@coral-xyz/anchor-31" "npm:@coral-xyz/anchor@0.31.1" "@isaacs/ttlcache" "^1.4.1" - "@switchboard-xyz/common" ">=3.0.0" - axios "^1.8.3" + "@solana/spl-token" "^0.4.14" + "@solana/web3.js" "^1.98.4" + "@switchboard-xyz/common" "^5.2.9" + axios "^1.9" bs58 "^6.0.0" buffer "^6.0.3" + events "^3.3.0" + isomorphic-ws "^5.0.0" js-yaml "^4.1.0" + tweetnacl "^1.0.3" + ws "^8.18.1" "@types/bn.js@5.1.6": version "5.1.6" @@ -717,11 +786,11 @@ integrity sha512-ekGvFhFgrc2zYQoX4JeZPmVzZxw6Dtllga7iGHzfbYIYkAMUx/sAFP2GdFpLff+vdHXu5fl7WX9AT+TtqYcsyw== "@types/node@*", "@types/node@>=13.7.0": - version "24.0.13" - resolved "https://registry.yarnpkg.com/@types/node/-/node-24.0.13.tgz#93ed8c05c7b188a59760be0ce2ee3fa7ad0f83f6" - integrity sha512-Qm9OYVOFHFYg3wJoTSrz80hoec5Lia/dPp84do3X7dZvLikQvM1YpmvTBEdIr/e+U8HTkFjLHLnl78K/qjf+jQ== + version "24.10.1" + resolved "https://registry.yarnpkg.com/@types/node/-/node-24.10.1.tgz#91e92182c93db8bd6224fca031e2370cef9a8f01" + integrity sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ== dependencies: - undici-types "~7.8.0" + undici-types "~7.16.0" "@types/node@^12.12.54": version "12.20.55" @@ -850,11 +919,6 @@ resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.3.0.tgz#d06bbb384ebcf6c505fde1c3d0ed4ddffe0aaff8" integrity sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g== -"@zod/core@0.11.6": - version "0.11.6" - resolved "https://registry.yarnpkg.com/@zod/core/-/core-0.11.6.tgz#9216e98848dc9364eda35e3da90f5362f10e8887" - integrity sha512-03Bv82fFSfjDAvMfdHHdGSS6SOJs0iCcJlWJv1kJHRtoTT02hZpyip/2Lk6oo4l4FtjuwTrsEQTwg/LD8I7dJA== - JSONStream@^1.3.5: version "1.3.5" resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0" @@ -963,7 +1027,7 @@ axios-retry@^3.8.0: "@babel/runtime" "^7.15.4" is-retry-allowed "^2.2.0" -axios@^1.5.1, axios@^1.8.3, axios@^1.9.0: +axios@^1.5.1: version "1.10.0" resolved "https://registry.yarnpkg.com/axios/-/axios-1.10.0.tgz#af320aee8632eaf2a400b6a1979fa75856f38d54" integrity sha512-/1xYAC4MP/HEG+3duIhFr4ZQXR4sQXOIe+o6sdqzeykGLx6Upp/1p8MHqhINOvGeP7xyNHe7tsiJByc4SSVUxw== @@ -972,6 +1036,15 @@ axios@^1.5.1, axios@^1.8.3, axios@^1.9.0: form-data "^4.0.0" proxy-from-env "^1.1.0" +axios@^1.9, axios@^1.9.0: + version "1.13.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.13.2.tgz#9ada120b7b5ab24509553ec3e40123521117f687" + integrity sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.4" + proxy-from-env "^1.1.0" + backslash@<0.2.1: version "0.2.0" resolved "https://registry.yarnpkg.com/backslash/-/backslash-0.2.0.tgz#6c3c1fce7e7e714ccfc10fd74f0f73410677375f" @@ -1017,9 +1090,9 @@ bigint-buffer@^1.1.5: bindings "^1.3.0" bignumber.js@^9.0.1: - version "9.3.0" - resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.3.0.tgz#bdba7e2a4c1a2eba08290e8dcad4f36393c92acd" - integrity sha512-EM7aMFTXbptt/wZdMlBv2t8IViwQL+h6SLHosp8Yf0dqJMTnY6iL32opnAB6kAdL0SZPuvcAzFr31o0c/R3/RA== + version "9.3.1" + resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.3.1.tgz#759c5aaddf2ffdc4f154f7b493e1c8770f88c4d7" + integrity sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ== bindings@^1.3.0: version "1.5.0" @@ -1240,9 +1313,9 @@ commander@^12.1.0: integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA== commander@^14.0.0: - version "14.0.0" - resolved "https://registry.yarnpkg.com/commander/-/commander-14.0.0.tgz#f244fc74a92343514e56229f16ef5c5e22ced5e9" - integrity sha512-2uM9rYjPvyq39NwLRqaiLtWHyDC1FvryJDa2ATTVims5YAS4PupsEQsDvP14FqhFr0P49CYDugi59xaxJlTXRA== + version "14.0.2" + resolved "https://registry.yarnpkg.com/commander/-/commander-14.0.2.tgz#b71fd37fe4069e4c3c7c13925252ada4eba14e8e" + integrity sha512-TywoWNNRbhoD0BXs1P3ZEScW8W5iKrnbithIl0YH+uCmBd0QpPOA8yc82DS3BIE5Ma6FnBVUsJ7wVUDz4dvOWQ== commander@^2.20.3: version "2.20.3" @@ -1560,6 +1633,11 @@ eventemitter3@^5.0.1: resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== +events@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/events/-/events-3.3.0.tgz#31a95ad0a924e2d2c419a813aeb2c4e878ea7400" + integrity sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q== + eyes@^0.1.8: version "0.1.8" resolved "https://registry.yarnpkg.com/eyes/-/eyes-0.1.8.tgz#62cf120234c683785d902348a800ef3e0cc20bc0" @@ -1666,9 +1744,9 @@ flatted@^3.2.9: integrity sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg== follow-redirects@^1.15.6: - version "1.15.9" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.9.tgz#a604fa10e443bf98ca94228d9eebcc2e8a2c8ee1" - integrity sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ== + version "1.15.11" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.11.tgz#777d73d72a92f8ec4d2e410eb47352a56b8e8340" + integrity sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ== for-each@^0.3.5: version "0.3.5" @@ -1677,10 +1755,10 @@ for-each@^0.3.5: dependencies: is-callable "^1.2.7" -form-data@^4.0.0: - version "4.0.3" - resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.3.tgz#608b1b3f3e28be0fccf5901fc85fb3641e5cf0ae" - integrity sha512-qsITQPfmvMOSAdeyZ+12I1c+CKSstAFAwu+97zrnWAbIr5u8wfsExUzCesVLC8NgHuRUqNN4Zy6UPWUTRGslcA== +form-data@^4.0.0, form-data@^4.0.4: + version "4.0.5" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.5.tgz#b49e48858045ff4cbf6b03e1805cebcad3679053" + integrity sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w== dependencies: asynckit "^0.4.0" combined-stream "^1.0.8" @@ -1978,6 +2056,11 @@ isomorphic-ws@^4.0.1: resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc" integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w== +isomorphic-ws@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-5.0.0.tgz#e5529148912ecb9b451b46ed44d53dae1ce04bbf" + integrity sha512-muId7Zzn9ywDsyXgTIafTry2sV3nySZeUDe6YedVd1Hvuuep5AsIlqK+XefWpYTyJG5e503F2xIuT2lcU6rCSw== + jayson@^3.4.4: version "3.7.0" resolved "https://registry.yarnpkg.com/jayson/-/jayson-3.7.0.tgz#b735b12d06d348639ae8230d7a1e2916cb078f25" @@ -2040,9 +2123,9 @@ js-sha256@^0.9.0: integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA== js-yaml@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602" - integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA== + version "4.1.1" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.1.tgz#854c292467705b699476e1a2decc0c8a3458806b" + integrity sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA== dependencies: argparse "^2.0.1" @@ -2379,7 +2462,7 @@ prettier@^2.5.1: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da" integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q== -protobufjs@^7.2.5, protobufjs@^7.4.0: +protobufjs@^7.2.5: version "7.5.3" resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.5.3.tgz#13f95a9e3c84669995ec3652db2ac2fb00b89363" integrity sha512-sildjKwVqOI2kmFDiXQ6aEB0fjYTafpEvIBs8tOR8qI4spuL9OPROLVu2qZqi/xgCfsHIwVqlaF8JBjWFHnKbw== @@ -2397,6 +2480,24 @@ protobufjs@^7.2.5, protobufjs@^7.4.0: "@types/node" ">=13.7.0" long "^5.0.0" +protobufjs@^7.4.0: + version "7.5.4" + resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-7.5.4.tgz#885d31fe9c4b37f25d1bb600da30b1c5b37d286a" + integrity sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg== + dependencies: + "@protobufjs/aspromise" "^1.1.2" + "@protobufjs/base64" "^1.1.2" + "@protobufjs/codegen" "^2.0.4" + "@protobufjs/eventemitter" "^1.1.0" + "@protobufjs/fetch" "^1.1.0" + "@protobufjs/float" "^1.0.2" + "@protobufjs/inquire" "^1.1.0" + "@protobufjs/path" "^1.1.2" + "@protobufjs/pool" "^1.1.0" + "@protobufjs/utf8" "^1.1.0" + "@types/node" ">=13.7.0" + long "^5.0.0" + proxy-from-env@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" @@ -2460,9 +2561,9 @@ rpc-websockets@^7.5.0, rpc-websockets@^7.5.1: utf-8-validate "^5.0.2" rpc-websockets@^9.0.2: - version "9.1.1" - resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-9.1.1.tgz#5764336f3623ee1c5cc8653b7335183e3c0c78bd" - integrity sha512-1IXGM/TfPT6nfYMIXkJdzn+L4JEsmb0FL1O2OBjaH03V3yuUDdKFulGLMFG6ErV+8pZ5HVC0limve01RyO+saA== + version "9.3.2" + resolved "https://registry.yarnpkg.com/rpc-websockets/-/rpc-websockets-9.3.2.tgz#26b4d7ebaf8e53422528619a3c314e83590d85bf" + integrity sha512-VuW2xJDnl1k8n8kjbdRSWawPRkwaVqUQNjE1TdeTawf0y0abGhtVJFTXCLfgpgGDBkO/Fj6kny8Dc/nvOW78MA== dependencies: "@swc/helpers" "^0.5.11" "@types/uuid" "^8.3.4" @@ -2750,6 +2851,11 @@ tslib@^2.0.3, tslib@^2.8.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== +tweetnacl@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" + integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== + type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -2787,10 +2893,10 @@ undici-types@~5.26.4: resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== -undici-types@~7.8.0: - version "7.8.0" - resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.8.0.tgz#de00b85b710c54122e44fbfd911f8d70174cd294" - integrity sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw== +undici-types@~7.16.0: + version "7.16.0" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-7.16.0.tgz#ffccdff36aea4884cbfce9a750a0580224f58a46" + integrity sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw== uri-js@^4.2.2: version "4.4.1" @@ -2889,7 +2995,7 @@ ws@^7.4.5, ws@^7.5.10: resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9" integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ== -ws@^8.5.0, ws@^8.6.0: +ws@^8.18.1, ws@^8.5.0, ws@^8.6.0: version "8.18.3" resolved "https://registry.yarnpkg.com/ws/-/ws-8.18.3.tgz#b56b88abffde62791c639170400c93dcb0c95472" integrity sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg== @@ -2899,11 +3005,6 @@ y18n@^5.0.5: resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== -yaml@^2.6.1: - version "2.8.0" - resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.8.0.tgz#15f8c9866211bdc2d3781a0890e44d4fa1a5fff6" - integrity sha512-4lLa/EcQCB0cJkyts+FpIRx5G/llPxfP6VQU5KByHEhLxY3IJCH0f0Hy1MHI8sClTvsIb8qwRJ6R/ZdlDJ/leQ== - yargs-parser@^21.1.1: version "21.1.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-21.1.1.tgz#9096bceebf990d21bb31fa9516e0ede294a77d35" @@ -2927,13 +3028,6 @@ yocto-queue@^0.1.0: resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== -zod@4.0.0-beta.20250505T195954: - version "4.0.0-beta.20250505T195954" - resolved "https://registry.yarnpkg.com/zod/-/zod-4.0.0-beta.20250505T195954.tgz#ba9da025671de2dde9d4d033089f03c37a35022f" - integrity sha512-iB8WvxkobVIXMARvQu20fKvbS7mUTiYRpcD8OQV1xjRhxO0EEpYIRJBk6yfBzHAHEdOSDh3SxDITr5Eajr2vtg== - dependencies: - "@zod/core" "0.11.6" - zod@4.0.17: version "4.0.17" resolved "https://registry.yarnpkg.com/zod/-/zod-4.0.17.tgz#95931170715f73f7426c385c237b7477750d6c8d"