-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add Lido as an Adapter #18
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
Open
alvinphilips
wants to merge
8
commits into
DappioLab:master
Choose a base branch
from
alvinphilips:feat-add-lido
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 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d8e90f
feat: Added Lido program
alvinphilips 2d93ec9
Deployed Lido Adapter
alvinphilips 28c1e8d
Merge branch 'DappioWonderland:master' into feat-add-lido
alvinphilips 2265f7f
Added Output Wrappers and cleaned up Deposit
alvinphilips ea19cb4
Updated Withdraw method with output struct
alvinphilips f0ee016
Removed v1 code
alvinphilips ece53de
Removed gateway state from Action
alvinphilips 44dd3a6
Added gateway key and switched to PDA
alvinphilips 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 hidden or 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 hidden or 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-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" |
This file contains hidden or 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 hidden or 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,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 { | ||
alvinphilips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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(()) | ||
alvinphilips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| #[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, | ||
alvinphilips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// 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, | ||
| } | ||
This file contains hidden or 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,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" | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.