Skip to content

Commit 56eb4c9

Browse files
authored
Fix vesting config initialization with pre-created vault ATA (#260)
1 parent e3d1ca1 commit 56eb4c9

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

solana/app/deploy/devnet/tests/getProgramIdBytes32Hex.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Usage: npx ts-node app/deploy/getProgramIdBytes32Hex.ts
1+
// Usage: npx ts-node app/deploy/devnet/tests/getProgramIdBytes32Hex.ts
22
// AFuHPdrQGsW8rNQ4oEFF35sm5fg36gwrxyqjkjKvi6ap
33

44
import { PublicKey } from "@solana/web3.js";

solana/programs/staking/src/contexts/initialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Initialize<'info> {
1515
mint: Account<'info, Mint>,
1616
// Initialize a vault for us to store our money in escrow for vesting
1717
#[account(
18-
init,
18+
init_if_needed,
1919
payer = admin,
2020
associated_token::mint = mint,
2121
associated_token::authority = config,

solana/tests/vesting.ts

+46
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {
1111
ASSOCIATED_TOKEN_PROGRAM_ID,
1212
createAssociatedTokenAccountIdempotentInstruction,
13+
createAssociatedTokenAccountInstruction,
1314
createInitializeMintInstruction,
1415
createMintToInstruction,
1516
createTransferCheckedInstruction,
@@ -77,12 +78,15 @@ describe("vesting", () => {
7778
const vesterWithoutAccount = Keypair.generate();
7879
const seed = new BN(randomBytes(8));
7980
const seed2 = new BN(randomBytes(8));
81+
const seed3 = new BN(randomBytes(8));
8082

8183
let accounts,
8284
config,
8385
config2,
86+
config3,
8487
vault,
8588
vault2,
89+
vault3,
8690
vesterTa,
8791
vester2Ta,
8892
vester3Ta,
@@ -161,6 +165,14 @@ describe("vesting", () => {
161165
],
162166
stakeConnection.program.programId,
163167
)[0];
168+
config3 = PublicKey.findProgramAddressSync(
169+
[
170+
Buffer.from(wasm.Constants.VESTING_CONFIG_SEED()),
171+
whMintAccount.publicKey.toBuffer(),
172+
seed3.toBuffer("le", 8),
173+
],
174+
stakeConnection.program.programId,
175+
)[0];
164176
vault = getAssociatedTokenAddressSync(
165177
whMintAccount.publicKey,
166178
config,
@@ -173,6 +185,12 @@ describe("vesting", () => {
173185
true,
174186
TOKEN_PROGRAM_ID,
175187
);
188+
vault3 = getAssociatedTokenAddressSync(
189+
whMintAccount.publicKey,
190+
config3,
191+
true,
192+
TOKEN_PROGRAM_ID,
193+
);
176194
vesterTa = getAssociatedTokenAddressSync(
177195
whMintAccount.publicKey,
178196
vester.publicKey,
@@ -670,6 +688,34 @@ describe("vesting", () => {
670688
}
671689
});
672690

691+
it("should successfully initialize vesting config if vault ATA is pre-created by another user", async () => {
692+
const tx = new Transaction();
693+
tx.add(
694+
createAssociatedTokenAccountInstruction(
695+
vester.publicKey, // payer
696+
vault3, // associatedToken
697+
config3, // owner
698+
whMintAccount.publicKey, // mint
699+
TOKEN_PROGRAM_ID,
700+
ASSOCIATED_TOKEN_PROGRAM_ID,
701+
),
702+
);
703+
await vesterStakeConnection.provider.sendAndConfirm(tx, [vester])
704+
.then(confirm);
705+
await sleep(1500);
706+
707+
await stakeConnection.program.methods
708+
.initializeVestingConfig(seed3)
709+
.accounts({
710+
...accounts,
711+
config: config3,
712+
vault: vault3,
713+
})
714+
.signers([whMintAuthority])
715+
.rpc()
716+
.then(confirm);
717+
});
718+
673719
it("Initialize config", async () => {
674720
await stakeConnection.program.methods
675721
.initializeVestingConfig(seed)

0 commit comments

Comments
 (0)