From 28520ea8f3830040452255906732c77a8751e627 Mon Sep 17 00:00:00 2001 From: segfaultdoctor <17258903+segfaultdoc@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:51:57 -0500 Subject: [PATCH] lil cleanup (#111) --- example-programs/jito-protecc/Cargo.lock | 805 +++++++++++++----- .../programs/jito-protecc/Cargo.toml | 3 +- .../jito-protecc/jito-protecc/Cargo.toml | 20 - .../jito-protecc/jito-protecc/Xargo.toml | 2 - .../jito-protecc/jito-protecc/src/lib.rs | 216 ----- .../programs/jito-protecc/src/lib.rs | 207 ++++- .../{jito-protecc => }/src/sdk/mod.rs | 0 7 files changed, 800 insertions(+), 453 deletions(-) delete mode 100644 example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Cargo.toml delete mode 100644 example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Xargo.toml delete mode 100644 example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/lib.rs rename example-programs/jito-protecc/programs/jito-protecc/{jito-protecc => }/src/sdk/mod.rs (100%) diff --git a/example-programs/jito-protecc/Cargo.lock b/example-programs/jito-protecc/Cargo.lock index 2ba9f22..1be3ed0 100644 --- a/example-programs/jito-protecc/Cargo.lock +++ b/example-programs/jito-protecc/Cargo.lock @@ -2,6 +2,42 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aead" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" +dependencies = [ + "generic-array", +] + +[[package]] +name = "aes" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" +dependencies = [ + "cfg-if", + "cipher 0.3.0", + "cpufeatures", + "opaque-debug", +] + +[[package]] +name = "aes-gcm-siv" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589c637f0e68c877bbd59a4599bbe849cac8e5f3e4b5a3ebae8f528cd218dcdc" +dependencies = [ + "aead", + "aes", + "cipher 0.3.0", + "ctr", + "polyval", + "subtle", + "zeroize", +] + [[package]] name = "ahash" version = "0.7.6" @@ -147,6 +183,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "anchor-spl" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cc8066fbd45e0e03edf48342c79265aa34ca76cefeace48ef6c402b6946665" +dependencies = [ + "anchor-lang", + "solana-program", + "spl-associated-token-account", + "spl-token", + "spl-token-2022 0.5.0", +] + [[package]] name = "anchor-syn" version = "0.27.0" @@ -172,108 +221,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" [[package]] -name = "ark-bn254" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea691771ebbb28aea556c044e2e5c5227398d840cee0c34d4d20fa8eb2689e8c" -dependencies = [ - "ark-ec", - "ark-ff", - "ark-std", -] - -[[package]] -name = "ark-ec" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea978406c4b1ca13c2db2373b05cc55429c3575b8b21f1b9ee859aa5b03dd42" -dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", - "derivative", - "num-traits", - "zeroize", -] - -[[package]] -name = "ark-ff" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" -dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", - "derivative", - "num-bigint", - "num-traits", - "paste", - "rustc_version 0.3.3", - "zeroize", -] - -[[package]] -name = "ark-ff-asm" -version = "0.3.0" +name = "arrayref" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" -dependencies = [ - "quote", - "syn 1.0.109", -] +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] -name = "ark-ff-macros" -version = "0.3.0" +name = "arrayvec" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" -dependencies = [ - "num-bigint", - "num-traits", - "quote", - "syn 1.0.109", -] +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] -name = "ark-serialize" -version = "0.3.0" +name = "assert_matches" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" -dependencies = [ - "ark-std", - "digest 0.9.0", -] +checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] -name = "ark-std" -version = "0.3.0" +name = "atty" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "num-traits", - "rand 0.8.5", + "hermit-abi 0.1.19", + "libc", + "winapi", ] -[[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.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - [[package]] name = "autocfg" version = "1.1.0" @@ -318,9 +293,9 @@ dependencies = [ [[package]] name = "blake3" -version = "1.3.3" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ae2468a89544a466886840aa467a25b766499f4f04bf7d9fcd10ecee9fccef" +checksum = "a08e53fc5a564bb15bfe6fae56bd71522205f1f91893f9c0116edad6496c183f" dependencies = [ "arrayref", "arrayvec", @@ -373,7 +348,7 @@ checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" dependencies = [ "borsh-derive-internal", "borsh-schema-derive-internal", - "proc-macro-crate", + "proc-macro-crate 0.1.5", "proc-macro2", "syn 1.0.109", ] @@ -469,6 +444,34 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "num-traits", +] + +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -491,9 +494,9 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.2.5" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13418e745008f7349ec7e449155f419a61b92b58a99cc3616942b926825ec76b" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cpufeatures" @@ -534,7 +537,7 @@ dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", + "memoffset 0.8.0", "scopeguard", ] @@ -573,6 +576,15 @@ dependencies = [ "subtle", ] +[[package]] +name = "ctr" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "049bb91fb4aaf0e3c7efa6cd5ef877dbbbd15b39dad06d9948de4ec8a75761ea" +dependencies = [ + "cipher 0.3.0", +] + [[package]] name = "curve25519-dalek" version = "3.2.1" @@ -588,15 +600,10 @@ dependencies = [ ] [[package]] -name = "derivative" -version = "2.2.0" +name = "derivation-path" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] +checksum = "6e5c37193a1db1d8ed868c03ec7b152175f26160a5b740e5e484143877e0adf0" [[package]] name = "digest" @@ -618,18 +625,78 @@ dependencies = [ "subtle", ] +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "ed25519-dalek-bip32" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d2be62a4061b872c8c0873ee4fc6f101ce7b889d039f019c5fa2af471a59908" +dependencies = [ + "derivation-path", + "ed25519-dalek", + "hmac 0.12.1", + "sha2 0.10.6", +] + [[package]] name = "either" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "env_logger" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" +dependencies = [ + "atty", + "humantime", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "feature-probe" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835a3dc7d1ec9e75e2b5fb4ba75396837112d2060b03f7d43bc1897c7f7211da" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "generic-array" version = "0.14.7" @@ -685,6 +752,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "heck" version = "0.3.3" @@ -694,6 +767,15 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + [[package]] name = "hermit-abi" version = "0.2.6" @@ -713,6 +795,15 @@ dependencies = [ "digest 0.9.0", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.6", +] + [[package]] name = "hmac-drbg" version = "0.3.0" @@ -721,9 +812,15 @@ checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", "generic-array", - "hmac", + "hmac 0.8.1", ] +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + [[package]] name = "im" version = "15.1.0" @@ -740,6 +837,25 @@ dependencies = [ "version_check", ] +[[package]] +name = "indexmap" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[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.10.5" @@ -760,6 +876,7 @@ name = "jito-protecc" version = "0.1.0" dependencies = [ "anchor-lang", + "anchor-spl", ] [[package]] @@ -814,7 +931,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.7.3", + "rand", "serde", "sha2 0.9.9", "typenum", @@ -883,6 +1000,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.8.0" @@ -893,14 +1019,15 @@ dependencies = [ ] [[package]] -name = "num-bigint" -version = "0.4.3" +name = "merlin" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d" dependencies = [ - "autocfg", - "num-integer", - "num-traits", + "byteorder", + "keccak", + "rand_core 0.6.4", + "zeroize", ] [[package]] @@ -914,16 +1041,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "num-integer" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -939,10 +1056,31 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] +[[package]] +name = "num_enum" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "once_cell" version = "1.17.1" @@ -978,12 +1116,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - [[package]] name = "pbkdf2" version = "0.4.0" @@ -994,13 +1126,30 @@ dependencies = [ ] [[package]] -name = "pest" -version = "2.5.7" +name = "pbkdf2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1403e8401ad5dedea73c626b99758535b342502f8d1e361f4a2dd952749122" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" dependencies = [ - "thiserror", - "ucd-trie", + "digest 0.10.6", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "polyval" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8419d2b623c7c0896ff2d5d96e2cb4ede590fed28fcc34934f4c33c036e620a1" +dependencies = [ + "cfg-if", + "cpufeatures", + "opaque-debug", + "universal-hash", ] [[package]] @@ -1018,6 +1167,16 @@ dependencies = [ "toml", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.56" @@ -1027,6 +1186,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "qstring" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d464fae65fff2680baf48019211ce37aaec0c78e9264c84a3e484717f965104e" +dependencies = [ + "percent-encoding", +] + [[package]] name = "quote" version = "1.0.26" @@ -1044,21 +1212,11 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom 0.1.16", "libc", - "rand_chacha 0.2.2", + "rand_chacha", "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" @@ -1069,16 +1227,6 @@ 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" @@ -1169,22 +1317,13 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver 0.11.0", -] - [[package]] name = "rustc_version" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.17", + "semver", ] [[package]] @@ -1205,30 +1344,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "serde" version = "1.0.160" @@ -1293,6 +1414,18 @@ dependencies = [ "digest 0.10.6", ] +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer 0.9.0", + "digest 0.9.0", + "keccak", + "opaque-debug", +] + [[package]] name = "sha3" version = "0.10.7" @@ -1303,6 +1436,12 @@ dependencies = [ "keccak", ] +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + [[package]] name = "sized-chunks" version = "0.6.5" @@ -1321,9 +1460,9 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "solana-frozen-abi" -version = "1.15.2" +version = "1.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48f7051cccdf891ac2603cdd295eb651529fe2b678b6b3af60b82dec9a9b3b06" +checksum = "2623f65dae901566617eaf9255697c0fea8c012282e85ad86dd79c7133dff767" dependencies = [ "ahash", "blake3", @@ -1342,7 +1481,7 @@ dependencies = [ "memmap2", "once_cell", "rand_core 0.6.4", - "rustc_version 0.4.0", + "rustc_version", "serde", "serde_bytes", "serde_derive", @@ -1355,26 +1494,33 @@ dependencies = [ [[package]] name = "solana-frozen-abi-macro" -version = "1.15.2" +version = "1.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06395428329810ade1d2518a7e75d8a6f02d01fe548aabb60ff1ba6a2eaebbe5" +checksum = "0f90f630bb756af28f703c217fd5e14661dd5ec33cf2471276d0279130feba74" dependencies = [ "proc-macro2", "quote", - "rustc_version 0.4.0", + "rustc_version", "syn 1.0.109", ] +[[package]] +name = "solana-logger" +version = "1.14.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cadbbc900718637b8d0df476d71f3164d758058871007be52b94378db6025c0" +dependencies = [ + "env_logger", + "lazy_static", + "log", +] + [[package]] name = "solana-program" -version = "1.15.2" +version = "1.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ae9f0fa7db3a4e90fa0df2723ac8cbc042e579cf109cd0380bc5a8c88bed924" +checksum = "19350699312e8c6f92d56c899cb40e45e86d97815b26608ea9bde69648548e44" dependencies = [ - "ark-bn254", - "ark-ec", - "ark-ff", - "array-bytes", "base64 0.13.1", "bincode", "bitflags", @@ -1395,21 +1541,20 @@ dependencies = [ "libc", "libsecp256k1", "log", - "memoffset", - "num-bigint", + "memoffset 0.6.5", "num-derive", "num-traits", "parking_lot", - "rand 0.7.3", - "rand_chacha 0.2.2", - "rustc_version 0.4.0", + "rand", + "rand_chacha", + "rustc_version", "rustversion", "serde", "serde_bytes", "serde_derive", "serde_json", "sha2 0.10.6", - "sha3", + "sha3 0.10.7", "solana-frozen-abi", "solana-frozen-abi-macro", "solana-sdk-macro", @@ -1419,11 +1564,62 @@ dependencies = [ "zeroize", ] +[[package]] +name = "solana-sdk" +version = "1.14.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdde2c0b0e210fb013cbc0ecb73967ab77333e4304ce816a73cb258d4a2e1176" +dependencies = [ + "assert_matches", + "base64 0.13.1", + "bincode", + "bitflags", + "borsh", + "bs58 0.4.0", + "bytemuck", + "byteorder", + "chrono", + "derivation-path", + "digest 0.10.6", + "ed25519-dalek", + "ed25519-dalek-bip32", + "generic-array", + "hmac 0.12.1", + "itertools", + "js-sys", + "lazy_static", + "libsecp256k1", + "log", + "memmap2", + "num-derive", + "num-traits", + "pbkdf2 0.11.0", + "qstring", + "rand", + "rand_chacha", + "rustc_version", + "rustversion", + "serde", + "serde_bytes", + "serde_derive", + "serde_json", + "sha2 0.10.6", + "sha3 0.10.7", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "solana-logger", + "solana-program", + "solana-sdk-macro", + "thiserror", + "uriparse", + "wasm-bindgen", +] + [[package]] name = "solana-sdk-macro" -version = "1.15.2" +version = "1.14.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f809319358d5da7c3a0ac08ebf4d87b21170d928dbb7260254e8f3061f7f9e0e" +checksum = "42288b67d0f503ee6606777b3fb8ceeee7087ed7a8b3a0317edb1cd20d3d206b" dependencies = [ "bs58 0.4.0", "proc-macro2", @@ -1432,6 +1628,113 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "solana-zk-token-sdk" +version = "1.14.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af14aa817cf4aadef7488d6e3df9403f4ea0cb91c83b60bc0bb20d34a68d05f2" +dependencies = [ + "aes-gcm-siv", + "arrayref", + "base64 0.13.1", + "bincode", + "bytemuck", + "byteorder", + "cipher 0.4.4", + "curve25519-dalek", + "getrandom 0.1.16", + "itertools", + "lazy_static", + "merlin", + "num-derive", + "num-traits", + "rand", + "serde", + "serde_json", + "sha3 0.9.1", + "solana-program", + "solana-sdk", + "subtle", + "thiserror", + "zeroize", +] + +[[package]] +name = "spl-associated-token-account" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978dba3bcbe88d0c2c58366c254d9ea41c5f73357e72fc0bdee4d6b5fc99c8f4" +dependencies = [ + "assert_matches", + "borsh", + "num-derive", + "num-traits", + "solana-program", + "spl-token", + "spl-token-2022 0.6.1", + "thiserror", +] + +[[package]] +name = "spl-memo" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0dc6f70db6bacea7ff25870b016a65ba1d1b6013536f08e4fd79a8f9005325" +dependencies = [ + "solana-program", +] + +[[package]] +name = "spl-token" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e85e168a785e82564160dcb87b2a8e04cee9bfd1f4d488c729d53d6a4bd300d" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive", + "num-traits", + "num_enum", + "solana-program", + "thiserror", +] + +[[package]] +name = "spl-token-2022" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0edb869dbe159b018f17fb9bfa67118c30f232d7f54a73742bc96794dff77ed8" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive", + "num-traits", + "num_enum", + "solana-program", + "solana-zk-token-sdk", + "spl-memo", + "spl-token", + "thiserror", +] + +[[package]] +name = "spl-token-2022" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0043b590232c400bad5ee9eb983ced003d15163c4c5d56b090ac6d9a57457b47" +dependencies = [ + "arrayref", + "bytemuck", + "num-derive", + "num-traits", + "num_enum", + "solana-program", + "solana-zk-token-sdk", + "spl-memo", + "spl-token", + "thiserror", +] + [[package]] name = "subtle" version = "2.4.1" @@ -1460,6 +1763,15 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.40" @@ -1487,10 +1799,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffc59cb9dfc85bb312c3a78fd6aa8a8582e310b0fa885d5bb877f6dcc601839d" dependencies = [ "anyhow", - "hmac", + "hmac 0.8.1", "once_cell", - "pbkdf2", - "rand 0.7.3", + "pbkdf2 0.4.0", + "rand", "rustc-hash", "sha2 0.9.9", "thiserror", @@ -1524,16 +1836,27 @@ dependencies = [ ] [[package]] -name = "typenum" -version = "1.16.0" +name = "toml_datetime" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" [[package]] -name = "ucd-trie" -version = "0.1.5" +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "unicode-ident" @@ -1556,6 +1879,26 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" +[[package]] +name = "universal-hash" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "uriparse" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0200d0fc04d809396c2ad43f3c95da3582a2556eba8d453c1087f4120ee352ff" +dependencies = [ + "fnv", + "lazy_static", +] + [[package]] name = "version_check" version = "0.9.4" @@ -1638,6 +1981,37 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.45.0" @@ -1704,6 +2078,15 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "winnow" +version = "0.5.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2" +dependencies = [ + "memchr", +] + [[package]] name = "zeroize" version = "1.3.0" diff --git a/example-programs/jito-protecc/programs/jito-protecc/Cargo.toml b/example-programs/jito-protecc/programs/jito-protecc/Cargo.toml index 53f990f..a7a0f41 100644 --- a/example-programs/jito-protecc/programs/jito-protecc/Cargo.toml +++ b/example-programs/jito-protecc/programs/jito-protecc/Cargo.toml @@ -16,4 +16,5 @@ cpi = ["no-entrypoint"] default = [] [dependencies] -anchor-lang = "0.27.0" +anchor-lang = { version = "0.27.0", features = ["init-if-needed"] } +anchor-spl = {version = "0.27.0", features = ["token"]} diff --git a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Cargo.toml b/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Cargo.toml deleted file mode 100644 index a7a0f41..0000000 --- a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "jito-protecc" -version = "0.1.0" -description = "Created with Anchor" -edition = "2021" - -[lib] -crate-type = ["cdylib", "lib"] -name = "jito_protecc" - -[features] -no-entrypoint = [] -no-idl = [] -no-log-ix-name = [] -cpi = ["no-entrypoint"] -default = [] - -[dependencies] -anchor-lang = { version = "0.27.0", features = ["init-if-needed"] } -anchor-spl = {version = "0.27.0", features = ["token"]} diff --git a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Xargo.toml b/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Xargo.toml deleted file mode 100644 index 475fb71..0000000 --- a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.bpfel-unknown-unknown.dependencies.std] -features = [] diff --git a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/lib.rs b/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/lib.rs deleted file mode 100644 index 0a1377e..0000000 --- a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/lib.rs +++ /dev/null @@ -1,216 +0,0 @@ -pub mod sdk; - -use std::mem::size_of; - -use anchor_lang::prelude::*; -use anchor_spl::token::TokenAccount; - -declare_id!("B7XTCnuyLmbhea4KzhzgPN2JidbeTtTogBCk2M3vDSKf"); - -/// The pre/post guard instructions should be separate transactions or instructions wrapping the inner contents of a bundle or transaction. -#[program] -pub mod jito_protecc { - use super::*; - - pub fn close_sol_guarded_state(_ctx: Context) -> Result<()> { - Ok(()) - } - - pub fn pre_sol_guard(ctx: Context, bump: u8) -> Result<()> { - let sol_guarded_state = &mut ctx.accounts.sol_guarded_state; - sol_guarded_state.pre_balance = ctx.accounts.guarded_account.lamports(); - sol_guarded_state.bump = bump; - - Ok(()) - } - - pub fn post_sol_guard(ctx: Context) -> Result<()> { - if ctx.accounts.guarded_account.lamports() < ctx.accounts.sol_guarded_state.pre_balance { - Err(Error::AnchorError(AnchorError { - error_name: "sol guard failure".to_string(), - error_code_number: 69, - error_msg: format!( - "negative balance change: pre_balance: {}, post_balance: {}", - ctx.accounts.sol_guarded_state.pre_balance, - ctx.accounts.guarded_account.lamports(), - ), - error_origin: None, - compared_values: None, - })) - } else { - Ok(()) - } - } - - pub fn close_token_guarded_state(_ctx: Context) -> Result<()> { - Ok(()) - } - - pub fn pre_token_guard(ctx: Context, bump: u8) -> Result<()> { - let token_guarded_state = &mut ctx.accounts.token_guarded_state; - token_guarded_state.pre_balance = ctx.accounts.token_account.amount; - token_guarded_state.bump = bump; - - Ok(()) - } - - pub fn post_token_guard(ctx: Context) -> Result<()> { - if ctx.accounts.token_account.amount < ctx.accounts.token_guarded_state.pre_balance { - Err(Error::AnchorError(AnchorError { - error_name: "spl_token_state guard failure".to_string(), - error_code_number: 69, - error_msg: format!( - "negative balance change: pre_balance: {}, post_balance: {}", - ctx.accounts.token_guarded_state.pre_balance, ctx.accounts.token_account.amount, - ), - error_origin: None, - compared_values: None, - })) - } else { - Ok(()) - } - } -} - -#[derive(Accounts)] -pub struct CloseTokenGuardedState<'info> { - #[account( - mut, - seeds = [ - GuardedState::SEED, - token_account.key().as_ref(), - signer.key().as_ref(), - ], - bump = token_guarded_state.bump, - close = signer - )] - pub token_guarded_state: Account<'info, GuardedState>, - - pub token_account: Account<'info, TokenAccount>, - - /// Anyone can crank this instruction. - #[account(mut)] - pub signer: Signer<'info>, -} - -#[derive(Accounts)] -pub struct CloseSolGuardedState<'info> { - /// CHECK: We just care about the account's lamports. - pub guarded_account: AccountInfo<'info>, - - #[account( - mut, - seeds = [ - GuardedState::SEED, - guarded_account.key().as_ref(), - signer.key().as_ref(), - ], - bump = sol_guarded_state.bump, - close = signer - )] - pub sol_guarded_state: Account<'info, GuardedState>, - - /// Anyone can crank this instruction. - #[account(mut)] - pub signer: Signer<'info>, -} - -#[derive(Accounts)] -pub struct PreTokenGuard<'info> { - #[account( - init_if_needed, - seeds = [ - GuardedState::SEED, - token_account.key().as_ref(), - signer.key().as_ref(), - ], - bump, - space = GuardedState::SIZE, - payer = signer - )] - pub token_guarded_state: Account<'info, GuardedState>, - - pub token_account: Account<'info, TokenAccount>, - - #[account(mut)] - pub signer: Signer<'info>, - - pub system_program: Program<'info, System>, -} - -#[derive(Accounts)] -pub struct PreSolGuard<'info> { - /// CHECK: We just care about the account's lamports. - pub guarded_account: AccountInfo<'info>, - - #[account( - init_if_needed, - seeds = [ - GuardedState::SEED, - guarded_account.key().as_ref(), - signer.key().as_ref(), - ], - bump, - space = GuardedState::SIZE, - payer = signer - )] - pub sol_guarded_state: Account<'info, GuardedState>, - - #[account(mut)] - pub signer: Signer<'info>, - - pub system_program: Program<'info, System>, -} - -#[derive(Accounts)] -pub struct PostTokenGuard<'info> { - #[account( - mut, - seeds = [ - GuardedState::SEED, - token_account.key().as_ref(), - signer.key().as_ref(), - ], - bump = token_guarded_state.bump, - close = signer - )] - pub token_guarded_state: Account<'info, GuardedState>, - - pub token_account: Account<'info, TokenAccount>, - - #[account(mut)] - pub signer: Signer<'info>, -} - -#[derive(Accounts)] -pub struct PostSolGuard<'info> { - /// CHECK: We just care about the account's lamports. - pub guarded_account: AccountInfo<'info>, - - #[account( - mut, - seeds = [ - GuardedState::SEED, - guarded_account.key().as_ref(), - signer.key().as_ref(), - ], - bump = sol_guarded_state.bump, - close = signer - )] - pub sol_guarded_state: Account<'info, GuardedState>, - - #[account(mut)] - pub signer: Signer<'info>, -} - -#[account] -#[derive(Default)] -pub struct GuardedState { - pub pre_balance: u64, - pub bump: u8, -} - -impl GuardedState { - pub const SEED: &'static [u8] = b"GUARDED_STATE"; - pub const SIZE: usize = 8 + size_of::(); -} diff --git a/example-programs/jito-protecc/programs/jito-protecc/src/lib.rs b/example-programs/jito-protecc/programs/jito-protecc/src/lib.rs index 7a886a0..0a1377e 100644 --- a/example-programs/jito-protecc/programs/jito-protecc/src/lib.rs +++ b/example-programs/jito-protecc/programs/jito-protecc/src/lib.rs @@ -1,15 +1,216 @@ +pub mod sdk; + +use std::mem::size_of; + use anchor_lang::prelude::*; +use anchor_spl::token::TokenAccount; -declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); +declare_id!("B7XTCnuyLmbhea4KzhzgPN2JidbeTtTogBCk2M3vDSKf"); +/// The pre/post guard instructions should be separate transactions or instructions wrapping the inner contents of a bundle or transaction. #[program] pub mod jito_protecc { use super::*; - pub fn initialize(_ctx: Context) -> Result<()> { + pub fn close_sol_guarded_state(_ctx: Context) -> Result<()> { + Ok(()) + } + + pub fn pre_sol_guard(ctx: Context, bump: u8) -> Result<()> { + let sol_guarded_state = &mut ctx.accounts.sol_guarded_state; + sol_guarded_state.pre_balance = ctx.accounts.guarded_account.lamports(); + sol_guarded_state.bump = bump; + + Ok(()) + } + + pub fn post_sol_guard(ctx: Context) -> Result<()> { + if ctx.accounts.guarded_account.lamports() < ctx.accounts.sol_guarded_state.pre_balance { + Err(Error::AnchorError(AnchorError { + error_name: "sol guard failure".to_string(), + error_code_number: 69, + error_msg: format!( + "negative balance change: pre_balance: {}, post_balance: {}", + ctx.accounts.sol_guarded_state.pre_balance, + ctx.accounts.guarded_account.lamports(), + ), + error_origin: None, + compared_values: None, + })) + } else { + Ok(()) + } + } + + pub fn close_token_guarded_state(_ctx: Context) -> Result<()> { + Ok(()) + } + + pub fn pre_token_guard(ctx: Context, bump: u8) -> Result<()> { + let token_guarded_state = &mut ctx.accounts.token_guarded_state; + token_guarded_state.pre_balance = ctx.accounts.token_account.amount; + token_guarded_state.bump = bump; + Ok(()) } + + pub fn post_token_guard(ctx: Context) -> Result<()> { + if ctx.accounts.token_account.amount < ctx.accounts.token_guarded_state.pre_balance { + Err(Error::AnchorError(AnchorError { + error_name: "spl_token_state guard failure".to_string(), + error_code_number: 69, + error_msg: format!( + "negative balance change: pre_balance: {}, post_balance: {}", + ctx.accounts.token_guarded_state.pre_balance, ctx.accounts.token_account.amount, + ), + error_origin: None, + compared_values: None, + })) + } else { + Ok(()) + } + } } #[derive(Accounts)] -pub struct Initialize {} +pub struct CloseTokenGuardedState<'info> { + #[account( + mut, + seeds = [ + GuardedState::SEED, + token_account.key().as_ref(), + signer.key().as_ref(), + ], + bump = token_guarded_state.bump, + close = signer + )] + pub token_guarded_state: Account<'info, GuardedState>, + + pub token_account: Account<'info, TokenAccount>, + + /// Anyone can crank this instruction. + #[account(mut)] + pub signer: Signer<'info>, +} + +#[derive(Accounts)] +pub struct CloseSolGuardedState<'info> { + /// CHECK: We just care about the account's lamports. + pub guarded_account: AccountInfo<'info>, + + #[account( + mut, + seeds = [ + GuardedState::SEED, + guarded_account.key().as_ref(), + signer.key().as_ref(), + ], + bump = sol_guarded_state.bump, + close = signer + )] + pub sol_guarded_state: Account<'info, GuardedState>, + + /// Anyone can crank this instruction. + #[account(mut)] + pub signer: Signer<'info>, +} + +#[derive(Accounts)] +pub struct PreTokenGuard<'info> { + #[account( + init_if_needed, + seeds = [ + GuardedState::SEED, + token_account.key().as_ref(), + signer.key().as_ref(), + ], + bump, + space = GuardedState::SIZE, + payer = signer + )] + pub token_guarded_state: Account<'info, GuardedState>, + + pub token_account: Account<'info, TokenAccount>, + + #[account(mut)] + pub signer: Signer<'info>, + + pub system_program: Program<'info, System>, +} + +#[derive(Accounts)] +pub struct PreSolGuard<'info> { + /// CHECK: We just care about the account's lamports. + pub guarded_account: AccountInfo<'info>, + + #[account( + init_if_needed, + seeds = [ + GuardedState::SEED, + guarded_account.key().as_ref(), + signer.key().as_ref(), + ], + bump, + space = GuardedState::SIZE, + payer = signer + )] + pub sol_guarded_state: Account<'info, GuardedState>, + + #[account(mut)] + pub signer: Signer<'info>, + + pub system_program: Program<'info, System>, +} + +#[derive(Accounts)] +pub struct PostTokenGuard<'info> { + #[account( + mut, + seeds = [ + GuardedState::SEED, + token_account.key().as_ref(), + signer.key().as_ref(), + ], + bump = token_guarded_state.bump, + close = signer + )] + pub token_guarded_state: Account<'info, GuardedState>, + + pub token_account: Account<'info, TokenAccount>, + + #[account(mut)] + pub signer: Signer<'info>, +} + +#[derive(Accounts)] +pub struct PostSolGuard<'info> { + /// CHECK: We just care about the account's lamports. + pub guarded_account: AccountInfo<'info>, + + #[account( + mut, + seeds = [ + GuardedState::SEED, + guarded_account.key().as_ref(), + signer.key().as_ref(), + ], + bump = sol_guarded_state.bump, + close = signer + )] + pub sol_guarded_state: Account<'info, GuardedState>, + + #[account(mut)] + pub signer: Signer<'info>, +} + +#[account] +#[derive(Default)] +pub struct GuardedState { + pub pre_balance: u64, + pub bump: u8, +} + +impl GuardedState { + pub const SEED: &'static [u8] = b"GUARDED_STATE"; + pub const SIZE: usize = 8 + size_of::(); +} diff --git a/example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/sdk/mod.rs b/example-programs/jito-protecc/programs/jito-protecc/src/sdk/mod.rs similarity index 100% rename from example-programs/jito-protecc/programs/jito-protecc/jito-protecc/src/sdk/mod.rs rename to example-programs/jito-protecc/programs/jito-protecc/src/sdk/mod.rs