1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! On-chain execution layer.
//!
//! Exposes two public entry points consumed by `crate::main`:
//!
//! * [`execute_swap`] - wraps a Jupiter swap simulation inside an isolated
//! [`signer::LocalSolanaSigner`] context and returns a [`jupiter::SwapResult`].
//! * [`demo_signer`] - spawns three concurrent tasks to demonstrate that the task-local signer
//! storage is fully isolated per task.
//!
//! ## Security boundary
//!
//! All on-chain operations are wrapped in [`signer::with_signer`], which uses
//! `tokio::task_local!` to scope the active keypair to exactly one async task.
//! This mirrors the `rig-onchain-kit` `SignerContext` pattern and prevents
//! concurrent tasks from accidentally sharing or overwriting each other's
//! signing credentials.
use Result;
use SwapResult;
use info;
use crate::;
/// Execute a swap for the given route inside an isolated signer context.
///
/// Loads a [`signer::LocalSolanaSigner`] from the environment, logs the
/// public key, then runs the Jupiter simulation inside [`signer::with_signer`]
/// to guarantee the keypair is scoped to this task only.
///
/// The `live` flag is inverted before being passed to
/// [`jupiter::simulate_swap`] because that function's parameter is named
/// `dry_run` - the logical complement of `live`.
///
/// # Arguments
///
/// * `cfg` - Runtime configuration (provides the RPC URL and dry-run flag).
/// * `route` - The SOR-selected venue and price quote to execute against.
/// * `live` - `true` to attempt a real transaction; `false` (default) for dry-run simulation.
///
/// # Errors
///
/// Returns `Err` if the signer context setup or the Jupiter simulation fails.
pub async
/// Demonstrate [`signer::with_signer`] isolation across three concurrent tasks.
///
/// Delegates directly to [`signer::demo_signer`].
///
/// # Arguments
///
/// * `cfg` - Runtime configuration (reserved for future credential loading).
///
/// # Errors
///
/// Returns `Err` if any spawned task panics or its [`tokio::task::JoinHandle`]
/// fails.
pub async