Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions amm/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub enum Instruction {
token_b_amount: u128,
fees: u128,
amm_program_id: ProgramId,
/// Unix timestamp (milliseconds) after which this transaction is invalid.
deadline: u64,
},

/// Adds liquidity to the Pool
Expand All @@ -51,6 +53,8 @@ pub enum Instruction {
min_amount_liquidity: u128,
max_amount_to_add_token_a: u128,
max_amount_to_add_token_b: u128,
/// Unix timestamp (milliseconds) after which this transaction is invalid.
deadline: u64,
},

/// Removes liquidity from the Pool
Expand All @@ -67,6 +71,8 @@ pub enum Instruction {
remove_liquidity_amount: u128,
min_amount_to_remove_token_a: u128,
min_amount_to_remove_token_b: u128,
/// Unix timestamp (milliseconds) after which this transaction is invalid.
deadline: u64,
},

/// Swap some quantity of Tokens (either Token A or Token B)
Expand All @@ -77,12 +83,13 @@ pub enum Instruction {
/// - Vault Holding Account for Token A (initialized)
/// - Vault Holding Account for Token B (initialized)
/// - User Holding Account for Token A
/// - User Holding Account for Token B Either User Holding Account for Token A or Token B is
/// authorized.
/// - User Holding Account for Token B; either is authorized.
SwapExactInput {
swap_amount_in: u128,
min_amount_out: u128,
token_definition_id_in: AccountId,
/// Unix timestamp (milliseconds) after which this transaction is invalid.
deadline: u64,
},

/// Swap tokens specifying the exact desired output amount,
Expand All @@ -93,12 +100,13 @@ pub enum Instruction {
/// - Vault Holding Account for Token A (initialized)
/// - Vault Holding Account for Token B (initialized)
/// - User Holding Account for Token A
/// - User Holding Account for Token B Either User Holding Account for Token A or Token B is
/// authorized.
/// - User Holding Account for Token B; either is authorized.
SwapExactOutput {
exact_amount_out: u128,
max_amount_in: u128,
token_definition_id_in: AccountId,
/// Unix timestamp (milliseconds) after which this transaction is invalid.
deadline: u64,
},

/// Sync pool reserves with current vault balances.
Expand Down
10 changes: 7 additions & 3 deletions amm/methods/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amm/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "amm"
path = "src/bin/amm.rs"

[dependencies]
Comment thread
0x-r4bbit marked this conversation as resolved.
spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", package = "spel-framework" }
spel-framework = { git = "https://github.com/logos-co/spel.git", rev = "9e7f2754e1d4cdb3ea36e63b1ff86c3af55488d3", package = "spel-framework" }
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" }
risc0-zkvm = { version = "=3.0.5", default-features = false }
amm_core = { path = "../../core" }
Expand Down
20 changes: 15 additions & 5 deletions amm/methods/guest/src/bin/amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mod amm {
token_b_amount: u128,
fees: u128,
amm_program_id: ProgramId,
deadline: u64,
) -> SpelResult {
let (post_states, chained_calls) = amm_program::new_definition::new_definition(
pool,
Expand All @@ -46,7 +47,8 @@ mod amm {
fees,
amm_program_id,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Ok(SpelOutput::with_chained_calls(post_states, chained_calls)
.with_timestamp_validity_window(..deadline))
}

/// Adds liquidity to the Pool.
Expand All @@ -62,6 +64,7 @@ mod amm {
min_amount_liquidity: u128,
max_amount_to_add_token_a: u128,
max_amount_to_add_token_b: u128,
deadline: u64,
) -> SpelResult {
let (post_states, chained_calls) = amm_program::add::add_liquidity(
pool,
Expand All @@ -75,7 +78,8 @@ mod amm {
max_amount_to_add_token_a,
max_amount_to_add_token_b,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Ok(SpelOutput::with_chained_calls(post_states, chained_calls)
.with_timestamp_validity_window(..deadline))
}

/// Removes liquidity from the Pool.
Expand All @@ -91,6 +95,7 @@ mod amm {
remove_liquidity_amount: u128,
min_amount_to_remove_token_a: u128,
min_amount_to_remove_token_b: u128,
deadline: u64,
) -> SpelResult {
let (post_states, chained_calls) = amm_program::remove::remove_liquidity(
pool,
Expand All @@ -105,7 +110,8 @@ mod amm {
min_amount_to_remove_token_a,
min_amount_to_remove_token_b,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Ok(SpelOutput::with_chained_calls(post_states, chained_calls)
.with_timestamp_validity_window(..deadline))
}

/// Swap some quantity of tokens while maintaining the pool constant product.
Expand All @@ -119,6 +125,7 @@ mod amm {
swap_amount_in: u128,
min_amount_out: u128,
token_definition_id_in: AccountId,
deadline: u64,
) -> SpelResult {
let (post_states, chained_calls) = amm_program::swap::swap_exact_input(
pool,
Expand All @@ -130,7 +137,8 @@ mod amm {
min_amount_out,
token_definition_id_in,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Ok(SpelOutput::with_chained_calls(post_states, chained_calls)
.with_timestamp_validity_window(..deadline))
}

/// Swap tokens specifying the exact desired output amount.
Expand All @@ -144,6 +152,7 @@ mod amm {
exact_amount_out: u128,
max_amount_in: u128,
token_definition_id_in: AccountId,
deadline: u64,
) -> SpelResult {
let (post_states, chained_calls) = amm_program::swap::swap_exact_output(
pool,
Expand All @@ -155,7 +164,8 @@ mod amm {
max_amount_in,
token_definition_id_in,
);
Ok(SpelOutput::with_chained_calls(post_states, chained_calls))
Ok(SpelOutput::with_chained_calls(post_states, chained_calls)
.with_timestamp_validity_window(..deadline))
}

/// Sync pool reserves with current vault balances.
Expand Down
20 changes: 20 additions & 0 deletions artifacts/amm-idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
{
"name": "amm_program_id",
"type": "program_id"
},
{
"name": "deadline",
"type": "u64"
}
]
},
Expand Down Expand Up @@ -131,6 +135,10 @@
{
"name": "max_amount_to_add_token_b",
"type": "u128"
},
{
"name": "deadline",
"type": "u64"
}
]
},
Expand Down Expand Up @@ -192,6 +200,10 @@
{
"name": "min_amount_to_remove_token_b",
"type": "u128"
},
{
"name": "deadline",
"type": "u64"
}
]
},
Expand Down Expand Up @@ -241,6 +253,10 @@
{
"name": "token_definition_id_in",
"type": "account_id"
},
{
"name": "deadline",
"type": "u64"
}
]
},
Expand Down Expand Up @@ -290,6 +306,10 @@
{
"name": "token_definition_id_in",
"type": "account_id"
},
{
"name": "deadline",
"type": "u64"
}
]
},
Expand Down
10 changes: 7 additions & 3 deletions ata/methods/guest/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ata/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "ata"
path = "src/bin/ata.rs"

[dependencies]
spel-framework = { git = "https://github.com/logos-co/spel.git", tag = "v0.2.0-rc.2", package = "spel-framework" }
spel-framework = { git = "https://github.com/logos-co/spel.git", rev = "9e7f2754e1d4cdb3ea36e63b1ff86c3af55488d3", package = "spel-framework" }
nssa_core = { git = "https://github.com/logos-blockchain/logos-execution-zone.git", tag = "v0.2.0-rc1" }
risc0-zkvm = { version = "=3.0.5", default-features = false }
ata_core = { path = "../../core" }
Expand Down
Loading
Loading