From a397b08368c19260f258982a9f219c3bb765fbb4 Mon Sep 17 00:00:00 2001 From: Emanuele Cesena Date: Sat, 6 Apr 2024 18:38:37 -0700 Subject: [PATCH] docs --- DEVELOPER.md | 80 +++++++++++++ README.md | 82 +++++-------- anchor/programs-old/custody/Cargo.toml | 19 --- anchor/programs-old/custody/Xargo.toml | 2 - anchor/programs-old/custody/src/constants.rs | 4 - anchor/programs-old/custody/src/error.rs | 7 -- .../custody/src/instructions/initialize.rs | 8 -- .../custody/src/instructions/mod.rs | 3 - anchor/programs-old/custody/src/lib.rs | 20 ---- anchor/programs-old/custody/src/state/mod.rs | 1 - anchor/programs-old/policy/Cargo.toml | 26 ---- anchor/programs-old/policy/Xargo.toml | 2 - anchor/programs-old/policy/src/constants.rs | 4 - anchor/programs-old/policy/src/error.rs | 7 -- .../policy/src/instructions/mod.rs | 3 - .../policy/src/instructions/transfer_hook.rs | 38 ------ anchor/programs-old/policy/src/lib.rs | 111 ------------------ anchor/programs-old/policy/src/state/mod.rs | 1 - anchor/programs-old/pricing/Cargo.toml | 21 ---- anchor/programs-old/pricing/Xargo.toml | 2 - anchor/programs-old/pricing/src/constants.rs | 4 - anchor/programs-old/pricing/src/error.rs | 9 -- .../pricing/src/instructions/initialize.rs | 8 -- .../pricing/src/instructions/mod.rs | 5 - .../pricing/src/instructions/pay_usd.rs | 50 -------- anchor/programs-old/pricing/src/lib.rs | 24 ---- anchor/programs-old/pricing/src/state/mod.rs | 1 - anchor/programs-old/pricing/src/tokens.rs | 18 --- anchor/programs-old/strategy/Cargo.toml | 19 --- anchor/programs-old/strategy/Xargo.toml | 2 - anchor/programs-old/strategy/src/constants.rs | 4 - anchor/programs-old/strategy/src/error.rs | 7 -- .../strategy/src/instructions/initialize.rs | 8 -- .../strategy/src/instructions/mod.rs | 3 - anchor/programs-old/strategy/src/lib.rs | 20 ---- anchor/programs-old/strategy/src/state/mod.rs | 1 - 36 files changed, 109 insertions(+), 515 deletions(-) create mode 100644 DEVELOPER.md delete mode 100644 anchor/programs-old/custody/Cargo.toml delete mode 100644 anchor/programs-old/custody/Xargo.toml delete mode 100644 anchor/programs-old/custody/src/constants.rs delete mode 100644 anchor/programs-old/custody/src/error.rs delete mode 100644 anchor/programs-old/custody/src/instructions/initialize.rs delete mode 100644 anchor/programs-old/custody/src/instructions/mod.rs delete mode 100644 anchor/programs-old/custody/src/lib.rs delete mode 100644 anchor/programs-old/custody/src/state/mod.rs delete mode 100644 anchor/programs-old/policy/Cargo.toml delete mode 100644 anchor/programs-old/policy/Xargo.toml delete mode 100644 anchor/programs-old/policy/src/constants.rs delete mode 100644 anchor/programs-old/policy/src/error.rs delete mode 100644 anchor/programs-old/policy/src/instructions/mod.rs delete mode 100644 anchor/programs-old/policy/src/instructions/transfer_hook.rs delete mode 100644 anchor/programs-old/policy/src/lib.rs delete mode 100644 anchor/programs-old/policy/src/state/mod.rs delete mode 100644 anchor/programs-old/pricing/Cargo.toml delete mode 100644 anchor/programs-old/pricing/Xargo.toml delete mode 100644 anchor/programs-old/pricing/src/constants.rs delete mode 100644 anchor/programs-old/pricing/src/error.rs delete mode 100644 anchor/programs-old/pricing/src/instructions/initialize.rs delete mode 100644 anchor/programs-old/pricing/src/instructions/mod.rs delete mode 100644 anchor/programs-old/pricing/src/instructions/pay_usd.rs delete mode 100644 anchor/programs-old/pricing/src/lib.rs delete mode 100644 anchor/programs-old/pricing/src/state/mod.rs delete mode 100644 anchor/programs-old/pricing/src/tokens.rs delete mode 100644 anchor/programs-old/strategy/Cargo.toml delete mode 100644 anchor/programs-old/strategy/Xargo.toml delete mode 100644 anchor/programs-old/strategy/src/constants.rs delete mode 100644 anchor/programs-old/strategy/src/error.rs delete mode 100644 anchor/programs-old/strategy/src/instructions/initialize.rs delete mode 100644 anchor/programs-old/strategy/src/instructions/mod.rs delete mode 100644 anchor/programs-old/strategy/src/lib.rs delete mode 100644 anchor/programs-old/strategy/src/state/mod.rs diff --git a/DEVELOPER.md b/DEVELOPER.md new file mode 100644 index 00000000..10195be0 --- /dev/null +++ b/DEVELOPER.md @@ -0,0 +1,80 @@ +

