@xandeum/web3.js 1.3.6 → 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,7 +59,7 @@ 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, innerData, innerLen, 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');
@@ -71,14 +71,10 @@ function poke(fsid, path, position, wallet, dataKey) {
71
71
  pathLengthBuffer,
72
72
  pathBuffer
73
73
  ]);
74
- innerLen = Buffer.alloc(4);
75
- innerLen.writeUInt32LE(innerData.length);
76
- instructionData = Buffer.concat([
77
- Buffer.from([0]),
78
- innerLen,
79
- innerData
80
- ]);
74
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
81
75
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
76
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
77
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
82
78
  instruction = new web3_js_1.TransactionInstruction({
83
79
  keys: [
84
80
  {
@@ -97,7 +93,17 @@ function poke(fsid, path, position, wallet, dataKey) {
97
93
  isWritable: true
98
94
  },
99
95
  {
100
- pubkey: web3_js_1.SystemProgram.programId,
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,
101
107
  isSigner: false,
102
108
  isWritable: false
103
109
  }
@@ -57,7 +57,7 @@ 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 innerData, innerLen, 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
63
  innerData = Buffer.concat([
@@ -65,14 +65,10 @@ function removeDirectory(fsid, path, wallet) {
65
65
  Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
66
66
  Buffer.from("".concat(path), 'utf-8')
67
67
  ]);
68
- innerLen = Buffer.alloc(4);
69
- innerLen.writeUInt32LE(innerData.length);
70
- instructionData = Buffer.concat([
71
- Buffer.from([0]),
72
- innerLen,
73
- innerData
74
- ]);
68
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
75
69
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
70
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
71
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
76
72
  instruction = new web3_js_1.TransactionInstruction({
77
73
  keys: [
78
74
  {
@@ -86,7 +82,17 @@ function removeDirectory(fsid, path, wallet) {
86
82
  isWritable: true
87
83
  },
88
84
  {
89
- pubkey: web3_js_1.SystemProgram.programId,
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,
90
96
  isSigner: false,
91
97
  isWritable: false
92
98
  }
@@ -57,7 +57,7 @@ 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 innerData, innerLen, 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
63
  innerData = Buffer.concat([
@@ -65,14 +65,10 @@ function removeFile(fsid, path, wallet) {
65
65
  Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
66
66
  Buffer.from("".concat(path), 'utf-8')
67
67
  ]);
68
- innerLen = Buffer.alloc(4);
69
- innerLen.writeUInt32LE(innerData.length);
70
- instructionData = Buffer.concat([
71
- Buffer.from([0]),
72
- innerLen,
73
- innerData
74
- ]);
68
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
75
69
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
70
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
71
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
76
72
  instruction = new web3_js_1.TransactionInstruction({
77
73
  keys: [
78
74
  {
@@ -86,7 +82,17 @@ function removeFile(fsid, path, wallet) {
86
82
  isWritable: true
87
83
  },
88
84
  {
89
- pubkey: web3_js_1.SystemProgram.programId,
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,
90
96
  isSigner: false,
91
97
  isWritable: false
92
98
  }
@@ -58,7 +58,7 @@ 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, innerData, innerLen, 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);
@@ -68,14 +68,10 @@ function renamePath(fsid, oldPath, name, wallet) {
68
68
  Buffer.from(new bn_js_1.default(fsid).toArray('le', 8)),
69
69
  rest
70
70
  ]);
71
- innerLen = Buffer.alloc(4);
72
- innerLen.writeUInt32LE(innerData.length);
73
- instructionData = Buffer.concat([
74
- Buffer.from([0]),
75
- innerLen,
76
- innerData
77
- ]);
71
+ instructionData = (0, helpers_1.buildInstructionData)(innerData);
78
72
  feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
73
+ payerAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(wallet);
74
+ feeAta = (0, helpers_1.getAssociatedTokenAddressWithProgramIds)(feeDistributorPda.pda);
79
75
  instruction = new web3_js_1.TransactionInstruction({
80
76
  keys: [
81
77
  {
@@ -89,7 +85,17 @@ function renamePath(fsid, oldPath, name, wallet) {
89
85
  isWritable: true
90
86
  },
91
87
  {
92
- pubkey: web3_js_1.SystemProgram.programId,
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,
93
99
  isSigner: false,
94
100
  isWritable: false
95
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xandeum/web3.js",
3
- "version": "1.3.6",
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
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
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
@@ -21,16 +21,10 @@ export async function armageddon (
21
21
  Buffer.from(new BN(fsid).toArray('le', 8))
22
22
  ])
23
23
 
24
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
25
- const innerLen = Buffer.alloc(4)
26
- innerLen.writeUInt32LE(innerData.length)
27
-
28
- const instructionData = Buffer.concat([
29
- Buffer.from([0]),
30
- innerLen,
31
- innerData
32
- ])
24
+ const instructionData = buildInstructionData(innerData)
33
25
  let feeDistributorPda = getFeeDistributorPda()
26
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
27
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
34
28
 
35
29
  const instruction = new TransactionInstruction({
36
30
  keys: [
@@ -45,7 +39,17 @@ export async function armageddon (
45
39
  isWritable: true
46
40
  },
47
41
  {
48
- pubkey: SystemProgram.programId,
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,
49
53
  isSigner: false,
50
54
  isWritable: false
51
55
  }
@@ -1,7 +1,7 @@
1
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
2
- import { programId } from './const'
1
+ import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
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
@@ -28,16 +28,11 @@ export async function assignCoowner (
28
28
  rest
29
29
  ])
30
30
 
31
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
32
- const innerLen = Buffer.alloc(4)
33
- innerLen.writeUInt32LE(innerData.length)
34
-
35
- const instructionData = Buffer.concat([
36
- Buffer.from([0]),
37
- innerLen,
38
- innerData
39
- ])
31
+ const instructionData = buildInstructionData(innerData)
40
32
  let feeDistributorPda = getFeeDistributorPda()
33
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
34
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
35
+
41
36
  const instruction = new TransactionInstruction({
42
37
  keys: [
43
38
  {
@@ -51,7 +46,17 @@ export async function assignCoowner (
51
46
  isWritable: true
52
47
  },
53
48
  {
54
- pubkey: SystemProgram.programId,
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,
55
60
  isSigner: false,
56
61
  isWritable: false
57
62
  }
@@ -62,4 +67,4 @@ export async function assignCoowner (
62
67
 
63
68
  const tx = new Transaction().add(instruction)
64
69
  return tx
65
- }
70
+ }
package/src/bigbang.ts CHANGED
@@ -1,53 +1,52 @@
1
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
2
- import BN from 'bn.js'
3
- import { programId } from './const'
4
- import { getFeeDistributorPda } from './helpers'
1
+ import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
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
- const innerData = Buffer.concat([
15
- Buffer.from([0]),
16
- Buffer.from(new BN(replica_count).toArray('le', 8))
17
- ])
18
-
19
- const innerLen = Buffer.alloc(4)
20
- innerLen.writeUInt32LE(innerData.length)
21
-
22
- const instructionData = Buffer.concat([
23
- Buffer.from([0]),
24
- innerLen,
25
- innerData
26
- ])
27
- 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);
28
18
 
29
19
  const instruction = new TransactionInstruction({
30
20
  keys: [
31
21
  {
32
22
  pubkey: wallet,
33
23
  isSigner: true,
34
- isWritable: true
24
+ isWritable: true,
35
25
  },
36
26
  {
37
27
  pubkey: feeDistributorPda.pda,
38
28
  isSigner: false,
39
- isWritable: true
29
+ isWritable: true,
30
+ },
31
+ {
32
+ pubkey: payerAta.ata,
33
+ isSigner: false,
34
+ isWritable: true,
40
35
  },
41
36
  {
42
- pubkey: SystemProgram.programId,
37
+ pubkey: feeAta.ata,
43
38
  isSigner: false,
44
- isWritable: false
45
- }
39
+ isWritable: true,
40
+ },
41
+ {
42
+ pubkey: TOKEN_PROGRAM_ID,
43
+ isSigner: false,
44
+ isWritable: false,
45
+ },
46
46
  ],
47
47
  programId: new PublicKey(programId),
48
- data: instructionData
49
- })
48
+ data: instructionData,
49
+ });
50
50
 
51
- const tx = new Transaction().add(instruction)
52
- return tx
51
+ return new Transaction().add(instruction);
53
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
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
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.
@@ -36,16 +36,11 @@ export async function copyPath (
36
36
  rest
37
37
  ])
38
38
 
39
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
40
- const innerLen = Buffer.alloc(4)
41
- innerLen.writeUInt32LE(innerData.length)
42
-
43
- const instructionData = Buffer.concat([
44
- Buffer.from([0]),
45
- innerLen,
46
- innerData
47
- ])
39
+ const instructionData = buildInstructionData(innerData)
48
40
  let feeDistributorPda = getFeeDistributorPda()
41
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
42
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
43
+
49
44
  const instruction = new TransactionInstruction({
50
45
  keys: [
51
46
  {
@@ -59,7 +54,17 @@ export async function copyPath (
59
54
  isWritable: true
60
55
  },
61
56
  {
62
- pubkey: SystemProgram.programId,
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,
63
68
  isSigner: false,
64
69
  isWritable: false
65
70
  }
@@ -1,8 +1,8 @@
1
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
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
  */
@@ -33,16 +33,11 @@ export async function createDirectory (
33
33
  rest
34
34
  ])
35
35
 
36
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
37
- const innerLen = Buffer.alloc(4)
38
- innerLen.writeUInt32LE(innerData.length)
39
-
40
- const instructionData = Buffer.concat([
41
- Buffer.from([0]),
42
- innerLen,
43
- innerData
44
- ])
36
+ const instructionData = buildInstructionData(innerData)
45
37
  let feeDistributorPda = getFeeDistributorPda()
38
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
39
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
40
+
46
41
  const instruction = new TransactionInstruction({
47
42
  keys: [
48
43
  {
@@ -56,7 +51,17 @@ export async function createDirectory (
56
51
  isWritable: true
57
52
  },
58
53
  {
59
- pubkey: SystemProgram.programId,
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,
60
65
  isSigner: false,
61
66
  isWritable: false
62
67
  }
package/src/createFile.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { Transaction, TransactionInstruction, PublicKey, SystemProgram } from '@solana/web3.js'
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`).
@@ -32,16 +33,11 @@ export async function createFile (
32
33
  rest
33
34
  ])
34
35
 
35
- // wrap_storage_tx: [0u8, inner_data.len() as u32 LE, inner_data]
36
- const innerLen = Buffer.alloc(4)
37
- innerLen.writeUInt32LE(innerData.length)
38
-
39
- const instructionData = Buffer.concat([
40
- Buffer.from([0]),
41
- innerLen,
42
- innerData
43
- ])
36
+ const instructionData = buildInstructionData(innerData)
44
37
  let feeDistributorPda = getFeeDistributorPda()
38
+ const payerAta = getAssociatedTokenAddressWithProgramIds(wallet)
39
+ const feeAta = getAssociatedTokenAddressWithProgramIds(feeDistributorPda.pda)
40
+
45
41
  const instruction = new TransactionInstruction({
46
42
  keys: [
47
43
  {
@@ -55,7 +51,17 @@ export async function createFile (
55
51
  isWritable: true
56
52
  },
57
53
  {
58
- pubkey: SystemProgram.programId,
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,
59
65
  isSigner: false,
60
66
  isWritable: false
61
67
  }
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