Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: port makeAuction action #131

Merged
merged 8 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@
"@commitlint/config-conventional"
]
}
}
}
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './transactions';
export * from './initStore';
export * from './initStoreV2';
export * from './makeAuction';
export * from './mintNFT';
export * from './mintEditionFromMaster';
export * from './closeVault';
Expand Down
56 changes: 56 additions & 0 deletions src/actions/makeAuction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Transaction } from '@metaplex-foundation/mpl-core';
import {
Auction,
AuctionExtended,
CreateAuction,
CreateAuctionArgs,
} from '@metaplex-foundation/mpl-auction';
import { PublicKey, TransactionSignature } from '@solana/web3.js';

import { Wallet } from '../wallet';
import { Connection } from '../Connection';
import { sendTransaction } from './transactions';

interface MakeAuctionParams {
connection: Connection;
wallet: Wallet;
vault: PublicKey;
auctionSettings: CreateAuctionArgs;
}

interface MakeAuctionResponse {
txId: TransactionSignature;
auction: PublicKey;
}

export const makeAuction = async ({
tbiedukhin marked this conversation as resolved.
Show resolved Hide resolved
connection,
wallet,
vault,
auctionSettings,
}: MakeAuctionParams): Promise<MakeAuctionResponse> => {
const txOptions = { feePayer: wallet.publicKey };

const auctionKey = await Auction.getPDA(vault);
const fullSettings = new CreateAuctionArgs({
...auctionSettings,
authority: wallet.publicKey.toBase58(),
resource: vault.toBase58(),
});

const auctionTx: Transaction = new CreateAuction(txOptions, {
args: fullSettings,
auction: auctionKey,
creator: wallet.publicKey,
auctionExtended: await AuctionExtended.getPDA(vault),
});

const txId = await sendTransaction({
connection,
signers: [],
txs: [auctionTx],
wallet,
});

return { txId, auction: auctionKey };
};
56 changes: 56 additions & 0 deletions test/actions/makeAuction.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import BN from 'bn.js';
import { NATIVE_MINT } from '@solana/spl-token';
import {
CreateAuctionArgs,
PriceFloor,
PriceFloorType,
WinnerLimit,
WinnerLimitType,
} from '@metaplex-foundation/mpl-auction';

import { Connection, NodeWallet } from '../../src';
import { FEE_PAYER, NETWORK, pause } from '../utils';
import { createVault, createExternalPriceAccount, makeAuction } from '../../src/actions';

describe('makeAuction action', () => {
const connection = new Connection(NETWORK);
tbiedukhin marked this conversation as resolved.
Show resolved Hide resolved
const wallet = new NodeWallet(FEE_PAYER);

test('making an auction for newly created vault', async () => {
const externalPriceAccountData = await createExternalPriceAccount({ connection, wallet });

await pause(20000);

const { vault } = await createVault({
connection,
wallet,
...externalPriceAccountData,
});

await pause(20000);

const auctionSettings: CreateAuctionArgs = {
instruction: 1,
tickSize: null,
auctionGap: null,
endAuctionAt: null,
gapTickSizePercentage: null,
winners: new WinnerLimit({
type: WinnerLimitType.Capped,
usize: new BN(1),
}),
resource: vault.toBase58(),
tokenMint: NATIVE_MINT.toBase58(),
authority: wallet.publicKey.toBase58(),
priceFloor: new PriceFloor({ type: PriceFloorType.Minimum }),
};

const { auction } = await makeAuction({
connection,
wallet,
vault,
auctionSettings,
});
expect(Boolean(auction)).not.toBeFalsy();
}, 50000);
});