mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-04 22:33:06 +00:00
fixed accountId
This commit is contained in:
parent
3e9f0f9384
commit
c0c1228e10
@ -12,7 +12,7 @@ chacha20 = { version = "0.9", default-features = false }
|
||||
k256 = { version = "0.13.3", optional = true }
|
||||
base58 = { version = "0.2.0", optional = true }
|
||||
anyhow = { version = "1.0.98", optional = true }
|
||||
borsh.workspace = true
|
||||
borsh = "1.5.7"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
@ -41,10 +41,10 @@ impl AccountWithMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize)]
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Hash, BorshSerialize, BorshDeserialize, Default)]
|
||||
#[cfg_attr(
|
||||
any(feature = "host", test),
|
||||
derive(Debug, Copy, PartialOrd, Ord, Default)
|
||||
derive(Debug, Copy, PartialOrd, Ord)
|
||||
)]
|
||||
pub struct AccountId {
|
||||
value: [u8; 32],
|
||||
@ -175,4 +175,11 @@ mod tests {
|
||||
let result = base58_str.parse::<AccountId>().unwrap_err();
|
||||
assert!(matches!(result, AccountIdError::InvalidLength(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_account_id() {
|
||||
let default_account_id = AccountId::default();
|
||||
let expected_account_id = AccountId::new([0;32]);
|
||||
assert!(default_account_id == expected_account_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use nssa_core::{
|
||||
address::Address,
|
||||
account::{Account, AccountId, AccountWithMetadata, Data},
|
||||
program::{ProgramId, ProgramInput, ChainedCall, read_nssa_inputs, write_nssa_outputs_with_chained_call},
|
||||
};
|
||||
@ -37,8 +36,8 @@ use bytemuck;
|
||||
const POOL_DEFINITION_DATA_SIZE: usize = 240;
|
||||
|
||||
struct PoolDefinition{
|
||||
definition_token_a_id: Address,
|
||||
definition_token_b_id: Address,
|
||||
definition_token_a_id: AccountId,
|
||||
definition_token_b_id: AccountId,
|
||||
vault_a_addr: AccountId,
|
||||
vault_b_addr: AccountId,
|
||||
liquidity_pool_id: AccountId,
|
||||
@ -166,7 +165,7 @@ fn main() {
|
||||
let mut token_addr: [u8;32] = [0;32];
|
||||
token_addr[0..].copy_from_slice(&instruction[17..49]);
|
||||
|
||||
let token_addr = Address::new(token_addr);
|
||||
let token_addr = AccountId::new(token_addr);
|
||||
|
||||
let amount = u128::from_le_bytes(instruction[1..17].try_into().unwrap());
|
||||
|
||||
@ -181,7 +180,7 @@ fn main() {
|
||||
|
||||
let mut token_addr: [u8;32] = [0;32];
|
||||
token_addr[0..].copy_from_slice(&instruction[33..65]);
|
||||
let token_addr = Address::new(token_addr);
|
||||
let token_addr = AccountId::new(token_addr);
|
||||
|
||||
let (post_states, chained_call) = add_liquidity(&pre_states,
|
||||
&[balance_a, balance_b], token_addr.clone());
|
||||
@ -320,12 +319,14 @@ fn new_definition(
|
||||
fn swap(
|
||||
pre_states: &[AccountWithMetadata],
|
||||
amount: u128,
|
||||
token_id: Address,
|
||||
token_id: AccountId,
|
||||
) -> (Vec<Account>, Vec<ChainedCall>) {
|
||||
|
||||
if pre_states.len() != 5 {
|
||||
panic!("Invalid number of input accounts");
|
||||
}
|
||||
//TODO: get rid of
|
||||
|
||||
|
||||
let pool = &pre_states[0];
|
||||
let vault1 = &pre_states[1];
|
||||
@ -357,7 +358,7 @@ fn swap(
|
||||
true
|
||||
} else if token_id == pool_def_data.definition_token_b_id { false }
|
||||
else {
|
||||
panic!("Address is not a token type for the pool");
|
||||
panic!("AccountId is not a token type for the pool");
|
||||
};
|
||||
|
||||
let deposit_a = if a_to_b { amount } else { 0 };
|
||||
@ -469,7 +470,7 @@ fn swap(
|
||||
|
||||
fn add_liquidity(pre_states: &[AccountWithMetadata],
|
||||
max_balance_in: &[u128],
|
||||
main_token: Address) -> (Vec<Account>, Vec<ChainedCall>) {
|
||||
main_token: AccountId) -> (Vec<Account>, Vec<ChainedCall>) {
|
||||
|
||||
if pre_states.len() != 7 {
|
||||
panic!("Invalid number of input accounts");
|
||||
@ -943,7 +944,7 @@ mod tests {
|
||||
let pre_states = vec![AccountWithMetadata {
|
||||
account: pool,
|
||||
is_authorized: true,
|
||||
account_id: AccountId::default()},
|
||||
account_id: AccountId::new([0;32])},
|
||||
AccountWithMetadata {
|
||||
account: Account::default(),
|
||||
is_authorized: true,
|
||||
@ -3574,7 +3575,7 @@ mod tests {
|
||||
let _post_states = swap(&pre_states, amount, vault_addr);
|
||||
}
|
||||
|
||||
#[should_panic(expected = "Address is not a token type for the pool")]
|
||||
#[should_panic(expected = "AccountId is not a token type for the pool")]
|
||||
#[test]
|
||||
fn test_call_swap_incorrect_token_type() {
|
||||
let mut pool = Account::default();
|
||||
|
||||
@ -99,7 +99,7 @@ impl Program {
|
||||
pub fn amm() -> Self {
|
||||
// This unwrap wont panic since the `AMM_ELF` comes from risc0 build of
|
||||
// `program_methods`
|
||||
Self::new(AMM_ELF.to_vec()).unwrap()
|
||||
Self::new(AMM_ELF.to_vec()).expect("The AMM program must be a valid Risc0 program")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user