Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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_lido = "ADPTPxbHbEBo9A8E53P2PZnmw3ZYJuwc8ArQQkbJtqhx"

[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-lido/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "adapter-lido"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

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

[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-lido/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
124 changes: 124 additions & 0 deletions programs/adapter-lido/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
use anchor_lang::prelude::*;
use anchor_lang::solana_program::{
instruction::{AccountMeta, Instruction},
program::invoke,
pubkey::Pubkey,
};
use anchor_spl::token::{Mint, TokenAccount};

declare_id!("ADPTPxbHbEBo9A8E53P2PZnmw3ZYJuwc8ArQQkbJtqhx");

#[program]
pub mod adapter_lido {
use anchor_lang::solana_program::{account_info::next_account_infos, stake};

use super::*;

pub fn deposit<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, Action<'info>>,
input: Vec<u8>,
) -> Result<()> {
// Get Input
let mut input_bytes = &input[..];
let input_struct = DepositInputWrapper::deserialize(&mut input_bytes)?;

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

let deposit_accounts = vec![
AccountMeta::new(ctx.remaining_accounts[0].key(), false),
AccountMeta::new(ctx.remaining_accounts[1].key(), true),
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_readonly(ctx.remaining_accounts[5].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[6].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[7].key(), false),
];

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

invoke(&ix, ctx.remaining_accounts)?;

Ok(())
}

pub fn withdraw<'a, 'b, 'c, 'info>(
ctx: Context<'a, 'b, 'c, 'info, Action<'info>>,
input: Vec<u8>,
) -> Result<()> {
// Get Input
let mut input_bytes = &input[..];
let input_struct = WithdrawInputWrapper::deserialize(&mut input_bytes)?;

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

let withdraw_accounts = if input_struct.instruction == 23 {
vec![
AccountMeta::new(ctx.remaining_accounts[0].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[1].key(), true),
AccountMeta::new(ctx.remaining_accounts[2].key(), false),
AccountMeta::new(ctx.remaining_accounts[3].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[4].key(), false),
AccountMeta::new(ctx.remaining_accounts[5].key(), false),
AccountMeta::new(ctx.remaining_accounts[6].key(), true),
AccountMeta::new_readonly(ctx.remaining_accounts[7].key(), false),
AccountMeta::new(ctx.remaining_accounts[8].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[9].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[10].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[11].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[12].key(), false),
]
} else {
vec![
AccountMeta::new(ctx.remaining_accounts[0].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[1].key(), true),
AccountMeta::new(ctx.remaining_accounts[2].key(), false),
AccountMeta::new(ctx.remaining_accounts[3].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[4].key(), false),
AccountMeta::new(ctx.remaining_accounts[5].key(), false),
AccountMeta::new(ctx.remaining_accounts[6].key(), true),
AccountMeta::new_readonly(ctx.remaining_accounts[7].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[8].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[9].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[10].key(), false),
AccountMeta::new_readonly(ctx.remaining_accounts[11].key(), false),
]
};

let withdraw_ix = Instruction { program_id: ctx.accounts.base_program_id.key(), accounts: withdraw_accounts, data: input };

invoke(&withdraw_ix, ctx.remaining_accounts)?;

let deactivate_ix = stake::instruction::deactivate_stake(&ctx.remaining_accounts[1].key(), &ctx.remaining_accounts[6].key());
invoke(&deactivate_ix, &vec![ctx.remaining_accounts[1].clone()])?;

Ok(())
}
}

#[derive(Accounts)]
pub struct Action<'info> {
pub gateway_authority: Signer<'info>,
/// CHECK: Safe
pub gateway_state_info: AccountInfo<'info>,
/// CHECK: Safe
pub base_program_id: AccountInfo<'info>,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
pub struct DepositInputWrapper {
/// The instruction to deposit. Should always be 1.
pub instruction: u8,
/// Amount to deposit.
pub amount: u64,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)]
pub struct WithdrawInputWrapper {
/// The instuction to withdraw. This is either a 2 (for v1) or 23 (v2).
pub instruction: u8,
/// Amount to withdraw.
pub amount: u64,
/// Index of the Heaviest Validator. Unused in Lido v1.
pub validator_index: u32,
}
99 changes: 99 additions & 0 deletions target/idl/adapter_lido.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"version": "0.1.0",
"name": "adapter_lido",
"instructions": [
{
"name": "deposit",
"accounts": [
{
"name": "gatewayAuthority",
"isMut": false,
"isSigner": true
},
{
"name": "gatewayStateInfo",
"isMut": false,
"isSigner": false
},
{
"name": "baseProgramId",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "input",
"type": "bytes"
}
]
},
{
"name": "withdraw",
"accounts": [
{
"name": "gatewayAuthority",
"isMut": false,
"isSigner": true
},
{
"name": "gatewayStateInfo",
"isMut": false,
"isSigner": false
},
{
"name": "baseProgramId",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "input",
"type": "bytes"
}
]
}
],
"types": [
{
"name": "DepositInputWrapper",
"type": {
"kind": "struct",
"fields": [
{
"name": "instruction",
"type": "u8"
},
{
"name": "amount",
"type": "u64"
}
]
}
},
{
"name": "WithdrawInputWrapper",
"type": {
"kind": "struct",
"fields": [
{
"name": "instruction",
"type": "u8"
},
{
"name": "amount",
"type": "u64"
},
{
"name": "validatorIndex",
"type": "u32"
}
]
}
}
],
"metadata": {
"address": "4XnyVwkN5dR7Rinnys59qMqLjhxytpv4JbFLJuXe5mKk"
}
}
Loading