Last active
October 9, 2022 16:05
-
-
Save staccDOTsol/0387cff4263272e1bda5ee95fb341eac to your computer and use it in GitHub Desktop.
coping fixed price
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put this in this dir https://github.com/metaplex-foundation/metaplex-program-library/blob/master/fixed-price-sale/js/test/buy.test.ts | |
import test from 'tape'; | |
import { killStuckProcess, logDebug, sleep } from './utils'; | |
import { | |
createStore, | |
createPrerequisites, | |
initSellingResource, | |
createMarket, | |
mintTokenToAccount, | |
} from './actions'; | |
import { CreateMarketInstructionArgs, findTradeHistoryAddress } from '../src'; | |
import { PublicKey } from '@solana/web3.js'; | |
import { createBuyTransaction } from './transactions'; | |
import { BN } from 'bn.js'; | |
import { deprecated } from '@metaplex-foundation/mpl-token-metadata'; | |
killStuckProcess(); | |
test('create-market: success', async (t) => { | |
const { payer, connection, transactionHandler } = await createPrerequisites(); | |
console.log(1) | |
const store = await createStore({ | |
test: t, | |
transactionHandler, | |
payer, | |
connection, | |
params: { | |
name: 'Sto22re', | |
description: 'De22scription', | |
}, | |
}); | |
const { sellingResource, vault, vaultOwner, vaultOwnerBump, resourceMint } = | |
await initSellingResource({ | |
test: t, | |
transactionHandler, | |
payer, | |
connection, | |
store: store.publicKey, | |
maxSupply: 100, | |
}); | |
const startDate = Math.round(Date.now() / 1000) + 5; | |
const params: Omit<CreateMarketInstructionArgs, 'treasuryOwnerBump'> = { | |
name: 'Market', | |
description: '', | |
startDate, | |
endDate: startDate + 5 * 20, | |
mutable: true, | |
price: 0.001, | |
piecesInOneWallet: 1, | |
gatingConfig: null, | |
}; | |
const { market, treasuryHolder } = | |
await createMarket({ | |
test: t, | |
transactionHandler, | |
payer, | |
connection, | |
store: store.publicKey, | |
sellingResource: sellingResource.publicKey, | |
treasuryMint: new PublicKey("8HGyAAB1yoM1ttS7pXjHMa3dukTFGQggnFFH3hJZgzQh"), | |
params, | |
}); | |
const [tradeHistory, tradeHistoryBump] = await findTradeHistoryAddress( | |
payer.publicKey, | |
market.publicKey, | |
); | |
const { mint: newMint, mintAta } = await mintTokenToAccount({ | |
connection, | |
payer: payer.publicKey, | |
transactionHandler, | |
}); | |
logDebug('new mint', newMint.publicKey.toBase58()); | |
const newMintEdition = await deprecated.Edition.getPDA(newMint.publicKey); | |
const newMintMetadata = await deprecated.Metadata.getPDA(newMint.publicKey); | |
const resourceMintMasterEdition = await deprecated.Edition.getPDA(resourceMint.publicKey); | |
const resourceMintMetadata = await deprecated.Metadata.getPDA(resourceMint.publicKey); | |
const resourceMintEditionMarker = await deprecated.EditionMarker.getPDA( | |
resourceMint.publicKey, | |
new BN(1), | |
); | |
await sleep(1000); | |
const { tx: buyTx } = await createBuyTransaction({ | |
connection, | |
buyer: payer.publicKey, | |
userTokenAccount: new PublicKey("5ieyQ2td5SVJdBbQBWwKPME76QSEyfKRKrwKqq4ngMsz"), | |
resourceMintMetadata, | |
resourceMintEditionMarker, | |
resourceMintMasterEdition, | |
sellingResource: sellingResource.publicKey, | |
market: market.publicKey, | |
marketTreasuryHolder: treasuryHolder.publicKey, | |
vaultOwner, | |
tradeHistory, | |
tradeHistoryBump, | |
vault: vault.publicKey, | |
vaultOwnerBump, | |
newMint: newMint.publicKey, | |
newMintEdition, | |
newMintMetadata, | |
newTokenAccount: mintAta.publicKey, | |
}); | |
const buyRes = await transactionHandler.sendAndConfirmTransaction( | |
buyTx, | |
[payer], | |
{skipPreflight: true, | |
maxRetries: 99 | |
} | |
); | |
console.log(buyRes) | |
logDebug('buy:: successful purchase'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment