Skip to content

Commit 45a97b2

Browse files
authored
chore: fixed-price upgrade spl-token dep to 0.2.0 (metaplex-foundation#304)
* token-vault: update to use new spl-token API * token-metadata: move test consts to avoid circular ref * token-metadata: update to new spl-token API * deps: upgrade spl-token to latest except for fixed-price and core - we had linked it so far to adapt API - core is using this library only for `TokenAccount` wrapper - TokenAccount wrapper is only used by fixed-price at this point and by token-metadata but only until the SDK is revamped (which is WIP) * core: deprecated TokenAcccount and remove spl dep * metaplex: replace type + const removed from token-vault * fixed-price: add mpl-core dep * fixed-price: fix type error in test helper * fixed-price: remove extranous parameter for test transaction * fixed-price: removed unneeded `await`s in test transactions * fixed-price: adding test and test-utils updates (currently some failing) * fixed-price: upgrade spl-token package and annotate invalid type errors * nit: removing stray todo comment which was fixed
1 parent e93c2a5 commit 45a97b2

File tree

12 files changed

+45
-72
lines changed

12 files changed

+45
-72
lines changed

fixed-price-sale/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@metaplex-foundation/beet": "^0.0.8",
4242
"@metaplex-foundation/beet-solana": "^0.0.6",
4343
"@metaplex-foundation/mpl-core": "^0.0.5",
44-
"@solana/spl-token": "^0.1.8",
44+
"@solana/spl-token": "^0.2.0",
4545
"@solana/web3.js": "^1.35.1"
4646
},
4747
"devDependencies": {

fixed-price-sale/js/test/actions/createMintAccount.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { strict as assert } from 'assert';
2-
import { MintLayout, Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
2+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3+
// @ts-ignore createInitializeMintInstruction export actually exist but isn't setup correctly
4+
import { createInitializeMintInstruction, MintLayout, TOKEN_PROGRAM_ID } from '@solana/spl-token';
35
import {
46
Connection,
57
Keypair,
@@ -40,8 +42,7 @@ export class CreateMint extends Transaction {
4042
);
4143

4244
this.add(
43-
Token.createInitMintInstruction(
44-
TOKEN_PROGRAM_ID,
45+
createInitializeMintInstruction(
4546
newAccountPubkey,
4647
decimals ?? 0,
4748
owner ?? feePayer,

fixed-price-sale/js/test/actions/initSellingResource.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export const initSellingResource = async ({
104104

105105
const { savePrimaryMetadataCreatorsInstruction, primaryMetadataCreators } =
106106
await createSavePrimaryMetadataCreators({
107-
test,
108107
transactionHandler,
109108
payer,
110109
connection,

fixed-price-sale/js/test/actions/mintNft.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import {
1212
CreateMasterEdition,
1313
Creator,
1414
} from '@metaplex-foundation/mpl-token-metadata';
15-
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
15+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
16+
// @ts-ignore createMintToInstruction export actually exist but isn't setup correctly
17+
import { createMintToInstruction } from '@solana/spl-token';
1618
import { strict as assert } from 'assert';
1719

1820
import { createTokenAccount } from '../transactions/createTokenAccount';
@@ -47,14 +49,7 @@ export async function mintNFT({ transactionHandler, payer, connection, creators
4749
});
4850

4951
createTokenTx.add(
50-
Token.createMintToInstruction(
51-
new PublicKey(TOKEN_PROGRAM_ID),
52-
mint.publicKey,
53-
tokenAccount.publicKey,
54-
payer.publicKey,
55-
[],
56-
1,
57-
),
52+
createMintToInstruction(mint.publicKey, tokenAccount.publicKey, payer.publicKey, 1),
5853
);
5954

6055
const associatedTokenAccountRes = await transactionHandler.sendAndConfirmTransaction(

fixed-price-sale/js/test/actions/mintTokenToAccount.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Connection, PublicKey, Transaction } from '@solana/web3.js';
2-
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
2+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3+
// @ts-ignore createMintToInstruction export actually exist but isn't setup correctly
4+
import { createMintToInstruction } from '@solana/spl-token';
35
import { defaultSendOptions, TransactionHandler } from '@metaplex-foundation/amman';
46

57
import { CreateMint } from './createMintAccount';
@@ -30,16 +32,7 @@ export const mintTokenToAccount = async ({
3032

3133
tx.add(createTokenTx);
3234

33-
tx.add(
34-
Token.createMintToInstruction(
35-
new PublicKey(TOKEN_PROGRAM_ID),
36-
mint.publicKey,
37-
associatedTokenAccount.publicKey,
38-
payer,
39-
[],
40-
1,
41-
),
42-
);
35+
tx.add(createMintToInstruction(mint.publicKey, associatedTokenAccount.publicKey, payer, 1));
4336

4437
await transactionHandler.sendAndConfirmTransaction(
4538
tx,

fixed-price-sale/js/test/claimResource.test.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import BN from 'bn.js';
22
import test from 'tape';
3-
import { ASSOCIATED_TOKEN_PROGRAM_ID, Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
3+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4+
// @ts-ignore these exports actually exist but aren't setup correctly
5+
import { getAccount, getAssociatedTokenAddress } from '@solana/spl-token';
46
import {
57
assertConfirmedTransaction,
68
assertError,
@@ -163,12 +165,7 @@ test('claim resource: success', async (t) => {
163165
payer.publicKey,
164166
);
165167

166-
const destination = await Token.getAssociatedTokenAddress(
167-
ASSOCIATED_TOKEN_PROGRAM_ID,
168-
TOKEN_PROGRAM_ID,
169-
treasuryMint.publicKey,
170-
payer.publicKey,
171-
);
168+
const destination = await getAssociatedTokenAddress(treasuryMint.publicKey, payer.publicKey);
172169

173170
const metadata = await Metadata.getPDA(resourceMint.publicKey);
174171

@@ -231,8 +228,7 @@ test('claim resource: success', async (t) => {
231228

232229
assertConfirmedTransaction(t, claimResourceRes.txConfirmed);
233230

234-
const token = new Token(connection, resourceMint.publicKey, TOKEN_PROGRAM_ID, payer);
235-
const createdToken = await token.getAccountInfo(claimToken.publicKey);
231+
const createdToken = await getAccount(connection, claimToken.publicKey);
236232

237233
t.assert(createdToken.mint.toBase58() === resourceMint.publicKey.toBase58());
238234
t.assert(createdToken.owner.toBase58() === payer.publicKey.toBase58());

fixed-price-sale/js/test/transactions/buy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const createBuyTransaction = async ({
4444
newMintMetadata,
4545
newTokenAccount,
4646
}: BuyParams) => {
47-
const instruction = await createBuyInstruction(
47+
const instruction = createBuyInstruction(
4848
{
4949
// buyer wallet
5050
userWallet: buyer,

fixed-price-sale/js/test/transactions/claimResource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const createClaimResourceTransaction = async ({
2828
vaultOwnerBump,
2929
owner,
3030
}: ClaimResourceParams): Promise<Transaction> => {
31-
const instruction = await createClaimResourceInstruction(
31+
const instruction = createClaimResourceInstruction(
3232
{
3333
market,
3434
treasuryHolder,

fixed-price-sale/js/test/transactions/createSavePrimaryMetadataCreators.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import test from 'tape';
21
import { PayerTransactionHandler } from '@metaplex-foundation/amman';
32
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
43

54
import { CreatorAccountData, findPrimaryMetadataCreatorsAddress } from '../../src';
65
import { createSavePrimaryMetadataCreatorsInstruction } from '../../src/generated/instructions/savePrimaryMetadataCreators';
76

87
type CreateSecondaryMetadataCreatorsParams = {
9-
test: test.Test;
108
transactionHandler: PayerTransactionHandler;
119
payer: Keypair;
1210
connection: Connection;

fixed-price-sale/js/test/transactions/createTokenAccount.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Connection, Keypair, PublicKey, SystemProgram, Transaction } from '@solana/web3.js';
2-
import { AccountLayout, Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
2+
import {
3+
AccountLayout,
4+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5+
// @ts-ignore createInitializeAccountInstruction export actually exist but isn't setup correctly
6+
createInitializeAccountInstruction,
7+
TOKEN_PROGRAM_ID,
8+
} from '@solana/spl-token';
39

410
export const createTokenAccount = async ({
511
payer,
@@ -29,12 +35,7 @@ export const createTokenAccount = async ({
2935
);
3036

3137
createTokenTx.add(
32-
Token.createInitAccountInstruction(
33-
new PublicKey(TOKEN_PROGRAM_ID),
34-
mint,
35-
tokenAccount.publicKey,
36-
owner ?? payer,
37-
),
38+
createInitializeAccountInstruction(tokenAccount.publicKey, mint, owner ?? payer),
3839
);
3940

4041
createTokenTx.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;

0 commit comments

Comments
 (0)