From 2556e09b0bb143da5ef5bca41fdc45e9a3d0e985 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Tue, 10 Dec 2024 15:00:43 +0100 Subject: [PATCH 1/3] chore: update payment vault interface --- Cargo.lock | 494 +++--------------- autonomi/Cargo.toml | 2 +- autonomi/tests/external_signer.rs | 6 +- evmlib/abi/IPaymentVault.json | 147 +++--- evmlib/artifacts/DataPayments.json | 90 ---- evmlib/artifacts/PaymentVaultNoProxy.json | 351 +++++++++++++ evmlib/src/contract/payment_vault/error.rs | 2 + evmlib/src/contract/payment_vault/handler.rs | 35 +- .../contract/payment_vault/implementation.rs | 37 +- .../src/contract/payment_vault/interface.rs | 14 +- evmlib/src/contract/payment_vault/mod.rs | 29 +- evmlib/src/testnet.rs | 10 +- evmlib/tests/common/quote.rs | 2 +- evmlib/tests/payment_vault.rs | 58 +- 14 files changed, 642 insertions(+), 635 deletions(-) delete mode 100644 evmlib/artifacts/DataPayments.json create mode 100644 evmlib/artifacts/PaymentVaultNoProxy.json diff --git a/Cargo.lock b/Cargo.lock index 7d580d7a9d..2bc3dc97e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -116,51 +116,28 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" -[[package]] -name = "alloy" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea8ebf106e84a1c37f86244df7da0c7587e697b71a0d565cce079449b85ac6f8" -dependencies = [ - "alloy-consensus 0.5.4", - "alloy-contract 0.5.4", - "alloy-core", - "alloy-eips 0.5.4", - "alloy-genesis 0.5.4", - "alloy-network 0.5.4", - "alloy-node-bindings 0.5.4", - "alloy-provider 0.5.4", - "alloy-rpc-client 0.5.4", - "alloy-rpc-types 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", -] - [[package]] name = "alloy" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02b0561294ccedc6181e5528b850b4579e3fbde696507baa00109bfd9054c5bb" dependencies = [ - "alloy-consensus 0.7.3", - "alloy-contract 0.7.3", + "alloy-consensus", + "alloy-contract", "alloy-core", - "alloy-eips 0.7.3", - "alloy-genesis 0.7.3", - "alloy-json-rpc 0.7.3", - "alloy-network 0.7.3", - "alloy-node-bindings 0.7.3", - "alloy-provider 0.7.3", - "alloy-rpc-client 0.7.3", - "alloy-rpc-types 0.7.3", - "alloy-serde 0.7.3", - "alloy-signer 0.7.3", - "alloy-signer-local 0.7.3", - "alloy-transport 0.7.3", - "alloy-transport-http 0.7.3", + "alloy-eips", + "alloy-genesis", + "alloy-json-rpc", + "alloy-network", + "alloy-node-bindings", + "alloy-provider", + "alloy-rpc-client", + "alloy-rpc-types", + "alloy-serde", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", ] [[package]] @@ -174,32 +151,16 @@ dependencies = [ "strum", ] -[[package]] -name = "alloy-consensus" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41ed961a48297c732a5d97ee321aa8bb5009ecadbcb077d8bec90cb54e651629" -dependencies = [ - "alloy-eips 0.5.4", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.5.4", - "auto_impl", - "c-kzg", - "derive_more", - "serde", -] - [[package]] name = "alloy-consensus" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a101d4d016f47f13890a74290fdd17b05dd175191d9337bc600791fb96e4dea8" dependencies = [ - "alloy-eips 0.7.3", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.3", + "alloy-serde", "alloy-trie", "auto_impl", "c-kzg", @@ -213,34 +174,14 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa60357dda9a3d0f738f18844bd6d0f4a5924cc5cf00bfad2ff1369897966123" dependencies = [ - "alloy-consensus 0.7.3", - "alloy-eips 0.7.3", + "alloy-consensus", + "alloy-eips", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.3", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-contract" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460ab80ce4bda1c80bcf96fe7460520476f2c7b734581c6567fac2708e2a60ef" -dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network 0.5.4", - "alloy-network-primitives 0.5.4", - "alloy-primitives", - "alloy-provider 0.5.4", - "alloy-rpc-types-eth 0.5.4", - "alloy-sol-types", - "alloy-transport 0.5.4", - "futures", - "futures-util", - "thiserror 1.0.69", -] - [[package]] name = "alloy-contract" version = "0.7.3" @@ -249,13 +190,13 @@ checksum = "2869e4fb31331d3b8c58c7db567d1e4e4e94ef64640beda3b6dd9b7045690941" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", - "alloy-network 0.7.3", - "alloy-network-primitives 0.7.3", + "alloy-network", + "alloy-network-primitives", "alloy-primitives", - "alloy-provider 0.7.3", - "alloy-rpc-types-eth 0.7.3", + "alloy-provider", + "alloy-rpc-types-eth", "alloy-sol-types", - "alloy-transport 0.7.3", + "alloy-transport", "futures", "futures-util", "thiserror 2.0.6", @@ -302,18 +243,6 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-eip7702" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ffc577390ce50234e02d841214b3dc0bea6aaaae8e04bbf3cb82e9a45da9eb" -dependencies = [ - "alloy-primitives", - "alloy-rlp", - "derive_more", - "serde", -] - [[package]] name = "alloy-eip7702" version = "0.4.2" @@ -326,24 +255,6 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-eips" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69e06cf9c37be824b9d26d6d101114fdde6af0c87de2828b414c05c4b3daa71" -dependencies = [ - "alloy-eip2930", - "alloy-eip7702 0.3.2", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.5.4", - "c-kzg", - "derive_more", - "once_cell", - "serde", - "sha2 0.10.8", -] - [[package]] name = "alloy-eips" version = "0.7.3" @@ -351,10 +262,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b6755b093afef5925f25079dd5a7c8d096398b804ba60cb5275397b06b31689" dependencies = [ "alloy-eip2930", - "alloy-eip7702 0.4.2", + "alloy-eip7702", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.3", + "alloy-serde", "c-kzg", "derive_more", "once_cell", @@ -362,17 +273,6 @@ dependencies = [ "sha2 0.10.8", ] -[[package]] -name = "alloy-genesis" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dde15e14944a88bd6a57d325e9a49b75558746fe16aaccc79713ae50a6a9574c" -dependencies = [ - "alloy-primitives", - "alloy-serde 0.5.4", - "serde", -] - [[package]] name = "alloy-genesis" version = "0.7.3" @@ -380,7 +280,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aeec8e6eab6e52b7c9f918748c9b811e87dbef7312a2e3a2ca1729a92966a6af" dependencies = [ "alloy-primitives", - "alloy-serde 0.7.3", + "alloy-serde", "alloy-trie", "serde", ] @@ -397,20 +297,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-json-rpc" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5979e0d5a7bf9c7eb79749121e8256e59021af611322aee56e77e20776b4b3" -dependencies = [ - "alloy-primitives", - "alloy-sol-types", - "serde", - "serde_json", - "thiserror 1.0.69", - "tracing", -] - [[package]] name = "alloy-json-rpc" version = "0.7.3" @@ -425,43 +311,22 @@ dependencies = [ "tracing", ] -[[package]] -name = "alloy-network" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "204237129086ce5dc17a58025e93739b01b45313841f98fa339eb1d780511e57" -dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-json-rpc 0.5.4", - "alloy-network-primitives 0.5.4", - "alloy-primitives", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", - "alloy-signer 0.5.4", - "alloy-sol-types", - "async-trait", - "auto_impl", - "futures-utils-wasm", - "thiserror 1.0.69", -] - [[package]] name = "alloy-network" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "209a1882a08e21aca4aac6e2a674dc6fcf614058ef8cb02947d63782b1899552" dependencies = [ - "alloy-consensus 0.7.3", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.3", - "alloy-json-rpc 0.7.3", - "alloy-network-primitives 0.7.3", + "alloy-eips", + "alloy-json-rpc", + "alloy-network-primitives", "alloy-primitives", "alloy-rpc-types-any", - "alloy-rpc-types-eth 0.7.3", - "alloy-serde 0.7.3", - "alloy-signer 0.7.3", + "alloy-rpc-types-eth", + "alloy-serde", + "alloy-signer", "alloy-sol-types", "async-trait", "auto_impl", @@ -471,56 +336,26 @@ dependencies = [ "thiserror 2.0.6", ] -[[package]] -name = "alloy-network-primitives" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514f70ee2a953db21631cd817b13a1571474ec77ddc03d47616d5e8203489fde" -dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-primitives", - "alloy-serde 0.5.4", - "serde", -] - [[package]] name = "alloy-network-primitives" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c20219d1ad261da7a6331c16367214ee7ded41d001fabbbd656fbf71898b2773" dependencies = [ - "alloy-consensus 0.7.3", - "alloy-eips 0.7.3", + "alloy-consensus", + "alloy-eips", "alloy-primitives", - "alloy-serde 0.7.3", + "alloy-serde", "serde", ] -[[package]] -name = "alloy-node-bindings" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27444ea67d360508753022807cdd0b49a95c878924c9c5f8f32668b7d7768245" -dependencies = [ - "alloy-genesis 0.5.4", - "alloy-primitives", - "k256", - "rand 0.8.5", - "serde_json", - "tempfile", - "thiserror 1.0.69", - "tracing", - "url", -] - [[package]] name = "alloy-node-bindings" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bffcf33dd319f21cd6f066d81cbdef0326d4bdaaf7cfe91110bc090707858e9f" dependencies = [ - "alloy-genesis 0.7.3", + "alloy-genesis", "alloy-primitives", "k256", "rand 0.8.5", @@ -559,47 +394,6 @@ dependencies = [ "tiny-keccak", ] -[[package]] -name = "alloy-provider" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4814d141ede360bb6cd1b4b064f1aab9de391e7c4d0d4d50ac89ea4bc1e25fbd" -dependencies = [ - "alloy-chains", - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-json-rpc 0.5.4", - "alloy-network 0.5.4", - "alloy-network-primitives 0.5.4", - "alloy-node-bindings 0.5.4", - "alloy-primitives", - "alloy-rpc-client 0.5.4", - "alloy-rpc-types-anvil 0.5.4", - "alloy-rpc-types-eth 0.5.4", - "alloy-signer 0.5.4", - "alloy-signer-local 0.5.4", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", - "async-stream", - "async-trait", - "auto_impl", - "dashmap", - "futures", - "futures-utils-wasm", - "lru", - "parking_lot", - "pin-project", - "reqwest 0.12.9", - "schnellru", - "serde", - "serde_json", - "thiserror 1.0.69", - "tokio", - "tracing", - "url", - "wasmtimer 0.2.1", -] - [[package]] name = "alloy-provider" version = "0.7.3" @@ -607,20 +401,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9eefa6f4c798ad01f9b4202d02cea75f5ec11fa180502f4701e2b47965a8c0bb" dependencies = [ "alloy-chains", - "alloy-consensus 0.7.3", - "alloy-eips 0.7.3", - "alloy-json-rpc 0.7.3", - "alloy-network 0.7.3", - "alloy-network-primitives 0.7.3", - "alloy-node-bindings 0.7.3", + "alloy-consensus", + "alloy-eips", + "alloy-json-rpc", + "alloy-network", + "alloy-network-primitives", + "alloy-node-bindings", "alloy-primitives", - "alloy-rpc-client 0.7.3", - "alloy-rpc-types-anvil 0.7.3", - "alloy-rpc-types-eth 0.7.3", - "alloy-signer 0.7.3", - "alloy-signer-local 0.7.3", - "alloy-transport 0.7.3", - "alloy-transport-http 0.7.3", + "alloy-rpc-client", + "alloy-rpc-types-anvil", + "alloy-rpc-types-eth", + "alloy-signer", + "alloy-signer-local", + "alloy-transport", + "alloy-transport-http", "async-stream", "async-trait", "auto_impl", @@ -663,39 +457,16 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "alloy-rpc-client" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc2bd1e7403463a5f2c61e955bcc9d3072b63aa177442b0f9aa6a6d22a941e3" -dependencies = [ - "alloy-json-rpc 0.5.4", - "alloy-primitives", - "alloy-transport 0.5.4", - "alloy-transport-http 0.5.4", - "futures", - "pin-project", - "reqwest 0.12.9", - "serde", - "serde_json", - "tokio", - "tokio-stream", - "tower 0.5.1", - "tracing", - "url", - "wasmtimer 0.2.1", -] - [[package]] name = "alloy-rpc-client" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed30bf1041e84cabc5900f52978ca345dd9969f2194a945e6fdec25b0620705c" dependencies = [ - "alloy-json-rpc 0.7.3", + "alloy-json-rpc", "alloy-primitives", - "alloy-transport 0.7.3", - "alloy-transport-http 0.7.3", + "alloy-transport", + "alloy-transport-http", "futures", "pin-project", "reqwest 0.12.9", @@ -709,19 +480,6 @@ dependencies = [ "wasmtimer 0.4.1", ] -[[package]] -name = "alloy-rpc-types" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eea9bf1abdd506f985a53533f5ac01296bcd6102c5e139bbc5d40bc468d2c916" -dependencies = [ - "alloy-primitives", - "alloy-rpc-types-anvil 0.5.4", - "alloy-rpc-types-eth 0.5.4", - "alloy-serde 0.5.4", - "serde", -] - [[package]] name = "alloy-rpc-types" version = "0.7.3" @@ -729,19 +487,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ab686b0fa475d2a4f5916c5f07797734a691ec58e44f0f55d4746ea39cbcefb" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth 0.7.3", - "alloy-serde 0.7.3", - "serde", -] - -[[package]] -name = "alloy-rpc-types-anvil" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2382fc63fb0cf3e02818d547b80cb66cc49a31f8803d0c328402b2008bc13650" -dependencies = [ - "alloy-primitives", - "alloy-serde 0.5.4", + "alloy-rpc-types-eth", + "alloy-serde", "serde", ] @@ -752,8 +499,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d33bc190844626c08e21897736dbd7956ab323c09e6f141b118d1c8b7aff689e" dependencies = [ "alloy-primitives", - "alloy-rpc-types-eth 0.7.3", - "alloy-serde 0.7.3", + "alloy-rpc-types-eth", + "alloy-serde", "serde", ] @@ -764,27 +511,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "200661999b6e235d9840be5d60a6e8ae2f0af9eb2a256dd378786744660e36ec" dependencies = [ "alloy-consensus-any", - "alloy-rpc-types-eth 0.7.3", - "alloy-serde 0.7.3", -] - -[[package]] -name = "alloy-rpc-types-eth" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b034779a4850b4b03f5be5ea674a1cf7d746b2da762b34d1860ab45e48ca27" -dependencies = [ - "alloy-consensus 0.5.4", - "alloy-eips 0.5.4", - "alloy-network-primitives 0.5.4", - "alloy-primitives", - "alloy-rlp", - "alloy-serde 0.5.4", - "alloy-sol-types", - "derive_more", - "itertools 0.13.0", - "serde", - "serde_json", + "alloy-rpc-types-eth", + "alloy-serde", ] [[package]] @@ -793,13 +521,13 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0600b8b5e2dc0cab12cbf91b5a885c35871789fb7b3a57b434bd4fced5b7a8b" dependencies = [ - "alloy-consensus 0.7.3", + "alloy-consensus", "alloy-consensus-any", - "alloy-eips 0.7.3", - "alloy-network-primitives 0.7.3", + "alloy-eips", + "alloy-network-primitives", "alloy-primitives", "alloy-rlp", - "alloy-serde 0.7.3", + "alloy-serde", "alloy-sol-types", "derive_more", "itertools 0.13.0", @@ -807,17 +535,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-serde" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "028e72eaa9703e4882344983cfe7636ce06d8cce104a78ea62fd19b46659efc4" -dependencies = [ - "alloy-primitives", - "serde", - "serde_json", -] - [[package]] name = "alloy-serde" version = "0.7.3" @@ -829,20 +546,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "alloy-signer" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "592c185d7100258c041afac51877660c7bf6213447999787197db4842f0e938e" -dependencies = [ - "alloy-primitives", - "async-trait", - "auto_impl", - "elliptic-curve 0.13.8", - "k256", - "thiserror 1.0.69", -] - [[package]] name = "alloy-signer" version = "0.7.3" @@ -857,32 +560,16 @@ dependencies = [ "thiserror 2.0.6", ] -[[package]] -name = "alloy-signer-local" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6614f02fc1d5b079b2a4a5320018317b506fd0a6d67c1fd5542a71201724986c" -dependencies = [ - "alloy-consensus 0.5.4", - "alloy-network 0.5.4", - "alloy-primitives", - "alloy-signer 0.5.4", - "async-trait", - "k256", - "rand 0.8.5", - "thiserror 1.0.69", -] - [[package]] name = "alloy-signer-local" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd6d988cb6cd7d2f428a74476515b1a6e901e08c796767f9f93311ab74005c8b" dependencies = [ - "alloy-consensus 0.7.3", - "alloy-network 0.7.3", + "alloy-consensus", + "alloy-network", "alloy-primitives", - "alloy-signer 0.7.3", + "alloy-signer", "async-trait", "k256", "rand 0.8.5", @@ -962,33 +649,13 @@ dependencies = [ "serde", ] -[[package]] -name = "alloy-transport" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be77579633ebbc1266ae6fd7694f75c408beb1aeb6865d0b18f22893c265a061" -dependencies = [ - "alloy-json-rpc 0.5.4", - "base64 0.22.1", - "futures-util", - "futures-utils-wasm", - "serde", - "serde_json", - "thiserror 1.0.69", - "tokio", - "tower 0.5.1", - "tracing", - "url", - "wasmtimer 0.2.1", -] - [[package]] name = "alloy-transport" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d69d36982b9e46075ae6b792b0f84208c6c2c15ad49f6c500304616ef67b70e0" dependencies = [ - "alloy-json-rpc 0.7.3", + "alloy-json-rpc", "base64 0.22.1", "futures-util", "futures-utils-wasm", @@ -1003,29 +670,14 @@ dependencies = [ "wasmtimer 0.4.1", ] -[[package]] -name = "alloy-transport-http" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91fd1a5d0827939847983b46f2f79510361f901dc82f8e3c38ac7397af142c6e" -dependencies = [ - "alloy-json-rpc 0.5.4", - "alloy-transport 0.5.4", - "reqwest 0.12.9", - "serde_json", - "tower 0.5.1", - "tracing", - "url", -] - [[package]] name = "alloy-transport-http" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e02ffd5d93ffc51d72786e607c97de3b60736ca3e636ead0ec1f7dce68ea3fd" dependencies = [ - "alloy-json-rpc 0.7.3", - "alloy-transport 0.7.3", + "alloy-json-rpc", + "alloy-transport", "reqwest 0.12.9", "serde_json", "tower 0.5.1", @@ -1898,7 +1550,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" name = "autonomi" version = "0.2.4" dependencies = [ - "alloy 0.5.4", + "alloy", "ant-evm", "ant-logging", "ant-networking", @@ -3649,7 +3301,7 @@ dependencies = [ name = "evmlib" version = "0.1.4" dependencies = [ - "alloy 0.7.3", + "alloy", "dirs-next", "getrandom 0.2.15", "rand 0.8.5", diff --git a/autonomi/Cargo.toml b/autonomi/Cargo.toml index b154f9d8f5..f5cbf14744 100644 --- a/autonomi/Cargo.toml +++ b/autonomi/Cargo.toml @@ -61,7 +61,7 @@ wasm-bindgen-futures = "0.4.43" xor_name = "5.0.0" [dev-dependencies] -alloy = { version = "0.5.3", default-features = false, features = ["std", "reqwest-rustls-tls", "provider-anvil-node", "sol-types", "json", "signers", "contract", "signer-local", "network"] } +alloy = { version = "0.7.3", default-features = false, features = ["contract", "json-rpc", "network", "node-bindings", "provider-http", "reqwest-rustls-tls", "rpc-client", "rpc-types", "signer-local", "std"] } ant-logging = { path = "../ant-logging", version = "0.2.40" } ant-peers-acquisition = { path = "../ant-peers-acquisition", version = "0.5.7" } eyre = "0.6.5" diff --git a/autonomi/tests/external_signer.rs b/autonomi/tests/external_signer.rs index 2f8dbde8a9..9ef392f8a0 100644 --- a/autonomi/tests/external_signer.rs +++ b/autonomi/tests/external_signer.rs @@ -1,11 +1,13 @@ #![cfg(feature = "external-signer")] +use alloy::network::TransactionBuilder; +use alloy::providers::Provider; use ant_evm::{QuoteHash, TxHash}; use ant_logging::LogBuilder; use autonomi::client::archive::Metadata; use autonomi::client::archive_private::PrivateArchive; use autonomi::client::external_signer::encrypt_data; -use autonomi::client::payment::Receipt; +use autonomi::client::payment::{receipt_from_store_quotes_and_payments, Receipt}; use autonomi::client::vault::user_data::USER_DATA_VAULT_CONTENT_IDENTIFIER; use autonomi::client::vault::VaultSecretKey; use autonomi::{Client, Wallet}; @@ -92,7 +94,7 @@ async fn pay_for_content_addresses( } // Payment proofs - Ok(receipt_from_quotes_and_payments("es, &payments)) + Ok(receipt_from_store_quotes_and_payments("es, payments)) } // Example of how put would be done using external signers. diff --git a/evmlib/abi/IPaymentVault.json b/evmlib/abi/IPaymentVault.json index 48f3303a77..d2bc495a5f 100644 --- a/evmlib/abi/IPaymentVault.json +++ b/evmlib/abi/IPaymentVault.json @@ -1,4 +1,19 @@ [ + { + "inputs": [], + "name": "AntTokenNull", + "type": "error" + }, + { + "inputs": [], + "name": "BatchLimitExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInputLength", + "type": "error" + }, { "anonymous": false, "inputs": [ @@ -24,16 +39,6 @@ "name": "DataPaymentMade", "type": "event" }, - { - "inputs": [], - "name": "AntTokenNull", - "type": "error" - }, - { - "inputs": [], - "name": "BatchLimitExceeded", - "type": "error" - }, { "inputs": [ { @@ -120,72 +125,96 @@ { "components": [ { - "internalType": "uint256", - "name": "closeRecordsStored", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxRecords", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "receivedPaymentCount", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "liveTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "networkDensity", - "type": "uint256" + "components": [ + { + "internalType": "uint256", + "name": "closeRecordsStored", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxRecords", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "receivedPaymentCount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liveTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkDensity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkSize", + "type": "uint256" + } + ], + "internalType": "struct IPaymentVault.QuotingMetrics", + "name": "metrics", + "type": "tuple" }, { - "internalType": "uint256", - "name": "networkSize", - "type": "uint256" + "components": [ + { + "internalType": "address", + "name": "rewardsAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + } + ], + "internalType": "struct IPaymentVault.DataPayment", + "name": "dataPayment", + "type": "tuple" } ], - "internalType": "struct IPaymentVault.QuotingMetrics", - "name": "_metrics", - "type": "tuple" - }, + "internalType": "struct IPaymentVault.PaymentVerification[]", + "name": "_payments", + "type": "tuple[]" + } + ], + "name": "verifyPayment", + "outputs": [ { "components": [ { - "internalType": "address", - "name": "rewardsAddress", - "type": "address" + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" }, { "internalType": "uint256", - "name": "amount", + "name": "amountPaid", "type": "uint256" }, { - "internalType": "bytes32", - "name": "quoteHash", - "type": "bytes32" + "internalType": "bool", + "name": "isValid", + "type": "bool" } ], - "internalType": "struct IPaymentVault.DataPayment", - "name": "_payment", - "type": "tuple" - } - ], - "name": "verifyPayment", - "outputs": [ - { - "internalType": "bool", - "name": "isValid", - "type": "bool" + "internalType": "struct IPaymentVault.PaymentVerificationResult[3]", + "name": "verificationResults", + "type": "tuple[3]" } ], "stateMutability": "view", "type": "function" } -] +] \ No newline at end of file diff --git a/evmlib/artifacts/DataPayments.json b/evmlib/artifacts/DataPayments.json deleted file mode 100644 index a72afa0b8b..0000000000 --- a/evmlib/artifacts/DataPayments.json +++ /dev/null @@ -1,90 +0,0 @@ -{ - "_format": "hh-sol-artifact-1", - "contractName": "DataPayments", - "sourceName": "contracts/DataPayments.sol", - "abi": [ - { - "inputs": [ - { - "internalType": "address", - "name": "_tokenAddress", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "rewardsAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "bytes32", - "name": "quoteHash", - "type": "bytes32" - } - ], - "name": "DataPaymentMade", - "type": "event" - }, - { - "inputs": [], - "name": "PAYMENT_TOKEN_ADDRESS", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "rewardsAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "quoteHash", - "type": "bytes32" - } - ], - "internalType": "struct DataPayments.DataPayment[]", - "name": "dataPayments", - "type": "tuple[]" - } - ], - "name": "submitDataPayments", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } - ], - "bytecode": "0x60a060405234801561001057600080fd5b506040516105f73803806105f783398101604081905261002f916100a6565b6001600160a01b0381166100955760405162461bcd60e51b8152602060048201526024808201527f546f6b656e20616464726573732063616e6e6f74206265207a65726f206164646044820152637265737360e01b606482015260840160405180910390fd5b6001600160a01b03166080526100d6565b6000602082840312156100b857600080fd5b81516001600160a01b03811681146100cf57600080fd5b9392505050565b6080516104f26101056000396000818160400152818161015101528181610253015261035301526104f26000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80635c0d32861461003b578063dee1dfa01461007e575b600080fd5b6100627f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b61009161008c3660046103c6565b610093565b005b60005b8181101561012b57368383838181106100b1576100b161043b565b6060029190910191506100d79050336100cd6020840184610451565b8360200135610130565b6040810135602082018035906100ed9084610451565b6001600160a01b03167ff998960b1c6f0e0e89b7bbe6b6fbf3e03e6f08eee5b8430877d8adb8e149d58060405160405180910390a450600101610096565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa15801561019a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101be9190610481565b101561021c5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b038316301461032557604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561029c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c09190610481565b10156103255760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610213565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561039c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c0919061049a565b50505050565b600080602083850312156103d957600080fd5b823567ffffffffffffffff808211156103f157600080fd5b818501915085601f83011261040557600080fd5b81358181111561041457600080fd5b86602060608302850101111561042957600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561046357600080fd5b81356001600160a01b038116811461047a57600080fd5b9392505050565b60006020828403121561049357600080fd5b5051919050565b6000602082840312156104ac57600080fd5b8151801515811461047a57600080fdfea26469706673582212206f3a305284dc687832455d7d49b202dcf22b32d76aff5ccd14c3c8539596bcf464736f6c63430008180033", - "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c80635c0d32861461003b578063dee1dfa01461007e575b600080fd5b6100627f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b61009161008c3660046103c6565b610093565b005b60005b8181101561012b57368383838181106100b1576100b161043b565b6060029190910191506100d79050336100cd6020840184610451565b8360200135610130565b6040810135602082018035906100ed9084610451565b6001600160a01b03167ff998960b1c6f0e0e89b7bbe6b6fbf3e03e6f08eee5b8430877d8adb8e149d58060405160405180910390a450600101610096565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa15801561019a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101be9190610481565b101561021c5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b038316301461032557604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561029c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c09190610481565b10156103255760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610213565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561039c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c0919061049a565b50505050565b600080602083850312156103d957600080fd5b823567ffffffffffffffff808211156103f157600080fd5b818501915085601f83011261040557600080fd5b81358181111561041457600080fd5b86602060608302850101111561042957600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561046357600080fd5b81356001600160a01b038116811461047a57600080fd5b9392505050565b60006020828403121561049357600080fd5b5051919050565b6000602082840312156104ac57600080fd5b8151801515811461047a57600080fdfea26469706673582212206f3a305284dc687832455d7d49b202dcf22b32d76aff5ccd14c3c8539596bcf464736f6c63430008180033", - "linkReferences": {}, - "deployedLinkReferences": {} -} \ No newline at end of file diff --git a/evmlib/artifacts/PaymentVaultNoProxy.json b/evmlib/artifacts/PaymentVaultNoProxy.json new file mode 100644 index 0000000000..5514cc77f7 --- /dev/null +++ b/evmlib/artifacts/PaymentVaultNoProxy.json @@ -0,0 +1,351 @@ +{ + "_format": "hh-sol-artifact-1", + "contractName": "PaymentVaultNoProxy", + "sourceName": "contracts/PaymentVaultNoProxy.sol", + "abi": [ + { + "inputs": [ + { + "internalType": "contract IERC20", + "name": "_antToken", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_batchLimit", + "type": "uint256" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "AddressInsufficientBalance", + "type": "error" + }, + { + "inputs": [], + "name": "AntTokenNull", + "type": "error" + }, + { + "inputs": [], + "name": "BatchLimitExceeded", + "type": "error" + }, + { + "inputs": [], + "name": "FailedInnerCall", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInputLength", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "token", + "type": "address" + } + ], + "name": "SafeERC20FailedOperation", + "type": "error" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "rewardsAddress", + "type": "address" + }, + { + "indexed": true, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + } + ], + "name": "DataPaymentMade", + "type": "event" + }, + { + "inputs": [], + "name": "antToken", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "batchLimit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "uint256", + "name": "closeRecordsStored", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxRecords", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "receivedPaymentCount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liveTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkDensity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkSize", + "type": "uint256" + } + ], + "internalType": "struct IPaymentVault.QuotingMetrics", + "name": "", + "type": "tuple" + } + ], + "name": "getQuote", + "outputs": [ + { + "internalType": "uint256", + "name": "price", + "type": "uint256" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "internalType": "address", + "name": "rewardsAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + } + ], + "internalType": "struct IPaymentVault.DataPayment[]", + "name": "_payments", + "type": "tuple[]" + } + ], + "name": "payForQuotes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "payments", + "outputs": [ + { + "internalType": "address", + "name": "rewardsAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "requiredPaymentVerificationLength", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "components": [ + { + "components": [ + { + "internalType": "uint256", + "name": "closeRecordsStored", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "maxRecords", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "receivedPaymentCount", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "liveTime", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkDensity", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "networkSize", + "type": "uint256" + } + ], + "internalType": "struct IPaymentVault.QuotingMetrics", + "name": "metrics", + "type": "tuple" + }, + { + "components": [ + { + "internalType": "address", + "name": "rewardsAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + } + ], + "internalType": "struct IPaymentVault.DataPayment", + "name": "dataPayment", + "type": "tuple" + } + ], + "internalType": "struct IPaymentVault.PaymentVerification[]", + "name": "_payments", + "type": "tuple[]" + } + ], + "name": "verifyPayment", + "outputs": [ + { + "components": [ + { + "internalType": "bytes32", + "name": "quoteHash", + "type": "bytes32" + }, + { + "internalType": "uint256", + "name": "amountPaid", + "type": "uint256" + }, + { + "internalType": "bool", + "name": "isValid", + "type": "bool" + } + ], + "internalType": "struct IPaymentVault.PaymentVerificationResult[3]", + "name": "verificationResults", + "type": "tuple[3]" + } + ], + "stateMutability": "view", + "type": "function" + } + ], + "bytecode": "0x6080604052348015600f57600080fd5b50604051610cce380380610cce833981016040819052602c91607f565b6001600160a01b038216605257604051632d06160b60e21b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b039390931692909217909155600055600560035560b7565b60008060408385031215609157600080fd5b82516001600160a01b038116811460a757600080fd5b6020939093015192949293505050565b610c08806100c66000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80634ec42e8e1161005b5780634ec42e8e14610111578063b6c2141b1461013c578063bcb2c1da14610151578063c7170bb61461017157600080fd5b80630716326d146100825780633c150bf2146100e6578063474740b114610108575b600080fd5b6100bc61009036600461082f565b60026020819052600091825260409091208054600182015491909201546001600160a01b039092169183565b604080516001600160a01b0390941684526020840192909252908201526060015b60405180910390f35b6100fa6100f4366004610848565b50600190565b6040519081526020016100dd565b6100fa60005481565b600154610124906001600160a01b031681565b6040516001600160a01b0390911681526020016100dd565b61014f61014a366004610863565b61017a565b005b61016461015f3660046108da565b61026a565b6040516100dd9190610942565b6100fa60035481565b600054819081111561019f57604051630d67f41160e21b815260040160405180910390fd5b60005b8181101561026457368484838181106101bd576101bd610992565b6060029190910191506101f19050336101d960208401846109bd565b6001546001600160a01b0316919060208501356103f5565b6040808201356000908152600260205220819061020e82826109da565b505060408101356020820180359061022690846109bd565b6001600160a01b03167ff998960b1c6f0e0e89b7bbe6b6fbf3e03e6f08eee5b8430877d8adb8e149d58060405160405180910390a4506001016101a2565b50505050565b61027261075c565b600354821461029457604051637db491eb60e01b815260040160405180910390fd5b60006102a0848461044f565b905060005b60038110156103ed576000600260008484600381106102c6576102c6610992565b602090810291909101518101516040908101518352828201939093529082016000908120835160608101855281546001600160a01b031681526001820154938101939093526002015492820192909252915083836003811061032a5761032a610992565b602002015160200151602001518260200151149050600084846003811061035357610353610992565b602002015160200151600001516001600160a01b031683600001516001600160a01b03161490506000604051806060016040528087876003811061039957610399610992565b602002015160200151604001518152602001856020015181526020018480156103bf5750835b151590529050808786600381106103d8576103d8610992565b60200201525050600190920191506102a59050565b505092915050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526102649085906105b5565b61045761079b565b60005b828110156105ae578151602090810151015184848381811061047e5761047e610992565b9050610120020160c0016020013511156104d8576020820180516040840152825190528383828181106104b3576104b3610992565b905061012002018036038101906104ca9190610af1565b8260005b60200201526105a6565b60208083015181015101518484838181106104f5576104f5610992565b9050610120020160c001602001351115610544576020820151604083015283838281811061052557610525610992565b9050610120020180360381019061053c9190610af1565b8260016104ce565b6040820151602090810151015184848381811061056357610563610992565b9050610120020160c0016020013511156105a65783838281811061058957610589610992565b905061012002018036038101906105a09190610af1565b60408301525b60010161045a565b5092915050565b60006105ca6001600160a01b03841683610622565b905080516000141580156105ef5750808060200190518101906105ed9190610b81565b155b1561061d57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b505050565b606061063083836000610637565b9392505050565b60608147101561065c5760405163cd78605960e01b8152306004820152602401610614565b600080856001600160a01b031684866040516106789190610ba3565b60006040518083038185875af1925050503d80600081146106b5576040519150601f19603f3d011682016040523d82523d6000602084013e6106ba565b606091505b50915091506106ca8683836106d4565b9695505050505050565b6060826106e9576106e482610730565b610630565b815115801561070057506001600160a01b0384163b155b1561072957604051639996b31560e01b81526001600160a01b0385166004820152602401610614565b5080610630565b8051156107405780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b60405180606001604052806003905b604080516060810182526000808252602080830182905292820152825260001990920191018161076b5790505090565b60405180606001604052806003905b6107b26107c8565b8152602001906001900390816107aa5790505090565b604051806040016040528061080c6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b815260408051606081018252600080825260208281018290529282015291015290565b60006020828403121561084157600080fd5b5035919050565b600060c082840312801561085b57600080fd5b509092915050565b6000806020838503121561087657600080fd5b823567ffffffffffffffff81111561088d57600080fd5b8301601f8101851361089e57600080fd5b803567ffffffffffffffff8111156108b557600080fd5b8560206060830284010111156108ca57600080fd5b6020919091019590945092505050565b600080602083850312156108ed57600080fd5b823567ffffffffffffffff81111561090457600080fd5b8301601f8101851361091557600080fd5b803567ffffffffffffffff81111561092c57600080fd5b856020610120830284010111156108ca57600080fd5b6101208101818360005b600381101561098957815180518452602081015160208501526040810151151560408501525060608301925060208201915060018101905061094c565b50505092915050565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b038116811461075957600080fd5b6000602082840312156109cf57600080fd5b8135610630816109a8565b81356109e5816109a8565b81546001600160a01b0319166001600160a01b039190911617815560208201356001820155604090910135600290910155565b6040805190810167ffffffffffffffff81118282101715610a4957634e487b7160e01b600052604160045260246000fd5b60405290565b60405160c0810167ffffffffffffffff81118282101715610a4957634e487b7160e01b600052604160045260246000fd5b600060608284031215610a9257600080fd5b6040516060810167ffffffffffffffff81118282101715610ac357634e487b7160e01b600052604160045260246000fd5b6040529050808235610ad4816109a8565b815260208381013590820152604092830135920191909152919050565b600081830361012081128015610b0657600080fd5b506000610b11610a18565b60c0831215610b1e578182fd5b610b26610a4f565b853581526020808701359082015260408087013590820152606080870135908201526080808701359082015260a0808701359082018190528183529093509150610b738660c08701610a80565b602082015295945050505050565b600060208284031215610b9357600080fd5b8151801515811461063057600080fd5b6000825160005b81811015610bc45760208186018101518583015201610baa565b50600092019182525091905056fea2646970667358221220fd6ef361aaba52d0f9503b51aea1d0b7a8363a9a66c9502aa7b931f1f44c507f64736f6c634300081c0033", + "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80634ec42e8e1161005b5780634ec42e8e14610111578063b6c2141b1461013c578063bcb2c1da14610151578063c7170bb61461017157600080fd5b80630716326d146100825780633c150bf2146100e6578063474740b114610108575b600080fd5b6100bc61009036600461082f565b60026020819052600091825260409091208054600182015491909201546001600160a01b039092169183565b604080516001600160a01b0390941684526020840192909252908201526060015b60405180910390f35b6100fa6100f4366004610848565b50600190565b6040519081526020016100dd565b6100fa60005481565b600154610124906001600160a01b031681565b6040516001600160a01b0390911681526020016100dd565b61014f61014a366004610863565b61017a565b005b61016461015f3660046108da565b61026a565b6040516100dd9190610942565b6100fa60035481565b600054819081111561019f57604051630d67f41160e21b815260040160405180910390fd5b60005b8181101561026457368484838181106101bd576101bd610992565b6060029190910191506101f19050336101d960208401846109bd565b6001546001600160a01b0316919060208501356103f5565b6040808201356000908152600260205220819061020e82826109da565b505060408101356020820180359061022690846109bd565b6001600160a01b03167ff998960b1c6f0e0e89b7bbe6b6fbf3e03e6f08eee5b8430877d8adb8e149d58060405160405180910390a4506001016101a2565b50505050565b61027261075c565b600354821461029457604051637db491eb60e01b815260040160405180910390fd5b60006102a0848461044f565b905060005b60038110156103ed576000600260008484600381106102c6576102c6610992565b602090810291909101518101516040908101518352828201939093529082016000908120835160608101855281546001600160a01b031681526001820154938101939093526002015492820192909252915083836003811061032a5761032a610992565b602002015160200151602001518260200151149050600084846003811061035357610353610992565b602002015160200151600001516001600160a01b031683600001516001600160a01b03161490506000604051806060016040528087876003811061039957610399610992565b602002015160200151604001518152602001856020015181526020018480156103bf5750835b151590529050808786600381106103d8576103d8610992565b60200201525050600190920191506102a59050565b505092915050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b1790526102649085906105b5565b61045761079b565b60005b828110156105ae578151602090810151015184848381811061047e5761047e610992565b9050610120020160c0016020013511156104d8576020820180516040840152825190528383828181106104b3576104b3610992565b905061012002018036038101906104ca9190610af1565b8260005b60200201526105a6565b60208083015181015101518484838181106104f5576104f5610992565b9050610120020160c001602001351115610544576020820151604083015283838281811061052557610525610992565b9050610120020180360381019061053c9190610af1565b8260016104ce565b6040820151602090810151015184848381811061056357610563610992565b9050610120020160c0016020013511156105a65783838281811061058957610589610992565b905061012002018036038101906105a09190610af1565b60408301525b60010161045a565b5092915050565b60006105ca6001600160a01b03841683610622565b905080516000141580156105ef5750808060200190518101906105ed9190610b81565b155b1561061d57604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b505050565b606061063083836000610637565b9392505050565b60608147101561065c5760405163cd78605960e01b8152306004820152602401610614565b600080856001600160a01b031684866040516106789190610ba3565b60006040518083038185875af1925050503d80600081146106b5576040519150601f19603f3d011682016040523d82523d6000602084013e6106ba565b606091505b50915091506106ca8683836106d4565b9695505050505050565b6060826106e9576106e482610730565b610630565b815115801561070057506001600160a01b0384163b155b1561072957604051639996b31560e01b81526001600160a01b0385166004820152602401610614565b5080610630565b8051156107405780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b50565b60405180606001604052806003905b604080516060810182526000808252602080830182905292820152825260001990920191018161076b5790505090565b60405180606001604052806003905b6107b26107c8565b8152602001906001900390816107aa5790505090565b604051806040016040528061080c6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b815260408051606081018252600080825260208281018290529282015291015290565b60006020828403121561084157600080fd5b5035919050565b600060c082840312801561085b57600080fd5b509092915050565b6000806020838503121561087657600080fd5b823567ffffffffffffffff81111561088d57600080fd5b8301601f8101851361089e57600080fd5b803567ffffffffffffffff8111156108b557600080fd5b8560206060830284010111156108ca57600080fd5b6020919091019590945092505050565b600080602083850312156108ed57600080fd5b823567ffffffffffffffff81111561090457600080fd5b8301601f8101851361091557600080fd5b803567ffffffffffffffff81111561092c57600080fd5b856020610120830284010111156108ca57600080fd5b6101208101818360005b600381101561098957815180518452602081015160208501526040810151151560408501525060608301925060208201915060018101905061094c565b50505092915050565b634e487b7160e01b600052603260045260246000fd5b6001600160a01b038116811461075957600080fd5b6000602082840312156109cf57600080fd5b8135610630816109a8565b81356109e5816109a8565b81546001600160a01b0319166001600160a01b039190911617815560208201356001820155604090910135600290910155565b6040805190810167ffffffffffffffff81118282101715610a4957634e487b7160e01b600052604160045260246000fd5b60405290565b60405160c0810167ffffffffffffffff81118282101715610a4957634e487b7160e01b600052604160045260246000fd5b600060608284031215610a9257600080fd5b6040516060810167ffffffffffffffff81118282101715610ac357634e487b7160e01b600052604160045260246000fd5b6040529050808235610ad4816109a8565b815260208381013590820152604092830135920191909152919050565b600081830361012081128015610b0657600080fd5b506000610b11610a18565b60c0831215610b1e578182fd5b610b26610a4f565b853581526020808701359082015260408087013590820152606080870135908201526080808701359082015260a0808701359082018190528183529093509150610b738660c08701610a80565b602082015295945050505050565b600060208284031215610b9357600080fd5b8151801515811461063057600080fd5b6000825160005b81811015610bc45760208186018101518583015201610baa565b50600092019182525091905056fea2646970667358221220fd6ef361aaba52d0f9503b51aea1d0b7a8363a9a66c9502aa7b931f1f44c507f64736f6c634300081c0033", + "linkReferences": {}, + "deployedLinkReferences": {} +} diff --git a/evmlib/src/contract/payment_vault/error.rs b/evmlib/src/contract/payment_vault/error.rs index 6c94c680f1..f4a5b76cce 100644 --- a/evmlib/src/contract/payment_vault/error.rs +++ b/evmlib/src/contract/payment_vault/error.rs @@ -10,4 +10,6 @@ pub enum Error { PendingTransactionError(#[from] alloy::providers::PendingTransactionError), #[error("Payment is invalid.")] PaymentInvalid, + #[error("Payment verification length must be 3.")] + PaymentVerificationLengthInvalid, } diff --git a/evmlib/src/contract/payment_vault/handler.rs b/evmlib/src/contract/payment_vault/handler.rs index 38d1dd2da8..5f21e5574e 100644 --- a/evmlib/src/contract/payment_vault/handler.rs +++ b/evmlib/src/contract/payment_vault/handler.rs @@ -1,7 +1,9 @@ use crate::common::{Address, Amount, Calldata, TxHash}; use crate::contract::payment_vault::error::Error; -use crate::contract::payment_vault::interface::IPaymentVault; use crate::contract::payment_vault::interface::IPaymentVault::IPaymentVaultInstance; +use crate::contract::payment_vault::interface::{ + IPaymentVault, REQUIRED_PAYMENT_VERIFICATION_LENGTH, +}; use alloy::network::{Network, TransactionBuilder}; use alloy::providers::Provider; use alloy::transports::Transport; @@ -16,7 +18,7 @@ where P: Provider, N: Network, { - /// Create a new PaymentVaultHandler instance from a deployed contract's address + /// Create a new PaymentVaultHandler instance from a (proxy) contract's address pub fn new(contract_address: Address, provider: P) -> Self { let contract = IPaymentVault::new(contract_address, provider); Self { contract } @@ -79,22 +81,27 @@ where Ok((calldata, *self.contract.address())) } - /// Verify if a payment is valid - pub async fn verify_payment< - Q: Into, - I: Into, - >( + /// Verify if payments are valid + pub async fn verify_payment>>( &self, - metrics: Q, - payment: I, - ) -> Result { - let is_valid = self + payment_verifications: I, + ) -> Result<[IPaymentVault::PaymentVerificationResult; 3], Error> { + let payment_verifications: Vec = payment_verifications + .into_iter() + .map(|v| v.into()) + .collect(); + + if payment_verifications.len() != REQUIRED_PAYMENT_VERIFICATION_LENGTH { + return Err(Error::PaymentVerificationLengthInvalid); + } + + let results = self .contract - .verifyPayment(metrics.into(), payment.into()) + .verifyPayment(payment_verifications) .call() .await? - .isValid; + .verificationResults; - Ok(is_valid) + Ok(results) } } diff --git a/evmlib/src/contract/payment_vault/implementation.rs b/evmlib/src/contract/payment_vault/implementation.rs index 4cbc469248..64fd9da1f9 100644 --- a/evmlib/src/contract/payment_vault/implementation.rs +++ b/evmlib/src/contract/payment_vault/implementation.rs @@ -1,31 +1,30 @@ -use crate::common::Address; -use alloy::hex; -use alloy::network::{Network, ReceiptResponse, TransactionBuilder}; +use crate::common::{Address, U256}; +use alloy::network::Network; use alloy::providers::Provider; +use alloy::sol; use alloy::transports::Transport; -// Payment Vault contract byte code -const BYTE_CODE: &str = "0x60a060405230608052348015610013575f5ffd5b5061001c610021565b6100d3565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100715760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d05780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b608051610ef76100f95f395f818161064d0152818161067601526107ba0152610ef75ff3fe6080604052600436106100bf575f3560e01c8063715018a61161007c578063ad3cb1cc11610057578063ad3cb1cc14610253578063b6c2141b14610290578063cd6dc687146102af578063f2fde38b146102ce575f5ffd5b8063715018a6146101d45780638da5cb5b146101e8578063a69bf4a314610224575f5ffd5b80630716326d146100c35780633c150bf214610132578063474740b1146101605780634ec42e8e146101745780634f1ef286146101ab57806352d1902d146101c0575b5f5ffd5b3480156100ce575f5ffd5b506101086100dd366004610bc4565b600260208190525f91825260409091208054600182015491909201546001600160a01b039092169183565b604080516001600160a01b0390941684526020840192909252908201526060015b60405180910390f35b34801561013d575f5ffd5b5061015261014c366004610bf1565b50600190565b604051908152602001610129565b34801561016b575f5ffd5b506101525f5481565b34801561017f575f5ffd5b50600154610193906001600160a01b031681565b6040516001600160a01b039091168152602001610129565b6101be6101b9366004610c33565b6102ed565b005b3480156101cb575f5ffd5b5061015261030c565b3480156101df575f5ffd5b506101be610327565b3480156101f3575f5ffd5b507f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b0316610193565b34801561022f575f5ffd5b5061024361023e366004610cf9565b61033a565b6040519015158152602001610129565b34801561025e575f5ffd5b50610283604051806040016040528060058152602001640352e302e360dc1b81525081565b6040516101299190610d37565b34801561029b575f5ffd5b506101be6102aa366004610d6c565b6103b6565b3480156102ba575f5ffd5b506101be6102c9366004610ddd565b6104a3565b3480156102d9575f5ffd5b506101be6102e8366004610e07565b610600565b6102f5610642565b6102fe826106e6565b61030882826106ee565b5050565b5f6103156107af565b505f516020610ea25f395f51905f5290565b61032f6107f8565b6103385f610853565b565b6040808201355f90815260026020818152838320845160608101865281546001600160a01b031681526001820154818401819052919093015494830194909452919290918401351480156103ae57506103966020840184610e07565b6001600160a01b0316815f01516001600160a01b0316145b949350505050565b5f5481908111156103da57604051630d67f41160e21b815260040160405180910390fd5b5f5b8181101561049d57368484838181106103f7576103f7610e22565b60600291909101915061042b9050336104136020840184610e07565b6001546001600160a01b0316919060208501356108c3565b6040808201355f90815260026020522081906104478282610e36565b505060408101356020820180359061045f9084610e07565b6001600160a01b03167ff998960b1c6f0e0e89b7bbe6b6fbf3e03e6f08eee5b8430877d8adb8e149d58060405160405180910390a4506001016103dc565b50505050565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a008054600160401b810460ff16159067ffffffffffffffff165f811580156104e85750825b90505f8267ffffffffffffffff1660011480156105045750303b155b905081158015610512575080155b156105305760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561055a57845460ff60401b1916600160401b1785555b6001600160a01b03871661058157604051632d06160b60e21b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0389161790555f8690556105a93361091d565b6105b161092e565b83156105f757845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b6106086107f8565b6001600160a01b03811661063657604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b61063f81610853565b50565b306001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614806106c857507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166106bc5f516020610ea25f395f51905f52546001600160a01b031690565b6001600160a01b031614155b156103385760405163703e46dd60e11b815260040160405180910390fd5b61063f6107f8565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610748575060408051601f3d908101601f1916820190925261074591810190610e74565b60015b61077057604051634c9c8ce360e01b81526001600160a01b038316600482015260240161062d565b5f516020610ea25f395f51905f5281146107a057604051632a87526960e21b81526004810182905260240161062d565b6107aa8383610936565b505050565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146103385760405163703e46dd60e11b815260040160405180910390fd5b3361082a7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b0316146103385760405163118cdaa760e01b815233600482015260240161062d565b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a3505050565b604080516001600160a01b0385811660248301528416604482015260648082018490528251808303909101815260849091019091526020810180516001600160e01b03166323b872dd60e01b17905261049d90859061098b565b6109256109f7565b61063f81610a40565b6103386109f7565b61093f82610a48565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b905f90a2805115610983576107aa8282610aab565b610308610b1d565b5f5f60205f8451602086015f885af1806109aa576040513d5f823e3d81fd5b50505f513d915081156109c15780600114156109ce565b6001600160a01b0384163b155b1561049d57604051635274afe760e01b81526001600160a01b038516600482015260240161062d565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054600160401b900460ff1661033857604051631afcd79f60e31b815260040160405180910390fd5b6106086109f7565b806001600160a01b03163b5f03610a7d57604051634c9c8ce360e01b81526001600160a01b038216600482015260240161062d565b5f516020610ea25f395f51905f5280546001600160a01b0319166001600160a01b0392909216919091179055565b60605f5f846001600160a01b031684604051610ac79190610e8b565b5f60405180830381855af49150503d805f8114610aff576040519150601f19603f3d011682016040523d82523d5f602084013e610b04565b606091505b5091509150610b14858383610b3c565b95945050505050565b34156103385760405163b398979f60e01b815260040160405180910390fd5b606082610b5157610b4c82610b9b565b610b94565b8151158015610b6857506001600160a01b0384163b155b15610b9157604051639996b31560e01b81526001600160a01b038516600482015260240161062d565b50805b9392505050565b805115610bab5780518082602001fd5b60405163d6bda27560e01b815260040160405180910390fd5b5f60208284031215610bd4575f5ffd5b5035919050565b5f60c08284031215610beb575f5ffd5b50919050565b5f60c08284031215610c01575f5ffd5b610b948383610bdb565b6001600160a01b038116811461063f575f5ffd5b634e487b7160e01b5f52604160045260245ffd5b5f5f60408385031215610c44575f5ffd5b8235610c4f81610c0b565b9150602083013567ffffffffffffffff811115610c6a575f5ffd5b8301601f81018513610c7a575f5ffd5b803567ffffffffffffffff811115610c9457610c94610c1f565b604051601f8201601f19908116603f0116810167ffffffffffffffff81118282101715610cc357610cc3610c1f565b604052818152828201602001871015610cda575f5ffd5b816020840160208301375f602083830101528093505050509250929050565b5f5f828403610120811215610d0c575f5ffd5b610d168585610bdb565b9250606060bf1982011215610d29575f5ffd5b5060c0830190509250929050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b5f5f60208385031215610d7d575f5ffd5b823567ffffffffffffffff811115610d93575f5ffd5b8301601f81018513610da3575f5ffd5b803567ffffffffffffffff811115610db9575f5ffd5b856020606083028401011115610dcd575f5ffd5b6020919091019590945092505050565b5f5f60408385031215610dee575f5ffd5b8235610df981610c0b565b946020939093013593505050565b5f60208284031215610e17575f5ffd5b8135610b9481610c0b565b634e487b7160e01b5f52603260045260245ffd5b8135610e4181610c0b565b81546001600160a01b0319166001600160a01b039190911617815560208201356001820155604090910135600290910155565b5f60208284031215610e84575f5ffd5b5051919050565b5f82518060208501845e5f92019182525091905056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbca26469706673582212203894ca52be6e6323aa3d296efd566c7f21d1723d4c66c56aed8a5f75a96b579d64736f6c634300081c0033"; +sol!( + #[allow(missing_docs)] + #[sol(rpc)] + PaymentVaultImplementation, + "artifacts/PaymentVaultNoProxy.json" +); -pub async fn deploy(provider: &P) -> Address +/// Deploys the payment vault contract and returns the contract address +pub async fn deploy( + provider: &P, + network_token_address: Address, + batch_limit: U256, +) -> Address where T: Transport + Clone, P: Provider, N: Network, { - let bytecode = hex::decode(BYTE_CODE).expect("Could not decode byte code"); - let tx = provider.transaction_request().with_deploy_code(bytecode); - - // Deploy the contract. - let receipt = provider - .send_transaction(tx) - .await - .expect("Could not send deployment transaction") - .get_receipt() + let contract = PaymentVaultImplementation::deploy(provider, network_token_address, batch_limit) .await - .expect("Deployment transaction failed"); + .expect("Could not deploy payment vault implementation contract"); - receipt - .contract_address() - .expect("Contract address missing") + *contract.address() } diff --git a/evmlib/src/contract/payment_vault/interface.rs b/evmlib/src/contract/payment_vault/interface.rs index 9f2d6f3490..36ec3ee6b8 100644 --- a/evmlib/src/contract/payment_vault/interface.rs +++ b/evmlib/src/contract/payment_vault/interface.rs @@ -3,17 +3,23 @@ use crate::quoting_metrics::QuotingMetrics; use alloy::primitives::FixedBytes; use alloy::sol; +pub const REQUIRED_PAYMENT_VERIFICATION_LENGTH: usize = 5; + sol!( #[allow(missing_docs)] + #[derive(Debug)] #[sol(rpc)] IPaymentVault, "abi/IPaymentVault.json" ); -pub struct PaymentVerification { - pub quote_hash: FixedBytes<32>, - pub amount_paid: Amount, - pub is_valid: bool, +impl From<(QuoteHash, QuotingMetrics, Address)> for IPaymentVault::PaymentVerification { + fn from(value: (QuoteHash, QuotingMetrics, Address)) -> Self { + Self { + metrics: value.1.into(), + dataPayment: (value.0, value.2, Amount::ZERO).into(), + } + } } impl From<(QuoteHash, Address, Amount)> for IPaymentVault::DataPayment { diff --git a/evmlib/src/contract/payment_vault/mod.rs b/evmlib/src/contract/payment_vault/mod.rs index 8ed1a9a92b..efa6f4fbd0 100644 --- a/evmlib/src/contract/payment_vault/mod.rs +++ b/evmlib/src/contract/payment_vault/mod.rs @@ -1,6 +1,5 @@ use crate::common::{Address, Amount, QuoteHash}; use crate::contract::payment_vault::handler::PaymentVaultHandler; -use crate::contract::payment_vault::interface::PaymentVerification; use crate::quoting_metrics::QuotingMetrics; use crate::utils::http_provider; use crate::Network; @@ -12,7 +11,7 @@ pub mod interface; pub const MAX_TRANSFERS_PER_TRANSACTION: usize = 256; -/// Helper function to return a quote for the given quoting metrics +/// Helper function to return a quote for the given quoting metrics. pub async fn get_market_price( network: &Network, quoting_metrics: QuotingMetrics, @@ -22,7 +21,8 @@ pub async fn get_market_price( payment_vault.get_quote(quoting_metrics).await } -/// Helper function to verify whether a data payment is valid +/// Helper function to verify whether a data payment is valid. +/// Returns the amount paid to the owned quote hashes. pub async fn verify_data_payment( network: &Network, owned_quote_hashes: Vec, @@ -33,24 +33,21 @@ pub async fn verify_data_payment( let mut amount = Amount::ZERO; - // TODO: @mick change this for loop to a batch when the smart contract changes - for (quote_hash, quoting_metrics, rewards_address) in payment { - let payment_verification: PaymentVerification = payment_vault - .verify_payment(quoting_metrics, (quote_hash, rewards_address, Amount::ZERO)) - .await - .map(|is_valid| PaymentVerification { - quote_hash, - amount_paid: Amount::from(1), // TODO: update placeholder amount when the smart contract changes - is_valid, - })?; + let payment_verifications: Vec<_> = payment + .into_iter() + .map(interface::IPaymentVault::PaymentVerification::from) + .collect(); + let payment_verification_results = payment_vault.verify_payment(payment_verifications).await?; + + for payment_verification_result in payment_verification_results { // CODE REVIEW: should we fail on a single invalid payment? - if !payment_verification.is_valid { + if !payment_verification_result.isValid { return Err(error::Error::PaymentInvalid); } - if owned_quote_hashes.contains("e_hash) { - amount += payment_verification.amount_paid; + if owned_quote_hashes.contains(&payment_verification_result.quoteHash) { + amount += payment_verification_result.amountPaid; } } diff --git a/evmlib/src/testnet.rs b/evmlib/src/testnet.rs index f5b76fea5c..d9c25bcffd 100644 --- a/evmlib/src/testnet.rs +++ b/evmlib/src/testnet.rs @@ -6,7 +6,7 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use crate::common::Address; +use crate::common::{Address, Amount}; use crate::contract::network_token::NetworkToken; use crate::contract::payment_vault; use crate::contract::payment_vault::handler::PaymentVaultHandler; @@ -22,6 +22,8 @@ use alloy::providers::{Identity, ProviderBuilder, ReqwestProvider}; use alloy::signers::local::PrivateKeySigner; use alloy::transports::http::{Client, Http}; +const BATCH_LIMIT: u16 = 256; + pub struct Testnet { anvil: AnvilInstance, rpc_url: Url, @@ -120,7 +122,7 @@ pub async fn deploy_network_token_contract( pub async fn deploy_data_payments_contract( rpc_url: &Url, anvil: &AnvilInstance, - _token_address: Address, + token_address: Address, ) -> PaymentVaultHandler< Http, FillProvider< @@ -147,7 +149,9 @@ pub async fn deploy_data_payments_contract( .on_http(rpc_url.clone()); // Deploy the contract. - let payment_vault_contract_address = payment_vault::implementation::deploy(&provider).await; + let payment_vault_contract_address = + payment_vault::implementation::deploy(&provider, token_address, Amount::from(BATCH_LIMIT)) + .await; // Create a handler for the deployed contract PaymentVaultHandler::new(payment_vault_contract_address, provider) diff --git a/evmlib/tests/common/quote.rs b/evmlib/tests/common/quote.rs index 21d05cf189..28f8cbd3a8 100644 --- a/evmlib/tests/common/quote.rs +++ b/evmlib/tests/common/quote.rs @@ -5,6 +5,6 @@ use evmlib::utils::{dummy_address, dummy_hash}; pub fn random_quote_payment() -> QuotePayment { let quote_hash = dummy_hash(); let reward_address = dummy_address(); - let amount = Amount::from(200); + let amount = Amount::from(1); (quote_hash, reward_address, amount) } diff --git a/evmlib/tests/payment_vault.rs b/evmlib/tests/payment_vault.rs index 1e68e800c9..fe2df5905f 100644 --- a/evmlib/tests/payment_vault.rs +++ b/evmlib/tests/payment_vault.rs @@ -14,7 +14,9 @@ use alloy::transports::http::{Client, Http}; use evmlib::common::{Amount, U256}; use evmlib::contract::network_token::NetworkToken; use evmlib::contract::payment_vault::handler::PaymentVaultHandler; -use evmlib::contract::payment_vault::MAX_TRANSFERS_PER_TRANSACTION; +use evmlib::contract::payment_vault::interface::IPaymentVault::DataPayment; +use evmlib::contract::payment_vault::interface::REQUIRED_PAYMENT_VERIFICATION_LENGTH; +use evmlib::contract::payment_vault::{interface, MAX_TRANSFERS_PER_TRANSACTION}; use evmlib::quoting_metrics::QuotingMetrics; use evmlib::testnet::{deploy_data_payments_contract, deploy_network_token_contract, start_node}; use evmlib::utils::http_provider; @@ -129,9 +131,55 @@ async fn test_proxy_reachable() { assert_eq!(amount, Amount::from(1)); } +#[tokio::test] +async fn test_verify_payment() { + let (_anvil, network_token, mut payment_vault) = setup().await; + + let mut quote_payments = vec![]; + + for _ in 0..REQUIRED_PAYMENT_VERIFICATION_LENGTH { + let quote_payment = random_quote_payment(); + quote_payments.push(quote_payment); + } + + let _ = network_token + .approve(*payment_vault.contract.address(), U256::MAX) + .await + .unwrap(); + + // Contract provider has a different account coupled to it, + // so we set it to the same as the network token contract + payment_vault.set_provider(network_token.contract.provider().clone()); + + let result = payment_vault.pay_for_quotes(quote_payments.clone()).await; + + assert!(result.is_ok(), "Failed with error: {:?}", result.err()); + + let payment_verifications: Vec<_> = quote_payments + .into_iter() + .map(|v| interface::IPaymentVault::PaymentVerification { + metrics: QuotingMetrics::default().into(), + dataPayment: DataPayment { + rewardsAddress: v.1, + amount: v.2, + quoteHash: v.0, + }, + }) + .collect(); + + let results = payment_vault + .verify_payment(payment_verifications) + .await + .expect("Verify payment failed"); + + for result in results { + assert!(result.isValid); + } +} + #[tokio::test] async fn test_pay_for_quotes() { - let (_anvil, network_token, mut data_payments) = setup().await; + let (_anvil, network_token, mut payment_vault) = setup().await; let mut quote_payments = vec![]; @@ -141,15 +189,15 @@ async fn test_pay_for_quotes() { } let _ = network_token - .approve(*data_payments.contract.address(), U256::MAX) + .approve(*payment_vault.contract.address(), U256::MAX) .await .unwrap(); // Contract provider has a different account coupled to it, // so we set it to the same as the network token contract - data_payments.set_provider(network_token.contract.provider().clone()); + payment_vault.set_provider(network_token.contract.provider().clone()); - let result = data_payments.pay_for_quotes(quote_payments).await; + let result = payment_vault.pay_for_quotes(quote_payments).await; assert!(result.is_ok(), "Failed with error: {:?}", result.err()); } From 61e9b94af7aa9d13ac54650ab361cf22a4f061f7 Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Tue, 10 Dec 2024 16:42:48 +0100 Subject: [PATCH 2/3] fix: include unpaid store quotes in receipt --- autonomi/src/client/payment.rs | 14 +++----------- autonomi/src/client/utils.rs | 6 +++--- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/autonomi/src/client/payment.rs b/autonomi/src/client/payment.rs index 509615fb20..29a8f11576 100644 --- a/autonomi/src/client/payment.rs +++ b/autonomi/src/client/payment.rs @@ -1,17 +1,14 @@ use crate::client::data::PayError; use crate::client::quote::StoreQuote; use crate::Client; -use ant_evm::{AttoTokens, EncodedPeerId, EvmWallet, ProofOfPayment, QuoteHash, TxHash}; -use std::collections::{BTreeMap, HashMap}; +use ant_evm::{AttoTokens, EncodedPeerId, EvmWallet, ProofOfPayment}; +use std::collections::HashMap; use xor_name::XorName; /// Contains the proof of payments for each XOR address and the amount paid pub type Receipt = HashMap; -pub fn receipt_from_store_quotes_and_payments( - quotes: StoreQuote, - payments: BTreeMap, -) -> Receipt { +pub fn receipt_from_store_quotes(quotes: StoreQuote) -> Receipt { let mut receipt = Receipt::new(); for (content_addr, quote_for_address) in quotes.0 { @@ -22,11 +19,6 @@ pub fn receipt_from_store_quotes_and_payments( }; for (peer_id, quote, _amount) in quote_for_address.0 { - // skip quotes that haven't been paid - if !payments.contains_key("e.hash()) { - continue; - } - proof_of_payment .peer_quotes .push((EncodedPeerId::from(peer_id), quote)); diff --git a/autonomi/src/client/utils.rs b/autonomi/src/client/utils.rs index 3d4b0c7e29..91b60e2eff 100644 --- a/autonomi/src/client/utils.rs +++ b/autonomi/src/client/utils.rs @@ -6,7 +6,7 @@ // KIND, either express or implied. Please review the Licences for the specific language governing // permissions and limitations relating to use of the SAFE Network Software. -use crate::client::payment::{receipt_from_store_quotes_and_payments, Receipt}; +use crate::client::payment::{receipt_from_store_quotes, Receipt}; use ant_evm::{EvmWallet, ProofOfPayment}; use ant_networking::{GetRecordCfg, PutRecordCfg, VerificationKind}; use ant_protocol::{ @@ -174,7 +174,7 @@ impl Client { // TODO: the error might contain some succeeded quote payments as well. These should be returned on err, so that they can be skipped when retrying. // TODO: retry when it fails? // Execute chunk payments - let payments = wallet + let _payments = wallet .pay_for_quotes(quotes.payments()) .await .map_err(|err| PayError::from(err.0))?; @@ -190,7 +190,7 @@ impl Client { skipped_chunks ); - let receipt = receipt_from_store_quotes_and_payments(quotes, payments); + let receipt = receipt_from_store_quotes(quotes); Ok(receipt) } From 61f0f2296cb77ae2f1797b69c46d2315a0b966ea Mon Sep 17 00:00:00 2001 From: Warm Beer Date: Tue, 10 Dec 2024 16:43:05 +0100 Subject: [PATCH 3/3] fix: add rate limit to get market price RPC calls --- autonomi/src/client/quote.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/autonomi/src/client/quote.rs b/autonomi/src/client/quote.rs index 3f48587552..2c527fafd2 100644 --- a/autonomi/src/client/quote.rs +++ b/autonomi/src/client/quote.rs @@ -9,12 +9,16 @@ use super::{data::CostError, Client}; use ant_evm::payment_vault::get_market_price; use ant_evm::{Amount, PaymentQuote, QuotePayment}; +use ant_networking::target_arch::{sleep, Duration, Instant}; use ant_networking::{Network, NetworkError}; use ant_protocol::{storage::ChunkAddress, NetworkAddress}; use libp2p::PeerId; use std::collections::HashMap; use xor_name::XorName; +// set rate limit to 2 req/s +const TIME_BETWEEN_RPC_CALLS_IN_MS: u64 = 500; + /// A quote for a single address pub struct QuoteForAddress(pub(crate) Vec<(PeerId, PaymentQuote, Amount)>); @@ -63,15 +67,34 @@ impl Client { .collect(); let raw_quotes_per_addr = futures::future::try_join_all(futures).await?; + debug!("Fetched store quotes: {raw_quotes_per_addr:?}"); + // choose the quotes to pay for each address let mut quotes_to_pay_per_addr = HashMap::new(); for (content_addr, raw_quotes) in raw_quotes_per_addr { // ask smart contract for the market price let mut prices = vec![]; + + // rate limit + let mut maybe_last_call: Option = None; + for (peer, quote) in raw_quotes { // NB TODO @mick we need to batch this smart contract call + // check if we have to wait for the rate limit + if let Some(last_call) = maybe_last_call { + let elapsed = Instant::now() - last_call; + let time_to_sleep_ms = + TIME_BETWEEN_RPC_CALLS_IN_MS as u128 - elapsed.as_millis(); + if time_to_sleep_ms > 0 { + sleep(Duration::from_millis(time_to_sleep_ms as u64)).await; + } + } + let price = get_market_price(&self.evm_network, quote.quoting_metrics.clone()).await?; + + maybe_last_call = Some(Instant::now()); + prices.push((peer, quote, price)); }