Skip to content

Commit

Permalink
chore: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Sep 25, 2024
2 parents 9a0ac37 + abec526 commit ecb70cc
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 381 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/node_modules
js/lib

cli/target
cli/target/.rustc_info.json
/node_modules

js/dist
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ The [Bonfida Token Vesting UI](https://vesting.bonfida.org) can be used to unloc
<h2 align="center">Structure</h2>
<br />

- `cli` : CLI tool to interact with on-chain token vesting contract
- `js` : JavaScript binding to interact with on-chain token vesting contract
- `program` : The BPF compatible token vesting on-chain program/smart contract

Expand Down
4 changes: 0 additions & 4 deletions js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ The code allows you to

- Create vesting instructions for any SPL token: `createCreateInstruction`
- Create unlock instructions: `createUnlockInstruction`
- Change the destination of the vested tokens: `createChangeDestinationInstruction`

(To import Solana accounts created with [Sollet](https://sollet.io) you can use `getAccountFromSeed`)

Expand All @@ -37,7 +36,4 @@ Fetching contract r2p2mLJvyrTzetxxsttQ54CS1m18zMgYqKSRzxP9WpE
✅ Successfully created unlocking instructions
🚚 Transaction signature: 2Vg3W1w8WBdRAWBEwFTn2BtMkKPD3Xor7SRvzC193UnsUnhmneUChPHe7vLF9Lfw9BKxWH5JbbJmnda4XztHMVHz
Fetching contract r2p2mLJvyrTzetxxsttQ54CS1m18zMgYqKSRzxP9WpE
✅ Successfully changed destination
🚚 Transaction signature: 4tgPgCdM5ubaSKNLKD1WrfAJPZgRajxRSnmcPkHcN1TCeCRmq3cUCYVdCzsYwr63JRf4D2K1UZnt8rwu2pkGxeYe
```
42 changes: 0 additions & 42 deletions js/src/instructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,45 +201,3 @@ export function createInitializeUnlockInstruction(
data,
});
}

export function createChangeDestinationInstruction(
vestingProgramId: PublicKey,
vestingAccountKey: PublicKey,
currentDestinationTokenAccountOwner: PublicKey,
currentDestinationTokenAccount: PublicKey,
targetDestinationTokenAccount: PublicKey,
seeds: Array<Buffer | Uint8Array>,
): TransactionInstruction {
const data = Buffer.concat([
Buffer.from(Int8Array.from([4]).buffer),
Buffer.concat(seeds),
]);

const keys = [
{
pubkey: vestingAccountKey,
isSigner: false,
isWritable: true,
},
{
pubkey: currentDestinationTokenAccount,
isSigner: false,
isWritable: false,
},
{
pubkey: currentDestinationTokenAccountOwner,
isSigner: true,
isWritable: false,
},
{
pubkey: targetDestinationTokenAccount,
isSigner: false,
isWritable: false,
},
];
return new TransactionInstruction({
keys,
programId: vestingProgramId,
data,
});
}
54 changes: 1 addition & 53 deletions js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getAssociatedTokenAddress,
} from '@solana/spl-token';
import {
createChangeDestinationInstruction,
createCreateInstruction,
createInitInstruction,
createUnlockInstruction,
Expand Down Expand Up @@ -229,55 +228,4 @@ export async function getContractInfo(
throw new Error('Vesting contract account is not initialized');
}
return info!;
}

/**
* This function can be used to transfer a vesting account to a new wallet. It requires the current owner to sign.
* @param connection The Solana RPC connection object
* @param programId The token vesting program ID
* @param currentDestinationTokenAccountPublicKey The current token account to which the vested tokens are transfered to as they unlock
* @param newDestinationTokenAccountOwner The new owner of the vesting account
* @param newDestinationTokenAccount The new token account to which the vested tokens will be transfered to as they unlock
* @param vestingSeed Seed words used to derive the vesting account
* @returns An array of `TransactionInstruction`
*/
export async function changeDestination(
connection: Connection,
programId: PublicKey,
currentDestinationTokenAccountPublicKey: PublicKey,
newDestinationTokenAccountOwner: PublicKey | undefined,
newDestinationTokenAccount: PublicKey | undefined,
vestingSeed: Array<Buffer | Uint8Array>,
): Promise<Array<TransactionInstruction>> {
let seedWord = vestingSeed[0];
seedWord = seedWord.slice(0, 31);
const [vestingAccountKey, bump] = await PublicKey.findProgramAddress(
[seedWord],
programId,
);
seedWord = Buffer.from(seedWord.toString('hex') + bump.toString(16), 'hex');

const contractInfo = await getContractInfo(connection, vestingAccountKey);
if (!newDestinationTokenAccount) {
assert(
!!newDestinationTokenAccountOwner,
'At least one of newDestinationTokenAccount and newDestinationTokenAccountOwner must be provided!',
);
newDestinationTokenAccount = await getAssociatedTokenAddress(
contractInfo.mintAddress,
newDestinationTokenAccountOwner!,
true,
);
}

return [
createChangeDestinationInstruction(
programId,
vestingAccountKey,
currentDestinationTokenAccountPublicKey,
contractInfo.destinationAddress,
newDestinationTokenAccount,
[seedWord],
),
];
}
}
73 changes: 1 addition & 72 deletions program/fuzz/src/vesting_fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_sdk::{signature::Keypair, signature::Signer, system_instruction, tran
use arbitrary::Arbitrary;
use std::collections::HashMap;
use token_vesting::{instruction::{Schedule, VestingInstruction}, processor::Processor};
use token_vesting::instruction::{init, unlock, change_destination, create};
use token_vesting::instruction::{init, unlock, create};
use solana_sdk::{account::Account, instruction::InstructionError, transaction::TransactionError};
struct TokenVestingEnv {
system_program_id: Pubkey,
Expand Down Expand Up @@ -327,59 +327,6 @@ fn run_fuzz_instruction(
clone_keypair(&token_vesting_testenv.mint_authority),
clone_keypair(source_token_account_owner_key),
]);
},

FuzzInstruction {
instruction: VestingInstruction::ChangeDestination{ .. },
..
} => {
let mut instructions_acc = vec![init(
&token_vesting_testenv.system_program_id,
&token_vesting_testenv.rent_program_id,
&token_vesting_testenv.vesting_program_id,
&correct_payer.pubkey(),
&correct_vesting_account_key,
correct_seeds,
fuzz_instruction.number_of_schedules as u32
).unwrap()];
let mut create_instructions = create_fuzzinstruction(
token_vesting_testenv,
fuzz_instruction,
correct_payer,
&correct_source_token_account_key,
source_token_account_owner_key,
destination_token_key,
&destination_token_owner_key.pubkey(),
&correct_vesting_account_key,
&correct_vesting_token_key,
correct_seeds,
mint_key,
fuzz_instruction.source_token_amount
);
instructions_acc.append(&mut create_instructions);

let new_destination_instruction = create_associated_token_account(
&correct_payer.pubkey(),
&Pubkey::new_unique(), // Arbitrary
&mint_key.pubkey()
);
instructions_acc.push(new_destination_instruction);

let change_instruction = change_destination(
&token_vesting_testenv.vesting_program_id,
&correct_vesting_account_key,
&destination_token_owner_key.pubkey(),
&destination_token_key,
new_destination_token_key,
correct_seeds
).unwrap();
instructions_acc.push(change_instruction);
return (instructions_acc, vec![
clone_keypair(mint_key),
clone_keypair(&token_vesting_testenv.mint_authority),
clone_keypair(source_token_account_owner_key),
clone_keypair(destination_token_owner_key),
]);
}
};

Expand Down Expand Up @@ -441,24 +388,6 @@ fn run_fuzz_instruction(
vec![unlock_instruction],
vec![]
);
},

FuzzInstruction {
instruction: VestingInstruction::ChangeDestination{ .. },
..
} => {
let change_instruction = change_destination(
&token_vesting_testenv.vesting_program_id,
vesting_account_key,
&destination_token_owner_key.pubkey(),
&destination_token_key,
new_destination_token_key,
fuzz_instruction.seeds,
).unwrap();
return (
vec![change_instruction],
vec![clone_keypair(destination_token_owner_key)]
);
}
};
}
Expand Down
Loading

0 comments on commit ecb70cc

Please sign in to comment.