@w3lib/solana-batch-call 0.2.2 → 0.3.0
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/CHANGELOG.md +14 -0
- package/README.md +132 -2
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +5 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +16 -0
- package/dist/layout.js.map +1 -1
- package/dist/lp.d.ts +123 -0
- package/dist/lp.d.ts.map +1 -0
- package/dist/lp.js +631 -0
- package/dist/lp.js.map +1 -0
- package/dist/lpMath.d.ts +37 -0
- package/dist/lpMath.d.ts.map +1 -0
- package/dist/lpMath.js +176 -0
- package/dist/lpMath.js.map +1 -0
- package/dist/shortcuts.d.ts +8 -0
- package/dist/shortcuts.d.ts.map +1 -1
- package/dist/shortcuts.js +1 -1
- package/dist/shortcuts.js.map +1 -1
- package/dist/subpaths/lp.d.ts +31 -0
- package/dist/subpaths/lp.d.ts.map +1 -0
- package/dist/subpaths/lp.js +33 -0
- package/dist/subpaths/lp.js.map +1 -0
- package/dist/subpaths/write.d.ts +22 -0
- package/dist/subpaths/write.d.ts.map +1 -0
- package/dist/subpaths/write.js +19 -0
- package/dist/subpaths/write.js.map +1 -0
- package/dist/write/batch.d.ts +41 -0
- package/dist/write/batch.d.ts.map +1 -0
- package/dist/write/batch.js +46 -0
- package/dist/write/batch.js.map +1 -0
- package/dist/write/collect.d.ts +50 -0
- package/dist/write/collect.d.ts.map +1 -0
- package/dist/write/collect.js +220 -0
- package/dist/write/collect.js.map +1 -0
- package/dist/write/instructions.d.ts +16 -0
- package/dist/write/instructions.d.ts.map +1 -0
- package/dist/write/instructions.js +89 -0
- package/dist/write/instructions.js.map +1 -0
- package/dist/write/send.d.ts +115 -0
- package/dist/write/send.d.ts.map +1 -0
- package/dist/write/send.js +720 -0
- package/dist/write/send.js.map +1 -0
- package/dist/write/signer.d.ts +94 -0
- package/dist/write/signer.d.ts.map +1 -0
- package/dist/write/signer.js +197 -0
- package/dist/write/signer.js.map +1 -0
- package/dist/write/transaction.d.ts +75 -0
- package/dist/write/transaction.d.ts.map +1 -0
- package/dist/write/transaction.js +133 -0
- package/dist/write/transaction.js.map +1 -0
- package/dist/write/transfer.d.ts +72 -0
- package/dist/write/transfer.d.ts.map +1 -0
- package/dist/write/transfer.js +127 -0
- package/dist/write/transfer.js.map +1 -0
- package/package.json +23 -12
- package/src/client.ts +10 -0
- package/src/index.ts +1 -0
- package/src/layout.ts +17 -0
- package/src/lp.ts +849 -0
- package/src/lpMath.ts +205 -0
- package/src/shortcuts.ts +1 -1
- package/src/subpaths/lp.ts +62 -0
- package/src/subpaths/write.ts +29 -0
- package/src/write/batch.ts +78 -0
- package/src/write/collect.ts +286 -0
- package/src/write/instructions.ts +98 -0
- package/src/write/send.ts +876 -0
- package/src/write/signer.ts +314 -0
- package/src/write/transaction.ts +181 -0
- package/src/write/transfer.ts +189 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, SYSTEM_PROGRAM_ID } from '../constants.js'
|
|
2
|
+
import type { Instruction } from './transaction.js'
|
|
3
|
+
|
|
4
|
+
export const COMPUTE_BUDGET_PROGRAM_ID = 'ComputeBudget111111111111111111111111111111'
|
|
5
|
+
|
|
6
|
+
/** 单笔交易的计算单元上限 */
|
|
7
|
+
export const MAX_COMPUTE_UNITS = 1_400_000
|
|
8
|
+
|
|
9
|
+
function bytes(size: number, write: (view: DataView) => void): Uint8Array {
|
|
10
|
+
const out = new Uint8Array(size)
|
|
11
|
+
write(new DataView(out.buffer))
|
|
12
|
+
return out
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** System Program Transfer:转 SOL */
|
|
16
|
+
export function systemTransfer(from: string, to: string, lamports: bigint): Instruction {
|
|
17
|
+
return {
|
|
18
|
+
programId: SYSTEM_PROGRAM_ID,
|
|
19
|
+
keys: [
|
|
20
|
+
{ pubkey: from, isSigner: true, isWritable: true },
|
|
21
|
+
{ pubkey: to, isSigner: false, isWritable: true },
|
|
22
|
+
],
|
|
23
|
+
data: bytes(12, (v) => {
|
|
24
|
+
v.setUint32(0, 2, true)
|
|
25
|
+
v.setBigUint64(4, lamports, true)
|
|
26
|
+
}),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** SPL Token / Token-2022 TransferChecked(校验 mint 和精度) */
|
|
31
|
+
export function transferChecked(source: string, mint: string, destination: string, owner: string, amount: bigint, decimals: number, tokenProgram: string): Instruction {
|
|
32
|
+
return {
|
|
33
|
+
programId: tokenProgram,
|
|
34
|
+
keys: [
|
|
35
|
+
{ pubkey: source, isSigner: false, isWritable: true },
|
|
36
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
37
|
+
{ pubkey: destination, isSigner: false, isWritable: true },
|
|
38
|
+
{ pubkey: owner, isSigner: true, isWritable: false },
|
|
39
|
+
],
|
|
40
|
+
data: bytes(10, (v) => {
|
|
41
|
+
v.setUint8(0, 12)
|
|
42
|
+
v.setBigUint64(1, amount, true)
|
|
43
|
+
v.setUint8(9, decimals)
|
|
44
|
+
}),
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 创建关联代币账户(已存在时什么都不做),租金由 payer 付 */
|
|
49
|
+
export function createAssociatedTokenAccountIdempotent(payer: string, ata: string, owner: string, mint: string, tokenProgram: string): Instruction {
|
|
50
|
+
return {
|
|
51
|
+
programId: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
52
|
+
keys: [
|
|
53
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
54
|
+
{ pubkey: ata, isSigner: false, isWritable: true },
|
|
55
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
56
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
57
|
+
{ pubkey: SYSTEM_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
58
|
+
{ pubkey: tokenProgram, isSigner: false, isWritable: false },
|
|
59
|
+
],
|
|
60
|
+
data: new Uint8Array([1]),
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 关闭代币账户(余额必须为 0),租金退给 destination */
|
|
65
|
+
export function closeAccount(account: string, destination: string, owner: string, tokenProgram: string): Instruction {
|
|
66
|
+
return {
|
|
67
|
+
programId: tokenProgram,
|
|
68
|
+
keys: [
|
|
69
|
+
{ pubkey: account, isSigner: false, isWritable: true },
|
|
70
|
+
{ pubkey: destination, isSigner: false, isWritable: true },
|
|
71
|
+
{ pubkey: owner, isSigner: true, isWritable: false },
|
|
72
|
+
],
|
|
73
|
+
data: new Uint8Array([9]),
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function setComputeUnitLimit(units: number): Instruction {
|
|
78
|
+
return {
|
|
79
|
+
programId: COMPUTE_BUDGET_PROGRAM_ID,
|
|
80
|
+
keys: [],
|
|
81
|
+
data: bytes(5, (v) => {
|
|
82
|
+
v.setUint8(0, 2)
|
|
83
|
+
v.setUint32(1, units, true)
|
|
84
|
+
}),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 优先费用:每个计算单元多付多少 micro-lamports */
|
|
89
|
+
export function setComputeUnitPrice(microLamports: bigint): Instruction {
|
|
90
|
+
return {
|
|
91
|
+
programId: COMPUTE_BUDGET_PROGRAM_ID,
|
|
92
|
+
keys: [],
|
|
93
|
+
data: bytes(9, (v) => {
|
|
94
|
+
v.setUint8(0, 3)
|
|
95
|
+
v.setBigUint64(1, microLamports, true)
|
|
96
|
+
}),
|
|
97
|
+
}
|
|
98
|
+
}
|