From 65c1f4d5e67cc1a3fe065918671d60b4d8fe7877 Mon Sep 17 00:00:00 2001 From: Wei Date: Wed, 2 Nov 2022 22:53:29 +0000 Subject: [PATCH 01/17] add genopets staking adapter --- programs/adapter-genopets-staking/Cargo.toml | 22 ++ programs/adapter-genopets-staking/Xargo.toml | 2 + programs/adapter-genopets-staking/src/lib.rs | 288 +++++++++++++++++++ 3 files changed, 312 insertions(+) create mode 100644 programs/adapter-genopets-staking/Cargo.toml create mode 100644 programs/adapter-genopets-staking/Xargo.toml create mode 100644 programs/adapter-genopets-staking/src/lib.rs diff --git a/programs/adapter-genopets-staking/Cargo.toml b/programs/adapter-genopets-staking/Cargo.toml new file mode 100644 index 0000000..326a29b --- /dev/null +++ b/programs/adapter-genopets-staking/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "adapter-genopets-staking" +version = "0.1.0" +description = "Created with Anchor" +edition = "2021" + +[lib] +crate-type = ["cdylib", "lib"] +name = "adapter_genopets_staking" + +[features] +no-entrypoint = [] +no-idl = [] +no-log-ix-name = [] +cpi = ["no-entrypoint"] + +[profile.release] +overflow-checks = true + +[dependencies] +anchor-lang = {version = "0.24.2", features = [ "init-if-needed" ] } +anchor-spl = "0.24.2" \ No newline at end of file diff --git a/programs/adapter-genopets-staking/Xargo.toml b/programs/adapter-genopets-staking/Xargo.toml new file mode 100644 index 0000000..475fb71 --- /dev/null +++ b/programs/adapter-genopets-staking/Xargo.toml @@ -0,0 +1,2 @@ +[target.bpfel-unknown-unknown.dependencies.std] +features = [] diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs new file mode 100644 index 0000000..2403350 --- /dev/null +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -0,0 +1,288 @@ +use anchor_lang::prelude::*; +use anchor_lang::solana_program::{ + hash::hash, + instruction::{AccountMeta, Instruction}, + program::invoke, + pubkey::Pubkey, +}; +use anchor_spl::token::TokenAccount; +declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); + +#[program] +pub mod adapter_genopets_staking { + use super::*; + + pub fn stake<'a, 'b, 'c, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Action<'info>>, + input: Vec, + ) -> Result<()> { + // Get Input + let mut input_bytes = &input[..]; + let input_struct = StakeInputWrapper::deserialize(&mut input_bytes)?; + + let mut stake_data = sighash("global", "stake").to_vec(); + stake_data.append(&mut input_struct.amount.to_le_bytes().to_vec()); + stake_data.append(&mut input_struct.lock_for_months.to_le_bytes().to_vec()); + stake_data.append(&mut input_struct.as_sgene.try_to_vec()?); + + let stake_accounts = load_remaining_accounts( + ctx.remaining_accounts, + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + ); + + let mut stake_token_account_and_balance = + load_token_account_and_balance(ctx.remaining_accounts, 5); + + let stake_ix = Instruction { + program_id: ctx.accounts.base_program_id.key(), + accounts: stake_accounts, + data: stake_data, + }; + invoke(&stake_ix, ctx.remaining_accounts)?; + + // Wrap Output + let output_struct = StakeOutputWrapper { + token_in_amount: stake_token_account_and_balance.get_balance_change(), + ..Default::default() + }; + let mut output: Vec = Vec::new(); + output_struct.serialize(&mut output).unwrap(); + + // Return Result + anchor_lang::solana_program::program::set_return_data(&output); + + msg!("Output: {:?}", output_struct); + Ok(()) + } + pub fn unstake<'a, 'b, 'c, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Action<'info>>, + input: Vec, + ) -> Result<()> { + // Get Input + let mut input_bytes = &input[..]; + let input_struct = UnstakeInputWrapper::deserialize(&mut input_bytes)?; + + let mut unstake_data = vec![]; // Instruction data + let mut unstake_accout_index_array: Vec = vec![]; // Remaining accounts + let mut unstake_token_account_index: usize = 0; + if input_struct.as_sgene { + unstake_data = sighash("global", "withdraw_as_sgene").to_vec(); + unstake_accout_index_array = + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; + unstake_token_account_index = 4; + } else { + unstake_data = sighash("global", "withdraw").to_vec(); + unstake_data.push(0); // default False cuz it's deprecated + unstake_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + unstake_token_account_index = 5; + } + + let unstake_ix_accounts = + load_remaining_accounts(ctx.remaining_accounts, unstake_accout_index_array); + + let mut unstake_token_account_and_balance = + load_token_account_and_balance(ctx.remaining_accounts, unstake_token_account_index); + + let unstake_ix = Instruction { + program_id: ctx.accounts.base_program_id.key(), + accounts: unstake_ix_accounts, + data: unstake_data, + }; + invoke(&unstake_ix, ctx.remaining_accounts)?; + + // Wrap Output + let output_struct = UnstakeOutputWrapper { + token_out_amount: unstake_token_account_and_balance.get_balance_change(), + ..Default::default() + }; + let mut output: Vec = Vec::new(); + output_struct.serialize(&mut output).unwrap(); + + // Return Result + anchor_lang::solana_program::program::set_return_data(&output); + + msg!("Output: {:?}", output_struct); + + Ok(()) + } + pub fn harvest<'a, 'b, 'c, 'info>( + ctx: Context<'a, 'b, 'c, 'info, Action<'info>>, + input: Vec, + ) -> Result<()> { + // Get Input + let mut input_bytes = &input[..]; + let input_struct = HarvestInputWrapper::deserialize(&mut input_bytes)?; + + let harvest_data = sighash("global", "claim_rewards").to_vec(); + + let harvest_accounts = load_remaining_accounts( + ctx.remaining_accounts, + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + ); + + let harvest_ix = Instruction { + program_id: ctx.accounts.base_program_id.key(), + accounts: harvest_accounts, + data: harvest_data, + }; + invoke(&harvest_ix, ctx.remaining_accounts)?; + + // Wrap Output + let output_struct = HarvestOutputWrapper { + ..Default::default() + }; + let mut output: Vec = Vec::new(); + output_struct.serialize(&mut output).unwrap(); + + // Return Result + anchor_lang::solana_program::program::set_return_data(&output); + + msg!("Output: {:?}", output_struct); + 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 StakeInputWrapper { + pub amount: u64, + pub lock_for_months: u8, + pub as_sgene: bool, +} + +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] +pub struct StakeOutputWrapper { + pub token_in_amount: u64, + pub dummy_2: u64, + pub dummy_3: u64, + pub dummy_4: u64, +} +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] +pub struct UnstakeInputWrapper { + pub as_sgene: bool, +} +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] +pub struct UnstakeOutputWrapper { + pub token_out_amount: u64, + pub dummy_2: u64, + pub dummy_3: u64, + pub dummy_4: u64, +} + +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] +pub struct HarvestInputWrapper {} +#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] +pub struct HarvestOutputWrapper { + pub dummy_1: u64, + pub dummy_2: u64, + pub dummy_3: u64, + pub dummy_4: u64, +} + +pub type StakeOutputTuple = (u64, u64, u64, u64); +pub type UnstakeOutputTuple = (u64, u64, u64, u64); +pub type HarvestOutputTuple = (u64, u64, u64, u64); + +impl From for StakeOutputTuple { + fn from(result: StakeOutputWrapper) -> StakeOutputTuple { + let StakeOutputWrapper { + token_in_amount, + dummy_2, + dummy_3, + dummy_4, + } = result; + (token_in_amount, dummy_2, dummy_3, dummy_4) + } +} + +impl From for UnstakeOutputTuple { + fn from(result: UnstakeOutputWrapper) -> UnstakeOutputTuple { + let UnstakeOutputWrapper { + token_out_amount, + dummy_2, + dummy_3, + dummy_4, + } = result; + (token_out_amount, dummy_2, dummy_3, dummy_4) + } +} +impl From for HarvestOutputTuple { + fn from(result: HarvestOutputWrapper) -> HarvestOutputTuple { + let HarvestOutputWrapper { + dummy_1, + dummy_2, + dummy_3, + dummy_4, + } = result; + (dummy_1, dummy_2, dummy_3, dummy_4) + } +} + +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 +} + +pub fn load_token_account_and_balance<'info>( + remaining_accounts: &[AccountInfo<'info>], + account_index: usize, +) -> TokenAccountAndBalance<'info> { + let token_account_info = &remaining_accounts[account_index]; + let token_account = Account::::try_from(token_account_info).unwrap(); + let balance_before = token_account.amount.clone(); + return TokenAccountAndBalance { + token_accout: token_account, + balance_before: balance_before, + }; +} + +pub struct TokenAccountAndBalance<'info> { + token_accout: Account<'info, TokenAccount>, + balance_before: u64, +} + +impl<'info> TokenAccountAndBalance<'info> { + pub fn get_balance_change(&mut self) -> u64 { + self.token_accout.reload().unwrap(); + let balance_before = self.balance_before; + let balance_after = self.token_accout.amount; + if balance_after > balance_before { + balance_after.checked_sub(balance_before).unwrap() + } else if balance_after == balance_before { + 0_u64 + } else { + balance_before.checked_sub(balance_after).unwrap() + } + } +} + +pub fn load_remaining_accounts<'info>( + remaining_accounts: &[AccountInfo<'info>], + index_array: Vec, +) -> Vec { + let mut accounts: Vec = vec![]; + for index in index_array.iter() { + if remaining_accounts[*index].is_writable { + accounts.push(AccountMeta::new( + remaining_accounts[*index].key(), + remaining_accounts[*index].is_signer, + )) + } else { + accounts.push(AccountMeta::new_readonly( + remaining_accounts[*index].key(), + remaining_accounts[*index].is_signer, + )) + } + } + return accounts; +} From 8746613bee3c00c3129de772a1a68e386ee62967 Mon Sep 17 00:00:00 2001 From: Wei Date: Wed, 2 Nov 2022 22:54:40 +0000 Subject: [PATCH 02/17] update IDL --- target/idl/adapter_genopets_staking.json | 197 +++++++++++ target/types/adapter_genopets_staking.ts | 395 +++++++++++++++++++++++ 2 files changed, 592 insertions(+) create mode 100644 target/idl/adapter_genopets_staking.json create mode 100644 target/types/adapter_genopets_staking.ts diff --git a/target/idl/adapter_genopets_staking.json b/target/idl/adapter_genopets_staking.json new file mode 100644 index 0000000..911cc10 --- /dev/null +++ b/target/idl/adapter_genopets_staking.json @@ -0,0 +1,197 @@ +{ + "version": "0.1.0", + "name": "adapter_genopets_staking", + "instructions": [ + { + "name": "stake", + "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": "unstake", + "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": "harvest", + "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": "StakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "lockForMonths", + "type": "u8" + }, + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "StakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenInAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "UnstakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "UnstakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenOutAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "HarvestInputWrapper", + "type": { + "kind": "struct", + "fields": [] + } + }, + { + "name": "HarvestOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "dummy1", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + } + ] +} \ No newline at end of file diff --git a/target/types/adapter_genopets_staking.ts b/target/types/adapter_genopets_staking.ts new file mode 100644 index 0000000..a7c41c6 --- /dev/null +++ b/target/types/adapter_genopets_staking.ts @@ -0,0 +1,395 @@ +export type AdapterGenopetsStaking = { + "version": "0.1.0", + "name": "adapter_genopets_staking", + "instructions": [ + { + "name": "stake", + "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": "unstake", + "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": "harvest", + "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": "StakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "lockForMonths", + "type": "u8" + }, + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "StakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenInAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "UnstakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "UnstakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenOutAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "HarvestInputWrapper", + "type": { + "kind": "struct", + "fields": [] + } + }, + { + "name": "HarvestOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "dummy1", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + } + ] +}; + +export const IDL: AdapterGenopetsStaking = { + "version": "0.1.0", + "name": "adapter_genopets_staking", + "instructions": [ + { + "name": "stake", + "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": "unstake", + "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": "harvest", + "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": "StakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "lockForMonths", + "type": "u8" + }, + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "StakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenInAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "UnstakeInputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] + } + }, + { + "name": "UnstakeOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "tokenOutAmount", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + }, + { + "name": "HarvestInputWrapper", + "type": { + "kind": "struct", + "fields": [] + } + }, + { + "name": "HarvestOutputWrapper", + "type": { + "kind": "struct", + "fields": [ + { + "name": "dummy1", + "type": "u64" + }, + { + "name": "dummy2", + "type": "u64" + }, + { + "name": "dummy3", + "type": "u64" + }, + { + "name": "dummy4", + "type": "u64" + } + ] + } + } + ] +}; From 9b44f8ab8d77ca059570bf4d2b7e1fd411afb9ba Mon Sep 17 00:00:00 2001 From: Wei Date: Wed, 2 Nov 2022 22:54:54 +0000 Subject: [PATCH 03/17] update cargo lock file --- Cargo.lock | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c643f19..26ca50e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,14 @@ dependencies = [ "anchor-spl", ] +[[package]] +name = "adapter-genopets-staking" +version = "0.1.0" +dependencies = [ + "anchor-lang", + "anchor-spl", +] + [[package]] name = "adapter-katana" version = "0.1.0" From 70ff33e51ba41424a597bcc5b844f14c5654fc39 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 00:01:19 +0000 Subject: [PATCH 04/17] update id --- programs/adapter-genopets-staking/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 2403350..3371e2a 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -6,7 +6,7 @@ use anchor_lang::solana_program::{ pubkey::Pubkey, }; use anchor_spl::token::TokenAccount; -declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"); +declare_id!("ADPTR3wPKDCZ8HNBBpY3GGXB8hu6DZDqyPJMimyHjKNk"); #[program] pub mod adapter_genopets_staking { From e3b510ced1a5463a5bbdd0648bd61ded30a12c32 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 00:11:17 +0000 Subject: [PATCH 05/17] v0.2.1-test.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce4c4d1..3c570c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dappio-wonderland/adapter-idls", - "version": "0.2.1", + "version": "0.2.1-test.1", "description": "Dappio Adapter IDLs: The IDL files of Dappio Adapters", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", From 08c70dbe1bdc0f5c128c5a753431dedddf06d844 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 01:44:44 +0000 Subject: [PATCH 06/17] bug fix --- programs/adapter-genopets-staking/src/lib.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 3371e2a..a2bbd2a 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -63,17 +63,18 @@ pub mod adapter_genopets_staking { let input_struct = UnstakeInputWrapper::deserialize(&mut input_bytes)?; let mut unstake_data = vec![]; // Instruction data - let mut unstake_accout_index_array: Vec = vec![]; // Remaining accounts + let mut unstake_accout_index_array: Vec = vec![]; // Remaining accounts let mut unstake_token_account_index: usize = 0; if input_struct.as_sgene { unstake_data = sighash("global", "withdraw_as_sgene").to_vec(); - unstake_accout_index_array = - vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; + unstake_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + unstake_token_account_index = 4; } else { unstake_data = sighash("global", "withdraw").to_vec(); unstake_data.push(0); // default False cuz it's deprecated - unstake_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + unstake_accout_index_array = + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; unstake_token_account_index = 5; } @@ -113,8 +114,8 @@ pub mod adapter_genopets_staking { let mut input_bytes = &input[..]; let input_struct = HarvestInputWrapper::deserialize(&mut input_bytes)?; - let harvest_data = sighash("global", "claim_rewards").to_vec(); - + let mut harvest_data = sighash("global", "claim_rewards").to_vec(); + harvest_data.push(0); let harvest_accounts = load_remaining_accounts( ctx.remaining_accounts, vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], From 2d14b9b94bfb80bd518df97f4e230891dce89ae3 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 12:06:42 +0000 Subject: [PATCH 07/17] change withdraw, harvest ix --- programs/adapter-genopets-staking/src/lib.rs | 69 +++++++++++--------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index a2bbd2a..0047c7e 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -62,27 +62,16 @@ pub mod adapter_genopets_staking { let mut input_bytes = &input[..]; let input_struct = UnstakeInputWrapper::deserialize(&mut input_bytes)?; - let mut unstake_data = vec![]; // Instruction data - let mut unstake_accout_index_array: Vec = vec![]; // Remaining accounts - let mut unstake_token_account_index: usize = 0; - if input_struct.as_sgene { - unstake_data = sighash("global", "withdraw_as_sgene").to_vec(); - unstake_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - - unstake_token_account_index = 4; - } else { - unstake_data = sighash("global", "withdraw").to_vec(); - unstake_data.push(0); // default False cuz it's deprecated - unstake_accout_index_array = - vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; - unstake_token_account_index = 5; - } + let mut unstake_data = sighash("global", "withdraw").to_vec(); // Instruction data + unstake_data.push(0); // default False cuz it's deprecated + let unstake_accout_index_array: Vec = + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; // Remaining accounts let unstake_ix_accounts = load_remaining_accounts(ctx.remaining_accounts, unstake_accout_index_array); let mut unstake_token_account_and_balance = - load_token_account_and_balance(ctx.remaining_accounts, unstake_token_account_index); + load_token_account_and_balance(ctx.remaining_accounts, 5); let unstake_ix = Instruction { program_id: ctx.accounts.base_program_id.key(), @@ -114,22 +103,42 @@ pub mod adapter_genopets_staking { let mut input_bytes = &input[..]; let input_struct = HarvestInputWrapper::deserialize(&mut input_bytes)?; - let mut harvest_data = sighash("global", "claim_rewards").to_vec(); - harvest_data.push(0); - let harvest_accounts = load_remaining_accounts( - ctx.remaining_accounts, - vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - ); + let mut harvest_data = vec![]; // Instruction data + let mut harvest_accout_index_array: Vec = vec![]; // Remaining accounts + let mut harvest_token_account_index: usize = 0; + if input_struct.as_sgene { + harvest_data = sighash("global", "withdraw_as_sgene").to_vec(); + harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + harvest_token_account_index = 4; + } else if ctx.remaining_accounts.len() == 18 { + harvest_data = sighash("global", "withdraw").to_vec(); + harvest_data.push(0); // default False cuz it's deprecated + harvest_accout_index_array = + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; + harvest_token_account_index = 5; + } else { + harvest_data = sighash("global", "claim_rewards").to_vec(); + harvest_data.push(0); // default False cuz it's deprecated + harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + harvest_token_account_index = 5; + } + + let harvest_ix_accounts = + load_remaining_accounts(ctx.remaining_accounts, harvest_accout_index_array); + + let mut harvest_token_account_and_balance = + load_token_account_and_balance(ctx.remaining_accounts, harvest_token_account_index); let harvest_ix = Instruction { program_id: ctx.accounts.base_program_id.key(), - accounts: harvest_accounts, + accounts: harvest_ix_accounts, data: harvest_data, }; invoke(&harvest_ix, ctx.remaining_accounts)?; // Wrap Output let output_struct = HarvestOutputWrapper { + reward_amount: harvest_token_account_and_balance.get_balance_change(), ..Default::default() }; let mut output: Vec = Vec::new(); @@ -166,9 +175,7 @@ pub struct StakeOutputWrapper { pub dummy_4: u64, } #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] -pub struct UnstakeInputWrapper { - pub as_sgene: bool, -} +pub struct UnstakeInputWrapper {} #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct UnstakeOutputWrapper { pub token_out_amount: u64, @@ -178,10 +185,12 @@ pub struct UnstakeOutputWrapper { } #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] -pub struct HarvestInputWrapper {} +pub struct HarvestInputWrapper { + pub as_sgene: bool, +} #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct HarvestOutputWrapper { - pub dummy_1: u64, + pub reward_amount: u64, pub dummy_2: u64, pub dummy_3: u64, pub dummy_4: u64, @@ -217,12 +226,12 @@ impl From for UnstakeOutputTuple { impl From for HarvestOutputTuple { fn from(result: HarvestOutputWrapper) -> HarvestOutputTuple { let HarvestOutputWrapper { - dummy_1, + reward_amount, dummy_2, dummy_3, dummy_4, } = result; - (dummy_1, dummy_2, dummy_3, dummy_4) + (reward_amount, dummy_2, dummy_3, dummy_4) } } From 02decb46aa59fd7ac1d8b3a115725c72b01833c3 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 12:07:05 +0000 Subject: [PATCH 08/17] update IDL --- target/idl/adapter_genopets_staking.json | 16 ++++++------ target/types/adapter_genopets_staking.ts | 32 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/target/idl/adapter_genopets_staking.json b/target/idl/adapter_genopets_staking.json index 911cc10..c23c4d0 100644 --- a/target/idl/adapter_genopets_staking.json +++ b/target/idl/adapter_genopets_staking.json @@ -130,12 +130,7 @@ "name": "UnstakeInputWrapper", "type": { "kind": "struct", - "fields": [ - { - "name": "asSgene", - "type": "bool" - } - ] + "fields": [] } }, { @@ -166,7 +161,12 @@ "name": "HarvestInputWrapper", "type": { "kind": "struct", - "fields": [] + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] } }, { @@ -175,7 +175,7 @@ "kind": "struct", "fields": [ { - "name": "dummy1", + "name": "rewardAmount", "type": "u64" }, { diff --git a/target/types/adapter_genopets_staking.ts b/target/types/adapter_genopets_staking.ts index a7c41c6..eb979fe 100644 --- a/target/types/adapter_genopets_staking.ts +++ b/target/types/adapter_genopets_staking.ts @@ -130,12 +130,7 @@ export type AdapterGenopetsStaking = { "name": "UnstakeInputWrapper", "type": { "kind": "struct", - "fields": [ - { - "name": "asSgene", - "type": "bool" - } - ] + "fields": [] } }, { @@ -166,7 +161,12 @@ export type AdapterGenopetsStaking = { "name": "HarvestInputWrapper", "type": { "kind": "struct", - "fields": [] + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] } }, { @@ -175,7 +175,7 @@ export type AdapterGenopetsStaking = { "kind": "struct", "fields": [ { - "name": "dummy1", + "name": "rewardAmount", "type": "u64" }, { @@ -328,12 +328,7 @@ export const IDL: AdapterGenopetsStaking = { "name": "UnstakeInputWrapper", "type": { "kind": "struct", - "fields": [ - { - "name": "asSgene", - "type": "bool" - } - ] + "fields": [] } }, { @@ -364,7 +359,12 @@ export const IDL: AdapterGenopetsStaking = { "name": "HarvestInputWrapper", "type": { "kind": "struct", - "fields": [] + "fields": [ + { + "name": "asSgene", + "type": "bool" + } + ] } }, { @@ -373,7 +373,7 @@ export const IDL: AdapterGenopetsStaking = { "kind": "struct", "fields": [ { - "name": "dummy1", + "name": "rewardAmount", "type": "u64" }, { From 56af427434848e5fcba2b88245cc8972a0e4fb79 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 12:08:08 +0000 Subject: [PATCH 09/17] v0.2.1-test.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c570c4..a441fba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dappio-wonderland/adapter-idls", - "version": "0.2.1-test.1", + "version": "0.2.1-test.2", "description": "Dappio Adapter IDLs: The IDL files of Dappio Adapters", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", From a8f46328fe3c2975f7ece35eae6ecb134db201a0 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 18:04:28 +0000 Subject: [PATCH 10/17] remove gateway state --- programs/adapter-genopets-staking/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 0047c7e..82060e6 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -155,8 +155,6 @@ pub mod adapter_genopets_staking { 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>, } From ec8856843a3936b4f6c4e8ed7dbb5cd730ddc864 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 20:45:32 +0000 Subject: [PATCH 11/17] add blank line --- programs/adapter-genopets-staking/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/adapter-genopets-staking/Cargo.toml b/programs/adapter-genopets-staking/Cargo.toml index 326a29b..fa03d4f 100644 --- a/programs/adapter-genopets-staking/Cargo.toml +++ b/programs/adapter-genopets-staking/Cargo.toml @@ -19,4 +19,4 @@ overflow-checks = true [dependencies] anchor-lang = {version = "0.24.2", features = [ "init-if-needed" ] } -anchor-spl = "0.24.2" \ No newline at end of file +anchor-spl = "0.24.2" From b795d6c34f6c0982844e180ad3fe28684336c030 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 20:56:56 +0000 Subject: [PATCH 12/17] remove deprecated input --- programs/adapter-genopets-staking/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 82060e6..23b2a83 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -23,7 +23,7 @@ pub mod adapter_genopets_staking { let mut stake_data = sighash("global", "stake").to_vec(); stake_data.append(&mut input_struct.amount.to_le_bytes().to_vec()); stake_data.append(&mut input_struct.lock_for_months.to_le_bytes().to_vec()); - stake_data.append(&mut input_struct.as_sgene.try_to_vec()?); + stake_data.push(0); // default False cuz it's deprecated let stake_accounts = load_remaining_accounts( ctx.remaining_accounts, @@ -162,7 +162,6 @@ pub struct Action<'info> { pub struct StakeInputWrapper { pub amount: u64, pub lock_for_months: u8, - pub as_sgene: bool, } #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] From 789056692e358bd5c91bbceae323de021db7f2ec Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 21:05:29 +0000 Subject: [PATCH 13/17] change harvest type matching --- programs/adapter-genopets-staking/src/lib.rs | 46 ++++++++++++-------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 23b2a83..a54dbd3 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -106,21 +106,27 @@ pub mod adapter_genopets_staking { let mut harvest_data = vec![]; // Instruction data let mut harvest_accout_index_array: Vec = vec![]; // Remaining accounts let mut harvest_token_account_index: usize = 0; - if input_struct.as_sgene { - harvest_data = sighash("global", "withdraw_as_sgene").to_vec(); - harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - harvest_token_account_index = 4; - } else if ctx.remaining_accounts.len() == 18 { - harvest_data = sighash("global", "withdraw").to_vec(); - harvest_data.push(0); // default False cuz it's deprecated - harvest_accout_index_array = - vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; - harvest_token_account_index = 5; - } else { - harvest_data = sighash("global", "claim_rewards").to_vec(); - harvest_data.push(0); // default False cuz it's deprecated - harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - harvest_token_account_index = 5; + match input_struct.harvest_type { + 0 => { + harvest_data = sighash("global", "claim_rewards").to_vec(); + harvest_data.push(0); // default False cuz it's deprecated + harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + harvest_token_account_index = 5; + } + 1 => { + harvest_data = sighash("global", "withdraw").to_vec(); + harvest_data.push(0); // default False cuz it's deprecated + harvest_accout_index_array = + vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; + harvest_token_account_index = 5; + } + 2 => { + harvest_data = sighash("global", "withdraw_as_sgene").to_vec(); + harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + harvest_token_account_index = 4; + } + + _ => return Err(ErrorCode::UnsupportedAction.into()), } let harvest_ix_accounts = @@ -157,7 +163,13 @@ pub struct Action<'info> { /// CHECK: Safe pub base_program_id: AccountInfo<'info>, } - +#[error_code] +pub enum ErrorCode { + #[msg("Unsupported PoolDirection")] + UnsupportedPoolDirection, + #[msg("Unsupported Action")] + UnsupportedAction, +} #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct StakeInputWrapper { pub amount: u64, @@ -183,7 +195,7 @@ pub struct UnstakeOutputWrapper { #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct HarvestInputWrapper { - pub as_sgene: bool, + pub harvest_type: u8, } #[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Default)] pub struct HarvestOutputWrapper { From 1325eda6dc021cf371977c7ddda83c69d3a2bcf2 Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 21:18:01 +0000 Subject: [PATCH 14/17] update IDL --- target/idl/adapter_genopets_staking.json | 19 ------------ target/types/adapter_genopets_staking.ts | 38 ------------------------ 2 files changed, 57 deletions(-) diff --git a/target/idl/adapter_genopets_staking.json b/target/idl/adapter_genopets_staking.json index c23c4d0..c2f4371 100644 --- a/target/idl/adapter_genopets_staking.json +++ b/target/idl/adapter_genopets_staking.json @@ -10,11 +10,6 @@ "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -36,11 +31,6 @@ "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -62,11 +52,6 @@ "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -94,10 +79,6 @@ { "name": "lockForMonths", "type": "u8" - }, - { - "name": "asSgene", - "type": "bool" } ] } diff --git a/target/types/adapter_genopets_staking.ts b/target/types/adapter_genopets_staking.ts index eb979fe..c49460c 100644 --- a/target/types/adapter_genopets_staking.ts +++ b/target/types/adapter_genopets_staking.ts @@ -10,11 +10,6 @@ export type AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -36,11 +31,6 @@ export type AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -62,11 +52,6 @@ export type AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -94,10 +79,6 @@ export type AdapterGenopetsStaking = { { "name": "lockForMonths", "type": "u8" - }, - { - "name": "asSgene", - "type": "bool" } ] } @@ -208,11 +189,6 @@ export const IDL: AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -234,11 +210,6 @@ export const IDL: AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -260,11 +231,6 @@ export const IDL: AdapterGenopetsStaking = { "isMut": false, "isSigner": true }, - { - "name": "gatewayStateInfo", - "isMut": false, - "isSigner": false - }, { "name": "baseProgramId", "isMut": false, @@ -292,10 +258,6 @@ export const IDL: AdapterGenopetsStaking = { { "name": "lockForMonths", "type": "u8" - }, - { - "name": "asSgene", - "type": "bool" } ] } From f921a9850e6224865fa8d888d710c5c39ce3a01d Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 21:25:19 +0000 Subject: [PATCH 15/17] add comments --- programs/adapter-genopets-staking/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index a54dbd3..45fdc91 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -107,12 +107,15 @@ pub mod adapter_genopets_staking { let mut harvest_accout_index_array: Vec = vec![]; // Remaining accounts let mut harvest_token_account_index: usize = 0; match input_struct.harvest_type { + // the type index is to dispatch different type of harvest + // 0 is for claim rewards 0 => { harvest_data = sighash("global", "claim_rewards").to_vec(); harvest_data.push(0); // default False cuz it's deprecated harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; harvest_token_account_index = 5; } + // 0 is for withdraw rewards after the lockup period 1 => { harvest_data = sighash("global", "withdraw").to_vec(); harvest_data.push(0); // default False cuz it's deprecated @@ -120,6 +123,7 @@ pub mod adapter_genopets_staking { vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; harvest_token_account_index = 5; } + // 0 is for withdraw rewards as sGENE token during the lockup period 2 => { harvest_data = sighash("global", "withdraw_as_sgene").to_vec(); harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; From 41e51b932515e759c11c2554bd1722da635f918e Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 21:30:51 +0000 Subject: [PATCH 16/17] update comment --- programs/adapter-genopets-staking/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/adapter-genopets-staking/src/lib.rs b/programs/adapter-genopets-staking/src/lib.rs index 45fdc91..84b24fe 100644 --- a/programs/adapter-genopets-staking/src/lib.rs +++ b/programs/adapter-genopets-staking/src/lib.rs @@ -108,14 +108,14 @@ pub mod adapter_genopets_staking { let mut harvest_token_account_index: usize = 0; match input_struct.harvest_type { // the type index is to dispatch different type of harvest - // 0 is for claim rewards + // 0 is for initialize 0 => { harvest_data = sighash("global", "claim_rewards").to_vec(); harvest_data.push(0); // default False cuz it's deprecated harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; harvest_token_account_index = 5; } - // 0 is for withdraw rewards after the lockup period + // 1 is for completeAsGene 1 => { harvest_data = sighash("global", "withdraw").to_vec(); harvest_data.push(0); // default False cuz it's deprecated @@ -123,7 +123,7 @@ pub mod adapter_genopets_staking { vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]; harvest_token_account_index = 5; } - // 0 is for withdraw rewards as sGENE token during the lockup period + // 2 is for completeAsSGene 2 => { harvest_data = sighash("global", "withdraw_as_sgene").to_vec(); harvest_accout_index_array = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; From f94e236aebd7f18a789df90124d1a8025a98bcaf Mon Sep 17 00:00:00 2001 From: Wei Date: Thu, 3 Nov 2022 21:44:04 +0000 Subject: [PATCH 17/17] update IDL --- target/idl/adapter_genopets_staking.json | 16 ++++++++++-- target/types/adapter_genopets_staking.ts | 32 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/target/idl/adapter_genopets_staking.json b/target/idl/adapter_genopets_staking.json index c2f4371..95d0442 100644 --- a/target/idl/adapter_genopets_staking.json +++ b/target/idl/adapter_genopets_staking.json @@ -144,8 +144,8 @@ "kind": "struct", "fields": [ { - "name": "asSgene", - "type": "bool" + "name": "harvestType", + "type": "u8" } ] } @@ -174,5 +174,17 @@ ] } } + ], + "errors": [ + { + "code": 6000, + "name": "UnsupportedPoolDirection", + "msg": "Unsupported PoolDirection" + }, + { + "code": 6001, + "name": "UnsupportedAction", + "msg": "Unsupported Action" + } ] } \ No newline at end of file diff --git a/target/types/adapter_genopets_staking.ts b/target/types/adapter_genopets_staking.ts index c49460c..fcc1ace 100644 --- a/target/types/adapter_genopets_staking.ts +++ b/target/types/adapter_genopets_staking.ts @@ -144,8 +144,8 @@ export type AdapterGenopetsStaking = { "kind": "struct", "fields": [ { - "name": "asSgene", - "type": "bool" + "name": "harvestType", + "type": "u8" } ] } @@ -174,6 +174,18 @@ export type AdapterGenopetsStaking = { ] } } + ], + "errors": [ + { + "code": 6000, + "name": "UnsupportedPoolDirection", + "msg": "Unsupported PoolDirection" + }, + { + "code": 6001, + "name": "UnsupportedAction", + "msg": "Unsupported Action" + } ] }; @@ -323,8 +335,8 @@ export const IDL: AdapterGenopetsStaking = { "kind": "struct", "fields": [ { - "name": "asSgene", - "type": "bool" + "name": "harvestType", + "type": "u8" } ] } @@ -353,5 +365,17 @@ export const IDL: AdapterGenopetsStaking = { ] } } + ], + "errors": [ + { + "code": 6000, + "name": "UnsupportedPoolDirection", + "msg": "Unsupported PoolDirection" + }, + { + "code": 6001, + "name": "UnsupportedAction", + "msg": "Unsupported Action" + } ] };