-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#629): Add configurable destination for lazy distributor
- Loading branch information
1 parent
c1704f4
commit 7490d2a
Showing
20 changed files
with
445 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/lazy-distributor-sdk/src/functions/updateCompressionDestination.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Idl, Program } from "@coral-xyz/anchor"; | ||
import { LazyDistributor } from "@helium/idls/lib/types/lazy_distributor"; | ||
import { Asset, AssetProof, proofArgsAndAccounts } from "@helium/spl-utils"; | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { recipientKey } from "../pdas"; | ||
|
||
export async function updateCompressionDestination<IDL extends Idl>({ | ||
program, | ||
assetId, | ||
lazyDistributor, | ||
rewardsMint, | ||
payer, | ||
destination, | ||
...rest | ||
}: { | ||
program: Program<LazyDistributor>; | ||
assetId: PublicKey; | ||
rewardsMint?: PublicKey; | ||
assetEndpoint?: string; | ||
lazyDistributor: PublicKey; | ||
owner?: PublicKey; | ||
payer?: PublicKey; | ||
destination: PublicKey | null; | ||
getAssetFn?: (url: string, assetId: PublicKey) => Promise<Asset | undefined>; | ||
getAssetProofFn?: ( | ||
url: string, | ||
assetId: PublicKey | ||
) => Promise<AssetProof | undefined>; | ||
}) { | ||
const { | ||
asset: { | ||
ownership: { owner }, | ||
}, | ||
args, | ||
accounts, | ||
remainingAccounts, | ||
} = await proofArgsAndAccounts({ | ||
connection: program.provider.connection, | ||
assetId, | ||
...rest, | ||
}); | ||
|
||
return program.methods | ||
.updateCompressionDestinationV0({ | ||
...args, | ||
}) | ||
.accounts({ | ||
...accounts, | ||
owner, | ||
recipient: recipientKey(lazyDistributor, assetId)[0], | ||
destination: destination == null ? PublicKey.default : destination, | ||
}) | ||
.remainingAccounts(remainingAccounts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
programs/lazy-distributor/src/instructions/distribute/distribute_custom_destination_v0.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use super::*; | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct DistributeCustomDestinationV0<'info> { | ||
pub common: DistributeRewardsCommonV0<'info>, | ||
} | ||
|
||
pub fn handler(ctx: Context<DistributeCustomDestinationV0>) -> Result<()> { | ||
require_eq!( | ||
ctx.accounts.common.owner.key(), | ||
ctx.accounts.common.recipient.destination | ||
); | ||
|
||
distribute_impl(&mut ctx.accounts.common) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
pub mod common; | ||
pub mod distribute_compression_rewards_v0; | ||
pub mod distribute_custom_destination_v0; | ||
pub mod distribute_rewards_v0; | ||
|
||
pub use common::*; | ||
pub use distribute_compression_rewards_v0::*; | ||
pub use distribute_custom_destination_v0::*; | ||
pub use distribute_rewards_v0::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
programs/lazy-distributor/src/instructions/update_destination/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod update_compression_destination_v0; | ||
pub mod update_destination_v0; | ||
|
||
pub use update_compression_destination_v0::*; | ||
pub use update_destination_v0::*; |
46 changes: 46 additions & 0 deletions
46
...lazy-distributor/src/instructions/update_destination/update_compression_destination_v0.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::state::*; | ||
use account_compression_cpi::program::SplAccountCompression; | ||
use anchor_lang::prelude::*; | ||
use shared_utils::{verify_compressed_nft, VerifyCompressedNftArgs}; | ||
|
||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)] | ||
pub struct UpdateCompressionDestinationArgsV0 { | ||
pub data_hash: [u8; 32], | ||
pub creator_hash: [u8; 32], | ||
pub root: [u8; 32], | ||
pub index: u32, | ||
} | ||
|
||
#[derive(Accounts)] | ||
#[instruction(args: UpdateCompressionDestinationArgsV0)] | ||
pub struct UpdateCompressionDestinationV0<'info> { | ||
#[account(mut)] | ||
pub recipient: Box<Account<'info, RecipientV0>>, | ||
pub owner: Signer<'info>, | ||
/// CHECK: User provided destination | ||
pub destination: UncheckedAccount<'info>, | ||
/// CHECK: Checked via verify_compressed_nft | ||
pub merkle_tree: UncheckedAccount<'info>, | ||
pub compression_program: Program<'info, SplAccountCompression>, | ||
} | ||
|
||
pub fn handler<'info>( | ||
ctx: Context<'_, '_, '_, 'info, UpdateCompressionDestinationV0<'info>>, | ||
args: UpdateCompressionDestinationArgsV0, | ||
) -> Result<()> { | ||
verify_compressed_nft(VerifyCompressedNftArgs { | ||
data_hash: args.data_hash, | ||
creator_hash: args.creator_hash, | ||
root: args.root, | ||
index: args.index, | ||
compression_program: ctx.accounts.compression_program.to_account_info(), | ||
merkle_tree: ctx.accounts.merkle_tree.to_account_info(), | ||
owner: ctx.accounts.owner.key(), | ||
delegate: ctx.accounts.owner.key(), | ||
proof_accounts: ctx.remaining_accounts.to_vec(), | ||
})?; | ||
|
||
ctx.accounts.recipient.destination = ctx.accounts.destination.key(); | ||
|
||
Ok(()) | ||
} |
24 changes: 24 additions & 0 deletions
24
programs/lazy-distributor/src/instructions/update_destination/update_destination_v0.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::state::*; | ||
use anchor_lang::prelude::*; | ||
use anchor_spl::token::TokenAccount; | ||
|
||
#[derive(Accounts)] | ||
pub struct UpdateDestinationV0<'info> { | ||
#[account(mut)] | ||
pub recipient: Box<Account<'info, RecipientV0>>, | ||
pub owner: Signer<'info>, | ||
/// CHECK: User provided destination | ||
pub destination: UncheckedAccount<'info>, | ||
#[account( | ||
token::mint = recipient.asset, | ||
constraint = recipient_mint_account.amount > 0, | ||
constraint = recipient_mint_account.owner == owner.key() | ||
)] | ||
pub recipient_mint_account: Box<Account<'info, TokenAccount>>, | ||
} | ||
|
||
pub fn handler<'info>(ctx: Context<UpdateDestinationV0>) -> Result<()> { | ||
ctx.accounts.recipient.destination = ctx.accounts.destination.key(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.