Skip to content
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

Nhan/revert burn rent #134

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clients/js/src/generated/instructions/burnV1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function burnV1(
},
authority: {
index: 3,
isWritable: true as boolean,
isWritable: false as boolean,
value: input.authority ?? null,
},
systemProgram: {
Expand Down
30 changes: 30 additions & 0 deletions clients/js/test/burn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,33 @@ test('it cannot burn an asset with the wrong collection specified', async (t) =>

await t.throwsAsync(result, { name: 'InvalidCollection' });
});

test('it can burn asset with different payer', async (t) => {
const umi = await createUmi();
const owner = await generateSignerWithSol(umi);
const asset = await createAsset(umi, {
owner: owner.publicKey,
});
await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: owner.publicKey,
updateAuthority: { type: 'Address', address: umi.identity.publicKey },
});

const lamportsBefore = await umi.rpc.getBalance(umi.identity.publicKey);

await burnV1(umi, {
asset: asset.publicKey,
payer: umi.identity,
authority: owner,
}).sendAndConfirm(umi);

// And the asset address still exists but was resized to 1.
const afterAsset = await assertBurned(t, umi, asset.publicKey);
t.deepEqual(afterAsset.lamports, sol(0.00089784 + 0.0015));

const lamportsAfter = await umi.rpc.getBalance(umi.identity.publicKey);

t.true(lamportsAfter.basisPoints > lamportsBefore.basisPoints);
});
8 changes: 4 additions & 4 deletions clients/rust/src/generated/instructions/burn_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl BurnV1 {
self.payer, true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authority, true,
));
} else {
Expand Down Expand Up @@ -129,7 +129,7 @@ pub struct BurnV1InstructionArgs {
/// 0. `[writable]` asset
/// 1. `[writable, optional]` collection
/// 2. `[writable, signer]` payer
/// 3. `[writable, signer, optional]` authority
/// 3. `[signer, optional]` authority
/// 4. `[optional]` system_program
/// 5. `[optional]` log_wrapper
#[derive(Default)]
Expand Down Expand Up @@ -343,7 +343,7 @@ impl<'a, 'b> BurnV1Cpi<'a, 'b> {
true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new(
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authority.key,
true,
));
Expand Down Expand Up @@ -426,7 +426,7 @@ impl<'a, 'b> BurnV1Cpi<'a, 'b> {
/// 0. `[writable]` asset
/// 1. `[writable, optional]` collection
/// 2. `[writable, signer]` payer
/// 3. `[writable, signer, optional]` authority
/// 3. `[signer, optional]` authority
/// 4. `[optional]` system_program
/// 5. `[optional]` log_wrapper
pub struct BurnV1CpiBuilder<'a, 'b> {
Expand Down
2 changes: 1 addition & 1 deletion idls/mpl_core.json
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@
},
{
"name": "authority",
"isMut": true,
"isMut": false,
"isSigner": true,
"isOptional": true,
"docs": [
Expand Down
2 changes: 1 addition & 1 deletion programs/mpl-core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub(crate) enum MplAssetInstruction {
#[account(0, writable, name="asset", desc = "The address of the asset")]
#[account(1, optional, writable, name="collection", desc = "The collection to which the asset belongs")]
#[account(2, writable, signer, name="payer", desc = "The account paying for the storage fees")]
#[account(3, optional, writable, signer, name="authority", desc = "The owner or delegate of the asset")]
#[account(3, optional, signer, name="authority", desc = "The owner or delegate of the asset")]
#[account(4, optional, name="system_program", desc = "The system program")]
#[account(5, optional, name="log_wrapper", desc = "The SPL Noop Program")]
BurnV1(BurnV1Args),
Expand Down
4 changes: 2 additions & 2 deletions programs/mpl-core/src/processor/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub(crate) fn burn<'a>(accounts: &'a [AccountInfo<'a>], args: BurnV1Args) -> Pro
Some(HookableLifecycleEvent::Burn),
)?;

process_burn(ctx.accounts.asset, authority)?;
process_burn(ctx.accounts.asset, ctx.accounts.payer)?;
if let Some(mut collection) = collection {
collection.decrement()?;
collection.save(ctx.accounts.collection.unwrap(), 0)?;
Expand Down Expand Up @@ -146,7 +146,7 @@ pub(crate) fn burn_collection<'a>(
Some(HookableLifecycleEvent::Burn),
)?;

process_burn(ctx.accounts.collection, authority)
process_burn(ctx.accounts.collection, ctx.accounts.payer)
}

fn process_burn<'a>(core_info: &AccountInfo<'a>, authority: &AccountInfo<'a>) -> ProgramResult {
Expand Down
Loading