Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip:feat: added marinade as an adapter #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ adapter_katana = "ADPTwDKJTizC3V8gZXDxt5uLjJv4pBnh1nTTf9dZJnS2"
adapter_tulip = "ADPT9nhC1asRcEB13FKymLTatqWGCuZHDznGgnakWKxW"
adapter_friktion = "ADPTzbsaBdXA3FqXoPHjaTjPfh9kadxxFKxonZihP1Ji"
adapter_nft_finance = "ADPTyBr92sBCE1hdYBRvXbMpF4hKs17xyDjFPxopcsrh"
adapter_marinade = "ADPTAGmW9f42rJ5a25vECpjtzhQCHVDBgqhRCxi5cQbi"

[registry]
url = "https://anchor.projectserum.com"
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

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

19 changes: 19 additions & 0 deletions programs/adapter-marinade/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "adapter-marinade"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "adapter_marinade"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]

[dependencies]
anchor-lang = "0.24.2"
anchor-spl = "0.24.2"
2 changes: 2 additions & 0 deletions programs/adapter-marinade/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
71 changes: 71 additions & 0 deletions programs/adapter-marinade/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use anchor_lang::prelude::*;
use anchor_lang::solana_program::{
hash::hash,
instruction::{AccountMeta, Instruction},
program::invoke,
};

declare_id!("ADPTAGmW9f42rJ5a25vECpjtzhQCHVDBgqhRCxi5cQbi");

pub mod adapter_lido {
use super::*;
use std::borrow::BorrowMut;

pub fn initiate_deposit<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, Action<'info>>,
input: Vec<u8>,
) -> Result<()> {
let mut deposit_data = sighash("global", "deposit").to_vec();
let mut input_bytes = &input[..];
let input_struct = InitiateDepositInputWrapper::deserialize(&mut input_bytes)?;

let deposit_amount = input_struct.deposit_amount;

deposit_data.append(deposit_amount.to_le_bytes().to_vec().borrow_mut());

let deposit_accounts = vec![
AccountMeta::new(ctx.remaining_accounts[0].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[1].key(), false),
AccountMeta::new(ctx.remaining_accounts[2].key(), false),
AccountMeta::new(ctx.remaining_accounts[3].key(), false),
AccountMeta::new(ctx.remaining_accounts[4].key(), false),
AccountMeta::new(ctx.remaining_accounts[5].key(), false),
AccountMeta::new(ctx.remaining_accounts[6].key(), false),
AccountMeta::new(ctx.remaining_accounts[7].key(), true),
AccountMeta::new_readonly(ctx.remaining_accounts[8].key(), false),
];

let ix = Instruction {
program_id: ctx.accounts.base_program_id.key(),
accounts: deposit_accounts,
data: deposit_data,
};

invoke(&ix, ctx.remaining_accounts)?;

msg!("Input: {:?}", input_struct);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe these lines should go higher up, before the Vec of AccountMetas?


// Deriving keys
Ok(())
}
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
pub struct InitiateDepositInputWrapper {
pub deposit_amount: u64,
}

pub struct Action<'info> {
// TODO: Add constraints
pub gateway_authority: Signer<'info>,
/// CHECK: Safe
pub base_program_id: AccountInfo<'info>,
}

pub fn sighash(namespace: &str, name: &str) -> [u8; 8] {
let preimage = format!("{}:{}", namespace, name);
let mut sighash = [0u8; 8];

sighash.copy_from_slice(&hash(preimage.as_bytes()).to_bytes()[..8]);
sighash
}