-
Notifications
You must be signed in to change notification settings - Fork 2
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
ayushpaharia
wants to merge
1
commit into
DappioLab:master
Choose a base branch
from
ayushpaharia:marinade-adapter
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
// 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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
ofAccountMeta
s?