Rename 'delivery' to 'distributor'
This commit is contained in:
parent
393021948a
commit
6f884de25f
|
@ -99,7 +99,7 @@ This is done by running:
|
||||||
$ spl-feature-proposal propose feature-proposal.json
|
$ spl-feature-proposal propose feature-proposal.json
|
||||||
Feature Id: HQ3baDfNU7WKCyWvtMYZmi51YPs7vhSiLn1ESYp3jhiA
|
Feature Id: HQ3baDfNU7WKCyWvtMYZmi51YPs7vhSiLn1ESYp3jhiA
|
||||||
Token Mint Address: ALvA7Lv9jbo8JFhxqnRpjWWuR3aD12uCb5KBJst4uc3d
|
Token Mint Address: ALvA7Lv9jbo8JFhxqnRpjWWuR3aD12uCb5KBJst4uc3d
|
||||||
Delivery Token Address: GK55hNft4TGc3Hg4KzbjEmju8VfaNuXK8jQNDTZKcsNF
|
Distributor Token Address: GK55hNft4TGc3Hg4KzbjEmju8VfaNuXK8jQNDTZKcsNF
|
||||||
Acceptance Token Address: AdqKm3mSJf8AtTWjfpA5ZbJszWQPcwyLA2XkRyLbf3Di
|
Acceptance Token Address: AdqKm3mSJf8AtTWjfpA5ZbJszWQPcwyLA2XkRyLbf3Di
|
||||||
Number of validators: 376
|
Number of validators: 376
|
||||||
Tokens to be minted: 134575791.53064314
|
Tokens to be minted: 134575791.53064314
|
||||||
|
|
|
@ -237,8 +237,8 @@ fn process_propose(
|
||||||
percent_stake_required: u8,
|
percent_stake_required: u8,
|
||||||
confirm: bool,
|
confirm: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let delivery_token_address =
|
let distributor_token_address =
|
||||||
spl_feature_proposal::get_delivery_token_address(&feature_proposal_keypair.pubkey());
|
spl_feature_proposal::get_distributor_token_address(&feature_proposal_keypair.pubkey());
|
||||||
let feature_id_address =
|
let feature_id_address =
|
||||||
spl_feature_proposal::get_feature_id_address(&feature_proposal_keypair.pubkey());
|
spl_feature_proposal::get_feature_id_address(&feature_proposal_keypair.pubkey());
|
||||||
let acceptance_token_address =
|
let acceptance_token_address =
|
||||||
|
@ -247,7 +247,7 @@ fn process_propose(
|
||||||
|
|
||||||
println!("Feature Id: {}", feature_id_address);
|
println!("Feature Id: {}", feature_id_address);
|
||||||
println!("Token Mint Address: {}", mint_address);
|
println!("Token Mint Address: {}", mint_address);
|
||||||
println!("Delivery Token Address: {}", delivery_token_address,);
|
println!("Distributor Token Address: {}", distributor_token_address);
|
||||||
println!("Acceptance Token Address: {}", acceptance_token_address);
|
println!("Acceptance Token Address: {}", acceptance_token_address);
|
||||||
|
|
||||||
let vote_accounts = rpc_client.get_vote_accounts()?;
|
let vote_accounts = rpc_client.get_vote_accounts()?;
|
||||||
|
@ -314,7 +314,7 @@ fn process_propose(
|
||||||
--db-path db.{} \
|
--db-path db.{} \
|
||||||
--fee-payer ~/.config/solana/id.json \
|
--fee-payer ~/.config/solana/id.json \
|
||||||
--owner <FEATURE_PROPOSAL_KEYPAIR>",
|
--owner <FEATURE_PROPOSAL_KEYPAIR>",
|
||||||
delivery_token_address,
|
distributor_token_address,
|
||||||
distribution_file,
|
distribution_file,
|
||||||
&feature_proposal_keypair.pubkey().to_string()[..8]
|
&feature_proposal_keypair.pubkey().to_string()[..8]
|
||||||
);
|
);
|
||||||
|
|
|
@ -20,14 +20,14 @@ pub enum FeatureProposalInstruction {
|
||||||
/// funded by account 0:
|
/// funded by account 0:
|
||||||
/// * A new token mint with a supply of `tokens_to_mint`, owned by the program and never
|
/// * A new token mint with a supply of `tokens_to_mint`, owned by the program and never
|
||||||
/// modified again
|
/// modified again
|
||||||
/// * A new "delivery" token account that holds the total supply, owned by account 0.
|
/// * A new "distributor" token account that holds the total supply, owned by account 0.
|
||||||
/// * A new "acceptance" token account that holds 0 tokens, owned by the program. Tokens
|
/// * A new "acceptance" token account that holds 0 tokens, owned by the program. Tokens
|
||||||
/// transfers to this address are irrevocable and permanent.
|
/// transfers to this address are irrevocable and permanent.
|
||||||
/// * A new feature id account that has been funded and allocated (as described in
|
/// * A new feature id account that has been funded and allocated (as described in
|
||||||
/// `solana_program::feature`)
|
/// `solana_program::feature`)
|
||||||
///
|
///
|
||||||
/// On successful execution of the instruction, the feature proposer is expected to distribute
|
/// On successful execution of the instruction, the feature proposer is expected to distribute
|
||||||
/// the tokens in the delivery token account out to all participating parties.
|
/// the tokens in the distributor token account out to all participating parties.
|
||||||
///
|
///
|
||||||
/// Based on the provided acceptance criteria, if `AcceptanceCriteria::tokens_required`
|
/// Based on the provided acceptance criteria, if `AcceptanceCriteria::tokens_required`
|
||||||
/// tokens are transferred into the acceptance token account before
|
/// tokens are transferred into the acceptance token account before
|
||||||
|
@ -41,7 +41,7 @@ pub enum FeatureProposalInstruction {
|
||||||
/// 0. `[writeable,signer]` Funding account (must be a system account)
|
/// 0. `[writeable,signer]` Funding account (must be a system account)
|
||||||
/// 1. `[writeable,signer]` Unallocated feature proposal account to create
|
/// 1. `[writeable,signer]` Unallocated feature proposal account to create
|
||||||
/// 2. `[writeable]` Token mint address from `get_mint_address`
|
/// 2. `[writeable]` Token mint address from `get_mint_address`
|
||||||
/// 3. `[writeable]` Delivery token account address from `get_delivery_token_address`
|
/// 3. `[writeable]` Distributor token account address from `get_distributor_token_address`
|
||||||
/// 4. `[writeable]` Acceptance token account address from `get_acceptance_token_address`
|
/// 4. `[writeable]` Acceptance token account address from `get_acceptance_token_address`
|
||||||
/// 5. `[writeable]` Feature id account address from `get_feature_id_address`
|
/// 5. `[writeable]` Feature id account address from `get_feature_id_address`
|
||||||
/// 6. `[]` System program
|
/// 6. `[]` System program
|
||||||
|
@ -109,7 +109,7 @@ pub fn propose(
|
||||||
acceptance_criteria: AcceptanceCriteria,
|
acceptance_criteria: AcceptanceCriteria,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mint_address = get_mint_address(feature_proposal_address);
|
let mint_address = get_mint_address(feature_proposal_address);
|
||||||
let delivery_token_address = get_delivery_token_address(feature_proposal_address);
|
let distributor_token_address = get_distributor_token_address(feature_proposal_address);
|
||||||
let acceptance_token_address = get_acceptance_token_address(feature_proposal_address);
|
let acceptance_token_address = get_acceptance_token_address(feature_proposal_address);
|
||||||
let feature_id_address = get_feature_id_address(feature_proposal_address);
|
let feature_id_address = get_feature_id_address(feature_proposal_address);
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ pub fn propose(
|
||||||
AccountMeta::new(*funding_address, true),
|
AccountMeta::new(*funding_address, true),
|
||||||
AccountMeta::new(*feature_proposal_address, true),
|
AccountMeta::new(*feature_proposal_address, true),
|
||||||
AccountMeta::new(mint_address, false),
|
AccountMeta::new(mint_address, false),
|
||||||
AccountMeta::new(delivery_token_address, false),
|
AccountMeta::new(distributor_token_address, false),
|
||||||
AccountMeta::new(acceptance_token_address, false),
|
AccountMeta::new(acceptance_token_address, false),
|
||||||
AccountMeta::new(feature_id_address, false),
|
AccountMeta::new(feature_id_address, false),
|
||||||
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
AccountMeta::new_readonly(solana_program::system_program::id(), false),
|
||||||
|
|
|
@ -18,10 +18,13 @@ pub(crate) fn get_mint_address_with_seed(feature_proposal_address: &Pubkey) -> (
|
||||||
Pubkey::find_program_address(&[&feature_proposal_address.to_bytes(), br"mint"], &id())
|
Pubkey::find_program_address(&[&feature_proposal_address.to_bytes(), br"mint"], &id())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_delivery_token_address_with_seed(
|
pub(crate) fn get_distributor_token_address_with_seed(
|
||||||
feature_proposal_address: &Pubkey,
|
feature_proposal_address: &Pubkey,
|
||||||
) -> (Pubkey, u8) {
|
) -> (Pubkey, u8) {
|
||||||
Pubkey::find_program_address(&[&feature_proposal_address.to_bytes(), br"delivery"], &id())
|
Pubkey::find_program_address(
|
||||||
|
&[&feature_proposal_address.to_bytes(), br"distributor"],
|
||||||
|
&id(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_acceptance_token_address_with_seed(
|
pub(crate) fn get_acceptance_token_address_with_seed(
|
||||||
|
@ -47,8 +50,8 @@ pub fn get_mint_address(feature_proposal_address: &Pubkey) -> Pubkey {
|
||||||
|
|
||||||
/// Derive the SPL Token token address associated with a feature proposal that receives the initial
|
/// Derive the SPL Token token address associated with a feature proposal that receives the initial
|
||||||
/// minted tokens
|
/// minted tokens
|
||||||
pub fn get_delivery_token_address(feature_proposal_address: &Pubkey) -> Pubkey {
|
pub fn get_distributor_token_address(feature_proposal_address: &Pubkey) -> Pubkey {
|
||||||
get_delivery_token_address_with_seed(feature_proposal_address).0
|
get_distributor_token_address_with_seed(feature_proposal_address).0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Derive the SPL Token token address associated with a feature proposal that users send their
|
/// Derive the SPL Token token address associated with a feature proposal that users send their
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub fn process_instruction(
|
||||||
let funder_info = next_account_info(account_info_iter)?;
|
let funder_info = next_account_info(account_info_iter)?;
|
||||||
let feature_proposal_info = next_account_info(account_info_iter)?;
|
let feature_proposal_info = next_account_info(account_info_iter)?;
|
||||||
let mint_info = next_account_info(account_info_iter)?;
|
let mint_info = next_account_info(account_info_iter)?;
|
||||||
let delivery_token_info = next_account_info(account_info_iter)?;
|
let distributor_token_info = next_account_info(account_info_iter)?;
|
||||||
let acceptance_token_info = next_account_info(account_info_iter)?;
|
let acceptance_token_info = next_account_info(account_info_iter)?;
|
||||||
let feature_id_info = next_account_info(account_info_iter)?;
|
let feature_id_info = next_account_info(account_info_iter)?;
|
||||||
let system_program_info = next_account_info(account_info_iter)?;
|
let system_program_info = next_account_info(account_info_iter)?;
|
||||||
|
@ -49,10 +49,10 @@ pub fn process_instruction(
|
||||||
return Err(ProgramError::InvalidArgument);
|
return Err(ProgramError::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
let (delivery_token_address, delivery_token_bump_seed) =
|
let (distributor_token_address, distributor_token_bump_seed) =
|
||||||
get_delivery_token_address_with_seed(feature_proposal_info.key);
|
get_distributor_token_address_with_seed(feature_proposal_info.key);
|
||||||
if delivery_token_address != *delivery_token_info.key {
|
if distributor_token_address != *distributor_token_info.key {
|
||||||
info!("Error: delivery token address derivation mismatch");
|
info!("Error: distributor token address derivation mismatch");
|
||||||
return Err(ProgramError::InvalidArgument);
|
return Err(ProgramError::InvalidArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,10 +76,10 @@ pub fn process_instruction(
|
||||||
&[mint_bump_seed],
|
&[mint_bump_seed],
|
||||||
];
|
];
|
||||||
|
|
||||||
let delivery_token_signer_seeds: &[&[_]] = &[
|
let distributor_token_signer_seeds: &[&[_]] = &[
|
||||||
&feature_proposal_info.key.to_bytes(),
|
&feature_proposal_info.key.to_bytes(),
|
||||||
br"delivery",
|
br"distributor",
|
||||||
&[delivery_token_bump_seed],
|
&[distributor_token_bump_seed],
|
||||||
];
|
];
|
||||||
|
|
||||||
let acceptance_token_signer_seeds: &[&[_]] = &[
|
let acceptance_token_signer_seeds: &[&[_]] = &[
|
||||||
|
@ -145,33 +145,33 @@ pub fn process_instruction(
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
info!("Creating delivery token account");
|
info!("Creating distributor token account");
|
||||||
invoke_signed(
|
invoke_signed(
|
||||||
&system_instruction::create_account(
|
&system_instruction::create_account(
|
||||||
funder_info.key,
|
funder_info.key,
|
||||||
delivery_token_info.key,
|
distributor_token_info.key,
|
||||||
1.max(rent.minimum_balance(spl_token::state::Account::get_packed_len())),
|
1.max(rent.minimum_balance(spl_token::state::Account::get_packed_len())),
|
||||||
spl_token::state::Account::get_packed_len() as u64,
|
spl_token::state::Account::get_packed_len() as u64,
|
||||||
&spl_token::id(),
|
&spl_token::id(),
|
||||||
),
|
),
|
||||||
&[
|
&[
|
||||||
funder_info.clone(),
|
funder_info.clone(),
|
||||||
delivery_token_info.clone(),
|
distributor_token_info.clone(),
|
||||||
system_program_info.clone(),
|
system_program_info.clone(),
|
||||||
],
|
],
|
||||||
&[&delivery_token_signer_seeds],
|
&[&distributor_token_signer_seeds],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
info!("Initializing delivery token account");
|
info!("Initializing distributor token account");
|
||||||
invoke(
|
invoke(
|
||||||
&spl_token::instruction::initialize_account(
|
&spl_token::instruction::initialize_account(
|
||||||
&spl_token::id(),
|
&spl_token::id(),
|
||||||
delivery_token_info.key,
|
distributor_token_info.key,
|
||||||
mint_info.key,
|
mint_info.key,
|
||||||
feature_proposal_info.key,
|
feature_proposal_info.key,
|
||||||
)?,
|
)?,
|
||||||
&[
|
&[
|
||||||
delivery_token_info.clone(),
|
distributor_token_info.clone(),
|
||||||
spl_token_program_info.clone(),
|
spl_token_program_info.clone(),
|
||||||
rent_sysvar_info.clone(),
|
rent_sysvar_info.clone(),
|
||||||
feature_proposal_info.clone(),
|
feature_proposal_info.clone(),
|
||||||
|
@ -243,21 +243,21 @@ pub fn process_instruction(
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Mint `tokens_to_mint` tokens into `delivery_token_account` owned by
|
// Mint `tokens_to_mint` tokens into `distributor_token_account` owned by
|
||||||
// `feature_proposal`
|
// `feature_proposal`
|
||||||
info!(&format!("Minting {} tokens", tokens_to_mint));
|
info!(&format!("Minting {} tokens", tokens_to_mint));
|
||||||
invoke_signed(
|
invoke_signed(
|
||||||
&spl_token::instruction::mint_to(
|
&spl_token::instruction::mint_to(
|
||||||
&spl_token::id(),
|
&spl_token::id(),
|
||||||
mint_info.key,
|
mint_info.key,
|
||||||
delivery_token_info.key,
|
distributor_token_info.key,
|
||||||
mint_info.key,
|
mint_info.key,
|
||||||
&[],
|
&[],
|
||||||
tokens_to_mint,
|
tokens_to_mint,
|
||||||
)?,
|
)?,
|
||||||
&[
|
&[
|
||||||
mint_info.clone(),
|
mint_info.clone(),
|
||||||
delivery_token_info.clone(),
|
distributor_token_info.clone(),
|
||||||
spl_token_program_info.clone(),
|
spl_token_program_info.clone(),
|
||||||
],
|
],
|
||||||
&[&mint_signer_seeds],
|
&[&mint_signer_seeds],
|
||||||
|
|
|
@ -57,7 +57,7 @@ async fn test_basic() {
|
||||||
|
|
||||||
let feature_id_address = get_feature_id_address(&feature_proposal.pubkey());
|
let feature_id_address = get_feature_id_address(&feature_proposal.pubkey());
|
||||||
let mint_address = get_mint_address(&feature_proposal.pubkey());
|
let mint_address = get_mint_address(&feature_proposal.pubkey());
|
||||||
let delivery_token_address = get_delivery_token_address(&feature_proposal.pubkey());
|
let distributor_token_address = get_distributor_token_address(&feature_proposal.pubkey());
|
||||||
let acceptance_token_address = get_acceptance_token_address(&feature_proposal.pubkey());
|
let acceptance_token_address = get_acceptance_token_address(&feature_proposal.pubkey());
|
||||||
|
|
||||||
// Create a new feature proposal
|
// Create a new feature proposal
|
||||||
|
@ -94,15 +94,15 @@ async fn test_basic() {
|
||||||
assert!(mint.freeze_authority.is_none());
|
assert!(mint.freeze_authority.is_none());
|
||||||
assert_eq!(mint.mint_authority, COption::Some(mint_address));
|
assert_eq!(mint.mint_authority, COption::Some(mint_address));
|
||||||
|
|
||||||
// Confirm delivery token account state
|
// Confirm distributor token account state
|
||||||
let delivery_token =
|
let distributor_token =
|
||||||
get_account_data::<spl_token::state::Account>(&mut banks_client, delivery_token_address)
|
get_account_data::<spl_token::state::Account>(&mut banks_client, distributor_token_address)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(delivery_token.amount, 42);
|
assert_eq!(distributor_token.amount, 42);
|
||||||
assert_eq!(delivery_token.mint, mint_address);
|
assert_eq!(distributor_token.mint, mint_address);
|
||||||
assert_eq!(delivery_token.owner, feature_proposal.pubkey());
|
assert_eq!(distributor_token.owner, feature_proposal.pubkey());
|
||||||
assert!(delivery_token.close_authority.is_none());
|
assert!(distributor_token.close_authority.is_none());
|
||||||
|
|
||||||
// Confirm acceptance token account state
|
// Confirm acceptance token account state
|
||||||
let acceptance_token =
|
let acceptance_token =
|
||||||
|
@ -140,7 +140,7 @@ async fn test_basic() {
|
||||||
let mut transaction = Transaction::new_with_payer(
|
let mut transaction = Transaction::new_with_payer(
|
||||||
&[spl_token::instruction::transfer(
|
&[spl_token::instruction::transfer(
|
||||||
&spl_token::id(),
|
&spl_token::id(),
|
||||||
&delivery_token_address,
|
&distributor_token_address,
|
||||||
&acceptance_token_address,
|
&acceptance_token_address,
|
||||||
&feature_proposal.pubkey(),
|
&feature_proposal.pubkey(),
|
||||||
&[],
|
&[],
|
||||||
|
|
Loading…
Reference in New Issue