@solana/spl-token-group
Advanced tools
Comparing version 0.0.1 to 0.0.2
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createInitializeMemberInstruction = exports.createUpdateGroupAuthorityInstruction = exports.createUpdateGroupMaxSizeInstruction = exports.createInitializeGroupInstruction = void 0; | ||
const codecs_data_structures_1 = require("@solana/codecs-data-structures"); | ||
const codecs_numbers_1 = require("@solana/codecs-numbers"); | ||
const codecs_1 = require("@solana/codecs"); | ||
const spl_type_length_value_1 = require("@solana/spl-type-length-value"); | ||
const web3_js_1 = require("@solana/web3.js"); | ||
function packInstruction(layout, discriminator, values) { | ||
const encoder = (0, codecs_data_structures_1.getStructEncoder)(layout); | ||
const data = encoder.encode(values); | ||
return Buffer.concat([discriminator, data]); | ||
function getInstructionEncoder(discriminator, dataEncoder) { | ||
return (0, codecs_1.mapEncoder)((0, codecs_1.getTupleEncoder)([(0, codecs_1.getBytesEncoder)(), dataEncoder]), (data) => [ | ||
discriminator, | ||
data, | ||
]); | ||
} | ||
function getPublicKeyEncoder() { | ||
return (0, codecs_1.mapEncoder)((0, codecs_1.getBytesEncoder)({ size: 32 }), (publicKey) => publicKey.toBytes()); | ||
} | ||
function createInitializeGroupInstruction(args) { | ||
const { programId, group, mint, mintAuthority, updateAuthority, maxSize } = args; | ||
const updateAuthorityBuffer = Buffer.alloc(32); | ||
if (updateAuthority) { | ||
updateAuthorityBuffer.set(updateAuthority.toBuffer()); | ||
} | ||
else { | ||
updateAuthorityBuffer.fill(0); | ||
} | ||
return new web3_js_1.TransactionInstruction({ | ||
@@ -29,6 +25,6 @@ programId, | ||
], | ||
data: packInstruction([ | ||
['updateAuthority', (0, codecs_data_structures_1.getBytesEncoder)({ size: 32 })], | ||
['maxSize', (0, codecs_numbers_1.getU32Encoder)()], | ||
], (0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:initialize_token_group'), { updateAuthority: updateAuthorityBuffer, maxSize }), | ||
data: Buffer.from(getInstructionEncoder((0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:initialize_token_group'), (0, codecs_1.getStructEncoder)([ | ||
['updateAuthority', getPublicKeyEncoder()], | ||
['maxSize', (0, codecs_1.getU32Encoder)()], | ||
])).encode({ updateAuthority: updateAuthority !== null && updateAuthority !== void 0 ? updateAuthority : web3_js_1.SystemProgram.programId, maxSize })), | ||
}); | ||
@@ -45,3 +41,3 @@ } | ||
], | ||
data: packInstruction([['maxSize', (0, codecs_numbers_1.getU32Encoder)()]], (0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:update_group_max_size'), { maxSize }), | ||
data: Buffer.from(getInstructionEncoder((0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:update_group_max_size'), (0, codecs_1.getStructEncoder)([['maxSize', (0, codecs_1.getU32Encoder)()]])).encode({ maxSize })), | ||
}); | ||
@@ -52,9 +48,2 @@ } | ||
const { programId, group, currentAuthority, newAuthority } = args; | ||
const newAuthorityBuffer = Buffer.alloc(32); | ||
if (newAuthority) { | ||
newAuthorityBuffer.set(newAuthority.toBuffer()); | ||
} | ||
else { | ||
newAuthorityBuffer.fill(0); | ||
} | ||
return new web3_js_1.TransactionInstruction({ | ||
@@ -66,3 +55,3 @@ programId, | ||
], | ||
data: packInstruction([['newAuthority', (0, codecs_data_structures_1.getBytesEncoder)({ size: 32 })]], (0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:update_authority'), { newAuthority: newAuthorityBuffer }), | ||
data: Buffer.from(getInstructionEncoder((0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:update_authority'), (0, codecs_1.getStructEncoder)([['newAuthority', getPublicKeyEncoder()]])).encode({ newAuthority: newAuthority !== null && newAuthority !== void 0 ? newAuthority : web3_js_1.SystemProgram.programId })), | ||
}); | ||
@@ -82,3 +71,3 @@ } | ||
], | ||
data: packInstruction([], (0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:initialize_member'), {}), | ||
data: Buffer.from(getInstructionEncoder((0, spl_type_length_value_1.splDiscriminate)('spl_token_group_interface:initialize_member'), (0, codecs_1.getStructEncoder)([])).encode({})), | ||
}); | ||
@@ -85,0 +74,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unpackTokenGroup = exports.packTokenGroup = void 0; | ||
exports.unpackTokenGroup = exports.packTokenGroup = exports.TOKEN_GROUP_SIZE = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const codecs_data_structures_1 = require("@solana/codecs-data-structures"); | ||
const codecs_numbers_1 = require("@solana/codecs-numbers"); | ||
const tokenGroupCodec = (0, codecs_data_structures_1.getStructCodec)([ | ||
['updateAuthority', (0, codecs_data_structures_1.getBytesCodec)({ size: 32 })], | ||
['mint', (0, codecs_data_structures_1.getBytesCodec)({ size: 32 })], | ||
['size', (0, codecs_numbers_1.getU32Codec)()], | ||
['maxSize', (0, codecs_numbers_1.getU32Codec)()], | ||
const codecs_1 = require("@solana/codecs"); | ||
const tokenGroupCodec = (0, codecs_1.getStructCodec)([ | ||
['updateAuthority', (0, codecs_1.getBytesCodec)({ size: 32 })], | ||
['mint', (0, codecs_1.getBytesCodec)({ size: 32 })], | ||
['size', (0, codecs_1.getU32Codec)()], | ||
['maxSize', (0, codecs_1.getU32Codec)()], | ||
]); | ||
exports.TOKEN_GROUP_SIZE = tokenGroupCodec.fixedSize; | ||
// Checks if all elements in the array are 0 | ||
@@ -14,0 +14,0 @@ function isNonePubkey(buffer) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.unpackTokenGroupMember = exports.packTokenGroupMember = void 0; | ||
exports.unpackTokenGroupMember = exports.packTokenGroupMember = exports.TOKEN_GROUP_MEMBER_SIZE = void 0; | ||
const web3_js_1 = require("@solana/web3.js"); | ||
const codecs_data_structures_1 = require("@solana/codecs-data-structures"); | ||
const codecs_numbers_1 = require("@solana/codecs-numbers"); | ||
const tokenGroupMemberCodec = (0, codecs_data_structures_1.getStructCodec)([ | ||
['mint', (0, codecs_data_structures_1.getBytesCodec)({ size: 32 })], | ||
['group', (0, codecs_data_structures_1.getBytesCodec)({ size: 32 })], | ||
['memberNumber', (0, codecs_numbers_1.getU32Codec)()], | ||
const codecs_1 = require("@solana/codecs"); | ||
const tokenGroupMemberCodec = (0, codecs_1.getStructCodec)([ | ||
['mint', (0, codecs_1.getBytesCodec)({ size: 32 })], | ||
['group', (0, codecs_1.getBytesCodec)({ size: 32 })], | ||
['memberNumber', (0, codecs_1.getU32Codec)()], | ||
]); | ||
exports.TOKEN_GROUP_MEMBER_SIZE = tokenGroupMemberCodec.fixedSize; | ||
// Pack TokenGroupMember into byte slab | ||
@@ -13,0 +13,0 @@ function packTokenGroupMember(member) { |
@@ -1,19 +0,15 @@ | ||
import { getBytesEncoder, getStructEncoder } from '@solana/codecs-data-structures'; | ||
import { getU32Encoder } from '@solana/codecs-numbers'; | ||
import { getBytesEncoder, getStructEncoder, getTupleEncoder, getU32Encoder, mapEncoder } from '@solana/codecs'; | ||
import { splDiscriminate } from '@solana/spl-type-length-value'; | ||
import { TransactionInstruction } from '@solana/web3.js'; | ||
function packInstruction(layout, discriminator, values) { | ||
const encoder = getStructEncoder(layout); | ||
const data = encoder.encode(values); | ||
return Buffer.concat([discriminator, data]); | ||
import { SystemProgram, TransactionInstruction } from '@solana/web3.js'; | ||
function getInstructionEncoder(discriminator, dataEncoder) { | ||
return mapEncoder(getTupleEncoder([getBytesEncoder(), dataEncoder]), (data) => [ | ||
discriminator, | ||
data, | ||
]); | ||
} | ||
function getPublicKeyEncoder() { | ||
return mapEncoder(getBytesEncoder({ size: 32 }), (publicKey) => publicKey.toBytes()); | ||
} | ||
export function createInitializeGroupInstruction(args) { | ||
const { programId, group, mint, mintAuthority, updateAuthority, maxSize } = args; | ||
const updateAuthorityBuffer = Buffer.alloc(32); | ||
if (updateAuthority) { | ||
updateAuthorityBuffer.set(updateAuthority.toBuffer()); | ||
} | ||
else { | ||
updateAuthorityBuffer.fill(0); | ||
} | ||
return new TransactionInstruction({ | ||
@@ -26,6 +22,6 @@ programId, | ||
], | ||
data: packInstruction([ | ||
['updateAuthority', getBytesEncoder({ size: 32 })], | ||
data: Buffer.from(getInstructionEncoder(splDiscriminate('spl_token_group_interface:initialize_token_group'), getStructEncoder([ | ||
['updateAuthority', getPublicKeyEncoder()], | ||
['maxSize', getU32Encoder()], | ||
], splDiscriminate('spl_token_group_interface:initialize_token_group'), { updateAuthority: updateAuthorityBuffer, maxSize }), | ||
])).encode({ updateAuthority: updateAuthority ?? SystemProgram.programId, maxSize })), | ||
}); | ||
@@ -41,3 +37,3 @@ } | ||
], | ||
data: packInstruction([['maxSize', getU32Encoder()]], splDiscriminate('spl_token_group_interface:update_group_max_size'), { maxSize }), | ||
data: Buffer.from(getInstructionEncoder(splDiscriminate('spl_token_group_interface:update_group_max_size'), getStructEncoder([['maxSize', getU32Encoder()]])).encode({ maxSize })), | ||
}); | ||
@@ -47,9 +43,2 @@ } | ||
const { programId, group, currentAuthority, newAuthority } = args; | ||
const newAuthorityBuffer = Buffer.alloc(32); | ||
if (newAuthority) { | ||
newAuthorityBuffer.set(newAuthority.toBuffer()); | ||
} | ||
else { | ||
newAuthorityBuffer.fill(0); | ||
} | ||
return new TransactionInstruction({ | ||
@@ -61,3 +50,3 @@ programId, | ||
], | ||
data: packInstruction([['newAuthority', getBytesEncoder({ size: 32 })]], splDiscriminate('spl_token_group_interface:update_authority'), { newAuthority: newAuthorityBuffer }), | ||
data: Buffer.from(getInstructionEncoder(splDiscriminate('spl_token_group_interface:update_authority'), getStructEncoder([['newAuthority', getPublicKeyEncoder()]])).encode({ newAuthority: newAuthority ?? SystemProgram.programId })), | ||
}); | ||
@@ -76,5 +65,5 @@ } | ||
], | ||
data: packInstruction([], splDiscriminate('spl_token_group_interface:initialize_member'), {}), | ||
data: Buffer.from(getInstructionEncoder(splDiscriminate('spl_token_group_interface:initialize_member'), getStructEncoder([])).encode({})), | ||
}); | ||
} | ||
//# sourceMappingURL=instruction.js.map |
import { PublicKey } from '@solana/web3.js'; | ||
import { getBytesCodec, getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU32Codec } from '@solana/codecs-numbers'; | ||
import { getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs'; | ||
const tokenGroupCodec = getStructCodec([ | ||
@@ -10,2 +9,3 @@ ['updateAuthority', getBytesCodec({ size: 32 })], | ||
]); | ||
export const TOKEN_GROUP_SIZE = tokenGroupCodec.fixedSize; | ||
// Checks if all elements in the array are 0 | ||
@@ -12,0 +12,0 @@ function isNonePubkey(buffer) { |
import { PublicKey } from '@solana/web3.js'; | ||
import { getBytesCodec, getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU32Codec } from '@solana/codecs-numbers'; | ||
import { getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs'; | ||
const tokenGroupMemberCodec = getStructCodec([ | ||
@@ -9,2 +8,3 @@ ['mint', getBytesCodec({ size: 32 })], | ||
]); | ||
export const TOKEN_GROUP_MEMBER_SIZE = tokenGroupMemberCodec.fixedSize; | ||
// Pack TokenGroupMember into byte slab | ||
@@ -11,0 +11,0 @@ export function packTokenGroupMember(member) { |
/// <reference types="node" /> | ||
import { PublicKey } from '@solana/web3.js'; | ||
export declare const TOKEN_GROUP_SIZE: number; | ||
export interface TokenGroup { | ||
@@ -4,0 +5,0 @@ /** The authority that can sign to update the group */ |
/// <reference types="node" /> | ||
import { PublicKey } from '@solana/web3.js'; | ||
export declare const TOKEN_GROUP_MEMBER_SIZE: number; | ||
export interface TokenGroupMember { | ||
@@ -4,0 +5,0 @@ /** The associated mint, used to counter spoofing to be sure that member belongs to a particular mint */ |
{ | ||
"name": "@solana/spl-token-group", | ||
"description": "SPL Token Group Interface JS API", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"author": "Solana Labs Maintainers <maintainers@solanalabs.com>", | ||
@@ -31,31 +31,28 @@ "repository": "https://github.com/solana-labs/solana-program-library", | ||
"peerDependencies": { | ||
"@solana/web3.js": "^1.87.6" | ||
"@solana/web3.js": "^1.91.1" | ||
}, | ||
"dependencies": { | ||
"@solana/codecs-data-structures": "2.0.0-experimental.9741939", | ||
"@solana/codecs-numbers": "2.0.0-experimental.9741939", | ||
"@solana/codecs-strings": "2.0.0-experimental.9741939", | ||
"@solana/options": "2.0.0-experimental.9741939", | ||
"@solana/codecs": "2.0.0-preview.2", | ||
"@solana/spl-type-length-value": "0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@solana/web3.js": "^1.87.6", | ||
"@types/chai": "^4.3.11", | ||
"@solana/web3.js": "^1.91.1", | ||
"@types/chai": "^4.3.14", | ||
"@types/mocha": "^10.0.6", | ||
"@types/node": "^20.10.4", | ||
"@typescript-eslint/eslint-plugin": "^6.14.0", | ||
"@typescript-eslint/parser": "^6.14.0", | ||
"chai": "^4.3.6", | ||
"eslint": "^8.55.0", | ||
"@types/node": "^20.11.30", | ||
"@typescript-eslint/eslint-plugin": "^7.3.1", | ||
"@typescript-eslint/parser": "^7.3.1", | ||
"chai": "^5.1.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-require-extensions": "^0.1.1", | ||
"gh-pages": "^6.1.0", | ||
"mocha": "^10.1.0", | ||
"prettier": "^3.1.1", | ||
"gh-pages": "^6.1.1", | ||
"mocha": "^10.3.0", | ||
"prettier": "^3.2.5", | ||
"shx": "^0.3.4", | ||
"ts-node": "^10.9.2", | ||
"tslib": "^2.3.1", | ||
"typedoc": "^0.25.4", | ||
"typescript": "^5.3.3" | ||
"typedoc": "^0.25.12", | ||
"typescript": "^5.4.3" | ||
}, | ||
@@ -62,0 +59,0 @@ "scripts": { |
@@ -1,18 +0,18 @@ | ||
import type { StructToEncoderTuple } from '@solana/codecs-data-structures'; | ||
import type { Encoder } from '@solana/codecs'; | ||
import type { PublicKey } from '@solana/web3.js'; | ||
import { getBytesEncoder, getStructEncoder } from '@solana/codecs-data-structures'; | ||
import { getU32Encoder } from '@solana/codecs-numbers'; | ||
import { getBytesEncoder, getStructEncoder, getTupleEncoder, getU32Encoder, mapEncoder } from '@solana/codecs'; | ||
import { splDiscriminate } from '@solana/spl-type-length-value'; | ||
import { TransactionInstruction } from '@solana/web3.js'; | ||
import { SystemProgram, TransactionInstruction } from '@solana/web3.js'; | ||
function packInstruction<T extends object>( | ||
layout: StructToEncoderTuple<T>, | ||
discriminator: Uint8Array, | ||
values: T | ||
): Buffer { | ||
const encoder = getStructEncoder(layout); | ||
const data = encoder.encode(values); | ||
return Buffer.concat([discriminator, data]); | ||
function getInstructionEncoder<T extends object>(discriminator: Uint8Array, dataEncoder: Encoder<T>): Encoder<T> { | ||
return mapEncoder(getTupleEncoder([getBytesEncoder(), dataEncoder]), (data: T): [Uint8Array, T] => [ | ||
discriminator, | ||
data, | ||
]); | ||
} | ||
function getPublicKeyEncoder(): Encoder<PublicKey> { | ||
return mapEncoder(getBytesEncoder({ size: 32 }), (publicKey: PublicKey) => publicKey.toBytes()); | ||
} | ||
export interface InitializeGroupInstruction { | ||
@@ -30,9 +30,2 @@ programId: PublicKey; | ||
const updateAuthorityBuffer = Buffer.alloc(32); | ||
if (updateAuthority) { | ||
updateAuthorityBuffer.set(updateAuthority.toBuffer()); | ||
} else { | ||
updateAuthorityBuffer.fill(0); | ||
} | ||
return new TransactionInstruction({ | ||
@@ -45,9 +38,10 @@ programId, | ||
], | ||
data: packInstruction( | ||
[ | ||
['updateAuthority', getBytesEncoder({ size: 32 })], | ||
['maxSize', getU32Encoder()], | ||
], | ||
splDiscriminate('spl_token_group_interface:initialize_token_group'), | ||
{ updateAuthority: updateAuthorityBuffer, maxSize } | ||
data: Buffer.from( | ||
getInstructionEncoder( | ||
splDiscriminate('spl_token_group_interface:initialize_token_group'), | ||
getStructEncoder([ | ||
['updateAuthority', getPublicKeyEncoder()], | ||
['maxSize', getU32Encoder()], | ||
]) | ||
).encode({ updateAuthority: updateAuthority ?? SystemProgram.programId, maxSize }) | ||
), | ||
@@ -72,6 +66,7 @@ }); | ||
], | ||
data: packInstruction( | ||
[['maxSize', getU32Encoder()]], | ||
splDiscriminate('spl_token_group_interface:update_group_max_size'), | ||
{ maxSize } | ||
data: Buffer.from( | ||
getInstructionEncoder( | ||
splDiscriminate('spl_token_group_interface:update_group_max_size'), | ||
getStructEncoder([['maxSize', getU32Encoder()]]) | ||
).encode({ maxSize }) | ||
), | ||
@@ -91,9 +86,2 @@ }); | ||
const newAuthorityBuffer = Buffer.alloc(32); | ||
if (newAuthority) { | ||
newAuthorityBuffer.set(newAuthority.toBuffer()); | ||
} else { | ||
newAuthorityBuffer.fill(0); | ||
} | ||
return new TransactionInstruction({ | ||
@@ -105,6 +93,7 @@ programId, | ||
], | ||
data: packInstruction( | ||
[['newAuthority', getBytesEncoder({ size: 32 })]], | ||
splDiscriminate('spl_token_group_interface:update_authority'), | ||
{ newAuthority: newAuthorityBuffer } | ||
data: Buffer.from( | ||
getInstructionEncoder( | ||
splDiscriminate('spl_token_group_interface:update_authority'), | ||
getStructEncoder([['newAuthority', getPublicKeyEncoder()]]) | ||
).encode({ newAuthority: newAuthority ?? SystemProgram.programId }) | ||
), | ||
@@ -135,4 +124,9 @@ }); | ||
], | ||
data: packInstruction([], splDiscriminate('spl_token_group_interface:initialize_member'), {}), | ||
data: Buffer.from( | ||
getInstructionEncoder( | ||
splDiscriminate('spl_token_group_interface:initialize_member'), | ||
getStructEncoder([]) | ||
).encode({}) | ||
), | ||
}); | ||
} |
import { PublicKey } from '@solana/web3.js'; | ||
import { getBytesCodec, getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU32Codec } from '@solana/codecs-numbers'; | ||
import { getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs'; | ||
@@ -12,2 +11,4 @@ const tokenGroupCodec = getStructCodec([ | ||
export const TOKEN_GROUP_SIZE = tokenGroupCodec.fixedSize; | ||
export interface TokenGroup { | ||
@@ -14,0 +15,0 @@ /** The authority that can sign to update the group */ |
import { PublicKey } from '@solana/web3.js'; | ||
import { getBytesCodec, getStructCodec } from '@solana/codecs-data-structures'; | ||
import { getU32Codec } from '@solana/codecs-numbers'; | ||
import { getBytesCodec, getStructCodec, getU32Codec } from '@solana/codecs'; | ||
@@ -11,2 +10,4 @@ const tokenGroupMemberCodec = getStructCodec([ | ||
export const TOKEN_GROUP_MEMBER_SIZE = tokenGroupMemberCodec.fixedSize; | ||
export interface TokenGroupMember { | ||
@@ -13,0 +14,0 @@ /** The associated mint, used to counter spoofing to be sure that member belongs to a particular mint */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
63820
760
+ Added@solana/codecs@2.0.0-preview.2(transitive)
+ Added@solana/codecs-core@2.0.0-preview.2(transitive)
+ Added@solana/codecs-data-structures@2.0.0-preview.2(transitive)
+ Added@solana/codecs-numbers@2.0.0-preview.2(transitive)
+ Added@solana/codecs-strings@2.0.0-preview.2(transitive)
+ Added@solana/errors@2.0.0-preview.2(transitive)
+ Added@solana/options@2.0.0-preview.2(transitive)
+ Addedchalk@5.3.0(transitive)
+ Addedcommander@12.1.0(transitive)
- Removed@solana/codecs-data-structures@2.0.0-experimental.9741939
- Removed@solana/codecs-core@2.0.0-experimental.9741939(transitive)
- Removed@solana/codecs-data-structures@2.0.0-experimental.9741939(transitive)
- Removed@solana/codecs-numbers@2.0.0-experimental.9741939(transitive)
- Removed@solana/codecs-strings@2.0.0-experimental.9741939(transitive)
- Removed@solana/options@2.0.0-experimental.9741939(transitive)