Added name to the auction data
This commit is contained in:
parent
a96a5f9b2d
commit
1857649730
|
@ -456,6 +456,8 @@ pub struct AuctionDataExtended {
|
||||||
pub tick_size: Option<u64>,
|
pub tick_size: Option<u64>,
|
||||||
/// gap_tick_size_percentage - two decimal points
|
/// gap_tick_size_percentage - two decimal points
|
||||||
pub gap_tick_size_percentage: Option<u8>,
|
pub gap_tick_size_percentage: Option<u8>,
|
||||||
|
/// auction name
|
||||||
|
pub name: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Define valid auction state transitions.
|
/// Define valid auction state transitions.
|
||||||
|
|
|
@ -15,7 +15,7 @@ import { findProgramAddress } from '../utils';
|
||||||
export const AUCTION_PREFIX = 'auction';
|
export const AUCTION_PREFIX = 'auction';
|
||||||
export const METADATA = 'metadata';
|
export const METADATA = 'metadata';
|
||||||
export const EXTENDED = 'extended';
|
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 {
|
export enum AuctionState {
|
||||||
Created = 0,
|
Created = 0,
|
||||||
|
@ -177,15 +177,18 @@ export class AuctionDataExtended {
|
||||||
totalUncancelledBids: BN;
|
totalUncancelledBids: BN;
|
||||||
tickSize: BN | null;
|
tickSize: BN | null;
|
||||||
gapTickSizePercentage: number | null;
|
gapTickSizePercentage: number | null;
|
||||||
|
name: Uint8Array;
|
||||||
|
|
||||||
constructor(args: {
|
constructor(args: {
|
||||||
totalUncancelledBids: BN;
|
totalUncancelledBids: BN;
|
||||||
tickSize: BN | null;
|
tickSize: BN | null;
|
||||||
gapTickSizePercentage: number | null;
|
gapTickSizePercentage: number | null;
|
||||||
|
name: Uint8Array;
|
||||||
}) {
|
}) {
|
||||||
this.totalUncancelledBids = args.totalUncancelledBids;
|
this.totalUncancelledBids = args.totalUncancelledBids;
|
||||||
this.tickSize = args.tickSize;
|
this.tickSize = args.tickSize;
|
||||||
this.gapTickSizePercentage = args.gapTickSizePercentage;
|
this.gapTickSizePercentage = args.gapTickSizePercentage;
|
||||||
|
this.name = args.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,6 +369,8 @@ export interface IPartialCreateAuctionArgs {
|
||||||
tickSize: BN | null;
|
tickSize: BN | null;
|
||||||
|
|
||||||
gapTickSizePercentage: number | null;
|
gapTickSizePercentage: number | null;
|
||||||
|
|
||||||
|
name: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
|
export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
|
||||||
|
@ -389,6 +394,8 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
|
||||||
|
|
||||||
gapTickSizePercentage: number | null;
|
gapTickSizePercentage: number | null;
|
||||||
|
|
||||||
|
name: Uint8Array;
|
||||||
|
|
||||||
constructor(args: {
|
constructor(args: {
|
||||||
winners: WinnerLimit;
|
winners: WinnerLimit;
|
||||||
endAuctionAt: BN | null;
|
endAuctionAt: BN | null;
|
||||||
|
@ -399,6 +406,7 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
|
||||||
priceFloor: PriceFloor;
|
priceFloor: PriceFloor;
|
||||||
tickSize: BN | null;
|
tickSize: BN | null;
|
||||||
gapTickSizePercentage: number | null;
|
gapTickSizePercentage: number | null;
|
||||||
|
name: string | null;
|
||||||
}) {
|
}) {
|
||||||
this.winners = args.winners;
|
this.winners = args.winners;
|
||||||
this.endAuctionAt = args.endAuctionAt;
|
this.endAuctionAt = args.endAuctionAt;
|
||||||
|
@ -409,6 +417,10 @@ export class CreateAuctionArgs implements IPartialCreateAuctionArgs {
|
||||||
this.priceFloor = args.priceFloor;
|
this.priceFloor = args.priceFloor;
|
||||||
this.tickSize = args.tickSize;
|
this.tickSize = args.tickSize;
|
||||||
this.gapTickSizePercentage = args.gapTickSizePercentage;
|
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],
|
['priceFloor', PriceFloor],
|
||||||
['tickSize', { kind: 'option', type: 'u64' }],
|
['tickSize', { kind: 'option', type: 'u64' }],
|
||||||
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
|
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
|
||||||
|
['name', [32]],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -538,6 +551,7 @@ export const AUCTION_SCHEMA = new Map<any, any>([
|
||||||
['totalUncancelledBids', 'u64'],
|
['totalUncancelledBids', 'u64'],
|
||||||
['tickSize', { kind: 'option', type: 'u64' }],
|
['tickSize', { kind: 'option', type: 'u64' }],
|
||||||
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
|
['gapTickSizePercentage', { kind: 'option', type: 'u8' }],
|
||||||
|
['name', [32]],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -24,6 +24,12 @@ use {
|
||||||
const PROGRAM_PUBKEY: &str = "HLGetPpEUaagthEtF4px9S24hwJrwz3qvgRZxkWTw4ei";
|
const PROGRAM_PUBKEY: &str = "HLGetPpEUaagthEtF4px9S24hwJrwz3qvgRZxkWTw4ei";
|
||||||
const TOKEN_PROGRAM_PUBKEY: &str = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
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) {
|
fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
|
||||||
use spl_auction::{
|
use spl_auction::{
|
||||||
instruction,
|
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!(
|
println!(
|
||||||
"Creating Auction:\n\
|
"Creating Auction:\n\
|
||||||
- Auction: {}\n\
|
- Auction: {}\n\
|
||||||
- Payer: {}\n\
|
- Payer: {}\n\
|
||||||
- Mint: {}\n\
|
- Mint: {}\n\
|
||||||
- Resource: {}\n\
|
- Resource: {}\n\
|
||||||
- Salt: {}\n\n\
|
- Salt: {}\n\
|
||||||
|
- Name: {}\n\n\
|
||||||
Use the salt when revealing the price.
|
Use the salt when revealing the price.
|
||||||
",
|
",
|
||||||
auction_pubkey,
|
auction_pubkey,
|
||||||
|
@ -71,8 +81,11 @@ fn create_auction(app_matches: &ArgMatches, payer: Keypair, client: RpcClient) {
|
||||||
mint.pubkey(),
|
mint.pubkey(),
|
||||||
resource,
|
resource,
|
||||||
salt,
|
salt,
|
||||||
|
name,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let name = string_to_array(name);
|
||||||
|
|
||||||
let instructions = [
|
let instructions = [
|
||||||
// Create a new mint to test this auction with.
|
// Create a new mint to test this auction with.
|
||||||
create_account(
|
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])),
|
price_floor: floor.unwrap_or(PriceFloor::None([0; 32])),
|
||||||
gap_tick_size_percentage: Some(0),
|
gap_tick_size_percentage: Some(0),
|
||||||
tick_size: Some(0),
|
tick_size: Some(0),
|
||||||
|
name,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
@ -604,6 +618,13 @@ fn main() {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("If set, hide the minimum required bid price until the end of the auction."),
|
.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(
|
||||||
SubCommand::with_name("inspect")
|
SubCommand::with_name("inspect")
|
||||||
|
|
|
@ -90,7 +90,7 @@ pub struct AuctionData {
|
||||||
pub bid_state: BidState,
|
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
|
// 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
|
// 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.
|
// 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>,
|
pub tick_size: Option<u64>,
|
||||||
/// gap_tick_size_percentage - two decimal points
|
/// gap_tick_size_percentage - two decimal points
|
||||||
pub gap_tick_size_percentage: Option<u8>,
|
pub gap_tick_size_percentage: Option<u8>,
|
||||||
|
/// auction name
|
||||||
|
pub name: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuctionDataExtended {
|
impl AuctionDataExtended {
|
||||||
|
|
|
@ -44,6 +44,8 @@ pub struct CreateAuctionArgs {
|
||||||
pub tick_size: Option<u64>,
|
pub tick_size: Option<u64>,
|
||||||
/// Add a minimum percentage increase each bid must meet.
|
/// Add a minimum percentage increase each bid must meet.
|
||||||
pub gap_tick_size_percentage: Option<u8>,
|
pub gap_tick_size_percentage: Option<u8>,
|
||||||
|
/// Auction name
|
||||||
|
pub name: [u8; 32],
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Accounts<'a, 'b: 'a> {
|
struct Accounts<'a, 'b: 'a> {
|
||||||
|
@ -156,6 +158,7 @@ pub fn create_auction(
|
||||||
total_uncancelled_bids: 0,
|
total_uncancelled_bids: 0,
|
||||||
tick_size: args.tick_size,
|
tick_size: args.tick_size,
|
||||||
gap_tick_size_percentage: args.gap_tick_size_percentage,
|
gap_tick_size_percentage: args.gap_tick_size_percentage,
|
||||||
|
name: args.name,
|
||||||
}
|
}
|
||||||
.serialize(&mut *accounts.auction_extended.data.borrow_mut())?;
|
.serialize(&mut *accounts.auction_extended.data.borrow_mut())?;
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
pub async fn get_account(banks_client: &mut BanksClient, pubkey: &Pubkey) -> Account {
|
||||||
banks_client
|
banks_client
|
||||||
.get_account(*pubkey)
|
.get_account(*pubkey)
|
||||||
|
@ -140,6 +149,7 @@ pub async fn create_auction(
|
||||||
resource: &Pubkey,
|
resource: &Pubkey,
|
||||||
mint_keypair: &Pubkey,
|
mint_keypair: &Pubkey,
|
||||||
max_winners: usize,
|
max_winners: usize,
|
||||||
|
name: &str,
|
||||||
) -> Result<(), TransportError> {
|
) -> Result<(), TransportError> {
|
||||||
let transaction = Transaction::new_signed_with_payer(
|
let transaction = Transaction::new_signed_with_payer(
|
||||||
&[instruction::create_auction_instruction(
|
&[instruction::create_auction_instruction(
|
||||||
|
@ -155,6 +165,7 @@ pub async fn create_auction(
|
||||||
price_floor: PriceFloor::None([0u8; 32]),
|
price_floor: PriceFloor::None([0u8; 32]),
|
||||||
gap_tick_size_percentage: Some(0),
|
gap_tick_size_percentage: Some(0),
|
||||||
tick_size: Some(0),
|
tick_size: Some(0),
|
||||||
|
name: string_to_array(name)?,
|
||||||
},
|
},
|
||||||
)],
|
)],
|
||||||
Some(&payer.pubkey()),
|
Some(&payer.pubkey()),
|
||||||
|
|
|
@ -70,6 +70,7 @@ async fn setup_auction(
|
||||||
&resource,
|
&resource,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
max_winners,
|
max_winners,
|
||||||
|
"Some name",
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
Loading…
Reference in New Issue