Skip to content

Commit 334a04b

Browse files
fix: burn folio tokens when user pending basket does not exist (#115)
1 parent 9f3f13a commit 334a04b

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

programs/folio/src/instructions/user/redeem_folio/burn_folio_token.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use shared::{check_condition, constants::PendingBasketType};
3030
/// * `user_folio_token_account` - The user folio token account (PDA) (mut, not signer).
3131
#[derive(Accounts)]
3232
pub struct BurnFolioToken<'info> {
33+
pub system_program: Program<'info, System>,
3334
pub token_program: Interface<'info, TokenInterface>,
3435
pub associated_token_program: Program<'info, AssociatedToken>,
3536

@@ -63,7 +64,9 @@ pub struct BurnFolioToken<'info> {
6364
)]
6465
pub folio_basket: AccountLoader<'info, FolioBasket>,
6566

66-
#[account(mut,
67+
#[account(init_if_needed,
68+
payer = user,
69+
space = UserPendingBasket::SIZE,
6770
seeds = [USER_PENDING_BASKET_SEEDS, folio.key().as_ref(), user.key().as_ref()],
6871
bump
6972
)]

tests-ts/bankrun/tests/tests-folio-redeeming.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ describe("Bankrun - Folio redeeming", () => {
121121
expectedFolioTokenBalanceChange: BN;
122122
expectedTokenBalanceChanges: BN[];
123123
minimumOutForTokenAmounts: { mint: PublicKey; minimumOut: BN }[];
124+
user_pending_basket_not_initalized: boolean;
124125
} = {
125126
alreadyIncludedTokens: [],
126127
tokens: [],
@@ -140,6 +141,7 @@ describe("Bankrun - Folio redeeming", () => {
140141
expectedFolioTokenBalanceChange: new BN(0),
141142
expectedTokenBalanceChanges: Array(MINTS.length).fill(new BN(0)),
142143
minimumOutForTokenAmounts: [],
144+
user_pending_basket_not_initalized: false,
143145
};
144146

145147
const TEST_CASES_BURN_FOLIO_TOKEN = [
@@ -261,6 +263,28 @@ describe("Bankrun - Folio redeeming", () => {
261263
new BN(1_000_000_000),
262264
],
263265
},
266+
267+
{
268+
desc: "(users burns max amount of shares, even when his alreadyIncludedTokens is empty)",
269+
expectedError: null,
270+
folioBasketTokens: [
271+
new FolioTokenAmount(MINTS[0].publicKey, new BN(1_000).mul(D9)),
272+
new FolioTokenAmount(MINTS[1].publicKey, new BN(1_000).mul(D9)),
273+
],
274+
alreadyIncludedTokens: [],
275+
user_pending_basket_not_initalized: true,
276+
tokens: [
277+
{ mint: MINTS[0].publicKey, amount: new BN(0) },
278+
{ mint: MINTS[1].publicKey, amount: new BN(0) },
279+
],
280+
initialUserShares: new BN(1_000_000_000),
281+
shares: new BN(1_000_000_000),
282+
expectedFolioTokenBalanceChange: new BN(1_000_000_000),
283+
expectedTokenBalanceChanges: [
284+
new BN(1_000_000_000),
285+
new BN(1_000_000_000),
286+
],
287+
},
264288
];
265289

266290
const TEST_CASES_REDEEM_FROM_PENDING_BASKET = [
@@ -551,6 +575,7 @@ describe("Bankrun - Folio redeeming", () => {
551575
customFolioTokenMint,
552576
customFolioFeeConfig,
553577
minimumOutForTokenAmounts,
578+
user_pending_basket_not_initalized,
554579
} = {
555580
...DEFAULT_PARAMS,
556581
...restOfParams,
@@ -575,13 +600,15 @@ describe("Bankrun - Folio redeeming", () => {
575600
customFolioFeeConfig
576601
);
577602

578-
await createAndSetUserPendingBasket(
579-
context,
580-
programFolio,
581-
folioPDA,
582-
userKeypair.publicKey,
583-
alreadyIncludedTokens
584-
);
603+
if (!user_pending_basket_not_initalized) {
604+
await createAndSetUserPendingBasket(
605+
context,
606+
programFolio,
607+
folioPDA,
608+
userKeypair.publicKey,
609+
alreadyIncludedTokens
610+
);
611+
}
585612

586613
await travelFutureSlot(context);
587614

0 commit comments

Comments
 (0)