Skip to content

Commit

Permalink
feat: add create auction v2 transaction (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kurpav authored Nov 16, 2021
1 parent 2723a42 commit 04bbba7
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 8 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const rates = await new Coingecko().getRate([Currency.AR, Currency.SOL], Currenc
- [x] RedeemBid
- [ ] RedeemFullRightsTransferBid
- [x] StartAuction
- [ ] EndAuction
- [x] ClaimBid
- [ ] EmptyPaymentAccount
- [x] SetStore
Expand All @@ -108,7 +109,6 @@ const rates = await new Coingecko().getRate([Currency.AR, Currency.SOL], Currenc
- [x] InitAuctionManagerV2
- [ ] ValidateSafetyDepositBoxV2
- [ ] RedeemParticipationBidV3
- [ ] EndAuction
- [ ] SetStoreIndex
- [ ] SetAuctionCache
- [ ] Actions
Expand All @@ -120,17 +120,15 @@ const rates = await new Coingecko().getRate([Currency.AR, Currency.SOL], Currenc
- [x] Bidder Meta
- [ ] Instructions
- [x] CancelBid
- [ ] CreateAuctionV2
- [ ] ClaimBid
- [ ] EndAuction
- [ ] StartAuction
- [x] CreateAuction
- [x] CreateAuctionV2
- [x] SetAuthority
- [x] PlaceBid
- [ ] Actions (no standalone actions)
- [x] Cancel Bid
- [x] Place Bid
- [ ] Redeem Bid
- [ ] Instant Sale
- [x] Redeem Bid
- [x] Instant Sale
- [ ] Vault
- [ ] Accounts
- [x] Safety Deposit Box
Expand Down
7 changes: 6 additions & 1 deletion src/programs/auction/transactions/CreateAuction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type WinnerLimitArgs = {
type: WinnerLimitType;
usize: BN;
};

export class WinnerLimit extends Borsh.Data<WinnerLimitArgs> {
static readonly SCHEMA = this.struct([
['type', 'u8'],
Expand All @@ -31,7 +32,7 @@ export class WinnerLimit extends Borsh.Data<WinnerLimitArgs> {
usize: BN;
}

type Args = {
export type Args = {
winners: WinnerLimit;
endAuctionAt: BN | null;
auctionGap: BN | null;
Expand All @@ -42,6 +43,7 @@ type Args = {
tickSize: BN | null;
gapTickSizePercentage: number | null;
};

export class CreateAuctionArgs extends Borsh.Data<Args> {
static readonly SCHEMA = new Map([
...WinnerLimit.SCHEMA,
Expand Down Expand Up @@ -73,8 +75,11 @@ export class CreateAuctionArgs extends Borsh.Data<Args> {
authority: StringPublicKey;
/// The resource being auctioned. See AuctionData.
resource: StringPublicKey;
/// Set a price floor.
priceFloor: PriceFloor;
/// Add a tick size increment
tickSize: BN | null;
/// Add a minimum percentage increase each bid must meet.
gapTickSizePercentage: number | null;
}

Expand Down
103 changes: 103 additions & 0 deletions src/programs/auction/transactions/CreateAuctionV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { StringPublicKey } from '@metaplex/types';
import { Borsh } from '@metaplex/utils';
import {
PublicKey,
SystemProgram,
SYSVAR_RENT_PUBKEY,
TransactionCtorFields,
TransactionInstruction,
} from '@solana/web3.js';
import BN from 'bn.js';
import { AuctionProgram } from '../AuctionProgram';
import { Transaction } from '../../../Transaction';
import { PriceFloor } from '../accounts/Auction';
import { Args as CreateAuctionArgsType, CreateAuctionArgs, WinnerLimit } from './CreateAuction';

type Args = CreateAuctionArgsType & {
instantSalePrice: BN | null;
name: number[] | null;
};

export class CreateAuctionV2Args extends Borsh.Data<Args> {
static readonly SCHEMA = new Map([
...CreateAuctionArgs.SCHEMA,
...this.struct([
['instantSalePrice', { kind: 'option', type: 'u64' }],
['name', { kind: 'option', type: [32] }],
]),
]);

instruction = 7;
/// How many winners are allowed for this auction. See AuctionData.
winners: WinnerLimit;
/// End time is the cut-off point that the auction is forced to end by. See AuctionData.
endAuctionAt: BN | null;
/// Gap time is how much time after the previous bid where the auction ends. See AuctionData.
auctionGap: BN | null;
/// Token mint for the SPL token used for bidding.
tokenMint: StringPublicKey;
/// Authority
authority: StringPublicKey;
/// The resource being auctioned. See AuctionData.
resource: StringPublicKey;
/// Set a price floor.
priceFloor: PriceFloor;
/// Add a tick size increment
tickSize: BN | null;
/// Add a minimum percentage increase each bid must meet.
gapTickSizePercentage: number | null;
/// Add a instant sale price.
instantSalePrice: BN | null;
/// Auction name
name: number[] | null;
}

type CreateAuctionV2Params = {
auction: PublicKey;
auctionExtended: PublicKey;
creator: PublicKey;
args: CreateAuctionV2Args;
};

export class CreateAuctionV2 extends Transaction {
constructor(options: TransactionCtorFields, params: CreateAuctionV2Params) {
super(options);
const { args, auction, auctionExtended, creator } = params;

const data = CreateAuctionV2Args.serialize(args);

this.add(
new TransactionInstruction({
keys: [
{
pubkey: creator,
isSigner: true,
isWritable: true,
},
{
pubkey: auction,
isSigner: false,
isWritable: true,
},
{
pubkey: auctionExtended,
isSigner: false,
isWritable: true,
},
{
pubkey: SYSVAR_RENT_PUBKEY,
isSigner: false,
isWritable: false,
},
{
pubkey: SystemProgram.programId,
isSigner: false,
isWritable: false,
},
],
programId: AuctionProgram.PUBKEY,
data,
}),
);
}
}
1 change: 1 addition & 0 deletions src/programs/auction/transactions/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './CancelBid';
export * from './CreateAuction';
export * from './CreateAuctionV2';
export * from './PlaceBid';
export * from './SetAuctionAuthority';
5 changes: 5 additions & 0 deletions test/transactions/__snapshots__/auction.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Auction transactions CreateAuction 1`] = `"{\\"type\\":\\"Buffer\\",\\"data\\":[2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,3,7,93,135,29,120,250,13,109,171,35,122,77,213,58,178,208,153,32,156,150,192,153,14,177,253,172,197,7,247,216,61,254,175,187,209,148,182,34,149,175,173,192,85,175,252,231,130,76,40,175,177,44,111,250,168,3,236,149,34,236,19,46,9,66,138,155,76,202,43,34,141,168,115,82,176,65,170,75,45,110,185,97,234,236,43,234,0,144,234,95,255,33,107,30,38,145,153,130,131,135,32,113,60,44,78,85,97,231,146,60,57,129,72,71,229,99,140,205,42,175,85,79,60,2,195,134,224,132,55,6,167,213,23,25,44,92,81,33,140,201,76,61,74,241,127,88,218,238,8,155,161,253,68,227,219,217,138,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,175,169,191,10,132,153,239,245,177,12,199,221,36,59,224,20,103,70,219,249,150,85,157,145,130,193,93,188,24,246,87,131,79,219,30,88,36,153,69,200,48,40,136,227,246,197,102,213,141,122,4,186,57,98,62,139,154,145,152,59,13,211,149,1,6,5,1,2,3,4,5,168,1,1,1,1,0,0,0,0,0,0,0,1,195,115,146,97,0,0,0,0,1,30,0,0,0,0,0,0,0,113,178,77,47,3,206,165,188,130,225,172,175,199,64,162,55,188,104,159,223,218,116,88,247,167,60,131,209,170,44,208,98,70,65,21,141,143,89,143,146,210,57,211,217,223,24,20,153,223,130,92,14,226,188,44,87,44,70,212,74,67,174,21,67,151,236,219,224,54,47,112,197,46,29,246,29,105,42,66,214,178,206,61,219,206,132,245,159,159,124,100,29,253,0,131,115,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,10,0,0,0,0,0,0,0,1,1]}"`;

exports[`Auction transactions CreateAuctionV2 1`] = `"{\\"type\\":\\"Buffer\\",\\"data\\":[2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,3,7,93,135,29,120,250,13,109,171,35,122,77,213,58,178,208,153,32,156,150,192,153,14,177,253,172,197,7,247,216,61,254,175,187,209,148,182,34,149,175,173,192,85,175,252,231,130,76,40,175,177,44,111,250,168,3,236,149,34,236,19,46,9,66,138,155,76,202,43,34,141,168,115,82,176,65,170,75,45,110,185,97,234,236,43,234,0,144,234,95,255,33,107,30,38,145,153,130,131,135,32,113,60,44,78,85,97,231,146,60,57,129,72,71,229,99,140,205,42,175,85,79,60,2,195,134,224,132,55,6,167,213,23,25,44,92,81,33,140,201,76,61,74,241,127,88,218,238,8,155,161,253,68,227,219,217,138,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,175,169,191,10,132,153,239,245,177,12,199,221,36,59,224,20,103,70,219,249,150,85,157,145,130,193,93,188,24,246,87,131,79,219,30,88,36,153,69,200,48,40,136,227,246,197,102,213,141,122,4,186,57,98,62,139,154,145,152,59,13,211,149,1,6,5,1,2,3,4,5,10,1,0,202,154,59,0,0,0,0,0]}"`;
72 changes: 72 additions & 0 deletions test/transactions/auction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import BN from 'bn.js';
import { LAMPORTS_PER_SOL } from '@solana/web3.js';
import {
AUCTION_EXTENDED_PUBKEY,
AUCTION_PUBKEY,
FEE_PAYER,
mockTransaction,
NEW_AUTHORITY_PUBKEY,
serializeConfig,
TOKEN_MINT_PUBKEY,
VAULT_PUBKEY,
} from '../utils';
import {
CreateAuctionV2,
CreateAuctionV2Args,
} from '../../src/programs/auction/transactions/CreateAuctionV2';
import {
CreateAuction,
CreateAuctionArgs,
PriceFloor,
PriceFloorType,
WinnerLimit,
WinnerLimitType,
} from '../../src/programs/auction';

describe('Auction transactions', () => {
test('CreateAuction', async () => {
const data = new CreateAuction(mockTransaction, {
auction: AUCTION_PUBKEY,
auctionExtended: AUCTION_EXTENDED_PUBKEY,
creator: FEE_PAYER.publicKey,
args: new CreateAuctionArgs({
winners: new WinnerLimit({ type: WinnerLimitType.Capped, usize: new BN(1) }),
endAuctionAt: new BN(1636987843),
auctionGap: new BN(30),
tokenMint: TOKEN_MINT_PUBKEY.toString(),
authority: NEW_AUTHORITY_PUBKEY.toString(),
resource: VAULT_PUBKEY.toString(),
priceFloor: new PriceFloor({ type: PriceFloorType.Minimum }),
tickSize: new BN(10),
gapTickSizePercentage: 1,
}),
});

const serializedData = data.serialize(serializeConfig);
expect(JSON.stringify(serializedData)).toMatchSnapshot();
});

test('CreateAuctionV2', async () => {
const data = new CreateAuctionV2(mockTransaction, {
auction: AUCTION_PUBKEY,
auctionExtended: AUCTION_EXTENDED_PUBKEY,
creator: FEE_PAYER.publicKey,
args: new CreateAuctionV2Args({
winners: new WinnerLimit({ type: WinnerLimitType.Capped, usize: new BN(1) }),
endAuctionAt: new BN(1636987843),
auctionGap: new BN(30),
tokenMint: TOKEN_MINT_PUBKEY.toString(),
authority: NEW_AUTHORITY_PUBKEY.toString(),
resource: VAULT_PUBKEY.toString(),
priceFloor: new PriceFloor({ type: PriceFloorType.Minimum }),
tickSize: new BN(10),
gapTickSizePercentage: 1,
instantSalePrice: new BN(LAMPORTS_PER_SOL),
name: null,
}),
});

const serializedData = data.serialize(serializeConfig);
expect(JSON.stringify(serializedData)).toMatchSnapshot();
});
});

0 comments on commit 04bbba7

Please sign in to comment.