Added name to the auction data

This commit is contained in:
Yuriy Savchenko 2021-07-25 12:00:40 +03:00
parent a96a5f9b2d
commit 1857649730
7 changed files with 57 additions and 3 deletions

View File

@ -456,6 +456,8 @@ pub struct AuctionDataExtended {
pub tick_size: Option<u64>,
/// gap_tick_size_percentage - two decimal points
pub gap_tick_size_percentage: Option<u8>,
/// auction name
pub name: [u8; 32],
}
/// Define valid auction state transitions.

View File

@ -15,7 +15,7 @@ import { findProgramAddress } from '../utils';
export const AUCTION_PREFIX = 'auction';
export const METADATA = 'metadata';
export const EXTENDED = 'extended';
export const MAX_AUCTION_DATA_EXTENDED_SIZE = 8 + 9 + 2 + 200;
export const MAX_AUCTION_DATA_EXTENDED_SIZE = 8 + 9 + 2 + 32 + 168;
export enum AuctionState {
Created = 0,
@ -177,15 +177,18 @@ export class AuctionDataExtended {
totalUncancelledBids: BN;
tickSize: BN | null;
gapTickSizePercentage: number | null;
name: Uint8Array;
constructor(args: {
totalUncancelledBids: BN;
tickSize: BN | null;
gapTickSizePercentage: number | null;
name: Uint8Array;
}) {
this.totalUncancelledBids = args.totalUncancelledBids;
this.tickSize = args.tickSize;
this.gapTickSizePercentage = args.gapTickSizePercentage;
this.name = args.name;
}
}
@ -366,6 +369,8 @@ export interface IPartialCreateAuctionArgs {
tickSize: BN | null;
gapTickSizePercentage: number | null;
name: Uint8Array;
}
export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
@ -389,6 +394,8 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
gapTickSizePercentage: number | null;
name: Uint8Array;
constructor(args: {
winners: WinnerLimit;
endAuctionAt: BN | null;
@ -399,6 +406,7 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
priceFloor: PriceFloor;
tickSize: BN | null;
gapTickSizePercentage: number | null;
name: string | null;
}) {
this.winners = args.winners;
this.endAuctionAt = args.endAuctionAt;
@ -409,6 +417,10 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
this.priceFloor = args.priceFloor;
this.tickSize = args.tickSize;
this.gapTickSizePercentage = args.gapTickSizePercentage;
let fixedBuffer = new Buffer(32)
if (name) Buffer.from(name).copy(fixedBuffer);
this.string = new Uint8Array(fixedBuffer);
}
}
@ -461,6 +473,7 @@ export const AUCTION_SCHEMA = new Map<any, any>([
['priceFloor', PriceFloor],
['tickSize', { kind: 'option', type: 'u64' }],
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
['name', [32]],
],
},
],
@ -538,6 +551,7 @@ export const AUCTION_SCHEMA = new Map<any, any>([
['totalUncancelledBids', 'u64'],
['tickSize', { kind: 'option', type: 'u64' }],
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
['name', [32]],
],
},
],

View File

@ -24,6 +24,12 @@ use {
const PROGRAM_PUBKEY: &str = "HLGetPpEUaagthEtF4px9S24hwJrwz3qvgRZxkWTw4ei";
const TOKEN_PROGRAM_PUBKEY: &str = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
fn string_to_array(value: &str) -> [u8; 32] {
let mut result: [u8; 32] = Default::default();
&result[0..value.len()].copy_from_slice(value.as_bytes());
result
}
fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
use spl_auction::{
instruction,
@ -57,13 +63,17 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
}
});
// Optional auction name
let name: &str = app_matches.value_of("name").unwrap_or("");
println!(
"Creating Auction:\n\
- Auction: {}\n\
- Payer: {}\n\
- Mint: {}\n\
- Resource: {}\n\
- Salt: {}\n\n\
- Salt: {}\n\
- Name: {}\n\n\
Use the salt when revealing the price.
",
auction_pubkey,
@ -71,8 +81,11 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
mint.pubkey(),
resource,
salt,
name,
);
let name = string_to_array(name);
let instructions = [
// Create a new mint to test this auction with.
create_account(
@ -118,6 +131,7 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
price_floor: floor.unwrap_or(PriceFloor::None([0; 32])),
gap_tick_size_percentage: Some(0),
tick_size: Some(0),
name,
},
),
];
@ -604,6 +618,13 @@ fn main() {
.takes_value(false)
.help("If set, hide the minimum required bid price until the end of the auction."),
)
.arg(
Arg::with_name("name")
.long("name")
.value_name("STRING")
.takes_value(true)
.help("Optional auction name (up to 32 characters long)."),
)
)
.subcommand(
SubCommand::with_name("inspect")

View File

@ -90,7 +90,7 @@ pub struct AuctionData {
pub bid_state: BidState,
}
pub const MAX_AUCTION_DATA_EXTENDED_SIZE: usize = 8 + 9 + 2 + 200;
pub const MAX_AUCTION_DATA_EXTENDED_SIZE: usize = 8 + 9 + 2 + 32 + 168;
// Further storage for more fields. Would like to store more on the main data but due
// to a borsh issue that causes more added fields to inflict "Access violation" errors
// during redemption in main Metaplex app for no reason, we had to add this nasty PDA.
@ -104,6 +104,8 @@ pub struct AuctionDataExtended {
pub tick_size: Option<u64>,
/// gap_tick_size_percentage - two decimal points
pub gap_tick_size_percentage: Option<u8>,
/// auction name
pub name: [u8; 32],
}
impl AuctionDataExtended {

View File

@ -44,6 +44,8 @@ pub struct CreateAuctionArgs {
pub tick_size: Option<u64>,
/// Add a minimum percentage increase each bid must meet.
pub gap_tick_size_percentage: Option<u8>,
/// Auction name
pub name: [u8; 32],
}
struct Accounts<'a, 'b: 'a> {
@ -156,6 +158,7 @@ pub fn create_auction(
total_uncancelled_bids: 0,
tick_size: args.tick_size,
gap_tick_size_percentage: args.gap_tick_size_percentage,
name: args.name,
}
.serialize(&mut *accounts.auction_extended.data.borrow_mut())?;

View File

@ -14,6 +14,15 @@ use spl_auction::{
},
};
fn string_to_array(value: &str) -> Result<[u8; 32], TransportError> {
if value.len() > 32 {
return Err(TransportError::Custom("String too long".to_string()));
}
let mut result: [u8; 32] = Default::default();
&result[0..value.len()].copy_from_slice(value.as_bytes());
Ok(result)
}
pub async fn get_account(banks_client: &mut BanksClient, pubkey: &Pubkey) -> Account {
banks_client
.get_account(*pubkey)
@ -140,6 +149,7 @@ pub async fn create_auction(
resource: &Pubkey,
mint_keypair: &Pubkey,
max_winners: usize,
name: &str,
) -> Result<(), TransportError> {
let transaction = Transaction::new_signed_with_payer(
&[instruction::create_auction_instruction(
@ -155,6 +165,7 @@ pub async fn create_auction(
price_floor: PriceFloor::None([0u8; 32]),
gap_tick_size_percentage: Some(0),
tick_size: Some(0),
name: string_to_array(name)?,
},
)],
Some(&payer.pubkey()),

View File

@ -70,6 +70,7 @@ async fn setup_auction(
&resource,
&mint_keypair.pubkey(),
max_winners,
"Some name",
)
.await
.unwrap();