@revibase/core 0.0.58 → 0.0.60
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 +299 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -18
- package/dist/index.d.ts +42 -18
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# @revibase/core
|
|
2
|
+
|
|
3
|
+
Core types and helpers for Revibase multi-wallet: transfer intents and custom vault-paid transactions (sync or Jito bundles).
|
|
4
|
+
|
|
5
|
+
**Contents:** [Create user](#create-a-user-account) → [Create wallet](#create-a-wallet) → [Transfer intents](#transfer-intents) (SOL / SPL) → [Custom transactions](#custom-transactions-sync-vs-bundle) (sync or Jito).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Create a user account
|
|
10
|
+
|
|
11
|
+
Create one or more user accounts. Each user is identified by a member key (e.g. an Ed25519 signer) and a role. The helper returns an instruction—send it in a transaction with your Solana client.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createUserAccounts, UserRole } from "@revibase/core";
|
|
15
|
+
import type { TransactionSigner } from "gill";
|
|
16
|
+
|
|
17
|
+
declare const payer: TransactionSigner;
|
|
18
|
+
declare const memberSigner: TransactionSigner;
|
|
19
|
+
|
|
20
|
+
const createUserIx = await createUserAccounts({
|
|
21
|
+
payer,
|
|
22
|
+
createUserArgs: [{ member: memberSigner, role: UserRole.Member }],
|
|
23
|
+
});
|
|
24
|
+
// Build a tx with createUserIx; sign with payer + memberSigner, then send.
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Create a wallet
|
|
30
|
+
|
|
31
|
+
Create a wallet (settings + vault) with an existing user as the initial member. The user must exist first (see [Create a user account](#create-a-user-account)). Use the global counter for the next wallet index, then optionally set this wallet as the user’s delegate.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {
|
|
35
|
+
createWallet,
|
|
36
|
+
editUserDelegate,
|
|
37
|
+
fetchGlobalCounter,
|
|
38
|
+
getGlobalCounterAddress,
|
|
39
|
+
getSolanaRpc,
|
|
40
|
+
} from "@revibase/core";
|
|
41
|
+
import type { TransactionSigner } from "gill";
|
|
42
|
+
|
|
43
|
+
declare const payer: TransactionSigner;
|
|
44
|
+
declare const memberSigner: TransactionSigner;
|
|
45
|
+
|
|
46
|
+
const globalCounter = await fetchGlobalCounter(
|
|
47
|
+
getSolanaRpc(),
|
|
48
|
+
await getGlobalCounterAddress(),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const createWalletIx = await createWallet({
|
|
52
|
+
index: globalCounter.data.index,
|
|
53
|
+
payer,
|
|
54
|
+
initialMember: memberSigner,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Build a tx with createWalletIx; sign with payer + memberSigner, then send.
|
|
58
|
+
|
|
59
|
+
const setWalletAsDelegateIx = await editUserDelegate({
|
|
60
|
+
payer,
|
|
61
|
+
user: memberSigner,
|
|
62
|
+
newDelegate: {
|
|
63
|
+
index: globalCounter.data.index,
|
|
64
|
+
settingsAddressTreeIndex: 0,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Build a tx with setWalletAsDelegateIx; sign with payer + memberSigner, then send.
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
After confirmation, use [Resolve settings and compressed flag](#1-resolve-settings-and-compressed-flag) with this index to get `settings`, `compressed`, and `walletAddress` for transfers or custom transactions.
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Transfer intents
|
|
76
|
+
|
|
77
|
+
Move SOL or SPL tokens from a multi-wallet via on-chain intent instructions.
|
|
78
|
+
|
|
79
|
+
### 1. Resolve settings and compressed flag
|
|
80
|
+
|
|
81
|
+
Using the member signer, get the delegated wallet’s settings and compression flag:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import {
|
|
85
|
+
fetchUserAccountData,
|
|
86
|
+
fetchSettingsAccountData,
|
|
87
|
+
getSettingsFromIndex,
|
|
88
|
+
getWalletAddressFromSettings,
|
|
89
|
+
} from "@revibase/core";
|
|
90
|
+
import type { TransactionSigner } from "gill";
|
|
91
|
+
|
|
92
|
+
declare const memberSigner: TransactionSigner;
|
|
93
|
+
|
|
94
|
+
const user = await fetchUserAccountData(memberSigner.address);
|
|
95
|
+
const delegatedWallet = user.wallets.find((w) => w.isDelegate);
|
|
96
|
+
if (!delegatedWallet)
|
|
97
|
+
throw new Error("memberSigner is not delegated to any wallet");
|
|
98
|
+
|
|
99
|
+
const settingsIndex = delegatedWallet.index;
|
|
100
|
+
const settings = await getSettingsFromIndex(settingsIndex);
|
|
101
|
+
const settingsAccount = await fetchSettingsAccountData(settings);
|
|
102
|
+
const compressed = settingsAccount.isCompressed;
|
|
103
|
+
const walletAddress = await getWalletAddressFromSettings(settings);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Use `settings`, `compressed`, and (optionally) `walletAddress` in the following steps.
|
|
107
|
+
|
|
108
|
+
### 2. Native SOL transfer
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { nativeTransferIntent } from "@revibase/core";
|
|
112
|
+
import type { TransactionSigner } from "gill";
|
|
113
|
+
|
|
114
|
+
declare const payer: TransactionSigner;
|
|
115
|
+
declare const memberSigner: TransactionSigner;
|
|
116
|
+
declare const destination: string;
|
|
117
|
+
|
|
118
|
+
const { transactionManagerAddress, userAddressTreeIndex } =
|
|
119
|
+
retrieveTransactionManager(memberSigner.address.toString(), settingsAccount);
|
|
120
|
+
const transactionManagerSigner = await getSignedTransactionManager({
|
|
121
|
+
transactionMessageBytes,
|
|
122
|
+
transactionManagerAddress,
|
|
123
|
+
userAddressTreeIndex,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const instructions = await nativeTransferIntent({
|
|
127
|
+
settings,
|
|
128
|
+
destination,
|
|
129
|
+
amount: 100_000n, // lamports
|
|
130
|
+
signers: [
|
|
131
|
+
memberSigner,
|
|
132
|
+
...(transactionManagerSigner ? [transactionManagerSigner] : []),
|
|
133
|
+
],
|
|
134
|
+
payer,
|
|
135
|
+
compressed,
|
|
136
|
+
});
|
|
137
|
+
// Send instructions in a transaction. With a transaction manager, add its signer to signers (retrieveTransactionManager + getSignedTransactionManager).
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. SPL / Token-2022 transfer
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { tokenTransferIntent } from "@revibase/core";
|
|
144
|
+
import type { Address, TransactionSigner } from "gill";
|
|
145
|
+
import { TOKEN_2022_PROGRAM_ADDRESS } from "gill/programs";
|
|
146
|
+
|
|
147
|
+
declare const payer: TransactionSigner;
|
|
148
|
+
declare const memberSigner: TransactionSigner;
|
|
149
|
+
declare const destinationWallet: Address;
|
|
150
|
+
declare const mint: Address;
|
|
151
|
+
|
|
152
|
+
const { transactionManagerAddress, userAddressTreeIndex } =
|
|
153
|
+
retrieveTransactionManager(memberSigner.address.toString(), settingsAccount);
|
|
154
|
+
const transactionManagerSigner = await getSignedTransactionManager({
|
|
155
|
+
transactionMessageBytes,
|
|
156
|
+
transactionManagerAddress,
|
|
157
|
+
userAddressTreeIndex,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const instructions = await tokenTransferIntent({
|
|
161
|
+
settings,
|
|
162
|
+
payer,
|
|
163
|
+
signers: [
|
|
164
|
+
memberSigner,
|
|
165
|
+
...(transactionManagerSigner ? [transactionManagerSigner] : []),
|
|
166
|
+
],
|
|
167
|
+
destination: destinationWallet,
|
|
168
|
+
amount: 1_000_000n,
|
|
169
|
+
mint,
|
|
170
|
+
tokenProgram: TOKEN_2022_PROGRAM_ADDRESS,
|
|
171
|
+
compressed,
|
|
172
|
+
});
|
|
173
|
+
// Send instructions in a transaction (same signer pattern as native transfer if using a transaction manager).
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Custom transactions (sync vs bundle)
|
|
179
|
+
|
|
180
|
+
- **Small tx size** → **sync**: `prepareTransactionMessage` → `prepareTransactionSync` → `signAndSendTransaction`
|
|
181
|
+
- **Larger tx size** → **Jito bundle**: `prepareTransactionMessage` → `prepareTransactionBundle` → `signAndSendBundledTransactions`
|
|
182
|
+
|
|
183
|
+
Prerequisite: `settings`, `compressed`, `walletAddress`, and `settingsAccount` from [Resolve settings and compressed flag](#1-resolve-settings-and-compressed-flag).
|
|
184
|
+
|
|
185
|
+
### Sync: prepareTransactionSync
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
import {
|
|
189
|
+
prepareTransactionMessage,
|
|
190
|
+
prepareTransactionSync,
|
|
191
|
+
signAndSendTransaction,
|
|
192
|
+
retrieveTransactionManager,
|
|
193
|
+
getSignedTransactionManager,
|
|
194
|
+
} from "@revibase/core";
|
|
195
|
+
import {
|
|
196
|
+
createNoopSigner,
|
|
197
|
+
type Address,
|
|
198
|
+
type AddressesByLookupTableAddress,
|
|
199
|
+
type TransactionSigner,
|
|
200
|
+
} from "gill";
|
|
201
|
+
import { getTransferSolInstruction } from "gill/programs";
|
|
202
|
+
|
|
203
|
+
declare const destination: Address;
|
|
204
|
+
declare const payer: TransactionSigner;
|
|
205
|
+
declare const memberSigner: TransactionSigner;
|
|
206
|
+
declare const addressLookups: AddressesByLookupTableAddress | undefined;
|
|
207
|
+
|
|
208
|
+
const transferIx = getTransferSolInstruction({
|
|
209
|
+
source: createNoopSigner(walletAddress),
|
|
210
|
+
destination,
|
|
211
|
+
amount: 1_000_000n,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const transactionMessageBytes = prepareTransactionMessage({
|
|
215
|
+
payer: walletAddress,
|
|
216
|
+
instructions: [transferIx],
|
|
217
|
+
addressesByLookupTableAddress: addressLookups,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const { transactionManagerAddress, userAddressTreeIndex } =
|
|
221
|
+
retrieveTransactionManager(memberSigner.address.toString(), settingsAccount);
|
|
222
|
+
const transactionManagerSigner = await getSignedTransactionManager({
|
|
223
|
+
transactionMessageBytes,
|
|
224
|
+
transactionManagerAddress,
|
|
225
|
+
userAddressTreeIndex,
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
const details = await prepareTransactionSync({
|
|
229
|
+
compressed,
|
|
230
|
+
payer,
|
|
231
|
+
settings,
|
|
232
|
+
transactionMessageBytes,
|
|
233
|
+
signers: [
|
|
234
|
+
memberSigner,
|
|
235
|
+
...(transactionManagerSigner ? [transactionManagerSigner] : []),
|
|
236
|
+
],
|
|
237
|
+
addressesByLookupTableAddress: addressLookups,
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const signature = await signAndSendTransaction(details);
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Jito bundle
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import {
|
|
247
|
+
prepareTransactionMessage,
|
|
248
|
+
prepareTransactionBundle,
|
|
249
|
+
signAndSendBundledTransactions,
|
|
250
|
+
pollJitoBundleConfirmation,
|
|
251
|
+
retrieveTransactionManager,
|
|
252
|
+
getSignedTransactionManager,
|
|
253
|
+
} from "@revibase/core";
|
|
254
|
+
import {
|
|
255
|
+
createNoopSigner,
|
|
256
|
+
type Address,
|
|
257
|
+
type AddressesByLookupTableAddress,
|
|
258
|
+
type TransactionSigner,
|
|
259
|
+
} from "gill";
|
|
260
|
+
import { getTransferSolInstruction } from "gill/programs";
|
|
261
|
+
|
|
262
|
+
declare const destination: Address;
|
|
263
|
+
declare const payer: TransactionSigner;
|
|
264
|
+
declare const memberSigner: TransactionSigner;
|
|
265
|
+
declare const addressLookups: AddressesByLookupTableAddress | undefined;
|
|
266
|
+
|
|
267
|
+
const transferIx = getTransferSolInstruction({
|
|
268
|
+
source: createNoopSigner(walletAddress),
|
|
269
|
+
destination,
|
|
270
|
+
amount: 1_000_000n,
|
|
271
|
+
});
|
|
272
|
+
const transactionMessageBytes = prepareTransactionMessage({
|
|
273
|
+
payer: walletAddress,
|
|
274
|
+
instructions: [transferIx],
|
|
275
|
+
addressesByLookupTableAddress: addressLookups,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const { transactionManagerAddress, userAddressTreeIndex } =
|
|
279
|
+
retrieveTransactionManager(memberSigner.address.toString(), settingsAccount);
|
|
280
|
+
const transactionManagerSigner = await getSignedTransactionManager({
|
|
281
|
+
transactionMessageBytes,
|
|
282
|
+
transactionManagerAddress,
|
|
283
|
+
userAddressTreeIndex,
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const bundle = await prepareTransactionBundle({
|
|
287
|
+
payer,
|
|
288
|
+
settings,
|
|
289
|
+
transactionMessageBytes,
|
|
290
|
+
creator: transactionManagerSigner ?? memberSigner,
|
|
291
|
+
executor: transactionManagerSigner ? memberSigner : undefined,
|
|
292
|
+
compressed,
|
|
293
|
+
addressesByLookupTableAddress: addressLookups,
|
|
294
|
+
jitoBundlesTipAmount: 10_000, // optional, lamports
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
const bundleId = await signAndSendBundledTransactions(bundle);
|
|
298
|
+
const signature = await pollJitoBundleConfirmation(bundleId);
|
|
299
|
+
```
|