@solana/plugin-interfaces 6.4.0 → 6.5.0-canary-20260319134241
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/README.md +86 -59
- package/dist/types/get-minimum-balance.d.ts +47 -0
- package/dist/types/get-minimum-balance.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/get-minimum-balance.ts +48 -0
- package/src/index.ts +1 -0
package/README.md
CHANGED
|
@@ -37,17 +37,18 @@ npm install @solana/plugin-interfaces
|
|
|
37
37
|
Represents a client that provides a default transaction payer.
|
|
38
38
|
|
|
39
39
|
```ts
|
|
40
|
+
import { extendClient } from '@solana/plugin-core';
|
|
40
41
|
import { ClientWithPayer } from '@solana/plugin-interfaces';
|
|
41
42
|
|
|
42
43
|
function memoPlugin() {
|
|
43
|
-
return <T extends ClientWithPayer>(client: T) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
return <T extends ClientWithPayer>(client: T) =>
|
|
45
|
+
extendClient(client, {
|
|
46
|
+
sendMemo: (message: string) => {
|
|
47
|
+
// Use client.payer as the fee payer for the memo transaction
|
|
48
|
+
const feePayer = client.payer;
|
|
49
|
+
// ...
|
|
50
|
+
},
|
|
51
|
+
});
|
|
51
52
|
}
|
|
52
53
|
```
|
|
53
54
|
|
|
@@ -56,15 +57,38 @@ function memoPlugin() {
|
|
|
56
57
|
Represents a client that can request SOL airdrops (typically on devnet/testnet). The airdrop succeeds when the promise resolves. Some implementations (e.g., LiteSVM) update balances directly without a transaction, so no signature is returned in those cases.
|
|
57
58
|
|
|
58
59
|
```ts
|
|
60
|
+
import { extendClient } from '@solana/plugin-core';
|
|
59
61
|
import { ClientWithAirdrop, ClientWithPayer } from '@solana/plugin-interfaces';
|
|
60
62
|
|
|
61
63
|
function faucetPlugin() {
|
|
62
|
-
return <T extends ClientWithAirdrop & ClientWithPayer>(client: T) =>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
return <T extends ClientWithAirdrop & ClientWithPayer>(client: T) =>
|
|
65
|
+
extendClient(client, {
|
|
66
|
+
fundMyself: async (amount: Lamports) => {
|
|
67
|
+
await client.airdrop(client.payer.address, amount);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### `ClientWithGetMinimumBalance`
|
|
74
|
+
|
|
75
|
+
Represents a client that can compute the minimum balance required for an account to be exempt from deletion. Different implementations may compute this differently — for example, by calling the `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value.
|
|
76
|
+
|
|
77
|
+
By default, the 128-byte account header is added on top of the provided `space`. Pass `{ withoutHeader: true }` to skip adding the header bytes.
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
import { extendClient } from '@solana/plugin-core';
|
|
81
|
+
import { ClientWithGetMinimumBalance } from '@solana/plugin-interfaces';
|
|
82
|
+
|
|
83
|
+
function accountCreationPlugin() {
|
|
84
|
+
return <T extends ClientWithGetMinimumBalance>(client: T) =>
|
|
85
|
+
extendClient(client, {
|
|
86
|
+
getAccountCreationCost: async (dataSize: number) => {
|
|
87
|
+
const minimumBalance = await client.getMinimumBalance(dataSize);
|
|
88
|
+
console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`);
|
|
89
|
+
return minimumBalance;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
68
92
|
}
|
|
69
93
|
```
|
|
70
94
|
|
|
@@ -73,17 +97,18 @@ function faucetPlugin() {
|
|
|
73
97
|
Represents a client with access to a Solana RPC endpoint.
|
|
74
98
|
|
|
75
99
|
```ts
|
|
100
|
+
import { extendClient } from '@solana/plugin-core';
|
|
76
101
|
import { ClientWithRpc } from '@solana/plugin-interfaces';
|
|
77
102
|
import { GetBalanceApi } from '@solana/rpc-api';
|
|
78
103
|
|
|
79
104
|
function balancePlugin() {
|
|
80
|
-
return <T extends ClientWithRpc<GetBalanceApi>>(client: T) =>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
return <T extends ClientWithRpc<GetBalanceApi>>(client: T) =>
|
|
106
|
+
extendClient(client, {
|
|
107
|
+
getBalance: async (address: Address): Promise<Lamports> => {
|
|
108
|
+
const { value } = await client.rpc.getBalance(address).send();
|
|
109
|
+
return value;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
87
112
|
}
|
|
88
113
|
```
|
|
89
114
|
|
|
@@ -92,19 +117,20 @@ function balancePlugin() {
|
|
|
92
117
|
Represents a client that provides access to Solana RPC subscriptions for real-time notifications such as account changes, slot updates, and transaction confirmations.
|
|
93
118
|
|
|
94
119
|
```ts
|
|
120
|
+
import { extendClient } from '@solana/plugin-core';
|
|
95
121
|
import { ClientWithRpcSubscriptions } from '@solana/plugin-interfaces';
|
|
96
122
|
import { AccountNotificationsApi } from '@solana/rpc-subscriptions-api';
|
|
97
123
|
|
|
98
124
|
function accountWatcherPlugin() {
|
|
99
|
-
return <T extends ClientWithRpcSubscriptions<AccountNotificationsApi>>(client: T) =>
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
return <T extends ClientWithRpcSubscriptions<AccountNotificationsApi>>(client: T) =>
|
|
126
|
+
extendClient(client, {
|
|
127
|
+
onAccountChange: async (address: Address, callback: (lamports: Lamports) => void) => {
|
|
128
|
+
const subscription = await client.rpcSubscriptions.accountNotifications(address).subscribe();
|
|
129
|
+
for await (const notification of subscription) {
|
|
130
|
+
callback(notification.value.lamports);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
});
|
|
108
134
|
}
|
|
109
135
|
```
|
|
110
136
|
|
|
@@ -114,16 +140,17 @@ Represents a client that can convert instructions or instruction plans into tran
|
|
|
114
140
|
|
|
115
141
|
```ts
|
|
116
142
|
import { flattenTransactionPlan } from '@solana/instruction-plans';
|
|
143
|
+
import { extendClient } from '@solana/plugin-core';
|
|
117
144
|
import { ClientWithTransactionPlanning } from '@solana/plugin-interfaces';
|
|
118
145
|
|
|
119
146
|
function transactionCounterPlugin() {
|
|
120
|
-
return <T extends ClientWithTransactionPlanning>(client: T) =>
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
147
|
+
return <T extends ClientWithTransactionPlanning>(client: T) =>
|
|
148
|
+
extendClient(client, {
|
|
149
|
+
countTransactions: async (instructions: IInstruction[]) => {
|
|
150
|
+
const plan = await client.planTransactions(instructions);
|
|
151
|
+
return flattenTransactionPlan(plan).length;
|
|
152
|
+
},
|
|
153
|
+
});
|
|
127
154
|
}
|
|
128
155
|
```
|
|
129
156
|
|
|
@@ -132,21 +159,22 @@ function transactionCounterPlugin() {
|
|
|
132
159
|
Represents a client that can send transactions to the Solana network. It supports flexible input formats including instructions, instruction plans, transaction messages, or transaction plans.
|
|
133
160
|
|
|
134
161
|
```ts
|
|
162
|
+
import { extendClient } from '@solana/plugin-core';
|
|
135
163
|
import { ClientWithPayer, ClientWithTransactionSending } from '@solana/plugin-interfaces';
|
|
136
164
|
|
|
137
165
|
function transferPlugin() {
|
|
138
|
-
return <T extends ClientWithPayer & ClientWithTransactionSending>(client: T) =>
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
166
|
+
return <T extends ClientWithPayer & ClientWithTransactionSending>(client: T) =>
|
|
167
|
+
extendClient(client, {
|
|
168
|
+
transfer: async (recipient: Address, amount: Lamports) => {
|
|
169
|
+
const instruction = getTransferSolInstruction({
|
|
170
|
+
source: client.payer,
|
|
171
|
+
destination: recipient,
|
|
172
|
+
amount,
|
|
173
|
+
});
|
|
174
|
+
const result = await client.sendTransaction(instruction);
|
|
175
|
+
return result.context.signature;
|
|
176
|
+
},
|
|
177
|
+
});
|
|
150
178
|
}
|
|
151
179
|
```
|
|
152
180
|
|
|
@@ -155,19 +183,18 @@ function transferPlugin() {
|
|
|
155
183
|
Use TypeScript intersection types to require multiple capabilities from the client:
|
|
156
184
|
|
|
157
185
|
```ts
|
|
186
|
+
import { extendClient } from '@solana/plugin-core';
|
|
158
187
|
import { ClientWithPayer, ClientWithRpc, ClientWithTransactionSending } from '@solana/plugin-interfaces';
|
|
159
188
|
import { GetAccountInfoApi } from '@solana/rpc-api';
|
|
160
189
|
|
|
161
190
|
function tokenTransferPlugin() {
|
|
162
|
-
return <T extends ClientWithPayer & ClientWithRpc<GetAccountInfoApi> & ClientWithTransactionSending>(
|
|
163
|
-
client
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
},
|
|
171
|
-
});
|
|
191
|
+
return <T extends ClientWithPayer & ClientWithRpc<GetAccountInfoApi> & ClientWithTransactionSending>(client: T) =>
|
|
192
|
+
extendClient(client, {
|
|
193
|
+
transferToken: async (mint: Address, recipient: Address, amount: bigint) => {
|
|
194
|
+
// Use client.rpc to fetch token accounts
|
|
195
|
+
// Use client.payer as the token owner
|
|
196
|
+
// Use client.sendTransaction to execute the transfer
|
|
197
|
+
},
|
|
198
|
+
});
|
|
172
199
|
}
|
|
173
200
|
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Lamports } from '@solana/rpc-types';
|
|
2
|
+
/**
|
|
3
|
+
* Configuration options for {@link ClientWithGetMinimumBalance.getMinimumBalance}.
|
|
4
|
+
*/
|
|
5
|
+
export type GetMinimumBalanceConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* When `true`, the 128-byte account header is not added to the provided `space` value.
|
|
8
|
+
*
|
|
9
|
+
* By default, the account header (128 bytes) is included in the minimum balance computation
|
|
10
|
+
* on top of the provided `space`. Set this to `true` if the provided `space` already accounts
|
|
11
|
+
* for the header or if you want the minimum balance for the data portion only.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant.
|
|
14
|
+
*/
|
|
15
|
+
withoutHeader?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Represents a client that can compute the minimum balance required for an account to be
|
|
19
|
+
* exempt from deletion.
|
|
20
|
+
*
|
|
21
|
+
* Different implementations may compute this value differently — for example, by calling the
|
|
22
|
+
* `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* async function logAccountCost(client: ClientWithGetMinimumBalance, dataSize: number) {
|
|
27
|
+
* const minimumBalance = await client.getMinimumBalance(dataSize);
|
|
28
|
+
* console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export type ClientWithGetMinimumBalance = {
|
|
33
|
+
/**
|
|
34
|
+
* Computes the minimum lamports required for an account with the given data size.
|
|
35
|
+
*
|
|
36
|
+
* By default, the 128-byte account header is added on top of the provided `space`. Pass
|
|
37
|
+
* `{ withoutHeader: true }` to skip adding the header bytes.
|
|
38
|
+
*
|
|
39
|
+
* @param space - The number of bytes of account data.
|
|
40
|
+
* @param config - Optional configuration for the computation.
|
|
41
|
+
* @returns A promise resolving to the minimum {@link Lamports} required.
|
|
42
|
+
*
|
|
43
|
+
* @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant.
|
|
44
|
+
*/
|
|
45
|
+
getMinimumBalance: (space: number, config?: GetMinimumBalanceConfig) => Promise<Lamports>;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=get-minimum-balance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-minimum-balance.d.ts","sourceRoot":"","sources":["../../src/get-minimum-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAClC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACtC;;;;;;;;;;;OAWG;IACH,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,uBAAuB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7F,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/plugin-interfaces",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.0-canary-20260319134241",
|
|
4
4
|
"description": "TypeScript interfaces for building pluggable Solana clients",
|
|
5
5
|
"homepage": "https://www.solanakit.com/api#solanaplugin-interfaces",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"maintained node versions"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@solana/addresses": "6.
|
|
33
|
-
"@solana/
|
|
34
|
-
"@solana/
|
|
35
|
-
"@solana/rpc-spec": "6.
|
|
36
|
-
"@solana/rpc-subscriptions-spec": "6.
|
|
37
|
-
"@solana/rpc-types": "6.
|
|
38
|
-
"@solana/signers": "6.
|
|
32
|
+
"@solana/addresses": "6.5.0-canary-20260319134241",
|
|
33
|
+
"@solana/instruction-plans": "6.5.0-canary-20260319134241",
|
|
34
|
+
"@solana/keys": "6.5.0-canary-20260319134241",
|
|
35
|
+
"@solana/rpc-spec": "6.5.0-canary-20260319134241",
|
|
36
|
+
"@solana/rpc-subscriptions-spec": "6.5.0-canary-20260319134241",
|
|
37
|
+
"@solana/rpc-types": "6.5.0-canary-20260319134241",
|
|
38
|
+
"@solana/signers": "6.5.0-canary-20260319134241"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": "^5.0.0"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Lamports } from '@solana/rpc-types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for {@link ClientWithGetMinimumBalance.getMinimumBalance}.
|
|
5
|
+
*/
|
|
6
|
+
export type GetMinimumBalanceConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* When `true`, the 128-byte account header is not added to the provided `space` value.
|
|
9
|
+
*
|
|
10
|
+
* By default, the account header (128 bytes) is included in the minimum balance computation
|
|
11
|
+
* on top of the provided `space`. Set this to `true` if the provided `space` already accounts
|
|
12
|
+
* for the header or if you want the minimum balance for the data portion only.
|
|
13
|
+
*
|
|
14
|
+
* @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant.
|
|
15
|
+
*/
|
|
16
|
+
withoutHeader?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Represents a client that can compute the minimum balance required for an account to be
|
|
21
|
+
* exempt from deletion.
|
|
22
|
+
*
|
|
23
|
+
* Different implementations may compute this value differently — for example, by calling the
|
|
24
|
+
* `getMinimumBalanceForRentExemption` RPC method, or by using a locally cached value.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* async function logAccountCost(client: ClientWithGetMinimumBalance, dataSize: number) {
|
|
29
|
+
* const minimumBalance = await client.getMinimumBalance(dataSize);
|
|
30
|
+
* console.log(`Minimum balance for ${dataSize} bytes: ${minimumBalance} lamports`);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export type ClientWithGetMinimumBalance = {
|
|
35
|
+
/**
|
|
36
|
+
* Computes the minimum lamports required for an account with the given data size.
|
|
37
|
+
*
|
|
38
|
+
* By default, the 128-byte account header is added on top of the provided `space`. Pass
|
|
39
|
+
* `{ withoutHeader: true }` to skip adding the header bytes.
|
|
40
|
+
*
|
|
41
|
+
* @param space - The number of bytes of account data.
|
|
42
|
+
* @param config - Optional configuration for the computation.
|
|
43
|
+
* @returns A promise resolving to the minimum {@link Lamports} required.
|
|
44
|
+
*
|
|
45
|
+
* @see {@link @solana/accounts#BASE_ACCOUNT_SIZE | BASE_ACCOUNT_SIZE} for the account header size constant.
|
|
46
|
+
*/
|
|
47
|
+
getMinimumBalance: (space: number, config?: GetMinimumBalanceConfig) => Promise<Lamports>;
|
|
48
|
+
};
|