feat(amm): bootstrap pool TWAP current-tick account at pool creation

Extend new_definition to also create the pool's TWAP current-tick account
via a chained CreateCurrentTickAccount, so a pool and its price feed are
born together. The opening tick is derived on-chain from the pool's own
reserves (reserve_b / reserve_a as Q64.64), not caller-supplied, so it
cannot be forged. The pool is passed in its post-claim state and authorized
as the price source via its pool PDA seed.

Add spot_price_q64_64 to amm_core (not the oracle): the reserves -> price
mapping is the price source's concern; the oracle only converts price to a
tick.
This commit is contained in:
r4bbit
2026-06-22 11:02:22 +02:00
parent 4e4338945d
commit b997ca678e
9 changed files with 281 additions and 35 deletions
+2
View File
@@ -85,9 +85,11 @@ dependencies = [
name = "amm_core"
version = "0.1.0"
dependencies = [
"alloy-primitives",
"borsh",
"nssa_core",
"risc0-zkvm",
"ruint",
"serde",
"spel-framework-macros",
"token_core",
@@ -118,6 +118,8 @@ mod amm {
user_holding_a: AccountWithMetadata,
user_holding_b: AccountWithMetadata,
user_holding_lp: AccountWithMetadata,
current_tick_account: AccountWithMetadata,
clock: AccountWithMetadata,
token_a_amount: u128,
token_b_amount: u128,
fees: u128,
@@ -133,6 +135,8 @@ mod amm {
user_holding_a,
user_holding_b,
user_holding_lp,
current_tick_account,
clock,
NonZeroU128::new(token_a_amount).expect("token_a_amount must be nonzero"),
NonZeroU128::new(token_b_amount).expect("token_b_amount must be nonzero"),
fees,