jup-lend-sdk 0.2.15

SDK for Jupiter lending protocol
Documentation
#[macro_export]
macro_rules! get_accounts {
    ($rpc:expr, $($key:expr => $type:ty),+ $(,)?) => {{
        async {
            use anchor_lang::AccountDeserialize;

            let keys = vec![$($key),+];
            let accounts = $rpc
                .get_multiple_accounts(&keys)
                .await?
                .into_iter();

            let mut iter = accounts.into_iter();

            let result = (
                $(
                    {
                        let account = iter
                            .next()
                            .ok_or_else(|| anyhow::anyhow!("Missing account"))?
                            .ok_or_else(|| anyhow::anyhow!("Account not found"))?;

                        <$type>::try_deserialize(
                            &mut account.data.as_slice()
                        )?
                    }
                ),+
            );


            anyhow::Ok(result)
        }
    }};
}

#[macro_export]
macro_rules! try_get_accounts {
    ($rpc:expr, $($key:expr => $type:ty),+ $(,)?) => {{
        async {
            let keys = vec![$($key),+];
            let accounts = $rpc.get_multiple_accounts(&keys).await?;

            let mut idx = 0;
            #[allow(unused_assignments)]
            let result = (
                $(
                    {
                         match accounts[idx].as_ref() {
                            Some(acc) => {
                                let deserialized = <$type>::try_deserialize(&mut &acc.data[..])?;
                                idx += 1;
                                Some(deserialized)
                            },
                            None => None
                        }
                    }
                ),+
            );

            Ok::<_, anyhow::Error>(result)
        }
    }};
}

#[macro_export]
macro_rules! get_accounts_owners {
    ($rpc:expr, $($key:expr),+ $(,)?) => {{
        async {
            let keys = vec![$($key),+];
            let accounts = $rpc.get_multiple_accounts(&keys).await?;

            let mut idx = 0;
            #[allow(unused_assignments)]
            let result = (
                $(
                    {
                        let _ = $key;
                        let account = accounts
                            .get(idx)
                            .ok_or_else(|| anyhow::anyhow!("Account at index {} not found", idx))?
                            .as_ref()
                            .ok_or_else(|| anyhow::anyhow!("Account at index {} is None", idx))?
                            .owner;
                        idx += 1;
                        account
                    }
                ),+
            );

            anyhow::Ok(result)
        }
    }};
}