+ + + + GLAM *.+ The New Standard for Asset Management. + +
+ Website | + Contact | + X +
+
+
+

+ +--- + +
+ +GLAM is a decentralized on-chain asset management protocol on Solana that enables efficient management & operations of investment products, empowering investors to have greater control & equity in their financial futures. + +## Dev + +This project was generated with the [create-solana-dapp](https://github.com/solana-developers/create-solana-dapp) generator using React preset. + +### Prerequisites + +- Node v20.11.0 or higher +- Pnpm v8.15.1 or higher +- Rust v1.75.0 or higher +- Anchor CLI 0.29.0 or higher +- Solana CLI 1.18.7 + +Recommended: + +```shell +sh -c "$(curl -sSfL https://release.solana.com/v1.18.7/install)" +``` + +### Installation + +```shell +git clone ... +cd glam + +pnpm install +``` + +(Internal team only: get `keypairs.zip` and unpack it into `./anchor/target/deploy`) + +### Run the tests + +```shell +cd anchor +anchor build +# ^ this will create target/deploy +cd target/deploy +unzip /path/to/keypairs.zip +cd - +anchor test +``` + +This should also work: + +```shell +pnpm run anchor-build +pnpm run anchor-test +``` + +### Start the web app + +```shell +pnpm run dev +``` + +### Start the api server + +```shell +cd api && npm start +``` diff --git a/README.md b/README.md index eddfbbfe..dbeaad91 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,9 @@ GLAM *.+ The New Standard for Asset Management.
- Website | - Contact | - X + Website | + Contact | + X


