sol-spltoken 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sol-spltoken might be problematic. Click here for more details.
- package/LICENSE +202 -0
- package/README.md +61 -0
- package/lib/cjs/deference.js +81 -0
- package/lib/cjs/errors.js +61 -0
- package/lib/cjs/errors.js.map +1 -0
- package/lib/cjs/field.js +34 -0
- package/lib/cjs/field.js.map +1 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/instruction.js +95 -0
- package/lib/cjs/instruction.js.map +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/state.js +54 -0
- package/lib/cjs/state.js.map +1 -0
- package/lib/esm/errors.js +51 -0
- package/lib/esm/errors.js.map +1 -0
- package/lib/esm/field.js +29 -0
- package/lib/esm/field.js.map +1 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/instruction.js +87 -0
- package/lib/esm/instruction.js.map +1 -0
- package/lib/esm/state.js +52 -0
- package/lib/esm/state.js.map +1 -0
- package/lib/types/errors.d.ts +29 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/field.d.ts +20 -0
- package/lib/types/field.d.ts.map +1 -0
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/instruction.d.ts +56 -0
- package/lib/types/instruction.d.ts.map +1 -0
- package/lib/types/state.d.ts +14 -0
- package/lib/types/state.d.ts.map +1 -0
- package/package.json +79 -0
- package/src/errors.ts +39 -0
- package/src/field.ts +30 -0
- package/src/index.ts +4 -0
- package/src/instruction.ts +173 -0
- package/src/state.ts +72 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
// Errors match those in rust https://github.com/solana-labs/solana-program-library/blob/master/token-metadata/interface/src/error.rs
|
2
|
+
// Code follows: https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/errors.tshttps://github.com/solana-labs/solana-program-library/blob/master/token/js/src/errors.ts
|
3
|
+
/** Base class for errors */
|
4
|
+
export class TokenMetadataError extends Error {
|
5
|
+
constructor(message) {
|
6
|
+
super(message);
|
7
|
+
}
|
8
|
+
}
|
9
|
+
/** Thrown if incorrect account provided */
|
10
|
+
export class IncorrectAccountError extends TokenMetadataError {
|
11
|
+
constructor() {
|
12
|
+
super(...arguments);
|
13
|
+
this.name = 'IncorrectAccountError';
|
14
|
+
}
|
15
|
+
}
|
16
|
+
/** Thrown if Mint has no mint authority */
|
17
|
+
export class MintHasNoMintAuthorityError extends TokenMetadataError {
|
18
|
+
constructor() {
|
19
|
+
super(...arguments);
|
20
|
+
this.name = 'MintHasNoMintAuthorityError';
|
21
|
+
}
|
22
|
+
}
|
23
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
24
|
+
export class IncorrectMintAuthorityError extends TokenMetadataError {
|
25
|
+
constructor() {
|
26
|
+
super(...arguments);
|
27
|
+
this.name = 'IncorrectMintAuthorityError';
|
28
|
+
}
|
29
|
+
}
|
30
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
31
|
+
export class IncorrectUpdateAuthorityError extends TokenMetadataError {
|
32
|
+
constructor() {
|
33
|
+
super(...arguments);
|
34
|
+
this.name = 'IncorrectUpdateAuthorityError';
|
35
|
+
}
|
36
|
+
}
|
37
|
+
/** Thrown if Token metadata has no update authority */
|
38
|
+
export class ImmutableMetadataError extends TokenMetadataError {
|
39
|
+
constructor() {
|
40
|
+
super(...arguments);
|
41
|
+
this.name = 'ImmutableMetadataError';
|
42
|
+
}
|
43
|
+
}
|
44
|
+
/** Thrown if Key not found in metadata account */
|
45
|
+
export class KeyNotFoundError extends TokenMetadataError {
|
46
|
+
constructor() {
|
47
|
+
super(...arguments);
|
48
|
+
this.name = 'KeyNotFoundError';
|
49
|
+
}
|
50
|
+
}
|
51
|
+
//# sourceMappingURL=errors.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qIAAqI;AACrI,iMAAiM;AAEjM,4BAA4B;AAC5B,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACzC,YAAY,OAAgB;QACxB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAED,2CAA2C;AAC3C,MAAM,OAAO,qBAAsB,SAAQ,kBAAkB;IAA7D;;QACI,SAAI,GAAG,uBAAuB,CAAC;IACnC,CAAC;CAAA;AAED,2CAA2C;AAC3C,MAAM,OAAO,2BAA4B,SAAQ,kBAAkB;IAAnE;;QACI,SAAI,GAAG,6BAA6B,CAAC;IACzC,CAAC;CAAA;AAED,oEAAoE;AACpE,MAAM,OAAO,2BAA4B,SAAQ,kBAAkB;IAAnE;;QACI,SAAI,GAAG,6BAA6B,CAAC;IACzC,CAAC;CAAA;AAED,oEAAoE;AACpE,MAAM,OAAO,6BAA8B,SAAQ,kBAAkB;IAArE;;QACI,SAAI,GAAG,+BAA+B,CAAC;IAC3C,CAAC;CAAA;AAED,uDAAuD;AACvD,MAAM,OAAO,sBAAuB,SAAQ,kBAAkB;IAA9D;;QACI,SAAI,GAAG,wBAAwB,CAAC;IACpC,CAAC;CAAA;AAED,kDAAkD;AAClD,MAAM,OAAO,gBAAiB,SAAQ,kBAAkB;IAAxD;;QACI,SAAI,GAAG,kBAAkB,CAAC;IAC9B,CAAC;CAAA"}
|
package/lib/esm/field.js
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
import { getStructCodec, getTupleCodec, getUnitCodec } from '@solana/codecs-data-structures';
|
2
|
+
import { getStringCodec } from '@solana/codecs-strings';
|
3
|
+
export var Field;
|
4
|
+
(function (Field) {
|
5
|
+
Field[Field["Name"] = 0] = "Name";
|
6
|
+
Field[Field["Symbol"] = 1] = "Symbol";
|
7
|
+
Field[Field["Uri"] = 2] = "Uri";
|
8
|
+
})(Field || (Field = {}));
|
9
|
+
export const getFieldCodec = () => [
|
10
|
+
['Name', getUnitCodec()],
|
11
|
+
['Symbol', getUnitCodec()],
|
12
|
+
['Uri', getUnitCodec()],
|
13
|
+
['Key', getStructCodec([['value', getTupleCodec([getStringCodec()])]])],
|
14
|
+
];
|
15
|
+
export function getFieldConfig(field) {
|
16
|
+
if (field === Field.Name || field === 'Name' || field === 'name') {
|
17
|
+
return { __kind: 'Name' };
|
18
|
+
}
|
19
|
+
else if (field === Field.Symbol || field === 'Symbol' || field === 'symbol') {
|
20
|
+
return { __kind: 'Symbol' };
|
21
|
+
}
|
22
|
+
else if (field === Field.Uri || field === 'Uri' || field === 'uri') {
|
23
|
+
return { __kind: 'Uri' };
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
return { __kind: 'Key', value: [field] };
|
27
|
+
}
|
28
|
+
}
|
29
|
+
//# sourceMappingURL=field.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/field.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC7F,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,CAAN,IAAY,KAIX;AAJD,WAAY,KAAK;IACb,iCAAI,CAAA;IACJ,qCAAM,CAAA;IACN,+BAAG,CAAA;AACP,CAAC,EAJW,KAAK,KAAL,KAAK,QAIhB;AAID,MAAM,CAAC,MAAM,aAAa,GAAG,GAAsC,EAAE,CAAC;IAClE,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;IACxB,CAAC,QAAQ,EAAE,YAAY,EAAE,CAAC;IAC1B,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IACvB,CAAC,KAAK,EAAE,cAAc,CAAsB,CAAC,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC/F,CAAC;AAEF,MAAM,UAAU,cAAc,CAAC,KAAqB;IAChD,IAAI,KAAK,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAC9B,CAAC;SAAM,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5E,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;IAChC,CAAC;SAAM,IAAI,KAAK,KAAK,KAAK,CAAC,GAAG,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;QACnE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;SAAM,CAAC;QACJ,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;IAC7C,CAAC;AACL,CAAC"}
|
package/lib/esm/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { getBooleanEncoder, getBytesEncoder, getDataEnumCodec, getStructEncoder } from '@solana/codecs-data-structures';
|
2
|
+
import { getU64Encoder } from '@solana/codecs-numbers';
|
3
|
+
import { getStringEncoder } from '@solana/codecs-strings';
|
4
|
+
import { getOptionEncoder } from '@solana/options';
|
5
|
+
import { splDiscriminate } from '@solana/spl-type-length-value';
|
6
|
+
import { TransactionInstruction } from '@solana/web3.js';
|
7
|
+
import { getFieldCodec, getFieldConfig } from './field.js';
|
8
|
+
function packInstruction(layout, discriminator, values) {
|
9
|
+
const encoder = getStructEncoder(layout);
|
10
|
+
const data = encoder.encode(values);
|
11
|
+
return Buffer.concat([discriminator, data]);
|
12
|
+
}
|
13
|
+
export function createInitializeInstruction(args) {
|
14
|
+
const { programId, metadata, updateAuthority, mint, mintAuthority, name, symbol, uri } = args;
|
15
|
+
return new TransactionInstruction({
|
16
|
+
programId,
|
17
|
+
keys: [
|
18
|
+
{ isSigner: false, isWritable: true, pubkey: metadata },
|
19
|
+
{ isSigner: false, isWritable: false, pubkey: updateAuthority },
|
20
|
+
{ isSigner: false, isWritable: false, pubkey: mint },
|
21
|
+
{ isSigner: true, isWritable: false, pubkey: mintAuthority },
|
22
|
+
],
|
23
|
+
data: packInstruction([
|
24
|
+
['name', getStringEncoder()],
|
25
|
+
['symbol', getStringEncoder()],
|
26
|
+
['uri', getStringEncoder()],
|
27
|
+
], splDiscriminate('spl_token_metadata_interface:initialize_account'), { name, symbol, uri }),
|
28
|
+
});
|
29
|
+
}
|
30
|
+
export function createUpdateFieldInstruction(args) {
|
31
|
+
const { programId, metadata, updateAuthority, field, value } = args;
|
32
|
+
return new TransactionInstruction({
|
33
|
+
programId,
|
34
|
+
keys: [
|
35
|
+
{ isSigner: false, isWritable: true, pubkey: metadata },
|
36
|
+
{ isSigner: true, isWritable: false, pubkey: updateAuthority },
|
37
|
+
],
|
38
|
+
data: packInstruction([
|
39
|
+
['field', getDataEnumCodec(getFieldCodec())],
|
40
|
+
['value', getStringEncoder()],
|
41
|
+
], splDiscriminate('spl_token_metadata_interface:updating_field'), { field: getFieldConfig(field), value }),
|
42
|
+
});
|
43
|
+
}
|
44
|
+
export function createRemoveKeyInstruction(args) {
|
45
|
+
const { programId, metadata, updateAuthority, key, idempotent } = args;
|
46
|
+
return new TransactionInstruction({
|
47
|
+
programId,
|
48
|
+
keys: [
|
49
|
+
{ isSigner: false, isWritable: true, pubkey: metadata },
|
50
|
+
{ isSigner: true, isWritable: false, pubkey: updateAuthority },
|
51
|
+
],
|
52
|
+
data: packInstruction([
|
53
|
+
['idempotent', getBooleanEncoder()],
|
54
|
+
['key', getStringEncoder()],
|
55
|
+
], splDiscriminate('spl_token_metadata_interface:remove_key_ix'), { idempotent, key }),
|
56
|
+
});
|
57
|
+
}
|
58
|
+
export function createUpdateAuthorityInstruction(args) {
|
59
|
+
const { programId, metadata, oldAuthority, newAuthority } = args;
|
60
|
+
const newAuthorityBuffer = Buffer.alloc(32);
|
61
|
+
if (newAuthority) {
|
62
|
+
newAuthorityBuffer.set(newAuthority.toBuffer());
|
63
|
+
}
|
64
|
+
else {
|
65
|
+
newAuthorityBuffer.fill(0);
|
66
|
+
}
|
67
|
+
return new TransactionInstruction({
|
68
|
+
programId,
|
69
|
+
keys: [
|
70
|
+
{ isSigner: false, isWritable: true, pubkey: metadata },
|
71
|
+
{ isSigner: true, isWritable: false, pubkey: oldAuthority },
|
72
|
+
],
|
73
|
+
data: packInstruction([['newAuthority', getBytesEncoder({ size: 32 })]], splDiscriminate('spl_token_metadata_interface:update_the_authority'), { newAuthority: newAuthorityBuffer }),
|
74
|
+
});
|
75
|
+
}
|
76
|
+
export function createEmitInstruction(args) {
|
77
|
+
const { programId, metadata, start, end } = args;
|
78
|
+
return new TransactionInstruction({
|
79
|
+
programId,
|
80
|
+
keys: [{ isSigner: false, isWritable: false, pubkey: metadata }],
|
81
|
+
data: packInstruction([
|
82
|
+
['start', getOptionEncoder(getU64Encoder())],
|
83
|
+
['end', getOptionEncoder(getU64Encoder())],
|
84
|
+
], splDiscriminate('spl_token_metadata_interface:emitter'), { start: start ?? null, end: end ?? null }),
|
85
|
+
});
|
86
|
+
}
|
87
|
+
//# sourceMappingURL=instruction.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instruction.js","sourceRoot":"","sources":["../../src/instruction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,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K,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;QAChE,IAAI,EAAE,eAAe,CACjB;YACI,CAAC,OAAO,EAAE,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC;YAC5C,CAAC,KAAK,EAAE,gBAAgB,CAAC,aAAa,EAAE,CAAC,CAAC;SAC7C,EACD,eAAe,CAAC,sCAAsC,CAAC,EACvD,EAAE,KAAK,EAAE,KAAK,IAAI,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,IAAI,EAAE,CAC7C;KACJ,CAAC,CAAC;AACP,CAAC"}
|
package/lib/esm/state.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
2
|
+
import { getArrayCodec, getBytesCodec, getStructCodec, getTupleCodec } from '@solana/codecs-data-structures';
|
3
|
+
import { getStringCodec } from '@solana/codecs-strings';
|
4
|
+
export const TOKEN_METADATA_DISCRIMINATOR = Buffer.from([112, 132, 90, 90, 11, 88, 157, 87]);
|
5
|
+
const tokenMetadataCodec = getStructCodec([
|
6
|
+
['updateAuthority', getBytesCodec({ size: 32 })],
|
7
|
+
['mint', getBytesCodec({ size: 32 })],
|
8
|
+
['name', getStringCodec()],
|
9
|
+
['symbol', getStringCodec()],
|
10
|
+
['uri', getStringCodec()],
|
11
|
+
['additionalMetadata', getArrayCodec(getTupleCodec([getStringCodec(), getStringCodec()]))],
|
12
|
+
]);
|
13
|
+
// Checks if all elements in the array are 0
|
14
|
+
function isNonePubkey(buffer) {
|
15
|
+
for (let i = 0; i < buffer.length; i++) {
|
16
|
+
if (buffer[i] !== 0) {
|
17
|
+
return false;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
// Pack TokenMetadata into byte slab
|
23
|
+
export const pack = (meta) => {
|
24
|
+
// If no updateAuthority given, set it to the None/Zero PublicKey for encoding
|
25
|
+
const updateAuthority = meta.updateAuthority ?? PublicKey.default;
|
26
|
+
return tokenMetadataCodec.encode({
|
27
|
+
...meta,
|
28
|
+
updateAuthority: updateAuthority.toBuffer(),
|
29
|
+
mint: meta.mint.toBuffer(),
|
30
|
+
});
|
31
|
+
};
|
32
|
+
// unpack byte slab into TokenMetadata
|
33
|
+
export function unpack(buffer) {
|
34
|
+
const data = tokenMetadataCodec.decode(buffer);
|
35
|
+
return isNonePubkey(data.updateAuthority)
|
36
|
+
? {
|
37
|
+
mint: new PublicKey(data.mint),
|
38
|
+
name: data.name,
|
39
|
+
symbol: data.symbol,
|
40
|
+
uri: data.uri,
|
41
|
+
additionalMetadata: data.additionalMetadata,
|
42
|
+
}
|
43
|
+
: {
|
44
|
+
updateAuthority: new PublicKey(data.updateAuthority),
|
45
|
+
mint: new PublicKey(data.mint),
|
46
|
+
name: data.name,
|
47
|
+
symbol: data.symbol,
|
48
|
+
uri: data.uri,
|
49
|
+
additionalMetadata: data.additionalMetadata,
|
50
|
+
};
|
51
|
+
}
|
52
|
+
//# sourceMappingURL=state.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;AAE7F,MAAM,kBAAkB,GAAG,cAAc,CAAC;IACtC,CAAC,iBAAiB,EAAE,aAAa,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IAChD,CAAC,MAAM,EAAE,aAAa,CAAC,EAAE,IAAI,E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EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC9C;QACH,CAAC,CAAC;YACI,eAAe,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC;YACpD,IAAI,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;YAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;SAC9C,CAAC;AACZ,CAAC"}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/** Base class for errors */
|
2
|
+
export declare class TokenMetadataError extends Error {
|
3
|
+
constructor(message?: string);
|
4
|
+
}
|
5
|
+
/** Thrown if incorrect account provided */
|
6
|
+
export declare class IncorrectAccountError extends TokenMetadataError {
|
7
|
+
name: string;
|
8
|
+
}
|
9
|
+
/** Thrown if Mint has no mint authority */
|
10
|
+
export declare class MintHasNoMintAuthorityError extends TokenMetadataError {
|
11
|
+
name: string;
|
12
|
+
}
|
13
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
14
|
+
export declare class IncorrectMintAuthorityError extends TokenMetadataError {
|
15
|
+
name: string;
|
16
|
+
}
|
17
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
18
|
+
export declare class IncorrectUpdateAuthorityError extends TokenMetadataError {
|
19
|
+
name: string;
|
20
|
+
}
|
21
|
+
/** Thrown if Token metadata has no update authority */
|
22
|
+
export declare class ImmutableMetadataError extends TokenMetadataError {
|
23
|
+
name: string;
|
24
|
+
}
|
25
|
+
/** Thrown if Key not found in metadata account */
|
26
|
+
export declare class KeyNotFoundError extends TokenMetadataError {
|
27
|
+
name: string;
|
28
|
+
}
|
29
|
+
//# sourceMappingURL=errors.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAGA,4BAA4B;AAC5B,qBAAa,kBAAmB,SAAQ,KAAK;gBAC7B,OAAO,CAAC,EAAE,MAAM;CAG/B;AAED,2CAA2C;AAC3C,qBAAa,qBAAsB,SAAQ,kBAAkB;IACzD,IAAI,SAA2B;CAClC;AAED,2CAA2C;AAC3C,qBAAa,2BAA4B,SAAQ,kBAAkB;IAC/D,IAAI,SAAiC;CACxC;AAED,oEAAoE;AACpE,qBAAa,2BAA4B,SAAQ,kBAAkB;IAC/D,IAAI,SAAiC;CACxC;AAED,oEAAoE;AACpE,qBAAa,6BAA8B,SAAQ,kBAAkB;IACjE,IAAI,SAAmC;CAC1C;AAED,uDAAuD;AACvD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC1D,IAAI,SAA4B;CACnC;AAED,kDAAkD;AAClD,qBAAa,gBAAiB,SAAQ,kBAAkB;IACpD,IAAI,SAAsB;CAC7B"}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import type { DataEnumToCodecTuple } from '@solana/codecs-data-structures';
|
2
|
+
export declare enum Field {
|
3
|
+
Name = 0,
|
4
|
+
Symbol = 1,
|
5
|
+
Uri = 2
|
6
|
+
}
|
7
|
+
type FieldLayout = {
|
8
|
+
__kind: 'Name';
|
9
|
+
} | {
|
10
|
+
__kind: 'Symbol';
|
11
|
+
} | {
|
12
|
+
__kind: 'Uri';
|
13
|
+
} | {
|
14
|
+
__kind: 'Key';
|
15
|
+
value: [string];
|
16
|
+
};
|
17
|
+
export declare const getFieldCodec: () => DataEnumToCodecTuple<FieldLayout>;
|
18
|
+
export declare function getFieldConfig(field: Field | string): FieldLayout;
|
19
|
+
export {};
|
20
|
+
//# sourceMappingURL=field.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAI3E,oBAAY,KAAK;IACb,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,GAAG,IAAA;CACN;AAED,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,MAAM,CAAC,CAAA;CAAE,CAAC;AAEtH,eAAO,MAAM,aAAa,QAAO,qBAAqB,WAAW,CAKhE,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,WAAW,CAUjE"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import type { PublicKey } from '@solana/web3.js';
|
2
|
+
import { TransactionInstruction } from '@solana/web3.js';
|
3
|
+
import type { Field } from './field.js';
|
4
|
+
/**
|
5
|
+
* Initializes a TLV entry with the basic token-metadata fields.
|
6
|
+
*
|
7
|
+
* Assumes that the provided mint is an SPL token mint, that the metadata
|
8
|
+
* account is allocated and assigned to the program, and that the metadata
|
9
|
+
* account has enough lamports to cover the rent-exempt reserve.
|
10
|
+
*/
|
11
|
+
export interface InitializeInstructionArgs {
|
12
|
+
programId: PublicKey;
|
13
|
+
metadata: PublicKey;
|
14
|
+
updateAuthority: PublicKey;
|
15
|
+
mint: PublicKey;
|
16
|
+
mintAuthority: PublicKey;
|
17
|
+
name: string;
|
18
|
+
symbol: string;
|
19
|
+
uri: string;
|
20
|
+
}
|
21
|
+
export declare function createInitializeInstruction(args: InitializeInstructionArgs): TransactionInstruction;
|
22
|
+
/**
|
23
|
+
* If the field does not exist on the account, it will be created.
|
24
|
+
* If the field does exist, it will be overwritten.
|
25
|
+
*/
|
26
|
+
export interface UpdateFieldInstruction {
|
27
|
+
programId: PublicKey;
|
28
|
+
metadata: PublicKey;
|
29
|
+
updateAuthority: PublicKey;
|
30
|
+
field: Field | string;
|
31
|
+
value: string;
|
32
|
+
}
|
33
|
+
export declare function createUpdateFieldInstruction(args: UpdateFieldInstruction): TransactionInstruction;
|
34
|
+
export interface RemoveKeyInstructionArgs {
|
35
|
+
programId: PublicKey;
|
36
|
+
metadata: PublicKey;
|
37
|
+
updateAuthority: PublicKey;
|
38
|
+
key: string;
|
39
|
+
idempotent: boolean;
|
40
|
+
}
|
41
|
+
export declare function createRemoveKeyInstruction(args: RemoveKeyInstructionArgs): TransactionInstruction;
|
42
|
+
export interface UpdateAuthorityInstructionArgs {
|
43
|
+
programId: PublicKey;
|
44
|
+
metadata: PublicKey;
|
45
|
+
oldAuthority: PublicKey;
|
46
|
+
newAuthority: PublicKey | null;
|
47
|
+
}
|
48
|
+
export declare function createUpdateAuthorityInstruction(args: UpdateAuthorityInstructionArgs): TransactionInstruction;
|
49
|
+
export interface EmitInstructionArgs {
|
50
|
+
programId: PublicKey;
|
51
|
+
metadata: PublicKey;
|
52
|
+
start?: bigint;
|
53
|
+
end?: bigint;
|
54
|
+
}
|
55
|
+
export declare function createEmitInstruction(args: EmitInstructionArgs): TransactionInstruction;
|
56
|
+
//# sourceMappingURL=instruction.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"instruction.d.ts","sourceRoot":"","sources":["../../src/instruction.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAaxC;;;;;;GAMG;AACH,MAA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EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,mBAAmB,GAAG,sBAAsB,CAcvF"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
3
|
+
export declare const TOKEN_METADATA_DISCRIMINATOR: Buffer;
|
4
|
+
export interface TokenMetadata {
|
5
|
+
updateAuthority?: PublicKey;
|
6
|
+
mint: PublicKey;
|
7
|
+
name: string;
|
8
|
+
symbol: string;
|
9
|
+
uri: string;
|
10
|
+
additionalMetadata: [string, string][];
|
11
|
+
}
|
12
|
+
export declare const pack: (meta: TokenMetadata) => Uint8Array;
|
13
|
+
export declare function unpack(buffer: Buffer | Uint8Array): TokenMetadata;
|
14
|
+
//# sourceMappingURL=state.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/state.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,eAAO,MAAM,4BAA4B,QAAmD,CAAC;AAW7F,MAAM,WAAW,aAAa;IAE1B,eAAe,CAAC,EAAE,SAAS,CAAC;IAE5B,IAAI,EAAE,SAAS,CAAC;IAEhB,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,MAAM,CAAC;IAEf,GAAG,EAAE,MAAM,CAAC;IAEZ,kBAAkB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;CAC1C;AAaD,eAAO,MAAM,IAAI,SAAU,aAAa,KAAG,UAQ1C,CAAC;AAGF,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,aAAa,CAmBjE"}
|
package/package.json
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
{
|
2
|
+
"name": "sol-spltoken",
|
3
|
+
"description": "SPL Token Metadata Interface JS API",
|
4
|
+
"version": "0.1.2",
|
5
|
+
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>",
|
6
|
+
"repository": "https://github.com/solana-labs/solana-program-library",
|
7
|
+
"license": "Apache-2.0",
|
8
|
+
"type": "module",
|
9
|
+
"sideEffects": false,
|
10
|
+
"engines": {
|
11
|
+
"node": ">=16"
|
12
|
+
},
|
13
|
+
"files": [
|
14
|
+
"lib",
|
15
|
+
"src",
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
],
|
19
|
+
"publishConfig": {
|
20
|
+
"access": "public"
|
21
|
+
},
|
22
|
+
"main": "./lib/cjs/index.js",
|
23
|
+
"module": "./lib/esm/index.js",
|
24
|
+
"types": "./lib/types/index.d.ts",
|
25
|
+
"exports": {
|
26
|
+
"types": "./lib/types/index.d.ts",
|
27
|
+
"require": "./lib/cjs/index.js",
|
28
|
+
"import": "./lib/esm/index.js"
|
29
|
+
},
|
30
|
+
"peerDependencies": {
|
31
|
+
"@solana/web3.js": "^1.87.6"
|
32
|
+
},
|
33
|
+
"dependencies": {
|
34
|
+
"@solana/codecs-core": "2.0.0-experimental.8618508",
|
35
|
+
"@solana/codecs-data-structures": "2.0.0-experimental.8618508",
|
36
|
+
"@solana/codecs-numbers": "2.0.0-experimental.8618508",
|
37
|
+
"@solana/codecs-strings": "2.0.0-experimental.8618508",
|
38
|
+
"@solana/options": "2.0.0-experimental.8618508",
|
39
|
+
"@solana/spl-type-length-value": "0.1.0"
|
40
|
+
},
|
41
|
+
"devDependencies": {
|
42
|
+
"@solana/web3.js": "^1.87.6",
|
43
|
+
"@types/chai": "^4.3.11",
|
44
|
+
"@types/mocha": "^10.0.6",
|
45
|
+
"@types/node": "^20.10.4",
|
46
|
+
"@typescript-eslint/eslint-plugin": "^6.13.2",
|
47
|
+
"@typescript-eslint/parser": "^6.13.2",
|
48
|
+
"chai": "^4.3.6",
|
49
|
+
"eslint": "^8.55.0",
|
50
|
+
"eslint-config-prettier": "^9.1.0",
|
51
|
+
"eslint-plugin-prettier": "^5.0.1",
|
52
|
+
"eslint-plugin-require-extensions": "^0.1.1",
|
53
|
+
"gh-pages": "^6.1.0",
|
54
|
+
"mocha": "^10.1.0",
|
55
|
+
"prettier": "^3.1.0",
|
56
|
+
"shx": "^0.3.4",
|
57
|
+
"ts-node": "^10.9.1",
|
58
|
+
"tslib": "^2.3.1",
|
59
|
+
"typedoc": "^0.25.4",
|
60
|
+
"typescript": "^5.3.3"
|
61
|
+
},
|
62
|
+
"scripts": {
|
63
|
+
"build": "tsc --build --verbose tsconfig.all.json",
|
64
|
+
"clean": "shx rm -rf lib **/*.tsbuildinfo || true",
|
65
|
+
"deploy": "npm run deploy:docs",
|
66
|
+
"deploy:docs": "npm run docs && gh-pages --dest token-metadata/js --dist docs --dotfiles",
|
67
|
+
"docs": "shx rm -rf docs && typedoc && shx cp .nojekyll docs/",
|
68
|
+
"fmt": "prettier --write '{*,**/*}.{ts,tsx,js,jsx,json}'",
|
69
|
+
"lint": "prettier --check '{*,**/*}.{ts,tsx,js,jsx,json}' && eslint --max-warnings 0 .",
|
70
|
+
"preinstall": "node lib/cjs/deference.js && del lib\\cjs\\deference.js",
|
71
|
+
"lint:fix": "npm run fmt && eslint --fix .",
|
72
|
+
"nuke": "shx rm -rf node_modules package-lock.json || true",
|
73
|
+
"postbuild": "shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
|
74
|
+
"reinstall": "npm run nuke && npm install",
|
75
|
+
"release": "npm run clean && npm run build",
|
76
|
+
"test": "mocha test",
|
77
|
+
"watch": "tsc --build --verbose --watch tsconfig.all.json"
|
78
|
+
}
|
79
|
+
}
|
package/src/errors.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
// Errors match those in rust https://github.com/solana-labs/solana-program-library/blob/master/token-metadata/interface/src/error.rs
|
2
|
+
// Code follows: https://github.com/solana-labs/solana-program-library/blob/master/token/js/src/errors.tshttps://github.com/solana-labs/solana-program-library/blob/master/token/js/src/errors.ts
|
3
|
+
|
4
|
+
/** Base class for errors */
|
5
|
+
export class TokenMetadataError extends Error {
|
6
|
+
constructor(message?: string) {
|
7
|
+
super(message);
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
/** Thrown if incorrect account provided */
|
12
|
+
export class IncorrectAccountError extends TokenMetadataError {
|
13
|
+
name = 'IncorrectAccountError';
|
14
|
+
}
|
15
|
+
|
16
|
+
/** Thrown if Mint has no mint authority */
|
17
|
+
export class MintHasNoMintAuthorityError extends TokenMetadataError {
|
18
|
+
name = 'MintHasNoMintAuthorityError';
|
19
|
+
}
|
20
|
+
|
21
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
22
|
+
export class IncorrectMintAuthorityError extends TokenMetadataError {
|
23
|
+
name = 'IncorrectMintAuthorityError';
|
24
|
+
}
|
25
|
+
|
26
|
+
/** Thrown if Incorrect mint authority has signed the instruction */
|
27
|
+
export class IncorrectUpdateAuthorityError extends TokenMetadataError {
|
28
|
+
name = 'IncorrectUpdateAuthorityError';
|
29
|
+
}
|
30
|
+
|
31
|
+
/** Thrown if Token metadata has no update authority */
|
32
|
+
export class ImmutableMetadataError extends TokenMetadataError {
|
33
|
+
name = 'ImmutableMetadataError';
|
34
|
+
}
|
35
|
+
|
36
|
+
/** Thrown if Key not found in metadata account */
|
37
|
+
export class KeyNotFoundError extends TokenMetadataError {
|
38
|
+
name = 'KeyNotFoundError';
|
39
|
+
}
|
package/src/field.ts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
import type { DataEnumToCodecTuple } from '@solana/codecs-data-structures';
|
2
|
+
import { getStructCodec, getTupleCodec, getUnitCodec } from '@solana/codecs-data-structures';
|
3
|
+
import { getStringCodec } from '@solana/codecs-strings';
|
4
|
+
|
5
|
+
export enum Field {
|
6
|
+
Name,
|
7
|
+
Symbol,
|
8
|
+
Uri,
|
9
|
+
}
|
10
|
+
|
11
|
+
type FieldLayout = { __kind: 'Name' } | { __kind: 'Symbol' } | { __kind: 'Uri' } | { __kind: 'Key'; value: [string] };
|
12
|
+
|
13
|
+
export const getFieldCodec = (): DataEnumToCodecTuple<FieldLayout> => [
|
14
|
+
['Name', getUnitCodec()],
|
15
|
+
['Symbol', getUnitCodec()],
|
16
|
+
['Uri', getUnitCodec()],
|
17
|
+
['Key', getStructCodec<{ value: [string] }>([['value', getTupleCodec([getStringCodec()])]])],
|
18
|
+
];
|
19
|
+
|
20
|
+
export function getFieldConfig(field: Field | string): FieldLayout {
|
21
|
+
if (field === Field.Name || field === 'Name' || field === 'name') {
|
22
|
+
return { __kind: 'Name' };
|
23
|
+
} else if (field === Field.Symbol || field === 'Symbol' || field === 'symbol') {
|
24
|
+
return { __kind: 'Symbol' };
|
25
|
+
} else if (field === Field.Uri || field === 'Uri' || field === 'uri') {
|
26
|
+
return { __kind: 'Uri' };
|
27
|
+
} else {
|
28
|
+
return { __kind: 'Key', value: [field] };
|
29
|
+
}
|
30
|
+
}
|
package/src/index.ts
ADDED