From da6b50c202529c20969abcd0d0e3280af1246a4f Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Fri, 19 Jan 2024 15:53:13 -0500 Subject: [PATCH 01/16] sdk: account for settle lp in accoutnt breakdown --- sdk/src/user.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sdk/src/user.ts b/sdk/src/user.ts index 4516ad489..576cd17cb 100644 --- a/sdk/src/user.ts +++ b/sdk/src/user.ts @@ -3293,6 +3293,10 @@ export class User { }; for (const perpPosition of this.getActivePerpPositions()) { + const settledLpPosition = this.getPerpPositionWithLPSettle( + perpPosition.marketIndex, + perpPosition + )[0]; const perpMarket = this.driftClient.getPerpMarketAccount( perpPosition.marketIndex ); @@ -3301,7 +3305,7 @@ export class User { ).data; const oraclePrice = oraclePriceData.price; const worstCaseBaseAmount = - calculateWorstCaseBaseAssetAmount(perpPosition); + calculateWorstCaseBaseAssetAmount(settledLpPosition); const marginRatio = new BN( calculateMarketMarginRatio( From 4f8d1e28d0d358ebd2841c0f93f7078683899fab Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 21 Jan 2024 16:11:34 -0500 Subject: [PATCH 02/16] init --- Cargo.lock | 922 ++++++++++++++---- deploy-scripts/verified-build.sh | 2 + package.json | 2 +- programs/drift/Cargo.toml | 8 +- programs/drift/src/instructions/keeper.rs | 86 +- .../src/instructions/optional_accounts.rs | 22 +- programs/drift/src/instructions/user.rs | 100 +- programs/drift/src/lib.rs | 187 ++-- programs/drift/src/math/orders.rs | 10 +- .../src/state/fulfillment_params/drift.rs | 2 +- .../src/state/fulfillment_params/phoenix.rs | 2 +- .../src/state/fulfillment_params/serum.rs | 2 +- programs/drift/src/state/perp_market_map.rs | 19 +- programs/drift/src/state/spot_market_map.rs | 6 +- programs/drift/src/state/user.rs | 2 +- programs/drift/src/state/user_map.rs | 6 +- programs/pyth/Cargo.toml | 2 +- programs/token_faucet/Cargo.toml | 6 +- sdk/package.json | 2 +- sdk/src/adminClient.ts | 18 +- sdk/src/idl/drift.json | 6 +- yarn.lock | 19 +- 22 files changed, 1027 insertions(+), 404 deletions(-) create mode 100644 deploy-scripts/verified-build.sh diff --git a/Cargo.lock b/Cargo.lock index 2994e4870..530806641 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" dependencies = [ "cfg-if", - "cipher 0.3.0", + "cipher", "cpufeatures", "opaque-debug", ] @@ -31,7 +31,7 @@ checksum = "589c637f0e68c877bbd59a4599bbe849cac8e5f3e4b5a3ebae8f528cd218dcdc" dependencies = [ "aead", "aes", - "cipher 0.3.0", + "cipher", "ctr", "polyval", "subtle", @@ -49,6 +49,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72832d73be48bac96a5d7944568f305d829ed55b0ce3b483647089dfaf6cf704" +dependencies = [ + "cfg-if", + "getrandom 0.2.9", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "aho-corasick" version = "0.7.18" @@ -66,64 +79,58 @@ checksum = "6b2d54853319fd101b8dd81de382bcbf3e03410a64d8928bbee85a3e7dcde483" [[package]] name = "anchor-attribute-access-control" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5e1a413b311b039d29b61d0dbb401c9dbf04f792497ceca87593454bf6d7dd" +checksum = "e5f619f1d04f53621925ba8a2e633ba5a6081f2ae14758cbb67f38fd823e0a3e" dependencies = [ "anchor-syn", - "anyhow", "proc-macro2", "quote", - "regex", "syn 1.0.92", ] [[package]] name = "anchor-attribute-account" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cca9aeaf633c6e2365fed0525dcac68610be58eee5dc69d3b86fe0b1d4b320b9" +checksum = "e7f2a3e1df4685f18d12a943a9f2a7456305401af21a07c9fe076ef9ecd6e400" dependencies = [ "anchor-syn", - "anyhow", - "bs58 0.4.0", + "bs58 0.5.0", "proc-macro2", "quote", - "rustversion", "syn 1.0.92", ] [[package]] name = "anchor-attribute-constant" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "788e44f9e8501dabeb6f9229da0f3268fb2ae3208912608ffaa056a72031296f" +checksum = "9423945cb55627f0b30903288e78baf6f62c6c8ab28fb344b6b25f1ffee3dca7" dependencies = [ "anchor-syn", - "proc-macro2", + "quote", "syn 1.0.92", ] [[package]] name = "anchor-attribute-error" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c4d8c7e4a2605ede6fcdced9690288b2f74e24768619a85229d57e597bc97" +checksum = "93ed12720033cc3c3bf3cfa293349c2275cd5ab99936e33dd4bf283aaad3e241" dependencies = [ "anchor-syn", - "proc-macro2", "quote", "syn 1.0.92", ] [[package]] name = "anchor-attribute-event" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a3b07d5c5d87b5edc72428b447b8e9ee1143b83dd1afc6a6b1d352c6a6164d8" +checksum = "eef4dc0371eba2d8c8b54794b0b0eb786a234a559b77593d6f80825b6d2c77a2" dependencies = [ "anchor-syn", - "anyhow", "proc-macro2", "quote", "syn 1.0.92", @@ -131,25 +138,34 @@ dependencies = [ [[package]] name = "anchor-attribute-program" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b22ad0445115dbea5869b1d062da49ae125abed9132fc20c33227f25e42dfa6b" +checksum = "b18c4f191331e078d4a6a080954d1576241c29c56638783322a18d308ab27e4f" dependencies = [ "anchor-syn", - "anyhow", - "proc-macro2", "quote", "syn 1.0.92", ] [[package]] name = "anchor-derive-accounts" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48daeff6781ba2f02961b0ad211feb9a2de75af345d42c62b1a252fd4dfb0724" +checksum = "5de10d6e9620d3bcea56c56151cad83c5992f50d5960b3a9bebc4a50390ddc3c" dependencies = [ "anchor-syn", - "anyhow", + "quote", + "syn 1.0.92", +] + +[[package]] +name = "anchor-derive-serde" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" +dependencies = [ + "anchor-syn", + "borsh-derive-internal 0.9.3", "proc-macro2", "quote", "syn 1.0.92", @@ -157,9 +173,9 @@ dependencies = [ [[package]] name = "anchor-derive-space" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4fe2886f92c4f33ec1b2b8b2b43ca1b9070cf4929e63c7eaaa09a9f2c0d5123" +checksum = "1ecc31d19fa54840e74b7a979d44bcea49d70459de846088a1d71e87ba53c419" dependencies = [ "proc-macro2", "quote", @@ -168,9 +184,9 @@ dependencies = [ [[package]] name = "anchor-lang" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbbe5d1c7c057c6d63b4f2f538a320e4a22111126c9966340c3d9490e2f15ed1" +checksum = "35da4785497388af0553586d55ebdc08054a8b1724720ef2749d313494f2b8ad" dependencies = [ "anchor-attribute-access-control", "anchor-attribute-account", @@ -179,43 +195,45 @@ dependencies = [ "anchor-attribute-event", "anchor-attribute-program", "anchor-derive-accounts", + "anchor-derive-serde", "anchor-derive-space", "arrayref", "base64 0.13.0", "bincode", - "borsh", + "borsh 0.9.3", "bytemuck", + "getrandom 0.2.9", "solana-program", "thiserror", ] [[package]] name = "anchor-spl" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75cc8066fbd45e0e03edf48342c79265aa34ca76cefeace48ef6c402b6946665" +checksum = "6c4fd6e43b2ca6220d2ef1641539e678bfc31b6cc393cf892b373b5997b6a39a" dependencies = [ "anchor-lang", "solana-program", "spl-associated-token-account", - "spl-token", + "spl-token 4.0.0", "spl-token-2022", ] [[package]] name = "anchor-syn" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cb31fe143aedb36fc41409ea072aa0b840cbea727e62eb2ff6e7b6cea036ff" +checksum = "d9101b84702fed2ea57bd22992f75065da5648017135b844283a2f6d74f27825" dependencies = [ "anyhow", - "bs58 0.3.1", + "bs58 0.5.0", "heck", "proc-macro2", "quote", "serde", "serde_json", - "sha2 0.9.9", + "sha2 0.10.7", "syn 1.0.92", "thiserror", ] @@ -226,17 +244,140 @@ 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", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "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", +] + +[[package]] +name = "array-bytes" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ad284aeb45c13f2fb4f084de4a420ebf447423bdf9386c0540ce33cb3ef4b8c" + [[package]] name = "arrayref" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" -version = "0.7.2" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" [[package]] name = "assert_matches" @@ -273,6 +414,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "bincode" version = "1.3.3" @@ -299,9 +446,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.3.1" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" +checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" dependencies = [ "arrayref", "arrayvec", @@ -323,9 +470,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] @@ -342,18 +489,41 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" dependencies = [ - "borsh-derive", + "borsh-derive 0.9.3", "hashbrown 0.11.2", ] +[[package]] +name = "borsh" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" +dependencies = [ + "borsh-derive 0.10.3", + "hashbrown 0.12.3", +] + [[package]] name = "borsh-derive" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ - "borsh-derive-internal", - "borsh-schema-derive-internal", + "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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0754613691538d51f329cce9af41d7b7ca150bc973056f1156611489475f54f7" +dependencies = [ + "borsh-derive-internal 0.10.3", + "borsh-schema-derive-internal 0.10.3", "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.92", @@ -370,6 +540,17 @@ dependencies = [ "syn 1.0.92", ] +[[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" @@ -382,10 +563,15 @@ dependencies = [ ] [[package]] -name = "bs58" -version = "0.3.1" +name = "borsh-schema-derive-internal" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "476e9cd489f9e121e02ffa6014a8ef220ecb15c05ed23fc34cca13925dc283fb" +checksum = "634205cc43f74a1b9046ef87c4540ebda95696ec0f315024860cad7c5b0f5ccd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.92", +] [[package]] name = "bs58" @@ -393,6 +579,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +[[package]] +name = "bs58" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" +dependencies = [ + "tinyvec", +] + [[package]] name = "bumpalo" version = "3.9.1" @@ -411,9 +606,9 @@ dependencies = [ [[package]] name = "bytemuck" -version = "1.13.0" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c041d3eab048880cb0b86b256447da3f18859a163c3b8d8893f4e6368abe6393" +checksum = "374d28ec25809ee0e23827c2ab573d729e293f281dfe393500e7ad618baa61c6" dependencies = [ "bytemuck_derive", ] @@ -426,7 +621,7 @@ checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.48", ] [[package]] @@ -475,16 +670,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "cipher" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1873270f8f7942c191139cb8a40fd228da6c3fd2fc376d7e92d47aa14aeb59e" -dependencies = [ - "crypto-common", - "inout", -] - [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -497,9 +682,9 @@ dependencies = [ [[package]] name = "console_log" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501a375961cef1a0d44767200e66e4a559283097e91d0730b1d75dfb2f8a1494" +checksum = "e89f72f65e8501878b8a004d5a1afb780987e2ce2b4532c562e367a72c57499f" dependencies = [ "log", "web-sys", @@ -507,9 +692,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.1.5" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" [[package]] name = "cpufeatures" @@ -550,7 +735,7 @@ dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", + "memoffset 0.6.5", "once_cell", "scopeguard", ] @@ -597,7 +782,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" dependencies = [ - "cipher 0.3.0", + "cipher", ] [[package]] @@ -614,12 +799,58 @@ dependencies = [ "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 = "digest" version = "0.9.0" @@ -635,7 +866,7 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.2", + "block-buffer 0.10.4", "crypto-common", "subtle", ] @@ -648,12 +879,12 @@ dependencies = [ "anchor-spl", "arrayref", "base64 0.13.0", - "borsh", + "borsh 0.9.3", "bytemuck", "bytes", "drift-macros", "enumflags2", - "num-derive", + "num-derive 0.3.3", "num-integer", "num-traits", "phoenix-v1", @@ -693,7 +924,7 @@ checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ "curve25519-dalek", "ed25519", - "rand", + "rand 0.7.3", "serde", "sha2 0.9.9", "zeroize", @@ -776,7 +1007,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e1c54951450cbd39f3dbcf1005ac413b49487dabf18a720ad2383eccfeffb92" dependencies = [ - "memoffset", + "memoffset 0.6.5", "rustc_version 0.3.3", ] @@ -788,9 +1019,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "serde", "typenum", @@ -829,7 +1060,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" dependencies = [ - "ahash", + "ahash 0.7.6", ] [[package]] @@ -838,7 +1069,16 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.6", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.4", ] [[package]] @@ -901,6 +1141,12 @@ 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 = "im" version = "15.1.0" @@ -917,15 +1163,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "inout" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" -dependencies = [ - "generic-array", -] - [[package]] name = "itertools" version = "0.9.0" @@ -961,9 +1198,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -987,16 +1224,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6295db13f26aaa8bb4fb38e0c9ff50253814aa490eef7b4d6aa106ba6fc843" dependencies = [ "bytemuck", - "num-derive", + "num-derive 0.3.3", "num-traits", "thiserror", ] [[package]] name = "libc" -version = "0.2.141" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libsecp256k1" @@ -1011,7 +1248,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand", + "rand 0.7.3", "serde", "sha2 0.9.9", "typenum", @@ -1072,9 +1309,9 @@ checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" [[package]] name = "memmap2" -version = "0.5.3" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057a3db23999c867821a7a59feb06a578fcb03685e983dff90daf9e7d24ac08f" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" dependencies = [ "libc", ] @@ -1088,6 +1325,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "merlin" version = "3.0.0" @@ -1100,6 +1346,17 @@ dependencies = [ "zeroize", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + [[package]] name = "num-derive" version = "0.3.3" @@ -1111,6 +1368,17 @@ dependencies = [ "syn 1.0.92", ] +[[package]] +name = "num-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -1146,7 +1414,25 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d829733185c1ca374f17e52b762f24f535ec625d2cc1f070e34c8a9068f341b" dependencies = [ - "num_enum_derive", + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" +dependencies = [ + "num_enum_derive 0.6.1", +] + +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive 0.7.2", ] [[package]] @@ -1161,6 +1447,30 @@ dependencies = [ "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.15.0" @@ -1196,6 +1506,12 @@ dependencies = [ "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" @@ -1232,19 +1548,19 @@ dependencies = [ [[package]] name = "phoenix-v1" version = "0.2.4" -source = "git+https://github.com/drift-labs/phoenix-v1?rev=4c65c9#4c65c97cd62493e27425ea2830447c833152bed1" +source = "git+https://github.com/drift-labs/phoenix-v1?rev=d60b17#d60b17d12c8dd93f3764b89a6c0b37750c63e293" dependencies = [ - "borsh", + "borsh 0.9.3", "bytemuck", "ellipsis-macros", "itertools 0.10.5", "lib-sokoban", - "num_enum", + "num_enum 0.5.9", "shank", "solana-program", "solana-security-txt", "spl-associated-token-account", - "spl-token", + "spl-token 3.5.0", "static_assertions", "thiserror", ] @@ -1289,9 +1605,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -1322,9 +1638,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.26" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -1337,11 +1653,21 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha", + "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand_chacha" version = "0.2.2" @@ -1352,6 +1678,16 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + [[package]] name = "rand_core" version = "0.5.1" @@ -1512,44 +1848,66 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.159" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.5" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.48", ] [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.111" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "176e46fa42316f18edd598015a5166857fc835ec732f5215eac6b7bdbf0a84f4" dependencies = [ "itoa", "ryu", "serde", ] +[[package]] +name = "serde_with" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +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" @@ -1563,11 +1921,11 @@ dependencies = [ "field-offset", "itertools 0.9.0", "num-traits", - "num_enum", + "num_enum 0.5.9", "safe-transmute", "serde", "solana-program", - "spl-token", + "spl-token 3.5.0", "static_assertions", "thiserror", "without-alloc", @@ -1689,13 +2047,13 @@ checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "solana-frozen-abi" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23b4953578272ac0fadec245e85e83ae86454611f0c0a7fff7d906835124bdcf" +checksum = "67a96a0a64cbc75e06c8eb49d6cd0a87054c48dbf59100d9959389aba51fb501" dependencies = [ - "ahash", + "ahash 0.8.4", "blake3", - "block-buffer 0.9.0", + "block-buffer 0.10.4", "bs58 0.4.0", "bv", "byteorder", @@ -1703,7 +2061,6 @@ dependencies = [ "either", "generic-array", "getrandom 0.1.16", - "hashbrown 0.12.3", "im", "lazy_static", "log", @@ -1723,21 +2080,21 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57892538250428ad3dc3cbe05f6cd75ad14f4f16734fcb91bc7cd5fbb63d6315" +checksum = "5ae9765c963bebbf609dcdc82cfb969746cbdf6d65cfc9d94112e984475ae4ac" dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 1.0.92", + "syn 2.0.48", ] [[package]] name = "solana-logger" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06aa701c49493e93085dd1e800c05475baca15a9d4d527b59794f2ed0b66e055" +checksum = "9c039e4336890c7a0667207caeb452187efa0602d80eca61a854f2e39915e972" dependencies = [ "env_logger", "lazy_static", @@ -1746,16 +2103,21 @@ dependencies = [ [[package]] name = "solana-program" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f99052873619df68913cb8e92e28ff251a5483828925e87fa97ba15a9cbad51" +checksum = "20c16757f43d4384907f6e81924e155b8bd8228efcdcf9ea38bd4e18ea100804" dependencies = [ - "base64 0.13.0", + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-serialize", + "array-bytes", + "base64 0.21.7", "bincode", "bitflags", "blake3", - "borsh", - "borsh-derive", + "borsh 0.10.3", + "borsh 0.9.3", "bs58 0.4.0", "bv", "bytemuck", @@ -1770,12 +2132,13 @@ dependencies = [ "libc", "libsecp256k1", "log", - "memoffset", - "num-derive", + "memoffset 0.9.0", + "num-bigint", + "num-derive 0.3.3", "num-traits", "parking_lot", - "rand", - "rand_chacha", + "rand 0.7.3", + "rand_chacha 0.2.2", "rustc_version 0.4.0", "rustversion", "serde", @@ -1795,15 +2158,15 @@ dependencies = [ [[package]] name = "solana-sdk" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edb47da3e18cb669f6ace0b40cee0610e278903783e0c9f7fce1e1beb881a1b7" +checksum = "cdf179cda65775982e5f31da8d58dfa4349c3b5ae1573ceb507c7fc91df66690" dependencies = [ "assert_matches", - "base64 0.13.0", + "base64 0.21.7", "bincode", "bitflags", - "borsh", + "borsh 0.10.3", "bs58 0.4.0", "bytemuck", "byteorder", @@ -1820,18 +2183,20 @@ dependencies = [ "libsecp256k1", "log", "memmap2", - "num-derive", + "num-derive 0.3.3", "num-traits", + "num_enum 0.6.1", "pbkdf2 0.11.0", "qstring", - "rand", - "rand_chacha", + "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.7", "sha3 0.10.4", "solana-frozen-abi", @@ -1846,15 +2211,15 @@ dependencies = [ [[package]] name = "solana-sdk-macro" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d41a09b9cecd0a4df63c78a192adee99ebf2d3757c19713a68246e1d9789c7c" +checksum = "7f188d6fe76183137a4922274acbe76fc4fcc474b3fad860bb2612cb225e6e2a" dependencies = [ "bs58 0.4.0", "proc-macro2", "quote", "rustversion", - "syn 1.0.92", + "syn 2.0.48", ] [[package]] @@ -1865,25 +2230,23 @@ checksum = "7e0461f3afb29d8591300b3dd09b5472b3772d65688a2826ad960b8c0d5fa605" [[package]] name = "solana-zk-token-sdk" -version = "1.14.16" +version = "1.16.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab38abd096769f79fd8e3fe8465070f04742395db724606a5263c8ebc215567" +checksum = "9513c4f1595b61f8a39a14c27535da2b2145c20c6b35ab491a1830981972b2bd" dependencies = [ "aes-gcm-siv", - "arrayref", - "base64 0.13.0", + "base64 0.21.7", "bincode", "bytemuck", "byteorder", - "cipher 0.4.3", "curve25519-dalek", "getrandom 0.1.16", "itertools 0.10.5", "lazy_static", "merlin", - "num-derive", + "num-derive 0.3.3", "num-traits", - "rand", + "rand 0.7.3", "serde", "serde_json", "sha3 0.9.1", @@ -1896,27 +2259,114 @@ dependencies = [ [[package]] name = "spl-associated-token-account" -version = "1.1.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbc000f0fdf1f12f99d77d398137c1751345b18c88258ce0f99b7872cf6c9bd6" +checksum = "385e31c29981488f2820b2022d8e731aae3b02e6e18e2fd854e4c9a94dc44fc3" dependencies = [ "assert_matches", - "borsh", - "num-derive", + "borsh 0.10.3", + "num-derive 0.4.1", "num-traits", "solana-program", - "spl-token", + "spl-token 4.0.0", "spl-token-2022", "thiserror", ] +[[package]] +name = "spl-discriminator" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator-derive", +] + +[[package]] +name = "spl-discriminator-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadbefec4f3c678215ca72bd71862697bb06b41fd77c0088902dd3203354387b" +dependencies = [ + "quote", + "spl-discriminator-syn", + "syn 2.0.48", +] + +[[package]] +name = "spl-discriminator-syn" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e5f2044ca42c8938d54d1255ce599c79a1ffd86b677dfab695caa20f9ffc3f2" +dependencies = [ + "proc-macro2", + "quote", + "sha2 0.10.7", + "syn 2.0.48", + "thiserror", +] + [[package]] name = "spl-memo" -version = "3.0.1" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f180b03318c3dbab3ef4e1e4d46d5211ae3c780940dd0a28695aba4b59a75a" +dependencies = [ + "solana-program", +] + +[[package]] +name = "spl-pod" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2881dddfca792737c0706fa0175345ab282b1b0879c7d877bad129645737c079" +dependencies = [ + "borsh 0.10.3", + "bytemuck", + "solana-program", + "solana-zk-token-sdk", + "spl-program-error", +] + +[[package]] +name = "spl-program-error" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0dc6f70db6bacea7ff25870b016a65ba1d1b6013536f08e4fd79a8f9005325" +checksum = "249e0318493b6bcf27ae9902600566c689b7dfba9f1bdff5893e92253374e78c" dependencies = [ + "num-derive 0.4.1", + "num-traits", "solana-program", + "spl-program-error-derive", + "thiserror", +] + +[[package]] +name = "spl-program-error-derive" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5269c8e868da17b6552ef35a51355a017bd8e0eae269c201fef830d35fa52c" +dependencies = [ + "proc-macro2", + "quote", + "sha2 0.10.7", + "syn 2.0.48", +] + +[[package]] +name = "spl-tlv-account-resolution" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "062e148d3eab7b165582757453632ffeef490c02c86a48bfdb4988f63eefb3b9" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-type-length-value", ] [[package]] @@ -1927,37 +2377,105 @@ checksum = "8e85e168a785e82564160dcb87b2a8e04cee9bfd1f4d488c729d53d6a4bd300d" dependencies = [ "arrayref", "bytemuck", - "num-derive", + "num-derive 0.3.3", "num-traits", - "num_enum", + "num_enum 0.5.9", + "solana-program", + "thiserror", +] + +[[package]] +name = "spl-token" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08459ba1b8f7c1020b4582c4edf0f5c7511a5e099a7a97570c9698d4f2337060" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive 0.3.3", + "num-traits", + "num_enum 0.6.1", "solana-program", "thiserror", ] [[package]] name = "spl-token-2022" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0edb869dbe159b018f17fb9bfa67118c30f232d7f54a73742bc96794dff77ed8" +checksum = "e4abf34a65ba420584a0c35f3903f8d727d1f13ababbdc3f714c6b065a686e86" dependencies = [ "arrayref", "bytemuck", - "num-derive", + "num-derive 0.4.1", "num-traits", - "num_enum", + "num_enum 0.7.2", "solana-program", "solana-zk-token-sdk", "spl-memo", - "spl-token", + "spl-pod", + "spl-token 4.0.0", + "spl-token-metadata-interface", + "spl-transfer-hook-interface", + "spl-type-length-value", "thiserror", ] +[[package]] +name = "spl-token-metadata-interface" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" +dependencies = [ + "borsh 0.10.3", + "solana-program", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-type-length-value", +] + +[[package]] +name = "spl-transfer-hook-interface" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "051d31803f873cabe71aec3c1b849f35248beae5d19a347d93a5c9cccc5d5a9b" +dependencies = [ + "arrayref", + "bytemuck", + "solana-program", + "spl-discriminator", + "spl-pod", + "spl-program-error", + "spl-tlv-account-resolution", + "spl-type-length-value", +] + +[[package]] +name = "spl-type-length-value" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" +dependencies = [ + "bytemuck", + "solana-program", + "spl-discriminator", + "spl-pod", + "spl-program-error", +] + [[package]] name = "static_assertions" 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" @@ -1977,9 +2495,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.13" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -1997,22 +2515,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 2.0.48", ] [[package]] @@ -2025,7 +2543,7 @@ dependencies = [ "hmac 0.8.1", "once_cell", "pbkdf2 0.4.0", - "rand", + "rand 0.7.3", "rustc-hash", "sha2 0.9.9", "thiserror", @@ -2141,9 +2659,9 @@ dependencies = [ [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" @@ -2159,9 +2677,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2169,24 +2687,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.92", + "syn 2.0.48", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2194,22 +2712,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", - "syn 1.0.92", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "web-sys" @@ -2304,6 +2822,26 @@ dependencies = [ "alloc-traits", ] +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "zeroize" version = "1.3.0" @@ -2321,5 +2859,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn 2.0.48", ] diff --git a/deploy-scripts/verified-build.sh b/deploy-scripts/verified-build.sh new file mode 100644 index 000000000..65ddcb90d --- /dev/null +++ b/deploy-scripts/verified-build.sh @@ -0,0 +1,2 @@ +#!/bin/sh +solana-verify build --library-name drift \ No newline at end of file diff --git a/package.json b/package.json index b6fe41f6d..09975bcd3 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "", "license": "ISC", "devDependencies": { - "@coral-xyz/anchor": "0.28.1-beta.2", + "@coral-xyz/anchor": "0.29.0", "@project-serum/common": "0.0.1-beta.3", "@project-serum/serum": "^0.13.38", "@pythnetwork/client": "^2.5.1", diff --git a/programs/drift/Cargo.toml b/programs/drift/Cargo.toml index 5ea3c174c..dac58fd45 100644 --- a/programs/drift/Cargo.toml +++ b/programs/drift/Cargo.toml @@ -16,9 +16,9 @@ mainnet-beta=[] default=["mainnet-beta"] [dependencies] -anchor-lang = "0.27.0" -solana-program = "=1.14.16" -anchor-spl = "0.27.0" +anchor-lang = "0.29.0" +solana-program = "1.16" +anchor-spl = "0.29.0" pyth-client = "0.2.2" bytemuck = { version = "1.4.0" } borsh = "0.9.1" @@ -31,7 +31,7 @@ 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"] } enumflags2 = "0.6.4" -phoenix-v1 = { git = "https://github.com/drift-labs/phoenix-v1", rev = "4c65c9", version = "0.2.4", features = ["no-entrypoint"] } +phoenix-v1 = { git = "https://github.com/drift-labs/phoenix-v1", rev = "d60b17", version = "0.2.4", 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" } diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index 1c24b4cd1..4686c5f7d 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -38,7 +38,10 @@ use crate::{validate, QUOTE_PRECISION_I128}; #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_fill_perp_order<'info>(ctx: Context, order_id: Option) -> Result<()> { +pub fn handle_fill_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, + order_id: Option, +) -> Result<()> { let (order_id, market_index) = { let user = &load!(ctx.accounts.user)?; // if there is no order id, use the users last order id @@ -67,7 +70,11 @@ pub fn handle_fill_perp_order<'info>(ctx: Context, order_id: Option, order_id: u32, market_index: u16) -> Result<()> { +fn fill_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, + order_id: u32, + market_index: u16, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -149,7 +156,7 @@ impl Default for SpotFulfillmentType { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_fill_spot_order<'a, 'b, 'c, 'info>( +pub fn handle_fill_spot_order<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, order_id: Option, fulfillment_type: Option, @@ -183,8 +190,8 @@ pub fn handle_fill_spot_order<'a, 'b, 'c, 'info>( Ok(()) } -fn fill_spot_order<'info>( - ctx: Context<'_, '_, '_, 'info, FillOrder<'info>>, +fn fill_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, order_id: u32, market_index: u16, fulfillment_type: SpotFulfillmentType, @@ -275,7 +282,10 @@ fn fill_spot_order<'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_trigger_order<'info>(ctx: Context, order_id: u32) -> Result<()> { +pub fn handle_trigger_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, TriggerOrder<'info>>, + order_id: u32, +) -> Result<()> { let AccountMaps { perp_market_map, spot_market_map, @@ -325,7 +335,9 @@ pub fn handle_trigger_order<'info>(ctx: Context, order_id: u32) -> #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_force_cancel_orders<'info>(ctx: Context) -> Result<()> { +pub fn handle_force_cancel_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ForceCancelOrder>, +) -> Result<()> { let AccountMaps { perp_market_map, spot_market_map, @@ -354,7 +366,9 @@ pub fn handle_force_cancel_orders<'info>(ctx: Context) -> Resu #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_update_user_idle<'info>(ctx: Context) -> Result<()> { +pub fn handle_update_user_idle<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateUserIdle<'info>>, +) -> Result<()> { let mut user = load_mut!(ctx.accounts.user)?; let clock = Clock::get()?; @@ -413,7 +427,10 @@ pub fn handle_update_user_open_orders_count<'info>(ctx: Context) #[access_control( settle_pnl_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_pnl(ctx: Context, market_index: u16) -> Result<()> { +pub fn handle_settle_pnl<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettlePNL>, + market_index: u16, +) -> Result<()> { let clock = Clock::get()?; let state = &ctx.accounts.state; @@ -485,7 +502,9 @@ pub fn handle_settle_pnl(ctx: Context, market_index: u16) -> Result<( #[access_control( funding_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_funding_payment(ctx: Context) -> Result<()> { +pub fn handle_settle_funding_payment<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettleFunding>, +) -> Result<()> { let clock = Clock::get()?; let now = clock.unix_timestamp; @@ -510,7 +529,10 @@ pub fn handle_settle_funding_payment(ctx: Context) -> Result<()> #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_lp<'info>(ctx: Context, market_index: u16) -> Result<()> { +pub fn handle_settle_lp<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettleLP>, + market_index: u16, +) -> Result<()> { let user_key = ctx.accounts.user.key(); let user = &mut load_mut!(ctx.accounts.user)?; @@ -538,7 +560,10 @@ pub fn handle_settle_lp<'info>(ctx: Context, market_index: u16) -> Res #[access_control( settle_pnl_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_expired_market(ctx: Context, market_index: u16) -> Result<()> { +pub fn handle_settle_expired_market<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + market_index: u16, +) -> Result<()> { let clock = Clock::get()?; let _now = clock.unix_timestamp; let state = &ctx.accounts.state; @@ -578,8 +603,8 @@ pub fn handle_settle_expired_market(ctx: Context, market_index: u16) #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_perp( - ctx: Context, +pub fn handle_liquidate_perp<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidatePerp<'info>>, market_index: u16, liquidator_max_base_asset_amount: u64, limit_price: Option, @@ -638,8 +663,8 @@ pub fn handle_liquidate_perp( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_spot( - ctx: Context, +pub fn handle_liquidate_spot<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidateSpot<'info>>, asset_market_index: u16, liability_market_index: u16, liquidator_max_liability_transfer: u128, @@ -695,8 +720,8 @@ pub fn handle_liquidate_spot( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_borrow_for_perp_pnl( - ctx: Context, +pub fn handle_liquidate_borrow_for_perp_pnl<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_liability_transfer: u128, @@ -754,8 +779,8 @@ pub fn handle_liquidate_borrow_for_perp_pnl( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_perp_pnl_for_deposit( - ctx: Context, +pub fn handle_liquidate_perp_pnl_for_deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_pnl_transfer: u128, @@ -813,8 +838,8 @@ pub fn handle_liquidate_perp_pnl_for_deposit( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_perp_pnl_deficit( - ctx: Context, +pub fn handle_resolve_perp_pnl_deficit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolvePerpPnlDeficit<'info>>, spot_market_index: u16, perp_market_index: u16, ) -> Result<()> { @@ -936,8 +961,8 @@ pub fn handle_resolve_perp_pnl_deficit( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_perp_bankruptcy( - ctx: Context, +pub fn handle_resolve_perp_bankruptcy<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, quote_spot_market_index: u16, market_index: u16, ) -> Result<()> { @@ -1048,8 +1073,8 @@ pub fn handle_resolve_perp_bankruptcy( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_spot_bankruptcy( - ctx: Context, +pub fn handle_resolve_spot_bankruptcy<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, market_index: u16, ) -> Result<()> { let state = &ctx.accounts.state; @@ -1211,7 +1236,9 @@ pub fn handle_update_funding_rate( funding_not_paused(&ctx.accounts.state) valid_oracle_for_perp_market(&ctx.accounts.oracle, &ctx.accounts.perp_market) )] -pub fn handle_update_perp_bid_ask_twap(ctx: Context) -> Result<()> { +pub fn handle_update_perp_bid_ask_twap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdatePerpBidAskTwap<'info>>, +) -> Result<()> { let perp_market = &mut load_mut!(ctx.accounts.perp_market)?; let clock = Clock::get()?; let now = clock.unix_timestamp; @@ -1400,7 +1427,10 @@ pub fn handle_update_spot_market_cumulative_interest( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_update_amms(ctx: Context, market_indexes: [u16; 5]) -> Result<()> { +pub fn handle_update_amms<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + market_indexes: [u16; 5], +) -> Result<()> { // up to ~60k compute units (per amm) worst case let clock = Clock::get()?; diff --git a/programs/drift/src/instructions/optional_accounts.rs b/programs/drift/src/instructions/optional_accounts.rs index f84d0fef0..a615e5f24 100644 --- a/programs/drift/src/instructions/optional_accounts.rs +++ b/programs/drift/src/instructions/optional_accounts.rs @@ -25,8 +25,8 @@ pub struct AccountMaps<'a> { pub oracle_map: OracleMap<'a>, } -pub fn load_maps<'a, 'b>( - account_info_iter: &mut Peekable>>, +pub fn load_maps<'a, 'b, 'c: 'a>( + account_info_iter: &mut Peekable>>, writable_perp_markets: &'b MarketSet, writable_spot_markets: &'b MarketSet, slot: u64, @@ -43,8 +43,8 @@ pub fn load_maps<'a, 'b>( }) } -pub fn get_maker_and_maker_stats<'a>( - account_info_iter: &mut Peekable>>, +pub fn get_maker_and_maker_stats<'a, 'b>( + account_info_iter: &mut Peekable>>, ) -> DriftResult<(AccountLoader<'a, User>, AccountLoader<'a, UserStats>)> { let maker_account_info = next_account_info(account_info_iter).or(Err(ErrorCode::MakerNotFound))?; @@ -73,11 +73,11 @@ pub fn get_maker_and_maker_stats<'a>( } #[allow(clippy::type_complexity)] -pub fn get_referrer_and_referrer_stats<'a>( - account_info_iter: &mut Peekable>>, +pub fn get_referrer_and_referrer_stats<'a: 'b, 'b>( + account_info_iter: &mut Peekable>>, ) -> DriftResult<( - Option>, - Option>, + Option>, + Option>, )> { let referrer_account_info = account_info_iter.peek(); @@ -146,9 +146,9 @@ pub fn get_referrer_and_referrer_stats<'a>( Ok((Some(referrer), Some(referrer_stats))) } -pub fn get_whitelist_token<'a>( - account_info_iter: &mut Peekable>>, -) -> DriftResult> { +pub fn get_whitelist_token<'a: 'b, 'b>( + account_info_iter: &mut Peekable>>, +) -> DriftResult> { let token_account_info = account_info_iter.peek(); if token_account_info.is_none() { msg!("Could not find whitelist token"); diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index afcb8611f..79a6b5bf4 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -70,8 +70,8 @@ use anchor_lang::solana_program::sysvar::instructions; use anchor_spl::associated_token::AssociatedToken; use borsh::{BorshDeserialize, BorshSerialize}; -pub fn handle_initialize_user( - ctx: Context, +pub fn handle_initialize_user<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, InitializeUser<'info>>, sub_account_id: u16, name: [u8; 32], ) -> Result<()> { @@ -184,7 +184,9 @@ pub fn handle_initialize_user( Ok(()) } -pub fn handle_initialize_user_stats(ctx: Context) -> Result<()> { +pub fn handle_initialize_user_stats<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, InitializeUserStats>, +) -> Result<()> { let clock = Clock::get()?; let mut user_stats = ctx @@ -247,8 +249,8 @@ pub fn handle_initialize_referrer_name( #[access_control( deposit_not_paused(&ctx.accounts.state) )] -pub fn handle_deposit( - ctx: Context, +pub fn handle_deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Deposit<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -414,8 +416,8 @@ pub fn handle_deposit( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_withdraw( - ctx: Context, +pub fn handle_withdraw<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Withdraw<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -584,8 +586,8 @@ pub fn handle_withdraw( deposit_not_paused(&ctx.accounts.state) withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_transfer_deposit( - ctx: Context, +pub fn handle_transfer_deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, TransferDeposit<'info>>, market_index: u16, amount: u64, ) -> anchor_lang::Result<()> { @@ -788,7 +790,10 @@ pub fn handle_transfer_deposit( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_place_perp_order(ctx: Context, params: OrderParams) -> Result<()> { +pub fn handle_place_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: OrderParams, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -830,7 +835,10 @@ pub fn handle_place_perp_order(ctx: Context, params: OrderParams) -> #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_order(ctx: Context, order_id: Option) -> Result<()> { +pub fn handle_cancel_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + order_id: Option, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -866,7 +874,10 @@ pub fn handle_cancel_order(ctx: Context, order_id: Option) -> #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_order_by_user_id(ctx: Context, user_order_id: u8) -> Result<()> { +pub fn handle_cancel_order_by_user_id<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + user_order_id: u8, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -897,7 +908,10 @@ pub fn handle_cancel_order_by_user_id(ctx: Context, user_order_id: #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_orders_by_ids(ctx: Context, order_ids: Vec) -> Result<()> { +pub fn handle_cancel_orders_by_ids<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + order_ids: Vec, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -930,8 +944,8 @@ pub fn handle_cancel_orders_by_ids(ctx: Context, order_ids: Vec, +pub fn handle_cancel_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, market_type: Option, market_index: Option, direction: Option, @@ -975,8 +989,8 @@ pub fn handle_cancel_orders( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_modify_order( - ctx: Context, +pub fn handle_modify_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, order_id: Option, modify_order_params: ModifyOrderParams, ) -> Result<()> { @@ -1017,8 +1031,8 @@ pub fn handle_modify_order( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_modify_order_by_user_order_id( - ctx: Context, +pub fn handle_modify_order_by_user_order_id<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, user_order_id: u8, modify_order_params: ModifyOrderParams, ) -> Result<()> { @@ -1054,7 +1068,10 @@ pub fn handle_modify_order_by_user_order_id( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_place_orders(ctx: Context, params: Vec) -> Result<()> { +pub fn handle_place_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: Vec, +) -> Result<()> { let clock = &Clock::get()?; let state = &ctx.accounts.state; @@ -1127,8 +1144,8 @@ pub fn handle_place_orders(ctx: Context, params: Vec) - #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_take_perp_order<'info>( - ctx: Context, +pub fn handle_place_and_take_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, _maker_order_id: Option, ) -> Result<()> { @@ -1225,7 +1242,7 @@ pub fn handle_place_and_take_perp_order<'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_make_perp_order<'a, 'b, 'c, 'info>( +pub fn handle_place_and_make_perp_order<'a, 'b, 'c: 'info, 'info>( ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, @@ -1322,7 +1339,10 @@ pub fn handle_place_and_make_perp_order<'a, 'b, 'c, 'info>( Ok(()) } -pub fn handle_place_spot_order(ctx: Context, params: OrderParams) -> Result<()> { +pub fn handle_place_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: OrderParams, +) -> Result<()> { let AccountMaps { perp_market_map, spot_market_map, @@ -1361,8 +1381,8 @@ pub fn handle_place_spot_order(ctx: Context, params: OrderParams) -> #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_take_spot_order<'info>( - ctx: Context, +pub fn handle_place_and_take_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, fulfillment_type: SpotFulfillmentType, maker_order_id: Option, @@ -1496,8 +1516,8 @@ pub fn handle_place_and_take_spot_order<'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_make_spot_order<'info>( - ctx: Context, +pub fn handle_place_and_make_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, fulfillment_type: SpotFulfillmentType, @@ -1625,8 +1645,8 @@ pub fn handle_place_and_make_spot_order<'info>( #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_add_perp_lp_shares<'info>( - ctx: Context, +pub fn handle_add_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, n_shares: u64, market_index: u16, ) -> Result<()> { @@ -1724,8 +1744,8 @@ pub fn handle_add_perp_lp_shares<'info>( Ok(()) } -pub fn handle_remove_perp_lp_shares_in_expiring_market( - ctx: Context, +pub fn handle_remove_perp_lp_shares_in_expiring_market<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -1777,8 +1797,8 @@ pub fn handle_remove_perp_lp_shares_in_expiring_market( #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_remove_perp_lp_shares( - ctx: Context, +pub fn handle_remove_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -1837,8 +1857,8 @@ pub fn handle_update_user_custom_margin_ratio( Ok(()) } -pub fn handle_update_user_margin_trading_enabled( - ctx: Context, +pub fn handle_update_user_margin_trading_enabled<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateUser<'info>>, _sub_account_id: u16, margin_trading_enabled: bool, ) -> Result<()> { @@ -2361,8 +2381,8 @@ pub struct Swap<'info> { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_begin_swap( - ctx: Context, +pub fn handle_begin_swap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, amount_in: u64, @@ -2611,8 +2631,8 @@ pub enum SwapReduceOnly { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_end_swap( - ctx: Context, +pub fn handle_end_swap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, limit_price: Option, diff --git a/programs/drift/src/lib.rs b/programs/drift/src/lib.rs index 53acdbdc3..5e86c754c 100644 --- a/programs/drift/src/lib.rs +++ b/programs/drift/src/lib.rs @@ -43,15 +43,17 @@ pub mod drift { // User Instructions - pub fn initialize_user( - ctx: Context, + pub fn initialize_user<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, InitializeUser<'info>>, sub_account_id: u16, name: [u8; 32], ) -> Result<()> { handle_initialize_user(ctx, sub_account_id, name) } - pub fn initialize_user_stats(ctx: Context) -> Result<()> { + pub fn initialize_user_stats<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, InitializeUserStats>, + ) -> Result<()> { handle_initialize_user_stats(ctx) } @@ -62,8 +64,8 @@ pub mod drift { handle_initialize_referrer_name(ctx, name) } - pub fn deposit( - ctx: Context, + pub fn deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Deposit<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -71,8 +73,8 @@ pub mod drift { handle_deposit(ctx, market_index, amount, reduce_only) } - pub fn withdraw( - ctx: Context, + pub fn withdraw<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Withdraw<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -80,28 +82,37 @@ pub mod drift { handle_withdraw(ctx, market_index, amount, reduce_only) } - pub fn transfer_deposit( - ctx: Context, + pub fn transfer_deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, TransferDeposit<'info>>, market_index: u16, amount: u64, ) -> anchor_lang::Result<()> { handle_transfer_deposit(ctx, market_index, amount) } - pub fn place_perp_order(ctx: Context, params: OrderParams) -> Result<()> { + pub fn place_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: OrderParams, + ) -> Result<()> { handle_place_perp_order(ctx, params) } - pub fn cancel_order(ctx: Context, order_id: Option) -> Result<()> { + pub fn cancel_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + order_id: Option, + ) -> Result<()> { handle_cancel_order(ctx, order_id) } - pub fn cancel_order_by_user_id(ctx: Context, user_order_id: u8) -> Result<()> { + pub fn cancel_order_by_user_id<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + user_order_id: u8, + ) -> Result<()> { handle_cancel_order_by_user_id(ctx, user_order_id) } - pub fn cancel_orders( - ctx: Context, + pub fn cancel_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, market_type: Option, market_index: Option, direction: Option, @@ -109,48 +120,54 @@ pub mod drift { handle_cancel_orders(ctx, market_type, market_index, direction) } - pub fn cancel_orders_by_ids(ctx: Context, order_ids: Vec) -> Result<()> { + pub fn cancel_orders_by_ids<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + order_ids: Vec, + ) -> Result<()> { handle_cancel_orders_by_ids(ctx, order_ids) } - pub fn modify_order( - ctx: Context, + pub fn modify_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, order_id: Option, modify_order_params: ModifyOrderParams, ) -> Result<()> { handle_modify_order(ctx, order_id, modify_order_params) } - pub fn modify_order_by_user_id( - ctx: Context, + pub fn modify_order_by_user_id<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, user_order_id: u8, modify_order_params: ModifyOrderParams, ) -> Result<()> { handle_modify_order_by_user_order_id(ctx, user_order_id, modify_order_params) } - pub fn place_and_take_perp_order( - ctx: Context, + pub fn place_and_take_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, maker_order_id: Option, ) -> Result<()> { handle_place_and_take_perp_order(ctx, params, maker_order_id) } - pub fn place_and_make_perp_order<'info>( - ctx: Context<'_, '_, '_, 'info, PlaceAndMake<'info>>, + pub fn place_and_make_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, ) -> Result<()> { handle_place_and_make_perp_order(ctx, params, taker_order_id) } - pub fn place_spot_order(ctx: Context, params: OrderParams) -> Result<()> { + pub fn place_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: OrderParams, + ) -> Result<()> { handle_place_spot_order(ctx, params) } - pub fn place_and_take_spot_order( - ctx: Context, + pub fn place_and_take_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, fulfillment_type: Option, maker_order_id: Option, @@ -163,8 +180,8 @@ pub mod drift { ) } - pub fn place_and_make_spot_order( - ctx: Context, + pub fn place_and_make_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, fulfillment_type: Option, @@ -177,12 +194,15 @@ pub mod drift { ) } - pub fn place_orders(ctx: Context, params: Vec) -> Result<()> { + pub fn place_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + params: Vec, + ) -> Result<()> { handle_place_orders(ctx, params) } - pub fn begin_swap( - ctx: Context, + pub fn begin_swap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, amount_in: u64, @@ -190,8 +210,8 @@ pub mod drift { handle_begin_swap(ctx, in_market_index, out_market_index, amount_in) } - pub fn end_swap( - ctx: Context, + pub fn end_swap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, limit_price: Option, @@ -206,24 +226,24 @@ pub mod drift { ) } - pub fn add_perp_lp_shares( - ctx: Context, + pub fn add_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, n_shares: u64, market_index: u16, ) -> Result<()> { handle_add_perp_lp_shares(ctx, n_shares, market_index) } - pub fn remove_perp_lp_shares( - ctx: Context, + pub fn remove_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { handle_remove_perp_lp_shares(ctx, shares_to_burn, market_index) } - pub fn remove_perp_lp_shares_in_expiring_market( - ctx: Context, + pub fn remove_perp_lp_shares_in_expiring_market<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -246,8 +266,8 @@ pub mod drift { handle_update_user_custom_margin_ratio(ctx, _sub_account_id, margin_ratio) } - pub fn update_user_margin_trading_enabled( - ctx: Context, + pub fn update_user_margin_trading_enabled<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateUser<'info>>, _sub_account_id: u16, margin_trading_enabled: bool, ) -> Result<()> { @@ -270,7 +290,9 @@ pub mod drift { handle_update_user_reduce_only(ctx, _sub_account_id, reduce_only) } - pub fn delete_user(ctx: Context) -> Result<()> { + pub fn delete_user<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, DeleteUser>, + ) -> Result<()> { handle_delete_user(ctx) } @@ -280,8 +302,8 @@ pub mod drift { // Keeper Instructions - pub fn fill_perp_order( - ctx: Context, + pub fn fill_perp_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, order_id: Option, _maker_order_id: Option, ) -> Result<()> { @@ -292,8 +314,8 @@ pub mod drift { handle_revert_fill(ctx) } - pub fn fill_spot_order<'info>( - ctx: Context<'_, '_, '_, 'info, FillOrder<'info>>, + pub fn fill_spot_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, order_id: Option, fulfillment_type: Option, maker_order_id: Option, @@ -301,15 +323,22 @@ pub mod drift { handle_fill_spot_order(ctx, order_id, fulfillment_type, maker_order_id) } - pub fn trigger_order(ctx: Context, order_id: u32) -> Result<()> { + pub fn trigger_order<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, TriggerOrder<'info>>, + order_id: u32, + ) -> Result<()> { handle_trigger_order(ctx, order_id) } - pub fn force_cancel_orders(ctx: Context) -> Result<()> { + pub fn force_cancel_orders<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ForceCancelOrder<'info>>, + ) -> Result<()> { handle_force_cancel_orders(ctx) } - pub fn update_user_idle(ctx: Context) -> Result<()> { + pub fn update_user_idle<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateUserIdle<'info>>, + ) -> Result<()> { handle_update_user_idle(ctx) } @@ -324,24 +353,35 @@ pub mod drift { handle_admin_disable_update_perp_bid_ask_twap(ctx, disable) } - pub fn settle_pnl(ctx: Context, market_index: u16) -> Result<()> { + pub fn settle_pnl<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettlePNL>, + market_index: u16, + ) -> Result<()> { handle_settle_pnl(ctx, market_index) } - pub fn settle_funding_payment(ctx: Context) -> Result<()> { + pub fn settle_funding_payment<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettleFunding>, + ) -> Result<()> { handle_settle_funding_payment(ctx) } - pub fn settle_lp(ctx: Context, market_index: u16) -> Result<()> { + pub fn settle_lp<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettleLP>, + market_index: u16, + ) -> Result<()> { handle_settle_lp(ctx, market_index) } - pub fn settle_expired_market(ctx: Context, market_index: u16) -> Result<()> { + pub fn settle_expired_market<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + market_index: u16, + ) -> Result<()> { handle_settle_expired_market(ctx, market_index) } - pub fn liquidate_perp( - ctx: Context, + pub fn liquidate_perp<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidatePerp<'info>>, market_index: u16, liquidator_max_base_asset_amount: u64, limit_price: Option, @@ -354,8 +394,8 @@ pub mod drift { ) } - pub fn liquidate_spot( - ctx: Context, + pub fn liquidate_spot<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidateSpot<'info>>, asset_market_index: u16, liability_market_index: u16, liquidator_max_liability_transfer: u128, @@ -370,8 +410,8 @@ pub mod drift { ) } - pub fn liquidate_borrow_for_perp_pnl( - ctx: Context, + pub fn liquidate_borrow_for_perp_pnl<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_liability_transfer: u128, @@ -386,8 +426,8 @@ pub mod drift { ) } - pub fn liquidate_perp_pnl_for_deposit( - ctx: Context, + pub fn liquidate_perp_pnl_for_deposit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_pnl_transfer: u128, @@ -402,31 +442,31 @@ pub mod drift { ) } - pub fn resolve_perp_pnl_deficit( - ctx: Context, + pub fn resolve_perp_pnl_deficit<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolvePerpPnlDeficit<'info>>, spot_market_index: u16, perp_market_index: u16, ) -> Result<()> { handle_resolve_perp_pnl_deficit(ctx, spot_market_index, perp_market_index) } - pub fn resolve_perp_bankruptcy( - ctx: Context, + pub fn resolve_perp_bankruptcy<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, quote_spot_market_index: u16, market_index: u16, ) -> Result<()> { handle_resolve_perp_bankruptcy(ctx, quote_spot_market_index, market_index) } - pub fn resolve_spot_bankruptcy( - ctx: Context, + pub fn resolve_spot_bankruptcy<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, market_index: u16, ) -> Result<()> { handle_resolve_spot_bankruptcy(ctx, market_index) } - pub fn settle_revenue_to_insurance_fund( - ctx: Context, + pub fn settle_revenue_to_insurance_fund<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, SettleRevenueToInsuranceFund<'info>>, spot_market_index: u16, ) -> Result<()> { handle_settle_revenue_to_insurance_fund(ctx, spot_market_index) @@ -436,7 +476,9 @@ pub mod drift { handle_update_funding_rate(ctx, market_index) } - pub fn update_perp_bid_ask_twap(ctx: Context) -> Result<()> { + pub fn update_perp_bid_ask_twap<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdatePerpBidAskTwap<'info>>, + ) -> Result<()> { handle_update_perp_bid_ask_twap(ctx) } @@ -446,7 +488,10 @@ pub mod drift { handle_update_spot_market_cumulative_interest(ctx) } - pub fn update_amms(ctx: Context, market_indexes: [u16; 5]) -> Result<()> { + pub fn update_amms<'a, 'b, 'c: 'info, 'info>( + ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + market_indexes: [u16; 5], + ) -> Result<()> { handle_update_amms(ctx, market_indexes) } diff --git a/programs/drift/src/math/orders.rs b/programs/drift/src/math/orders.rs index 944512620..6d2b35c73 100644 --- a/programs/drift/src/math/orders.rs +++ b/programs/drift/src/math/orders.rs @@ -1156,17 +1156,15 @@ pub struct Level { pub base_asset_amount: u64, } -pub type Side = Vec; - pub fn find_bids_and_asks_from_users( perp_market: &PerpMarket, oracle_price_date: &OraclePriceData, users: &UserMap, slot: u64, now: i64, -) -> DriftResult<(Side, Side)> { - let mut bids: Side = Vec::with_capacity(32); - let mut asks: Side = Vec::with_capacity(32); +) -> DriftResult<(Vec, Vec)> { + let mut bids: Vec = Vec::with_capacity(32); + let mut asks: Vec = Vec::with_capacity(32); let market_index = perp_market.market_index; let tick_size = perp_market.amm.order_tick_size; @@ -1236,7 +1234,7 @@ pub fn find_bids_and_asks_from_users( Ok((bids, asks)) } -pub fn estimate_price_from_side(side: &Side, depth: u64) -> DriftResult> { +pub fn estimate_price_from_side(side: &Vec, depth: u64) -> DriftResult> { let mut depth_remaining = depth; let mut cumulative_base = 0_u64; let mut cumulative_quote = 0_u128; diff --git a/programs/drift/src/state/fulfillment_params/drift.rs b/programs/drift/src/state/fulfillment_params/drift.rs index e9dd2c1ce..a529c3603 100644 --- a/programs/drift/src/state/fulfillment_params/drift.rs +++ b/programs/drift/src/state/fulfillment_params/drift.rs @@ -23,7 +23,7 @@ pub struct MatchFulfillmentParams<'a> { } impl<'a> MatchFulfillmentParams<'a> { - pub fn new<'b, 'c>( + pub fn new<'b, 'c: 'a>( account_info_iter: &'b mut std::iter::Peekable>>, base_market: &SpotMarket, quote_market: &SpotMarket, diff --git a/programs/drift/src/state/fulfillment_params/phoenix.rs b/programs/drift/src/state/fulfillment_params/phoenix.rs index cedfdfd72..f45040bb2 100644 --- a/programs/drift/src/state/fulfillment_params/phoenix.rs +++ b/programs/drift/src/state/fulfillment_params/phoenix.rs @@ -185,7 +185,7 @@ pub struct PhoenixFulfillmentParams<'a, 'b> { /// Constructor for PhoenixFulfillmentParams impl<'a, 'b> PhoenixFulfillmentParams<'a, 'b> { #[allow(clippy::type_complexity)] - pub fn new<'c>( + pub fn new<'c: 'b>( account_info_iter: &'a mut std::iter::Peekable>>, state: &State, base_market: &SpotMarket, diff --git a/programs/drift/src/state/fulfillment_params/serum.rs b/programs/drift/src/state/fulfillment_params/serum.rs index 7cf5281f5..f75981642 100644 --- a/programs/drift/src/state/fulfillment_params/serum.rs +++ b/programs/drift/src/state/fulfillment_params/serum.rs @@ -212,7 +212,7 @@ impl<'a, 'b> Deref for SerumFulfillmentParams<'a, 'b> { /// Constructor for SerumFulfillmentParams impl<'a, 'b> SerumFulfillmentParams<'a, 'b> { #[allow(clippy::type_complexity)] - pub fn new<'c>( + pub fn new<'c: 'b>( account_info_iter: &'a mut std::iter::Peekable>>, state: &State, base_market: &SpotMarket, diff --git a/programs/drift/src/state/perp_market_map.rs b/programs/drift/src/state/perp_market_map.rs index c897f1b9a..a097fa15c 100644 --- a/programs/drift/src/state/perp_market_map.rs +++ b/programs/drift/src/state/perp_market_map.rs @@ -87,9 +87,9 @@ impl<'a> PerpMarketMap<'a> { } } - pub fn load<'b, 'c>( + pub fn load<'b, 'c, 'd: 'a>( writable_markets: &'b MarketSet, - account_info_iter: &'c mut Peekable>>, + account_info_iter: &'c mut Peekable>>, ) -> DriftResult> { let mut perp_market_map: PerpMarketMap = PerpMarketMap(BTreeMap::new()); @@ -217,7 +217,7 @@ impl<'a> PerpMarketMap<'a> { } } -pub type MarketSet = BTreeSet; +pub(crate) type MarketSet = BTreeSet; pub fn get_writable_perp_market_set(market_index: u16) -> MarketSet { let mut writable_markets = MarketSet::new(); @@ -243,16 +243,3 @@ pub fn get_market_set_for_user_positions(user_positions: &PerpPositions) -> Mark } writable_markets } - -pub fn get_market_set_for_user_positions_and_order( - user_positions: &PerpPositions, - market_index: u16, -) -> MarketSet { - let mut writable_markets = MarketSet::new(); - for position in user_positions.iter() { - writable_markets.insert(position.market_index); - } - writable_markets.insert(market_index); - - writable_markets -} diff --git a/programs/drift/src/state/spot_market_map.rs b/programs/drift/src/state/spot_market_map.rs index 9d2304444..5c71f2795 100644 --- a/programs/drift/src/state/spot_market_map.rs +++ b/programs/drift/src/state/spot_market_map.rs @@ -151,9 +151,9 @@ impl<'a> SpotMarketMap<'a> { } } - pub fn load<'b, 'c>( + pub fn load<'b, 'c, 'd: 'a>( writable_spot_markets: &'b SpotMarketSet, - account_info_iter: &'c mut Peekable>>, + account_info_iter: &'c mut Peekable>>, ) -> DriftResult> { let mut spot_market_map: SpotMarketMap = SpotMarketMap(BTreeMap::new()); @@ -276,7 +276,7 @@ impl<'a> SpotMarketMap<'a> { } } -pub type SpotMarketSet = BTreeSet; +pub(crate) type SpotMarketSet = BTreeSet; pub fn get_writable_spot_market_set(market_index: u16) -> SpotMarketSet { let mut writable_markets = SpotMarketSet::new(); diff --git a/programs/drift/src/state/user.rs b/programs/drift/src/state/user.rs index 0bf2aa6ac..04584ca36 100644 --- a/programs/drift/src/state/user.rs +++ b/programs/drift/src/state/user.rs @@ -934,7 +934,7 @@ impl PerpPosition { } } -pub type PerpPositions = [PerpPosition; 8]; +pub(crate) type PerpPositions = [PerpPosition; 8]; #[zero_copy(unsafe)] #[repr(C)] diff --git a/programs/drift/src/state/user_map.rs b/programs/drift/src/state/user_map.rs index ec4adda30..770d45eab 100644 --- a/programs/drift/src/state/user_map.rs +++ b/programs/drift/src/state/user_map.rs @@ -273,10 +273,10 @@ impl<'a> UserStatsMap<'a> { } } -pub fn load_user_maps<'a>( - account_info_iter: &mut Peekable>>, +pub fn load_user_maps<'a: 'b, 'b>( + account_info_iter: &mut Peekable>>, must_be_writable: bool, -) -> DriftResult<(UserMap<'a>, UserStatsMap<'a>)> { +) -> DriftResult<(UserMap<'b>, UserStatsMap<'b>)> { let mut user_map = UserMap::empty(); let mut user_stats_map = UserStatsMap::empty(); diff --git a/programs/pyth/Cargo.toml b/programs/pyth/Cargo.toml index af0ef3433..8c68971cc 100644 --- a/programs/pyth/Cargo.toml +++ b/programs/pyth/Cargo.toml @@ -16,6 +16,6 @@ default = ["mainnet-beta"] mainnet-beta=[] [dependencies] -anchor-lang = "0.27.0" +anchor-lang = "0.29.0" arrayref = "0.3.6" bytemuck = { version = "1.4.0" } diff --git a/programs/token_faucet/Cargo.toml b/programs/token_faucet/Cargo.toml index d02628818..272d5c945 100644 --- a/programs/token_faucet/Cargo.toml +++ b/programs/token_faucet/Cargo.toml @@ -14,7 +14,7 @@ cpi = ["no-entrypoint"] mainnet-beta=[] [dependencies] -anchor-lang = "0.27.0" -solana-program = "1.14.9" -anchor-spl = "0.27.0" +anchor-lang = "0.29.0" +solana-program = "1.16" +anchor-spl = "0.29.0" bytemuck = { version = "1.4.0" } \ No newline at end of file diff --git a/sdk/package.json b/sdk/package.json index c2ead3573..25a3e9f7e 100644 --- a/sdk/package.json +++ b/sdk/package.json @@ -34,7 +34,7 @@ "access": "public" }, "dependencies": { - "@coral-xyz/anchor": "0.28.1-beta.2", + "@coral-xyz/anchor": "0.29.0", "@ellipsis-labs/phoenix-sdk": "^1.4.2", "@project-serum/serum": "^0.13.38", "@pythnetwork/client": "2.5.3", diff --git a/sdk/src/adminClient.ts b/sdk/src/adminClient.ts index 2170ffbf7..f2d1f492b 100644 --- a/sdk/src/adminClient.ts +++ b/sdk/src/adminClient.ts @@ -63,13 +63,17 @@ export class AdminClient extends DriftClient { }, }); - const { txSig: initializeTxSig } = await super.sendTransaction( - initializeTx, - [], - this.opts - ); - - return [initializeTxSig]; + try { + const { txSig: initializeTxSig } = await super.sendTransaction( + initializeTx, + [], + this.opts + ); + return [initializeTxSig]; + } catch (e) { + console.log(e); + throw e; + } } public async initializeSpotMarket( diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index 5b5095542..fb9b1ccbc 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -8527,7 +8527,7 @@ "name": "Standard", "fields": [ { - "name": "track_open_orders_fraction", + "name": "trackOpenOrdersFraction", "type": "bool" } ] @@ -8536,11 +8536,11 @@ "name": "Liquidation", "fields": [ { - "name": "margin_buffer", + "name": "marginBuffer", "type": "u128" }, { - "name": "market_to_track_margin_requirement", + "name": "marketToTrackMarginRequirement", "type": { "option": { "defined": "MarketIdentifier" diff --git a/yarn.lock b/yarn.lock index e2f614a5e..d999cfc2a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -30,15 +30,14 @@ dependencies: regenerator-runtime "^0.13.11" -"@coral-xyz/anchor@0.28.1-beta.2": - version "0.28.1-beta.2" - resolved "https://registry.yarnpkg.com/@coral-xyz/anchor/-/anchor-0.28.1-beta.2.tgz#4ddd4b2b66af04407be47cf9524147793ec514a0" - integrity sha512-xreUcOFF8+IQKWOBUrDKJbIw2ftpRVybFlEPVrbSlOBCbreCWrQ5754Gt9cHIcuBDAzearCDiBqzsGQdNgPJiw== +"@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/borsh" "^0.28.0" + "@coral-xyz/borsh" "^0.29.0" "@noble/hashes" "^1.3.1" "@solana/web3.js" "^1.68.0" - base64-js "^1.5.1" bn.js "^5.1.2" bs58 "^4.0.1" buffer-layout "^1.2.2" @@ -80,10 +79,10 @@ bn.js "^5.1.2" buffer-layout "^1.2.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" - integrity sha512-/u1VTzw7XooK7rqeD7JLUSwOyRSesPUk0U37BV9zK0axJc1q0nRbKFGFLYCQ16OtdOJTTwGfGp11Lx9B45bRCQ== +"@coral-xyz/borsh@^0.29.0": + version "0.29.0" + resolved "https://registry.yarnpkg.com/@coral-xyz/borsh/-/borsh-0.29.0.tgz#79f7045df2ef66da8006d47f5399c7190363e71f" + integrity sha512-s7VFVa3a0oqpkuRloWVPdCK7hMbAMY270geZOGfCnaqexrP5dTIpbEHL33req6IYPPJ0hYa71cdvJ1h6V55/oQ== dependencies: bn.js "^5.1.2" buffer-layout "^1.2.0" From e7516b64ba8e407b65c54e52bfc6ea63168f3a61 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 22 Jan 2024 13:43:53 -0500 Subject: [PATCH 03/16] update borsh --- Cargo.lock | 21 ++++++------------- programs/drift/Cargo.toml | 4 ++-- programs/drift/src/math/bn.rs | 39 ----------------------------------- 3 files changed, 8 insertions(+), 56 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 530806641..37ef49ae6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -165,7 +165,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4e2e5be518ec6053d90a2a7f26843dbee607583c779e6c8395951b9739bdfbe" dependencies = [ "anchor-syn", - "borsh-derive-internal 0.9.3", + "borsh-derive-internal 0.10.3", "proc-macro2", "quote", "syn 1.0.92", @@ -200,7 +200,7 @@ dependencies = [ "arrayref", "base64 0.13.0", "bincode", - "borsh 0.9.3", + "borsh 0.10.3", "bytemuck", "getrandom 0.2.9", "solana-program", @@ -500,7 +500,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4114279215a005bc675e386011e594e1d9b800918cea18fcadadcce864a2046b" dependencies = [ "borsh-derive 0.10.3", - "hashbrown 0.12.3", + "hashbrown 0.11.2", ] [[package]] @@ -879,7 +879,7 @@ dependencies = [ "anchor-spl", "arrayref", "base64 0.13.0", - "borsh 0.9.3", + "borsh 0.10.3", "bytemuck", "bytes", "drift-macros", @@ -1063,15 +1063,6 @@ 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", -] - [[package]] name = "hashbrown" version = "0.13.2" @@ -1548,9 +1539,9 @@ dependencies = [ [[package]] name = "phoenix-v1" version = "0.2.4" -source = "git+https://github.com/drift-labs/phoenix-v1?rev=d60b17#d60b17d12c8dd93f3764b89a6c0b37750c63e293" +source = "git+https://github.com/drift-labs/phoenix-v1?rev=7703c5#7703c50cf92f2bb321dcd1e2824e1c041135ec5c" dependencies = [ - "borsh 0.9.3", + "borsh 0.10.3", "bytemuck", "ellipsis-macros", "itertools 0.10.5", diff --git a/programs/drift/Cargo.toml b/programs/drift/Cargo.toml index dac58fd45..795d65fdf 100644 --- a/programs/drift/Cargo.toml +++ b/programs/drift/Cargo.toml @@ -21,7 +21,7 @@ solana-program = "1.16" anchor-spl = "0.29.0" pyth-client = "0.2.2" bytemuck = { version = "1.4.0" } -borsh = "0.9.1" +borsh = "0.10.3" num-traits = "0.2" uint = { version = "0.9.1", default-features = false } num-derive = "0.3" @@ -31,7 +31,7 @@ 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"] } enumflags2 = "0.6.4" -phoenix-v1 = { git = "https://github.com/drift-labs/phoenix-v1", rev = "d60b17", version = "0.2.4", features = ["no-entrypoint"] } +phoenix-v1 = { git = "https://github.com/drift-labs/phoenix-v1", rev = "7703c5", version = "0.2.4", 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" } diff --git a/programs/drift/src/math/bn.rs b/programs/drift/src/math/bn.rs index 9e7505417..0218b2a5a 100644 --- a/programs/drift/src/math/bn.rs +++ b/programs/drift/src/math/bn.rs @@ -5,46 +5,13 @@ #![allow(clippy::manual_range_contains)] use crate::error::ErrorCode::BnConversionError; -use borsh::{BorshDeserialize, BorshSerialize}; use std::borrow::BorrowMut; use std::convert::TryInto; -use std::io::{Error, ErrorKind, Write}; use std::mem::size_of; use uint::construct_uint; use crate::error::DriftResult; -macro_rules! impl_borsh_serialize_for_bn { - ($type: ident) => { - impl BorshSerialize for $type { - #[inline] - fn serialize(&self, writer: &mut W) -> std::io::Result<()> { - let bytes = self.to_le_bytes(); - writer.write_all(&bytes) - } - } - }; -} - -macro_rules! impl_borsh_deserialize_for_bn { - ($type: ident) => { - impl BorshDeserialize for $type { - #[inline] - fn deserialize(buf: &mut &[u8]) -> std::io::Result { - if buf.len() < size_of::<$type>() { - return Err(Error::new( - ErrorKind::InvalidInput, - "Unexpected length of input", - )); - } - let res = $type::from_le_bytes(buf[..size_of::<$type>()].try_into().unwrap()); - *buf = &buf[size_of::<$type>()..]; - Ok(res) - } - } - }; -} - construct_uint! { /// 256-bit unsigned integer. pub struct U256(4); @@ -87,9 +54,6 @@ impl U256 { } } -impl_borsh_deserialize_for_bn!(U256); -impl_borsh_serialize_for_bn!(U256); - construct_uint! { /// 192-bit unsigned integer. pub struct U192(3); @@ -131,6 +95,3 @@ impl U192 { bytes } } - -impl_borsh_deserialize_for_bn!(U192); -impl_borsh_serialize_for_bn!(U192); From 9b6f39a1dc2706027334cc0a8c05301c413ae4ce Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 22 Jan 2024 18:30:59 -0500 Subject: [PATCH 04/16] revert changes to adminClient --- sdk/src/adminClient.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/sdk/src/adminClient.ts b/sdk/src/adminClient.ts index f2d1f492b..2170ffbf7 100644 --- a/sdk/src/adminClient.ts +++ b/sdk/src/adminClient.ts @@ -63,17 +63,13 @@ export class AdminClient extends DriftClient { }, }); - try { - const { txSig: initializeTxSig } = await super.sendTransaction( - initializeTx, - [], - this.opts - ); - return [initializeTxSig]; - } catch (e) { - console.log(e); - throw e; - } + const { txSig: initializeTxSig } = await super.sendTransaction( + initializeTx, + [], + this.opts + ); + + return [initializeTxSig]; } public async initializeSpotMarket( From 30e6e461afc208f585d1d88b3f7e97ee1df11514 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 22 Jan 2024 20:29:03 -0500 Subject: [PATCH 05/16] try simplifying lifetimes --- .../src/instructions/optional_accounts.rs | 20 +++++++++---------- programs/drift/src/state/perp_market_map.rs | 4 ++-- programs/drift/src/state/spot_market_map.rs | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/programs/drift/src/instructions/optional_accounts.rs b/programs/drift/src/instructions/optional_accounts.rs index a615e5f24..18a0b90b1 100644 --- a/programs/drift/src/instructions/optional_accounts.rs +++ b/programs/drift/src/instructions/optional_accounts.rs @@ -25,8 +25,8 @@ pub struct AccountMaps<'a> { pub oracle_map: OracleMap<'a>, } -pub fn load_maps<'a, 'b, 'c: 'a>( - account_info_iter: &mut Peekable>>, +pub fn load_maps<'a, 'b>( + account_info_iter: &mut Peekable>>, writable_perp_markets: &'b MarketSet, writable_spot_markets: &'b MarketSet, slot: u64, @@ -43,7 +43,7 @@ pub fn load_maps<'a, 'b, 'c: 'a>( }) } -pub fn get_maker_and_maker_stats<'a, 'b>( +pub fn get_maker_and_maker_stats<'a>( account_info_iter: &mut Peekable>>, ) -> DriftResult<(AccountLoader<'a, User>, AccountLoader<'a, UserStats>)> { let maker_account_info = @@ -73,11 +73,11 @@ pub fn get_maker_and_maker_stats<'a, 'b>( } #[allow(clippy::type_complexity)] -pub fn get_referrer_and_referrer_stats<'a: 'b, 'b>( - account_info_iter: &mut Peekable>>, +pub fn get_referrer_and_referrer_stats<'a>( + account_info_iter: &mut Peekable>>, ) -> DriftResult<( - Option>, - Option>, + Option>, + Option>, )> { let referrer_account_info = account_info_iter.peek(); @@ -146,9 +146,9 @@ pub fn get_referrer_and_referrer_stats<'a: 'b, 'b>( Ok((Some(referrer), Some(referrer_stats))) } -pub fn get_whitelist_token<'a: 'b, 'b>( - account_info_iter: &mut Peekable>>, -) -> DriftResult> { +pub fn get_whitelist_token<'a>( + account_info_iter: &mut Peekable>>, +) -> DriftResult> { let token_account_info = account_info_iter.peek(); if token_account_info.is_none() { msg!("Could not find whitelist token"); diff --git a/programs/drift/src/state/perp_market_map.rs b/programs/drift/src/state/perp_market_map.rs index a097fa15c..17a652e2e 100644 --- a/programs/drift/src/state/perp_market_map.rs +++ b/programs/drift/src/state/perp_market_map.rs @@ -87,9 +87,9 @@ impl<'a> PerpMarketMap<'a> { } } - pub fn load<'b, 'c, 'd: 'a>( + pub fn load<'b, 'c>( writable_markets: &'b MarketSet, - account_info_iter: &'c mut Peekable>>, + account_info_iter: &'c mut Peekable>>, ) -> DriftResult> { let mut perp_market_map: PerpMarketMap = PerpMarketMap(BTreeMap::new()); diff --git a/programs/drift/src/state/spot_market_map.rs b/programs/drift/src/state/spot_market_map.rs index 5c71f2795..c0f4ea40c 100644 --- a/programs/drift/src/state/spot_market_map.rs +++ b/programs/drift/src/state/spot_market_map.rs @@ -151,9 +151,9 @@ impl<'a> SpotMarketMap<'a> { } } - pub fn load<'b, 'c, 'd: 'a>( + pub fn load<'b, 'c>( writable_spot_markets: &'b SpotMarketSet, - account_info_iter: &'c mut Peekable>>, + account_info_iter: &'c mut Peekable>>, ) -> DriftResult> { let mut spot_market_map: SpotMarketMap = SpotMarketMap(BTreeMap::new()); From 3157396b9d314d4d6978d732b3aa5be6a41662b7 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 22 Jan 2024 20:40:51 -0500 Subject: [PATCH 06/16] remove unnecessary lifetimes --- programs/drift/src/instructions/keeper.rs | 80 +++++----- programs/drift/src/lib.rs | 176 +++++++++++----------- 2 files changed, 128 insertions(+), 128 deletions(-) diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index 4686c5f7d..2fd420b15 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -38,8 +38,8 @@ use crate::{validate, QUOTE_PRECISION_I128}; #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_fill_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, +pub fn handle_fill_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: Option, ) -> Result<()> { let (order_id, market_index) = { @@ -70,8 +70,8 @@ pub fn handle_fill_perp_order<'a, 'b, 'c: 'info, 'info>( Ok(()) } -fn fill_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, +fn fill_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: u32, market_index: u16, ) -> Result<()> { @@ -156,8 +156,8 @@ impl Default for SpotFulfillmentType { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_fill_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, +pub fn handle_fill_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: Option, fulfillment_type: Option, maker_order_id: Option, @@ -190,8 +190,8 @@ pub fn handle_fill_spot_order<'a, 'b, 'c: 'info, 'info>( Ok(()) } -fn fill_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, +fn fill_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: u32, market_index: u16, fulfillment_type: SpotFulfillmentType, @@ -282,8 +282,8 @@ fn fill_spot_order<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_trigger_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, TriggerOrder<'info>>, +pub fn handle_trigger_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, TriggerOrder<'info>>, order_id: u32, ) -> Result<()> { let AccountMaps { @@ -335,8 +335,8 @@ pub fn handle_trigger_order<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_force_cancel_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ForceCancelOrder>, +pub fn handle_force_cancel_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ForceCancelOrder>, ) -> Result<()> { let AccountMaps { perp_market_map, @@ -366,8 +366,8 @@ pub fn handle_force_cancel_orders<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_update_user_idle<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateUserIdle<'info>>, +pub fn handle_update_user_idle<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateUserIdle<'info>>, ) -> Result<()> { let mut user = load_mut!(ctx.accounts.user)?; let clock = Clock::get()?; @@ -427,8 +427,8 @@ pub fn handle_update_user_open_orders_count<'info>(ctx: Context) #[access_control( settle_pnl_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_pnl<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettlePNL>, +pub fn handle_settle_pnl<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettlePNL>, market_index: u16, ) -> Result<()> { let clock = Clock::get()?; @@ -502,8 +502,8 @@ pub fn handle_settle_pnl<'a, 'b, 'c: 'info, 'info>( #[access_control( funding_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_funding_payment<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettleFunding>, +pub fn handle_settle_funding_payment<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettleFunding>, ) -> Result<()> { let clock = Clock::get()?; let now = clock.unix_timestamp; @@ -529,8 +529,8 @@ pub fn handle_settle_funding_payment<'a, 'b, 'c: 'info, 'info>( #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_lp<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettleLP>, +pub fn handle_settle_lp<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettleLP>, market_index: u16, ) -> Result<()> { let user_key = ctx.accounts.user.key(); @@ -560,8 +560,8 @@ pub fn handle_settle_lp<'a, 'b, 'c: 'info, 'info>( #[access_control( settle_pnl_not_paused(&ctx.accounts.state) )] -pub fn handle_settle_expired_market<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, +pub fn handle_settle_expired_market<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateAMM<'info>>, market_index: u16, ) -> Result<()> { let clock = Clock::get()?; @@ -603,8 +603,8 @@ pub fn handle_settle_expired_market<'a, 'b, 'c: 'info, 'info>( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_perp<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidatePerp<'info>>, +pub fn handle_liquidate_perp<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidatePerp<'info>>, market_index: u16, liquidator_max_base_asset_amount: u64, limit_price: Option, @@ -663,8 +663,8 @@ pub fn handle_liquidate_perp<'a, 'b, 'c: 'info, 'info>( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_spot<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidateSpot<'info>>, +pub fn handle_liquidate_spot<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidateSpot<'info>>, asset_market_index: u16, liability_market_index: u16, liquidator_max_liability_transfer: u128, @@ -720,8 +720,8 @@ pub fn handle_liquidate_spot<'a, 'b, 'c: 'info, 'info>( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_borrow_for_perp_pnl<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, +pub fn handle_liquidate_borrow_for_perp_pnl<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_liability_transfer: u128, @@ -779,8 +779,8 @@ pub fn handle_liquidate_borrow_for_perp_pnl<'a, 'b, 'c: 'info, 'info>( #[access_control( liq_not_paused(&ctx.accounts.state) )] -pub fn handle_liquidate_perp_pnl_for_deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, +pub fn handle_liquidate_perp_pnl_for_deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_pnl_transfer: u128, @@ -838,8 +838,8 @@ pub fn handle_liquidate_perp_pnl_for_deposit<'a, 'b, 'c: 'info, 'info>( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_perp_pnl_deficit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolvePerpPnlDeficit<'info>>, +pub fn handle_resolve_perp_pnl_deficit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolvePerpPnlDeficit<'info>>, spot_market_index: u16, perp_market_index: u16, ) -> Result<()> { @@ -961,8 +961,8 @@ pub fn handle_resolve_perp_pnl_deficit<'a, 'b, 'c: 'info, 'info>( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_perp_bankruptcy<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, +pub fn handle_resolve_perp_bankruptcy<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolveBankruptcy<'info>>, quote_spot_market_index: u16, market_index: u16, ) -> Result<()> { @@ -1073,8 +1073,8 @@ pub fn handle_resolve_perp_bankruptcy<'a, 'b, 'c: 'info, 'info>( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_resolve_spot_bankruptcy<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, +pub fn handle_resolve_spot_bankruptcy<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolveBankruptcy<'info>>, market_index: u16, ) -> Result<()> { let state = &ctx.accounts.state; @@ -1236,8 +1236,8 @@ pub fn handle_update_funding_rate( funding_not_paused(&ctx.accounts.state) valid_oracle_for_perp_market(&ctx.accounts.oracle, &ctx.accounts.perp_market) )] -pub fn handle_update_perp_bid_ask_twap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdatePerpBidAskTwap<'info>>, +pub fn handle_update_perp_bid_ask_twap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdatePerpBidAskTwap<'info>>, ) -> Result<()> { let perp_market = &mut load_mut!(ctx.accounts.perp_market)?; let clock = Clock::get()?; @@ -1427,8 +1427,8 @@ pub fn handle_update_spot_market_cumulative_interest( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_update_amms<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, +pub fn handle_update_amms<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateAMM<'info>>, market_indexes: [u16; 5], ) -> Result<()> { // up to ~60k compute units (per amm) worst case diff --git a/programs/drift/src/lib.rs b/programs/drift/src/lib.rs index 5e86c754c..09971485e 100644 --- a/programs/drift/src/lib.rs +++ b/programs/drift/src/lib.rs @@ -43,16 +43,16 @@ pub mod drift { // User Instructions - pub fn initialize_user<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, InitializeUser<'info>>, + pub fn initialize_user<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, InitializeUser<'info>>, sub_account_id: u16, name: [u8; 32], ) -> Result<()> { handle_initialize_user(ctx, sub_account_id, name) } - pub fn initialize_user_stats<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, InitializeUserStats>, + pub fn initialize_user_stats<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, InitializeUserStats>, ) -> Result<()> { handle_initialize_user_stats(ctx) } @@ -64,8 +64,8 @@ pub mod drift { handle_initialize_referrer_name(ctx, name) } - pub fn deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Deposit<'info>>, + pub fn deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Deposit<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -73,8 +73,8 @@ pub mod drift { handle_deposit(ctx, market_index, amount, reduce_only) } - pub fn withdraw<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Withdraw<'info>>, + pub fn withdraw<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Withdraw<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -82,37 +82,37 @@ pub mod drift { handle_withdraw(ctx, market_index, amount, reduce_only) } - pub fn transfer_deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, TransferDeposit<'info>>, + pub fn transfer_deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, TransferDeposit<'info>>, market_index: u16, amount: u64, ) -> anchor_lang::Result<()> { handle_transfer_deposit(ctx, market_index, amount) } - pub fn place_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + pub fn place_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: OrderParams, ) -> Result<()> { handle_place_perp_order(ctx, params) } - pub fn cancel_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + pub fn cancel_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, order_id: Option, ) -> Result<()> { handle_cancel_order(ctx, order_id) } - pub fn cancel_order_by_user_id<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + pub fn cancel_order_by_user_id<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, user_order_id: u8, ) -> Result<()> { handle_cancel_order_by_user_id(ctx, user_order_id) } - pub fn cancel_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, + pub fn cancel_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, market_type: Option, market_index: Option, direction: Option, @@ -120,54 +120,54 @@ pub mod drift { handle_cancel_orders(ctx, market_type, market_index, direction) } - pub fn cancel_orders_by_ids<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, + pub fn cancel_orders_by_ids<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, order_ids: Vec, ) -> Result<()> { handle_cancel_orders_by_ids(ctx, order_ids) } - pub fn modify_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, + pub fn modify_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, order_id: Option, modify_order_params: ModifyOrderParams, ) -> Result<()> { handle_modify_order(ctx, order_id, modify_order_params) } - pub fn modify_order_by_user_id<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, + pub fn modify_order_by_user_id<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, user_order_id: u8, modify_order_params: ModifyOrderParams, ) -> Result<()> { handle_modify_order_by_user_order_id(ctx, user_order_id, modify_order_params) } - pub fn place_and_take_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, + pub fn place_and_take_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, maker_order_id: Option, ) -> Result<()> { handle_place_and_take_perp_order(ctx, params, maker_order_id) } - pub fn place_and_make_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, + pub fn place_and_make_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, ) -> Result<()> { handle_place_and_make_perp_order(ctx, params, taker_order_id) } - pub fn place_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + pub fn place_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: OrderParams, ) -> Result<()> { handle_place_spot_order(ctx, params) } - pub fn place_and_take_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, + pub fn place_and_take_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, fulfillment_type: Option, maker_order_id: Option, @@ -180,8 +180,8 @@ pub mod drift { ) } - pub fn place_and_make_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, + pub fn place_and_make_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, fulfillment_type: Option, @@ -194,15 +194,15 @@ pub mod drift { ) } - pub fn place_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, + pub fn place_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: Vec, ) -> Result<()> { handle_place_orders(ctx, params) } - pub fn begin_swap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, + pub fn begin_swap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, amount_in: u64, @@ -210,8 +210,8 @@ pub mod drift { handle_begin_swap(ctx, in_market_index, out_market_index, amount_in) } - pub fn end_swap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, + pub fn end_swap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, limit_price: Option, @@ -226,24 +226,24 @@ pub mod drift { ) } - pub fn add_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, + pub fn add_perp_lp_shares<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, AddRemoveLiquidity<'info>>, n_shares: u64, market_index: u16, ) -> Result<()> { handle_add_perp_lp_shares(ctx, n_shares, market_index) } - pub fn remove_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, + pub fn remove_perp_lp_shares<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, AddRemoveLiquidity<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { handle_remove_perp_lp_shares(ctx, shares_to_burn, market_index) } - pub fn remove_perp_lp_shares_in_expiring_market<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, + pub fn remove_perp_lp_shares_in_expiring_market<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -266,8 +266,8 @@ pub mod drift { handle_update_user_custom_margin_ratio(ctx, _sub_account_id, margin_ratio) } - pub fn update_user_margin_trading_enabled<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateUser<'info>>, + pub fn update_user_margin_trading_enabled<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateUser<'info>>, _sub_account_id: u16, margin_trading_enabled: bool, ) -> Result<()> { @@ -290,8 +290,8 @@ pub mod drift { handle_update_user_reduce_only(ctx, _sub_account_id, reduce_only) } - pub fn delete_user<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, DeleteUser>, + pub fn delete_user<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, DeleteUser>, ) -> Result<()> { handle_delete_user(ctx) } @@ -302,8 +302,8 @@ pub mod drift { // Keeper Instructions - pub fn fill_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, + pub fn fill_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: Option, _maker_order_id: Option, ) -> Result<()> { @@ -314,8 +314,8 @@ pub mod drift { handle_revert_fill(ctx) } - pub fn fill_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, FillOrder<'info>>, + pub fn fill_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, FillOrder<'info>>, order_id: Option, fulfillment_type: Option, maker_order_id: Option, @@ -323,21 +323,21 @@ pub mod drift { handle_fill_spot_order(ctx, order_id, fulfillment_type, maker_order_id) } - pub fn trigger_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, TriggerOrder<'info>>, + pub fn trigger_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, TriggerOrder<'info>>, order_id: u32, ) -> Result<()> { handle_trigger_order(ctx, order_id) } - pub fn force_cancel_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ForceCancelOrder<'info>>, + pub fn force_cancel_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ForceCancelOrder<'info>>, ) -> Result<()> { handle_force_cancel_orders(ctx) } - pub fn update_user_idle<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateUserIdle<'info>>, + pub fn update_user_idle<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateUserIdle<'info>>, ) -> Result<()> { handle_update_user_idle(ctx) } @@ -353,35 +353,35 @@ pub mod drift { handle_admin_disable_update_perp_bid_ask_twap(ctx, disable) } - pub fn settle_pnl<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettlePNL>, + pub fn settle_pnl<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettlePNL>, market_index: u16, ) -> Result<()> { handle_settle_pnl(ctx, market_index) } - pub fn settle_funding_payment<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettleFunding>, + pub fn settle_funding_payment<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettleFunding>, ) -> Result<()> { handle_settle_funding_payment(ctx) } - pub fn settle_lp<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettleLP>, + pub fn settle_lp<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettleLP>, market_index: u16, ) -> Result<()> { handle_settle_lp(ctx, market_index) } - pub fn settle_expired_market<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + pub fn settle_expired_market<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateAMM<'info>>, market_index: u16, ) -> Result<()> { handle_settle_expired_market(ctx, market_index) } - pub fn liquidate_perp<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidatePerp<'info>>, + pub fn liquidate_perp<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidatePerp<'info>>, market_index: u16, liquidator_max_base_asset_amount: u64, limit_price: Option, @@ -394,8 +394,8 @@ pub mod drift { ) } - pub fn liquidate_spot<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidateSpot<'info>>, + pub fn liquidate_spot<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidateSpot<'info>>, asset_market_index: u16, liability_market_index: u16, liquidator_max_liability_transfer: u128, @@ -410,8 +410,8 @@ pub mod drift { ) } - pub fn liquidate_borrow_for_perp_pnl<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, + pub fn liquidate_borrow_for_perp_pnl<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidateBorrowForPerpPnl<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_liability_transfer: u128, @@ -426,8 +426,8 @@ pub mod drift { ) } - pub fn liquidate_perp_pnl_for_deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, + pub fn liquidate_perp_pnl_for_deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, LiquidatePerpPnlForDeposit<'info>>, perp_market_index: u16, spot_market_index: u16, liquidator_max_pnl_transfer: u128, @@ -442,31 +442,31 @@ pub mod drift { ) } - pub fn resolve_perp_pnl_deficit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolvePerpPnlDeficit<'info>>, + pub fn resolve_perp_pnl_deficit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolvePerpPnlDeficit<'info>>, spot_market_index: u16, perp_market_index: u16, ) -> Result<()> { handle_resolve_perp_pnl_deficit(ctx, spot_market_index, perp_market_index) } - pub fn resolve_perp_bankruptcy<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, + pub fn resolve_perp_bankruptcy<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolveBankruptcy<'info>>, quote_spot_market_index: u16, market_index: u16, ) -> Result<()> { handle_resolve_perp_bankruptcy(ctx, quote_spot_market_index, market_index) } - pub fn resolve_spot_bankruptcy<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, ResolveBankruptcy<'info>>, + pub fn resolve_spot_bankruptcy<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, ResolveBankruptcy<'info>>, market_index: u16, ) -> Result<()> { handle_resolve_spot_bankruptcy(ctx, market_index) } - pub fn settle_revenue_to_insurance_fund<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, SettleRevenueToInsuranceFund<'info>>, + pub fn settle_revenue_to_insurance_fund<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, SettleRevenueToInsuranceFund<'info>>, spot_market_index: u16, ) -> Result<()> { handle_settle_revenue_to_insurance_fund(ctx, spot_market_index) @@ -476,8 +476,8 @@ pub mod drift { handle_update_funding_rate(ctx, market_index) } - pub fn update_perp_bid_ask_twap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdatePerpBidAskTwap<'info>>, + pub fn update_perp_bid_ask_twap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdatePerpBidAskTwap<'info>>, ) -> Result<()> { handle_update_perp_bid_ask_twap(ctx) } @@ -488,8 +488,8 @@ pub mod drift { handle_update_spot_market_cumulative_interest(ctx) } - pub fn update_amms<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateAMM<'info>>, + pub fn update_amms<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateAMM<'info>>, market_indexes: [u16; 5], ) -> Result<()> { handle_update_amms(ctx, market_indexes) From 125ba5357871a8a6dccc52cd894920bb5f8deb8d Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 22 Jan 2024 20:44:38 -0500 Subject: [PATCH 07/16] remove unnecessary lifetimes --- programs/drift/src/instructions/user.rs | 96 ++++++++++++------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index 79a6b5bf4..04e00d835 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -70,8 +70,8 @@ use anchor_lang::solana_program::sysvar::instructions; use anchor_spl::associated_token::AssociatedToken; use borsh::{BorshDeserialize, BorshSerialize}; -pub fn handle_initialize_user<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, InitializeUser<'info>>, +pub fn handle_initialize_user<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, InitializeUser<'info>>, sub_account_id: u16, name: [u8; 32], ) -> Result<()> { @@ -184,8 +184,8 @@ pub fn handle_initialize_user<'a, 'b, 'c: 'info, 'info>( Ok(()) } -pub fn handle_initialize_user_stats<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, InitializeUserStats>, +pub fn handle_initialize_user_stats<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, InitializeUserStats>, ) -> Result<()> { let clock = Clock::get()?; @@ -249,8 +249,8 @@ pub fn handle_initialize_referrer_name( #[access_control( deposit_not_paused(&ctx.accounts.state) )] -pub fn handle_deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Deposit<'info>>, +pub fn handle_deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Deposit<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -416,8 +416,8 @@ pub fn handle_deposit<'a, 'b, 'c: 'info, 'info>( #[access_control( withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_withdraw<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Withdraw<'info>>, +pub fn handle_withdraw<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Withdraw<'info>>, market_index: u16, amount: u64, reduce_only: bool, @@ -586,8 +586,8 @@ pub fn handle_withdraw<'a, 'b, 'c: 'info, 'info>( deposit_not_paused(&ctx.accounts.state) withdraw_not_paused(&ctx.accounts.state) )] -pub fn handle_transfer_deposit<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, TransferDeposit<'info>>, +pub fn handle_transfer_deposit<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, TransferDeposit<'info>>, market_index: u16, amount: u64, ) -> anchor_lang::Result<()> { @@ -790,8 +790,8 @@ pub fn handle_transfer_deposit<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_place_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, +pub fn handle_place_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: OrderParams, ) -> Result<()> { let clock = &Clock::get()?; @@ -835,8 +835,8 @@ pub fn handle_place_perp_order<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, +pub fn handle_cancel_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, order_id: Option, ) -> Result<()> { let clock = &Clock::get()?; @@ -874,8 +874,8 @@ pub fn handle_cancel_order<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_order_by_user_id<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, +pub fn handle_cancel_order_by_user_id<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, user_order_id: u8, ) -> Result<()> { let clock = &Clock::get()?; @@ -908,8 +908,8 @@ pub fn handle_cancel_order_by_user_id<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_orders_by_ids<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder>, +pub fn handle_cancel_orders_by_ids<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder>, order_ids: Vec, ) -> Result<()> { let clock = &Clock::get()?; @@ -944,8 +944,8 @@ pub fn handle_cancel_orders_by_ids<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_cancel_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, +pub fn handle_cancel_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, market_type: Option, market_index: Option, direction: Option, @@ -989,8 +989,8 @@ pub fn handle_cancel_orders<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_modify_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, +pub fn handle_modify_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, order_id: Option, modify_order_params: ModifyOrderParams, ) -> Result<()> { @@ -1031,8 +1031,8 @@ pub fn handle_modify_order<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_modify_order_by_user_order_id<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, CancelOrder<'info>>, +pub fn handle_modify_order_by_user_order_id<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, CancelOrder<'info>>, user_order_id: u8, modify_order_params: ModifyOrderParams, ) -> Result<()> { @@ -1068,8 +1068,8 @@ pub fn handle_modify_order_by_user_order_id<'a, 'b, 'c: 'info, 'info>( #[access_control( exchange_not_paused(&ctx.accounts.state) )] -pub fn handle_place_orders<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, +pub fn handle_place_orders<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: Vec, ) -> Result<()> { let clock = &Clock::get()?; @@ -1144,8 +1144,8 @@ pub fn handle_place_orders<'a, 'b, 'c: 'info, 'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_take_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, +pub fn handle_place_and_take_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, _maker_order_id: Option, ) -> Result<()> { @@ -1242,8 +1242,8 @@ pub fn handle_place_and_take_perp_order<'a, 'b, 'c: 'info, 'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_make_perp_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, +pub fn handle_place_and_make_perp_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, ) -> Result<()> { @@ -1339,8 +1339,8 @@ pub fn handle_place_and_make_perp_order<'a, 'b, 'c: 'info, 'info>( Ok(()) } -pub fn handle_place_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceOrder>, +pub fn handle_place_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceOrder>, params: OrderParams, ) -> Result<()> { let AccountMaps { @@ -1381,8 +1381,8 @@ pub fn handle_place_spot_order<'a, 'b, 'c: 'info, 'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_take_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndTake<'info>>, +pub fn handle_place_and_take_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndTake<'info>>, params: OrderParams, fulfillment_type: SpotFulfillmentType, maker_order_id: Option, @@ -1516,8 +1516,8 @@ pub fn handle_place_and_take_spot_order<'a, 'b, 'c: 'info, 'info>( #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_place_and_make_spot_order<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, PlaceAndMake<'info>>, +pub fn handle_place_and_make_spot_order<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, PlaceAndMake<'info>>, params: OrderParams, taker_order_id: u32, fulfillment_type: SpotFulfillmentType, @@ -1645,8 +1645,8 @@ pub fn handle_place_and_make_spot_order<'a, 'b, 'c: 'info, 'info>( #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_add_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, +pub fn handle_add_perp_lp_shares<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, AddRemoveLiquidity<'info>>, n_shares: u64, market_index: u16, ) -> Result<()> { @@ -1744,8 +1744,8 @@ pub fn handle_add_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( Ok(()) } -pub fn handle_remove_perp_lp_shares_in_expiring_market<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, +pub fn handle_remove_perp_lp_shares_in_expiring_market<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, RemoveLiquidityInExpiredMarket<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -1797,8 +1797,8 @@ pub fn handle_remove_perp_lp_shares_in_expiring_market<'a, 'b, 'c: 'info, 'info> #[access_control( amm_not_paused(&ctx.accounts.state) )] -pub fn handle_remove_perp_lp_shares<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, AddRemoveLiquidity<'info>>, +pub fn handle_remove_perp_lp_shares<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, AddRemoveLiquidity<'info>>, shares_to_burn: u64, market_index: u16, ) -> Result<()> { @@ -1857,8 +1857,8 @@ pub fn handle_update_user_custom_margin_ratio( Ok(()) } -pub fn handle_update_user_margin_trading_enabled<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, UpdateUser<'info>>, +pub fn handle_update_user_margin_trading_enabled<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, UpdateUser<'info>>, _sub_account_id: u16, margin_trading_enabled: bool, ) -> Result<()> { @@ -2381,8 +2381,8 @@ pub struct Swap<'info> { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_begin_swap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, +pub fn handle_begin_swap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, amount_in: u64, @@ -2631,8 +2631,8 @@ pub enum SwapReduceOnly { #[access_control( fill_not_paused(&ctx.accounts.state) )] -pub fn handle_end_swap<'a, 'b, 'c: 'info, 'info>( - ctx: Context<'a, 'b, 'c, 'info, Swap<'info>>, +pub fn handle_end_swap<'c: 'info, 'info>( + ctx: Context<'_, '_, 'c, 'info, Swap<'info>>, in_market_index: u16, out_market_index: u16, limit_price: Option, From 2244c99eb2857727d248acef78a85fa7ae801538 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 31 Mar 2024 13:29:39 -0400 Subject: [PATCH 08/16] fix idl --- sdk/src/idl/drift.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sdk/src/idl/drift.json b/sdk/src/idl/drift.json index 6f07c05f2..561418250 100644 --- a/sdk/src/idl/drift.json +++ b/sdk/src/idl/drift.json @@ -9024,15 +9024,7 @@ "name": "Liquidation", "fields": [ { -<<<<<<< HEAD - "name": "marginBuffer", - "type": "u128" - }, - { "name": "marketToTrackMarginRequirement", -======= - "name": "market_to_track_margin_requirement", ->>>>>>> master "type": { "option": { "defined": "MarketIdentifier" From 0ed92db9353c523c28128ea36ebda7969834ce23 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 31 Mar 2024 13:40:35 -0400 Subject: [PATCH 09/16] fix cargo fmt --- programs/switchboard/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/programs/switchboard/src/lib.rs b/programs/switchboard/src/lib.rs index 9d6dca523..f95c5969f 100644 --- a/programs/switchboard/src/lib.rs +++ b/programs/switchboard/src/lib.rs @@ -3,9 +3,7 @@ use anchor_lang::prelude::*; declare_id!("SW1TCH7qEPTdLsDHRgPuMQjbQxKdH2aBStViMFnt64f"); #[program] -pub mod switchboard { - -} +pub mod switchboard {} #[zero_copy(unsafe)] #[repr(packed)] From bfff1169076e503feb2c14e164452f37ed38cfac Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 31 Mar 2024 13:45:47 -0400 Subject: [PATCH 10/16] try updating anchor/solana/rust version --- .github/actions/setup-solana/action.yaml | 2 -- .github/workflows/main.yml | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/actions/setup-solana/action.yaml b/.github/actions/setup-solana/action.yaml index 929f8e6a7..e219b454e 100644 --- a/.github/actions/setup-solana/action.yaml +++ b/.github/actions/setup-solana/action.yaml @@ -17,7 +17,5 @@ runs: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_VERSION }}/install)" echo "$HOME/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH" - echo Configuring bpf toolchain... - (cd $HOME/.local/share/solana/install/active_release/bin/sdk/bpf/scripts; ./install.sh) echo "[41,242,37,42,13,160,221,13,242,224,230,17,141,228,35,40,57,231,71,8,239,32,226,165,181,216,231,245,170,229,117,123,39,103,128,179,245,168,230,228,127,219,58,249,69,6,251,148,173,190,191,217,50,67,123,105,121,215,242,41,242,85,71,109]" > $HOME/.config/solana/id.json shell: bash \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4a927a2d7..3f6406767 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,8 +13,8 @@ defaults: env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: 1.62.0 - SOLANA_VERSION: "1.14.16" + RUST_TOOLCHAIN: 1.70.0 + SOLANA_VERSION: "1.16.27" jobs: fmt-clippy: @@ -115,7 +115,7 @@ jobs: - uses: ./.github/actions/setup-solana/ - name: install anchor cli - run: cargo install --git https://github.com/coral-xyz/anchor --tag v0.26.0 anchor-cli --locked + run: cargo install --git https://github.com/coral-xyz/anchor --tag v0.29.0 anchor-cli --locked - name: Setup node uses: actions/setup-node@v2 From eecb1d3c958f09caee2e7d199941211b49cccce4 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Sun, 31 Mar 2024 13:57:45 -0400 Subject: [PATCH 11/16] fix cargo test --- programs/drift/src/math/orders/tests.rs | 6 +++--- programs/drift/src/state/perp_market_map.rs | 4 ++-- programs/drift/src/state/spot_market_map.rs | 4 ++-- programs/drift/src/state/user_map.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/programs/drift/src/math/orders/tests.rs b/programs/drift/src/math/orders/tests.rs index e760bc75e..4d19a3d82 100644 --- a/programs/drift/src/math/orders/tests.rs +++ b/programs/drift/src/math/orders/tests.rs @@ -3344,12 +3344,12 @@ pub mod get_price_for_perp_order { } pub mod estimate_price_from_side { - use crate::math::orders::{estimate_price_from_side, Level, Side}; + use crate::math::orders::{estimate_price_from_side, Level}; use crate::{BASE_PRECISION_U64, PRICE_PRECISION_U64}; #[test] fn ask() { - let mut asks: Side = vec![]; + let mut asks: Vec = vec![]; for i in 0..11 { asks.push(Level { price: (100 - i) * PRICE_PRECISION_U64, @@ -3370,7 +3370,7 @@ pub mod estimate_price_from_side { #[test] fn bids() { - let mut bids: Side = vec![]; + let mut bids: Vec = vec![]; for i in 0..11 { bids.push(Level { price: (90 + i) * PRICE_PRECISION_U64, diff --git a/programs/drift/src/state/perp_market_map.rs b/programs/drift/src/state/perp_market_map.rs index 17a652e2e..57f3e3fcd 100644 --- a/programs/drift/src/state/perp_market_map.rs +++ b/programs/drift/src/state/perp_market_map.rs @@ -136,7 +136,7 @@ impl<'a> PerpMarketMap<'a> { #[cfg(test)] impl<'a> PerpMarketMap<'a> { - pub fn load_one<'c>( + pub fn load_one<'c: 'a>( account_info: &'c AccountInfo<'a>, must_be_writable: bool, ) -> DriftResult> { @@ -177,7 +177,7 @@ impl<'a> PerpMarketMap<'a> { PerpMarketMap(BTreeMap::new()) } - pub fn load_multiple<'c>( + pub fn load_multiple<'c: 'a>( account_infos: Vec<&'c AccountInfo<'a>>, must_be_writable: bool, ) -> DriftResult> { diff --git a/programs/drift/src/state/spot_market_map.rs b/programs/drift/src/state/spot_market_map.rs index c0f4ea40c..8a6ea98ba 100644 --- a/programs/drift/src/state/spot_market_map.rs +++ b/programs/drift/src/state/spot_market_map.rs @@ -199,7 +199,7 @@ impl<'a> SpotMarketMap<'a> { #[cfg(test)] impl<'a> SpotMarketMap<'a> { - pub fn load_one<'c>( + pub fn load_one<'c: 'a>( account_info: &'c AccountInfo<'a>, must_be_writable: bool, ) -> DriftResult> { @@ -235,7 +235,7 @@ impl<'a> SpotMarketMap<'a> { Ok(spot_market_map) } - pub fn load_multiple<'c>( + pub fn load_multiple<'c: 'a>( account_info: Vec<&'c AccountInfo<'a>>, must_be_writable: bool, ) -> DriftResult> { diff --git a/programs/drift/src/state/user_map.rs b/programs/drift/src/state/user_map.rs index 770d45eab..330f30ede 100644 --- a/programs/drift/src/state/user_map.rs +++ b/programs/drift/src/state/user_map.rs @@ -105,7 +105,7 @@ impl<'a> UserMap<'a> { #[cfg(test)] impl<'a> UserMap<'a> { - pub fn load_one<'b>(account_info: &'b AccountInfo<'a>) -> DriftResult> { + 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(); @@ -233,7 +233,7 @@ impl<'a> UserStatsMap<'a> { #[cfg(test)] impl<'a> UserStatsMap<'a> { - pub fn load_one<'b>(account_info: &'b AccountInfo<'a>) -> DriftResult> { + 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(); From 068613fc15de3219cc0a90e2d8d06f533907ea08 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 10 Jun 2024 13:51:33 -0400 Subject: [PATCH 12/16] tweak switchboard test --- tests/switchboardTxCus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/switchboardTxCus.ts b/tests/switchboardTxCus.ts index 659adb1da..a38a1d05b 100644 --- a/tests/switchboardTxCus.ts +++ b/tests/switchboardTxCus.ts @@ -211,6 +211,6 @@ describe('switchboard place orders cus', () => { ) )[0]; console.log(cus); - assert(cus < 380000); + assert(cus < 400000); }); }); From 93c952730f7f193ae977b77597a442f7a4aa67ef Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 10 Jun 2024 14:12:49 -0400 Subject: [PATCH 13/16] try using rust 1.68 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31697c8e4..368cf5c77 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ defaults: env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: 1.70.0 + RUST_TOOLCHAIN: 1.68.0 SOLANA_VERSION: "1.16.27" jobs: From 145ec4cf87aff8d5f3670c0b434e59cf6230eeac Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 10 Jun 2024 14:19:55 -0400 Subject: [PATCH 14/16] Revert "try using rust 1.68" This reverts commit 93c952730f7f193ae977b77597a442f7a4aa67ef. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 368cf5c77..31697c8e4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ defaults: env: CARGO_TERM_COLOR: always - RUST_TOOLCHAIN: 1.68.0 + RUST_TOOLCHAIN: 1.70.0 SOLANA_VERSION: "1.16.27" jobs: From 6f34861538a344b1a0e1fcfdea8398a369a092e9 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 10 Jun 2024 15:20:57 -0400 Subject: [PATCH 15/16] fix pre-commit --- .../drift/src/controller/insurance/tests.rs | 2 +- .../drift/src/controller/liquidation/tests.rs | 36 +++++----- programs/drift/src/controller/lp/tests.rs | 6 +- .../src/controller/orders/amm_jit_tests.rs | 2 +- .../src/controller/orders/amm_lp_jit_tests.rs | 2 +- programs/drift/src/controller/orders/tests.rs | 60 ++++++++-------- programs/drift/src/controller/pnl.rs | 18 +++-- .../drift/src/controller/pnl/delisting.rs | 20 +++--- programs/drift/src/controller/pnl/tests.rs | 32 ++++----- programs/drift/src/controller/position.rs | 10 +-- programs/drift/src/controller/spot_balance.rs | 2 +- .../src/controller/spot_balance/tests.rs | 8 +-- programs/drift/src/instructions/admin.rs | 12 ++-- programs/drift/src/instructions/keeper.rs | 9 +-- programs/drift/src/math/amm/tests.rs | 2 +- programs/drift/src/math/amm_spread/tests.rs | 4 +- programs/drift/src/math/constants.rs | 14 ++-- programs/drift/src/math/funding/tests.rs | 12 ++-- programs/drift/src/math/insurance.rs | 2 +- programs/drift/src/math/liquidation/tests.rs | 8 +-- programs/drift/src/math/margin/tests.rs | 14 ++-- programs/drift/src/math/oracle.rs | 13 ++-- programs/drift/src/math/orders/tests.rs | 20 +++--- programs/drift/src/state/events.rs | 68 ++++--------------- programs/drift/src/state/oracle.rs | 10 +-- programs/drift/src/state/order_params.rs | 11 +-- .../drift/src/state/order_params/tests.rs | 12 ++-- .../src/state/paused_operations/tests.rs | 6 +- programs/drift/src/state/perp_market.rs | 27 +++----- programs/drift/src/state/perp_market_map.rs | 2 +- programs/drift/src/state/settle_pnl_mode.rs | 8 +-- programs/drift/src/state/spot_market.rs | 29 +++----- programs/drift/src/state/user.rs | 29 ++------ programs/drift/src/state/user/tests.rs | 6 +- programs/drift/src/validation/user.rs | 2 +- programs/pyth/src/lib.rs | 4 +- programs/pyth/src/pc.rs | 27 ++------ 37 files changed, 211 insertions(+), 338 deletions(-) diff --git a/programs/drift/src/controller/insurance/tests.rs b/programs/drift/src/controller/insurance/tests.rs index f05e269f3..4301a3d26 100644 --- a/programs/drift/src/controller/insurance/tests.rs +++ b/programs/drift/src/controller/insurance/tests.rs @@ -1531,7 +1531,7 @@ fn test_transfer_protocol_owned_stake() { // withdraw half let amount_returned = admin_remove_insurance_fund_stake( if_balance, - (spot_market.insurance_fund.total_shares / 2) as u128, + spot_market.insurance_fund.total_shares / 2, &mut spot_market, 1, Pubkey::default(), diff --git a/programs/drift/src/controller/liquidation/tests.rs b/programs/drift/src/controller/liquidation/tests.rs index 2e7b9adae..61230af1f 100644 --- a/programs/drift/src/controller/liquidation/tests.rs +++ b/programs/drift/src/controller/liquidation/tests.rs @@ -574,7 +574,7 @@ pub mod liquidate_perp { let mut user_stats = UserStats::default(); let mut liquidator_stats = UserStats::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -725,7 +725,7 @@ pub mod liquidate_perp { let mut user_stats = UserStats::default(); let mut liquidator_stats = UserStats::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -1511,7 +1511,7 @@ pub mod liquidate_perp { let mut user_stats = UserStats::default(); let mut liquidator_stats = UserStats::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: (LIQUIDATION_PCT_PRECISION / 10) as u16, liquidation_duration: 150, ..Default::default() @@ -1788,7 +1788,7 @@ pub mod liquidate_perp { let mut user_stats = UserStats::default(); let mut liquidator_stats = UserStats::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: (LIQUIDATION_PCT_PRECISION / 10) as u16, liquidation_duration: 150, ..Default::default() @@ -1913,7 +1913,7 @@ pub mod liquidate_perp { let mut user_stats = UserStats::default(); let mut liquidator_stats = UserStats::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: (LIQUIDATION_PCT_PRECISION / 10) as u16, liquidation_duration: 150, ..Default::default() @@ -2631,7 +2631,7 @@ pub mod liquidate_spot { let liquidator_key = Pubkey::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -2843,7 +2843,7 @@ pub mod liquidate_spot { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -2967,7 +2967,7 @@ pub mod liquidate_spot { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -3093,7 +3093,7 @@ pub mod liquidate_spot { let liquidator_key = Pubkey::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, liquidation_duration: 150, ..Default::default() @@ -3223,7 +3223,7 @@ pub mod liquidate_spot { let liquidator_key = Pubkey::default(); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: (LIQUIDATION_PCT_PRECISION / 10) as u16, liquidation_duration: 150, ..Default::default() @@ -3463,7 +3463,7 @@ pub mod liquidate_spot { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); - let liquidation_buffer = MARGIN_PRECISION as u32 / 50; + let liquidation_buffer = MARGIN_PRECISION / 50; let state = State { liquidation_margin_buffer_ratio: liquidation_buffer, initial_pct_to_liquidate: LIQUIDATION_PCT_PRECISION as u16, @@ -3825,7 +3825,7 @@ pub mod liquidate_borrow_for_perp_pnl { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); - let liquidation_buffer = MARGIN_PRECISION as u32 / 50; + let liquidation_buffer = MARGIN_PRECISION / 50; liquidate_borrow_for_perp_pnl( 0, 1, @@ -4471,7 +4471,7 @@ pub mod liquidate_borrow_for_perp_pnl { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); - let liquidation_buffer = MARGIN_PRECISION as u32 / 50; + let liquidation_buffer = MARGIN_PRECISION / 50; liquidate_borrow_for_perp_pnl( 0, 1, @@ -4628,7 +4628,7 @@ pub mod liquidate_borrow_for_perp_pnl { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); - let liquidation_buffer = MARGIN_PRECISION as u32 / 50; + let liquidation_buffer = MARGIN_PRECISION / 50; liquidate_borrow_for_perp_pnl( 0, 1, @@ -5071,7 +5071,7 @@ pub mod liquidate_perp_pnl_for_deposit { &mut oracle_map, now, slot, - MARGIN_PRECISION as u32 / 50, + MARGIN_PRECISION / 50, PERCENTAGE_PRECISION, 150, ) @@ -5679,7 +5679,7 @@ pub mod liquidate_perp_pnl_for_deposit { &mut oracle_map, now, slot, - MARGIN_PRECISION as u32 / 50, + MARGIN_PRECISION / 50, PERCENTAGE_PRECISION, 150, ) @@ -5821,7 +5821,7 @@ pub mod liquidate_perp_pnl_for_deposit { let user_key = Pubkey::default(); let liquidator_key = Pubkey::default(); - let liquidation_buffer = MARGIN_PRECISION as u32 / 50; + let liquidation_buffer = MARGIN_PRECISION / 50; liquidate_perp_pnl_for_deposit( 0, 1, @@ -6093,7 +6093,7 @@ pub mod liquidate_perp_pnl_for_deposit { .is_err()); let state = State { - liquidation_margin_buffer_ratio: MARGIN_PRECISION as u32 / 50, + liquidation_margin_buffer_ratio: MARGIN_PRECISION / 50, initial_pct_to_liquidate: (PERCENTAGE_PRECISION / 10) as u16, liquidation_duration: 150, ..Default::default() diff --git a/programs/drift/src/controller/lp/tests.rs b/programs/drift/src/controller/lp/tests.rs index 27889448e..3ff96a32f 100644 --- a/programs/drift/src/controller/lp/tests.rs +++ b/programs/drift/src/controller/lp/tests.rs @@ -487,7 +487,7 @@ pub fn test_lp_settle_pnl() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -634,7 +634,7 @@ fn test_lp_margin_calc() { status: MarketStatus::Active, liquidator_fee: LIQUIDATION_FEE_PRECISION / 100, pnl_pool: PoolBalance { - scaled_balance: (50 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -697,7 +697,7 @@ fn test_lp_margin_calc() { // add move lower let oracle_price_data = OraclePriceData { - price: oracle_price.agg.price as i64, + price: oracle_price.agg.price, confidence: 100000, delay: 1, has_sufficient_number_of_data_points: true, diff --git a/programs/drift/src/controller/orders/amm_jit_tests.rs b/programs/drift/src/controller/orders/amm_jit_tests.rs index d6320ad3d..fa88f0e19 100644 --- a/programs/drift/src/controller/orders/amm_jit_tests.rs +++ b/programs/drift/src/controller/orders/amm_jit_tests.rs @@ -2553,7 +2553,7 @@ pub mod amm_jit { post_only: true, order_type: OrderType::Limit, direction: PositionDirection::Short, - base_asset_amount: baa as u64, + base_asset_amount: baa, price: auction_price, ..Order::default() }), diff --git a/programs/drift/src/controller/orders/amm_lp_jit_tests.rs b/programs/drift/src/controller/orders/amm_lp_jit_tests.rs index 31a22f5b6..d053bd72a 100644 --- a/programs/drift/src/controller/orders/amm_lp_jit_tests.rs +++ b/programs/drift/src/controller/orders/amm_lp_jit_tests.rs @@ -2742,7 +2742,7 @@ pub mod amm_lp_jit { post_only: true, order_type: OrderType::Limit, direction: PositionDirection::Short, - base_asset_amount: baa as u64, + base_asset_amount: baa, price: auction_price, ..Order::default() }), diff --git a/programs/drift/src/controller/orders/tests.rs b/programs/drift/src/controller/orders/tests.rs index 35ea817a5..73ae0298c 100644 --- a/programs/drift/src/controller/orders/tests.rs +++ b/programs/drift/src/controller/orders/tests.rs @@ -4831,9 +4831,9 @@ pub mod fill_order { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: oracle_price.twap as i64, - last_oracle_price_twap_5min: oracle_price.twap as i64, - last_oracle_price: oracle_price.agg.price as i64, + last_oracle_price_twap: oracle_price.twap, + last_oracle_price_twap_5min: oracle_price.twap, + last_oracle_price: oracle_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -5036,9 +5036,9 @@ pub mod fill_order { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: oracle_price.twap as i64, - last_oracle_price_twap_5min: oracle_price.twap as i64, - last_oracle_price: oracle_price.agg.price as i64, + last_oracle_price_twap: oracle_price.twap, + last_oracle_price_twap_5min: oracle_price.twap, + last_oracle_price: oracle_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -5378,9 +5378,9 @@ pub mod fill_order { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: oracle_price.twap as i64, - last_oracle_price_twap_5min: oracle_price.twap as i64, - last_oracle_price: oracle_price.agg.price as i64, + last_oracle_price_twap: oracle_price.twap, + last_oracle_price_twap_5min: oracle_price.twap, + last_oracle_price: oracle_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -9256,9 +9256,9 @@ pub mod force_cancel_orders { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: oracle_price.twap as i64, - last_oracle_price_twap_5min: oracle_price.twap as i64, - last_oracle_price: oracle_price.agg.price as i64, + last_oracle_price_twap: oracle_price.twap, + last_oracle_price_twap_5min: oracle_price.twap, + last_oracle_price: oracle_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -9552,9 +9552,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -9746,9 +9746,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -9941,9 +9941,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -10122,9 +10122,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -10377,9 +10377,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() @@ -10574,9 +10574,9 @@ pub mod get_maker_orders_info { long_spread: 0, short_spread: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: pyth_price.twap as i64, - last_oracle_price_twap_5min: pyth_price.twap as i64, - last_oracle_price: pyth_price.agg.price as i64, + last_oracle_price_twap: pyth_price.twap, + last_oracle_price_twap_5min: pyth_price.twap, + last_oracle_price: pyth_price.agg.price, ..HistoricalOracleData::default() }, ..AMM::default() diff --git a/programs/drift/src/controller/pnl.rs b/programs/drift/src/controller/pnl.rs index 950808fa2..aaeda8d3f 100644 --- a/programs/drift/src/controller/pnl.rs +++ b/programs/drift/src/controller/pnl.rs @@ -213,16 +213,14 @@ pub fn settle_pnl( ); return mode.result(ErrorCode::InvalidMarketStatusToSettlePnl, &msg); } - } else { - if perp_market.status != MarketStatus::Active - && perp_market.status != MarketStatus::ReduceOnly - { - let msg = format!( - "Cannot settle pnl under current market = {} status (neither Active or ReduceOnly)", - market_index - ); - return mode.result(ErrorCode::InvalidMarketStatusToSettlePnl, &msg); - } + } else if perp_market.status != MarketStatus::Active + && perp_market.status != MarketStatus::ReduceOnly + { + let msg = format!( + "Cannot settle pnl under current market = {} status (neither Active or ReduceOnly)", + market_index + ); + return mode.result(ErrorCode::InvalidMarketStatusToSettlePnl, &msg); } let pnl_pool_token_amount = get_token_amount( diff --git a/programs/drift/src/controller/pnl/delisting.rs b/programs/drift/src/controller/pnl/delisting.rs index 58449fbf7..e9e73b60c 100644 --- a/programs/drift/src/controller/pnl/delisting.rs +++ b/programs/drift/src/controller/pnl/delisting.rs @@ -664,7 +664,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -882,7 +882,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1103,7 +1103,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1306,7 +1306,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1350,7 +1350,7 @@ pub mod delisting_test { borrow_balance: SPOT_BALANCE_PRECISION, liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: (oracle_price.agg.price * 99 / 100) as i64, + last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), ..HistoricalOracleData::default() }, ..SpotMarket::default() @@ -1729,7 +1729,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1774,7 +1774,7 @@ pub mod delisting_test { borrow_balance: SPOT_BALANCE_PRECISION, liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: (oracle_price.agg.price * 99 / 100) as i64, + last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), ..HistoricalOracleData::default() }, ..SpotMarket::default() @@ -2113,7 +2113,7 @@ pub mod delisting_test { margin_ratio_maintenance: 500, status: MarketStatus::Initialized, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -2158,8 +2158,8 @@ pub mod delisting_test { borrow_balance: SPOT_BALANCE_PRECISION, liquidator_fee: 0, historical_oracle_data: HistoricalOracleData { - last_oracle_price_twap: (oracle_price.agg.price * 99 / 100) as i64, - last_oracle_price_twap_5min: (oracle_price.agg.price * 99 / 100) as i64, + last_oracle_price_twap: (oracle_price.agg.price * 99 / 100), + last_oracle_price_twap_5min: (oracle_price.agg.price * 99 / 100), ..HistoricalOracleData::default() }, diff --git a/programs/drift/src/controller/pnl/tests.rs b/programs/drift/src/controller/pnl/tests.rs index 24cc21421..b88bbeda1 100644 --- a/programs/drift/src/controller/pnl/tests.rs +++ b/programs/drift/src/controller/pnl/tests.rs @@ -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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -617,7 +617,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -753,7 +753,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -892,7 +892,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1017,7 +1017,7 @@ pub fn market_fee_pool_pays_back_to_pnl_pool() { oracle: oracle_price_key, total_fee_minus_distributions: QUOTE_PRECISION_I128, fee_pool: PoolBalance { - scaled_balance: (2 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (2 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1036,7 +1036,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1173,7 +1173,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1311,7 +1311,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1446,7 +1446,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1584,7 +1584,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1722,7 +1722,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -1862,7 +1862,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -2082,7 +2082,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) as u128, + scaled_balance: (50 * SPOT_BALANCE_PRECISION), 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 baf13c184..dfa39ab18 100644 --- a/programs/drift/src/controller/position.rs +++ b/programs/drift/src/controller/position.rs @@ -24,19 +24,13 @@ use crate::validate; #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum PositionDirection { + #[default] Long, Short, } -impl Default for PositionDirection { - // UpOnly - fn default() -> Self { - PositionDirection::Long - } -} - impl PositionDirection { pub fn opposite(&self) -> Self { match self { diff --git a/programs/drift/src/controller/spot_balance.rs b/programs/drift/src/controller/spot_balance.rs index 0b6a7f00c..9503a6c08 100644 --- a/programs/drift/src/controller/spot_balance.rs +++ b/programs/drift/src/controller/spot_balance.rs @@ -90,7 +90,7 @@ pub fn update_spot_market_twap_stats( now, spot_market.historical_oracle_data.last_oracle_price_twap, spot_market.historical_oracle_data.last_oracle_price_twap_ts, - ONE_HOUR as i64, + ONE_HOUR, )?; let oracle_price_twap_5min = calculate_new_twap( diff --git a/programs/drift/src/controller/spot_balance/tests.rs b/programs/drift/src/controller/spot_balance/tests.rs index d22fdb6a9..2a95e0b30 100644 --- a/programs/drift/src/controller/spot_balance/tests.rs +++ b/programs/drift/src/controller/spot_balance/tests.rs @@ -819,7 +819,7 @@ fn check_fee_collection() { let amount = QUOTE_PRECISION / 4; update_spot_balances_and_cumulative_deposits_with_limits( - (amount / 2) as u128, + amount / 2, &SpotBalanceType::Borrow, &mut spot_market, &mut user, @@ -1188,7 +1188,7 @@ fn check_fee_collection_larger_nums() { let amount = 540510 * QUOTE_PRECISION; update_spot_balances( - amount as u128, + amount, &SpotBalanceType::Borrow, &mut spot_market, &mut user.spot_positions[1], @@ -1400,7 +1400,7 @@ fn attempt_borrow_with_massive_upnl() { ..AMM::default() }, unrealized_pnl_initial_asset_weight: 0, - unrealized_pnl_maintenance_asset_weight: SPOT_WEIGHT_PRECISION as u32, + unrealized_pnl_maintenance_asset_weight: SPOT_WEIGHT_PRECISION, margin_ratio_initial: 1000, //10x margin_ratio_maintenance: 500, //20x number_of_users_with_base: 1, @@ -1510,7 +1510,7 @@ fn attempt_borrow_with_massive_upnl() { let mut market = perp_market_map.get_ref_mut(&0).unwrap(); // assert_eq!(market.pnl_pool.scaled_balance, 960549500000); - market.unrealized_pnl_initial_asset_weight = SPOT_WEIGHT_PRECISION as u32; + market.unrealized_pnl_initial_asset_weight = SPOT_WEIGHT_PRECISION; drop(market); let MarginCalculation { diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index 512cd02e1..23cb6b0c1 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -3261,8 +3261,8 @@ pub fn handle_update_protocol_if_shares_transfer_config( Ok(()) } -pub fn handle_initialize_prelaunch_oracle<'info>( - ctx: Context>, +pub fn handle_initialize_prelaunch_oracle( + ctx: Context, params: PrelaunchOracleParams, ) -> Result<()> { let mut oracle = ctx.accounts.prelaunch_oracle.load_init()?; @@ -3280,8 +3280,8 @@ pub fn handle_initialize_prelaunch_oracle<'info>( Ok(()) } -pub fn handle_update_prelaunch_oracle_params<'info>( - ctx: Context>, +pub fn handle_update_prelaunch_oracle_params( + ctx: Context, params: PrelaunchOracleParams, ) -> Result<()> { let mut oracle = ctx.accounts.prelaunch_oracle.load_mut()?; @@ -3318,8 +3318,8 @@ pub fn handle_update_prelaunch_oracle_params<'info>( Ok(()) } -pub fn handle_delete_prelaunch_oracle<'info>( - ctx: Context>, +pub fn handle_delete_prelaunch_oracle( + ctx: Context, _perp_market_index: u16, ) -> Result<()> { let perp_market = ctx.accounts.perp_market.load()?; diff --git a/programs/drift/src/instructions/keeper.rs b/programs/drift/src/instructions/keeper.rs index ed4f8f03c..9e831ed42 100644 --- a/programs/drift/src/instructions/keeper.rs +++ b/programs/drift/src/instructions/keeper.rs @@ -141,19 +141,14 @@ pub fn handle_revert_fill<'info>(ctx: Context) -> Result<()> { Ok(()) } -#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, AnchorSerialize, AnchorDeserialize, PartialEq, Debug, Eq, Default)] pub enum SpotFulfillmentType { + #[default] SerumV3, Match, PhoenixV1, } -impl Default for SpotFulfillmentType { - fn default() -> Self { - SpotFulfillmentType::SerumV3 - } -} - #[access_control( fill_not_paused(&ctx.accounts.state) )] diff --git a/programs/drift/src/math/amm/tests.rs b/programs/drift/src/math/amm/tests.rs index 992e9eab7..4e594b8c8 100644 --- a/programs/drift/src/math/amm/tests.rs +++ b/programs/drift/src/math/amm/tests.rs @@ -458,7 +458,7 @@ fn calc_mark_std_tests() { update_amm_mark_std(&mut amm, now, PRICE_PRECISION_U64 * 23, 0).unwrap(); assert_eq!(amm.mark_std, 23000000); - amm.mark_std = PRICE_PRECISION_U64 as u64; + amm.mark_std = PRICE_PRECISION_U64; amm.last_mark_price_twap_ts = now - 60; update_amm_mark_std(&mut amm, now, PRICE_PRECISION_U64 * 2, 0).unwrap(); assert_eq!(amm.mark_std, 2000000); diff --git a/programs/drift/src/math/amm_spread/tests.rs b/programs/drift/src/math/amm_spread/tests.rs index 71a3f4066..d2e22ddae 100644 --- a/programs/drift/src/math/amm_spread/tests.rs +++ b/programs/drift/src/math/amm_spread/tests.rs @@ -272,7 +272,7 @@ mod test { // oracle retreat * skew that increases long spread last_oracle_reserve_price_spread_pct = BID_ASK_SPREAD_PRECISION_I64 / 20; //5% - last_oracle_conf_pct = (BID_ASK_SPREAD_PRECISION / 100) as u64; //1% + last_oracle_conf_pct = BID_ASK_SPREAD_PRECISION / 100; //1% total_fee_minus_distributions = QUOTE_PRECISION as i128; let (long_spread3, short_spread3) = calculate_spread( base_spread, @@ -961,7 +961,7 @@ mod test { // user long => bar < sqrt_k < qar => tqar < qar => peg < reserve_price let lscale = calculate_spread_leverage_scale( AMM_RESERVE_PRECISION * 1000, - (AMM_RESERVE_PRECISION * 9999 / 10000) as u128, + AMM_RESERVE_PRECISION * 9999 / 10000, 12 * PEG_PRECISION, BASE_PRECISION_I128, (12.1 * PRICE_PRECISION as f64) as u64, diff --git a/programs/drift/src/math/constants.rs b/programs/drift/src/math/constants.rs index c9c3f03ae..8155763c1 100644 --- a/programs/drift/src/math/constants.rs +++ b/programs/drift/src/math/constants.rs @@ -84,7 +84,7 @@ pub const AMM_TO_QUOTE_PRECISION_RATIO_I128: i128 = pub const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: u128 = AMM_RESERVE_PRECISION * PEG_PRECISION / QUOTE_PRECISION; // expo: 9 pub const QUOTE_TO_BASE_AMT_FUNDING_PRECISION: i128 = - (AMM_RESERVE_PRECISION_I128 * FUNDING_RATE_PRECISION_I128 / QUOTE_PRECISION_I128) as i128; // expo: 12 + AMM_RESERVE_PRECISION_I128 * FUNDING_RATE_PRECISION_I128 / QUOTE_PRECISION_I128; // expo: 12 pub const PRICE_TO_QUOTE_PRECISION_RATIO: u128 = PRICE_PRECISION / QUOTE_PRECISION; // expo: 1 pub const PRICE_TIMES_AMM_TO_QUOTE_PRECISION_RATIO: u128 = PRICE_PRECISION * AMM_TO_QUOTE_PRECISION_RATIO; // expo 9 @@ -139,9 +139,9 @@ pub const ONE_THOUSAND_QUOTE: u64 = 1_000_u64 * QUOTE_PRECISION_U64; pub const TWO_HUNDRED_FIFTY_QUOTE: u64 = 250_u64 * QUOTE_PRECISION_U64; // INSURANCE TIERS -pub const INSURANCE_A_MAX: u64 = ONE_HUNDRED_MILLION_QUOTE as u64; -pub const INSURANCE_B_MAX: u64 = ONE_MILLION_QUOTE as u64; -pub const INSURANCE_C_MAX: u64 = ONE_HUNDRED_THOUSAND_QUOTE as u64; +pub const INSURANCE_A_MAX: u64 = ONE_HUNDRED_MILLION_QUOTE; +pub const INSURANCE_B_MAX: u64 = ONE_MILLION_QUOTE; +pub const INSURANCE_C_MAX: u64 = ONE_HUNDRED_THOUSAND_QUOTE; pub const INSURANCE_SPECULATIVE_MAX: u64 = 0; // QUOTE THRESHOLDS @@ -177,8 +177,8 @@ pub const MAX_LIQUIDATION_SLIPPAGE: i128 = 10_000; // expo = -2 pub const MAX_LIQUIDATION_SLIPPAGE_U128: u128 = 10_000; // expo = -2 pub const MAX_MARK_TWAP_DIVERGENCE: u128 = 500_000; // expo = -3 -pub const MAX_MARGIN_RATIO: u32 = MARGIN_PRECISION as u32; // 1x leverage -pub const MIN_MARGIN_RATIO: u32 = MARGIN_PRECISION as u32 / 50; // 50x leverage +pub const MAX_MARGIN_RATIO: u32 = MARGIN_PRECISION; // 1x leverage +pub const MIN_MARGIN_RATIO: u32 = MARGIN_PRECISION / 50; // 50x leverage pub const MAX_BID_ASK_INVENTORY_SKEW_FACTOR: u64 = 10 * BID_ASK_SPREAD_PRECISION; @@ -188,7 +188,7 @@ pub const DEFAULT_MAX_TWAP_UPDATE_PRICE_BAND_DENOMINATOR: i64 = 3; // '3' here m // DEFAULTS pub const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: i64 = -25 * QUOTE_PRECISION_I64; //$25 loss pub const DEFAULT_LARGE_BID_ASK_FACTOR: u64 = 10 * BID_ASK_SPREAD_PRECISION; -pub const DEFAULT_LIQUIDATION_MARGIN_BUFFER_RATIO: u32 = (MARGIN_PRECISION as u32) / 50; // 2% +pub const DEFAULT_LIQUIDATION_MARGIN_BUFFER_RATIO: u32 = MARGIN_PRECISION / 50; // 2% pub const DEFAULT_BASE_ASSET_AMOUNT_STEP_SIZE: u64 = BASE_PRECISION_U64 / 10000; // 1e-4; pub const DEFAULT_QUOTE_ASSET_AMOUNT_TICK_SIZE: u64 = PRICE_PRECISION_U64 / DEFAULT_BASE_ASSET_AMOUNT_STEP_SIZE; // 1e-2 diff --git a/programs/drift/src/math/funding/tests.rs b/programs/drift/src/math/funding/tests.rs index ae3da9c86..a2eceb881 100644 --- a/programs/drift/src/math/funding/tests.rs +++ b/programs/drift/src/math/funding/tests.rs @@ -63,9 +63,9 @@ fn balanced_funding_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: sqrt_k as u128, - quote_asset_reserve: sqrt_k as u128, - sqrt_k: sqrt_k as u128, + 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, @@ -115,9 +115,9 @@ fn balanced_funding_test() { let mut market = PerpMarket { amm: AMM { - base_asset_reserve: sqrt_k as u128, - quote_asset_reserve: sqrt_k as u128, - sqrt_k: sqrt_k as u128, + 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, diff --git a/programs/drift/src/math/insurance.rs b/programs/drift/src/math/insurance.rs index 23e690ca4..d1bb78d7a 100644 --- a/programs/drift/src/math/insurance.rs +++ b/programs/drift/src/math/insurance.rs @@ -57,7 +57,7 @@ pub fn if_shares_to_vault_amount( get_proportion_u128( insurance_fund_vault_balance as u128, n_shares, - total_if_shares as u128, + total_if_shares, )? .cast::()? } else { diff --git a/programs/drift/src/math/liquidation/tests.rs b/programs/drift/src/math/liquidation/tests.rs index 86c5014a1..4c5fb40ca 100644 --- a/programs/drift/src/math/liquidation/tests.rs +++ b/programs/drift/src/math/liquidation/tests.rs @@ -9,7 +9,7 @@ mod calculate_base_asset_amount_to_cover_margin_shortage { #[test] pub fn zero_percent_liquidation_fee() { let margin_shortage = 10 * QUOTE_PRECISION; // $10 shortage - let margin_ratio = MARGIN_PRECISION as u32 / 10; // 10x leverage + let margin_ratio = MARGIN_PRECISION / 10; // 10x leverage let liquidation_fee = 0; // 0 percent let oracle_price = 100 * PRICE_PRECISION_I64; // $100 / base let base_asset_amount = calculate_base_asset_amount_to_cover_margin_shortage( @@ -28,7 +28,7 @@ mod calculate_base_asset_amount_to_cover_margin_shortage { #[test] pub fn usdc_not_one() { let margin_shortage = 10 * QUOTE_PRECISION; // $10 shortage - let margin_ratio = MARGIN_PRECISION as u32 / 10; // 10x leverage + let margin_ratio = MARGIN_PRECISION / 10; // 10x leverage let liquidation_fee = 0; // 0 percent let oracle_price = 100 * PRICE_PRECISION_I64; // $100 / base let quote_oracle_price = 99 * 10000; @@ -61,7 +61,7 @@ mod calculate_base_asset_amount_to_cover_margin_shortage { #[test] pub fn one_percent_liquidation_fee() { let margin_shortage = 10 * QUOTE_PRECISION; // $10 shortage - let margin_ratio = MARGIN_PRECISION as u32 / 10; // 10x leverage + let margin_ratio = MARGIN_PRECISION / 10; // 10x leverage let liquidation_fee = LIQUIDATION_FEE_PRECISION / 100; // 1 percent let oracle_price = 100 * PRICE_PRECISION_I64; // $100 / base let base_asset_amount = calculate_base_asset_amount_to_cover_margin_shortage( @@ -94,7 +94,7 @@ mod calculate_base_asset_amount_to_cover_margin_shortage { #[test] pub fn one_percent_liquidation_fee_and_one_percent_if_liquidation_fee() { let margin_shortage = 10 * QUOTE_PRECISION; // $10 shortage - let margin_ratio = MARGIN_PRECISION as u32 / 10; // 10x leverage + let margin_ratio = MARGIN_PRECISION / 10; // 10x leverage let liquidation_fee = LIQUIDATION_FEE_PRECISION / 100; // 1 percent let oracle_price = 100 * PRICE_PRECISION_I64; // $100 / base let if_liquidation_fee = LIQUIDATION_FEE_PRECISION / 100; // 1 percent diff --git a/programs/drift/src/math/margin/tests.rs b/programs/drift/src/math/margin/tests.rs index f638a0d46..5661b67fd 100644 --- a/programs/drift/src/math/margin/tests.rs +++ b/programs/drift/src/math/margin/tests.rs @@ -937,7 +937,7 @@ mod calculate_margin_requirement_and_total_collateral { ..PerpPosition::default() }), spot_positions, - max_margin_ratio: 2 * MARGIN_PRECISION as u32, // .5x leverage + max_margin_ratio: 2 * MARGIN_PRECISION, // .5x leverage ..User::default() }; @@ -955,7 +955,7 @@ mod calculate_margin_requirement_and_total_collateral { assert_eq!(margin_requirement, 50000000000); // 100 * $100 * 3 + 100 * $100 * 2 let user = User { - max_margin_ratio: MARGIN_PRECISION as u32, // 1x leverage + max_margin_ratio: MARGIN_PRECISION, // 1x leverage ..user }; @@ -973,7 +973,7 @@ mod calculate_margin_requirement_and_total_collateral { assert_eq!(margin_requirement, 30000000000); // 100 * 100 * 1 + 100 * $100 * 2 let user = User { - max_margin_ratio: MARGIN_PRECISION as u32 / 2, // 2x leverage + max_margin_ratio: MARGIN_PRECISION / 2, // 2x leverage ..user }; @@ -991,7 +991,7 @@ mod calculate_margin_requirement_and_total_collateral { assert_eq!(margin_requirement, 20000000000); // 100 * 100 * .5 + 100 * $100 * 1.5 let user = User { - max_margin_ratio: 10 * MARGIN_PRECISION as u32, // .1x leverage + max_margin_ratio: 10 * MARGIN_PRECISION, // .1x leverage ..user }; @@ -1021,7 +1021,7 @@ mod calculate_margin_requirement_and_total_collateral { let user = User { orders: [Order::default(); 32], spot_positions, - max_margin_ratio: MARGIN_PRECISION as u32 / 2, // 2x leverage + max_margin_ratio: MARGIN_PRECISION / 2, // 2x leverage ..User::default() }; @@ -1123,7 +1123,7 @@ mod calculate_margin_requirement_and_total_collateral { let user = User { orders: [Order::default(); 32], spot_positions, - max_margin_ratio: 2 * MARGIN_PRECISION as u32, // .5x leverage + max_margin_ratio: 2 * MARGIN_PRECISION, // .5x leverage ..User::default() }; @@ -1244,7 +1244,7 @@ mod calculate_margin_requirement_and_total_collateral { let user = User { orders: [Order::default(); 32], spot_positions, - max_margin_ratio: 2 * MARGIN_PRECISION as u32, // .5x leverage + max_margin_ratio: 2 * MARGIN_PRECISION, // .5x leverage ..User::default() }; diff --git a/programs/drift/src/math/oracle.rs b/programs/drift/src/math/oracle.rs index 10abacca6..65453471b 100644 --- a/programs/drift/src/math/oracle.rs +++ b/programs/drift/src/math/oracle.rs @@ -20,7 +20,7 @@ use std::fmt; mod tests; // ordered by "severity" -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum OracleValidity { Invalid, TooVolatile, @@ -28,15 +28,10 @@ pub enum OracleValidity { StaleForMargin, InsufficientDataPoints, StaleForAMM, + #[default] Valid, } -impl Default for OracleValidity { - fn default() -> Self { - OracleValidity::Valid - } -} - impl fmt::Display for OracleValidity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -172,9 +167,9 @@ pub struct OracleStatus { pub oracle_validity: OracleValidity, } -pub fn get_oracle_status<'a>( +pub fn get_oracle_status( market: &PerpMarket, - oracle_price_data: &'a OraclePriceData, + oracle_price_data: &OraclePriceData, guard_rails: &OracleGuardRails, precomputed_reserve_price: Option, ) -> DriftResult { diff --git a/programs/drift/src/math/orders/tests.rs b/programs/drift/src/math/orders/tests.rs index 4d19a3d82..767724fa1 100644 --- a/programs/drift/src/math/orders/tests.rs +++ b/programs/drift/src/math/orders/tests.rs @@ -139,7 +139,7 @@ mod order_breaches_oracle_price_limits { #[test] fn bid_does_not_breach() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x ..PerpMarket::default() }; @@ -169,7 +169,7 @@ mod order_breaches_oracle_price_limits { #[test] fn bid_does_not_breach_4_99_percent_move() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x ..PerpMarket::default() }; @@ -199,8 +199,8 @@ mod order_breaches_oracle_price_limits { #[test] fn bid_breaches() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x - margin_ratio_maintenance: (MARGIN_PRECISION / 20) as u32, // 20x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x + margin_ratio_maintenance: (MARGIN_PRECISION / 20), // 20x ..PerpMarket::default() }; @@ -231,8 +231,8 @@ mod order_breaches_oracle_price_limits { #[test] fn ask_does_not_breach() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x - margin_ratio_maintenance: (MARGIN_PRECISION / 20) as u32, // 20x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x + margin_ratio_maintenance: (MARGIN_PRECISION / 20), // 20x ..PerpMarket::default() }; @@ -263,8 +263,8 @@ mod order_breaches_oracle_price_limits { #[test] fn ask_does_not_breach_4_99_percent_move() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x - margin_ratio_maintenance: (MARGIN_PRECISION / 20) as u32, // 20x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x + margin_ratio_maintenance: (MARGIN_PRECISION / 20), // 20x ..PerpMarket::default() }; @@ -295,8 +295,8 @@ mod order_breaches_oracle_price_limits { #[test] fn ask_breaches() { let _market = PerpMarket { - margin_ratio_initial: (MARGIN_PRECISION / 10) as u32, // 10x - margin_ratio_maintenance: (MARGIN_PRECISION / 20) as u32, // 20x + margin_ratio_initial: (MARGIN_PRECISION / 10), // 10x + margin_ratio_maintenance: (MARGIN_PRECISION / 20), // 20x ..PerpMarket::default() }; diff --git a/programs/drift/src/state/events.rs b/programs/drift/src/state/events.rs index 6c0f7dde6..faa67b3ed 100644 --- a/programs/drift/src/state/events.rs +++ b/programs/drift/src/state/events.rs @@ -52,21 +52,15 @@ pub struct DepositRecord { pub transfer_user: Option, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum DepositExplanation { + #[default] None, Transfer, Borrow, RepayBorrow, } -impl Default for DepositExplanation { - // UpOnly - fn default() -> Self { - DepositExplanation::None - } -} - #[event] pub struct SpotInterestRecord { pub ts: i64, @@ -87,19 +81,13 @@ pub struct SpotInterestRecord { pub max_borrow_rate: u32, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum DepositDirection { + #[default] Deposit, Withdraw, } -impl Default for DepositDirection { - // UpOnly - fn default() -> Self { - DepositDirection::Deposit - } -} - #[event] pub struct FundingPaymentRecord { pub ts: i64, @@ -313,8 +301,9 @@ pub fn get_order_action_record( }) } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum OrderAction { + #[default] Place, Cancel, Fill, @@ -345,13 +334,6 @@ pub enum OrderActionExplanation { DeriskLp, } -impl Default for OrderAction { - // UpOnly - fn default() -> Self { - OrderAction::Place - } -} - #[event] #[derive(Default)] pub struct LPRecord { @@ -370,8 +352,9 @@ pub struct LPRecord { pub pnl: i64, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum LPAction { + #[default] AddLiquidity, RemoveLiquidity, SettleLiquidity, @@ -382,12 +365,6 @@ impl Size for LPRecord { const SIZE: usize = 112; } -impl Default for LPAction { - fn default() -> Self { - LPAction::AddLiquidity - } -} - #[event] #[derive(Default)] pub struct LiquidationRecord { @@ -409,8 +386,9 @@ pub struct LiquidationRecord { pub spot_bankruptcy: SpotBankruptcyRecord, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum LiquidationType { + #[default] LiquidatePerp, LiquidateSpot, LiquidateBorrowForPerpPnl, @@ -419,13 +397,6 @@ pub enum LiquidationType { SpotBankruptcy, } -impl Default for LiquidationType { - // UpOnly - fn default() -> Self { - LiquidationType::LiquidatePerp - } -} - #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct LiquidatePerpRecord { pub market_index: u16, @@ -508,19 +479,13 @@ pub struct SettlePnlRecord { pub explanation: SettlePnlExplanation, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum SettlePnlExplanation { + #[default] None, ExpiredPosition, } -impl Default for SettlePnlExplanation { - // UpOnly - fn default() -> Self { - SettlePnlExplanation::None - } -} - #[event] #[derive(Default)] pub struct InsuranceFundRecord { @@ -561,8 +526,9 @@ pub struct InsuranceFundStakeRecord { pub total_if_shares_after: u128, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] pub enum StakeAction { + #[default] Stake, UnstakeRequest, UnstakeCancelRequest, @@ -571,12 +537,6 @@ pub enum StakeAction { StakeTransfer, } -impl Default for StakeAction { - fn default() -> Self { - StakeAction::Stake - } -} - #[event] #[derive(Default)] pub struct SwapRecord { diff --git a/programs/drift/src/state/oracle.rs b/programs/drift/src/state/oracle.rs index 2ae958053..9461ab9ec 100644 --- a/programs/drift/src/state/oracle.rs +++ b/programs/drift/src/state/oracle.rs @@ -106,8 +106,9 @@ impl HistoricalIndexData { } } -#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Eq, PartialEq, Debug)] +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Eq, PartialEq, Debug, Default)] pub enum OracleSource { + #[default] Pyth, Switchboard, QuoteAsset, @@ -117,13 +118,6 @@ pub enum OracleSource { Prelaunch, } -impl Default for OracleSource { - // UpOnly - fn default() -> Self { - OracleSource::Pyth - } -} - #[derive(Default, Clone, Copy, Debug)] pub struct OraclePriceData { pub price: i64, diff --git a/programs/drift/src/state/order_params.rs b/programs/drift/src/state/order_params.rs index 0ae356615..7fd57a919 100644 --- a/programs/drift/src/state/order_params.rs +++ b/programs/drift/src/state/order_params.rs @@ -390,7 +390,7 @@ impl OrderParams { auction_start_price_offset = auction_start_price_offset.max(oracle_price_offset) }; - (auction_start_price_offset, oracle_price_offset as i64) + (auction_start_price_offset, oracle_price_offset) } else { let (auction_start_price_offset, auction_end_price_offset) = OrderParams::get_perp_baseline_start_end_price_offset(perp_market, direction, 1)?; @@ -642,20 +642,15 @@ fn get_auction_duration( .clamp(10, 180) as u8) // 180 slots max } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum PostOnlyParam { + #[default] None, MustPostOnly, // Tx fails if order can't be post only TryPostOnly, // Tx succeeds and order not placed if can't be post only Slide, // Modify price to be post only if can't be post only } -impl Default for PostOnlyParam { - fn default() -> Self { - PostOnlyParam::None - } -} - #[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] pub struct ModifyOrderParams { pub direction: Option, diff --git a/programs/drift/src/state/order_params/tests.rs b/programs/drift/src/state/order_params/tests.rs index debd82a2c..915dc7d0c 100644 --- a/programs/drift/src/state/order_params/tests.rs +++ b/programs/drift/src/state/order_params/tests.rs @@ -61,8 +61,8 @@ mod update_perp_auction_params { amm.last_bid_price_twap = (oracle_price - 192988) as u64; amm.last_mark_price_twap_5min = oracle_price as u64; amm.last_ask_price_twap = (oracle_price + 192988) as u64; - amm.historical_oracle_data.last_oracle_price_twap = oracle_price as i64; - amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price as i64; + amm.historical_oracle_data.last_oracle_price_twap = oracle_price; + amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price; amm.historical_oracle_data.last_oracle_price = oracle_price; let perp_market = PerpMarket { @@ -154,8 +154,8 @@ mod update_perp_auction_params { amm.last_bid_price_twap = (oracle_price * 15 / 10 - 192988) as u64; amm.last_mark_price_twap_5min = (oracle_price * 16 / 10) as u64; amm.last_ask_price_twap = (oracle_price * 16 / 10 + 192988) as u64; - amm.historical_oracle_data.last_oracle_price_twap = oracle_price as i64; - amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price as i64; + amm.historical_oracle_data.last_oracle_price_twap = oracle_price; + amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price; amm.historical_oracle_data.last_oracle_price = oracle_price; let perp_market = PerpMarket { @@ -199,8 +199,8 @@ mod update_perp_auction_params { amm.last_bid_price_twap = (oracle_price * 99 / 100) as u64; amm.last_mark_price_twap_5min = oracle_price as u64; amm.last_ask_price_twap = (oracle_price * 101 / 100) as u64; - amm.historical_oracle_data.last_oracle_price_twap = oracle_price as i64; - amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price as i64; + amm.historical_oracle_data.last_oracle_price_twap = oracle_price; + amm.historical_oracle_data.last_oracle_price_twap_5min = oracle_price; amm.historical_oracle_data.last_oracle_price = oracle_price; let perp_market = PerpMarket { diff --git a/programs/drift/src/state/paused_operations/tests.rs b/programs/drift/src/state/paused_operations/tests.rs index 53461505a..155b3e098 100644 --- a/programs/drift/src/state/paused_operations/tests.rs +++ b/programs/drift/src/state/paused_operations/tests.rs @@ -64,15 +64,15 @@ mod test { // Test with multiple operations let multiple_operations = PerpOperation::AmmFill as u8 | PerpOperation::SettlePnl as u8; assert!(PerpOperation::is_operation_paused( - multiple_operations as u8, + multiple_operations, PerpOperation::AmmFill )); assert!(PerpOperation::is_operation_paused( - multiple_operations as u8, + multiple_operations, PerpOperation::SettlePnl )); assert!(!PerpOperation::is_operation_paused( - multiple_operations as u8, + multiple_operations, PerpOperation::Fill )); } diff --git a/programs/drift/src/state/perp_market.rs b/programs/drift/src/state/perp_market.rs index 39b949c20..96cb41468 100644 --- a/programs/drift/src/state/perp_market.rs +++ b/programs/drift/src/state/perp_market.rs @@ -41,9 +41,10 @@ use static_assertions::const_assert_eq; #[cfg(test)] mod tests; -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum MarketStatus { /// warm up period for initialization, fills are paused + #[default] Initialized, /// all operations allowed Active, @@ -63,12 +64,6 @@ pub enum MarketStatus { Delisted, } -impl Default for MarketStatus { - fn default() -> Self { - MarketStatus::Initialized - } -} - impl MarketStatus { pub fn validate_not_deprecated(&self) -> DriftResult { if matches!( @@ -86,19 +81,16 @@ impl MarketStatus { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum ContractType { + #[default] Perpetual, Future, } -impl Default for ContractType { - fn default() -> Self { - ContractType::Perpetual - } -} - -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord)] +#[derive( + Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, +)] pub enum ContractTier { /// max insurance capped at A level A, @@ -109,16 +101,13 @@ pub enum ContractTier { /// no insurance Speculative, /// no insurance, another tranches below + #[default] HighlySpeculative, /// no insurance, only single position allowed Isolated, } impl ContractTier { - pub fn default() -> Self { - ContractTier::HighlySpeculative - } - pub fn is_as_safe_as(&self, best_contract: &ContractTier, best_asset: &AssetTier) -> bool { self.is_as_safe_as_contract(best_contract) && self.is_as_safe_as_asset(best_asset) } diff --git a/programs/drift/src/state/perp_market_map.rs b/programs/drift/src/state/perp_market_map.rs index 8193aca1d..4990ac95b 100644 --- a/programs/drift/src/state/perp_market_map.rs +++ b/programs/drift/src/state/perp_market_map.rs @@ -225,7 +225,7 @@ pub fn get_writable_perp_market_set(market_index: u16) -> MarketSet { writable_markets } -pub fn get_writable_perp_market_set_from_vec(market_indexes: &Vec) -> MarketSet { +pub fn get_writable_perp_market_set_from_vec(market_indexes: &[u16]) -> MarketSet { let mut writable_markets = MarketSet::new(); for market_index in market_indexes.iter() { writable_markets.insert(*market_index); diff --git a/programs/drift/src/state/settle_pnl_mode.rs b/programs/drift/src/state/settle_pnl_mode.rs index b0276edd4..edb64362d 100644 --- a/programs/drift/src/state/settle_pnl_mode.rs +++ b/programs/drift/src/state/settle_pnl_mode.rs @@ -25,12 +25,8 @@ impl SettlePnlMode { caller.line() ); match self { - SettlePnlMode::MustSettle => { - return Err(error_code); - } - SettlePnlMode::TrySettle => { - return Ok(()); - } + SettlePnlMode::MustSettle => Err(error_code), + SettlePnlMode::TrySettle => Ok(()), } } } diff --git a/programs/drift/src/state/spot_market.rs b/programs/drift/src/state/spot_market.rs index bd48ceb61..2eb1eb62a 100644 --- a/programs/drift/src/state/spot_market.rs +++ b/programs/drift/src/state/spot_market.rs @@ -545,8 +545,9 @@ impl SpotMarket { } } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Default)] pub enum SpotBalanceType { + #[default] Deposit, Borrow, } @@ -560,12 +561,6 @@ impl Display for SpotBalanceType { } } -impl Default for SpotBalanceType { - fn default() -> Self { - SpotBalanceType::Deposit - } -} - pub trait SpotBalance { fn market_index(&self) -> u16; @@ -580,19 +575,16 @@ pub trait SpotBalance { fn update_balance_type(&mut self, balance_type: SpotBalanceType) -> DriftResult; } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum SpotFulfillmentConfigStatus { + #[default] Enabled, Disabled, } -impl Default for SpotFulfillmentConfigStatus { - fn default() -> Self { - SpotFulfillmentConfigStatus::Enabled - } -} - -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord)] +#[derive( + Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, PartialOrd, Ord, Default, +)] pub enum AssetTier { /// full priviledge Collateral, @@ -603,15 +595,10 @@ pub enum AssetTier { /// not collateral, only single borrow Isolated, /// no privilege + #[default] Unlisted, } -impl Default for AssetTier { - fn default() -> Self { - AssetTier::Unlisted - } -} - #[zero_copy(unsafe)] #[derive(Default, Eq, PartialEq, Debug)] #[repr(C)] diff --git a/programs/drift/src/state/user.rs b/programs/drift/src/state/user.rs index bbefeb0d0..7b90a12b9 100644 --- a/programs/drift/src/state/user.rs +++ b/programs/drift/src/state/user.rs @@ -669,7 +669,7 @@ impl SpotPosition { token_amount: i128, open_orders: i128| { let order_value = get_token_value( - -open_orders as i128, + -open_orders, spot_market.decimals, strict_oracle_price.max(), )?; @@ -1336,9 +1336,10 @@ pub enum OrderStatus { Canceled, } -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum OrderType { Market, + #[default] Limit, TriggerMarket, TriggerLimit, @@ -1346,28 +1347,18 @@ pub enum OrderType { Oracle, } -impl Default for OrderType { - fn default() -> Self { - OrderType::Limit - } -} - -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq, Default)] pub enum OrderTriggerCondition { + #[default] Above, Below, TriggeredAbove, // above condition has been triggered TriggeredBelow, // below condition has been triggered } -impl Default for OrderTriggerCondition { - fn default() -> Self { - OrderTriggerCondition::Above - } -} - -#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] +#[derive(Default, Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Debug, Eq)] pub enum MarketType { + #[default] Spot, Perp, } @@ -1381,12 +1372,6 @@ impl fmt::Display for MarketType { } } -impl Default for MarketType { - fn default() -> Self { - MarketType::Spot - } -} - #[account(zero_copy(unsafe))] #[derive(Eq, PartialEq, Debug)] #[repr(C)] diff --git a/programs/drift/src/state/user/tests.rs b/programs/drift/src/state/user/tests.rs index 76ca508c7..5c4e0724b 100644 --- a/programs/drift/src/state/user/tests.rs +++ b/programs/drift/src/state/user/tests.rs @@ -237,7 +237,7 @@ mod get_claimable_pnl { ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (10 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (10 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -343,7 +343,7 @@ mod get_claimable_pnl { ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (60 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (60 * SPOT_BALANCE_PRECISION), market_index: QUOTE_SPOT_MARKET_INDEX, ..PoolBalance::default() }, @@ -494,7 +494,7 @@ mod get_claimable_pnl { ..AMM::default() }, pnl_pool: PoolBalance { - scaled_balance: (1000 * SPOT_BALANCE_PRECISION) as u128, + scaled_balance: (1000 * SPOT_BALANCE_PRECISION), market_index: 0, ..PoolBalance::default() }, diff --git a/programs/drift/src/validation/user.rs b/programs/drift/src/validation/user.rs index b25f94693..38edc0947 100644 --- a/programs/drift/src/validation/user.rs +++ b/programs/drift/src/validation/user.rs @@ -56,7 +56,7 @@ pub fn validate_user_deletion( if state.max_initialize_user_fee > 0 { let estimated_user_stats_age = user_stats.get_age_ts(now); - if estimated_user_stats_age < THIRTEEN_DAY as i64 { + if estimated_user_stats_age < THIRTEEN_DAY { validate!( user.idle, ErrorCode::UserCantBeDeleted, diff --git a/programs/pyth/src/lib.rs b/programs/pyth/src/lib.rs index 4cf313324..199249ce0 100644 --- a/programs/pyth/src/lib.rs +++ b/programs/pyth/src/lib.rs @@ -41,7 +41,7 @@ pub mod pyth { .unwrap() .checked_div(2) .unwrap(); //todo - price_oracle.agg.price = price as i64; + price_oracle.agg.price = price; Ok(()) } @@ -55,7 +55,7 @@ pub mod pyth { .unwrap() .checked_div(2) .unwrap(); //todo - price_oracle.agg.price = price as i64; + price_oracle.agg.price = price; price_oracle.agg.conf = conf; price_oracle.valid_slot = slot; diff --git a/programs/pyth/src/pc.rs b/programs/pyth/src/pc.rs index d7d3a624d..42cc61a6b 100644 --- a/programs/pyth/src/pc.rs +++ b/programs/pyth/src/pc.rs @@ -9,34 +9,24 @@ pub struct AccKey { pub val: [u8; 32], } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] #[repr(C)] #[allow(dead_code)] pub enum PriceStatus { Unknown, + #[default] Trading, Halted, Auction, } -impl Default for PriceStatus { - fn default() -> Self { - PriceStatus::Trading - } -} - -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] #[repr(C)] pub enum CorpAction { + #[default] NoCorpAct, } -impl Default for CorpAction { - fn default() -> Self { - CorpAction::NoCorpAct - } -} - #[derive(Default, Copy, Clone)] #[repr(C)] pub struct PriceInfo { @@ -54,22 +44,17 @@ pub struct PriceComp { latest: PriceInfo, } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, Default)] #[repr(C)] #[allow(dead_code, clippy::upper_case_acronyms)] pub enum PriceType { Unknown, + #[default] Price, TWAP, Volatility, } -impl Default for PriceType { - fn default() -> Self { - PriceType::Price - } -} - #[derive(Default, Copy, Clone)] #[repr(C)] pub struct Price { From 7c9dbede21ca4d1c254ddd7ff3c4c7a455970d99 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Mon, 10 Jun 2024 15:33:53 -0400 Subject: [PATCH 16/16] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0324b68a..4a237bfb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Breaking +- program: upgrade to anchor 0.29.0 and solana 1.16 + ## [2.83.0] - 2024-06-06 ### Features