@@ -20,62 +19,39 @@ GLAM is a decentralized on-chain asset management protocol on Solana that enables efficient management & operations of investment products, empowering investors to have greater control & equity in their financial futures. -## Dev +## Demo -This project is generated with the [create-solana-dapp](https://github.com/solana-developers/create-solana-dapp) generator using React preset. +Check out the live demo: [https://beta.glam.systems](https://beta.glam.systems) -### Prerequisites +Or watch our 3 min video: -- Node v20.11.0 or higher -- Pnpm v8.15.1 or higher -- Rust v1.75.0 or higher -- Anchor CLI 0.29.0 or higher -- Solana CLI 1.18.7 +[![GLAM demo](https://img.youtube.com/vi/K6H1TRbiaR4/0.jpg)](https://www.youtube.com/watch?v=K6H1TRbiaR4) -Recommended: +## Features -```shell -sh -c "$(curl -sSfL https://release.solana.com/v1.18.7/install)" -``` +Fund: -### Installation +- [x] On chain [Openfunds](https://openfunds.org) +- [x] Segregated treasury account +- [x] Share classes (Token 2022) + - [x] On chain Openfunds Share Class (Metadata Extension) + - [x] Lockup period (Transfer Hook, in progress) + - [ ] Non-Transferable + - [ ] Permanent Delegate +- [x] Investors subscribe & redeem +- [ ] Fees +- [ ] Subscription limits +- [ ] External/off chain assets -```shell -git clone ... -cd glam +Integrations: -pnpm install -``` +- [x] User wallets (Phantom, Backpack) +- [x] Pricing (Pyth) +- [x] Trading (Drift delegate account, deposit, withdraw) +- [ ] Swap, rebalance (Orca?, Jupiter?) +- [ ] Alternative strategy engine (Symmetry?) +- [ ] Alternative custody (Squad?) -Get `keypairs.zip` and unpack it into `./anchor/target/deploy`. +## Contribute -### Run the tests - -```shell -cd anchor -anchor build -# ^ this will create target/deploy -cd target/deploy -unzip /path/to/keypairs.zip -cd - -anchor test -``` - -This should also work: - -```shell -pnpm run anchor-build -pnpm run anchor-test -``` - -### Start the web app - -```shell -pnpm run dev -``` - -### Start the api server - -```shell -cd api/ && npm start -``` +We love any type of contribution, bug fixes, new integrations and better docs. See [DEVELOPER.md](./DEVELOPER.md) to get started. diff --git a/anchor/programs-old/custody/Cargo.toml b/anchor/programs-old/custody/Cargo.toml deleted file mode 100644 index f647a5fb..00000000 --- a/anchor/programs-old/custody/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "custody" -version = "0.1.0" -description = "Created with Anchor" -edition = "2021" - -[lib] -crate-type = ["cdylib", "lib"] -name = "custody" - -[features] -no-entrypoint = [] -no-idl = [] -no-log-ix-name = [] -cpi = ["no-entrypoint"] -default = [] - -[dependencies] -anchor-lang = { workspace = true } diff --git a/anchor/programs-old/custody/Xargo.toml b/anchor/programs-old/custody/Xargo.toml deleted file mode 100644 index 475fb71e..00000000 --- a/anchor/programs-old/custody/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.bpfel-unknown-unknown.dependencies.std] -features = [] diff --git a/anchor/programs-old/custody/src/constants.rs b/anchor/programs-old/custody/src/constants.rs deleted file mode 100644 index fae45359..00000000 --- a/anchor/programs-old/custody/src/constants.rs +++ /dev/null @@ -1,4 +0,0 @@ -use anchor_lang::prelude::*; - -#[constant] -pub const SEED: &str = "anchor"; diff --git a/anchor/programs-old/custody/src/error.rs b/anchor/programs-old/custody/src/error.rs deleted file mode 100644 index c37199a4..00000000 --- a/anchor/programs-old/custody/src/error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use anchor_lang::prelude::*; - -#[error_code] -pub enum ErrorCode { - #[msg("Custom error message")] - CustomError, -} diff --git a/anchor/programs-old/custody/src/instructions/initialize.rs b/anchor/programs-old/custody/src/instructions/initialize.rs deleted file mode 100644 index bc0305f2..00000000 --- a/anchor/programs-old/custody/src/instructions/initialize.rs +++ /dev/null @@ -1,8 +0,0 @@ -use anchor_lang::prelude::*; - -#[derive(Accounts)] -pub struct Initialize {} - -pub fn handler(_ctx: Context) -> Result<()> { - Ok(()) -} diff --git a/anchor/programs-old/custody/src/instructions/mod.rs b/anchor/programs-old/custody/src/instructions/mod.rs deleted file mode 100644 index b5a1d312..00000000 --- a/anchor/programs-old/custody/src/instructions/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod initialize; - -pub use initialize::*; diff --git a/anchor/programs-old/custody/src/lib.rs b/anchor/programs-old/custody/src/lib.rs deleted file mode 100644 index 3c4d401c..00000000 --- a/anchor/programs-old/custody/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -pub mod constants; -pub mod error; -pub mod instructions; -pub mod state; - -use anchor_lang::prelude::*; - -pub use constants::*; -pub use instructions::*; - -declare_id!("Gcu1vbed9bwpfwU9PCnJw8QanQfVHfETWxAK3EZczbgo"); - -#[program] -pub mod custody { - use super::*; - - pub fn initialize(ctx: Context) -> Result<()> { - initialize::handler(ctx) - } -} diff --git a/anchor/programs-old/custody/src/state/mod.rs b/anchor/programs-old/custody/src/state/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/anchor/programs-old/custody/src/state/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/anchor/programs-old/policy/Cargo.toml b/anchor/programs-old/policy/Cargo.toml deleted file mode 100644 index 6668b419..00000000 --- a/anchor/programs-old/policy/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "policy" -version = "0.1.0" -description = "Created with Anchor" -edition = "2021" - -[lib] -crate-type = ["cdylib", "lib"] -name = "policy" - -[features] -no-entrypoint = [] -no-idl = [] -no-log-ix-name = [] -cpi = ["no-entrypoint"] -default = [] - -[dependencies] -anchor-lang = { workspace = true } -anchor-spl = { workspace = true } -solana-program = { workspace = true } -spl-associated-token-account = { workspace = true } -spl-token = { workspace = true } -spl-token-2022 = { workspace = true } -spl-tlv-account-resolution = { workspace = true } -spl-transfer-hook-interface = { workspace = true } diff --git a/anchor/programs-old/policy/Xargo.toml b/anchor/programs-old/policy/Xargo.toml deleted file mode 100644 index 475fb71e..00000000 --- a/anchor/programs-old/policy/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.bpfel-unknown-unknown.dependencies.std] -features = [] diff --git a/anchor/programs-old/policy/src/constants.rs b/anchor/programs-old/policy/src/constants.rs deleted file mode 100644 index fae45359..00000000 --- a/anchor/programs-old/policy/src/constants.rs +++ /dev/null @@ -1,4 +0,0 @@ -use anchor_lang::prelude::*; - -#[constant] -pub const SEED: &str = "anchor"; diff --git a/anchor/programs-old/policy/src/error.rs b/anchor/programs-old/policy/src/error.rs deleted file mode 100644 index 97e478b9..00000000 --- a/anchor/programs-old/policy/src/error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use anchor_lang::prelude::*; - -#[error_code] -pub enum PolicyError { - #[msg("Amount too big")] - AmountTooBig, -} diff --git a/anchor/programs-old/policy/src/instructions/mod.rs b/anchor/programs-old/policy/src/instructions/mod.rs deleted file mode 100644 index 34c70324..00000000 --- a/anchor/programs-old/policy/src/instructions/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod transfer_hook; - -pub use transfer_hook::*; diff --git a/anchor/programs-old/policy/src/instructions/transfer_hook.rs b/anchor/programs-old/policy/src/instructions/transfer_hook.rs deleted file mode 100644 index 4ea23a30..00000000 --- a/anchor/programs-old/policy/src/instructions/transfer_hook.rs +++ /dev/null @@ -1,38 +0,0 @@ -use anchor_lang::prelude::*; -use anchor_spl::token_interface::{Mint, TokenAccount}; - -use crate::error::PolicyError; - -#[derive(Accounts)] -pub struct Initialize {} - -pub fn handler(_ctx: Context, amount: u64) -> Result<()> { - msg!("Hello policy hook!"); - - if amount > 50_000_000 { - return err!(PolicyError::AmountTooBig); - } - - Ok(()) -} - -// Order of accounts matters for this struct. -// The first 4 accounts are the accounts required for token transfer (source, mint, destination, owner) -// Remaining accounts are the extra accounts required from the ExtraAccountMetaList account -// These accounts are provided via CPI to this program from the token2022 program -#[derive(Accounts)] -pub struct TransferHook<'info> { - #[account(token::mint = mint, token::authority = owner)] - pub source_token: InterfaceAccount<'info, TokenAccount>, - pub mint: InterfaceAccount<'info, Mint>, - #[account(token::mint = mint)] - pub destination_token: InterfaceAccount<'info, TokenAccount>, - /// CHECK: source token account owner, can be SystemAccount or PDA owned by another program - pub owner: UncheckedAccount<'info>, - /// CHECK: ExtraAccountMetaList Account, - #[account( - seeds = [b"extra-account-metas", mint.key().as_ref()], - bump - )] - pub extra_account_meta_list: UncheckedAccount<'info>, -} diff --git a/anchor/programs-old/policy/src/lib.rs b/anchor/programs-old/policy/src/lib.rs deleted file mode 100644 index 3b8109fd..00000000 --- a/anchor/programs-old/policy/src/lib.rs +++ /dev/null @@ -1,111 +0,0 @@ -/* https://solana.com/zh/developers/guides/token-extensions/transfer-hook#hello-world-transfer-hook */ -pub mod constants; -pub mod error; -pub mod instructions; -pub mod state; - -use anchor_lang::{ - prelude::*, - system_program::{create_account, CreateAccount}, -}; -use anchor_spl::{ - associated_token::AssociatedToken, - token_interface::{Mint, TokenInterface}, -}; -use spl_tlv_account_resolution::state::ExtraAccountMetaList; -use spl_transfer_hook_interface::instruction::{ExecuteInstruction, TransferHookInstruction}; - -pub use constants::*; -pub use instructions::*; - -declare_id!("Gpo1jXtEFepqyPQWTG7oDJrg8rye8JL3zcsczHzXKqLt"); - -#[program] -pub mod policy { - use super::*; - - pub fn transfer_hook(ctx: Context, amount: u64) -> Result<()> { - transfer_hook::handler(ctx, amount) - } - - pub fn initialize_extra_account_meta_list( - ctx: Context, - ) -> Result<()> { - // The `addExtraAccountsToInstruction` JS helper function resolving incorrectly - let account_metas = vec![]; - - // calculate account size - let account_size = ExtraAccountMetaList::size_of(account_metas.len())? as u64; - // calculate minimum required lamports - let lamports = Rent::get()?.minimum_balance(account_size as usize); - - let mint = ctx.accounts.mint.key(); - let signer_seeds: &[&[&[u8]]] = &[&[ - b"extra-account-metas", - &mint.as_ref(), - &[ctx.bumps.extra_account_meta_list], - ]]; - - // create ExtraAccountMetaList account - create_account( - CpiContext::new( - ctx.accounts.system_program.to_account_info(), - CreateAccount { - from: ctx.accounts.payer.to_account_info(), - to: ctx.accounts.extra_account_meta_list.to_account_info(), - }, - ) - .with_signer(signer_seeds), - lamports, - account_size, - ctx.program_id, - )?; - - // initialize ExtraAccountMetaList account with extra accounts - ExtraAccountMetaList::init::( - &mut ctx.accounts.extra_account_meta_list.try_borrow_mut_data()?, - &account_metas, - )?; - - Ok(()) - } - - // fallback instruction handler as workaround to anchor instruction discriminator check - pub fn fallback<'info>( - program_id: &Pubkey, - accounts: &'info [AccountInfo<'info>], - data: &[u8], - ) -> Result<()> { - let instruction = TransferHookInstruction::unpack(data)?; - - // match instruction discriminator to transfer hook interface execute instruction - // token2022 program CPIs this instruction on token transfer - match instruction { - TransferHookInstruction::Execute { amount } => { - let amount_bytes = amount.to_le_bytes(); - - // invoke custom transfer hook instruction on our program - __private::__global::transfer_hook(program_id, accounts, &amount_bytes) - } - _ => Err(ProgramError::InvalidInstructionData.into()), - } - } -} - -#[derive(Accounts)] -pub struct InitializeExtraAccountMetaList<'info> { - #[account(mut)] - payer: Signer<'info>, - - /// CHECK: ExtraAccountMetaList Account, must use these seeds - #[account( - mut, - seeds = [b"extra-account-metas", mint.key().as_ref()], - bump - )] - pub extra_account_meta_list: AccountInfo<'info>, - pub mint: InterfaceAccount<'info, Mint>, - pub token_program: Interface<'info, TokenInterface>, - pub associated_token_program: Program<'info, AssociatedToken>, - pub system_program: Program<'info, System>, -} diff --git a/anchor/programs-old/policy/src/state/mod.rs b/anchor/programs-old/policy/src/state/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/anchor/programs-old/policy/src/state/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/anchor/programs-old/pricing/Cargo.toml b/anchor/programs-old/pricing/Cargo.toml deleted file mode 100644 index 954f0818..00000000 --- a/anchor/programs-old/pricing/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "pricing" -version = "0.1.0" -description = "Created with Anchor" -edition = "2021" - -[lib] -crate-type = ["cdylib", "lib"] -name = "pricing" - -[features] -no-entrypoint = [] -no-idl = [] -no-log-ix-name = [] -cpi = ["no-entrypoint"] -default = [] - -[dependencies] -anchor-lang = { workspace = true } -solana-program = { workspace = true } -pyth-sdk-solana = { workspace = true } diff --git a/anchor/programs-old/pricing/Xargo.toml b/anchor/programs-old/pricing/Xargo.toml deleted file mode 100644 index 475fb71e..00000000 --- a/anchor/programs-old/pricing/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.bpfel-unknown-unknown.dependencies.std] -features = [] diff --git a/anchor/programs-old/pricing/src/constants.rs b/anchor/programs-old/pricing/src/constants.rs deleted file mode 100644 index fae45359..00000000 --- a/anchor/programs-old/pricing/src/constants.rs +++ /dev/null @@ -1,4 +0,0 @@ -use anchor_lang::prelude::*; - -#[constant] -pub const SEED: &str = "anchor"; diff --git a/anchor/programs-old/pricing/src/error.rs b/anchor/programs-old/pricing/src/error.rs deleted file mode 100644 index 41e477bf..00000000 --- a/anchor/programs-old/pricing/src/error.rs +++ /dev/null @@ -1,9 +0,0 @@ -use anchor_lang::prelude::*; - -#[error_code] -pub enum PricingError { - #[msg("Price is currently not available")] - PriceUnavailable, - #[msg("Invalid price feed id")] - InvalidPriceFeedId, -} diff --git a/anchor/programs-old/pricing/src/instructions/initialize.rs b/anchor/programs-old/pricing/src/instructions/initialize.rs deleted file mode 100644 index bc0305f2..00000000 --- a/anchor/programs-old/pricing/src/instructions/initialize.rs +++ /dev/null @@ -1,8 +0,0 @@ -use anchor_lang::prelude::*; - -#[derive(Accounts)] -pub struct Initialize {} - -pub fn handler(_ctx: Context) -> Result<()> { - Ok(()) -} diff --git a/anchor/programs-old/pricing/src/instructions/mod.rs b/anchor/programs-old/pricing/src/instructions/mod.rs deleted file mode 100644 index a49b1835..00000000 --- a/anchor/programs-old/pricing/src/instructions/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod initialize; -pub mod pay_usd; - -pub use initialize::*; -pub use pay_usd::*; diff --git a/anchor/programs-old/pricing/src/instructions/pay_usd.rs b/anchor/programs-old/pricing/src/instructions/pay_usd.rs deleted file mode 100644 index a632ebec..00000000 --- a/anchor/programs-old/pricing/src/instructions/pay_usd.rs +++ /dev/null @@ -1,50 +0,0 @@ -use anchor_lang::prelude::*; -use anchor_lang::solana_program::{ - native_token::LAMPORTS_PER_SOL, program::invoke, system_instruction, -}; -use pyth_sdk_solana::state::SolanaPriceAccount; -use std::str::FromStr; - -use crate::error::PricingError; - -const SOL_USD_PRICEFEED_ID: &str = "J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"; - -#[derive(Accounts)] -#[instruction(amount : u64)] -pub struct PayUsd<'info> { - pub from: Signer<'info>, - /// CHECK: This is an unchecked receiver account - #[account(mut)] - pub to: AccountInfo<'info>, - /// CHECK: We will manually check this against the Pubkey of the price feed - pub sol_usd_price_account: AccountInfo<'info>, - pub system_program: Program<'info, System>, -} - -pub fn handler(ctx: Context, amount: u64) -> Result<()> { - if Pubkey::from_str(SOL_USD_PRICEFEED_ID) != Ok(ctx.accounts.sol_usd_price_account.key()) { - return Err(error!(PricingError::InvalidPriceFeedId)); - }; - let sol_usd_price_feed = SolanaPriceAccount::account_info_to_feed(&ctx.accounts.sol_usd_price_account).unwrap(); - - let timestamp = Clock::get()?.unix_timestamp; - - if let Some(current_price) = sol_usd_price_feed.get_price_no_older_than(timestamp, 60) { - msg!("price: {} * 10^{}", current_price.price, current_price.expo); - - let amount_in_lamports = - amount * LAMPORTS_PER_SOL * 10u64.pow(u32::try_from(-current_price.expo).unwrap()) - / (u64::try_from(current_price.price).unwrap()); - - let transfer_instruction = system_instruction::transfer( - &ctx.accounts.from.key(), - &ctx.accounts.to.key(), - amount_in_lamports, - ); - invoke(&transfer_instruction, &ctx.accounts.to_account_infos())?; - } else { - return Err(error!(PricingError::PriceUnavailable)); - } - - Ok(()) -} diff --git a/anchor/programs-old/pricing/src/lib.rs b/anchor/programs-old/pricing/src/lib.rs deleted file mode 100644 index 6ef9f290..00000000 --- a/anchor/programs-old/pricing/src/lib.rs +++ /dev/null @@ -1,24 +0,0 @@ -pub mod constants; -pub mod error; -pub mod instructions; -pub mod state; - -use anchor_lang::prelude::*; - -pub use constants::*; -pub use instructions::*; - -declare_id!("Gpr1WZZXAty2L9eiMwZPC7ra69vMFojhdqDuiRHkQQQp"); - -#[program] -pub mod pricing { - use super::*; - - pub fn initialize(ctx: Context) -> Result<()> { - initialize::handler(ctx) - } - - pub fn pay_usd(ctx: Context, amount: u64) -> Result<()> { - pay_usd::handler(ctx, amount) - } -} diff --git a/anchor/programs-old/pricing/src/state/mod.rs b/anchor/programs-old/pricing/src/state/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/anchor/programs-old/pricing/src/state/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/anchor/programs-old/pricing/src/tokens.rs b/anchor/programs-old/pricing/src/tokens.rs deleted file mode 100644 index 231004d7..00000000 --- a/anchor/programs-old/pricing/src/tokens.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anchor_lang::prelude::*; -use std::str::FromStr; - -pub struct Token { - pub symbol: u64, - pub mint: Pubkey, -} - -const AVAILABLE_TOKENS: Vec = vec![ - Token{ - symbol: 1, - mint: Pubkey::from_str("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"), - }, - Token{ - symbol: 2, - mint: Pubkey::from_str("J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix"), - }, -]; diff --git a/anchor/programs-old/strategy/Cargo.toml b/anchor/programs-old/strategy/Cargo.toml deleted file mode 100644 index 5086eb15..00000000 --- a/anchor/programs-old/strategy/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "strategy" -version = "0.1.0" -description = "Created with Anchor" -edition = "2021" - -[lib] -crate-type = ["cdylib", "lib"] -name = "strategy" - -[features] -no-entrypoint = [] -no-idl = [] -no-log-ix-name = [] -cpi = ["no-entrypoint"] -default = [] - -[dependencies] -anchor-lang = { workspace = true } \ No newline at end of file diff --git a/anchor/programs-old/strategy/Xargo.toml b/anchor/programs-old/strategy/Xargo.toml deleted file mode 100644 index 475fb71e..00000000 --- a/anchor/programs-old/strategy/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[target.bpfel-unknown-unknown.dependencies.std] -features = [] diff --git a/anchor/programs-old/strategy/src/constants.rs b/anchor/programs-old/strategy/src/constants.rs deleted file mode 100644 index fae45359..00000000 --- a/anchor/programs-old/strategy/src/constants.rs +++ /dev/null @@ -1,4 +0,0 @@ -use anchor_lang::prelude::*; - -#[constant] -pub const SEED: &str = "anchor"; diff --git a/anchor/programs-old/strategy/src/error.rs b/anchor/programs-old/strategy/src/error.rs deleted file mode 100644 index c37199a4..00000000 --- a/anchor/programs-old/strategy/src/error.rs +++ /dev/null @@ -1,7 +0,0 @@ -use anchor_lang::prelude::*; - -#[error_code] -pub enum ErrorCode { - #[msg("Custom error message")] - CustomError, -} diff --git a/anchor/programs-old/strategy/src/instructions/initialize.rs b/anchor/programs-old/strategy/src/instructions/initialize.rs deleted file mode 100644 index bc0305f2..00000000 --- a/anchor/programs-old/strategy/src/instructions/initialize.rs +++ /dev/null @@ -1,8 +0,0 @@ -use anchor_lang::prelude::*; - -#[derive(Accounts)] -pub struct Initialize {} - -pub fn handler(_ctx: Context) -> Result<()> { - Ok(()) -} diff --git a/anchor/programs-old/strategy/src/instructions/mod.rs b/anchor/programs-old/strategy/src/instructions/mod.rs deleted file mode 100644 index b5a1d312..00000000 --- a/anchor/programs-old/strategy/src/instructions/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod initialize; - -pub use initialize::*; diff --git a/anchor/programs-old/strategy/src/lib.rs b/anchor/programs-old/strategy/src/lib.rs deleted file mode 100644 index 02cdb3e5..00000000 --- a/anchor/programs-old/strategy/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -pub mod constants; -pub mod error; -pub mod instructions; -pub mod state; - -use anchor_lang::prelude::*; - -pub use constants::*; -pub use instructions::*; - -declare_id!("Gst1YGe5vKURSWfCqM7GhZys1oML9E9t91WRyV2rt4yS"); - -#[program] -pub mod strategy { - use super::*; - - pub fn initialize(ctx: Context) -> Result<()> { - initialize::handler(ctx) - } -} diff --git a/anchor/programs-old/strategy/src/state/mod.rs b/anchor/programs-old/strategy/src/state/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/anchor/programs-old/strategy/src/state/mod.rs +++ /dev/null @@ -1 +0,0 @@ -