@xandeum/web3.js 1.3.5 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/poke.js CHANGED
@@ -46,7 +46,7 @@ var const_1 = require("./const");
46
46
  var sanitizePath_1 = require("./sanitizePath");
47
47
  var helpers_1 = require("./helpers");
48
48
  /**
49
- * Constructs a Solana transaction to perform a poke\operation, which writes data
49
+ * Constructs a Solana transaction to perform a poke operation, which writes data
50
50
  * to a file at the specified path and byte position.
51
51
  *
52
52
  * @param fsid - A stringified integer representing the file system ID where the file resides.
@@ -59,20 +59,22 @@ var helpers_1 = require("./helpers");
59
59
  */
60
60
  function poke(fsid, path, position, wallet, dataKey) {
61
61
  return __awaiter(this, void 0, void 0, function () {
62
- var pathBuffer, pathLengthBuffer, instructionData, feeDistributorPda, instruction, tx;
62
+ var pathBuffer, pathLengthBuffer, innerData, instructionData, feeDistributorPda, payerAta, feeAta, instruction, tx;
63
63
  return __generator(this, function (_a) {
64
64
  (0, sanitizePath_1.sanitizePath)(path);
65
65
  pathBuffer = Buffer.from(path, 'utf-8');
66
- pathLengthBuffer = Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(pathBuffer.length).toArray('le', 8)));
67
- instructionData = Buffer.concat([
68
- Buffer.from(Int8Array.from([0]).buffer),
69
- Buffer.from(Int8Array.from([4]).buffer),
70
- Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
71
- Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(position).toArray('le', 8))),
66
+ pathLengthBuffer = Buffer.from(new bn_js_1.default(pathBuffer.length).toArray('le', 8));
67
+ innerData = Buffer.concat([
68
+ Buffer.from([4]),
69
+ Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
70
+ Buffer.from(new bn_js_1.default(position).toArray('le', 8)),
72
71
  pathLengthBuffer,
73
72
  pathBuffer
74
73
  ]);
74
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
75
75
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
76
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
77
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
76
78
  instruction = new web3_js_1.TransactionInstruction({
77
79
  keys: [
78
80
  {
@@ -89,6 +91,21 @@ function poke(fsid, path, position, wallet, dataKey) {
89
91
  pubkey: feeDistributorPda.pda,
90
92
  isSigner: false,
91
93
  isWritable: true
94
+ },
95
+ {
96
+ pubkey: payerAta.ata,
97
+ isSigner: false,
98
+ isWritable: true
99
+ },
100
+ {
101
+ pubkey: feeAta.ata,
102
+ isSigner: false,
103
+ isWritable: true
104
+ },
105
+ {
106
+ pubkey: const_1.TOKEN_PROGRAM_ID,
107
+ isSigner: false,
108
+ isWritable: false
92
109
  }
93
110
  ],
94
111
  programId: new web3_js_1.PublicKey(const_1.programId),
@@ -57,16 +57,18 @@ var helpers_1 = require("./helpers");
57
57
  */
58
58
  function removeDirectory(fsid, path, wallet) {
59
59
  return __awaiter(this, void 0, void 0, function () {
60
- var instructionData, feeDistributorPda, instruction, tx;
60
+ var innerData, instructionData, feeDistributorPda, payerAta, feeAta, instruction, tx;
61
61
  return __generator(this, function (_a) {
62
62
  (0, sanitizePath_1.sanitizePath)(path);
63
- instructionData = Buffer.concat([
64
- Buffer.from(Int8Array.from([0]).buffer),
65
- Buffer.from(Int8Array.from([7]).buffer),
66
- Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
63
+ innerData = Buffer.concat([
64
+ Buffer.from([7]),
65
+ Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
67
66
  Buffer.from("".concat(path), 'utf-8')
68
67
  ]);
68
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
69
69
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
70
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
71
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
70
72
  instruction = new web3_js_1.TransactionInstruction({
71
73
  keys: [
72
74
  {
@@ -78,6 +80,21 @@ function removeDirectory(fsid, path, wallet) {
78
80
  pubkey: feeDistributorPda.pda,
79
81
  isSigner: false,
80
82
  isWritable: true
83
+ },
84
+ {
85
+ pubkey: payerAta.ata,
86
+ isSigner: false,
87
+ isWritable: true
88
+ },
89
+ {
90
+ pubkey: feeAta.ata,
91
+ isSigner: false,
92
+ isWritable: true
93
+ },
94
+ {
95
+ pubkey: const_1.TOKEN_PROGRAM_ID,
96
+ isSigner: false,
97
+ isWritable: false
81
98
  }
82
99
  ],
83
100
  programId: new web3_js_1.PublicKey(const_1.programId),
@@ -57,16 +57,18 @@ var helpers_1 = require("./helpers");
57
57
  */
58
58
  function removeFile(fsid, path, wallet) {
59
59
  return __awaiter(this, void 0, void 0, function () {
60
- var instructionData, feeDistributorPda, instruction, tx;
60
+ var innerData, instructionData, feeDistributorPda, payerAta, feeAta, instruction, tx;
61
61
  return __generator(this, function (_a) {
62
62
  (0, sanitizePath_1.sanitizePath)(path);
63
- instructionData = Buffer.concat([
64
- Buffer.from(Int8Array.from([0]).buffer),
65
- Buffer.from(Int8Array.from([5]).buffer),
66
- Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
63
+ innerData = Buffer.concat([
64
+ Buffer.from([5]),
65
+ Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
67
66
  Buffer.from("".concat(path), 'utf-8')
68
67
  ]);
68
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
69
69
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
70
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
71
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
70
72
  instruction = new web3_js_1.TransactionInstruction({
71
73
  keys: [
72
74
  {
@@ -78,6 +80,21 @@ function removeFile(fsid, path, wallet) {
78
80
  pubkey: feeDistributorPda.pda,
79
81
  isSigner: false,
80
82
  isWritable: true
83
+ },
84
+ {
85
+ pubkey: payerAta.ata,
86
+ isSigner: false,
87
+ isWritable: true
88
+ },
89
+ {
90
+ pubkey: feeAta.ata,
91
+ isSigner: false,
92
+ isWritable: true
93
+ },
94
+ {
95
+ pubkey: const_1.TOKEN_PROGRAM_ID,
96
+ isSigner: false,
97
+ isWritable: false
81
98
  }
82
99
  ],
83
100
  programId: new web3_js_1.PublicKey(const_1.programId),
@@ -58,18 +58,20 @@ var helpers_1 = require("./helpers");
58
58
  */
59
59
  function renamePath(fsid, oldPath, name, wallet) {
60
60
  return __awaiter(this, void 0, void 0, function () {
61
- var rest, instructionData, feeDistributorPda, instruction, tx;
61
+ var rest, innerData, instructionData, feeDistributorPda, payerAta, feeAta, instruction, tx;
62
62
  return __generator(this, function (_a) {
63
63
  (0, sanitizePath_1.sanitizePath)(oldPath);
64
64
  (0, sanitizePath_1.sanitizePath)(name);
65
65
  rest = Buffer.from("".concat(oldPath, "\0").concat(name), 'utf-8');
66
- instructionData = Buffer.concat([
67
- Buffer.from(Int8Array.from([0]).buffer),
68
- Buffer.from(Int8Array.from([8]).buffer),
69
- Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
66
+ innerData = Buffer.concat([
67
+ Buffer.from([8]),
68
+ Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
70
69
  rest
71
70
  ]);
71
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
72
72
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
73
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
74
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
73
75
  instruction = new web3_js_1.TransactionInstruction({
74
76
  keys: [
75
77
  {
@@ -81,6 +83,21 @@ function renamePath(fsid, oldPath, name, wallet) {
81
83
  pubkey: feeDistributorPda.pda,
82
84
  isSigner: false,
83
85
  isWritable: true
86
+ },
87
+ {
88
+ pubkey: payerAta.ata,
89
+ isSigner: false,
90
+ isWritable: true
91
+ },
92
+ {
93
+ pubkey: feeAta.ata,
94
+ isSigner: false,
95
+ isWritable: true
96
+ },
97
+ {
98
+ pubkey: const_1.TOKEN_PROGRAM_ID,
99
+ isSigner: false,
100
+ isWritable: false
84
101
  }
85
102
  ],
86
103
  programId: new web3_js_1.PublicKey(const_1.programId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xandeum/web3.js",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "Xandeum javascript api",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/armageddon.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const.js'
4
- import { getFeeDistributorPda } from './helpers.js'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
5
5
 
6
6
  /**
7
7
  * Constructs a Solana transaction that triggers the "armageddon" instruction
@@ -15,12 +15,16 @@ export async function armageddon (
15
15
  fsid: string,
16
16
  wallet: PublicKey
17
17
  ): Promise<Transaction> {
18
- const instructionData = Buffer.concat([
19
- Buffer.from(Int8Array.from([0]).buffer),
20
- Buffer.from(Int8Array.from([1]).buffer),
21
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8)))
18
+ // inner_data: [1u8 (operation), fsid as u64 LE]
19
+ const innerData = Buffer.concat([
20
+ Buffer.from([1]),
21
+ Buffer.from(new BN(fsid).toArray('le', 8))
22
22
  ])
23
+
24
+ const instructionData = buildInstructionData(innerData)
23
25
  let feeDistributorPda = getFeeDistributorPda()
26
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
27
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
24
28
 
25
29
  const instruction = new TransactionInstruction({
26
30
  keys: [
@@ -33,6 +37,21 @@ export async function armageddon (
33
37
  pubkey: feeDistributorPda.pda,
34
38
  isSigner: false,
35
39
  isWritable: true
40
+ },
41
+ {
42
+ pubkey: payerAta.ata,
43
+ isSigner: false,
44
+ isWritable: true
45
+ },
46
+ {
47
+ pubkey: feeAta.ata,
48
+ isSigner: false,
49
+ isWritable: true
50
+ },
51
+ {
52
+ pubkey: TOKEN_PROGRAM_ID,
53
+ isSigner: false,
54
+ isWritable: false
36
55
  }
37
56
  ],
38
57
  programId: new PublicKey(programId),
@@ -1,7 +1,7 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
- import { programId } from './const'
2
+ import { programId, TOKEN_PROGRAM_ID } from './const'
3
3
  import BN from 'bn.js'
4
- import { getFeeDistributorPda } from './helpers.js'
4
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
5
5
 
6
6
  /**
7
7
  * Constructs a Solana transaction to assign a co-owner to a file or directory
@@ -20,13 +20,19 @@ export async function assignCoowner (
20
20
  wallet: PublicKey
21
21
  ): Promise<Transaction> {
22
22
  const rest = Buffer.from(`${path}\0${coowner.toString()}`, 'utf-8')
23
- const instructionData = Buffer.concat([
24
- Buffer.from(Int8Array.from([0]).buffer),
25
- Buffer.from(Int8Array.from([14]).buffer),
26
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
23
+
24
+ // inner_data: [14u8 (operation), fsid as u64 LE, path\0coowner]
25
+ const innerData = Buffer.concat([
26
+ Buffer.from([14]),
27
+ Buffer.from(new BN(fsid).toArray('le', 8)),
27
28
  rest
28
29
  ])
30
+
31
+ const instructionData = buildInstructionData(innerData)
29
32
  let feeDistributorPda = getFeeDistributorPda()
33
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
34
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
35
+
30
36
  const instruction = new TransactionInstruction({
31
37
  keys: [
32
38
  {
@@ -38,6 +44,21 @@ export async function assignCoowner (
38
44
  pubkey: feeDistributorPda.pda,
39
45
  isSigner: false,
40
46
  isWritable: true
47
+ },
48
+ {
49
+ pubkey: payerAta.ata,
50
+ isSigner: false,
51
+ isWritable: true
52
+ },
53
+ {
54
+ pubkey: feeAta.ata,
55
+ isSigner: false,
56
+ isWritable: true
57
+ },
58
+ {
59
+ pubkey: TOKEN_PROGRAM_ID,
60
+ isSigner: false,
61
+ isWritable: false
41
62
  }
42
63
  ],
43
64
  programId: new PublicKey(programId),
@@ -46,4 +67,4 @@ export async function assignCoowner (
46
67
 
47
68
  const tx = new Transaction().add(instruction)
48
69
  return tx
49
- }
70
+ }
package/src/bigbang.ts CHANGED
@@ -1,50 +1,52 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
- import BN from 'bn.js'
3
- import { programId } from './const'
4
- import { getFeeDistributorPda } from './helpers'
2
+ import { programId, TOKEN_PROGRAM_ID } from './const'
3
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, u64ToLeBytes, buildInstructionData } from './helpers'
5
4
 
6
5
  /**
7
- * Constructs a Solana transaction that triggers the "bigbang" instruction and create new file system.
6
+ * Constructs a Solana transaction that triggers the "bigbang" instruction and creates a new file system.
8
7
  *
8
+ * @param replicaCount - The number of replicas for the new file system. Must be 2 or greater. The total number of copies will be replicaCount + 1 (one original plus the replicas).
9
9
  * @param wallet - The public key of the wallet that will sign and authorize the transaction.
10
- * @param replica_count - A stringified integer representing the number of replicas for the new file system. Must be 2 or greater. The total number of copies will be replica_count + 1 (one original plus the replicas).
11
10
  * @returns A Promise that resolves to a Solana `Transaction` object containing the bigbang instruction.
12
11
  */
13
- export async function bigbang(replica_count:string,wallet: PublicKey): Promise<Transaction> {
14
- // inner_data: [0u8 (operation), replica as u64 LE (8 bytes)]
15
- const innerData = Buffer.concat([
16
- Buffer.from([0]),
17
- Buffer.from(new BN(replica_count).toArray('le', 8))
18
- ])
19
-
20
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
21
- const innerLen = Buffer.alloc(4)
22
- innerLen.writeUInt32LE(innerData.length)
23
-
24
- const instructionData = Buffer.concat([
25
- Buffer.from([0]),
26
- innerLen,
27
- innerData
28
- ])
29
- let feeDistributorPda = getFeeDistributorPda()
12
+ export async function bigbang(replicaCount: number, wallet: PublicKey): Promise<Transaction> {
13
+ const feeDistributorPda = getFeeDistributorPda();
14
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet);
15
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda);
16
+ const innerData = Buffer.concat([Buffer.from([0]), u64ToLeBytes(replicaCount)]);
17
+ const instructionData = buildInstructionData(innerData);
30
18
 
31
19
  const instruction = new TransactionInstruction({
32
20
  keys: [
33
21
  {
34
22
  pubkey: wallet,
35
23
  isSigner: true,
36
- isWritable: true
24
+ isWritable: true,
37
25
  },
38
26
  {
39
27
  pubkey: feeDistributorPda.pda,
40
28
  isSigner: false,
41
- isWritable: true
42
- }
29
+ isWritable: true,
30
+ },
31
+ {
32
+ pubkey: payerAta.ata,
33
+ isSigner: false,
34
+ isWritable: true,
35
+ },
36
+ {
37
+ pubkey: feeAta.ata,
38
+ isSigner: false,
39
+ isWritable: true,
40
+ },
41
+ {
42
+ pubkey: TOKEN_PROGRAM_ID,
43
+ isSigner: false,
44
+ isWritable: false,
45
+ },
43
46
  ],
44
47
  programId: new PublicKey(programId),
45
- data: instructionData
46
- })
48
+ data: instructionData,
49
+ });
47
50
 
48
- const tx = new Transaction().add(instruction)
49
- return tx
51
+ return new Transaction().add(instruction);
50
52
  }
package/src/const.ts CHANGED
@@ -1 +1,6 @@
1
- export const programId="EaLDF7m76kzvrpeADHVHPLfk5qpPaPxYUYqYApByLp1S";
1
+ import { PublicKey } from '@solana/web3.js'
2
+
3
+ export const programId = "GH4eE2Wuzd2cFHQgXDp4avGLA3cEiNwEBVhkGkP8Vrs3";
4
+ export const TOKEN_PROGRAM_ID = new PublicKey("651cCwrKdzgNUBo3sUBGCahtsxzfC7yTaNounG3q3iDF");
5
+ export const ATA_PROGRAM_ID = new PublicKey("7aRtRTerxiPxr6fpUBfs2j2ehRANmpSLRWgNPyYitaxi");
6
+ export const TOKEN_MINT_ADDRESS = new PublicKey("BPbgHqagPnds7Rs5j7NvL8DjsJAZz1XSCQFW1mU2wigR");
package/src/copyPath.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers.js'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
6
 
7
7
  /**
8
8
  * Constructs a Solana transaction to copy a file or directory from one path to another.
@@ -29,13 +29,18 @@ export async function copyPath (
29
29
 
30
30
  const rest = Buffer.from(`${srcPath}\0${destPath}`, 'utf-8')
31
31
 
32
- const instructionData = Buffer.concat([
33
- Buffer.from(Int8Array.from([0]).buffer),
34
- Buffer.from(Int8Array.from([9]).buffer),
35
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
32
+ // inner_data: [9u8 (operation), fsid as u64 LE, paths]
33
+ const innerData = Buffer.concat([
34
+ Buffer.from([9]),
35
+ Buffer.from(new BN(fsid).toArray('le', 8)),
36
36
  rest
37
37
  ])
38
+
39
+ const instructionData = buildInstructionData(innerData)
38
40
  let feeDistributorPda = getFeeDistributorPda()
41
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
42
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
43
+
39
44
  const instruction = new TransactionInstruction({
40
45
  keys: [
41
46
  {
@@ -47,6 +52,21 @@ export async function copyPath (
47
52
  pubkey: feeDistributorPda.pda,
48
53
  isSigner: false,
49
54
  isWritable: true
55
+ },
56
+ {
57
+ pubkey: payerAta.ata,
58
+ isSigner: false,
59
+ isWritable: true
60
+ },
61
+ {
62
+ pubkey: feeAta.ata,
63
+ isSigner: false,
64
+ isWritable: true
65
+ },
66
+ {
67
+ pubkey: TOKEN_PROGRAM_ID,
68
+ isSigner: false,
69
+ isWritable: false
50
70
  }
51
71
  ],
52
72
  programId: new PublicKey(programId),
@@ -1,8 +1,8 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers.js'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
6
 
7
7
  /**
8
8
  * Constructs a Solana transaction to create a new directory within a file system.
@@ -10,7 +10,7 @@ import { getFeeDistributorPda } from './helpers.js'
10
10
  * @param fsid - A numeric filesystem identifier used to scope the directory creation.
11
11
  * @param path - The parent path where the directory should be created (e.g., `/documents`).
12
12
  * @param name - The name of the new directory (e.g., `reports`).
13
- * @param wallet - The signers public key that authorizes the transaction.
13
+ * @param wallet - The signer's public key that authorizes the transaction.
14
14
  * @returns A Promise that resolves to a Solana `Transaction` object containing the createDirectory instruction.
15
15
  * @throws Will throw an error if `path` or `name` contains invalid characters.@throws Will throw if the combined path is invalid (non-alphanumeric or unsupported characters).
16
16
  */
@@ -25,13 +25,19 @@ export async function createDirectory (
25
25
  const combinedPath = path.endsWith('/') ? `${path}${name}` : `${path}/${name}`
26
26
  sanitizePath(combinedPath)
27
27
  const rest = Buffer.from(`${path}\0${name}`, 'utf-8')
28
- const instructionData = Buffer.concat([
29
- Buffer.from(Int8Array.from([0]).buffer),
30
- Buffer.from(Int8Array.from([6]).buffer),
31
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
28
+
29
+ // inner_data: [6u8 (operation), fsid as u64 LE, paths]
30
+ const innerData = Buffer.concat([
31
+ Buffer.from([6]),
32
+ Buffer.from(new BN(fsid).toArray('le', 8)),
32
33
  rest
33
34
  ])
35
+
36
+ const instructionData = buildInstructionData(innerData)
34
37
  let feeDistributorPda = getFeeDistributorPda()
38
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
39
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
40
+
35
41
  const instruction = new TransactionInstruction({
36
42
  keys: [
37
43
  {
@@ -43,6 +49,21 @@ export async function createDirectory (
43
49
  pubkey: feeDistributorPda.pda,
44
50
  isSigner: false,
45
51
  isWritable: true
52
+ },
53
+ {
54
+ pubkey: payerAta.ata,
55
+ isSigner: false,
56
+ isWritable: true
57
+ },
58
+ {
59
+ pubkey: feeAta.ata,
60
+ isSigner: false,
61
+ isWritable: true
62
+ },
63
+ {
64
+ pubkey: TOKEN_PROGRAM_ID,
65
+ isSigner: false,
66
+ isWritable: false
46
67
  }
47
68
  ],
48
69
  programId: new PublicKey(programId),
package/src/createFile.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
2
  import BN from 'bn.js'
3
- import { programId } from './const'
3
+ import { programId, TOKEN_PROGRAM_ID } from './const'
4
4
  import { sanitizePath } from './sanitizePath'
5
- import { getFeeDistributorPda } from './helpers.js'
5
+ import { getFeeDistributorPda, getAssociatedTokenAddressWithProgramIds, buildInstructionData } from './helpers'
6
+
6
7
  /**
7
8
  * Constructs a Solana transaction to create a new file
8
9
  * within a file system, identified by a file system ID (`fsid`).
@@ -24,13 +25,19 @@ export async function createFile (
24
25
  sanitizePath(combinedPath);
25
26
 
26
27
  const rest = Buffer.from(`${path}\0${name}`, 'utf-8')
27
- const instructionData = Buffer.concat([
28
- Buffer.from(Int8Array.from([0]).buffer),
29
- Buffer.from(Int8Array.from([2]).buffer),
30
- Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
28
+
29
+ // inner_data: [2u8 (operation), fsid as u64 LE, paths]
30
+ const innerData = Buffer.concat([
31
+ Buffer.from([2]),
32
+ Buffer.from(new BN(fsid).toArray('le', 8)),
31
33
  rest
32
34
  ])
35
+
36
+ const instructionData = buildInstructionData(innerData)
33
37
  let feeDistributorPda = getFeeDistributorPda()
38
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
39
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
40
+
34
41
  const instruction = new TransactionInstruction({
35
42
  keys: [
36
43
  {
@@ -42,6 +49,21 @@ export async function createFile (
42
49
  pubkey: feeDistributorPda.pda,
43
50
  isSigner: false,
44
51
  isWritable: true
52
+ },
53
+ {
54
+ pubkey: payerAta.ata,
55
+ isSigner: false,
56
+ isWritable: true
57
+ },
58
+ {
59
+ pubkey: feeAta.ata,
60
+ isSigner: false,
61
+ isWritable: true
62
+ },
63
+ {
64
+ pubkey: TOKEN_PROGRAM_ID,
65
+ isSigner: false,
66
+ isWritable: false
45
67
  }
46
68
  ],
47
69
  programId: new PublicKey(programId),
package/src/helpers.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from '@solana/web3.js'
2
- import { programId } from './const'
2
+ import { programId, TOKEN_PROGRAM_ID, ATA_PROGRAM_ID, TOKEN_MINT_ADDRESS } from './const'
3
3
  import BN from 'bn.js'
4
4
 
5
5
  /**
@@ -68,6 +68,53 @@ export function getCurrentYuga(): number {
68
68
  * console.log('Bump seed:', bump)
69
69
  * ```
70
70
  */
71
+ /**
72
+ * Derives the Associated Token Address (ATA) for a given wallet using custom program IDs.
73
+ *
74
+ * @param walletAddress - The public key of the wallet
75
+ * @returns An object containing the ATA public key and bump seed
76
+ */
77
+ export function getAssociatedTokenAddressWithProgramIds(walletAddress: PublicKey): { ata: PublicKey; bump: number } {
78
+ const [ata, bump] = PublicKey.findProgramAddressSync(
79
+ [
80
+ walletAddress.toBuffer(),
81
+ TOKEN_PROGRAM_ID.toBuffer(),
82
+ TOKEN_MINT_ADDRESS.toBuffer(),
83
+ ],
84
+ ATA_PROGRAM_ID
85
+ );
86
+ return { ata, bump };
87
+ }
88
+
89
+ /**
90
+ * Converts a u64 value to little-endian bytes.
91
+ *
92
+ * @param value - The value to convert (number)
93
+ * @returns A Buffer containing the 8-byte little-endian representation
94
+ */
95
+ export function u64ToLeBytes(value: number): Buffer {
96
+ const bn = new BN(value);
97
+ if (bn.isNeg() || bn.byteLength() > 8) {
98
+ throw new Error(`u64 out of range: ${value}`);
99
+ }
100
+ return Buffer.from(bn.toArray('le', 8));
101
+ }
102
+
103
+ /**
104
+ * Builds the instruction data buffer for a given inner data payload.
105
+ * Allocates a fixed 33-byte buffer, sets the first byte to 0,
106
+ * and copies the inner data starting at offset 1.
107
+ *
108
+ * @param innerData - The inner data buffer to embed in the instruction
109
+ * @returns A 33-byte Buffer containing the instruction data
110
+ */
111
+ export function buildInstructionData(innerData: Buffer): Buffer {
112
+ const instructionData = Buffer.alloc(33, 0);
113
+ instructionData[0] = 0;
114
+ innerData.copy(instructionData, 1);
115
+ return instructionData;
116
+ }
117
+
71
118
  export function getFeeDistributorPda(): { pda: PublicKey; bump: number } {
72
119
  const yuga = getCurrentYuga()
73
120