diff --git a/Cargo.lock b/Cargo.lock index 41b7a03..44894c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -250,7 +250,7 @@ dependencies = [ "borsh 0.10.4", "bytemuck", "getrandom 0.2.15", - "solana-program", + "solana-program 1.18.26", "thiserror", ] @@ -1208,7 +1208,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "279a4314e755fb311d9e2dd6503fdc023f9c833ddceb158565b95b9323f5fd10" dependencies = [ - "solana-program", + "solana-program 1.18.26", ] [[package]] @@ -2342,7 +2342,7 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jito-account-traits-derive" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "proc-macro2", "quote", @@ -2352,24 +2352,24 @@ dependencies = [ [[package]] name = "jito-bytemuck" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "bytemuck", "jito-account-traits-derive", - "solana-program", + "solana-program 1.18.26", ] [[package]] name = "jito-jsm-core" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "bytemuck", "jito-bytemuck", "shank", - "solana-program", + "solana-program 1.18.26", "spl-associated-token-account", "spl-token", "spl-token-2022 3.0.4", @@ -2379,7 +2379,7 @@ dependencies = [ [[package]] name = "jito-restaking-client" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "anchor-lang", "borsh 0.10.4", @@ -2388,7 +2388,7 @@ dependencies = [ "num-traits", "serde", "serde_with 3.11.0", - "solana-program", + "solana-program 1.18.26", "solana-sdk", "thiserror", ] @@ -2396,7 +2396,7 @@ dependencies = [ [[package]] name = "jito-restaking-core" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "bytemuck", @@ -2404,7 +2404,7 @@ dependencies = [ "jito-jsm-core", "jito-restaking-sdk", "shank", - "solana-program", + "solana-program 1.18.26", "spl-associated-token-account", "spl-token", "thiserror", @@ -2413,7 +2413,7 @@ dependencies = [ [[package]] name = "jito-restaking-program" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "cfg-if", @@ -2424,7 +2424,7 @@ dependencies = [ "jito-restaking-sdk", "jito-vault-core", "shank", - "solana-program", + "solana-program 1.18.26", "solana-security-txt", "spl-associated-token-account", "spl-token", @@ -2435,11 +2435,11 @@ dependencies = [ [[package]] name = "jito-restaking-sdk" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "shank", - "solana-program", + "solana-program 1.18.26", "thiserror", ] @@ -2462,7 +2462,7 @@ dependencies = [ "log", "solana-account-decoder", "solana-cli-config", - "solana-program", + "solana-program 1.18.26", "solana-rpc-client", "solana-rpc-client-api", "solana-sdk", @@ -2483,7 +2483,7 @@ dependencies = [ "num-traits", "serde", "serde_with 3.11.0", - "solana-program", + "solana-program 1.18.26", "solana-sdk", "thiserror", ] @@ -2502,8 +2502,9 @@ dependencies = [ "jito-vault-core", "jito-vault-sdk", "shank", - "solana-program", + "solana-program 1.18.26", "spl-associated-token-account", + "spl-math", "spl-token", "thiserror", ] @@ -2526,7 +2527,7 @@ dependencies = [ "jito-vault-sdk", "log", "shank", - "solana-program", + "solana-program 1.18.26", "solana-program-test", "solana-sdk", "solana-security-txt", @@ -2554,7 +2555,7 @@ dependencies = [ "jito-vault-core", "jito-vault-sdk", "shank", - "solana-program", + "solana-program 1.18.26", "solana-security-txt", "spl-associated-token-account", "spl-token", @@ -2577,7 +2578,7 @@ dependencies = [ [[package]] name = "jito-vault-client" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "anchor-lang", "borsh 0.10.4", @@ -2586,7 +2587,7 @@ dependencies = [ "num-traits", "serde", "serde_with 3.11.0", - "solana-program", + "solana-program 1.18.26", "solana-sdk", "thiserror", ] @@ -2594,7 +2595,7 @@ dependencies = [ [[package]] name = "jito-vault-core" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "bytemuck", @@ -2602,7 +2603,7 @@ dependencies = [ "jito-jsm-core", "jito-vault-sdk", "shank", - "solana-program", + "solana-program 1.18.26", "spl-associated-token-account", "spl-token", "spl-token-2022 3.0.4", @@ -2612,7 +2613,7 @@ dependencies = [ [[package]] name = "jito-vault-program" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "cfg-if", @@ -2623,7 +2624,7 @@ dependencies = [ "jito-vault-core", "jito-vault-sdk", "shank", - "solana-program", + "solana-program 1.18.26", "solana-security-txt", "spl-associated-token-account", "spl-token", @@ -2634,11 +2635,11 @@ dependencies = [ [[package]] name = "jito-vault-sdk" version = "0.0.3" -source = "git+https://github.com/jito-foundation/restaking.git#6dab154dbf8a60176a0b510aa74f17140288496e" +source = "git+https://github.com/jito-foundation/restaking.git?rev=eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d#eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" dependencies = [ "borsh 0.10.4", "shank", - "solana-program", + "solana-program 1.18.26", "spl-token", "thiserror", ] @@ -4442,7 +4443,7 @@ dependencies = [ "serde", "solana-frozen-abi", "solana-frozen-abi-macro", - "solana-program", + "solana-program 1.18.26", "solana-program-runtime", "solana-sdk", "thiserror", @@ -4457,7 +4458,7 @@ dependencies = [ "borsh 1.5.1", "futures", "solana-banks-interface", - "solana-program", + "solana-program 1.18.26", "solana-sdk", "tarpc", "thiserror", @@ -4860,13 +4861,59 @@ dependencies = [ "sha3 0.10.8", "solana-frozen-abi", "solana-frozen-abi-macro", - "solana-sdk-macro", + "solana-sdk-macro 1.18.26", "thiserror", "tiny-bip39", "wasm-bindgen", "zeroize", ] +[[package]] +name = "solana-program" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2625a23c3813b620141ee447819b08d1b9a5f1c69a309754834e3f35798a21fb" +dependencies = [ + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-serialize", + "base64 0.22.1", + "bincode", + "bitflags 2.6.0", + "blake3", + "borsh 0.10.4", + "borsh 1.5.1", + "bs58 0.5.1", + "bv", + "bytemuck", + "bytemuck_derive", + "console_error_panic_hook", + "console_log", + "curve25519-dalek", + "getrandom 0.2.15", + "js-sys", + "lazy_static", + "libsecp256k1", + "log", + "memoffset 0.9.1", + "num-bigint 0.4.6", + "num-derive 0.4.2", + "num-traits", + "parking_lot", + "rand 0.8.5", + "rustc_version", + "rustversion", + "serde", + "serde_bytes", + "serde_derive", + "sha2 0.10.8", + "sha3 0.10.8", + "solana-sdk-macro 2.0.14", + "thiserror", + "wasm-bindgen", +] + [[package]] name = "solana-program-runtime" version = "1.18.26" @@ -5192,8 +5239,8 @@ dependencies = [ "solana-frozen-abi", "solana-frozen-abi-macro", "solana-logger", - "solana-program", - "solana-sdk-macro", + "solana-program 1.18.26", + "solana-sdk-macro 1.18.26", "thiserror", "uriparse", "wasm-bindgen", @@ -5212,6 +5259,19 @@ dependencies = [ "syn 2.0.85", ] +[[package]] +name = "solana-sdk-macro" +version = "2.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93a5a1eabc890415d326707afe62cd7a2009236e8d899c1519566fc8f7e3977b" +dependencies = [ + "bs58 0.5.1", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.85", +] + [[package]] name = "solana-security-txt" version = "1.1.1" @@ -5426,7 +5486,7 @@ dependencies = [ "solana-frozen-abi", "solana-frozen-abi-macro", "solana-metrics", - "solana-program", + "solana-program 1.18.26", "solana-program-runtime", "solana-sdk", "thiserror", @@ -5468,7 +5528,7 @@ dependencies = [ "serde", "serde_json", "sha3 0.9.1", - "solana-program", + "solana-program 1.18.26", "solana-sdk", "subtle", "thiserror", @@ -5526,7 +5586,7 @@ dependencies = [ "borsh 0.10.4", "num-derive 0.4.2", "num-traits", - "solana-program", + "solana-program 1.18.26", "spl-token", "spl-token-2022 1.0.0", "thiserror", @@ -5539,7 +5599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cce5d563b58ef1bb2cdbbfe0dfb9ffdc24903b10ae6a4df2d8f425ece375033f" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator-derive 0.1.2", ] @@ -5550,7 +5610,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "210101376962bb22bb13be6daea34656ea1cbc248fce2164b146e39203b55e03" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator-derive 0.2.0", ] @@ -5602,13 +5662,27 @@ dependencies = [ "thiserror", ] +[[package]] +name = "spl-math" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc5a6cc7a4f0cf7813ce44153bba73280909f697d7f6baf7b9f223a255e7887" +dependencies = [ + "borsh 1.5.1", + "num-derive 0.4.2", + "num-traits", + "solana-program 2.0.14", + "thiserror", + "uint", +] + [[package]] name = "spl-memo" version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f180b03318c3dbab3ef4e1e4d46d5211ae3c780940dd0a28695aba4b59a75a" dependencies = [ - "solana-program", + "solana-program 1.18.26", ] [[package]] @@ -5619,7 +5693,7 @@ checksum = "2881dddfca792737c0706fa0175345ab282b1b0879c7d877bad129645737c079" dependencies = [ "borsh 0.10.4", "bytemuck", - "solana-program", + "solana-program 1.18.26", "solana-zk-token-sdk", "spl-program-error 0.3.0", ] @@ -5632,7 +5706,7 @@ checksum = "c52d84c55efeef8edcc226743dc089d7e3888b8e3474569aa3eff152b37b9996" dependencies = [ "borsh 1.5.1", "bytemuck", - "solana-program", + "solana-program 1.18.26", "solana-zk-token-sdk", "spl-program-error 0.4.4", ] @@ -5645,7 +5719,7 @@ checksum = "249e0318493b6bcf27ae9902600566c689b7dfba9f1bdff5893e92253374e78c" dependencies = [ "num-derive 0.4.2", "num-traits", - "solana-program", + "solana-program 1.18.26", "spl-program-error-derive 0.3.2", "thiserror", ] @@ -5658,7 +5732,7 @@ checksum = "e45a49acb925db68aa501b926096b2164adbdcade7a0c24152af9f0742d0a602" dependencies = [ "num-derive 0.4.2", "num-traits", - "solana-program", + "solana-program 1.18.26", "spl-program-error-derive 0.4.1", "thiserror", ] @@ -5694,7 +5768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "615d381f48ddd2bb3c57c7f7fb207591a2a05054639b18a62e785117dd7a8683" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5708,7 +5782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fab8edfd37be5fa17c9e42c1bff86abbbaf0494b031b37957f2728ad2ff842ba" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5726,7 +5800,7 @@ dependencies = [ "num-derive 0.3.3", "num-traits", "num_enum 0.6.1", - "solana-program", + "solana-program 1.18.26", "thiserror", ] @@ -5741,7 +5815,7 @@ dependencies = [ "num-derive 0.4.2", "num-traits", "num_enum 0.7.3", - "solana-program", + "solana-program 1.18.26", "solana-security-txt", "solana-zk-token-sdk", "spl-memo", @@ -5765,7 +5839,7 @@ dependencies = [ "num-derive 0.4.2", "num-traits", "num_enum 0.7.3", - "solana-program", + "solana-program 1.18.26", "solana-security-txt", "solana-zk-token-sdk", "spl-memo", @@ -5785,7 +5859,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b889509d49fa74a4a033ca5dae6c2307e9e918122d97e58562f5c4ffa795c75d" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5798,7 +5872,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "014817d6324b1e20c4bbc883e8ee30a5faa13e59d91d1b2b95df98b920150c17" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5811,7 +5885,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c16ce3ba6979645fb7627aa1e435576172dd63088dc7848cb09aa331fa1fe4f" dependencies = [ "borsh 0.10.4", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5825,7 +5899,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3da00495b602ebcf5d8ba8b3ecff1ee454ce4c125c9077747be49c2d62335ba" dependencies = [ "borsh 1.5.1", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5840,7 +5914,7 @@ checksum = "7aabdb7c471566f6ddcee724beb8618449ea24b399e58d464d6b5bc7db550259" dependencies = [ "arrayref", "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5856,7 +5930,7 @@ checksum = "a9b5c08a89838e5a2931f79b17f611857f281a14a2100968a3ccef352cb7414b" dependencies = [ "arrayref", "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -5871,7 +5945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a468e6f6371f9c69aae760186ea9f1a01c2908351b06a5e0026d21cfc4d7ecac" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.1.0", "spl-pod 0.1.0", "spl-program-error 0.3.0", @@ -5884,7 +5958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c872f93d0600e743116501eba2d53460e73a12c9a496875a42a7d70e034fe06d" dependencies = [ "bytemuck", - "solana-program", + "solana-program 1.18.26", "spl-discriminator 0.2.5", "spl-pod 0.2.5", "spl-program-error 0.4.4", @@ -6497,6 +6571,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "uint" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unicode-bidi" version = "0.3.17" diff --git a/Cargo.toml b/Cargo.toml index 3fa60d6..d8b6127 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ serde = { version = "^1.0", features = ["derive"] } serde_with = "3.9.0" shank = "0.4.2" shank_idl = "0.4.2" +spl-math = { version = "0.3.0", features = ["no-entrypoint"] } solana-account-decoder = "~1.18" solana-cli-config = "~1.18" solana-program = "~1.18" @@ -68,14 +69,14 @@ jito-tip-router-client = { path = "./clients/rust/jito_tip_router", version = "0 jito-tip-router-core = { path = "./core", version = "=0.0.1" } jito-tip-router-program = { path = "./program", version = "=0.0.1" } jito-tip-router-shank-cli = { path = "./shank_cli", version = "=0.0.1" } -jito-bytemuck = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-account-traits-derive = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-jsm-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-restaking-client = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-restaking-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-restaking-program = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3", features = ["no-entrypoint"] } -jito-restaking-sdk = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-vault-client = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-vault-core = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } -jito-vault-program = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3", features = ["no-entrypoint"] } -jito-vault-sdk = { git = "https://github.com/jito-foundation/restaking.git", version = "=0.0.3" } +jito-bytemuck = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-account-traits-derive = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-jsm-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-restaking-client = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-restaking-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-restaking-program = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d", features = ["no-entrypoint"] } +jito-restaking-sdk = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-vault-client = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-vault-core = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } +jito-vault-program = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d", features = ["no-entrypoint"] } +jito-vault-sdk = { git = "https://github.com/jito-foundation/restaking.git", rev = "eaf88e7e5ca2845fe3108c4fc4a06a25f9a8514d" } diff --git a/clients/js/jito_tip_router/accounts/weightTable.ts b/clients/js/jito_tip_router/accounts/weightTable.ts index bfccf1d..2e051e9 100644 --- a/clients/js/jito_tip_router/accounts/weightTable.ts +++ b/clients/js/jito_tip_router/accounts/weightTable.ts @@ -46,7 +46,6 @@ export type WeightTable = { ncn: Address; ncnEpoch: bigint; slotCreated: bigint; - slotFinalized: bigint; bump: number; reserved: Array; table: Array; @@ -57,7 +56,6 @@ export type WeightTableArgs = { ncn: Address; ncnEpoch: number | bigint; slotCreated: number | bigint; - slotFinalized: number | bigint; bump: number; reserved: Array; table: Array; @@ -69,7 +67,6 @@ export function getWeightTableEncoder(): Encoder { ['ncn', getAddressEncoder()], ['ncnEpoch', getU64Encoder()], ['slotCreated', getU64Encoder()], - ['slotFinalized', getU64Encoder()], ['bump', getU8Encoder()], ['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })], ['table', getArrayEncoder(getWeightEntryEncoder(), { size: 32 })], @@ -82,7 +79,6 @@ export function getWeightTableDecoder(): Decoder { ['ncn', getAddressDecoder()], ['ncnEpoch', getU64Decoder()], ['slotCreated', getU64Decoder()], - ['slotFinalized', getU64Decoder()], ['bump', getU8Decoder()], ['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })], ['table', getArrayDecoder(getWeightEntryDecoder(), { size: 32 })], diff --git a/clients/js/jito_tip_router/errors/jitoTipRouter.ts b/clients/js/jito_tip_router/errors/jitoTipRouter.ts index e121839..45ac3fa 100644 --- a/clients/js/jito_tip_router/errors/jitoTipRouter.ts +++ b/clients/js/jito_tip_router/errors/jitoTipRouter.ts @@ -14,18 +14,34 @@ import { } from '@solana/web3.js'; import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; -/** NoMoreTableSlots: No more table slots available */ -export const JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS = 0x2000; // 8192 /** DenominatorIsZero: Zero in the denominator */ export const JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO = 0x2100; // 8448 /** ArithmeticOverflow: Overflow */ export const JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW = 0x2101; // 8449 /** ModuloOverflow: Modulo Overflow */ export const JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW = 0x2102; // 8450 +/** NewPreciseNumberError: New precise number error */ +export const JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR = 0x2103; // 8451 +/** CastToImpreciseNumberError: Cast to imprecise number error */ +export const JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR = 0x2104; // 8452 /** IncorrectWeightTableAdmin: Incorrect weight table admin */ export const JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN = 0x2200; // 8704 +/** DuplicateMintsInTable: Duplicate mints in table */ +export const JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE = 0x2201; // 8705 +/** NoMintsInTable: There are no mints in the table */ +export const JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE = 0x2202; // 8706 +/** TooManyMintsForTable: Too many mints for table */ +export const JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE = 0x2203; // 8707 +/** WeightTableAlreadyInitialized: Weight table already initialized */ +export const JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED = 0x2204; // 8708 /** CannotCreateFutureWeightTables: Cannnot create future weight tables */ -export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2201; // 8705 +export const JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES = 0x2205; // 8709 +/** WeightMintsDoNotMatchLength: Weight mints do not match - length */ +export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH = 0x2206; // 8710 +/** WeightMintsDoNotMatchMintHash: Weight mints do not match - mint hash */ +export const JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH = 0x2207; // 8711 +/** InvalidMintForWeightTable: Invalid mint for weight table */ +export const JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE = 0x2208; // 8712 /** FeeCapExceeded: Fee cap exceeded */ export const JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED = 0x2300; // 8960 /** IncorrectNcnAdmin: Incorrect NCN Admin */ @@ -38,28 +54,44 @@ export const JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN = 0x2402; // 9218 export type JitoTipRouterError = | typeof JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW | typeof JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES + | typeof JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR | typeof JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO + | typeof JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE | typeof JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED | typeof JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN | typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN | typeof JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN | typeof JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN + | typeof JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE | typeof JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW - | typeof JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS; + | typeof JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR + | typeof JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE + | typeof JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE + | typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH + | typeof JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH + | typeof JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED; let jitoTipRouterErrorMessages: Record | undefined; if (process.env.NODE_ENV !== 'production') { jitoTipRouterErrorMessages = { [JITO_TIP_ROUTER_ERROR__ARITHMETIC_OVERFLOW]: `Overflow`, [JITO_TIP_ROUTER_ERROR__CANNOT_CREATE_FUTURE_WEIGHT_TABLES]: `Cannnot create future weight tables`, + [JITO_TIP_ROUTER_ERROR__CAST_TO_IMPRECISE_NUMBER_ERROR]: `Cast to imprecise number error`, [JITO_TIP_ROUTER_ERROR__DENOMINATOR_IS_ZERO]: `Zero in the denominator`, + [JITO_TIP_ROUTER_ERROR__DUPLICATE_MINTS_IN_TABLE]: `Duplicate mints in table`, [JITO_TIP_ROUTER_ERROR__FEE_CAP_EXCEEDED]: `Fee cap exceeded`, [JITO_TIP_ROUTER_ERROR__INCORRECT_FEE_ADMIN]: `Incorrect fee admin`, [JITO_TIP_ROUTER_ERROR__INCORRECT_NCN]: `Incorrect NCN`, [JITO_TIP_ROUTER_ERROR__INCORRECT_NCN_ADMIN]: `Incorrect NCN Admin`, [JITO_TIP_ROUTER_ERROR__INCORRECT_WEIGHT_TABLE_ADMIN]: `Incorrect weight table admin`, + [JITO_TIP_ROUTER_ERROR__INVALID_MINT_FOR_WEIGHT_TABLE]: `Invalid mint for weight table`, [JITO_TIP_ROUTER_ERROR__MODULO_OVERFLOW]: `Modulo Overflow`, - [JITO_TIP_ROUTER_ERROR__NO_MORE_TABLE_SLOTS]: `No more table slots available`, + [JITO_TIP_ROUTER_ERROR__NEW_PRECISE_NUMBER_ERROR]: `New precise number error`, + [JITO_TIP_ROUTER_ERROR__NO_MINTS_IN_TABLE]: `There are no mints in the table`, + [JITO_TIP_ROUTER_ERROR__TOO_MANY_MINTS_FOR_TABLE]: `Too many mints for table`, + [JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_LENGTH]: `Weight mints do not match - length`, + [JITO_TIP_ROUTER_ERROR__WEIGHT_MINTS_DO_NOT_MATCH_MINT_HASH]: `Weight mints do not match - mint hash`, + [JITO_TIP_ROUTER_ERROR__WEIGHT_TABLE_ALREADY_INITIALIZED]: `Weight table already initialized`, }; } diff --git a/clients/js/jito_tip_router/instructions/finalizeWeightTable.ts b/clients/js/jito_tip_router/instructions/adminUpdateWeightTable.ts similarity index 69% rename from clients/js/jito_tip_router/instructions/finalizeWeightTable.ts rename to clients/js/jito_tip_router/instructions/adminUpdateWeightTable.ts index df722b3..36e207f 100644 --- a/clients/js/jito_tip_router/instructions/finalizeWeightTable.ts +++ b/clients/js/jito_tip_router/instructions/adminUpdateWeightTable.ts @@ -10,6 +10,8 @@ import { combineCodec, getStructDecoder, getStructEncoder, + getU128Decoder, + getU128Encoder, getU64Decoder, getU64Encoder, getU8Decoder, @@ -32,17 +34,18 @@ import { import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; -export const FINALIZE_WEIGHT_TABLE_DISCRIMINATOR = 3; +export const ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 4; -export function getFinalizeWeightTableDiscriminatorBytes() { - return getU8Encoder().encode(FINALIZE_WEIGHT_TABLE_DISCRIMINATOR); +export function getAdminUpdateWeightTableDiscriminatorBytes() { + return getU8Encoder().encode(ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR); } -export type FinalizeWeightTableInstruction< +export type AdminUpdateWeightTableInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, TAccountNcn extends string | IAccountMeta = string, TAccountWeightTable extends string | IAccountMeta = string, TAccountWeightTableAdmin extends string | IAccountMeta = string, + TAccountMint extends string | IAccountMeta = string, TAccountRestakingProgramId extends string | IAccountMeta = string, TRemainingAccounts extends readonly IAccountMeta[] = [], > = IInstruction & @@ -57,6 +60,9 @@ export type FinalizeWeightTableInstruction< ? ReadonlySignerAccount & IAccountSignerMeta : TAccountWeightTableAdmin, + TAccountMint extends string + ? ReadonlyAccount + : TAccountMint, TAccountRestakingProgramId extends string ? ReadonlyAccount : TAccountRestakingProgramId, @@ -64,77 +70,87 @@ export type FinalizeWeightTableInstruction< ] >; -export type FinalizeWeightTableInstructionData = { +export type AdminUpdateWeightTableInstructionData = { discriminator: number; ncnEpoch: bigint; + weight: bigint; }; -export type FinalizeWeightTableInstructionDataArgs = { +export type AdminUpdateWeightTableInstructionDataArgs = { ncnEpoch: number | bigint; + weight: number | bigint; }; -export function getFinalizeWeightTableInstructionDataEncoder(): Encoder { +export function getAdminUpdateWeightTableInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', getU8Encoder()], ['ncnEpoch', getU64Encoder()], + ['weight', getU128Encoder()], ]), (value) => ({ ...value, - discriminator: FINALIZE_WEIGHT_TABLE_DISCRIMINATOR, + discriminator: ADMIN_UPDATE_WEIGHT_TABLE_DISCRIMINATOR, }) ); } -export function getFinalizeWeightTableInstructionDataDecoder(): Decoder { +export function getAdminUpdateWeightTableInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', getU8Decoder()], ['ncnEpoch', getU64Decoder()], + ['weight', getU128Decoder()], ]); } -export function getFinalizeWeightTableInstructionDataCodec(): Codec< - FinalizeWeightTableInstructionDataArgs, - FinalizeWeightTableInstructionData +export function getAdminUpdateWeightTableInstructionDataCodec(): Codec< + AdminUpdateWeightTableInstructionDataArgs, + AdminUpdateWeightTableInstructionData > { return combineCodec( - getFinalizeWeightTableInstructionDataEncoder(), - getFinalizeWeightTableInstructionDataDecoder() + getAdminUpdateWeightTableInstructionDataEncoder(), + getAdminUpdateWeightTableInstructionDataDecoder() ); } -export type FinalizeWeightTableInput< +export type AdminUpdateWeightTableInput< TAccountNcn extends string = string, TAccountWeightTable extends string = string, TAccountWeightTableAdmin extends string = string, + TAccountMint extends string = string, TAccountRestakingProgramId extends string = string, > = { ncn: Address; weightTable: Address; weightTableAdmin: TransactionSigner; + mint: Address; restakingProgramId: Address; - ncnEpoch: FinalizeWeightTableInstructionDataArgs['ncnEpoch']; + ncnEpoch: AdminUpdateWeightTableInstructionDataArgs['ncnEpoch']; + weight: AdminUpdateWeightTableInstructionDataArgs['weight']; }; -export function getFinalizeWeightTableInstruction< +export function getAdminUpdateWeightTableInstruction< TAccountNcn extends string, TAccountWeightTable extends string, TAccountWeightTableAdmin extends string, + TAccountMint extends string, TAccountRestakingProgramId extends string, TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, >( - input: FinalizeWeightTableInput< + input: AdminUpdateWeightTableInput< TAccountNcn, TAccountWeightTable, TAccountWeightTableAdmin, + TAccountMint, TAccountRestakingProgramId >, config?: { programAddress?: TProgramAddress } -): FinalizeWeightTableInstruction< +): AdminUpdateWeightTableInstruction< TProgramAddress, TAccountNcn, TAccountWeightTable, TAccountWeightTableAdmin, + TAccountMint, TAccountRestakingProgramId > { // Program address. @@ -149,6 +165,7 @@ export function getFinalizeWeightTableInstruction< value: input.weightTableAdmin ?? null, isWritable: false, }, + mint: { value: input.mint ?? null, isWritable: false }, restakingProgramId: { value: input.restakingProgramId ?? null, isWritable: false, @@ -168,24 +185,26 @@ export function getFinalizeWeightTableInstruction< getAccountMeta(accounts.ncn), getAccountMeta(accounts.weightTable), getAccountMeta(accounts.weightTableAdmin), + getAccountMeta(accounts.mint), getAccountMeta(accounts.restakingProgramId), ], programAddress, - data: getFinalizeWeightTableInstructionDataEncoder().encode( - args as FinalizeWeightTableInstructionDataArgs + data: getAdminUpdateWeightTableInstructionDataEncoder().encode( + args as AdminUpdateWeightTableInstructionDataArgs ), - } as FinalizeWeightTableInstruction< + } as AdminUpdateWeightTableInstruction< TProgramAddress, TAccountNcn, TAccountWeightTable, TAccountWeightTableAdmin, + TAccountMint, TAccountRestakingProgramId >; return instruction; } -export type ParsedFinalizeWeightTableInstruction< +export type ParsedAdminUpdateWeightTableInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { @@ -194,20 +213,21 @@ export type ParsedFinalizeWeightTableInstruction< ncn: TAccountMetas[0]; weightTable: TAccountMetas[1]; weightTableAdmin: TAccountMetas[2]; - restakingProgramId: TAccountMetas[3]; + mint: TAccountMetas[3]; + restakingProgramId: TAccountMetas[4]; }; - data: FinalizeWeightTableInstructionData; + data: AdminUpdateWeightTableInstructionData; }; -export function parseFinalizeWeightTableInstruction< +export function parseAdminUpdateWeightTableInstruction< TProgram extends string, TAccountMetas extends readonly IAccountMeta[], >( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData -): ParsedFinalizeWeightTableInstruction { - if (instruction.accounts.length < 4) { +): ParsedAdminUpdateWeightTableInstruction { + if (instruction.accounts.length < 5) { // TODO: Coded error. throw new Error('Not enough accounts'); } @@ -223,9 +243,10 @@ export function parseFinalizeWeightTableInstruction< ncn: getNextAccount(), weightTable: getNextAccount(), weightTableAdmin: getNextAccount(), + mint: getNextAccount(), restakingProgramId: getNextAccount(), }, - data: getFinalizeWeightTableInstructionDataDecoder().decode( + data: getAdminUpdateWeightTableInstructionDataDecoder().decode( instruction.data ), }; diff --git a/clients/js/jito_tip_router/instructions/index.ts b/clients/js/jito_tip_router/instructions/index.ts index 0f849b9..5be6407 100644 --- a/clients/js/jito_tip_router/instructions/index.ts +++ b/clients/js/jito_tip_router/instructions/index.ts @@ -6,9 +6,8 @@ * @see https://github.com/kinobi-so/kinobi */ -export * from './finalizeWeightTable'; -export * from './initializeConfig'; +export * from './adminUpdateWeightTable'; +export * from './initializeNCNConfig'; export * from './initializeWeightTable'; export * from './setConfigFees'; export * from './setNewAdmin'; -export * from './updateWeightTable'; diff --git a/clients/js/jito_tip_router/instructions/initializeConfig.ts b/clients/js/jito_tip_router/instructions/initializeNCNConfig.ts similarity index 67% rename from clients/js/jito_tip_router/instructions/initializeConfig.ts rename to clients/js/jito_tip_router/instructions/initializeNCNConfig.ts index e5c99aa..0f7834e 100644 --- a/clients/js/jito_tip_router/instructions/initializeConfig.ts +++ b/clients/js/jito_tip_router/instructions/initializeNCNConfig.ts @@ -32,15 +32,16 @@ import { import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; -export const INITIALIZE_CONFIG_DISCRIMINATOR = 0; +export const INITIALIZE_N_C_N_CONFIG_DISCRIMINATOR = 0; -export function getInitializeConfigDiscriminatorBytes() { - return getU8Encoder().encode(INITIALIZE_CONFIG_DISCRIMINATOR); +export function getInitializeNCNConfigDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_N_C_N_CONFIG_DISCRIMINATOR); } -export type InitializeConfigInstruction< +export type InitializeNCNConfigInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, - TAccountConfig extends string | IAccountMeta = string, + TAccountRestakingConfig extends string | IAccountMeta = string, + TAccountNcnConfig extends string | IAccountMeta = string, TAccountNcn extends string | IAccountMeta = string, TAccountNcnAdmin extends string | IAccountMeta = string, TAccountFeeWallet extends string | IAccountMeta = string, @@ -54,9 +55,12 @@ export type InitializeConfigInstruction< IInstructionWithData & IInstructionWithAccounts< [ - TAccountConfig extends string - ? WritableAccount - : TAccountConfig, + TAccountRestakingConfig extends string + ? ReadonlyAccount + : TAccountRestakingConfig, + TAccountNcnConfig extends string + ? WritableAccount + : TAccountNcnConfig, TAccountNcn extends string ? ReadonlyAccount : TAccountNcn, TAccountNcnAdmin extends string ? ReadonlySignerAccount & @@ -78,20 +82,20 @@ export type InitializeConfigInstruction< ] >; -export type InitializeConfigInstructionData = { +export type InitializeNCNConfigInstructionData = { discriminator: number; daoFeeBps: bigint; ncnFeeBps: bigint; blockEngineFeeBps: bigint; }; -export type InitializeConfigInstructionDataArgs = { +export type InitializeNCNConfigInstructionDataArgs = { daoFeeBps: number | bigint; ncnFeeBps: number | bigint; blockEngineFeeBps: number | bigint; }; -export function getInitializeConfigInstructionDataEncoder(): Encoder { +export function getInitializeNCNConfigInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ['discriminator', getU8Encoder()], @@ -99,11 +103,14 @@ export function getInitializeConfigInstructionDataEncoder(): Encoder ({ ...value, discriminator: INITIALIZE_CONFIG_DISCRIMINATOR }) + (value) => ({ + ...value, + discriminator: INITIALIZE_N_C_N_CONFIG_DISCRIMINATOR, + }) ); } -export function getInitializeConfigInstructionDataDecoder(): Decoder { +export function getInitializeNCNConfigInstructionDataDecoder(): Decoder { return getStructDecoder([ ['discriminator', getU8Decoder()], ['daoFeeBps', getU64Decoder()], @@ -112,18 +119,19 @@ export function getInitializeConfigInstructionDataDecoder(): Decoder { return combineCodec( - getInitializeConfigInstructionDataEncoder(), - getInitializeConfigInstructionDataDecoder() + getInitializeNCNConfigInstructionDataEncoder(), + getInitializeNCNConfigInstructionDataDecoder() ); } -export type InitializeConfigInput< - TAccountConfig extends string = string, +export type InitializeNCNConfigInput< + TAccountRestakingConfig extends string = string, + TAccountNcnConfig extends string = string, TAccountNcn extends string = string, TAccountNcnAdmin extends string = string, TAccountFeeWallet extends string = string, @@ -131,20 +139,22 @@ export type InitializeConfigInput< TAccountRestakingProgramId extends string = string, TAccountSystemProgram extends string = string, > = { - config: Address; + restakingConfig: Address; + ncnConfig: Address; ncn: Address; ncnAdmin: TransactionSigner; feeWallet: Address; tieBreakerAdmin: Address; restakingProgramId: Address; systemProgram?: Address; - daoFeeBps: InitializeConfigInstructionDataArgs['daoFeeBps']; - ncnFeeBps: InitializeConfigInstructionDataArgs['ncnFeeBps']; - blockEngineFeeBps: InitializeConfigInstructionDataArgs['blockEngineFeeBps']; + daoFeeBps: InitializeNCNConfigInstructionDataArgs['daoFeeBps']; + ncnFeeBps: InitializeNCNConfigInstructionDataArgs['ncnFeeBps']; + blockEngineFeeBps: InitializeNCNConfigInstructionDataArgs['blockEngineFeeBps']; }; -export function getInitializeConfigInstruction< - TAccountConfig extends string, +export function getInitializeNCNConfigInstruction< + TAccountRestakingConfig extends string, + TAccountNcnConfig extends string, TAccountNcn extends string, TAccountNcnAdmin extends string, TAccountFeeWallet extends string, @@ -153,8 +163,9 @@ export function getInitializeConfigInstruction< TAccountSystemProgram extends string, TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, >( - input: InitializeConfigInput< - TAccountConfig, + input: InitializeNCNConfigInput< + TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountNcnAdmin, TAccountFeeWallet, @@ -163,9 +174,10 @@ export function getInitializeConfigInstruction< TAccountSystemProgram >, config?: { programAddress?: TProgramAddress } -): InitializeConfigInstruction< +): InitializeNCNConfigInstruction< TProgramAddress, - TAccountConfig, + TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountNcnAdmin, TAccountFeeWallet, @@ -179,7 +191,11 @@ export function getInitializeConfigInstruction< // Original accounts. const originalAccounts = { - config: { value: input.config ?? null, isWritable: true }, + restakingConfig: { + value: input.restakingConfig ?? null, + isWritable: false, + }, + ncnConfig: { value: input.ncnConfig ?? null, isWritable: true }, ncn: { value: input.ncn ?? null, isWritable: false }, ncnAdmin: { value: input.ncnAdmin ?? null, isWritable: false }, feeWallet: { value: input.feeWallet ?? null, isWritable: false }, @@ -210,7 +226,8 @@ export function getInitializeConfigInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ - getAccountMeta(accounts.config), + getAccountMeta(accounts.restakingConfig), + getAccountMeta(accounts.ncnConfig), getAccountMeta(accounts.ncn), getAccountMeta(accounts.ncnAdmin), getAccountMeta(accounts.feeWallet), @@ -219,12 +236,13 @@ export function getInitializeConfigInstruction< getAccountMeta(accounts.systemProgram), ], programAddress, - data: getInitializeConfigInstructionDataEncoder().encode( - args as InitializeConfigInstructionDataArgs + data: getInitializeNCNConfigInstructionDataEncoder().encode( + args as InitializeNCNConfigInstructionDataArgs ), - } as InitializeConfigInstruction< + } as InitializeNCNConfigInstruction< TProgramAddress, - TAccountConfig, + TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountNcnAdmin, TAccountFeeWallet, @@ -236,32 +254,33 @@ export function getInitializeConfigInstruction< return instruction; } -export type ParsedInitializeConfigInstruction< +export type ParsedInitializeNCNConfigInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], > = { programAddress: Address; accounts: { - config: TAccountMetas[0]; - ncn: TAccountMetas[1]; - ncnAdmin: TAccountMetas[2]; - feeWallet: TAccountMetas[3]; - tieBreakerAdmin: TAccountMetas[4]; - restakingProgramId: TAccountMetas[5]; - systemProgram: TAccountMetas[6]; + restakingConfig: TAccountMetas[0]; + ncnConfig: TAccountMetas[1]; + ncn: TAccountMetas[2]; + ncnAdmin: TAccountMetas[3]; + feeWallet: TAccountMetas[4]; + tieBreakerAdmin: TAccountMetas[5]; + restakingProgramId: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; }; - data: InitializeConfigInstructionData; + data: InitializeNCNConfigInstructionData; }; -export function parseInitializeConfigInstruction< +export function parseInitializeNCNConfigInstruction< TProgram extends string, TAccountMetas extends readonly IAccountMeta[], >( instruction: IInstruction & IInstructionWithAccounts & IInstructionWithData -): ParsedInitializeConfigInstruction { - if (instruction.accounts.length < 7) { +): ParsedInitializeNCNConfigInstruction { + if (instruction.accounts.length < 8) { // TODO: Coded error. throw new Error('Not enough accounts'); } @@ -274,7 +293,8 @@ export function parseInitializeConfigInstruction< return { programAddress: instruction.programAddress, accounts: { - config: getNextAccount(), + restakingConfig: getNextAccount(), + ncnConfig: getNextAccount(), ncn: getNextAccount(), ncnAdmin: getNextAccount(), feeWallet: getNextAccount(), @@ -282,6 +302,8 @@ export function parseInitializeConfigInstruction< restakingProgramId: getNextAccount(), systemProgram: getNextAccount(), }, - data: getInitializeConfigInstructionDataDecoder().decode(instruction.data), + data: getInitializeNCNConfigInstructionDataDecoder().decode( + instruction.data + ), }; } diff --git a/clients/js/jito_tip_router/instructions/initializeWeightTable.ts b/clients/js/jito_tip_router/instructions/initializeWeightTable.ts index 1f64e0c..fb1b904 100644 --- a/clients/js/jito_tip_router/instructions/initializeWeightTable.ts +++ b/clients/js/jito_tip_router/instructions/initializeWeightTable.ts @@ -30,12 +30,13 @@ import { type OptionOrNullable, type ReadonlyAccount, type TransactionSigner, + type WritableAccount, type WritableSignerAccount, } from '@solana/web3.js'; import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; -export const INITIALIZE_WEIGHT_TABLE_DISCRIMINATOR = 1; +export const INITIALIZE_WEIGHT_TABLE_DISCRIMINATOR = 3; export function getInitializeWeightTableDiscriminatorBytes() { return getU8Encoder().encode(INITIALIZE_WEIGHT_TABLE_DISCRIMINATOR); @@ -44,9 +45,10 @@ export function getInitializeWeightTableDiscriminatorBytes() { export type InitializeWeightTableInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, TAccountRestakingConfig extends string | IAccountMeta = string, + TAccountNcnConfig extends string | IAccountMeta = string, TAccountNcn extends string | IAccountMeta = string, TAccountWeightTable extends string | IAccountMeta = string, - TAccountWeightTableAdmin extends string | IAccountMeta = string, + TAccountPayer extends string | IAccountMeta = string, TAccountRestakingProgramId extends string | IAccountMeta = string, TAccountSystemProgram extends | string @@ -59,15 +61,17 @@ export type InitializeWeightTableInstruction< TAccountRestakingConfig extends string ? ReadonlyAccount : TAccountRestakingConfig, + TAccountNcnConfig extends string + ? ReadonlyAccount + : TAccountNcnConfig, TAccountNcn extends string ? ReadonlyAccount : TAccountNcn, TAccountWeightTable extends string - ? WritableSignerAccount & - IAccountSignerMeta + ? WritableAccount : TAccountWeightTable, - TAccountWeightTableAdmin extends string - ? WritableSignerAccount & - IAccountSignerMeta - : TAccountWeightTableAdmin, + TAccountPayer extends string + ? WritableSignerAccount & + IAccountSignerMeta + : TAccountPayer, TAccountRestakingProgramId extends string ? ReadonlyAccount : TAccountRestakingProgramId, @@ -119,16 +123,18 @@ export function getInitializeWeightTableInstructionDataCodec(): Codec< export type InitializeWeightTableInput< TAccountRestakingConfig extends string = string, + TAccountNcnConfig extends string = string, TAccountNcn extends string = string, TAccountWeightTable extends string = string, - TAccountWeightTableAdmin extends string = string, + TAccountPayer extends string = string, TAccountRestakingProgramId extends string = string, TAccountSystemProgram extends string = string, > = { restakingConfig: Address; + ncnConfig: Address; ncn: Address; - weightTable: TransactionSigner; - weightTableAdmin: TransactionSigner; + weightTable: Address; + payer: TransactionSigner; restakingProgramId: Address; systemProgram?: Address; firstSlotOfNcnEpoch: InitializeWeightTableInstructionDataArgs['firstSlotOfNcnEpoch']; @@ -136,18 +142,20 @@ export type InitializeWeightTableInput< export function getInitializeWeightTableInstruction< TAccountRestakingConfig extends string, + TAccountNcnConfig extends string, TAccountNcn extends string, TAccountWeightTable extends string, - TAccountWeightTableAdmin extends string, + TAccountPayer extends string, TAccountRestakingProgramId extends string, TAccountSystemProgram extends string, TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, >( input: InitializeWeightTableInput< TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountWeightTable, - TAccountWeightTableAdmin, + TAccountPayer, TAccountRestakingProgramId, TAccountSystemProgram >, @@ -155,9 +163,10 @@ export function getInitializeWeightTableInstruction< ): InitializeWeightTableInstruction< TProgramAddress, TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountWeightTable, - TAccountWeightTableAdmin, + TAccountPayer, TAccountRestakingProgramId, TAccountSystemProgram > { @@ -171,12 +180,10 @@ export function getInitializeWeightTableInstruction< value: input.restakingConfig ?? null, isWritable: false, }, + ncnConfig: { value: input.ncnConfig ?? null, isWritable: false }, ncn: { value: input.ncn ?? null, isWritable: false }, weightTable: { value: input.weightTable ?? null, isWritable: true }, - weightTableAdmin: { - value: input.weightTableAdmin ?? null, - isWritable: true, - }, + payer: { value: input.payer ?? null, isWritable: true }, restakingProgramId: { value: input.restakingProgramId ?? null, isWritable: false, @@ -201,9 +208,10 @@ export function getInitializeWeightTableInstruction< const instruction = { accounts: [ getAccountMeta(accounts.restakingConfig), + getAccountMeta(accounts.ncnConfig), getAccountMeta(accounts.ncn), getAccountMeta(accounts.weightTable), - getAccountMeta(accounts.weightTableAdmin), + getAccountMeta(accounts.payer), getAccountMeta(accounts.restakingProgramId), getAccountMeta(accounts.systemProgram), ], @@ -214,9 +222,10 @@ export function getInitializeWeightTableInstruction< } as InitializeWeightTableInstruction< TProgramAddress, TAccountRestakingConfig, + TAccountNcnConfig, TAccountNcn, TAccountWeightTable, - TAccountWeightTableAdmin, + TAccountPayer, TAccountRestakingProgramId, TAccountSystemProgram >; @@ -231,11 +240,12 @@ export type ParsedInitializeWeightTableInstruction< programAddress: Address; accounts: { restakingConfig: TAccountMetas[0]; - ncn: TAccountMetas[1]; - weightTable: TAccountMetas[2]; - weightTableAdmin: TAccountMetas[3]; - restakingProgramId: TAccountMetas[4]; - systemProgram: TAccountMetas[5]; + ncnConfig: TAccountMetas[1]; + ncn: TAccountMetas[2]; + weightTable: TAccountMetas[3]; + payer: TAccountMetas[4]; + restakingProgramId: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; }; data: InitializeWeightTableInstructionData; }; @@ -248,7 +258,7 @@ export function parseInitializeWeightTableInstruction< IInstructionWithAccounts & IInstructionWithData ): ParsedInitializeWeightTableInstruction { - if (instruction.accounts.length < 6) { + if (instruction.accounts.length < 7) { // TODO: Coded error. throw new Error('Not enough accounts'); } @@ -262,9 +272,10 @@ export function parseInitializeWeightTableInstruction< programAddress: instruction.programAddress, accounts: { restakingConfig: getNextAccount(), + ncnConfig: getNextAccount(), ncn: getNextAccount(), weightTable: getNextAccount(), - weightTableAdmin: getNextAccount(), + payer: getNextAccount(), restakingProgramId: getNextAccount(), systemProgram: getNextAccount(), }, diff --git a/clients/js/jito_tip_router/instructions/setConfigFees.ts b/clients/js/jito_tip_router/instructions/setConfigFees.ts index 7aba950..b6274cd 100644 --- a/clients/js/jito_tip_router/instructions/setConfigFees.ts +++ b/clients/js/jito_tip_router/instructions/setConfigFees.ts @@ -38,7 +38,7 @@ import { import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; -export const SET_CONFIG_FEES_DISCRIMINATOR = 4; +export const SET_CONFIG_FEES_DISCRIMINATOR = 1; export function getSetConfigFeesDiscriminatorBytes() { return getU8Encoder().encode(SET_CONFIG_FEES_DISCRIMINATOR); @@ -46,6 +46,7 @@ export function getSetConfigFeesDiscriminatorBytes() { export type SetConfigFeesInstruction< TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, + TAccountRestakingConfig extends string | IAccountMeta = string, TAccountConfig extends string | IAccountMeta = string, TAccountNcn extends string | IAccountMeta = string, TAccountNcnAdmin extends string | IAccountMeta = string, @@ -55,6 +56,9 @@ export type SetConfigFeesInstruction< IInstructionWithData & IInstructionWithAccounts< [ + TAccountRestakingConfig extends string + ? ReadonlyAccount + : TAccountRestakingConfig, TAccountConfig extends string ? WritableAccount : TAccountConfig, @@ -119,11 +123,13 @@ export function getSetConfigFeesInstructionDataCodec(): Codec< } export type SetConfigFeesInput< + TAccountRestakingConfig extends string = string, TAccountConfig extends string = string, TAccountNcn extends string = string, TAccountNcnAdmin extends string = string, TAccountRestakingProgramId extends string = string, > = { + restakingConfig: Address; config: Address; ncn: Address; ncnAdmin: TransactionSigner; @@ -135,6 +141,7 @@ export type SetConfigFeesInput< }; export function getSetConfigFeesInstruction< + TAccountRestakingConfig extends string, TAccountConfig extends string, TAccountNcn extends string, TAccountNcnAdmin extends string, @@ -142,6 +149,7 @@ export function getSetConfigFeesInstruction< TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, >( input: SetConfigFeesInput< + TAccountRestakingConfig, TAccountConfig, TAccountNcn, TAccountNcnAdmin, @@ -150,6 +158,7 @@ export function getSetConfigFeesInstruction< config?: { programAddress?: TProgramAddress } ): SetConfigFeesInstruction< TProgramAddress, + TAccountRestakingConfig, TAccountConfig, TAccountNcn, TAccountNcnAdmin, @@ -161,6 +170,10 @@ export function getSetConfigFeesInstruction< // Original accounts. const originalAccounts = { + restakingConfig: { + value: input.restakingConfig ?? null, + isWritable: false, + }, config: { value: input.config ?? null, isWritable: true }, ncn: { value: input.ncn ?? null, isWritable: false }, ncnAdmin: { value: input.ncnAdmin ?? null, isWritable: false }, @@ -180,6 +193,7 @@ export function getSetConfigFeesInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ + getAccountMeta(accounts.restakingConfig), getAccountMeta(accounts.config), getAccountMeta(accounts.ncn), getAccountMeta(accounts.ncnAdmin), @@ -191,6 +205,7 @@ export function getSetConfigFeesInstruction< ), } as SetConfigFeesInstruction< TProgramAddress, + TAccountRestakingConfig, TAccountConfig, TAccountNcn, TAccountNcnAdmin, @@ -206,10 +221,11 @@ export type ParsedSetConfigFeesInstruction< > = { programAddress: Address; accounts: { - config: TAccountMetas[0]; - ncn: TAccountMetas[1]; - ncnAdmin: TAccountMetas[2]; - restakingProgramId: TAccountMetas[3]; + restakingConfig: TAccountMetas[0]; + config: TAccountMetas[1]; + ncn: TAccountMetas[2]; + ncnAdmin: TAccountMetas[3]; + restakingProgramId: TAccountMetas[4]; }; data: SetConfigFeesInstructionData; }; @@ -222,7 +238,7 @@ export function parseSetConfigFeesInstruction< IInstructionWithAccounts & IInstructionWithData ): ParsedSetConfigFeesInstruction { - if (instruction.accounts.length < 4) { + if (instruction.accounts.length < 5) { // TODO: Coded error. throw new Error('Not enough accounts'); } @@ -235,6 +251,7 @@ export function parseSetConfigFeesInstruction< return { programAddress: instruction.programAddress, accounts: { + restakingConfig: getNextAccount(), config: getNextAccount(), ncn: getNextAccount(), ncnAdmin: getNextAccount(), diff --git a/clients/js/jito_tip_router/instructions/setNewAdmin.ts b/clients/js/jito_tip_router/instructions/setNewAdmin.ts index c2272f3..eb14e6c 100644 --- a/clients/js/jito_tip_router/instructions/setNewAdmin.ts +++ b/clients/js/jito_tip_router/instructions/setNewAdmin.ts @@ -36,7 +36,7 @@ import { type ConfigAdminRoleArgs, } from '../types'; -export const SET_NEW_ADMIN_DISCRIMINATOR = 5; +export const SET_NEW_ADMIN_DISCRIMINATOR = 2; export function getSetNewAdminDiscriminatorBytes() { return getU8Encoder().encode(SET_NEW_ADMIN_DISCRIMINATOR); diff --git a/clients/js/jito_tip_router/instructions/updateWeightTable.ts b/clients/js/jito_tip_router/instructions/updateWeightTable.ts deleted file mode 100644 index 41fb6be..0000000 --- a/clients/js/jito_tip_router/instructions/updateWeightTable.ts +++ /dev/null @@ -1,237 +0,0 @@ -/** - * This code was AUTOGENERATED using the kinobi library. - * Please DO NOT EDIT THIS FILE, instead use visitors - * to add features, then rerun kinobi to update it. - * - * @see https://github.com/kinobi-so/kinobi - */ - -import { - combineCodec, - getStructDecoder, - getStructEncoder, - getU64Decoder, - getU64Encoder, - getU8Decoder, - getU8Encoder, - transformEncoder, - type Address, - type Codec, - type Decoder, - type Encoder, - type IAccountMeta, - type IAccountSignerMeta, - type IInstruction, - type IInstructionWithAccounts, - type IInstructionWithData, - type ReadonlyAccount, - type ReadonlySignerAccount, - type TransactionSigner, - type WritableAccount, -} from '@solana/web3.js'; -import { JITO_TIP_ROUTER_PROGRAM_ADDRESS } from '../programs'; -import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; - -export const UPDATE_WEIGHT_TABLE_DISCRIMINATOR = 2; - -export function getUpdateWeightTableDiscriminatorBytes() { - return getU8Encoder().encode(UPDATE_WEIGHT_TABLE_DISCRIMINATOR); -} - -export type UpdateWeightTableInstruction< - TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, - TAccountNcn extends string | IAccountMeta = string, - TAccountWeightTable extends string | IAccountMeta = string, - TAccountWeightTableAdmin extends string | IAccountMeta = string, - TAccountRestakingProgramId extends string | IAccountMeta = string, - TRemainingAccounts extends readonly IAccountMeta[] = [], -> = IInstruction & - IInstructionWithData & - IInstructionWithAccounts< - [ - TAccountNcn extends string ? ReadonlyAccount : TAccountNcn, - TAccountWeightTable extends string - ? WritableAccount - : TAccountWeightTable, - TAccountWeightTableAdmin extends string - ? ReadonlySignerAccount & - IAccountSignerMeta - : TAccountWeightTableAdmin, - TAccountRestakingProgramId extends string - ? ReadonlyAccount - : TAccountRestakingProgramId, - ...TRemainingAccounts, - ] - >; - -export type UpdateWeightTableInstructionData = { - discriminator: number; - ncnEpoch: bigint; - weightNumerator: bigint; - weightDenominator: bigint; -}; - -export type UpdateWeightTableInstructionDataArgs = { - ncnEpoch: number | bigint; - weightNumerator: number | bigint; - weightDenominator: number | bigint; -}; - -export function getUpdateWeightTableInstructionDataEncoder(): Encoder { - return transformEncoder( - getStructEncoder([ - ['discriminator', getU8Encoder()], - ['ncnEpoch', getU64Encoder()], - ['weightNumerator', getU64Encoder()], - ['weightDenominator', getU64Encoder()], - ]), - (value) => ({ ...value, discriminator: UPDATE_WEIGHT_TABLE_DISCRIMINATOR }) - ); -} - -export function getUpdateWeightTableInstructionDataDecoder(): Decoder { - return getStructDecoder([ - ['discriminator', getU8Decoder()], - ['ncnEpoch', getU64Decoder()], - ['weightNumerator', getU64Decoder()], - ['weightDenominator', getU64Decoder()], - ]); -} - -export function getUpdateWeightTableInstructionDataCodec(): Codec< - UpdateWeightTableInstructionDataArgs, - UpdateWeightTableInstructionData -> { - return combineCodec( - getUpdateWeightTableInstructionDataEncoder(), - getUpdateWeightTableInstructionDataDecoder() - ); -} - -export type UpdateWeightTableInput< - TAccountNcn extends string = string, - TAccountWeightTable extends string = string, - TAccountWeightTableAdmin extends string = string, - TAccountRestakingProgramId extends string = string, -> = { - ncn: Address; - weightTable: Address; - weightTableAdmin: TransactionSigner; - restakingProgramId: Address; - ncnEpoch: UpdateWeightTableInstructionDataArgs['ncnEpoch']; - weightNumerator: UpdateWeightTableInstructionDataArgs['weightNumerator']; - weightDenominator: UpdateWeightTableInstructionDataArgs['weightDenominator']; -}; - -export function getUpdateWeightTableInstruction< - TAccountNcn extends string, - TAccountWeightTable extends string, - TAccountWeightTableAdmin extends string, - TAccountRestakingProgramId extends string, - TProgramAddress extends Address = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, ->( - input: UpdateWeightTableInput< - TAccountNcn, - TAccountWeightTable, - TAccountWeightTableAdmin, - TAccountRestakingProgramId - >, - config?: { programAddress?: TProgramAddress } -): UpdateWeightTableInstruction< - TProgramAddress, - TAccountNcn, - TAccountWeightTable, - TAccountWeightTableAdmin, - TAccountRestakingProgramId -> { - // Program address. - const programAddress = - config?.programAddress ?? JITO_TIP_ROUTER_PROGRAM_ADDRESS; - - // Original accounts. - const originalAccounts = { - ncn: { value: input.ncn ?? null, isWritable: false }, - weightTable: { value: input.weightTable ?? null, isWritable: true }, - weightTableAdmin: { - value: input.weightTableAdmin ?? null, - isWritable: false, - }, - restakingProgramId: { - value: input.restakingProgramId ?? null, - isWritable: false, - }, - }; - const accounts = originalAccounts as Record< - keyof typeof originalAccounts, - ResolvedAccount - >; - - // Original args. - const args = { ...input }; - - const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); - const instruction = { - accounts: [ - getAccountMeta(accounts.ncn), - getAccountMeta(accounts.weightTable), - getAccountMeta(accounts.weightTableAdmin), - getAccountMeta(accounts.restakingProgramId), - ], - programAddress, - data: getUpdateWeightTableInstructionDataEncoder().encode( - args as UpdateWeightTableInstructionDataArgs - ), - } as UpdateWeightTableInstruction< - TProgramAddress, - TAccountNcn, - TAccountWeightTable, - TAccountWeightTableAdmin, - TAccountRestakingProgramId - >; - - return instruction; -} - -export type ParsedUpdateWeightTableInstruction< - TProgram extends string = typeof JITO_TIP_ROUTER_PROGRAM_ADDRESS, - TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], -> = { - programAddress: Address; - accounts: { - ncn: TAccountMetas[0]; - weightTable: TAccountMetas[1]; - weightTableAdmin: TAccountMetas[2]; - restakingProgramId: TAccountMetas[3]; - }; - data: UpdateWeightTableInstructionData; -}; - -export function parseUpdateWeightTableInstruction< - TProgram extends string, - TAccountMetas extends readonly IAccountMeta[], ->( - instruction: IInstruction & - IInstructionWithAccounts & - IInstructionWithData -): ParsedUpdateWeightTableInstruction { - if (instruction.accounts.length < 4) { - // TODO: Coded error. - throw new Error('Not enough accounts'); - } - let accountIndex = 0; - const getNextAccount = () => { - const accountMeta = instruction.accounts![accountIndex]!; - accountIndex += 1; - return accountMeta; - }; - return { - programAddress: instruction.programAddress, - accounts: { - ncn: getNextAccount(), - weightTable: getNextAccount(), - weightTableAdmin: getNextAccount(), - restakingProgramId: getNextAccount(), - }, - data: getUpdateWeightTableInstructionDataDecoder().decode(instruction.data), - }; -} diff --git a/clients/js/jito_tip_router/programs/jitoTipRouter.ts b/clients/js/jito_tip_router/programs/jitoTipRouter.ts index 7320b4f..c3f29cd 100644 --- a/clients/js/jito_tip_router/programs/jitoTipRouter.ts +++ b/clients/js/jito_tip_router/programs/jitoTipRouter.ts @@ -13,12 +13,11 @@ import { type ReadonlyUint8Array, } from '@solana/web3.js'; import { - type ParsedFinalizeWeightTableInstruction, - type ParsedInitializeConfigInstruction, + type ParsedAdminUpdateWeightTableInstruction, + type ParsedInitializeNCNConfigInstruction, type ParsedInitializeWeightTableInstruction, type ParsedSetConfigFeesInstruction, type ParsedSetNewAdminInstruction, - type ParsedUpdateWeightTableInstruction, } from '../instructions'; export const JITO_TIP_ROUTER_PROGRAM_ADDRESS = @@ -30,12 +29,11 @@ export enum JitoTipRouterAccount { } export enum JitoTipRouterInstruction { - InitializeConfig, - InitializeWeightTable, - UpdateWeightTable, - FinalizeWeightTable, + InitializeNCNConfig, SetConfigFees, SetNewAdmin, + InitializeWeightTable, + AdminUpdateWeightTable, } export function identifyJitoTipRouterInstruction( @@ -43,22 +41,19 @@ export function identifyJitoTipRouterInstruction( ): JitoTipRouterInstruction { const data = 'data' in instruction ? instruction.data : instruction; if (containsBytes(data, getU8Encoder().encode(0), 0)) { - return JitoTipRouterInstruction.InitializeConfig; + return JitoTipRouterInstruction.InitializeNCNConfig; } if (containsBytes(data, getU8Encoder().encode(1), 0)) { - return JitoTipRouterInstruction.InitializeWeightTable; + return JitoTipRouterInstruction.SetConfigFees; } if (containsBytes(data, getU8Encoder().encode(2), 0)) { - return JitoTipRouterInstruction.UpdateWeightTable; + return JitoTipRouterInstruction.SetNewAdmin; } if (containsBytes(data, getU8Encoder().encode(3), 0)) { - return JitoTipRouterInstruction.FinalizeWeightTable; + return JitoTipRouterInstruction.InitializeWeightTable; } if (containsBytes(data, getU8Encoder().encode(4), 0)) { - return JitoTipRouterInstruction.SetConfigFees; - } - if (containsBytes(data, getU8Encoder().encode(5), 0)) { - return JitoTipRouterInstruction.SetNewAdmin; + return JitoTipRouterInstruction.AdminUpdateWeightTable; } throw new Error( 'The provided instruction could not be identified as a jitoTipRouter instruction.' @@ -69,20 +64,17 @@ export type ParsedJitoTipRouterInstruction< TProgram extends string = 'Fv9aHCgvPQSr4jg9W8eTS6Ys1SNmh2qjyATrbsjEMaSH', > = | ({ - instructionType: JitoTipRouterInstruction.InitializeConfig; - } & ParsedInitializeConfigInstruction) - | ({ - instructionType: JitoTipRouterInstruction.InitializeWeightTable; - } & ParsedInitializeWeightTableInstruction) - | ({ - instructionType: JitoTipRouterInstruction.UpdateWeightTable; - } & ParsedUpdateWeightTableInstruction) - | ({ - instructionType: JitoTipRouterInstruction.FinalizeWeightTable; - } & ParsedFinalizeWeightTableInstruction) + instructionType: JitoTipRouterInstruction.InitializeNCNConfig; + } & ParsedInitializeNCNConfigInstruction) | ({ instructionType: JitoTipRouterInstruction.SetConfigFees; } & ParsedSetConfigFeesInstruction) | ({ instructionType: JitoTipRouterInstruction.SetNewAdmin; - } & ParsedSetNewAdminInstruction); + } & ParsedSetNewAdminInstruction) + | ({ + instructionType: JitoTipRouterInstruction.InitializeWeightTable; + } & ParsedInitializeWeightTableInstruction) + | ({ + instructionType: JitoTipRouterInstruction.AdminUpdateWeightTable; + } & ParsedAdminUpdateWeightTableInstruction); diff --git a/clients/js/jito_tip_router/types/weightEntry.ts b/clients/js/jito_tip_router/types/weightEntry.ts index 745e000..e16f8f5 100644 --- a/clients/js/jito_tip_router/types/weightEntry.ts +++ b/clients/js/jito_tip_router/types/weightEntry.ts @@ -10,31 +10,55 @@ import { combineCodec, getAddressDecoder, getAddressEncoder, + getArrayDecoder, + getArrayEncoder, getStructDecoder, getStructEncoder, + getU128Decoder, + getU128Encoder, getU64Decoder, getU64Encoder, + getU8Decoder, + getU8Encoder, type Address, type Codec, type Decoder, type Encoder, } from '@solana/web3.js'; -export type WeightEntry = { mint: Address; weight: bigint }; +export type WeightEntry = { + mint: Address; + weight: bigint; + slotSet: bigint; + slotUpdated: bigint; + reserved: Array; +}; -export type WeightEntryArgs = { mint: Address; weight: number | bigint }; +export type WeightEntryArgs = { + mint: Address; + weight: number | bigint; + slotSet: number | bigint; + slotUpdated: number | bigint; + reserved: Array; +}; export function getWeightEntryEncoder(): Encoder { return getStructEncoder([ ['mint', getAddressEncoder()], - ['weight', getU64Encoder()], + ['weight', getU128Encoder()], + ['slotSet', getU64Encoder()], + ['slotUpdated', getU64Encoder()], + ['reserved', getArrayEncoder(getU8Encoder(), { size: 128 })], ]); } export function getWeightEntryDecoder(): Decoder { return getStructDecoder([ ['mint', getAddressDecoder()], - ['weight', getU64Decoder()], + ['weight', getU128Decoder()], + ['slotSet', getU64Decoder()], + ['slotUpdated', getU64Decoder()], + ['reserved', getArrayDecoder(getU8Decoder(), { size: 128 })], ]); } diff --git a/clients/rust/jito_tip_router/src/generated/accounts/weight_table.rs b/clients/rust/jito_tip_router/src/generated/accounts/weight_table.rs index 3a996b1..72be462 100644 --- a/clients/rust/jito_tip_router/src/generated/accounts/weight_table.rs +++ b/clients/rust/jito_tip_router/src/generated/accounts/weight_table.rs @@ -20,7 +20,6 @@ pub struct WeightTable { pub ncn: Pubkey, pub ncn_epoch: u64, pub slot_created: u64, - pub slot_finalized: u64, pub bump: u8, #[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] pub reserved: [u8; 128], diff --git a/clients/rust/jito_tip_router/src/generated/errors/jito_tip_router.rs b/clients/rust/jito_tip_router/src/generated/errors/jito_tip_router.rs index cfd022b..e094476 100644 --- a/clients/rust/jito_tip_router/src/generated/errors/jito_tip_router.rs +++ b/clients/rust/jito_tip_router/src/generated/errors/jito_tip_router.rs @@ -9,9 +9,6 @@ use thiserror::Error; #[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)] pub enum JitoTipRouterError { - /// 8192 - No more table slots available - #[error("No more table slots available")] - NoMoreTableSlots = 0x2000, /// 8448 - Zero in the denominator #[error("Zero in the denominator")] DenominatorIsZero = 0x2100, @@ -21,12 +18,39 @@ pub enum JitoTipRouterError { /// 8450 - Modulo Overflow #[error("Modulo Overflow")] ModuloOverflow = 0x2102, + /// 8451 - New precise number error + #[error("New precise number error")] + NewPreciseNumberError = 0x2103, + /// 8452 - Cast to imprecise number error + #[error("Cast to imprecise number error")] + CastToImpreciseNumberError = 0x2104, /// 8704 - Incorrect weight table admin #[error("Incorrect weight table admin")] IncorrectWeightTableAdmin = 0x2200, - /// 8705 - Cannnot create future weight tables + /// 8705 - Duplicate mints in table + #[error("Duplicate mints in table")] + DuplicateMintsInTable = 0x2201, + /// 8706 - There are no mints in the table + #[error("There are no mints in the table")] + NoMintsInTable = 0x2202, + /// 8707 - Too many mints for table + #[error("Too many mints for table")] + TooManyMintsForTable = 0x2203, + /// 8708 - Weight table already initialized + #[error("Weight table already initialized")] + WeightTableAlreadyInitialized = 0x2204, + /// 8709 - Cannnot create future weight tables #[error("Cannnot create future weight tables")] - CannotCreateFutureWeightTables = 0x2201, + CannotCreateFutureWeightTables = 0x2205, + /// 8710 - Weight mints do not match - length + #[error("Weight mints do not match - length")] + WeightMintsDoNotMatchLength = 0x2206, + /// 8711 - Weight mints do not match - mint hash + #[error("Weight mints do not match - mint hash")] + WeightMintsDoNotMatchMintHash = 0x2207, + /// 8712 - Invalid mint for weight table + #[error("Invalid mint for weight table")] + InvalidMintForWeightTable = 0x2208, /// 8960 - Fee cap exceeded #[error("Fee cap exceeded")] FeeCapExceeded = 0x2300, diff --git a/clients/rust/jito_tip_router/src/generated/instructions/update_weight_table.rs b/clients/rust/jito_tip_router/src/generated/instructions/admin_update_weight_table.rs similarity index 79% rename from clients/rust/jito_tip_router/src/generated/instructions/update_weight_table.rs rename to clients/rust/jito_tip_router/src/generated/instructions/admin_update_weight_table.rs index c10f0ba..0df738f 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/update_weight_table.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/admin_update_weight_table.rs @@ -7,30 +7,32 @@ use borsh::{BorshDeserialize, BorshSerialize}; /// Accounts. -pub struct UpdateWeightTable { +pub struct AdminUpdateWeightTable { pub ncn: solana_program::pubkey::Pubkey, pub weight_table: solana_program::pubkey::Pubkey, pub weight_table_admin: solana_program::pubkey::Pubkey, + pub mint: solana_program::pubkey::Pubkey, + pub restaking_program_id: solana_program::pubkey::Pubkey, } -impl UpdateWeightTable { +impl AdminUpdateWeightTable { pub fn instruction( &self, - args: UpdateWeightTableInstructionArgs, + args: AdminUpdateWeightTableInstructionArgs, ) -> solana_program::instruction::Instruction { self.instruction_with_remaining_accounts(args, &[]) } #[allow(clippy::vec_init_then_push)] pub fn instruction_with_remaining_accounts( &self, - args: UpdateWeightTableInstructionArgs, + args: AdminUpdateWeightTableInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.ncn, false, )); @@ -42,12 +44,15 @@ impl UpdateWeightTable { self.weight_table_admin, true, )); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + self.mint, false, + )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.restaking_program_id, false, )); accounts.extend_from_slice(remaining_accounts); - let mut data = UpdateWeightTableInstructionData::new() + let mut data = AdminUpdateWeightTableInstructionData::new() .try_to_vec() .unwrap(); let mut args = args.try_to_vec().unwrap(); @@ -62,17 +67,17 @@ impl UpdateWeightTable { } #[derive(BorshDeserialize, BorshSerialize)] -pub struct UpdateWeightTableInstructionData { +pub struct AdminUpdateWeightTableInstructionData { discriminator: u8, } -impl UpdateWeightTableInstructionData { +impl AdminUpdateWeightTableInstructionData { pub fn new() -> Self { - Self { discriminator: 2 } + Self { discriminator: 4 } } } -impl Default for UpdateWeightTableInstructionData { +impl Default for AdminUpdateWeightTableInstructionData { fn default() -> Self { Self::new() } @@ -80,33 +85,33 @@ impl Default for UpdateWeightTableInstructionData { #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct UpdateWeightTableInstructionArgs { +pub struct AdminUpdateWeightTableInstructionArgs { pub ncn_epoch: u64, - pub weight_numerator: u64, - pub weight_denominator: u64, + pub weight: u128, } -/// Instruction builder for `UpdateWeightTable`. +/// Instruction builder for `AdminUpdateWeightTable`. /// /// ### Accounts: /// /// 0. `[]` ncn /// 1. `[writable]` weight_table /// 2. `[signer]` weight_table_admin -/// 3. `[]` restaking_program_id +/// 3. `[]` mint +/// 4. `[]` restaking_program_id #[derive(Clone, Debug, Default)] -pub struct UpdateWeightTableBuilder { +pub struct AdminUpdateWeightTableBuilder { ncn: Option, weight_table: Option, weight_table_admin: Option, + mint: Option, restaking_program_id: Option, ncn_epoch: Option, - weight_numerator: Option, - weight_denominator: Option, + weight: Option, __remaining_accounts: Vec, } -impl UpdateWeightTableBuilder { +impl AdminUpdateWeightTableBuilder { pub fn new() -> Self { Self::default() } @@ -129,6 +134,11 @@ impl UpdateWeightTableBuilder { self } #[inline(always)] + pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self { + self.mint = Some(mint); + self + } + #[inline(always)] pub fn restaking_program_id( &mut self, restaking_program_id: solana_program::pubkey::Pubkey, @@ -142,13 +152,8 @@ impl UpdateWeightTableBuilder { self } #[inline(always)] - pub fn weight_numerator(&mut self, weight_numerator: u64) -> &mut Self { - self.weight_numerator = Some(weight_numerator); - self - } - #[inline(always)] - pub fn weight_denominator(&mut self, weight_denominator: u64) -> &mut Self { - self.weight_denominator = Some(weight_denominator); + pub fn weight(&mut self, weight: u128) -> &mut Self { + self.weight = Some(weight); self } /// Add an additional account to the instruction. @@ -171,45 +176,41 @@ impl UpdateWeightTableBuilder { } #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { - let accounts = UpdateWeightTable { + let accounts = AdminUpdateWeightTable { ncn: self.ncn.expect("ncn is not set"), weight_table: self.weight_table.expect("weight_table is not set"), weight_table_admin: self .weight_table_admin .expect("weight_table_admin is not set"), + mint: self.mint.expect("mint is not set"), restaking_program_id: self .restaking_program_id .expect("restaking_program_id is not set"), }; - let args = UpdateWeightTableInstructionArgs { + let args = AdminUpdateWeightTableInstructionArgs { ncn_epoch: self.ncn_epoch.clone().expect("ncn_epoch is not set"), - weight_numerator: self - .weight_numerator - .clone() - .expect("weight_numerator is not set"), - weight_denominator: self - .weight_denominator - .clone() - .expect("weight_denominator is not set"), + weight: self.weight.clone().expect("weight is not set"), }; accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) } } -/// `update_weight_table` CPI accounts. -pub struct UpdateWeightTableCpiAccounts<'a, 'b> { +/// `admin_update_weight_table` CPI accounts. +pub struct AdminUpdateWeightTableCpiAccounts<'a, 'b> { pub ncn: &'b solana_program::account_info::AccountInfo<'a>, pub weight_table: &'b solana_program::account_info::AccountInfo<'a>, pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, + pub mint: &'b solana_program::account_info::AccountInfo<'a>, + pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, } -/// `update_weight_table` CPI instruction. -pub struct UpdateWeightTableCpi<'a, 'b> { +/// `admin_update_weight_table` CPI instruction. +pub struct AdminUpdateWeightTableCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, @@ -219,22 +220,25 @@ pub struct UpdateWeightTableCpi<'a, 'b> { pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, + pub mint: &'b solana_program::account_info::AccountInfo<'a>, + pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, /// The arguments for the instruction. - pub __args: UpdateWeightTableInstructionArgs, + pub __args: AdminUpdateWeightTableInstructionArgs, } -impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { +impl<'a, 'b> AdminUpdateWeightTableCpi<'a, 'b> { pub fn new( program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: UpdateWeightTableCpiAccounts<'a, 'b>, - args: UpdateWeightTableInstructionArgs, + accounts: AdminUpdateWeightTableCpiAccounts<'a, 'b>, + args: AdminUpdateWeightTableInstructionArgs, ) -> Self { Self { __program: program, ncn: accounts.ncn, weight_table: accounts.weight_table, weight_table_admin: accounts.weight_table_admin, + mint: accounts.mint, restaking_program_id: accounts.restaking_program_id, __args: args, } @@ -272,7 +276,7 @@ impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { bool, )], ) -> solana_program::entrypoint::ProgramResult { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new_readonly( *self.ncn.key, false, @@ -285,6 +289,10 @@ impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { *self.weight_table_admin.key, true, )); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + *self.mint.key, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( *self.restaking_program_id.key, false, @@ -296,7 +304,7 @@ impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { is_writable: remaining_account.2, }) }); - let mut data = UpdateWeightTableInstructionData::new() + let mut data = AdminUpdateWeightTableInstructionData::new() .try_to_vec() .unwrap(); let mut args = self.__args.try_to_vec().unwrap(); @@ -307,11 +315,12 @@ impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { accounts, data, }; - let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); + let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); account_infos.push(self.ncn.clone()); account_infos.push(self.weight_table.clone()); account_infos.push(self.weight_table_admin.clone()); + account_infos.push(self.mint.clone()); account_infos.push(self.restaking_program_id.clone()); remaining_accounts .iter() @@ -325,30 +334,31 @@ impl<'a, 'b> UpdateWeightTableCpi<'a, 'b> { } } -/// Instruction builder for `UpdateWeightTable` via CPI. +/// Instruction builder for `AdminUpdateWeightTable` via CPI. /// /// ### Accounts: /// /// 0. `[]` ncn /// 1. `[writable]` weight_table /// 2. `[signer]` weight_table_admin -/// 3. `[]` restaking_program_id +/// 3. `[]` mint +/// 4. `[]` restaking_program_id #[derive(Clone, Debug)] -pub struct UpdateWeightTableCpiBuilder<'a, 'b> { - instruction: Box>, +pub struct AdminUpdateWeightTableCpiBuilder<'a, 'b> { + instruction: Box>, } -impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { +impl<'a, 'b> AdminUpdateWeightTableCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(UpdateWeightTableCpiBuilderInstruction { + let instruction = Box::new(AdminUpdateWeightTableCpiBuilderInstruction { __program: program, ncn: None, weight_table: None, weight_table_admin: None, + mint: None, restaking_program_id: None, ncn_epoch: None, - weight_numerator: None, - weight_denominator: None, + weight: None, __remaining_accounts: Vec::new(), }); Self { instruction } @@ -375,6 +385,11 @@ impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { self } #[inline(always)] + pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.mint = Some(mint); + self + } + #[inline(always)] pub fn restaking_program_id( &mut self, restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, @@ -388,13 +403,8 @@ impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { self } #[inline(always)] - pub fn weight_numerator(&mut self, weight_numerator: u64) -> &mut Self { - self.instruction.weight_numerator = Some(weight_numerator); - self - } - #[inline(always)] - pub fn weight_denominator(&mut self, weight_denominator: u64) -> &mut Self { - self.instruction.weight_denominator = Some(weight_denominator); + pub fn weight(&mut self, weight: u128) -> &mut Self { + self.instruction.weight = Some(weight); self } /// Add an additional account to the instruction. @@ -438,24 +448,15 @@ impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { &self, signers_seeds: &[&[&[u8]]], ) -> solana_program::entrypoint::ProgramResult { - let args = UpdateWeightTableInstructionArgs { + let args = AdminUpdateWeightTableInstructionArgs { ncn_epoch: self .instruction .ncn_epoch .clone() .expect("ncn_epoch is not set"), - weight_numerator: self - .instruction - .weight_numerator - .clone() - .expect("weight_numerator is not set"), - weight_denominator: self - .instruction - .weight_denominator - .clone() - .expect("weight_denominator is not set"), + weight: self.instruction.weight.clone().expect("weight is not set"), }; - let instruction = UpdateWeightTableCpi { + let instruction = AdminUpdateWeightTableCpi { __program: self.instruction.__program, ncn: self.instruction.ncn.expect("ncn is not set"), @@ -470,6 +471,8 @@ impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { .weight_table_admin .expect("weight_table_admin is not set"), + mint: self.instruction.mint.expect("mint is not set"), + restaking_program_id: self .instruction .restaking_program_id @@ -484,15 +487,15 @@ impl<'a, 'b> UpdateWeightTableCpiBuilder<'a, 'b> { } #[derive(Clone, Debug)] -struct UpdateWeightTableCpiBuilderInstruction<'a, 'b> { +struct AdminUpdateWeightTableCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, ncn: Option<&'b solana_program::account_info::AccountInfo<'a>>, weight_table: Option<&'b solana_program::account_info::AccountInfo<'a>>, weight_table_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>, + mint: Option<&'b solana_program::account_info::AccountInfo<'a>>, restaking_program_id: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn_epoch: Option, - weight_numerator: Option, - weight_denominator: Option, + weight: Option, /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. __remaining_accounts: Vec<( &'b solana_program::account_info::AccountInfo<'a>, diff --git a/clients/rust/jito_tip_router/src/generated/instructions/finalize_weight_table.rs b/clients/rust/jito_tip_router/src/generated/instructions/finalize_weight_table.rs deleted file mode 100644 index 16cac74..0000000 --- a/clients/rust/jito_tip_router/src/generated/instructions/finalize_weight_table.rs +++ /dev/null @@ -1,456 +0,0 @@ -//! This code was AUTOGENERATED using the kinobi library. -//! Please DO NOT EDIT THIS FILE, instead use visitors -//! to add features, then rerun kinobi to update it. -//! -//! - -use borsh::{BorshDeserialize, BorshSerialize}; - -/// Accounts. -pub struct FinalizeWeightTable { - pub ncn: solana_program::pubkey::Pubkey, - - pub weight_table: solana_program::pubkey::Pubkey, - - pub weight_table_admin: solana_program::pubkey::Pubkey, - - pub restaking_program_id: solana_program::pubkey::Pubkey, -} - -impl FinalizeWeightTable { - pub fn instruction( - &self, - args: FinalizeWeightTableInstructionArgs, - ) -> solana_program::instruction::Instruction { - self.instruction_with_remaining_accounts(args, &[]) - } - #[allow(clippy::vec_init_then_push)] - pub fn instruction_with_remaining_accounts( - &self, - args: FinalizeWeightTableInstructionArgs, - remaining_accounts: &[solana_program::instruction::AccountMeta], - ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - self.ncn, false, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - self.weight_table, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - self.weight_table_admin, - true, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - self.restaking_program_id, - false, - )); - accounts.extend_from_slice(remaining_accounts); - let mut data = FinalizeWeightTableInstructionData::new() - .try_to_vec() - .unwrap(); - let mut args = args.try_to_vec().unwrap(); - data.append(&mut args); - - solana_program::instruction::Instruction { - program_id: crate::JITO_TIP_ROUTER_ID, - accounts, - data, - } - } -} - -#[derive(BorshDeserialize, BorshSerialize)] -pub struct FinalizeWeightTableInstructionData { - discriminator: u8, -} - -impl FinalizeWeightTableInstructionData { - pub fn new() -> Self { - Self { discriminator: 3 } - } -} - -impl Default for FinalizeWeightTableInstructionData { - fn default() -> Self { - Self::new() - } -} - -#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct FinalizeWeightTableInstructionArgs { - pub ncn_epoch: u64, -} - -/// Instruction builder for `FinalizeWeightTable`. -/// -/// ### Accounts: -/// -/// 0. `[]` ncn -/// 1. `[writable]` weight_table -/// 2. `[signer]` weight_table_admin -/// 3. `[]` restaking_program_id -#[derive(Clone, Debug, Default)] -pub struct FinalizeWeightTableBuilder { - ncn: Option, - weight_table: Option, - weight_table_admin: Option, - restaking_program_id: Option, - ncn_epoch: Option, - __remaining_accounts: Vec, -} - -impl FinalizeWeightTableBuilder { - pub fn new() -> Self { - Self::default() - } - #[inline(always)] - pub fn ncn(&mut self, ncn: solana_program::pubkey::Pubkey) -> &mut Self { - self.ncn = Some(ncn); - self - } - #[inline(always)] - pub fn weight_table(&mut self, weight_table: solana_program::pubkey::Pubkey) -> &mut Self { - self.weight_table = Some(weight_table); - self - } - #[inline(always)] - pub fn weight_table_admin( - &mut self, - weight_table_admin: solana_program::pubkey::Pubkey, - ) -> &mut Self { - self.weight_table_admin = Some(weight_table_admin); - self - } - #[inline(always)] - pub fn restaking_program_id( - &mut self, - restaking_program_id: solana_program::pubkey::Pubkey, - ) -> &mut Self { - self.restaking_program_id = Some(restaking_program_id); - self - } - #[inline(always)] - pub fn ncn_epoch(&mut self, ncn_epoch: u64) -> &mut Self { - self.ncn_epoch = Some(ncn_epoch); - self - } - /// Add an additional account to the instruction. - #[inline(always)] - pub fn add_remaining_account( - &mut self, - account: solana_program::instruction::AccountMeta, - ) -> &mut Self { - self.__remaining_accounts.push(account); - self - } - /// Add additional accounts to the instruction. - #[inline(always)] - pub fn add_remaining_accounts( - &mut self, - accounts: &[solana_program::instruction::AccountMeta], - ) -> &mut Self { - self.__remaining_accounts.extend_from_slice(accounts); - self - } - #[allow(clippy::clone_on_copy)] - pub fn instruction(&self) -> solana_program::instruction::Instruction { - let accounts = FinalizeWeightTable { - ncn: self.ncn.expect("ncn is not set"), - weight_table: self.weight_table.expect("weight_table is not set"), - weight_table_admin: self - .weight_table_admin - .expect("weight_table_admin is not set"), - restaking_program_id: self - .restaking_program_id - .expect("restaking_program_id is not set"), - }; - let args = FinalizeWeightTableInstructionArgs { - ncn_epoch: self.ncn_epoch.clone().expect("ncn_epoch is not set"), - }; - - accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts) - } -} - -/// `finalize_weight_table` CPI accounts. -pub struct FinalizeWeightTableCpiAccounts<'a, 'b> { - pub ncn: &'b solana_program::account_info::AccountInfo<'a>, - - pub weight_table: &'b solana_program::account_info::AccountInfo<'a>, - - pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, - - pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, -} - -/// `finalize_weight_table` CPI instruction. -pub struct FinalizeWeightTableCpi<'a, 'b> { - /// The program to invoke. - pub __program: &'b solana_program::account_info::AccountInfo<'a>, - - pub ncn: &'b solana_program::account_info::AccountInfo<'a>, - - pub weight_table: &'b solana_program::account_info::AccountInfo<'a>, - - pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, - - pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, - /// The arguments for the instruction. - pub __args: FinalizeWeightTableInstructionArgs, -} - -impl<'a, 'b> FinalizeWeightTableCpi<'a, 'b> { - pub fn new( - program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: FinalizeWeightTableCpiAccounts<'a, 'b>, - args: FinalizeWeightTableInstructionArgs, - ) -> Self { - Self { - __program: program, - ncn: accounts.ncn, - weight_table: accounts.weight_table, - weight_table_admin: accounts.weight_table_admin, - restaking_program_id: accounts.restaking_program_id, - __args: args, - } - } - #[inline(always)] - pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult { - self.invoke_signed_with_remaining_accounts(&[], &[]) - } - #[inline(always)] - pub fn invoke_with_remaining_accounts( - &self, - remaining_accounts: &[( - &'b solana_program::account_info::AccountInfo<'a>, - bool, - bool, - )], - ) -> solana_program::entrypoint::ProgramResult { - self.invoke_signed_with_remaining_accounts(&[], remaining_accounts) - } - #[inline(always)] - pub fn invoke_signed( - &self, - signers_seeds: &[&[&[u8]]], - ) -> solana_program::entrypoint::ProgramResult { - self.invoke_signed_with_remaining_accounts(signers_seeds, &[]) - } - #[allow(clippy::clone_on_copy)] - #[allow(clippy::vec_init_then_push)] - pub fn invoke_signed_with_remaining_accounts( - &self, - signers_seeds: &[&[&[u8]]], - remaining_accounts: &[( - &'b solana_program::account_info::AccountInfo<'a>, - bool, - bool, - )], - ) -> solana_program::entrypoint::ProgramResult { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - *self.ncn.key, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new( - *self.weight_table.key, - false, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - *self.weight_table_admin.key, - true, - )); - accounts.push(solana_program::instruction::AccountMeta::new_readonly( - *self.restaking_program_id.key, - false, - )); - remaining_accounts.iter().for_each(|remaining_account| { - accounts.push(solana_program::instruction::AccountMeta { - pubkey: *remaining_account.0.key, - is_signer: remaining_account.1, - is_writable: remaining_account.2, - }) - }); - let mut data = FinalizeWeightTableInstructionData::new() - .try_to_vec() - .unwrap(); - let mut args = self.__args.try_to_vec().unwrap(); - data.append(&mut args); - - let instruction = solana_program::instruction::Instruction { - program_id: crate::JITO_TIP_ROUTER_ID, - accounts, - data, - }; - let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); - account_infos.push(self.__program.clone()); - account_infos.push(self.ncn.clone()); - account_infos.push(self.weight_table.clone()); - account_infos.push(self.weight_table_admin.clone()); - account_infos.push(self.restaking_program_id.clone()); - remaining_accounts - .iter() - .for_each(|remaining_account| account_infos.push(remaining_account.0.clone())); - - if signers_seeds.is_empty() { - solana_program::program::invoke(&instruction, &account_infos) - } else { - solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds) - } - } -} - -/// Instruction builder for `FinalizeWeightTable` via CPI. -/// -/// ### Accounts: -/// -/// 0. `[]` ncn -/// 1. `[writable]` weight_table -/// 2. `[signer]` weight_table_admin -/// 3. `[]` restaking_program_id -#[derive(Clone, Debug)] -pub struct FinalizeWeightTableCpiBuilder<'a, 'b> { - instruction: Box>, -} - -impl<'a, 'b> FinalizeWeightTableCpiBuilder<'a, 'b> { - pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(FinalizeWeightTableCpiBuilderInstruction { - __program: program, - ncn: None, - weight_table: None, - weight_table_admin: None, - restaking_program_id: None, - ncn_epoch: None, - __remaining_accounts: Vec::new(), - }); - Self { instruction } - } - #[inline(always)] - pub fn ncn(&mut self, ncn: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { - self.instruction.ncn = Some(ncn); - self - } - #[inline(always)] - pub fn weight_table( - &mut self, - weight_table: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.weight_table = Some(weight_table); - self - } - #[inline(always)] - pub fn weight_table_admin( - &mut self, - weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.weight_table_admin = Some(weight_table_admin); - self - } - #[inline(always)] - pub fn restaking_program_id( - &mut self, - restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.restaking_program_id = Some(restaking_program_id); - self - } - #[inline(always)] - pub fn ncn_epoch(&mut self, ncn_epoch: u64) -> &mut Self { - self.instruction.ncn_epoch = Some(ncn_epoch); - self - } - /// Add an additional account to the instruction. - #[inline(always)] - pub fn add_remaining_account( - &mut self, - account: &'b solana_program::account_info::AccountInfo<'a>, - is_writable: bool, - is_signer: bool, - ) -> &mut Self { - self.instruction - .__remaining_accounts - .push((account, is_writable, is_signer)); - self - } - /// Add additional accounts to the instruction. - /// - /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not, - /// and a `bool` indicating whether the account is a signer or not. - #[inline(always)] - pub fn add_remaining_accounts( - &mut self, - accounts: &[( - &'b solana_program::account_info::AccountInfo<'a>, - bool, - bool, - )], - ) -> &mut Self { - self.instruction - .__remaining_accounts - .extend_from_slice(accounts); - self - } - #[inline(always)] - pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult { - self.invoke_signed(&[]) - } - #[allow(clippy::clone_on_copy)] - #[allow(clippy::vec_init_then_push)] - pub fn invoke_signed( - &self, - signers_seeds: &[&[&[u8]]], - ) -> solana_program::entrypoint::ProgramResult { - let args = FinalizeWeightTableInstructionArgs { - ncn_epoch: self - .instruction - .ncn_epoch - .clone() - .expect("ncn_epoch is not set"), - }; - let instruction = FinalizeWeightTableCpi { - __program: self.instruction.__program, - - ncn: self.instruction.ncn.expect("ncn is not set"), - - weight_table: self - .instruction - .weight_table - .expect("weight_table is not set"), - - weight_table_admin: self - .instruction - .weight_table_admin - .expect("weight_table_admin is not set"), - - restaking_program_id: self - .instruction - .restaking_program_id - .expect("restaking_program_id is not set"), - __args: args, - }; - instruction.invoke_signed_with_remaining_accounts( - signers_seeds, - &self.instruction.__remaining_accounts, - ) - } -} - -#[derive(Clone, Debug)] -struct FinalizeWeightTableCpiBuilderInstruction<'a, 'b> { - __program: &'b solana_program::account_info::AccountInfo<'a>, - ncn: Option<&'b solana_program::account_info::AccountInfo<'a>>, - weight_table: Option<&'b solana_program::account_info::AccountInfo<'a>>, - weight_table_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>, - restaking_program_id: Option<&'b solana_program::account_info::AccountInfo<'a>>, - ncn_epoch: Option, - /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`. - __remaining_accounts: Vec<( - &'b solana_program::account_info::AccountInfo<'a>, - bool, - bool, - )>, -} diff --git a/clients/rust/jito_tip_router/src/generated/instructions/initialize_config.rs b/clients/rust/jito_tip_router/src/generated/instructions/initialize_n_c_n_config.rs similarity index 78% rename from clients/rust/jito_tip_router/src/generated/instructions/initialize_config.rs rename to clients/rust/jito_tip_router/src/generated/instructions/initialize_n_c_n_config.rs index 2e718af..1806829 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/initialize_config.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/initialize_n_c_n_config.rs @@ -7,8 +7,10 @@ use borsh::{BorshDeserialize, BorshSerialize}; /// Accounts. -pub struct InitializeConfig { - pub config: solana_program::pubkey::Pubkey, +pub struct InitializeNCNConfig { + pub restaking_config: solana_program::pubkey::Pubkey, + + pub ncn_config: solana_program::pubkey::Pubkey, pub ncn: solana_program::pubkey::Pubkey, @@ -23,22 +25,26 @@ pub struct InitializeConfig { pub system_program: solana_program::pubkey::Pubkey, } -impl InitializeConfig { +impl InitializeNCNConfig { pub fn instruction( &self, - args: InitializeConfigInstructionArgs, + args: InitializeNCNConfigInstructionArgs, ) -> solana_program::instruction::Instruction { self.instruction_with_remaining_accounts(args, &[]) } #[allow(clippy::vec_init_then_push)] pub fn instruction_with_remaining_accounts( &self, - args: InitializeConfigInstructionArgs, + args: InitializeNCNConfigInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(7 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(8 + remaining_accounts.len()); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + self.restaking_config, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new( - self.config, + self.ncn_config, false, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( @@ -65,7 +71,9 @@ impl InitializeConfig { false, )); accounts.extend_from_slice(remaining_accounts); - let mut data = InitializeConfigInstructionData::new().try_to_vec().unwrap(); + let mut data = InitializeNCNConfigInstructionData::new() + .try_to_vec() + .unwrap(); let mut args = args.try_to_vec().unwrap(); data.append(&mut args); @@ -78,17 +86,17 @@ impl InitializeConfig { } #[derive(BorshDeserialize, BorshSerialize)] -pub struct InitializeConfigInstructionData { +pub struct InitializeNCNConfigInstructionData { discriminator: u8, } -impl InitializeConfigInstructionData { +impl InitializeNCNConfigInstructionData { pub fn new() -> Self { Self { discriminator: 0 } } } -impl Default for InitializeConfigInstructionData { +impl Default for InitializeNCNConfigInstructionData { fn default() -> Self { Self::new() } @@ -96,26 +104,28 @@ impl Default for InitializeConfigInstructionData { #[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct InitializeConfigInstructionArgs { +pub struct InitializeNCNConfigInstructionArgs { pub dao_fee_bps: u64, pub ncn_fee_bps: u64, pub block_engine_fee_bps: u64, } -/// Instruction builder for `InitializeConfig`. +/// Instruction builder for `InitializeNCNConfig`. /// /// ### Accounts: /// -/// 0. `[writable]` config -/// 1. `[]` ncn -/// 2. `[signer]` ncn_admin -/// 3. `[]` fee_wallet -/// 4. `[]` tie_breaker_admin -/// 5. `[]` restaking_program_id -/// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 0. `[]` restaking_config +/// 1. `[writable]` ncn_config +/// 2. `[]` ncn +/// 3. `[signer]` ncn_admin +/// 4. `[]` fee_wallet +/// 5. `[]` tie_breaker_admin +/// 6. `[]` restaking_program_id +/// 7. `[optional]` system_program (default to `11111111111111111111111111111111`) #[derive(Clone, Debug, Default)] -pub struct InitializeConfigBuilder { - config: Option, +pub struct InitializeNCNConfigBuilder { + restaking_config: Option, + ncn_config: Option, ncn: Option, ncn_admin: Option, fee_wallet: Option, @@ -128,13 +138,21 @@ pub struct InitializeConfigBuilder { __remaining_accounts: Vec, } -impl InitializeConfigBuilder { +impl InitializeNCNConfigBuilder { pub fn new() -> Self { Self::default() } #[inline(always)] - pub fn config(&mut self, config: solana_program::pubkey::Pubkey) -> &mut Self { - self.config = Some(config); + pub fn restaking_config( + &mut self, + restaking_config: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.restaking_config = Some(restaking_config); + self + } + #[inline(always)] + pub fn ncn_config(&mut self, ncn_config: solana_program::pubkey::Pubkey) -> &mut Self { + self.ncn_config = Some(ncn_config); self } #[inline(always)] @@ -209,8 +227,9 @@ impl InitializeConfigBuilder { } #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { - let accounts = InitializeConfig { - config: self.config.expect("config is not set"), + let accounts = InitializeNCNConfig { + restaking_config: self.restaking_config.expect("restaking_config is not set"), + ncn_config: self.ncn_config.expect("ncn_config is not set"), ncn: self.ncn.expect("ncn is not set"), ncn_admin: self.ncn_admin.expect("ncn_admin is not set"), fee_wallet: self.fee_wallet.expect("fee_wallet is not set"), @@ -224,7 +243,7 @@ impl InitializeConfigBuilder { .system_program .unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")), }; - let args = InitializeConfigInstructionArgs { + let args = InitializeNCNConfigInstructionArgs { dao_fee_bps: self.dao_fee_bps.clone().expect("dao_fee_bps is not set"), ncn_fee_bps: self.ncn_fee_bps.clone().expect("ncn_fee_bps is not set"), block_engine_fee_bps: self @@ -237,9 +256,11 @@ impl InitializeConfigBuilder { } } -/// `initialize_config` CPI accounts. -pub struct InitializeConfigCpiAccounts<'a, 'b> { - pub config: &'b solana_program::account_info::AccountInfo<'a>, +/// `initialize_n_c_n_config` CPI accounts. +pub struct InitializeNCNConfigCpiAccounts<'a, 'b> { + pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + + pub ncn_config: &'b solana_program::account_info::AccountInfo<'a>, pub ncn: &'b solana_program::account_info::AccountInfo<'a>, @@ -254,12 +275,14 @@ pub struct InitializeConfigCpiAccounts<'a, 'b> { pub system_program: &'b solana_program::account_info::AccountInfo<'a>, } -/// `initialize_config` CPI instruction. -pub struct InitializeConfigCpi<'a, 'b> { +/// `initialize_n_c_n_config` CPI instruction. +pub struct InitializeNCNConfigCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, - pub config: &'b solana_program::account_info::AccountInfo<'a>, + pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + + pub ncn_config: &'b solana_program::account_info::AccountInfo<'a>, pub ncn: &'b solana_program::account_info::AccountInfo<'a>, @@ -273,18 +296,19 @@ pub struct InitializeConfigCpi<'a, 'b> { pub system_program: &'b solana_program::account_info::AccountInfo<'a>, /// The arguments for the instruction. - pub __args: InitializeConfigInstructionArgs, + pub __args: InitializeNCNConfigInstructionArgs, } -impl<'a, 'b> InitializeConfigCpi<'a, 'b> { +impl<'a, 'b> InitializeNCNConfigCpi<'a, 'b> { pub fn new( program: &'b solana_program::account_info::AccountInfo<'a>, - accounts: InitializeConfigCpiAccounts<'a, 'b>, - args: InitializeConfigInstructionArgs, + accounts: InitializeNCNConfigCpiAccounts<'a, 'b>, + args: InitializeNCNConfigInstructionArgs, ) -> Self { Self { __program: program, - config: accounts.config, + restaking_config: accounts.restaking_config, + ncn_config: accounts.ncn_config, ncn: accounts.ncn, ncn_admin: accounts.ncn_admin, fee_wallet: accounts.fee_wallet, @@ -327,9 +351,13 @@ impl<'a, 'b> InitializeConfigCpi<'a, 'b> { bool, )], ) -> solana_program::entrypoint::ProgramResult { - let mut accounts = Vec::with_capacity(7 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(8 + remaining_accounts.len()); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + *self.restaking_config.key, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.config.key, + *self.ncn_config.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( @@ -363,7 +391,9 @@ impl<'a, 'b> InitializeConfigCpi<'a, 'b> { is_writable: remaining_account.2, }) }); - let mut data = InitializeConfigInstructionData::new().try_to_vec().unwrap(); + let mut data = InitializeNCNConfigInstructionData::new() + .try_to_vec() + .unwrap(); let mut args = self.__args.try_to_vec().unwrap(); data.append(&mut args); @@ -372,9 +402,10 @@ impl<'a, 'b> InitializeConfigCpi<'a, 'b> { accounts, data, }; - let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len()); + let mut account_infos = Vec::with_capacity(8 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); - account_infos.push(self.config.clone()); + account_infos.push(self.restaking_config.clone()); + account_infos.push(self.ncn_config.clone()); account_infos.push(self.ncn.clone()); account_infos.push(self.ncn_admin.clone()); account_infos.push(self.fee_wallet.clone()); @@ -393,27 +424,29 @@ impl<'a, 'b> InitializeConfigCpi<'a, 'b> { } } -/// Instruction builder for `InitializeConfig` via CPI. +/// Instruction builder for `InitializeNCNConfig` via CPI. /// /// ### Accounts: /// -/// 0. `[writable]` config -/// 1. `[]` ncn -/// 2. `[signer]` ncn_admin -/// 3. `[]` fee_wallet -/// 4. `[]` tie_breaker_admin -/// 5. `[]` restaking_program_id -/// 6. `[]` system_program +/// 0. `[]` restaking_config +/// 1. `[writable]` ncn_config +/// 2. `[]` ncn +/// 3. `[signer]` ncn_admin +/// 4. `[]` fee_wallet +/// 5. `[]` tie_breaker_admin +/// 6. `[]` restaking_program_id +/// 7. `[]` system_program #[derive(Clone, Debug)] -pub struct InitializeConfigCpiBuilder<'a, 'b> { - instruction: Box>, +pub struct InitializeNCNConfigCpiBuilder<'a, 'b> { + instruction: Box>, } -impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> { +impl<'a, 'b> InitializeNCNConfigCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { - let instruction = Box::new(InitializeConfigCpiBuilderInstruction { + let instruction = Box::new(InitializeNCNConfigCpiBuilderInstruction { __program: program, - config: None, + restaking_config: None, + ncn_config: None, ncn: None, ncn_admin: None, fee_wallet: None, @@ -428,11 +461,19 @@ impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> { Self { instruction } } #[inline(always)] - pub fn config( + pub fn restaking_config( + &mut self, + restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.restaking_config = Some(restaking_config); + self + } + #[inline(always)] + pub fn ncn_config( &mut self, - config: &'b solana_program::account_info::AccountInfo<'a>, + ncn_config: &'b solana_program::account_info::AccountInfo<'a>, ) -> &mut Self { - self.instruction.config = Some(config); + self.instruction.ncn_config = Some(ncn_config); self } #[inline(always)] @@ -536,7 +577,7 @@ impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> { &self, signers_seeds: &[&[&[u8]]], ) -> solana_program::entrypoint::ProgramResult { - let args = InitializeConfigInstructionArgs { + let args = InitializeNCNConfigInstructionArgs { dao_fee_bps: self .instruction .dao_fee_bps @@ -553,10 +594,15 @@ impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> { .clone() .expect("block_engine_fee_bps is not set"), }; - let instruction = InitializeConfigCpi { + let instruction = InitializeNCNConfigCpi { __program: self.instruction.__program, - config: self.instruction.config.expect("config is not set"), + restaking_config: self + .instruction + .restaking_config + .expect("restaking_config is not set"), + + ncn_config: self.instruction.ncn_config.expect("ncn_config is not set"), ncn: self.instruction.ncn.expect("ncn is not set"), @@ -588,9 +634,10 @@ impl<'a, 'b> InitializeConfigCpiBuilder<'a, 'b> { } #[derive(Clone, Debug)] -struct InitializeConfigCpiBuilderInstruction<'a, 'b> { +struct InitializeNCNConfigCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, - config: Option<&'b solana_program::account_info::AccountInfo<'a>>, + restaking_config: Option<&'b solana_program::account_info::AccountInfo<'a>>, + ncn_config: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>, fee_wallet: Option<&'b solana_program::account_info::AccountInfo<'a>>, diff --git a/clients/rust/jito_tip_router/src/generated/instructions/initialize_weight_table.rs b/clients/rust/jito_tip_router/src/generated/instructions/initialize_weight_table.rs index b839b5e..1c703fc 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/initialize_weight_table.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/initialize_weight_table.rs @@ -10,11 +10,13 @@ use borsh::{BorshDeserialize, BorshSerialize}; pub struct InitializeWeightTable { pub restaking_config: solana_program::pubkey::Pubkey, + pub ncn_config: solana_program::pubkey::Pubkey, + pub ncn: solana_program::pubkey::Pubkey, pub weight_table: solana_program::pubkey::Pubkey, - pub weight_table_admin: solana_program::pubkey::Pubkey, + pub payer: solana_program::pubkey::Pubkey, pub restaking_program_id: solana_program::pubkey::Pubkey, @@ -34,21 +36,24 @@ impl InitializeWeightTable { args: InitializeWeightTableInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(6 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(7 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.restaking_config, false, )); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + self.ncn_config, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.ncn, false, )); accounts.push(solana_program::instruction::AccountMeta::new( self.weight_table, - true, + false, )); accounts.push(solana_program::instruction::AccountMeta::new( - self.weight_table_admin, - true, + self.payer, true, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( self.restaking_program_id, @@ -80,7 +85,7 @@ pub struct InitializeWeightTableInstructionData { impl InitializeWeightTableInstructionData { pub fn new() -> Self { - Self { discriminator: 1 } + Self { discriminator: 3 } } } @@ -101,17 +106,19 @@ pub struct InitializeWeightTableInstructionArgs { /// ### Accounts: /// /// 0. `[]` restaking_config -/// 1. `[]` ncn -/// 2. `[writable, signer]` weight_table -/// 3. `[writable, signer]` weight_table_admin -/// 4. `[]` restaking_program_id -/// 5. `[optional]` system_program (default to `11111111111111111111111111111111`) +/// 1. `[]` ncn_config +/// 2. `[]` ncn +/// 3. `[writable]` weight_table +/// 4. `[writable, signer]` payer +/// 5. `[]` restaking_program_id +/// 6. `[optional]` system_program (default to `11111111111111111111111111111111`) #[derive(Clone, Debug, Default)] pub struct InitializeWeightTableBuilder { restaking_config: Option, + ncn_config: Option, ncn: Option, weight_table: Option, - weight_table_admin: Option, + payer: Option, restaking_program_id: Option, system_program: Option, first_slot_of_ncn_epoch: Option, @@ -131,6 +138,11 @@ impl InitializeWeightTableBuilder { self } #[inline(always)] + pub fn ncn_config(&mut self, ncn_config: solana_program::pubkey::Pubkey) -> &mut Self { + self.ncn_config = Some(ncn_config); + self + } + #[inline(always)] pub fn ncn(&mut self, ncn: solana_program::pubkey::Pubkey) -> &mut Self { self.ncn = Some(ncn); self @@ -141,11 +153,8 @@ impl InitializeWeightTableBuilder { self } #[inline(always)] - pub fn weight_table_admin( - &mut self, - weight_table_admin: solana_program::pubkey::Pubkey, - ) -> &mut Self { - self.weight_table_admin = Some(weight_table_admin); + pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self { + self.payer = Some(payer); self } #[inline(always)] @@ -190,11 +199,10 @@ impl InitializeWeightTableBuilder { pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = InitializeWeightTable { restaking_config: self.restaking_config.expect("restaking_config is not set"), + ncn_config: self.ncn_config.expect("ncn_config is not set"), ncn: self.ncn.expect("ncn is not set"), weight_table: self.weight_table.expect("weight_table is not set"), - weight_table_admin: self - .weight_table_admin - .expect("weight_table_admin is not set"), + payer: self.payer.expect("payer is not set"), restaking_program_id: self .restaking_program_id .expect("restaking_program_id is not set"), @@ -214,11 +222,13 @@ impl InitializeWeightTableBuilder { pub struct InitializeWeightTableCpiAccounts<'a, 'b> { pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + pub ncn_config: &'b solana_program::account_info::AccountInfo<'a>, + pub ncn: &'b solana_program::account_info::AccountInfo<'a>, pub weight_table: &'b solana_program::account_info::AccountInfo<'a>, - pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, + pub payer: &'b solana_program::account_info::AccountInfo<'a>, pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, @@ -232,11 +242,13 @@ pub struct InitializeWeightTableCpi<'a, 'b> { pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + pub ncn_config: &'b solana_program::account_info::AccountInfo<'a>, + pub ncn: &'b solana_program::account_info::AccountInfo<'a>, pub weight_table: &'b solana_program::account_info::AccountInfo<'a>, - pub weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, + pub payer: &'b solana_program::account_info::AccountInfo<'a>, pub restaking_program_id: &'b solana_program::account_info::AccountInfo<'a>, @@ -254,9 +266,10 @@ impl<'a, 'b> InitializeWeightTableCpi<'a, 'b> { Self { __program: program, restaking_config: accounts.restaking_config, + ncn_config: accounts.ncn_config, ncn: accounts.ncn, weight_table: accounts.weight_table, - weight_table_admin: accounts.weight_table_admin, + payer: accounts.payer, restaking_program_id: accounts.restaking_program_id, system_program: accounts.system_program, __args: args, @@ -295,21 +308,25 @@ impl<'a, 'b> InitializeWeightTableCpi<'a, 'b> { bool, )], ) -> solana_program::entrypoint::ProgramResult { - let mut accounts = Vec::with_capacity(6 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(7 + remaining_accounts.len()); accounts.push(solana_program::instruction::AccountMeta::new_readonly( *self.restaking_config.key, false, )); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + *self.ncn_config.key, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( *self.ncn.key, false, )); accounts.push(solana_program::instruction::AccountMeta::new( *self.weight_table.key, - true, + false, )); accounts.push(solana_program::instruction::AccountMeta::new( - *self.weight_table_admin.key, + *self.payer.key, true, )); accounts.push(solana_program::instruction::AccountMeta::new_readonly( @@ -338,12 +355,13 @@ impl<'a, 'b> InitializeWeightTableCpi<'a, 'b> { accounts, data, }; - let mut account_infos = Vec::with_capacity(6 + 1 + remaining_accounts.len()); + let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); account_infos.push(self.restaking_config.clone()); + account_infos.push(self.ncn_config.clone()); account_infos.push(self.ncn.clone()); account_infos.push(self.weight_table.clone()); - account_infos.push(self.weight_table_admin.clone()); + account_infos.push(self.payer.clone()); account_infos.push(self.restaking_program_id.clone()); account_infos.push(self.system_program.clone()); remaining_accounts @@ -363,11 +381,12 @@ impl<'a, 'b> InitializeWeightTableCpi<'a, 'b> { /// ### Accounts: /// /// 0. `[]` restaking_config -/// 1. `[]` ncn -/// 2. `[writable, signer]` weight_table -/// 3. `[writable, signer]` weight_table_admin -/// 4. `[]` restaking_program_id -/// 5. `[]` system_program +/// 1. `[]` ncn_config +/// 2. `[]` ncn +/// 3. `[writable]` weight_table +/// 4. `[writable, signer]` payer +/// 5. `[]` restaking_program_id +/// 6. `[]` system_program #[derive(Clone, Debug)] pub struct InitializeWeightTableCpiBuilder<'a, 'b> { instruction: Box>, @@ -378,9 +397,10 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { let instruction = Box::new(InitializeWeightTableCpiBuilderInstruction { __program: program, restaking_config: None, + ncn_config: None, ncn: None, weight_table: None, - weight_table_admin: None, + payer: None, restaking_program_id: None, system_program: None, first_slot_of_ncn_epoch: None, @@ -397,6 +417,14 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { self } #[inline(always)] + pub fn ncn_config( + &mut self, + ncn_config: &'b solana_program::account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.ncn_config = Some(ncn_config); + self + } + #[inline(always)] pub fn ncn(&mut self, ncn: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { self.instruction.ncn = Some(ncn); self @@ -410,11 +438,8 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { self } #[inline(always)] - pub fn weight_table_admin( - &mut self, - weight_table_admin: &'b solana_program::account_info::AccountInfo<'a>, - ) -> &mut Self { - self.instruction.weight_table_admin = Some(weight_table_admin); + pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self { + self.instruction.payer = Some(payer); self } #[inline(always)] @@ -491,6 +516,8 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { .restaking_config .expect("restaking_config is not set"), + ncn_config: self.instruction.ncn_config.expect("ncn_config is not set"), + ncn: self.instruction.ncn.expect("ncn is not set"), weight_table: self @@ -498,10 +525,7 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { .weight_table .expect("weight_table is not set"), - weight_table_admin: self - .instruction - .weight_table_admin - .expect("weight_table_admin is not set"), + payer: self.instruction.payer.expect("payer is not set"), restaking_program_id: self .instruction @@ -525,9 +549,10 @@ impl<'a, 'b> InitializeWeightTableCpiBuilder<'a, 'b> { struct InitializeWeightTableCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, restaking_config: Option<&'b solana_program::account_info::AccountInfo<'a>>, + ncn_config: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn: Option<&'b solana_program::account_info::AccountInfo<'a>>, weight_table: Option<&'b solana_program::account_info::AccountInfo<'a>>, - weight_table_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>, + payer: Option<&'b solana_program::account_info::AccountInfo<'a>>, restaking_program_id: Option<&'b solana_program::account_info::AccountInfo<'a>>, system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>, first_slot_of_ncn_epoch: Option, diff --git a/clients/rust/jito_tip_router/src/generated/instructions/mod.rs b/clients/rust/jito_tip_router/src/generated/instructions/mod.rs index ad897c0..271bac3 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/mod.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/mod.rs @@ -4,14 +4,13 @@ //! //! -pub(crate) mod r#finalize_weight_table; -pub(crate) mod r#initialize_config; +pub(crate) mod r#admin_update_weight_table; +pub(crate) mod r#initialize_n_c_n_config; pub(crate) mod r#initialize_weight_table; pub(crate) mod r#set_config_fees; pub(crate) mod r#set_new_admin; -pub(crate) mod r#update_weight_table; pub use self::{ - r#finalize_weight_table::*, r#initialize_config::*, r#initialize_weight_table::*, - r#set_config_fees::*, r#set_new_admin::*, r#update_weight_table::*, + r#admin_update_weight_table::*, r#initialize_n_c_n_config::*, r#initialize_weight_table::*, + r#set_config_fees::*, r#set_new_admin::*, }; diff --git a/clients/rust/jito_tip_router/src/generated/instructions/set_config_fees.rs b/clients/rust/jito_tip_router/src/generated/instructions/set_config_fees.rs index 686f5d8..71a4cb2 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/set_config_fees.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/set_config_fees.rs @@ -9,6 +9,8 @@ use solana_program::pubkey::Pubkey; /// Accounts. pub struct SetConfigFees { + pub restaking_config: solana_program::pubkey::Pubkey, + pub config: solana_program::pubkey::Pubkey, pub ncn: solana_program::pubkey::Pubkey, @@ -31,7 +33,11 @@ impl SetConfigFees { args: SetConfigFeesInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta], ) -> solana_program::instruction::Instruction { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + self.restaking_config, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new( self.config, false, @@ -67,7 +73,7 @@ pub struct SetConfigFeesInstructionData { impl SetConfigFeesInstructionData { pub fn new() -> Self { - Self { discriminator: 4 } + Self { discriminator: 1 } } } @@ -90,12 +96,14 @@ pub struct SetConfigFeesInstructionArgs { /// /// ### Accounts: /// -/// 0. `[writable]` config -/// 1. `[]` ncn -/// 2. `[signer]` ncn_admin -/// 3. `[]` restaking_program_id +/// 0. `[]` restaking_config +/// 1. `[writable]` config +/// 2. `[]` ncn +/// 3. `[signer]` ncn_admin +/// 4. `[]` restaking_program_id #[derive(Clone, Debug, Default)] pub struct SetConfigFeesBuilder { + restaking_config: Option, config: Option, ncn: Option, ncn_admin: Option, @@ -112,6 +120,14 @@ impl SetConfigFeesBuilder { Self::default() } #[inline(always)] + pub fn restaking_config( + &mut self, + restaking_config: solana_program::pubkey::Pubkey, + ) -> &mut Self { + self.restaking_config = Some(restaking_config); + self + } + #[inline(always)] pub fn config(&mut self, config: solana_program::pubkey::Pubkey) -> &mut Self { self.config = Some(config); self @@ -179,6 +195,7 @@ impl SetConfigFeesBuilder { #[allow(clippy::clone_on_copy)] pub fn instruction(&self) -> solana_program::instruction::Instruction { let accounts = SetConfigFees { + restaking_config: self.restaking_config.expect("restaking_config is not set"), config: self.config.expect("config is not set"), ncn: self.ncn.expect("ncn is not set"), ncn_admin: self.ncn_admin.expect("ncn_admin is not set"), @@ -199,6 +216,8 @@ impl SetConfigFeesBuilder { /// `set_config_fees` CPI accounts. pub struct SetConfigFeesCpiAccounts<'a, 'b> { + pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + pub config: &'b solana_program::account_info::AccountInfo<'a>, pub ncn: &'b solana_program::account_info::AccountInfo<'a>, @@ -213,6 +232,8 @@ pub struct SetConfigFeesCpi<'a, 'b> { /// The program to invoke. pub __program: &'b solana_program::account_info::AccountInfo<'a>, + pub restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + pub config: &'b solana_program::account_info::AccountInfo<'a>, pub ncn: &'b solana_program::account_info::AccountInfo<'a>, @@ -232,6 +253,7 @@ impl<'a, 'b> SetConfigFeesCpi<'a, 'b> { ) -> Self { Self { __program: program, + restaking_config: accounts.restaking_config, config: accounts.config, ncn: accounts.ncn, ncn_admin: accounts.ncn_admin, @@ -272,7 +294,11 @@ impl<'a, 'b> SetConfigFeesCpi<'a, 'b> { bool, )], ) -> solana_program::entrypoint::ProgramResult { - let mut accounts = Vec::with_capacity(4 + remaining_accounts.len()); + let mut accounts = Vec::with_capacity(5 + remaining_accounts.len()); + accounts.push(solana_program::instruction::AccountMeta::new_readonly( + *self.restaking_config.key, + false, + )); accounts.push(solana_program::instruction::AccountMeta::new( *self.config.key, false, @@ -305,8 +331,9 @@ impl<'a, 'b> SetConfigFeesCpi<'a, 'b> { accounts, data, }; - let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len()); + let mut account_infos = Vec::with_capacity(5 + 1 + remaining_accounts.len()); account_infos.push(self.__program.clone()); + account_infos.push(self.restaking_config.clone()); account_infos.push(self.config.clone()); account_infos.push(self.ncn.clone()); account_infos.push(self.ncn_admin.clone()); @@ -327,10 +354,11 @@ impl<'a, 'b> SetConfigFeesCpi<'a, 'b> { /// /// ### Accounts: /// -/// 0. `[writable]` config -/// 1. `[]` ncn -/// 2. `[signer]` ncn_admin -/// 3. `[]` restaking_program_id +/// 0. `[]` restaking_config +/// 1. `[writable]` config +/// 2. `[]` ncn +/// 3. `[signer]` ncn_admin +/// 4. `[]` restaking_program_id #[derive(Clone, Debug)] pub struct SetConfigFeesCpiBuilder<'a, 'b> { instruction: Box>, @@ -340,6 +368,7 @@ impl<'a, 'b> SetConfigFeesCpiBuilder<'a, 'b> { pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self { let instruction = Box::new(SetConfigFeesCpiBuilderInstruction { __program: program, + restaking_config: None, config: None, ncn: None, ncn_admin: None, @@ -353,6 +382,14 @@ impl<'a, 'b> SetConfigFeesCpiBuilder<'a, 'b> { Self { instruction } } #[inline(always)] + pub fn restaking_config( + &mut self, + restaking_config: &'b solana_program::account_info::AccountInfo<'a>, + ) -> &mut Self { + self.instruction.restaking_config = Some(restaking_config); + self + } + #[inline(always)] pub fn config( &mut self, config: &'b solana_program::account_info::AccountInfo<'a>, @@ -455,6 +492,11 @@ impl<'a, 'b> SetConfigFeesCpiBuilder<'a, 'b> { let instruction = SetConfigFeesCpi { __program: self.instruction.__program, + restaking_config: self + .instruction + .restaking_config + .expect("restaking_config is not set"), + config: self.instruction.config.expect("config is not set"), ncn: self.instruction.ncn.expect("ncn is not set"), @@ -477,6 +519,7 @@ impl<'a, 'b> SetConfigFeesCpiBuilder<'a, 'b> { #[derive(Clone, Debug)] struct SetConfigFeesCpiBuilderInstruction<'a, 'b> { __program: &'b solana_program::account_info::AccountInfo<'a>, + restaking_config: Option<&'b solana_program::account_info::AccountInfo<'a>>, config: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn: Option<&'b solana_program::account_info::AccountInfo<'a>>, ncn_admin: Option<&'b solana_program::account_info::AccountInfo<'a>>, diff --git a/clients/rust/jito_tip_router/src/generated/instructions/set_new_admin.rs b/clients/rust/jito_tip_router/src/generated/instructions/set_new_admin.rs index aa1021d..c46086d 100644 --- a/clients/rust/jito_tip_router/src/generated/instructions/set_new_admin.rs +++ b/clients/rust/jito_tip_router/src/generated/instructions/set_new_admin.rs @@ -74,7 +74,7 @@ pub struct SetNewAdminInstructionData { impl SetNewAdminInstructionData { pub fn new() -> Self { - Self { discriminator: 5 } + Self { discriminator: 2 } } } diff --git a/clients/rust/jito_tip_router/src/generated/types/weight_entry.rs b/clients/rust/jito_tip_router/src/generated/types/weight_entry.rs index 11a9d11..fb3123b 100644 --- a/clients/rust/jito_tip_router/src/generated/types/weight_entry.rs +++ b/clients/rust/jito_tip_router/src/generated/types/weight_entry.rs @@ -15,5 +15,9 @@ pub struct WeightEntry { serde(with = "serde_with::As::") )] pub mint: Pubkey, - pub weight: u64, + pub weight: u128, + pub slot_set: u64, + pub slot_updated: u64, + #[cfg_attr(feature = "serde", serde(with = "serde_with::As::"))] + pub reserved: [u8; 128], } diff --git a/core/Cargo.toml b/core/Cargo.toml index fabfd39..1aa25c2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -21,6 +21,7 @@ jito-vault-sdk = { workspace = true } shank = { workspace = true } solana-program = { workspace = true } spl-associated-token-account = { workspace = true } +spl-math = { workspace = true } spl-token = { workspace = true } thiserror = { workspace = true } diff --git a/core/src/depreciated_weight.rs b/core/src/depreciated_weight.rs deleted file mode 100644 index 224069d..0000000 --- a/core/src/depreciated_weight.rs +++ /dev/null @@ -1,474 +0,0 @@ -use std::u64; - -use bytemuck::{Pod, Zeroable}; -use jito_bytemuck::types::PodU64; -use shank::ShankType; - -use crate::error::WeightTableError; - -#[derive(Debug, Clone, PartialEq, Eq, Copy, Zeroable, ShankType, Pod)] -#[repr(C)] -pub struct Weight { - numerator: PodU64, - denominator: PodU64, -} - -impl Weight { - pub fn numerator(&self) -> u64 { - self.numerator.into() - } - - pub fn denominator(&self) -> u64 { - self.denominator.into() - } - - pub fn new(numerator: u64, denominator: u64) -> Result { - if denominator == 0 { - return Err(WeightTableError::DenominatorIsZero); - } - - Ok(Self { - numerator: PodU64::from(numerator), - denominator: PodU64::from(denominator), - }) - } - - fn is_zero(&self) -> bool { - self.numerator() == 0 - } - - fn greatest_common_denominator(&self) -> Result { - let mut n: u64 = self.numerator(); - let mut d: u64 = self.denominator(); - - if d == 0 { - return Err(WeightTableError::DenominatorIsZero); - } - - if n == 0 { - return Ok(1); - } - - while d != 0 { - if d < n { - std::mem::swap(&mut d, &mut n); - } - d %= n; - } - - Ok(n) - } - - fn simplify(&self) -> Result { - let gcd_value = self.greatest_common_denominator()?; - - if gcd_value == 1 { - return Ok(*self); - } - - Ok(Self { - numerator: PodU64::from(self.numerator() / gcd_value), - denominator: PodU64::from(self.denominator() / gcd_value), - }) - } - - fn compare_weights(&self, other: &Self, compare: F) -> bool - where - F: Fn(u64, u64) -> bool, - { - let a = self.numerator(); - let b = self.denominator(); - let c = other.numerator(); - let d = other.denominator(); - - a.checked_mul(d) - .and_then(|ad| b.checked_mul(c).map(|bc| compare(ad, bc))) - .unwrap_or(false) - } - - pub fn gte(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad >= bc) - } - - pub fn gt(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad > bc) - } - - pub fn lt(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad < bc) - } - - pub fn lte(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad <= bc) - } - - pub fn eq(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad == bc) - } - - pub fn neq(&self, other: &Self) -> bool { - self.compare_weights(other, |ad, bc| ad != bc) - } - - pub fn checked_add(&self, other: &Self) -> Result { - let a = self.numerator(); - let b = self.denominator(); - let c = other.numerator(); - let d = other.denominator(); - - // Calculate ad and bc - let ad = a - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - let bc = b - .checked_mul(c) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate numerator (ad + bc) - let numerator = ad - .checked_add(bc) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate denominator (bd) - let denominator = b - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - let weight = Self { - numerator: PodU64::from(numerator), - denominator: PodU64::from(denominator), - }; - - weight.simplify() - } - - pub fn checked_sub(&self, other: &Self) -> Result { - let a = self.numerator(); - let b = self.denominator(); - let c = other.numerator(); - let d = other.denominator(); - - // Calculate ad and bc - let ad = a - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - let bc = b - .checked_mul(c) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate numerator (ad - bc) - let numerator = ad - .checked_sub(bc) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate denominator (bd) - let denominator = b - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Check if the result is zero - if numerator == 0 { - return Ok(Self::default()); - } - - let weight = Self { - numerator: PodU64::from(numerator), - denominator: PodU64::from(denominator), - }; - - weight.simplify() - } - - pub fn checked_mul(&self, other: &Self) -> Result { - let a = self.numerator(); - let b = self.denominator(); - let c = other.numerator(); - let d = other.denominator(); - - // Calculate numerator (ac) - let numerator = a - .checked_mul(c) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate denominator (bd) - let denominator = b - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - if denominator == 0 { - return Err(WeightTableError::DenominatorIsZero); - } - - let weight = Self { - numerator: PodU64::from(numerator), - denominator: PodU64::from(denominator), - }; - - weight.simplify() - } - - pub fn checked_div(&self, other: &Self) -> Result { - if other.is_zero() { - return Err(WeightTableError::DenominatorIsZero); - } - - let a = self.numerator(); - let b = self.denominator(); - let c = other.numerator(); - let d = other.denominator(); - - // Division by a/b / c/d is equivalent to multiplication by a/b * d/c - // So we multiply by the reciprocal - - // Calculate numerator (ad) - let numerator = a - .checked_mul(d) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - // Calculate denominator (bc) - let denominator = b - .checked_mul(c) - .ok_or(WeightTableError::ArithmeticOverflow)?; - - if denominator == 0 { - return Err(WeightTableError::DenominatorIsZero); - } - - let weight = Self { - numerator: PodU64::from(numerator), - denominator: PodU64::from(denominator), - }; - - weight.simplify() - } -} - -impl Default for Weight { - fn default() -> Self { - Self { - numerator: PodU64::from(0), - denominator: PodU64::from(1), - } - } -} - -impl From for Weight { - fn from(weight: u64) -> Self { - Self { - numerator: PodU64::from(weight), - denominator: PodU64::from(1), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_new() { - assert!(Weight::new(1, 2).is_ok()); - assert!(matches!( - Weight::new(1, 0), - Err(WeightTableError::DenominatorIsZero) - )); - } - - #[test] - fn test_is_zero() { - assert!(Weight::new(0, 1).unwrap().is_zero()); - assert!(!Weight::new(1, 2).unwrap().is_zero()); - } - - #[test] - fn test_gcd() { - assert_eq!( - Weight::new(6, 8) - .unwrap() - .greatest_common_denominator() - .unwrap(), - 2 - ); - assert_eq!( - Weight::new(17, 23) - .unwrap() - .greatest_common_denominator() - .unwrap(), - 1 - ); - - let bad_weight = Weight::new(1, 0).unwrap_err(); - assert!(matches!(bad_weight, WeightTableError::DenominatorIsZero)); - } - - #[test] - fn test_simplify() { - let w1 = Weight::new(6, 8).unwrap().simplify().unwrap(); - assert_eq!(w1.numerator(), 3); - assert_eq!(w1.denominator(), 4); - - let w2 = Weight::new(17, 23).unwrap().simplify().unwrap(); - assert_eq!(w2.numerator(), 17); - assert_eq!(w2.denominator(), 23); - } - - #[test] - fn test_comparisons() { - let w1 = Weight::new(1, 2).unwrap(); - let w2 = Weight::new(3, 4).unwrap(); - let w3 = Weight::new(1, 2).unwrap(); - - assert!(w1.lt(&w2)); - assert!(w1.lte(&w2)); - assert!(w2.gt(&w1)); - assert!(w2.gte(&w1)); - assert!(w1.eq(&w3)); - assert!(w1.neq(&w2)); - } - - #[test] - fn test_checked_add() { - let w1 = Weight::new(1, 2).unwrap(); - let w2 = Weight::new(1, 4).unwrap(); - let result = w1.checked_add(&w2).unwrap(); - assert_eq!(result.numerator(), 3); - assert_eq!(result.denominator(), 4); - - // Test overflow - let w_max = Weight::new(u64::MAX, 1).unwrap(); - assert!(matches!( - w_max.checked_add(&w1), - Err(WeightTableError::ArithmeticOverflow) - )); - } - - #[test] - fn test_checked_sub() { - let w1 = Weight::new(3, 4).unwrap(); - let w2 = Weight::new(1, 4).unwrap(); - let result = w1.checked_sub(&w2).unwrap(); - assert_eq!(result.numerator(), 1); - assert_eq!(result.denominator(), 2); - - // Test underflow - let w_min = Weight::new(0, 1).unwrap(); - assert!(matches!( - w_min.checked_sub(&w1), - Err(WeightTableError::ArithmeticOverflow) - )); - } - - #[test] - fn test_checked_mul() { - let w1 = Weight::new(2, 3).unwrap(); - let w2 = Weight::new(3, 4).unwrap(); - let result = w1.checked_mul(&w2).unwrap(); - assert_eq!(result.numerator(), 1); - assert_eq!(result.denominator(), 2); - - // Test overflow - let w_max = Weight::new(u64::MAX, 1).unwrap(); - assert!(matches!( - w_max.checked_mul(&w1), - Err(WeightTableError::ArithmeticOverflow) - )); - } - - #[test] - fn test_checked_div() { - let w1 = Weight::new(2, 3).unwrap(); - let w2 = Weight::new(3, 4).unwrap(); - let result = w1.checked_div(&w2).unwrap(); - assert_eq!(result.numerator(), 8); - assert_eq!(result.denominator(), 9); - - // Test division by zero - let w_zero = Weight::new(0, 1).unwrap(); - assert!(matches!( - w1.checked_div(&w_zero), - Err(WeightTableError::DenominatorIsZero) - )); - - // Test overflow - let w_max = Weight::new(u64::MAX, 1).unwrap(); - let w_min = Weight::new(1, u64::MAX).unwrap(); - assert!(matches!( - w_max.checked_div(&w_min), - Err(WeightTableError::ArithmeticOverflow) - )); - } - - #[test] - fn test_largest_and_smallest_comparison() { - let largest = Weight::new(u64::MAX, 1).unwrap(); - let smallest = Weight::new(1, u64::MAX).unwrap(); - - // Due to overflow protection, these comparisons will return false - assert!(!largest.gt(&smallest)); - assert!(!smallest.lt(&largest)); - assert!(!largest.eq(&smallest)); - } - - #[test] - fn test_large_number_comparison() { - let large1 = Weight::new(u64::MAX / 2, 1).unwrap(); - let large2 = Weight::new(u64::MAX / 2 + 1, 1).unwrap(); - - assert!(large2.gt(&large1)); - assert!(large1.lt(&large2)); - assert!(!large1.eq(&large2)); - } - - #[test] - fn test_small_number_comparison() { - let small1 = Weight::new(1, u64::MAX).unwrap(); - let small2 = Weight::new(2, u64::MAX).unwrap(); - - // Due to precision limitations, these might not compare as expected - assert!(!small2.gt(&small1)); - assert!(!small1.lt(&small2)); - assert!(!small1.eq(&small2)); - } - - #[test] - fn test_precision_limit() { - let w1 = Weight::new(u64::MAX / 2, u64::MAX / 2).unwrap(); - let w2 = Weight::new(u64::MAX / 2 + 1, u64::MAX / 2).unwrap(); - - // Due to overflow protection, these comparisons will return false - assert!(!w2.gt(&w1)); - assert!(!w1.lt(&w2)); - assert!(!w1.eq(&w2)); - } - - #[test] - fn test_overflow_handling() { - let w1 = Weight::new(u64::MAX, 2).unwrap(); - let w2 = Weight::new(u64::MAX - 1, 2).unwrap(); - - // This comparison should return false due to overflow protection - assert!(!w1.gt(&w2)); - assert!(!w1.lt(&w2)); - assert!(!w1.eq(&w2)); - } - - #[test] - fn test_equality_of_simplified_weights() { - let w1 = Weight::new(2, 4).unwrap(); - let w2 = Weight::new(1, 2).unwrap(); - - assert!(w1.eq(&w2)); - assert!(!w1.gt(&w2)); - assert!(!w1.lt(&w2)); - } - - #[test] - fn test_comparison_with_zero() { - let zero = Weight::new(0, 1).unwrap(); - let smallest_positive = Weight::new(1, u64::MAX).unwrap(); - - assert!(smallest_positive.gt(&zero)); - assert!(zero.lt(&smallest_positive)); - assert!(!zero.eq(&smallest_positive)); - } -} diff --git a/core/src/error.rs b/core/src/error.rs index 48e597c..21fe13a 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -3,19 +3,35 @@ use thiserror::Error; #[derive(Debug, Error, PartialEq, Eq)] pub enum TipRouterError { - #[error("No more table slots available")] - NoMoreTableSlots = 0x2000, #[error("Zero in the denominator")] DenominatorIsZero = 0x2100, #[error("Overflow")] - ArithmeticOverflow = 0x2101, + ArithmeticOverflow, #[error("Modulo Overflow")] - ModuloOverflow = 0x2102, + ModuloOverflow, + #[error("New precise number error")] + NewPreciseNumberError, + #[error("Cast to imprecise number error")] + CastToImpreciseNumberError, #[error("Incorrect weight table admin")] IncorrectWeightTableAdmin = 0x2200, + #[error("Duplicate mints in table")] + DuplicateMintsInTable, + #[error("There are no mints in the table")] + NoMintsInTable, + #[error("Too many mints for table")] + TooManyMintsForTable, + #[error("Weight table already initialized")] + WeightTableAlreadyInitialized, #[error("Cannnot create future weight tables")] - CannotCreateFutureWeightTables = 0x2201, + CannotCreateFutureWeightTables, + #[error("Weight mints do not match - length")] + WeightMintsDoNotMatchLength, + #[error("Weight mints do not match - mint hash")] + WeightMintsDoNotMatchMintHash, + #[error("Invalid mint for weight table")] + InvalidMintForWeightTable, #[error("Fee cap exceeded")] FeeCapExceeded = 0x2300, #[error("Incorrect NCN Admin")] diff --git a/core/src/instruction.rs b/core/src/instruction.rs index 3ffa68d..169247a 100644 --- a/core/src/instruction.rs +++ b/core/src/instruction.rs @@ -14,54 +14,26 @@ pub enum WeightTableInstruction { /// Initialize the global configuration for this NCN - #[account(0, writable, name = "config")] - #[account(1, name = "ncn")] - #[account(2, signer, name = "ncn_admin")] - #[account(3, name = "fee_wallet")] - #[account(4, name = "tie_breaker_admin")] - #[account(5, name = "restaking_program_id")] - #[account(6, name = "system_program")] - InitializeConfig { + #[account(0, name = "restaking_config")] + #[account(1, writable, name = "ncn_config")] + #[account(2, name = "ncn")] + #[account(3, signer, name = "ncn_admin")] + #[account(4, name = "fee_wallet")] + #[account(5, name = "tie_breaker_admin")] + #[account(6, name = "restaking_program_id")] + #[account(7, name = "system_program")] + InitializeNCNConfig { dao_fee_bps: u64, ncn_fee_bps: u64, block_engine_fee_bps: u64, }, - /// Initializes the weight table for a given NCN epoch + /// Updates the fee configuration #[account(0, name = "restaking_config")] - #[account(1, name = "ncn")] - #[account(2, writable, signer, name = "weight_table")] - #[account(3, writable, signer, name = "weight_table_admin")] + #[account(1, writable, name = "config")] + #[account(2, name = "ncn")] + #[account(3, signer, name = "ncn_admin")] #[account(4, name = "restaking_program_id")] - #[account(5, name = "system_program")] - InitializeWeightTable{ - first_slot_of_ncn_epoch: Option, - }, - - /// Updates the weight table - #[account(0, name = "ncn")] - #[account(1, writable, name = "weight_table")] - #[account(2, signer, name = "weight_table_admin")] - #[account(3, name = "restaking_program_id")] - UpdateWeightTable{ - ncn_epoch: u64, - weight_numerator: u64, - weight_denominator: u64, - }, - - #[account(0, name = "ncn")] - #[account(1, writable, name = "weight_table")] - #[account(2, signer, name = "weight_table_admin")] - #[account(3, name = "restaking_program_id")] - FinalizeWeightTable{ - ncn_epoch: u64, - }, - - /// Updates the fee configuration - #[account(0, writable, name = "config")] - #[account(1, name = "ncn")] - #[account(2, signer, name = "ncn_admin")] - #[account(3, name = "restaking_program_id")] SetConfigFees { new_dao_fee_bps: Option, new_ncn_fee_bps: Option, @@ -78,4 +50,27 @@ pub enum WeightTableInstruction { SetNewAdmin { role: ConfigAdminRole, }, + + /// Initializes the weight table for a given NCN epoch + #[account(0, name = "restaking_config")] + #[account(1, name = "ncn_config")] + #[account(2, name = "ncn")] + #[account(3, writable, name = "weight_table")] + #[account(4, writable, signer, name = "payer")] + #[account(5, name = "restaking_program_id")] + #[account(6, name = "system_program")] + InitializeWeightTable{ + first_slot_of_ncn_epoch: Option, + }, + + /// Updates the weight table + #[account(0, name = "ncn")] + #[account(1, writable, name = "weight_table")] + #[account(2, signer, name = "weight_table_admin")] + #[account(3, name = "mint")] + #[account(4, name = "restaking_program_id")] + AdminUpdateWeightTable{ + ncn_epoch: u64, + weight: u128, + }, } diff --git a/core/src/lib.rs b/core/src/lib.rs index 18715e5..a75de93 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,9 +1,9 @@ pub mod discriminators; pub mod error; -pub mod instruction; -// pub mod depreciated_weight; pub mod fees; +pub mod instruction; pub mod ncn_config; +pub mod weight_entry; pub mod weight_table; pub const MAX_FEE_BPS: u64 = 10_000; diff --git a/core/src/ncn_config.rs b/core/src/ncn_config.rs index d68a0fa..d7f72bb 100644 --- a/core/src/ncn_config.rs +++ b/core/src/ncn_config.rs @@ -82,30 +82,30 @@ impl NcnConfig { pub fn load( program_id: &Pubkey, ncn: &Pubkey, - account: &AccountInfo, + ncn_config_account: &AccountInfo, expect_writable: bool, ) -> Result<(), ProgramError> { - if account.owner.ne(program_id) { - msg!("Config account has an invalid owner"); + if ncn_config_account.owner.ne(program_id) { + msg!("NCN Config account has an invalid owner"); return Err(ProgramError::InvalidAccountOwner); } - if account.data_is_empty() { - msg!("Config account data is empty"); + if ncn_config_account.data_is_empty() { + msg!("NCN Config account data is empty"); return Err(ProgramError::InvalidAccountData); } - if expect_writable && !account.is_writable { - msg!("Config account is not writable"); + if expect_writable && !ncn_config_account.is_writable { + msg!("NCN Config account is not writable"); return Err(ProgramError::InvalidAccountData); } - if account.data.borrow()[0].ne(&Self::DISCRIMINATOR) { - msg!("Config account discriminator is invalid"); + if ncn_config_account.data.borrow()[0].ne(&Self::DISCRIMINATOR) { + msg!("NCN Config account discriminator is invalid"); return Err(ProgramError::InvalidAccountData); } - if account + if ncn_config_account .key .ne(&Self::find_program_address(program_id, ncn).0) { - msg!("Config account is not at the correct PDA"); + msg!("NCN Config account is not at the correct PDA"); return Err(ProgramError::InvalidAccountData); } Ok(()) diff --git a/core/src/weight_entry.rs b/core/src/weight_entry.rs new file mode 100644 index 0000000..8a0517c --- /dev/null +++ b/core/src/weight_entry.rs @@ -0,0 +1,104 @@ +use bytemuck::{Pod, Zeroable}; +use jito_bytemuck::types::{PodU128, PodU64}; +use shank::ShankType; +use solana_program::pubkey::Pubkey; +use spl_math::precise_number::PreciseNumber; + +use crate::error::TipRouterError; + +#[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod)] +#[repr(C)] +pub struct WeightEntry { + mint: Pubkey, + weight: PodU128, + slot_set: PodU64, + slot_updated: PodU64, + reserved: [u8; 128], +} + +impl Default for WeightEntry { + fn default() -> Self { + Self { + mint: Pubkey::default(), + weight: PodU128::default(), + slot_set: PodU64::default(), + slot_updated: PodU64::default(), + reserved: [0; 128], + } + } +} + +impl WeightEntry { + // Weights should have a decimal precision of 1e12 + // Meaning something has the exchange rate of 1.5, it should be stored as 1.5 * 1e12 + // This gives us 12 decimal places of precision + pub const DECIMAL_PRECISION: u128 = 1_000_000_000_000; // 1e12 + + pub fn new(mint: Pubkey) -> Self { + Self { + mint, + weight: PodU128::from(0), + slot_set: PodU64::from(0), + slot_updated: PodU64::from(0), + reserved: [0; 128], + } + } + + // Empty entry, no mint + pub fn is_empty(&self) -> bool { + self.mint.eq(&Pubkey::default()) + } + + pub fn is_set(&self) -> bool { + self.slot_set() > 0 + } + + pub fn slot_set(&self) -> u64 { + self.slot_set.into() + } + + pub fn slot_updated(&self) -> u64 { + self.slot_updated.into() + } + + pub const fn mint(&self) -> Pubkey { + self.mint + } + + pub fn weight(&self) -> u128 { + self.weight.into() + } + + pub fn precise_weight(&self) -> Result { + PreciseNumber::new(self.weight.into()).ok_or(TipRouterError::NewPreciseNumberError) + } + + pub fn set_weight(&mut self, weight: u128, current_slot: u64) { + self.weight = PodU128::from(weight); + + if self.slot_set() == 0 { + self.slot_set = PodU64::from(current_slot); + self.slot_updated = PodU64::from(current_slot); + } + + self.slot_updated = PodU64::from(current_slot); + } +} + +#[cfg(test)] +mod tests { + use solana_program::pubkey::Pubkey; + + use super::*; + + #[test] + fn test_weight_entry_new() { + let mint = Pubkey::new_unique(); + let weight_entry = WeightEntry::new(mint); + + assert_eq!(weight_entry.mint(), mint); + assert_eq!(weight_entry.weight(), 0); + assert_eq!(weight_entry.slot_set(), 0); + assert_eq!(weight_entry.slot_updated(), 0); + } +} diff --git a/core/src/weight_table.rs b/core/src/weight_table.rs index 61bd2ac..8ec499a 100644 --- a/core/src/weight_table.rs +++ b/core/src/weight_table.rs @@ -1,9 +1,11 @@ +use std::collections::HashSet; + use bytemuck::{Pod, Zeroable}; use jito_bytemuck::{types::PodU64, AccountDeserialize, Discriminator}; use shank::{ShankAccount, ShankType}; use solana_program::{account_info::AccountInfo, msg, program_error::ProgramError, pubkey::Pubkey}; -use crate::{discriminators::Discriminators, error::TipRouterError}; +use crate::{discriminators::Discriminators, error::TipRouterError, weight_entry::WeightEntry}; // PDA'd ["WEIGHT_TABLE", NCN, NCN_EPOCH_SLOT] #[derive(Debug, Clone, Copy, Zeroable, ShankType, Pod, AccountDeserialize, ShankAccount)] @@ -11,25 +13,22 @@ use crate::{discriminators::Discriminators, error::TipRouterError}; pub struct WeightTable { /// The NCN on-chain program is the signer to create and update this account, /// this pushes the responsibility of managing the account to the NCN program. - pub ncn: Pubkey, + ncn: Pubkey, /// The NCN epoch for which the weight table is valid - pub ncn_epoch: PodU64, + ncn_epoch: PodU64, /// Slot weight table was created slot_created: PodU64, - /// Slot weight table was finalized - slot_finalized: PodU64, - /// Bump seed for the PDA - pub bump: u8, + bump: u8, /// Reserved space reserved: [u8; 128], /// The weight table - pub table: [WeightEntry; 32], + table: [WeightEntry; 32], } impl Discriminator for WeightTable { @@ -38,14 +37,12 @@ impl Discriminator for WeightTable { impl WeightTable { pub const MAX_TABLE_ENTRIES: usize = 32; - pub const NOT_FINALIZED: u64 = u64::MAX; pub fn new(ncn: Pubkey, ncn_epoch: u64, slot_created: u64, bump: u8) -> Self { Self { ncn, ncn_epoch: PodU64::from(ncn_epoch), slot_created: PodU64::from(slot_created), - slot_finalized: PodU64::from(Self::NOT_FINALIZED), bump, reserved: [0; 128], table: [WeightEntry::default(); Self::MAX_TABLE_ENTRIES], @@ -75,51 +72,116 @@ impl WeightTable { (pda, bump, seeds) } - pub fn entry_count(&self) -> usize { - self.table.iter().filter(|entry| !entry.is_empty()).count() + pub fn initalize_weight_table( + &mut self, + config_supported_mints: &[Pubkey], + ) -> Result<(), TipRouterError> { + if self.initialized() { + return Err(TipRouterError::WeightTableAlreadyInitialized); + } + + // Check for empty vector + if config_supported_mints.is_empty() { + return Err(TipRouterError::NoMintsInTable); + } + + // Check if vector exceeds maximum allowed entries + if config_supported_mints.len() > Self::MAX_TABLE_ENTRIES { + return Err(TipRouterError::TooManyMintsForTable); + } + + // Check for duplicates using nested iterators + let unique_mints: HashSet<_> = config_supported_mints.iter().collect(); + + if unique_mints.len() != config_supported_mints.len() { + return Err(TipRouterError::DuplicateMintsInTable); + } + + // Set table using iterator + self.table + .iter_mut() + .zip(config_supported_mints.iter()) + .for_each(|(entry, &mint)| { + *entry = WeightEntry::new(mint); + }); + + self.check_initialized()?; + + Ok(()) } - pub fn find_weight(&self, mint: &Pubkey) -> Option { + pub fn set_weight( + &mut self, + mint: &Pubkey, + weight: u128, + current_slot: u64, + ) -> Result<(), TipRouterError> { + self.table + .iter_mut() + .find(|entry| entry.mint() == *mint) + .map_or(Err(TipRouterError::InvalidMintForWeightTable), |entry| { + entry.set_weight(weight, current_slot); + Ok(()) + }) + } + + pub fn get_weight(&self, mint: &Pubkey) -> Result { self.table .iter() - .find(|entry| entry.mint == *mint) - .map(|entry| entry.weight) + .find(|entry| entry.mint() == *mint) + .map_or(Err(TipRouterError::InvalidMintForWeightTable), |entry| { + Ok(entry.weight()) + }) } - pub fn set_weight(&mut self, mint: &Pubkey, weight: PodU64) -> Result<(), TipRouterError> { - let entry = self - .table - .iter_mut() - .find(|entry| entry.mint == *mint || entry.is_empty()); + pub fn get_mints(&self) -> Vec { + self.table + .iter() + .filter(|entry| !entry.is_empty()) + .map(|entry| entry.mint()) + .collect() + } - match entry { - Some(entry) => { - entry.weight = weight; + pub fn find_weight(&self, mint: &Pubkey) -> Option { + self.table + .iter() + .find(|entry| entry.mint() == *mint) + .map(|entry| entry.weight()) + } - if entry.mint == Pubkey::default() { - entry.mint = *mint; - } - } - None => return Err(TipRouterError::NoMoreTableSlots), - } + pub fn mint_count(&self) -> usize { + self.table.iter().filter(|entry| !entry.is_empty()).count() + } - Ok(()) + pub fn weight_count(&self) -> usize { + self.table.iter().filter(|entry| !entry.is_set()).count() + } + + pub const fn ncn(&self) -> Pubkey { + self.ncn + } + + pub fn ncn_epoch(&self) -> u64 { + self.ncn_epoch.into() } pub fn slot_created(&self) -> u64 { self.slot_created.into() } - pub fn slot_finalized(&self) -> u64 { - self.slot_finalized.into() + pub fn initialized(&self) -> bool { + self.mint_count() > 0 } pub fn finalized(&self) -> bool { - self.slot_finalized != PodU64::from(Self::NOT_FINALIZED) + self.initialized() && self.mint_count() == self.weight_count() } - pub fn finalize(&mut self, current_slot: u64) { - self.slot_finalized = PodU64::from(current_slot); + pub fn check_initialized(&self) -> Result<(), TipRouterError> { + if !self.initialized() { + return Err(TipRouterError::NoMintsInTable); + } + Ok(()) } pub fn load( @@ -134,7 +196,7 @@ impl WeightTable { return Err(ProgramError::InvalidAccountOwner); } if weight_table.data_is_empty() { - msg!("Weight table is empty"); + msg!("Weight table account is empty"); return Err(ProgramError::InvalidAccountData); } if expect_writable && !weight_table.is_writable { @@ -154,46 +216,135 @@ impl WeightTable { } } -#[derive(Default, Debug, Clone, Copy, Zeroable, ShankType, Pod)] -#[repr(C)] -pub struct WeightEntry { - pub mint: Pubkey, - pub weight: PodU64, //TODO Change - // pub weight: Weight, -} +#[cfg(test)] +mod tests { + use solana_program::pubkey::Pubkey; -impl WeightEntry { - pub const fn new(mint: Pubkey, weight: PodU64) -> Self { - Self { weight, mint } + use super::*; + + fn get_test_pubkeys(count: usize) -> Vec { + (0..count).map(|_| Pubkey::new_unique()).collect() } - pub fn is_empty(&self) -> bool { - self.weight.eq(&PodU64::from(0)) - // self.weight.denominator() == 0 || self.mint.eq(&Pubkey::default()) + #[test] + fn test_initialize_table_success() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + assert_eq!(table.mint_count(), 0); + + let mints = get_test_pubkeys(2); + table.initalize_weight_table(&mints).unwrap(); + assert_eq!(table.mint_count(), 2); } -} -#[cfg(test)] -mod tests { - use solana_program::pubkey::Pubkey; + #[test] + fn test_initialize_table_too_many() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let many_mints = get_test_pubkeys(WeightTable::MAX_TABLE_ENTRIES + 1); + assert_eq!( + table.initalize_weight_table(&many_mints), + Err(TipRouterError::TooManyMintsForTable) + ); + } - use super::*; + #[test] + fn test_initialize_table_max() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let max_mints = get_test_pubkeys(WeightTable::MAX_TABLE_ENTRIES); + table.initalize_weight_table(&max_mints).unwrap(); + assert_eq!(table.mint_count(), WeightTable::MAX_TABLE_ENTRIES); + } #[test] - fn test_weight_table_new() { + fn test_initialize_table_reinitialize() { let ncn = Pubkey::new_unique(); - let table = WeightTable::new(ncn, 0, 0, 0); - assert_eq!(table.entry_count(), 0); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let first_mints = get_test_pubkeys(2); + table.initalize_weight_table(&first_mints).unwrap(); + let second_mints = get_test_pubkeys(3); + + assert_eq!( + table.initalize_weight_table(&second_mints), + Err(TipRouterError::WeightTableAlreadyInitialized) + ); } #[test] - fn test_weight_table_finalize() { - let mut weight_table = WeightTable::new(Pubkey::new_unique(), 0, 0, 0); + fn test_set_weight_success() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let mints = get_test_pubkeys(2); + let mint = mints[0]; + + table.initalize_weight_table(&mints).unwrap(); + + table.set_weight(&mint, 100, 1).unwrap(); + assert_eq!(table.get_weight(&mint).unwrap(), 100); + } + + #[test] + fn test_set_weight_invalid_mint() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let mints = get_test_pubkeys(2); + + table.initalize_weight_table(&mints).unwrap(); + + let invalid_mint = Pubkey::new_unique(); + assert_eq!( + table.set_weight(&invalid_mint, 100, 1), + Err(TipRouterError::InvalidMintForWeightTable) + ); + } + + #[test] + fn test_set_weight_update_existing() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let mints = get_test_pubkeys(2); + let mint = mints[0]; + + table.initalize_weight_table(&mints).unwrap(); + + table.set_weight(&mint, 100, 1).unwrap(); + assert_eq!(table.get_weight(&mint).unwrap(), 100); + + table.set_weight(&mint, 200, 2).unwrap(); + assert_eq!(table.get_weight(&mint).unwrap(), 200); + } + + #[test] + fn test_set_weight_multiple_mints() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let mints = get_test_pubkeys(2); + let mint1 = mints[0]; + let mint2 = mints[1]; + + table.initalize_weight_table(&mints).unwrap(); + + table.set_weight(&mint1, 100, 1).unwrap(); + table.set_weight(&mint2, 200, 1).unwrap(); + + assert_eq!(table.get_weight(&mint1).unwrap(), 100); + assert_eq!(table.get_weight(&mint2).unwrap(), 200); + } + + #[test] + fn test_set_weight_different_slots() { + let ncn = Pubkey::new_unique(); + let mut table = WeightTable::new(ncn, 0, 0, 0); + let mints = get_test_pubkeys(2); + let mint = mints[0]; + + table.initalize_weight_table(&mints).unwrap(); - assert!(!weight_table.finalized()); - assert_eq!(weight_table.slot_finalized(), WeightTable::NOT_FINALIZED); + table.set_weight(&mint, 100, 1).unwrap(); + assert_eq!(table.get_weight(&mint).unwrap(), 100); - weight_table.finalize(0); - assert!(weight_table.finalized()); + table.set_weight(&mint, 200, 5).unwrap(); + assert_eq!(table.get_weight(&mint).unwrap(), 200); } } diff --git a/idl/jito_tip_router.json b/idl/jito_tip_router.json index 4078fd7..54c8f19 100644 --- a/idl/jito_tip_router.json +++ b/idl/jito_tip_router.json @@ -3,10 +3,15 @@ "name": "jito_tip_router", "instructions": [ { - "name": "InitializeConfig", + "name": "InitializeNCNConfig", "accounts": [ { - "name": "config", + "name": "restakingConfig", + "isMut": false, + "isSigner": false + }, + { + "name": "ncnConfig", "isMut": true, "isSigner": false }, @@ -61,7 +66,7 @@ } }, { - "name": "InitializeWeightTable", + "name": "SetConfigFees", "accounts": [ { "name": "restakingConfig", @@ -69,37 +74,50 @@ "isSigner": false }, { - "name": "ncn", - "isMut": false, + "name": "config", + "isMut": true, "isSigner": false }, { - "name": "weightTable", - "isMut": true, - "isSigner": true + "name": "ncn", + "isMut": false, + "isSigner": false }, { - "name": "weightTableAdmin", - "isMut": true, + "name": "ncnAdmin", + "isMut": false, "isSigner": true }, { "name": "restakingProgramId", "isMut": false, "isSigner": false - }, - { - "name": "systemProgram", - "isMut": false, - "isSigner": false } ], "args": [ { - "name": "firstSlotOfNcnEpoch", + "name": "newDaoFeeBps", "type": { "option": "u64" } + }, + { + "name": "newNcnFeeBps", + "type": { + "option": "u64" + } + }, + { + "name": "newBlockEngineFeeBps", + "type": { + "option": "u64" + } + }, + { + "name": "newFeeWallet", + "type": { + "option": "publicKey" + } } ], "discriminant": { @@ -108,23 +126,28 @@ } }, { - "name": "UpdateWeightTable", + "name": "SetNewAdmin", "accounts": [ { - "name": "ncn", - "isMut": false, + "name": "config", + "isMut": true, "isSigner": false }, { - "name": "weightTable", - "isMut": true, + "name": "ncn", + "isMut": false, "isSigner": false }, { - "name": "weightTableAdmin", + "name": "ncnAdmin", "isMut": false, "isSigner": true }, + { + "name": "newAdmin", + "isMut": false, + "isSigner": false + }, { "name": "restakingProgramId", "isMut": false, @@ -133,16 +156,10 @@ ], "args": [ { - "name": "ncnEpoch", - "type": "u64" - }, - { - "name": "weightNumerator", - "type": "u64" - }, - { - "name": "weightDenominator", - "type": "u64" + "name": "role", + "type": { + "defined": "ConfigAdminRole" + } } ], "discriminant": { @@ -151,115 +168,77 @@ } }, { - "name": "FinalizeWeightTable", + "name": "InitializeWeightTable", "accounts": [ { - "name": "ncn", + "name": "restakingConfig", "isMut": false, "isSigner": false }, { - "name": "weightTable", - "isMut": true, - "isSigner": false - }, - { - "name": "weightTableAdmin", + "name": "ncnConfig", "isMut": false, - "isSigner": true + "isSigner": false }, { - "name": "restakingProgramId", + "name": "ncn", "isMut": false, "isSigner": false - } - ], - "args": [ - { - "name": "ncnEpoch", - "type": "u64" - } - ], - "discriminant": { - "type": "u8", - "value": 3 - } - }, - { - "name": "SetConfigFees", - "accounts": [ + }, { - "name": "config", + "name": "weightTable", "isMut": true, "isSigner": false }, { - "name": "ncn", - "isMut": false, - "isSigner": false + "name": "payer", + "isMut": true, + "isSigner": true }, { - "name": "ncnAdmin", + "name": "restakingProgramId", "isMut": false, - "isSigner": true + "isSigner": false }, { - "name": "restakingProgramId", + "name": "systemProgram", "isMut": false, "isSigner": false } ], "args": [ { - "name": "newDaoFeeBps", - "type": { - "option": "u64" - } - }, - { - "name": "newNcnFeeBps", - "type": { - "option": "u64" - } - }, - { - "name": "newBlockEngineFeeBps", + "name": "firstSlotOfNcnEpoch", "type": { "option": "u64" } - }, - { - "name": "newFeeWallet", - "type": { - "option": "publicKey" - } } ], "discriminant": { "type": "u8", - "value": 4 + "value": 3 } }, { - "name": "SetNewAdmin", + "name": "AdminUpdateWeightTable", "accounts": [ { - "name": "config", - "isMut": true, + "name": "ncn", + "isMut": false, "isSigner": false }, { - "name": "ncn", - "isMut": false, + "name": "weightTable", + "isMut": true, "isSigner": false }, { - "name": "ncnAdmin", + "name": "weightTableAdmin", "isMut": false, "isSigner": true }, { - "name": "newAdmin", + "name": "mint", "isMut": false, "isSigner": false }, @@ -271,15 +250,17 @@ ], "args": [ { - "name": "role", - "type": { - "defined": "ConfigAdminRole" - } + "name": "ncnEpoch", + "type": "u64" + }, + { + "name": "weight", + "type": "u128" } ], "discriminant": { "type": "u8", - "value": 5 + "value": 4 } } ], @@ -344,12 +325,6 @@ "defined": "PodU64" } }, - { - "name": "slotFinalized", - "type": { - "defined": "PodU64" - } - }, { "name": "bump", "type": "u8" @@ -438,9 +413,30 @@ }, { "name": "weight", + "type": { + "defined": "PodU128" + } + }, + { + "name": "slotSet", "type": { "defined": "PodU64" } + }, + { + "name": "slotUpdated", + "type": { + "defined": "PodU64" + } + }, + { + "name": "reserved", + "type": { + "array": [ + "u8", + 128 + ] + } } ] } @@ -461,11 +457,6 @@ } ], "errors": [ - { - "code": 8192, - "name": "NoMoreTableSlots", - "msg": "No more table slots available" - }, { "code": 8448, "name": "DenominatorIsZero", @@ -481,6 +472,16 @@ "name": "ModuloOverflow", "msg": "Modulo Overflow" }, + { + "code": 8451, + "name": "NewPreciseNumberError", + "msg": "New precise number error" + }, + { + "code": 8452, + "name": "CastToImpreciseNumberError", + "msg": "Cast to imprecise number error" + }, { "code": 8704, "name": "IncorrectWeightTableAdmin", @@ -488,9 +489,44 @@ }, { "code": 8705, + "name": "DuplicateMintsInTable", + "msg": "Duplicate mints in table" + }, + { + "code": 8706, + "name": "NoMintsInTable", + "msg": "There are no mints in the table" + }, + { + "code": 8707, + "name": "TooManyMintsForTable", + "msg": "Too many mints for table" + }, + { + "code": 8708, + "name": "WeightTableAlreadyInitialized", + "msg": "Weight table already initialized" + }, + { + "code": 8709, "name": "CannotCreateFutureWeightTables", "msg": "Cannnot create future weight tables" }, + { + "code": 8710, + "name": "WeightMintsDoNotMatchLength", + "msg": "Weight mints do not match - length" + }, + { + "code": 8711, + "name": "WeightMintsDoNotMatchMintHash", + "msg": "Weight mints do not match - mint hash" + }, + { + "code": 8712, + "name": "InvalidMintForWeightTable", + "msg": "Invalid mint for weight table" + }, { "code": 8960, "name": "FeeCapExceeded", diff --git a/integration_tests/tests/fixtures/tip_router_client.rs b/integration_tests/tests/fixtures/tip_router_client.rs index 3a53ba8..ce14f56 100644 --- a/integration_tests/tests/fixtures/tip_router_client.rs +++ b/integration_tests/tests/fixtures/tip_router_client.rs @@ -1,9 +1,15 @@ use jito_bytemuck::AccountDeserialize; +use jito_restaking_core::config::Config; use jito_tip_router_client::{ - instructions::{InitializeConfigBuilder, SetConfigFeesBuilder, SetNewAdminBuilder}, + instructions::{ + AdminUpdateWeightTableBuilder, InitializeNCNConfigBuilder, InitializeWeightTableBuilder, + SetConfigFeesBuilder, SetNewAdminBuilder, + }, types::ConfigAdminRole, }; -use jito_tip_router_core::{error::TipRouterError, ncn_config::NcnConfig}; +use jito_tip_router_core::{ + error::TipRouterError, ncn_config::NcnConfig, weight_table::WeightTable, +}; use solana_program::{ instruction::InstructionError, native_token::sol_to_lamports, pubkey::Pubkey, system_instruction::transfer, @@ -12,6 +18,7 @@ use solana_program_test::BanksClient; use solana_sdk::{ commitment_config::CommitmentLevel, signature::{Keypair, Signer}, + system_program, transaction::{Transaction, TransactionError}, }; @@ -57,7 +64,17 @@ impl TipRouterClient { Ok(()) } - pub async fn get_config(&mut self, ncn_pubkey: Pubkey) -> TestResult { + pub async fn get_restaking_config(&mut self) -> TestResult { + let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0; + let restaking_config_data = self + .banks_client + .get_account(restaking_config) + .await? + .unwrap(); + Ok(*Config::try_from_slice_unchecked(restaking_config_data.data.as_slice()).unwrap()) + } + + pub async fn get_ncn_config(&mut self, ncn_pubkey: Pubkey) -> TestResult { let config_pda = NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn_pubkey).0; let config = self.banks_client.get_account(config_pda).await?.unwrap(); @@ -86,10 +103,12 @@ impl TipRouterClient { ncn_fee_bps: u64, block_engine_fee_bps: u64, ) -> TestResult<()> { - let config_pda = NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn).0; + let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0; + let ncn_config = NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn).0; - let ix = InitializeConfigBuilder::new() - .config(config_pda) + let ix = InitializeNCNConfigBuilder::new() + .restaking_config(restaking_config) + .ncn_config(ncn_config) .ncn(ncn) .ncn_admin(ncn_admin.pubkey()) .fee_wallet(fee_wallet) @@ -141,7 +160,10 @@ impl TipRouterClient { fee_wallet: Pubkey, ncn_root: &NcnRoot, ) -> TestResult<()> { + let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0; + let ix = SetConfigFeesBuilder::new() + .restaking_config(restaking_config) .config(config_pda) .ncn(ncn_root.ncn_pubkey) .ncn_admin(ncn_root.ncn_admin.pubkey()) @@ -200,6 +222,91 @@ impl TipRouterClient { )) .await } + + pub async fn do_initialize_weight_table( + &mut self, + ncn: Pubkey, + current_slot: u64, + ) -> TestResult<()> { + self.initialize_weight_table(ncn, current_slot).await + } + + pub async fn initialize_weight_table( + &mut self, + ncn: Pubkey, + current_slot: u64, + ) -> TestResult<()> { + let restaking_config = Config::find_program_address(&jito_restaking_program::id()).0; + + let restaking_config_account = self.get_restaking_config().await?; + let ncn_epoch = current_slot / restaking_config_account.epoch_length(); + + let config_pda = NcnConfig::find_program_address(&jito_tip_router_program::id(), &ncn).0; + let weight_table = + WeightTable::find_program_address(&jito_tip_router_program::id(), &ncn, ncn_epoch).0; + + let ix = InitializeWeightTableBuilder::new() + .restaking_config(restaking_config) + .ncn_config(config_pda) + .ncn(ncn) + .weight_table(weight_table) + .payer(self.payer.pubkey()) + .restaking_program_id(jito_restaking_program::id()) + .system_program(system_program::id()) + .instruction(); + + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.process_transaction(&Transaction::new_signed_with_payer( + &[ix], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + )) + .await + } + + pub async fn do_admin_update_weight_table( + &mut self, + ncn: Pubkey, + current_slot: u64, + mint: Pubkey, + weight: u128, + ) -> TestResult<()> { + self.admin_update_weight_table(ncn, current_slot, mint, weight) + .await + } + + pub async fn admin_update_weight_table( + &mut self, + ncn: Pubkey, + current_slot: u64, + mint: Pubkey, + weight: u128, + ) -> TestResult<()> { + let restaking_config_account = self.get_restaking_config().await?; + let ncn_epoch = current_slot / restaking_config_account.epoch_length(); + + let weight_table = + WeightTable::find_program_address(&jito_tip_router_program::id(), &ncn, ncn_epoch).0; + + let ix = AdminUpdateWeightTableBuilder::new() + .ncn(ncn) + .weight_table(weight_table) + .weight_table_admin(self.payer.pubkey()) + .mint(mint) + .restaking_program_id(jito_restaking_program::id()) + .weight(weight) + .instruction(); + + let blockhash = self.banks_client.get_latest_blockhash().await?; + self.process_transaction(&Transaction::new_signed_with_payer( + &[ix], + Some(&self.payer.pubkey()), + &[&self.payer], + blockhash, + )) + .await + } } #[inline(always)] diff --git a/integration_tests/tests/tip_router/admin_update_weight_table.rs b/integration_tests/tests/tip_router/admin_update_weight_table.rs new file mode 100644 index 0000000..dc91213 --- /dev/null +++ b/integration_tests/tests/tip_router/admin_update_weight_table.rs @@ -0,0 +1,37 @@ +#[cfg(test)] +mod tests { + + use solana_sdk::pubkey::Pubkey; + + use crate::fixtures::{test_builder::TestBuilder, TestResult}; + + #[tokio::test] + async fn test_admin_update_weight_table() -> TestResult<()> { + let mut fixture = TestBuilder::new().await; + let mut tip_router_client = fixture.tip_router_client(); + let ncn_root = fixture.setup_ncn().await?; + + fixture.warp_slot_incremental(1000).await?; + + let slot = fixture.clock().await.slot; + + //TODO fix when config has mints + tip_router_client + .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin) + .await?; + + tip_router_client + .do_initialize_weight_table(ncn_root.ncn_pubkey, slot) + .await?; + + let mint = Pubkey::new_unique(); + let weight = 100; + + tip_router_client + .do_admin_update_weight_table(ncn_root.ncn_pubkey, slot, mint, weight) + .await?; + + //TODO add functionality to update weight table + Ok(()) + } +} diff --git a/integration_tests/tests/tip_router/initialize_weight_table.rs b/integration_tests/tests/tip_router/initialize_weight_table.rs new file mode 100644 index 0000000..86c747f --- /dev/null +++ b/integration_tests/tests/tip_router/initialize_weight_table.rs @@ -0,0 +1,26 @@ +#[cfg(test)] +mod tests { + + use crate::fixtures::{test_builder::TestBuilder, TestResult}; + + #[tokio::test] + async fn test_initialize_weight_table_ok() -> TestResult<()> { + let mut fixture = TestBuilder::new().await; + let mut tip_router_client = fixture.tip_router_client(); + let ncn_root = fixture.setup_ncn().await?; + + fixture.warp_slot_incremental(1000).await?; + + let slot = fixture.clock().await.slot; + + //TODO fix when config has mints + tip_router_client + .do_initialize_config(ncn_root.ncn_pubkey, &ncn_root.ncn_admin) + .await?; + + tip_router_client + .do_initialize_weight_table(ncn_root.ncn_pubkey, slot) + .await?; + Ok(()) + } +} diff --git a/integration_tests/tests/tip_router/mod.rs b/integration_tests/tests/tip_router/mod.rs index 04d688f..dd9a5a4 100644 --- a/integration_tests/tests/tip_router/mod.rs +++ b/integration_tests/tests/tip_router/mod.rs @@ -1,3 +1,5 @@ +mod admin_update_weight_table; mod initialize_ncn_config; +mod initialize_weight_table; mod set_config_fees; mod set_new_admin; diff --git a/integration_tests/tests/tip_router/set_config_fees.rs b/integration_tests/tests/tip_router/set_config_fees.rs index dd79393..b99312d 100644 --- a/integration_tests/tests/tip_router/set_config_fees.rs +++ b/integration_tests/tests/tip_router/set_config_fees.rs @@ -98,7 +98,9 @@ mod tests { .warp_slot_incremental(2 * DEFAULT_SLOTS_PER_EPOCH) .await?; - let config = tip_router_client.get_config(ncn_root.ncn_pubkey).await?; + let config = tip_router_client + .get_ncn_config(ncn_root.ncn_pubkey) + .await?; let clock = fixture.clock().await; assert_eq!(config.fees.dao_fee(clock.epoch as u64).unwrap(), 100); assert_eq!(config.fees.ncn_fee(clock.epoch as u64).unwrap(), 200); diff --git a/integration_tests/tests/tip_router/set_new_admin.rs b/integration_tests/tests/tip_router/set_new_admin.rs index 14f19c0..8f56adc 100644 --- a/integration_tests/tests/tip_router/set_new_admin.rs +++ b/integration_tests/tests/tip_router/set_new_admin.rs @@ -24,7 +24,9 @@ mod tests { .do_set_new_admin(ConfigAdminRole::FeeAdmin, new_fee_admin, &ncn_root) .await?; - let config = tip_router_client.get_config(ncn_root.ncn_pubkey).await?; + let config = tip_router_client + .get_ncn_config(ncn_root.ncn_pubkey) + .await?; assert_eq!(config.fee_admin, new_fee_admin); let new_tie_breaker = Pubkey::new_unique(); @@ -32,7 +34,9 @@ mod tests { .do_set_new_admin(ConfigAdminRole::TieBreakerAdmin, new_tie_breaker, &ncn_root) .await?; - let config = tip_router_client.get_config(ncn_root.ncn_pubkey).await?; + let config = tip_router_client + .get_ncn_config(ncn_root.ncn_pubkey) + .await?; assert_eq!(config.tie_breaker_admin, new_tie_breaker); Ok(()) } diff --git a/program/src/update_weight_table.rs b/program/src/admin_update_weight_table.rs similarity index 70% rename from program/src/update_weight_table.rs rename to program/src/admin_update_weight_table.rs index aa9b167..ea52234 100644 --- a/program/src/update_weight_table.rs +++ b/program/src/admin_update_weight_table.rs @@ -1,19 +1,18 @@ -use jito_bytemuck::{types::PodU64, AccountDeserialize}; +use jito_bytemuck::AccountDeserialize; use jito_jsm_core::loader::{load_signer, load_token_mint}; use jito_restaking_core::ncn::Ncn; use jito_tip_router_core::{error::TipRouterError, weight_table::WeightTable}; use solana_program::{ - account_info::AccountInfo, entrypoint::ProgramResult, msg, program_error::ProgramError, - pubkey::Pubkey, + account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, msg, + program_error::ProgramError, pubkey::Pubkey, sysvar::Sysvar, }; -/// Initializes a Weight Table -pub fn process_update_weight_table( +/// Updates weight table +pub fn process_admin_update_weight_table( program_id: &Pubkey, accounts: &[AccountInfo], ncn_epoch: u64, - weight_numerator: u64, - weight_denominator: u64, + weight: u128, ) -> ProgramResult { let [ncn, weight_table, weight_table_admin, mint, restaking_program_id] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); @@ -21,7 +20,6 @@ pub fn process_update_weight_table( Ncn::load(restaking_program_id.key, ncn, false)?; let ncn_weight_table_admin = { - //TODO switch to weight table admin when that is merged let ncn_data = ncn.data.borrow(); let ncn = Ncn::try_from_slice_unchecked(&ncn_data)?; ncn.admin @@ -44,14 +42,9 @@ pub fn process_update_weight_table( let mut weight_table_data = weight_table.try_borrow_mut_data()?; let weight_table_account = WeightTable::try_from_slice_unchecked_mut(&mut weight_table_data)?; - weight_table_account.set_weight( - mint.key, - PodU64::from( - weight_numerator - .checked_div(weight_denominator) - .ok_or(TipRouterError::DenominatorIsZero)?, - ), - )?; + weight_table_account.check_initialized()?; + + weight_table_account.set_weight(mint.key, weight, Clock::get()?.slot)?; Ok(()) } diff --git a/program/src/finalize_weight_table.rs b/program/src/finalize_weight_table.rs index 8e5a9f1..76583c0 100644 --- a/program/src/finalize_weight_table.rs +++ b/program/src/finalize_weight_table.rs @@ -12,6 +12,8 @@ pub fn process_finalize_weight_table( program_id: &Pubkey, accounts: &[AccountInfo], ncn_epoch: u64, + mint_hash: u64, + mint_count: u8, ) -> ProgramResult { let [ncn, weight_table, weight_table_admin, restaking_program_id] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); @@ -19,10 +21,9 @@ pub fn process_finalize_weight_table( Ncn::load(restaking_program_id.key, ncn, false)?; let ncn_weight_table_admin = { - //TODO switch to weight table admin when that is merged let ncn_data = ncn.data.borrow(); let ncn = Ncn::try_from_slice_unchecked(&ncn_data)?; - ncn.admin + ncn.weight_table_admin }; load_signer(weight_table_admin, true)?; @@ -41,6 +42,8 @@ pub fn process_finalize_weight_table( let mut weight_table_data = weight_table.try_borrow_mut_data()?; let weight_table_account = WeightTable::try_from_slice_unchecked_mut(&mut weight_table_data)?; + weight_table_account.check_mints_okay(mint_hash, mint_count)?; + let current_slot = Clock::get()?.slot; weight_table_account.finalize(current_slot); diff --git a/program/src/initialize_ncn_config.rs b/program/src/initialize_ncn_config.rs index a1fe566..853d816 100644 --- a/program/src/initialize_ncn_config.rs +++ b/program/src/initialize_ncn_config.rs @@ -3,7 +3,7 @@ use jito_jsm_core::{ create_account, loader::{load_signer, load_system_account, load_system_program}, }; -use jito_restaking_core::ncn::Ncn; +use jito_restaking_core::{config::Config, ncn::Ncn}; use jito_tip_router_core::{error::TipRouterError, fees::Fees, ncn_config::NcnConfig, MAX_FEE_BPS}; use solana_program::{ account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, @@ -17,17 +17,31 @@ pub fn process_initialize_ncn_config( ncn_fee_bps: u64, block_engine_fee_bps: u64, ) -> ProgramResult { - let [config, ncn_account, fee_wallet, ncn_admin, tie_breaker_admin, restaking_program_id, system_program] = + let [restaking_config, ncn_config, ncn_account, fee_wallet, ncn_admin, tie_breaker_admin, restaking_program_id, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; - load_system_account(config, true)?; + load_system_account(ncn_config, true)?; load_system_program(system_program)?; load_signer(ncn_admin, false)?; Ncn::load(restaking_program_id.key, ncn_account, false)?; + Config::load(restaking_program_id.key, restaking_config, false)?; + + let ncn_epoch_length = { + let config_data = restaking_config.data.borrow(); + let config = Config::try_from_slice_unchecked(&config_data)?; + config.epoch_length() + }; + + let epoch = { + let current_slot = Clock::get()?.slot; + current_slot + .checked_div(ncn_epoch_length) + .ok_or(TipRouterError::DenominatorIsZero)? + }; let ncn_data = ncn_account.data.borrow(); let ncn = Ncn::try_from_slice_unchecked(&ncn_data)?; @@ -39,7 +53,7 @@ pub fn process_initialize_ncn_config( NcnConfig::find_program_address(program_id, ncn_account.key); config_seeds.push(vec![config_bump]); - if config_pda != *config.key { + if config_pda != *ncn_config.key { return Err(ProgramError::InvalidSeeds); } @@ -55,7 +69,7 @@ pub fn process_initialize_ncn_config( create_account( ncn_admin, - config, + ncn_config, system_program, program_id, &Rent::get()?, @@ -65,9 +79,7 @@ pub fn process_initialize_ncn_config( &config_seeds, )?; - let epoch = Clock::get()?.epoch; - - let mut config_data = config.try_borrow_mut_data()?; + let mut config_data = ncn_config.try_borrow_mut_data()?; config_data[0] = NcnConfig::DISCRIMINATOR; let config = NcnConfig::try_from_slice_unchecked_mut(&mut config_data)?; *config = NcnConfig::new( diff --git a/program/src/initialize_weight_table.rs b/program/src/initialize_weight_table.rs index d64bddc..9ef5ef4 100644 --- a/program/src/initialize_weight_table.rs +++ b/program/src/initialize_weight_table.rs @@ -5,8 +5,10 @@ use jito_jsm_core::{ create_account, loader::{load_signer, load_system_account, load_system_program}, }; -use jito_restaking_core::{config::Config, ncn::Ncn}; -use jito_tip_router_core::{error::TipRouterError, weight_table::WeightTable}; +use jito_restaking_core::config::Config; +use jito_tip_router_core::{ + error::TipRouterError, ncn_config::NcnConfig, weight_table::WeightTable, +}; use solana_program::{ account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, msg, program_error::ProgramError, pubkey::Pubkey, rent::Rent, sysvar::Sysvar, @@ -19,40 +21,36 @@ pub fn process_initialize_weight_table( accounts: &[AccountInfo], first_slot_of_ncn_epoch: Option, ) -> ProgramResult { - let [restaking_config, ncn, weight_table, weight_table_admin, restaking_program_id, system_program] = + let [restaking_config, ncn_config, ncn, weight_table, payer, restaking_program_id, system_program] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; + + NcnConfig::load(program_id, ncn.key, ncn_config, false)?; Config::load(restaking_program_id.key, restaking_config, false)?; + let ncn_epoch_length = { let config_data = restaking_config.data.borrow(); let config = Config::try_from_slice_unchecked(&config_data)?; config.epoch_length() }; - Ncn::load(restaking_program_id.key, ncn, false)?; - let ncn_weight_table_admin = { - //TODO switch to weight table admin when that is merged - let ncn_data = ncn.data.borrow(); - let ncn = Ncn::try_from_slice_unchecked(&ncn_data)?; - ncn.admin + let _todo_pubkeys = { + let ncn_config_data = ncn_config.data.borrow(); + let ncn_config = NcnConfig::try_from_slice_unchecked(&ncn_config_data)?; + ncn_config.bump }; load_system_account(weight_table, true)?; - load_signer(weight_table_admin, true)?; load_system_program(system_program)?; + load_signer(payer, true)?; if restaking_program_id.key.ne(&jito_restaking_program::id()) { msg!("Incorrect restaking program ID"); return Err(ProgramError::InvalidAccountData); } - if ncn_weight_table_admin.ne(weight_table_admin.key) { - msg!("Vault update delegations ticket is not at the correct PDA"); - return Err(TipRouterError::IncorrectWeightTableAdmin.into()); - } - let current_slot = Clock::get()?.slot; let current_ncn_epoch = current_slot .checked_div(ncn_epoch_length) @@ -84,7 +82,7 @@ pub fn process_initialize_weight_table( ncn_epoch ); create_account( - weight_table_admin, + payer, weight_table, system_program, program_id, @@ -99,5 +97,8 @@ pub fn process_initialize_weight_table( *weight_table_account = WeightTable::new(*ncn.key, ncn_epoch, current_slot, weight_table_bump); + //TODO pass in st_mint list from config + weight_table_account.initalize_weight_table(&[])?; + Ok(()) } diff --git a/program/src/lib.rs b/program/src/lib.rs index f91459d..77761aa 100644 --- a/program/src/lib.rs +++ b/program/src/lib.rs @@ -1,9 +1,8 @@ -mod finalize_weight_table; +mod admin_update_weight_table; mod initialize_ncn_config; mod initialize_weight_table; mod set_config_fees; mod set_new_admin; -mod update_weight_table; use borsh::BorshDeserialize; use const_str_to_pubkey::str_to_pubkey; @@ -17,10 +16,10 @@ use solana_program::{ use solana_security_txt::security_txt; use crate::{ - finalize_weight_table::process_finalize_weight_table, + admin_update_weight_table::process_admin_update_weight_table, initialize_ncn_config::process_initialize_ncn_config, initialize_weight_table::process_initialize_weight_table, - set_config_fees::process_set_config_fees, update_weight_table::process_update_weight_table, + set_config_fees::process_set_config_fees, }; declare_id!(str_to_pubkey(env!("TIP_ROUTER_PROGRAM_ID"))); @@ -55,7 +54,7 @@ pub fn process_instruction( // ------------------------------------------ // Initialization // ------------------------------------------ - WeightTableInstruction::InitializeConfig { + WeightTableInstruction::InitializeNCNConfig { dao_fee_bps, ncn_fee_bps, block_engine_fee_bps, @@ -78,26 +77,9 @@ pub fn process_instruction( // ------------------------------------------ // Update // ------------------------------------------ - WeightTableInstruction::UpdateWeightTable { - ncn_epoch, - weight_numerator, - weight_denominator, - } => { + WeightTableInstruction::AdminUpdateWeightTable { ncn_epoch, weight } => { msg!("Instruction: UpdateWeightTable"); - process_update_weight_table( - program_id, - accounts, - ncn_epoch, - weight_numerator, - weight_denominator, - ) - } - // ------------------------------------------ - // Finalization - // ------------------------------------------ - WeightTableInstruction::FinalizeWeightTable { ncn_epoch } => { - msg!("Instruction: FinalizeWeightTable"); - process_finalize_weight_table(program_id, accounts, ncn_epoch) + process_admin_update_weight_table(program_id, accounts, ncn_epoch, weight) } WeightTableInstruction::SetConfigFees { new_dao_fee_bps, diff --git a/program/src/set_config_fees.rs b/program/src/set_config_fees.rs index ad7b3be..0a25946 100644 --- a/program/src/set_config_fees.rs +++ b/program/src/set_config_fees.rs @@ -1,6 +1,6 @@ use jito_bytemuck::{AccountDeserialize, Discriminator}; use jito_jsm_core::loader::load_signer; -use jito_restaking_core::ncn::Ncn; +use jito_restaking_core::{config::Config, ncn::Ncn}; use jito_tip_router_core::{error::TipRouterError, ncn_config::NcnConfig}; use solana_program::{ account_info::AccountInfo, clock::Clock, entrypoint::ProgramResult, @@ -15,7 +15,7 @@ pub fn process_set_config_fees( new_block_engine_fee_bps: Option, new_fee_wallet: Option, ) -> ProgramResult { - let [config, ncn_account, fee_admin, restaking_program_id] = accounts else { + let [restaking_config, config, ncn_account, fee_admin, restaking_program_id] = accounts else { return Err(ProgramError::NotEnoughAccountKeys); }; @@ -23,6 +23,20 @@ pub fn process_set_config_fees( NcnConfig::load(program_id, ncn_account.key, config, true)?; Ncn::load(restaking_program_id.key, ncn_account, false)?; + Config::load(restaking_program_id.key, restaking_config, false)?; + + let ncn_epoch_length = { + let config_data = restaking_config.data.borrow(); + let config = Config::try_from_slice_unchecked(&config_data)?; + config.epoch_length() + }; + + let epoch = { + let current_slot = Clock::get()?.slot; + current_slot + .checked_div(ncn_epoch_length) + .ok_or(TipRouterError::DenominatorIsZero)? + }; let mut config_data = config.try_borrow_mut_data()?; if config_data[0] != NcnConfig::DISCRIMINATOR { @@ -39,7 +53,6 @@ pub fn process_set_config_fees( return Err(TipRouterError::IncorrectFeeAdmin.into()); } - let epoch = Clock::get()?.epoch; config.fees.set_new_fees( new_dao_fee_bps, new_ncn_fee_bps, diff --git a/scripts/generate-clients.js b/scripts/generate-clients.js index bae2eb4..73a0d1e 100644 --- a/scripts/generate-clients.js +++ b/scripts/generate-clients.js @@ -17,6 +17,22 @@ const jsWeightTableClientDir = path.join(jsClientsDir, "jito_tip_router"); const weightTableRootNode = anchorIdl.rootNodeFromAnchor(require(path.join(idlDir, "jito_tip_router.json"))); const weightTableKinobi = kinobi.createFromRoot(weightTableRootNode); weightTableKinobi.update(kinobi.bottomUpTransformerVisitor([ + { + // PodU128 -> u128 + select: (node) => { + return ( + kinobi.isNode(node, "structFieldTypeNode") && + node.type.name === "podU128" + ); + }, + transform: (node) => { + kinobi.assertIsNode(node, "structFieldTypeNode"); + return { + ...node, + type: kinobi.numberTypeNode("u128"), + }; + }, + }, { // PodU64 -> u64 select: (node) => {