From 545f3456adaaaabd8728eba658fafb2a206fb456 Mon Sep 17 00:00:00 2001 From: Lucas B Date: Tue, 30 Jul 2024 22:03:23 -0500 Subject: [PATCH] wip wtf --- Cargo.lock | 446 ++++++++++----- Cargo.toml | 6 +- integration_tests/Cargo.toml | 2 + integration_tests/tests/fixtures/fixture.rs | 108 ++-- .../tests/fixtures/restaking_client.rs | 93 +++- .../tests/fixtures/vault_client.rs | 506 ++++++++++++++++-- integration_tests/tests/vault/add_avs.rs | 145 ++--- .../tests/vault/enqueue_withdrawal.rs | 30 ++ .../tests/vault/initialize_config.rs | 14 +- .../tests/vault/initialize_vault.rs | 58 +- integration_tests/tests/vault/mod.rs | 1 + vault_core/src/vault.rs | 4 +- vault_program/src/add_avs.rs | 8 + ...ueue_withdrawal.rs => enqueue_withdraw.rs} | 12 +- vault_program/src/lib.rs | 8 +- vault_sdk/src/lib.rs | 44 +- 16 files changed, 1094 insertions(+), 391 deletions(-) create mode 100644 integration_tests/tests/vault/enqueue_withdrawal.rs rename vault_program/src/{enqueue_withdrawal.rs => enqueue_withdraw.rs} (97%) diff --git a/Cargo.lock b/Cargo.lock index 2e8eb74d..c6bcdc41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,9 +76,9 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.5" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7d5a2cecb58716e47d67d5703a249964b14c7be1ec3cad3affc295b2d1c35d" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom 0.2.12", @@ -147,6 +147,20 @@ version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +[[package]] +name = "aquamarine" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1da02abba9f9063d786eab1509833ebb2fac0f966862ca59439c76b9c566760" +dependencies = [ + "include_dir", + "itertools", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "ark-bn254" version = "0.4.0" @@ -520,6 +534,16 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "borsh" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6362ed55def622cddc70a4746a68554d7b687713770de539e59a739b249f8ed" +dependencies = [ + "borsh-derive 1.5.1", + "cfg_aliases", +] + [[package]] name = "borsh-derive" version = "0.9.3" @@ -546,6 +570,20 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ef8005764f53cd4dca619f5bf64cafd4664dada50ece25e4d81de54c80cc0b" +dependencies = [ + "once_cell", + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.55", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" version = "0.9.3" @@ -712,6 +750,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + [[package]] name = "chrono" version = "0.4.35" @@ -1006,12 +1050,15 @@ dependencies = [ [[package]] name = "dashmap" -version = "4.0.2" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e77a43b28d0668df09411cb0bc9a8c2adc40f9a048afe863e05fd43251e8e39c" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if", - "num_cpus", + "hashbrown 0.14.3", + "lock_api", + "once_cell", + "parking_lot_core", "rayon", ] @@ -1082,6 +1129,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + [[package]] name = "digest" version = "0.9.0" @@ -1145,6 +1198,12 @@ dependencies = [ "syn 2.0.55", ] +[[package]] +name = "downcast" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" + [[package]] name = "eager" version = "0.1.0" @@ -1321,6 +1380,15 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" +dependencies = [ + "num-traits", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1337,13 +1405,10 @@ dependencies = [ ] [[package]] -name = "fs-err" -version = "2.11.0" +name = "fragile" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41" -dependencies = [ - "autocfg", -] +checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "futures" @@ -1550,7 +1615,7 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.5", + "ahash 0.8.11", ] [[package]] @@ -1749,6 +1814,25 @@ dependencies = [ "version_check", ] +[[package]] +name = "include_dir" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "923d117408f1e49d914f1a379a309cffe4f18c05cf4e3d12e613a15fc81bd0dd" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cab85a7ed0bd5f0e76d93846e0147172bed2e2d3f859bcc33a8d9699cad1a75" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "index_list" version = "0.2.11" @@ -1860,6 +1944,7 @@ dependencies = [ "jito-vault-core", "jito-vault-program", "jito-vault-sdk", + "log", "shank", "solana-program", "solana-program-test", @@ -2218,6 +2303,33 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mockall" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c84490118f2ee2d74570d114f3d0493cbf02790df303d2707606c3e14e07c96" +dependencies = [ + "cfg-if", + "downcast", + "fragile", + "lazy_static", + "mockall_derive", + "predicates", + "predicates-tree", +] + +[[package]] +name = "mockall_derive" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ce75669015c4f47b289fd4d4f56e894e4c96003ffdf3ac51313126f94c6cbb" +dependencies = [ + "cfg-if", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "modular-bitfield" version = "0.11.2" @@ -2262,6 +2374,12 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "num" version = "0.2.1" @@ -2675,6 +2793,36 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "predicates" +version = "2.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59230a63c37f3e18569bdb90e4a89cbf5bf8b06fea0b84e65ea10cc4df47addd" +dependencies = [ + "difflib", + "float-cmp", + "itertools", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" + +[[package]] +name = "predicates-tree" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro-crate" version = "0.1.5" @@ -3238,6 +3386,15 @@ version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +[[package]] +name = "seqlock" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5c67b6f14ecc5b86c66fa63d76b5092352678545a8a3cdae80aef5128371910" +dependencies = [ + "parking_lot", +] + [[package]] name = "serde" version = "1.0.197" @@ -3488,9 +3645,9 @@ dependencies = [ [[package]] name = "solana-account-decoder" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a9721ff8b83683cb7dd856079cde8a8010bfd282d482699a867ad50ea9e727e" +checksum = "5e621af8405ad85f2c3822bb1794f57389b7bc2e8c8c49e0d5a38b85b8955565" dependencies = [ "Inflector", "base64 0.21.7", @@ -3513,9 +3670,9 @@ dependencies = [ [[package]] name = "solana-accounts-db" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cdae5f9d2562360bd07fde58976f6ff8f7d90c8311bc5a4959edd7ba61ccec4" +checksum = "b420b71476b1c5acd3552ecd5c6e360f46a262c972d02dac1a7d5eacb2d5adf0" dependencies = [ "arrayref", "bincode", @@ -3528,7 +3685,6 @@ dependencies = [ "dashmap", "flate2", "fnv", - "fs-err", "im", "index_list", "itertools", @@ -3537,10 +3693,10 @@ dependencies = [ "lz4", "memmap2", "modular-bitfield", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "num_cpus", - "num_enum 0.6.1", + "num_enum 0.7.2", "ouroboros", "percentage", "qualifier_attr", @@ -3548,14 +3704,17 @@ dependencies = [ "rayon", "regex", "rustc_version", + "seqlock", "serde", "serde_derive", + "smallvec", "solana-bucket-map", "solana-config-program", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-measure", "solana-metrics", + "solana-nohash-hasher", "solana-program-runtime", "solana-rayon-threadlimit", "solana-sdk", @@ -3572,14 +3731,14 @@ dependencies = [ [[package]] name = "solana-address-lookup-table-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c471a3f150762652b5d77f83432b8574738e621fae4885c47132cfe33676d27c" +checksum = "76ed10ab9edfb4bf390cf15c3f5fb075a78b202e4041af3db4d3fd899c4adfc5" dependencies = [ "bincode", "bytemuck", "log", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "rustc_version", "serde", @@ -3593,11 +3752,11 @@ dependencies = [ [[package]] name = "solana-banks-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4397a1bcefabb65c426c5baea8c5df1da2dff734ea9328789253e30e59bab25" +checksum = "704018ba89029425150d17ae69d668e3ecb076151d3446cf99862f7ca491f8b0" dependencies = [ - "borsh 0.10.3", + "borsh 1.5.1", "futures", "solana-banks-interface", "solana-program", @@ -3610,9 +3769,9 @@ dependencies = [ [[package]] name = "solana-banks-interface" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a61b939343909a74cc826326dfdcad16f6015301e3d2134bc29fee59c27171a9" +checksum = "100f1e18910f6c666d8860a675c2cc6a3e4f92c1b99b6948192da8fe1b6156f6" dependencies = [ "serde", "solana-sdk", @@ -3621,9 +3780,9 @@ dependencies = [ [[package]] name = "solana-banks-server" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b803ea31aa9b17a679454c921af320f9efb026355cb067dfbad57261ab771593" +checksum = "ac37078f40d968d3e47156ec5f65b392dba76618777c6f7fa915ced84a8f3f99" dependencies = [ "bincode", "crossbeam-channel", @@ -3641,9 +3800,9 @@ dependencies = [ [[package]] name = "solana-bpf-loader-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a99a75cdd7d4e40b51d8de8125f3d44db3f7735d96f4e3f31ee79d3110a8f4d" +checksum = "38d5e8dc69cfae82adf204822398688bc89ad1849964231c28037d7e5bede949" dependencies = [ "bincode", "byteorder", @@ -3660,16 +3819,16 @@ dependencies = [ [[package]] name = "solana-bucket-map" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9830a7dbea75c0cbd62a4ca31bcd9b8832fbdb915c949740a44a496630fb5eb6" +checksum = "af5cd35ff8bc73727f1eab457e0a3e97d683fcfbef2a324981a3b62d1fe17c15" dependencies = [ "bv", "bytemuck", "log", "memmap2", "modular-bitfield", - "num_enum 0.6.1", + "num_enum 0.7.2", "rand 0.8.5", "solana-measure", "solana-sdk", @@ -3678,9 +3837,9 @@ dependencies = [ [[package]] name = "solana-clap-utils" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4af0fe4584d7692f24e573b17a5245cfc0d99a4e351b0185dfe02baf52f99864" +checksum = "cfefc0f73fab9535c91c5bc4077ca21ce0b966df1fece0c39e5ff3f5617a9f78" dependencies = [ "chrono", "clap 2.34.0", @@ -3695,9 +3854,9 @@ dependencies = [ [[package]] name = "solana-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "250ffcda91bc30c2adcc290c9b7c796f59884f1043ae3bcf3245f05158c7986c" +checksum = "398c11649c8a1918e84935ca4fbcfe1bcb55ba1aa83d3051994595ba6833d8c6" dependencies = [ "async-trait", "bincode", @@ -3728,9 +3887,9 @@ dependencies = [ [[package]] name = "solana-compute-budget-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8703a92306dfdc4760e18db14b2f8b36c9769e5c47f0656bc77355875674e079" +checksum = "36964b228f72bac36a820acde67cd5c80d07af26d30fdf6fe83586a139c4f53c" dependencies = [ "solana-program-runtime", "solana-sdk", @@ -3738,9 +3897,9 @@ dependencies = [ [[package]] name = "solana-config-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16fd2daba039bad58277ec88143b1fe624f2352d8ccb2a80bba3693de61df440" +checksum = "5544b247de63cb2a90f8d8dbbe61468405ed9895d245c1e28f7806c918fe0fb4" dependencies = [ "bincode", "chrono", @@ -3752,9 +3911,9 @@ dependencies = [ [[package]] name = "solana-connection-cache" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "868e7fb550af97ad6fc283a5628f8ffb6dafd590dc30254163e7c9003f13ceb0" +checksum = "8e3f0556a82d5da2693159f150f3da5b5bdbf2fc0e8b3181b5ed9347096074e8" dependencies = [ "async-trait", "bincode", @@ -3774,9 +3933,9 @@ dependencies = [ [[package]] name = "solana-cost-model" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b79a349b86d02948720e4416463d50fd4f828b6a63512e47b497613df0d720" +checksum = "6bcac1b4ae9a7ed8cb8578d448d713ef4b98cfb7c8cc3ba76fac94b7631b6b9b" dependencies = [ "lazy_static", "log", @@ -3798,17 +3957,13 @@ dependencies = [ [[package]] name = "solana-frozen-abi" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "219c484f952f006e37a1a2598aebcc4dcfd48478c03fc2ce2d99787a5c78f248" +checksum = "0f0c52f25d28a1b5af57d5de3802e49883f68792a343101a9daf9817d8dfffff" dependencies = [ - "ahash 0.8.5", - "blake3", "block-buffer 0.10.4", "bs58", "bv", - "byteorder", - "cc", "either", "generic-array", "im", @@ -3819,7 +3974,6 @@ dependencies = [ "serde", "serde_bytes", "serde_derive", - "serde_json", "sha2 0.10.8", "solana-frozen-abi-macro", "subtle", @@ -3828,9 +3982,9 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffe4e1dc5fd61ac10c304b3eb8ddb49737b13e975281d623a6083cf5cf0a8616" +checksum = "fc7d0abca44a21c83305e8650341f67ccc919a1a9dd698ddafc86e78b74b9296" dependencies = [ "proc-macro2", "quote", @@ -3840,9 +3994,9 @@ dependencies = [ [[package]] name = "solana-loader-v4-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad035401037e6e7d1dc19c0ae4b613b36632b60443d28716355a4e0041892fa2" +checksum = "504108d5cb774abf89d0cf673ab6950bfe257aadf2fa872adb32b1473f7818f5" dependencies = [ "log", "solana-measure", @@ -3853,9 +4007,9 @@ dependencies = [ [[package]] name = "solana-logger" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64b4f281f2263de6d9cc65680b90b6bd2c93ba7de573db83fc86e2d05ca7ea8c" +checksum = "d5bc0644a410b8bff84ad18541a176f27776062b1ad116cb315c6f5f14b94fed" dependencies = [ "env_logger", "lazy_static", @@ -3864,9 +4018,9 @@ dependencies = [ [[package]] name = "solana-measure" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a3ed981230b6a3a8aebf9f03424f5c1ff98be75cc7f0ecb153879e8e439aea" +checksum = "3b2a96265160981b5aab8a73c9830f2cd8ce7b557790d19c18cabb8565563f2f" dependencies = [ "log", "solana-sdk", @@ -3874,9 +4028,9 @@ dependencies = [ [[package]] name = "solana-metrics" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efb65329e6716dc0ce5b1d719d6e0052e7ff1179ab361916f256054d6b846ee1" +checksum = "d140890d4f906315533de1c9b929e1b3b8f4a0515f45a85ee90859778ea6e6ab" dependencies = [ "crossbeam-channel", "gethostname", @@ -3889,9 +4043,9 @@ dependencies = [ [[package]] name = "solana-net-utils" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8345ffe2bd2a25a02e5dea046bbbf58f81f6b44ee97224474eae1c0ea03b520a" +checksum = "024848a9557dc5054ed96c3532b95ddefb753d68b677eb0495f69cc456160e8a" dependencies = [ "bincode", "clap 3.2.25", @@ -3909,13 +4063,19 @@ dependencies = [ "url", ] +[[package]] +name = "solana-nohash-hasher" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8a731ed60e89177c8a7ab05fe0f1511cedd3e70e773f288f9de33a9cfdc21e" + [[package]] name = "solana-perf" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0326bd89c2453bf2a408ff676cff4ed0080bff2a5c6543db5f62423bc23ad6e8" +checksum = "599733dcb745a7a346bc9ea540603078c99aa97e2da7395a269774a92231ebd4" dependencies = [ - "ahash 0.8.5", + "ahash 0.8.11", "bincode", "bv", "caps", @@ -3940,9 +4100,9 @@ dependencies = [ [[package]] name = "solana-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93dc0f422549c23c4464eaa9383f4b09cd92b50dea750731dd3c31d3ee2d310f" +checksum = "76a99c3bc26fda40f42db98494271bda4906b0d7ab55f3ea7755fa5f110f58b5" dependencies = [ "ark-bn254", "ark-ec", @@ -3954,6 +4114,7 @@ dependencies = [ "blake3", "borsh 0.10.3", "borsh 0.9.3", + "borsh 1.5.1", "bs58", "bv", "bytemuck", @@ -3971,7 +4132,7 @@ dependencies = [ "log", "memoffset 0.9.1", "num-bigint 0.4.4", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "parking_lot", "rand 0.8.5", @@ -3994,9 +4155,9 @@ dependencies = [ [[package]] name = "solana-program-runtime" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b407440b708ffda97e25b8cb977f72d1bb7466c28ea5f58751613df0af8d576" +checksum = "11ae79e82b97a66ff00770d9190abc7e6b610c108254cd84fcd0f100a1c4d165" dependencies = [ "base64 0.21.7", "bincode", @@ -4005,7 +4166,7 @@ dependencies = [ "itertools", "libc", "log", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "percentage", "rand 0.8.5", @@ -4022,9 +4183,9 @@ dependencies = [ [[package]] name = "solana-program-test" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a49b6bef92bce799f1d023e0083ace2a20720330bfe8e36dcf793ee4eb95ffe" +checksum = "48bad4093f3dc41967e33e644e09649fb86eabb67ed731cdb18b1303d053a48c" dependencies = [ "assert_matches", "async-trait", @@ -4052,9 +4213,9 @@ dependencies = [ [[package]] name = "solana-pubsub-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f82da20e0c0bb39f9123cf61a6e3c76a8e30b0f09e5215decfb7f6b54734f04" +checksum = "de7e67897cf69c207977eaf7923541d026b3de92f313df5f625461609c618325" dependencies = [ "crossbeam-channel", "futures-util", @@ -4077,9 +4238,9 @@ dependencies = [ [[package]] name = "solana-quic-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8478a6b4f2c2b8fa330d54ff22386a1792498cb6e84ce3893840337a992e47c6" +checksum = "13b3ca213d9c133d28484ac0eb1c741078d2495ec15fcc62f55357529147b528" dependencies = [ "async-mutex", "async-trait", @@ -4104,9 +4265,9 @@ dependencies = [ [[package]] name = "solana-rayon-threadlimit" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df0aac27af8e94f907f6a65305e0a7909800336e7108bd3ce1dc1f3ef011a20" +checksum = "379bd42e389ae50f7b9c6e4a32f7b2c6f1eb41f064d76158b50003877d4c7844" dependencies = [ "lazy_static", "num_cpus", @@ -4114,14 +4275,14 @@ dependencies = [ [[package]] name = "solana-remote-wallet" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a97d60701d3fe0fde4871c5856da9e52ba733fbcfb030482278c3af4ffa0bf3" +checksum = "d55362fbec27c74974fe9c5a0c89d8fb082d9a5063c9ca7ce30857b61d8003ad" dependencies = [ "console", "dialoguer", "log", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "parking_lot", "qstring", @@ -4133,9 +4294,9 @@ dependencies = [ [[package]] name = "solana-rpc-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b750c49be9dd90981f3c12c8357d0b0c847bf5b8c638c3eff3c09f6ea199393" +checksum = "d4dc7051e6e999041ac99c011f253012d594325b244ab9b2fd349dee1c1f2276" dependencies = [ "async-trait", "base64 0.21.7", @@ -4159,9 +4320,9 @@ dependencies = [ [[package]] name = "solana-rpc-client-api" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314d0f87fc7bab16b1b4674c03d4e92c7008fa181b67210780542c0e6cbfce38" +checksum = "4c7c5df5da53559461efae1ff370f6d89866246fc1dcbb3c3cb86b6d91cb565a" dependencies = [ "base64 0.21.7", "bs58", @@ -4181,9 +4342,9 @@ dependencies = [ [[package]] name = "solana-rpc-client-nonce-utils" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acf79164ae52ee1ee85cd7aeb1bb715a9f3b90678ee00501896d173dbc31731" +checksum = "7c7e57bc4da80bf225ba4835f876c07f66d1fe37b765efc8250beaf05202be46" dependencies = [ "clap 2.34.0", "solana-clap-utils", @@ -4194,10 +4355,11 @@ dependencies = [ [[package]] name = "solana-runtime" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3dfd09f3cd529ab56b33a1b389b449ddc31b338f062822c7cc30375a2f234b" +checksum = "70146346ffa147cc48238bac5bc75defd0016a217baf640957565c12701cccfe" dependencies = [ + "aquamarine", "arrayref", "base64 0.21.7", "bincode", @@ -4211,7 +4373,6 @@ dependencies = [ "dir-diff", "flate2", "fnv", - "fs-err", "im", "index_list", "itertools", @@ -4220,11 +4381,12 @@ dependencies = [ "lru", "lz4", "memmap2", + "mockall", "modular-bitfield", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "num_cpus", - "num_enum 0.6.1", + "num_enum 0.7.2", "ouroboros", "percentage", "qualifier_attr", @@ -4235,7 +4397,6 @@ dependencies = [ "serde", "serde_derive", "serde_json", - "siphasher", "solana-accounts-db", "solana-address-lookup-table-program", "solana-bpf-loader-program", @@ -4271,15 +4432,15 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3892ee0e2acdfbeae7315db6c7c56356384631deb943377de5957074bd2dc4d1" +checksum = "90a8affb5b3acd43f7164368b88243bf091e46eccff9bea5b743e4691d7c2600" dependencies = [ "assert_matches", "base64 0.21.7", "bincode", "bitflags 2.5.0", - "borsh 0.10.3", + "borsh 1.5.1", "bs58", "bytemuck", "byteorder", @@ -4296,9 +4457,9 @@ dependencies = [ "libsecp256k1", "log", "memmap2", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", - "num_enum 0.6.1", + "num_enum 0.7.2", "pbkdf2 0.11.0", "qstring", "qualifier_attr", @@ -4313,6 +4474,7 @@ dependencies = [ "serde_with", "sha2 0.10.8", "sha3 0.10.8", + "siphasher", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", @@ -4325,9 +4487,9 @@ dependencies = [ [[package]] name = "solana-sdk-macro" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8019cc997f6c07f09b23dfeb2c45530fa94df2e2fb9d654f3c772c9766a1511f" +checksum = "4c2ac8d7ef471476164edb2ed105bcf26071835a15f0e74703929d4ec913676b" dependencies = [ "bs58", "proc-macro2", @@ -4344,9 +4506,9 @@ checksum = "468aa43b7edb1f9b7b7b686d5c3aeb6630dc1708e86e31343499dd5c4d775183" [[package]] name = "solana-send-transaction-service" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4de519acd09b182fe8a56014a5cc9d9f676e5217e0e8e61c1ae2af777e7e0fa" +checksum = "2cb273c3f59950d747ac54396babcc6aca09fcb6ac40c83313ce4a65eb4ea208" dependencies = [ "crossbeam-channel", "log", @@ -4360,9 +4522,9 @@ dependencies = [ [[package]] name = "solana-stake-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c21a028ed8abed4a7a52b8410875d799b31b58489653e05ae885e2ba799463" +checksum = "ddeec78f830d8d91d4185d4cb92760efcc757013c57347de1dfd19cb3bfd07c1" dependencies = [ "bincode", "log", @@ -4375,9 +4537,9 @@ dependencies = [ [[package]] name = "solana-streamer" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "067d167db6be6f25c21e4c615607757ae7161b20e08197ec2d1a63360e522069" +checksum = "3027d10aacba000eca43ac59acfec0069f93dbe3ea372d94eb7d25ed490b396d" dependencies = [ "async-channel", "bytes", @@ -4408,9 +4570,9 @@ dependencies = [ [[package]] name = "solana-system-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4fa662731817f995cd114ce44d780be2814982a7674540be8d1c596a2d1ca43" +checksum = "244a998e66934e5a6283f69500da23af5c1d09c1f8493bc1b04d3b2f1553dad9" dependencies = [ "bincode", "log", @@ -4422,9 +4584,9 @@ dependencies = [ [[package]] name = "solana-thin-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0815c6d64a4bd71fd92ce33e82c24f5e8a5b105b26619521c4a8a43ab7573a9a" +checksum = "6e49f48b5734d90c9cc6022a2b3dcf31a8794d565850a25ff5b9820e16bd40e9" dependencies = [ "bincode", "log", @@ -4437,9 +4599,9 @@ dependencies = [ [[package]] name = "solana-tpu-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "576431a39a612dac9387fecb5e80fe58989b740337a07bca41f0d02695e415f9" +checksum = "474f9cd741f564f8a92b7a73da1c83ceb80137bad1b25f403bc1c57468c3e6a3" dependencies = [ "async-trait", "bincode", @@ -4461,9 +4623,9 @@ dependencies = [ [[package]] name = "solana-transaction-status" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0d8e2d97a8569afba70a105b402057b253fd9caee92c7ed2c3e1c3e0173fe91" +checksum = "65cbdbde85fff3b4c2e134f6bd70d26c0cc9cd2b63892be2afd424a21e2b316b" dependencies = [ "Inflector", "base64 0.21.7", @@ -4486,9 +4648,9 @@ dependencies = [ [[package]] name = "solana-udp-client" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8297b04cb335ffac5b4a2c727dd82a2f72c8a96e3d5e1c159e01866b74a17e50" +checksum = "e1263d731f2ee858b36fc6dac56be7fe7dc46fe223de6867c8a957cd587d565e" dependencies = [ "async-trait", "solana-connection-cache", @@ -4501,9 +4663,9 @@ dependencies = [ [[package]] name = "solana-version" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84a9f9ff3feebfaa960ac5387b133c6ef2c266779cb4932aed6acac5b83cb7b" +checksum = "c24d542f3b834717e81ac0d44905d3efa27ddf21c265a163e8b54ea0358204f5" dependencies = [ "log", "rustc_version", @@ -4517,9 +4679,9 @@ dependencies = [ [[package]] name = "solana-vote" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a2355a2b40d7b0b3a9ec5a5bd2196494c620a287ce6e4234cc4722fcb0cbb5" +checksum = "a11718909a64a22de2745be42f4f3f195122b3da8b028af75e3139198da0a373" dependencies = [ "crossbeam-channel", "itertools", @@ -4536,13 +4698,13 @@ dependencies = [ [[package]] name = "solana-vote-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab0fe8455b2f06016cddefe7e3a7b9c0a57661d44816a4105c81f1088cfc1ac" +checksum = "8f26743a7027077e88cd4b136099c926dc04b38dc638e88223e88c5d05b3374a" dependencies = [ "bincode", "log", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "rustc_version", "serde", @@ -4558,12 +4720,12 @@ dependencies = [ [[package]] name = "solana-zk-token-proof-program" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad624adcac620e41d052b29705f30c003b2e396ebca0145c1d296a1ef13f5aa7" +checksum = "cdfb619937c8cda3c862151473cf1a8443ac5b2e75a5b8a8675fcf9b1f0aa08c" dependencies = [ "bytemuck", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "solana-program-runtime", "solana-sdk", @@ -4572,9 +4734,9 @@ dependencies = [ [[package]] name = "solana-zk-token-sdk" -version = "1.17.34" +version = "1.18.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70a06e103ed5adf1664f9cca3d1c64edad8b5b603255d8a5dd21a4ac5d86b89c" +checksum = "8cf73fd7e430bf3269539c2fb1d05af0df26fc3b7bc090172ceda5cd4340657c" dependencies = [ "aes-gcm-siv", "base64 0.21.7", @@ -4586,7 +4748,7 @@ dependencies = [ "itertools", "lazy_static", "merlin", - "num-derive 0.3.3", + "num-derive 0.4.2", "num-traits", "rand 0.7.3", "serde", @@ -4921,6 +5083,18 @@ dependencies = [ "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.55", +] + [[package]] name = "sync_wrapper" version = "0.1.2" @@ -5027,6 +5201,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + [[package]] name = "test-case" version = "3.3.1" diff --git a/Cargo.toml b/Cargo.toml index 645e0392..dd9175d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,9 +44,9 @@ jito-vault-sdk = { path = "vault_sdk", version = "=0.0.1" } jito-vault-program = { path = "vault_program", version = "=0.0.1" } jito-restaking-program = { path = "restaking_program", version = "=0.0.1" } shank = "0.4.2" -solana-program = "~1.17" -solana-program-test = "~1.17" -solana-sdk = "~1.17" +solana-program = "~1.18" +solana-program-test = "~1.18" +solana-sdk = "~1.18" solana-security-txt = "1.1.1" spl-token = { version = "4.0.0", features = ["no-entrypoint"] } spl-associated-token-account = { version = "2.2.0", features = ["no-entrypoint"] } diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml index 4a512098..3ad394b2 100644 --- a/integration_tests/Cargo.toml +++ b/integration_tests/Cargo.toml @@ -27,3 +27,5 @@ spl-associated-token-account = { workspace = true } spl-token = { workspace = true } thiserror = { workspace = true } tokio = { workspace = true } +[dependencies] +log = "0.4.21" \ No newline at end of file diff --git a/integration_tests/tests/fixtures/fixture.rs b/integration_tests/tests/fixtures/fixture.rs index 0fa070b3..9ba2419f 100644 --- a/integration_tests/tests/fixtures/fixture.rs +++ b/integration_tests/tests/fixtures/fixture.rs @@ -1,14 +1,17 @@ -use std::fmt::{Debug, Formatter}; - +use borsh::BorshSerialize; use solana_program::{ + clock::Clock, native_token::sol_to_lamports, program_pack::Pack, pubkey::Pubkey, rent::Rent, system_instruction::{create_account, transfer}, }; -use solana_program_test::{processor, BanksClientError, ProgramTest, ProgramTestContext}; +use solana_program_test::{ + processor, BanksClient, BanksClientError, ProgramTest, ProgramTestContext, +}; use solana_sdk::{ + account::AccountSharedData, commitment_config::CommitmentLevel, signature::{Keypair, Signer}, transaction::Transaction, @@ -20,6 +23,8 @@ use spl_token::{ instruction::initialize_mint2, state::{Account, Mint}, }; +use std::fmt::{Debug, Formatter}; +use std::sync::Arc; use crate::fixtures::{restaking_client::RestakingProgramClient, vault_client::VaultProgramClient}; @@ -51,24 +56,56 @@ impl TestBuilder { Self { context } } - // pub async fn store_account( - // &mut self, - // pubkey: &Pubkey, - // owner: &Pubkey, - // data: &T, - // ) -> Result<(), BanksClientError> { - // let rent: Rent = self.context.banks_client.get_sysvar().await?; - // - // let serialized = data.try_to_vec().unwrap(); - // let mut data = AccountSharedData::new( - // rent.minimum_balance(serialized.len()), - // serialized.len(), - // owner, - // ); - // data.set_data_from_slice(serialized.as_slice()); - // self.context.set_account(pubkey, &data); - // Ok(()) - // } + pub async fn store_borsh_account( + &mut self, + pubkey: &Pubkey, + owner: &Pubkey, + data: &T, + ) -> Result<(), BanksClientError> { + let rent: Rent = self.context.banks_client.get_sysvar().await?; + + let serialized = data.try_to_vec().unwrap(); + let mut data = AccountSharedData::new( + rent.minimum_balance(serialized.len()), + serialized.len(), + owner, + ); + data.set_data_from_slice(serialized.as_slice()); + self.context.set_account(pubkey, &data); + Ok(()) + } + + pub async fn get_account( + &mut self, + pubkey: &Pubkey, + ) -> Result { + let account = self + .context + .banks_client + .get_account_with_commitment(*pubkey, CommitmentLevel::Processed) + .await? + .unwrap(); + Ok(account) + } + + pub async fn store_account( + &mut self, + pubkey: &Pubkey, + owner: &Pubkey, + data: &[u8], + ) -> Result<(), BanksClientError> { + let rent: Rent = self.context.banks_client.get_sysvar().await?; + + let serialized = data.to_vec(); + let mut data = AccountSharedData::new( + rent.minimum_balance(serialized.len()), + serialized.len(), + owner, + ); + data.set_data_from_slice(serialized.as_slice()); + self.context.set_account(pubkey, &data); + Ok(()) + } pub async fn transfer(&mut self, to: &Pubkey, sol: f64) -> Result<(), BanksClientError> { let blockhash = self.context.banks_client.get_latest_blockhash().await?; @@ -90,11 +127,6 @@ impl TestBuilder { .await } - // pub async fn get_mint(&mut self, mint: &Pubkey) -> Result { - // let account = self.context.banks_client.get_account(*mint).await?.unwrap(); - // Ok(Mint::unpack(&account.data).unwrap()) - // } - pub async fn get_token_account( &mut self, token_account: &Pubkey, @@ -204,19 +236,25 @@ impl TestBuilder { .await } - // pub async fn warp_to_next_slot(&mut self) -> Result<(), BanksClientError> { - // let clock: Clock = self.context.banks_client.get_sysvar().await?; - // self.context - // .warp_to_slot(clock.slot.checked_add(1).unwrap()) - // .map_err(|_| BanksClientError::ClientError("failed to warp slot"))?; - // Ok(()) - // } + pub async fn warp_to_next_slot(&mut self) -> Result<(), BanksClientError> { + let clock: Clock = self.context.banks_client.get_sysvar().await?; + self.context + .warp_to_slot(clock.slot.checked_add(1).unwrap()) + .map_err(|_| BanksClientError::ClientError("failed to warp slot"))?; + Ok(()) + } pub fn vault_program_client(&self) -> VaultProgramClient { - VaultProgramClient::new(self.context.banks_client.clone()) + VaultProgramClient::new( + self.context.banks_client.clone(), + self.context.payer.insecure_clone(), + ) } pub fn restaking_program_client(&self) -> RestakingProgramClient { - RestakingProgramClient::new(self.context.banks_client.clone()) + RestakingProgramClient::new( + self.context.banks_client.clone(), + self.context.payer.insecure_clone(), + ) } } diff --git a/integration_tests/tests/fixtures/restaking_client.rs b/integration_tests/tests/fixtures/restaking_client.rs index 6f0a0362..69c9c27c 100644 --- a/integration_tests/tests/fixtures/restaking_client.rs +++ b/integration_tests/tests/fixtures/restaking_client.rs @@ -9,7 +9,7 @@ use jito_restaking_sdk::{ avs_add_operator, avs_add_vault, avs_add_vault_slasher, initialize_avs, initialize_config, initialize_operator, operator_add_avs, operator_add_vault, }; -use solana_program::pubkey::Pubkey; +use solana_program::{native_token::sol_to_lamports, pubkey::Pubkey, system_instruction::transfer}; use solana_program_test::{BanksClient, BanksClientError}; use solana_sdk::{ commitment_config::CommitmentLevel, @@ -17,17 +17,30 @@ use solana_sdk::{ transaction::Transaction, }; +pub struct AvsRoot { + pub avs_pubkey: Pubkey, + pub avs_admin: Keypair, +} + pub struct RestakingProgramClient { banks_client: BanksClient, + payer: Keypair, } impl RestakingProgramClient { - pub const fn new(banks_client: BanksClient) -> Self { - Self { banks_client } + pub const fn new(banks_client: BanksClient, payer: Keypair) -> Self { + Self { + banks_client, + payer, + } } pub async fn get_avs(&mut self, avs: &Pubkey) -> Result { - let account = self.banks_client.get_account(*avs).await?.unwrap(); + let account = self + .banks_client + .get_account_with_commitment(*avs, CommitmentLevel::Processed) + .await? + .unwrap(); Ok(Avs::deserialize(&mut account.data.as_slice())?) } @@ -117,6 +130,17 @@ impl RestakingProgramClient { )?) } + pub async fn setup_config(&mut self) -> Result { + let restaking_config_pubkey = Config::find_program_address(&jito_restaking_program::id()).0; + let restaking_config_admin = Keypair::new(); + + self._airdrop(&restaking_config_admin.pubkey(), 1.0).await?; + self.initialize_config(&restaking_config_pubkey, &restaking_config_admin) + .await?; + + Ok(restaking_config_admin) + } + pub async fn initialize_config( &mut self, config: &Pubkey, @@ -137,6 +161,52 @@ impl RestakingProgramClient { .await } + pub async fn setup_avs(&mut self) -> Result { + let avs_admin = Keypair::new(); + let avs_base = Keypair::new(); + + self._airdrop(&avs_admin.pubkey(), 1.0).await?; + + let avs_pubkey = + Avs::find_program_address(&jito_restaking_program::id(), &avs_base.pubkey()).0; + self.initialize_avs( + &Config::find_program_address(&jito_restaking_program::id()).0, + &avs_pubkey, + &avs_admin, + &avs_base, + ) + .await + .unwrap(); + + Ok(AvsRoot { + avs_pubkey, + avs_admin, + }) + } + + pub async fn avs_vault_opt_in( + &mut self, + avs_root: &AvsRoot, + vault: &Pubkey, + ) -> Result<(), BanksClientError> { + let avs_vault_ticket = AvsVaultTicket::find_program_address( + &jito_restaking_program::id(), + &avs_root.avs_pubkey, + vault, + ) + .0; + + self.avs_add_vault( + &Config::find_program_address(&jito_restaking_program::id()).0, + &avs_root.avs_pubkey, + vault, + &avs_vault_ticket, + &avs_root.avs_admin, + &self.payer.insecure_clone(), + ) + .await + } + pub async fn initialize_avs( &mut self, config: &Pubkey, @@ -623,4 +693,19 @@ impl RestakingProgramClient { ) .await } + + pub async fn _airdrop(&mut self, to: &Pubkey, sol: f64) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.banks_client + .process_transaction_with_preflight_and_commitment( + Transaction::new_signed_with_payer( + &[transfer(&self.payer.pubkey(), to, sol_to_lamports(sol))], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + ), + CommitmentLevel::Processed, + ) + .await + } } diff --git a/integration_tests/tests/fixtures/vault_client.rs b/integration_tests/tests/fixtures/vault_client.rs index d11443ee..58d1f315 100644 --- a/integration_tests/tests/fixtures/vault_client.rs +++ b/integration_tests/tests/fixtures/vault_client.rs @@ -1,25 +1,242 @@ use borsh::BorshDeserialize; +use jito_restaking_core::avs_vault_ticket::AvsVaultTicket; use jito_vault_core::{ config::Config, vault::Vault, vault_avs_slasher_operator_ticket::VaultAvsSlasherOperatorTicket, vault_avs_slasher_ticket::VaultAvsSlasherTicket, vault_avs_ticket::VaultAvsTicket, vault_delegation_list::VaultDelegationList, vault_operator_ticket::VaultOperatorTicket, }; use jito_vault_sdk::{add_delegation, initialize_config, initialize_vault}; -use solana_program::pubkey::Pubkey; +use solana_program::{ + native_token::sol_to_lamports, + program_pack::Pack, + pubkey::Pubkey, + rent::Rent, + system_instruction::{create_account, transfer}, +}; use solana_program_test::{BanksClient, BanksClientError}; use solana_sdk::{ commitment_config::CommitmentLevel, signature::{Keypair, Signer}, transaction::Transaction, }; +use spl_associated_token_account::{ + get_associated_token_address, instruction::create_associated_token_account_idempotent, +}; +use spl_token::{ + instruction::initialize_mint2, + state::{Account, Mint}, +}; +// +// struct EnqueueWithdrawAccountData { +// config_pubkey: Pubkey, +// config: Config, +// +// vault_pubkey: Pubkey, +// vault: Vault, +// +// vault_delegation_list_pubkey: Pubkey, +// vault_delegation_list: VaultDelegationList, +// +// vault_staker_withdraw_ticket: Pubkey, +// +// vault_staker_withdraw_ticket_token_account: Pubkey, +// +// staker: Keypair, +// +// staker_lrt_token_account: Pubkey, +// +// base: Keypair, +// } + +// fn prepare_accounts( +// vault_index: u64, +// deposit_fee_bps: u16, +// withdrawal_fee_bps: u16, +// ) -> EnqueueWithdrawAccountData { +// let (config_pubkey, config_bump, _) = Config::find_program_address(&jito_vault_program::id()); +// let mut config = Config::new( +// Pubkey::new_unique(), +// jito_restaking_program::id(), +// config_bump, +// ); +// // assume the vault is created +// config.increment_vaults().unwrap(); +// +// let base = Pubkey::new_unique(); +// let (vault_pubkey, bump, _) = Vault::find_program_address(&jito_vault_program::id(), &base); +// let vault = Vault::new( +// Pubkey::new_unique(), +// Pubkey::new_unique(), +// Pubkey::new_unique(), +// vault_index, +// base, +// deposit_fee_bps, +// withdrawal_fee_bps, +// bump, +// ); +// +// let (vault_delegation_list_pubkey, vault_delegation_list_bump, _) = +// VaultDelegationList::find_program_address(&jito_vault_program::id(), &vault_pubkey); +// let vault_delegation_list = VaultDelegationList::new(vault_pubkey, vault_delegation_list_bump); +// +// let staker = Keypair::new(); +// +// let staker_lrt_token_account = +// get_associated_token_address(&staker.pubkey(), &vault.lrt_mint()); +// +// let base = Keypair::new(); +// +// let vault_staker_withdraw_ticket = VaultStakerWithdrawTicket::find_program_address( +// &jito_vault_program::id(), +// &vault_pubkey, +// &staker.pubkey(), +// &base.pubkey(), +// ) +// .0; +// let vault_staker_withdraw_ticket_token_account = +// get_associated_token_address(&vault_staker_withdraw_ticket, &vault.lrt_mint()); +// +// EnqueueWithdrawAccountData { +// config_pubkey, +// config, +// vault_pubkey, +// vault, +// vault_delegation_list_pubkey, +// vault_delegation_list, +// vault_staker_withdraw_ticket, +// vault_staker_withdraw_ticket_token_account, +// staker, +// staker_lrt_token_account, +// base, +// } +// } +// +// async fn write_enqueue_withdraw_accounts( +// accounts: &EnqueueWithdrawAccountData, +// fixture: &mut TestBuilder, +// ) { +// let EnqueueWithdrawAccountData { +// config_pubkey, +// config, +// vault_pubkey, +// vault, +// vault_delegation_list_pubkey, +// vault_delegation_list, +// vault_staker_withdraw_ticket: _, // created in the function +// vault_staker_withdraw_ticket_token_account, +// staker, +// staker_lrt_token_account, +// base: _, +// } = accounts; +// +// fixture +// .store_borsh_account(&config_pubkey, &jito_vault_program::id(), &config) +// .await +// .unwrap(); +// +// fixture +// .store_borsh_account(vault_pubkey, &jito_vault_program::id(), &vault) +// .await +// .unwrap(); +// let mut mint_buf = [0; Mint::LEN]; +// Mint { +// mint_authority: COption::Some(*vault_pubkey), +// supply: 0, +// decimals: 9, +// is_initialized: true, +// freeze_authority: COption::None, +// } +// .pack_into_slice(&mut mint_buf); +// fixture +// .store_account(&vault.lrt_mint(), &spl_token::id(), &mint_buf) +// .await +// .unwrap(); +// fixture +// .store_account(&vault.supported_mint(), &spl_token::id(), &mint_buf) +// .await +// .unwrap(); +// +// fixture +// .store_borsh_account( +// &VaultDelegationList::find_program_address(&jito_vault_program::id(), &vault_pubkey).0, +// &jito_vault_program::id(), +// &vault_delegation_list, +// ) +// .await +// .unwrap(); +// +// let mut token_account_buf = [0; Account::LEN]; +// // setup the LRT token account owned by the vault_staker_withdraw_ticket +// Account { +// mint: vault.lrt_mint(), +// owner: *vault_pubkey, +// amount: 0, +// delegate: COption::None, +// state: spl_token::state::AccountState::Initialized, +// is_native: COption::None, +// delegated_amount: 0, +// close_authority: COption::None, +// } +// .pack_into_slice(&mut token_account_buf); +// fixture +// .store_account( +// vault_staker_withdraw_ticket_token_account, +// &spl_token::id(), +// &token_account_buf, +// ) +// .await +// .unwrap(); +// +// // setup the LRT token account owned by the staker +// Account { +// mint: vault.lrt_mint(), +// owner: staker.pubkey(), +// amount: 0, +// delegate: COption::None, +// state: spl_token::state::AccountState::Initialized, +// is_native: COption::None, +// delegated_amount: 0, +// close_authority: COption::None, +// } +// .pack_into_slice(&mut token_account_buf); +// fixture +// .store_account( +// staker_lrt_token_account, +// &spl_token::id(), +// &token_account_buf, +// ) +// .await +// .unwrap(); +// } + +pub struct VaultRoot { + pub vault_pubkey: Pubkey, + pub vault_admin: Keypair, +} pub struct VaultProgramClient { banks_client: BanksClient, + payer: Keypair, } impl VaultProgramClient { - pub const fn new(banks_client: BanksClient) -> Self { - Self { banks_client } + pub const fn new(banks_client: BanksClient, payer: Keypair) -> Self { + Self { + banks_client, + payer, + } + } + + pub async fn get_account( + &mut self, + pubkey: &Pubkey, + ) -> Result { + let account = self + .banks_client + .get_account_with_commitment(*pubkey, CommitmentLevel::Processed) + .await? + .unwrap(); + Ok(account) } pub async fn get_config(&mut self, account: &Pubkey) -> Result { @@ -107,13 +324,25 @@ impl VaultProgramClient { )?) } + pub async fn setup_config(&mut self) -> Result { + let config_admin = Keypair::new(); + + self._airdrop(&config_admin.pubkey(), 1.0).await?; + + let config_pubkey = Config::find_program_address(&jito_vault_program::id()).0; + self.initialize_config(&config_pubkey, &config_admin) + .await?; + + Ok(config_admin) + } + pub async fn initialize_config( &mut self, config: &Pubkey, config_admin: &Keypair, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[initialize_config( &jito_vault_program::id(), &config, @@ -127,6 +356,80 @@ impl VaultProgramClient { .await } + pub async fn setup_vault( + &mut self, + deposit_fee_bps: u16, + withdraw_fee_bps: u16, + ) -> Result<(Keypair, VaultRoot), BanksClientError> { + let config_admin = self.setup_config().await?; + + let vault_base = Keypair::new(); + + let vault_pubkey = + Vault::find_program_address(&jito_vault_program::id(), &vault_base.pubkey()).0; + let vault_delegation_list = + VaultDelegationList::find_program_address(&jito_vault_program::id(), &vault_pubkey).0; + + let lrt_mint = Keypair::new(); + let vault_admin = Keypair::new(); + let token_mint = Keypair::new(); + + self._airdrop(&vault_admin.pubkey(), 1.0).await?; + self._create_token_mint(&token_mint).await?; + + self.initialize_vault( + &Config::find_program_address(&jito_vault_program::id()).0, + &vault_pubkey, + &vault_delegation_list, + &lrt_mint, + &token_mint, + &vault_admin, + &vault_base, + deposit_fee_bps, + withdraw_fee_bps, + ) + .await?; + + Ok(( + config_admin, + VaultRoot { + vault_admin, + vault_pubkey, + }, + )) + } + + pub async fn vault_avs_opt_in( + &mut self, + vault_root: &VaultRoot, + avs: &Pubkey, + ) -> Result<(), BanksClientError> { + let vault_avs_ticket = VaultAvsTicket::find_program_address( + &jito_vault_program::id(), + &vault_root.vault_pubkey, + &avs, + ) + .0; + let avs_vault_ticket = AvsVaultTicket::find_program_address( + &jito_restaking_program::id(), + &avs, + &vault_root.vault_pubkey, + ) + .0; + self.add_avs( + &Config::find_program_address(&jito_vault_program::id()).0, + &vault_root.vault_pubkey, + &avs, + &avs_vault_ticket, + &vault_avs_ticket, + &vault_root.vault_admin, + &self.payer.insecure_clone(), + ) + .await?; + + Ok(()) + } + pub async fn initialize_vault( &mut self, config: &Pubkey, @@ -141,7 +444,7 @@ impl VaultProgramClient { ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[initialize_vault( &jito_vault_program::id(), &config, @@ -172,7 +475,8 @@ impl VaultProgramClient { payer: &Keypair, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + + self._process_transaction(&Transaction::new_signed_with_payer( &[jito_vault_sdk::add_avs( &jito_vault_program::id(), config, @@ -226,7 +530,7 @@ impl VaultProgramClient { payer: &Keypair, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[jito_vault_sdk::add_operator( &jito_vault_program::id(), config, @@ -244,30 +548,38 @@ impl VaultProgramClient { .await } - // pub async fn remove_operator( - // &mut self, - // config: &Pubkey, - // vault: &Pubkey, - // operator: &Pubkey, - // vault_operator_ticket: &Pubkey, - // admin: &Keypair, - // ) -> Result<(), BanksClientError> { - // let blockhash = self.banks_client.get_latest_blockhash().await?; - // self.process_transaction(&Transaction::new_signed_with_payer( - // &[jito_vault_sdk::remove_operator( - // &jito_vault_program::id(), - // config, - // vault, - // operator, - // vault_operator_ticket, - // &admin.pubkey(), - // )], - // Some(&admin.pubkey()), - // &[admin], - // blockhash, - // )) - // .await - // } + pub async fn enqueue_withdraw( + &mut self, + config: &Pubkey, + vault: &Pubkey, + vault_delegation_list: &Pubkey, + vault_staker_withdraw_ticket: &Pubkey, + vault_staker_withdraw_ticket_token_account: &Pubkey, + staker: &Keypair, + staker_lrt_token_account: &Pubkey, + base: &Keypair, + amount: u64, + ) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + self._process_transaction(&Transaction::new_signed_with_payer( + &[jito_vault_sdk::enqueue_withdraw( + &jito_vault_program::id(), + config, + vault, + vault_delegation_list, + vault_staker_withdraw_ticket, + vault_staker_withdraw_ticket_token_account, + &staker.pubkey(), + staker_lrt_token_account, + &base.pubkey(), + amount, + )], + Some(&staker.pubkey()), + &[staker, base], + blockhash, + )) + .await + } pub async fn add_delegation( &mut self, @@ -281,7 +593,7 @@ impl VaultProgramClient { amount: u64, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[add_delegation( &jito_vault_program::id(), config, @@ -344,7 +656,7 @@ impl VaultProgramClient { if let Some(signer) = mint_signer { signers.push(signer); } - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[jito_vault_sdk::mint_to( &jito_vault_program::id(), vault, @@ -464,7 +776,7 @@ impl VaultProgramClient { payer: &Keypair, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[jito_vault_sdk::add_slasher( &jito_vault_program::id(), config, @@ -495,7 +807,7 @@ impl VaultProgramClient { payer: &Keypair, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[ jito_vault_sdk::initialize_vault_avs_slasher_operator_ticket( &jito_vault_program::id(), @@ -538,7 +850,7 @@ impl VaultProgramClient { amount: u64, ) -> Result<(), BanksClientError> { let blockhash = self.banks_client.get_latest_blockhash().await?; - self.process_transaction(&Transaction::new_signed_with_payer( + self._process_transaction(&Transaction::new_signed_with_payer( &[jito_vault_sdk::slash( &jito_vault_program::id(), config, @@ -567,7 +879,7 @@ impl VaultProgramClient { .await } - pub async fn process_transaction(&mut self, tx: &Transaction) -> Result<(), BanksClientError> { + async fn _process_transaction(&mut self, tx: &Transaction) -> Result<(), BanksClientError> { self.banks_client .process_transaction_with_preflight_and_commitment( tx.clone(), @@ -575,4 +887,124 @@ impl VaultProgramClient { ) .await } + + pub async fn _airdrop(&mut self, to: &Pubkey, sol: f64) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.banks_client + .process_transaction_with_preflight_and_commitment( + Transaction::new_signed_with_payer( + &[transfer(&self.payer.pubkey(), to, sol_to_lamports(sol))], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + ), + CommitmentLevel::Processed, + ) + .await + } + + pub async fn get_token_account( + &mut self, + token_account: &Pubkey, + ) -> Result { + let account = self + .banks_client + .get_account(*token_account) + .await? + .unwrap(); + Ok(Account::unpack(&account.data).unwrap()) + } + + /// Mints tokens to an ATA owned by the `to` address + pub async fn mint_spl_to( + &mut self, + mint: &Pubkey, + to: &Pubkey, + amount: u64, + ) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.banks_client + .process_transaction_with_preflight_and_commitment( + Transaction::new_signed_with_payer( + &[ + create_associated_token_account_idempotent( + &self.payer.pubkey(), + to, + mint, + &spl_token::id(), + ), + spl_token::instruction::mint_to( + &spl_token::id(), + mint, + &get_associated_token_address(to, mint), + &self.payer.pubkey(), + &[], + amount, + ) + .unwrap(), + ], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + ), + CommitmentLevel::Processed, + ) + .await + } + + async fn _create_token_mint(&mut self, mint: &Keypair) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + let rent: Rent = self.banks_client.get_sysvar().await?; + self.banks_client + .process_transaction_with_preflight_and_commitment( + Transaction::new_signed_with_payer( + &[ + create_account( + &self.payer.pubkey(), + &mint.pubkey(), + rent.minimum_balance(Mint::LEN), + Mint::LEN as u64, + &spl_token::id(), + ), + initialize_mint2( + &spl_token::id(), + &mint.pubkey(), + &self.payer.pubkey(), + None, + 9, + ) + .unwrap(), + ], + Some(&self.payer.pubkey()), + &[&self.payer, mint], + blockhash, + ), + CommitmentLevel::Processed, + ) + .await + } + + pub async fn create_ata( + &mut self, + mint: &Pubkey, + owner: &Pubkey, + ) -> Result<(), BanksClientError> { + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.banks_client + .process_transaction_with_preflight_and_commitment( + Transaction::new_signed_with_payer( + &[create_associated_token_account_idempotent( + &self.payer.pubkey(), + owner, + mint, + &spl_token::id(), + )], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + ), + CommitmentLevel::Processed, + ) + .await + } } diff --git a/integration_tests/tests/vault/add_avs.rs b/integration_tests/tests/vault/add_avs.rs index d54f8c49..4808440f 100644 --- a/integration_tests/tests/vault/add_avs.rs +++ b/integration_tests/tests/vault/add_avs.rs @@ -1,128 +1,65 @@ -use jito_restaking_core::{ - avs::Avs, avs_vault_ticket::AvsVaultTicket, config::Config as RestakingConfig, -}; -use jito_vault_core::{ - config::Config as VaultConfig, vault::Vault, vault_avs_ticket::VaultAvsTicket, - vault_delegation_list::VaultDelegationList, -}; +use crate::fixtures::{fixture::TestBuilder, restaking_client::AvsRoot}; +use jito_restaking_core::{avs::Avs, config::Config}; +use log::info; +use solana_program::clock::Clock; +use solana_program::sysvar::SysvarId; use solana_sdk::signature::{Keypair, Signer}; - -use crate::fixtures::fixture::TestBuilder; +use std::time::Duration; +use tokio::time::sleep; #[tokio::test] async fn test_add_avs_ok() { - let mut fixture = TestBuilder::new().await; + let fixture = TestBuilder::new().await; let mut restaking_program_client = fixture.restaking_program_client(); - let mut vault_program_client = fixture.vault_program_client(); - - let backing_token_mint = Keypair::new(); - fixture - .create_token_mint(&backing_token_mint) - .await - .unwrap(); - - let vault_config_pubkey = VaultConfig::find_program_address(&jito_vault_program::id()).0; - let vault_config_admin = Keypair::new(); - - fixture - .transfer(&vault_config_admin.pubkey(), 1.0) - .await - .unwrap(); - - vault_program_client - .initialize_config(&vault_config_pubkey, &vault_config_admin) - .await - .unwrap(); - - // create vault - let vault_base = Keypair::new(); - let vault_pubkey = - Vault::find_program_address(&jito_vault_program::id(), &vault_base.pubkey()).0; - let vault_delegation_list = - VaultDelegationList::find_program_address(&jito_vault_program::id(), &vault_pubkey).0; - let lrt_mint = Keypair::new(); - let vault_admin = Keypair::new(); + let mut fixture = TestBuilder::new().await; - fixture.transfer(&vault_admin.pubkey(), 1.0).await.unwrap(); + let mut vault_program_client = fixture.vault_program_client(); - vault_program_client - .initialize_vault( - &vault_config_pubkey, - &vault_pubkey, - &vault_delegation_list, - &lrt_mint, - &backing_token_mint, - &vault_admin, - &vault_base, - 100, - 100, - ) - .await - .unwrap(); + let (_config_admin, vault_root) = vault_program_client.setup_vault(99, 100).await.unwrap(); - let restaking_config_pubkey = - RestakingConfig::find_program_address(&jito_restaking_program::id()).0; - let restaking_config_admin = Keypair::new(); + let _restaking_config_admin = restaking_program_client.setup_config().await.unwrap(); - fixture - .transfer(&restaking_config_admin.pubkey(), 1.0) - .await - .unwrap(); - restaking_program_client - .initialize_config(&restaking_config_pubkey, &restaking_config_admin) - .await - .unwrap(); + // let avs_root = restaking_program_client.setup_avs().await.unwrap(); // create AVS + add AVS vault let avs_admin = Keypair::new(); let avs_base = Keypair::new(); fixture.transfer(&avs_admin.pubkey(), 1.0).await.unwrap(); + sleep(Duration::from_secs(1)).await; let avs_pubkey = Avs::find_program_address(&jito_restaking_program::id(), &avs_base.pubkey()).0; + restaking_program_client - .initialize_avs(&restaking_config_pubkey, &avs_pubkey, &avs_admin, &avs_base) - .await - .unwrap(); - let avs_vault_ticket = AvsVaultTicket::find_program_address( - &jito_restaking_program::id(), - &avs_pubkey, - &vault_pubkey, - ) - .0; - restaking_program_client - .avs_add_vault( - &restaking_config_pubkey, + .initialize_avs( + &Config::find_program_address(&jito_restaking_program::id()).0, &avs_pubkey, - &vault_pubkey, - &avs_vault_ticket, - &avs_admin, &avs_admin, + &avs_base, ) .await .unwrap(); - let vault_avs_ticket = - VaultAvsTicket::find_program_address(&jito_vault_program::id(), &vault_pubkey, &avs_pubkey) - .0; - vault_program_client - .add_avs( - &vault_config_pubkey, - &vault_pubkey, - &avs_pubkey, - &avs_vault_ticket, - &vault_avs_ticket, - &vault_admin, - &vault_admin, - ) - .await - .unwrap(); - - let vault_avs_ticket_account = vault_program_client - .get_vault_avs_ticket(&vault_pubkey, &avs_pubkey) - .await - .unwrap(); - assert_eq!(vault_avs_ticket_account.vault(), vault_pubkey); - assert_eq!(vault_avs_ticket_account.avs(), avs_pubkey); - assert_eq!(vault_avs_ticket_account.index(), 0); - assert_eq!(vault_avs_ticket_account.state().slot_added(), 1); + // let avs_root = AvsRoot { + // avs_pubkey, + // avs_admin, + // }; + // + // restaking_program_client + // .avs_vault_opt_in(&avs_root, &vault_root.vault_pubkey) + // .await + // .unwrap(); + // + // vault_program_client + // .vault_avs_opt_in(&vault_root, &avs_root.avs_pubkey) + // .await + // .unwrap(); + // + // let vault_avs_ticket_account = vault_program_client + // .get_vault_avs_ticket(&vault_root.vault_pubkey, &avs_root.avs_pubkey) + // .await + // .unwrap(); + // assert_eq!(vault_avs_ticket_account.vault(), vault_root.vault_pubkey); + // assert_eq!(vault_avs_ticket_account.avs(), avs_root.avs_pubkey); + // assert_eq!(vault_avs_ticket_account.index(), 0); + // assert_eq!(vault_avs_ticket_account.state().slot_added(), 1); } diff --git a/integration_tests/tests/vault/enqueue_withdrawal.rs b/integration_tests/tests/vault/enqueue_withdrawal.rs new file mode 100644 index 00000000..f7c0794e --- /dev/null +++ b/integration_tests/tests/vault/enqueue_withdrawal.rs @@ -0,0 +1,30 @@ +#[tokio::test] +async fn test_enqueue_withdrawal_success() { + // let fixture = TestBuilder::new().await; + // + // let mut vault_program_client = fixture.vault_program_client(); + + // let accounts = prepare_accounts(0, 0, 0); + // + // write_enqueue_withdraw_accounts(&accounts, &mut fixture).await; + + // fixture + // .transfer(&accounts.staker.pubkey(), 1.0) + // .await + // .unwrap(); + // + // vault_program_client + // .enqueue_withdraw( + // &accounts.config_pubkey, + // &accounts.vault_pubkey, + // &accounts.vault_delegation_list_pubkey, + // &accounts.vault_staker_withdraw_ticket, + // &accounts.vault_staker_withdraw_ticket_token_account, + // &accounts.staker, + // &accounts.staker_lrt_token_account, + // &accounts.base, + // 1000, + // ) + // .await + // .unwrap(); +} diff --git a/integration_tests/tests/vault/initialize_config.rs b/integration_tests/tests/vault/initialize_config.rs index 88f2af11..522637cf 100644 --- a/integration_tests/tests/vault/initialize_config.rs +++ b/integration_tests/tests/vault/initialize_config.rs @@ -5,21 +5,13 @@ use crate::fixtures::fixture::TestBuilder; #[tokio::test] async fn test_initialize_config_ok() { - let mut fixture = TestBuilder::new().await; + let fixture = TestBuilder::new().await; let mut vault_program_client = fixture.vault_program_client(); - let config_pubkey = Config::find_program_address(&jito_vault_program::id()).0; - let config_admin = Keypair::new(); - - fixture.transfer(&config_admin.pubkey(), 1.0).await.unwrap(); - - vault_program_client - .initialize_config(&config_pubkey, &config_admin) - .await - .unwrap(); + let config_admin = vault_program_client.setup_config().await.unwrap(); let config = vault_program_client - .get_config(&config_pubkey) + .get_config(&Config::find_program_address(&jito_vault_program::id()).0) .await .unwrap(); diff --git a/integration_tests/tests/vault/initialize_vault.rs b/integration_tests/tests/vault/initialize_vault.rs index 0b964fc2..c366f3d4 100644 --- a/integration_tests/tests/vault/initialize_vault.rs +++ b/integration_tests/tests/vault/initialize_vault.rs @@ -1,58 +1,22 @@ -use jito_vault_core::{config::Config, vault::Vault, vault_delegation_list::VaultDelegationList}; -use solana_sdk::signature::{Keypair, Signer}; +use solana_sdk::signature::Signer; -use crate::fixtures::fixture::TestBuilder; +use crate::fixtures::{fixture::TestBuilder, vault_client::VaultRoot}; #[tokio::test] async fn test_initialize_vault_ok() { - let mut fixture = TestBuilder::new().await; - let mut vault_program_client = fixture.vault_program_client(); - - let backing_token_mint = Keypair::new(); - fixture - .create_token_mint(&backing_token_mint) - .await - .unwrap(); - - let config_pubkey = Config::find_program_address(&jito_vault_program::id()).0; - let config_admin = Keypair::new(); - - fixture.transfer(&config_admin.pubkey(), 1.0).await.unwrap(); + let fixture = TestBuilder::new().await; - vault_program_client - .initialize_config(&config_pubkey, &config_admin) - .await - .unwrap(); - - let vault_base = Keypair::new(); - let vault_pubkey = - Vault::find_program_address(&jito_vault_program::id(), &vault_base.pubkey()).0; - let vault_delegation_list = - VaultDelegationList::find_program_address(&jito_vault_program::id(), &vault_pubkey).0; - let lrt_mint = Keypair::new(); - let vault_admin = Keypair::new(); - - fixture.transfer(&vault_admin.pubkey(), 1.0).await.unwrap(); + let mut vault_program_client = fixture.vault_program_client(); - vault_program_client - .initialize_vault( - &config_pubkey, - &vault_pubkey, - &vault_delegation_list, - &lrt_mint, - &backing_token_mint, - &vault_admin, - &vault_base, - 99, - 100, - ) - .await - .unwrap(); + let ( + _config_admin, + VaultRoot { + vault_pubkey, + vault_admin, + }, + ) = vault_program_client.setup_vault(99, 100).await.unwrap(); let vault = vault_program_client.get_vault(&vault_pubkey).await.unwrap(); - assert_eq!(vault.base(), vault_base.pubkey()); - assert_eq!(vault.lrt_mint(), lrt_mint.pubkey()); - assert_eq!(vault.supported_mint(), backing_token_mint.pubkey()); assert_eq!(vault.admin(), vault_admin.pubkey()); assert_eq!(vault.delegation_admin(), vault_admin.pubkey()); assert_eq!(vault.operator_admin(), vault_admin.pubkey()); diff --git a/integration_tests/tests/vault/mod.rs b/integration_tests/tests/vault/mod.rs index 59d08b5b..93af001b 100644 --- a/integration_tests/tests/vault/mod.rs +++ b/integration_tests/tests/vault/mod.rs @@ -1,6 +1,7 @@ mod add_avs; mod add_operator; mod add_slasher; +mod enqueue_withdrawal; mod initialize_config; mod initialize_vault; mod mint_to; diff --git a/vault_core/src/vault.rs b/vault_core/src/vault.rs index ca0a8ba8..b8ede6a4 100644 --- a/vault_core/src/vault.rs +++ b/vault_core/src/vault.rs @@ -75,7 +75,7 @@ impl Vault { lrt_mint: Pubkey, supported_mint: Pubkey, admin: Pubkey, - lrt_index: u64, + vault_index: u64, base: Pubkey, deposit_fee_bps: u16, withdrawal_fee_bps: u16, @@ -94,7 +94,7 @@ impl Vault { fee_owner: admin, mint_burn_authority: Pubkey::default(), capacity: u64::MAX, - vault_index: lrt_index, + vault_index, lrt_supply: 0, tokens_deposited: 0, deposit_fee_bps, diff --git a/vault_program/src/add_avs.rs b/vault_program/src/add_avs.rs index c657fd6b..93efc8a7 100644 --- a/vault_program/src/add_avs.rs +++ b/vault_program/src/add_avs.rs @@ -129,13 +129,16 @@ impl<'a, 'info> SanitizedAccounts<'a, 'info> { let config = SanitizedConfig::sanitize(program_id, next_account_info(&mut accounts_iter)?, false)?; + msg!("a"); let vault = SanitizedVault::sanitize(program_id, next_account_info(&mut accounts_iter)?, true)?; + msg!("b"); let avs = SanitizedAvs::sanitize( &config.config().restaking_program(), next_account_info(&mut accounts_iter)?, false, )?; + msg!("c"); let avs_vault_ticket = SanitizedAvsVaultTicket::sanitize( &config.config().restaking_program(), next_account_info(&mut accounts_iter)?, @@ -143,13 +146,18 @@ impl<'a, 'info> SanitizedAccounts<'a, 'info> { avs.account().key, vault.account().key, )?; + msg!("d"); let vault_avs_ticket = EmptyAccount::sanitize(next_account_info(&mut accounts_iter)?, true)?; + msg!("e"); let admin = SanitizedSignerAccount::sanitize(next_account_info(&mut accounts_iter)?, false)?; + msg!("f"); let payer = SanitizedSignerAccount::sanitize(next_account_info(&mut accounts_iter)?, true)?; + msg!("g"); let system_program = SanitizedSystemProgram::sanitize(next_account_info(&mut accounts_iter)?)?; + msg!("h"); Ok(SanitizedAccounts { vault, diff --git a/vault_program/src/enqueue_withdrawal.rs b/vault_program/src/enqueue_withdraw.rs similarity index 97% rename from vault_program/src/enqueue_withdrawal.rs rename to vault_program/src/enqueue_withdraw.rs index 85e03c18..71f60650 100644 --- a/vault_program/src/enqueue_withdrawal.rs +++ b/vault_program/src/enqueue_withdraw.rs @@ -33,7 +33,7 @@ use spl_token::instruction::transfer; /// ratio increases due to rewards. However, if the vault has excess collateral that isn't staked, the vault /// can withdraw that excess and return it to the staker. If there's no excess, they can withdraw the /// amount that was set aside for withdraw. -pub fn process_enqueue_withdrawal( +pub fn process_enqueue_withdraw( program_id: &Pubkey, accounts: &[AccountInfo], amount: u64, @@ -210,29 +210,39 @@ impl<'a, 'info> SanitizedAccounts<'a, 'info> { let config = SanitizedConfig::sanitize(program_id, next_account_info(accounts_iter)?, false)?; + msg!("a"); let vault = SanitizedVault::sanitize(program_id, next_account_info(accounts_iter)?, true)?; + msg!("b"); let vault_delegation_list = SanitizedVaultDelegationList::sanitize( program_id, next_account_info(accounts_iter)?, true, vault.account().key, )?; + msg!("c"); let vault_staker_withdraw_ticket = EmptyAccount::sanitize(next_account_info(accounts_iter)?, true)?; + msg!("d"); let vault_staker_withdraw_ticket_token_account = SanitizedAssociatedTokenAccount::sanitize( next_account_info(accounts_iter)?, &vault.vault().lrt_mint(), vault_staker_withdraw_ticket.account().key, )?; + msg!("e"); let staker = SanitizedSignerAccount::sanitize(next_account_info(accounts_iter)?, true)?; + msg!("f"); let staker_lrt_token_account = SanitizedTokenAccount::sanitize( next_account_info(accounts_iter)?, &vault.vault().lrt_mint(), staker.account().key, )?; + msg!("g"); let base = SanitizedSignerAccount::sanitize(next_account_info(accounts_iter)?, false)?; + msg!("h"); let token_program = SanitizedTokenProgram::sanitize(next_account_info(accounts_iter)?)?; + msg!("i"); let system_program = SanitizedSystemProgram::sanitize(next_account_info(accounts_iter)?)?; + msg!("j"); Ok(SanitizedAccounts { config, diff --git a/vault_program/src/lib.rs b/vault_program/src/lib.rs index 10830486..3605faa2 100644 --- a/vault_program/src/lib.rs +++ b/vault_program/src/lib.rs @@ -5,7 +5,7 @@ mod add_slasher; mod burn; mod burn_withdraw_ticket; mod create_token_metadata; -mod enqueue_withdrawal; +mod enqueue_withdraw; mod initialize_config; mod initialize_vault; mod initialize_vault_avs_slasher_operator_ticket; @@ -36,7 +36,7 @@ use crate::{ add_operator::process_vault_add_operator, add_slasher::process_add_slasher, burn::process_burn, burn_withdraw_ticket::process_burn_withdraw_ticket, create_token_metadata::process_create_token_metadata, - enqueue_withdrawal::process_enqueue_withdrawal, initialize_config::process_initialize_config, + enqueue_withdraw::process_enqueue_withdraw, initialize_config::process_initialize_config, initialize_vault::process_initialize_vault, initialize_vault_avs_slasher_operator_ticket::process_initialize_vault_avs_slasher_operator_ticket, initialize_vault_with_mint::process_initialize_vault_with_mint, mint_to::process_mint, @@ -125,8 +125,8 @@ pub fn process_instruction( process_burn(program_id, accounts, amount) } VaultInstruction::EnqueueWithdraw { amount } => { - msg!("Instruction: EnqueueWithdrawal"); - process_enqueue_withdrawal(program_id, accounts, amount) + msg!("Instruction: EnqueueWithdraw"); + process_enqueue_withdraw(program_id, accounts, amount) } VaultInstruction::BurnWithdrawTicket => { msg!("Instruction: BurnWithdrawTicket"); diff --git a/vault_sdk/src/lib.rs b/vault_sdk/src/lib.rs index f04e4583..db64a8dd 100644 --- a/vault_sdk/src/lib.rs +++ b/vault_sdk/src/lib.rs @@ -441,16 +441,6 @@ pub fn burn(program_id: &Pubkey, amount: u64) -> Instruction { } } -pub fn enqueue_withdrawal(program_id: &Pubkey, amount: u64) -> Instruction { - Instruction { - program_id: *program_id, - accounts: vec![], - data: VaultInstruction::EnqueueWithdraw { amount } - .try_to_vec() - .unwrap(), - } -} - pub fn set_deposit_capacity( program_id: &Pubkey, vault: &Pubkey, @@ -736,3 +726,37 @@ pub fn slash( data: VaultInstruction::Slash { amount }.try_to_vec().unwrap(), } } + +#[allow(clippy::too_many_arguments)] +pub fn enqueue_withdraw( + program_id: &Pubkey, + config: &Pubkey, + vault: &Pubkey, + vault_delegation_list: &Pubkey, + vault_staker_withdraw_ticket: &Pubkey, + vault_staker_withdraw_ticket_token_account: &Pubkey, + staker: &Pubkey, + staker_lrt_token_account: &Pubkey, + base: &Pubkey, + amount: u64, +) -> Instruction { + let accounts = vec![ + AccountMeta::new_readonly(*config, false), + AccountMeta::new(*vault, false), + AccountMeta::new(*vault_delegation_list, false), + AccountMeta::new(*vault_staker_withdraw_ticket, false), + AccountMeta::new(*vault_staker_withdraw_ticket_token_account, false), + AccountMeta::new(*staker, true), + AccountMeta::new(*staker_lrt_token_account, false), + AccountMeta::new_readonly(*base, true), + AccountMeta::new_readonly(spl_token::id(), false), + AccountMeta::new_readonly(system_program::id(), false), + ]; + Instruction { + program_id: *program_id, + accounts, + data: VaultInstruction::EnqueueWithdraw { amount } + .try_to_vec() + .unwrap(), + } +}