@loyal-labs/transactions 0.1.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/README.md +292 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +521 -0
- package/dist/src/LoyalTransactionsClient.d.ts +126 -0
- package/dist/src/constants.d.ts +27 -0
- package/dist/src/idl.d.ts +336 -0
- package/dist/src/pda.d.ts +17 -0
- package/dist/src/types.d.ts +65 -0
- package/dist/src/wallet-adapter.d.ts +31 -0
- package/package.json +58 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bundled IDL for the Telegram Transfer program
|
|
3
|
+
* Program ID: 4ewpzEPF5xrVAHeRkoe7XS1yKFGQBekD7PgFwEz9SaxY
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Program IDL type definition (camelCase for JS/TS usage)
|
|
7
|
+
*/
|
|
8
|
+
export type TelegramTransfer = {
|
|
9
|
+
address: "4ewpzEPF5xrVAHeRkoe7XS1yKFGQBekD7PgFwEz9SaxY";
|
|
10
|
+
metadata: {
|
|
11
|
+
name: "telegramTransfer";
|
|
12
|
+
version: "0.1.0";
|
|
13
|
+
spec: "0.1.0";
|
|
14
|
+
description: "Created with Anchor";
|
|
15
|
+
};
|
|
16
|
+
instructions: [
|
|
17
|
+
{
|
|
18
|
+
name: "claimDeposit";
|
|
19
|
+
discriminator: [201, 106, 1, 224, 122, 144, 210, 155];
|
|
20
|
+
accounts: [
|
|
21
|
+
{
|
|
22
|
+
name: "recipient";
|
|
23
|
+
docs: ["can be a new address"];
|
|
24
|
+
writable: true;
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "vault";
|
|
28
|
+
writable: true;
|
|
29
|
+
pda: {
|
|
30
|
+
seeds: [
|
|
31
|
+
{
|
|
32
|
+
kind: "const";
|
|
33
|
+
value: [118, 97, 117, 108, 116];
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "deposit";
|
|
40
|
+
writable: true;
|
|
41
|
+
pda: {
|
|
42
|
+
seeds: [
|
|
43
|
+
{
|
|
44
|
+
kind: "const";
|
|
45
|
+
value: [100, 101, 112, 111, 115, 105, 116];
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
kind: "account";
|
|
49
|
+
path: "deposit.user";
|
|
50
|
+
account: "deposit";
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
kind: "account";
|
|
54
|
+
path: "deposit.username";
|
|
55
|
+
account: "deposit";
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "session";
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "systemProgram";
|
|
65
|
+
address: "11111111111111111111111111111111";
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
args: [
|
|
69
|
+
{
|
|
70
|
+
name: "amount";
|
|
71
|
+
type: "u64";
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "depositForUsername";
|
|
77
|
+
discriminator: [85, 11, 120, 21, 51, 229, 125, 220];
|
|
78
|
+
accounts: [
|
|
79
|
+
{
|
|
80
|
+
name: "payer";
|
|
81
|
+
writable: true;
|
|
82
|
+
signer: true;
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "depositor";
|
|
86
|
+
writable: true;
|
|
87
|
+
signer: true;
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "vault";
|
|
91
|
+
writable: true;
|
|
92
|
+
pda: {
|
|
93
|
+
seeds: [
|
|
94
|
+
{
|
|
95
|
+
kind: "const";
|
|
96
|
+
value: [118, 97, 117, 108, 116];
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: "deposit";
|
|
103
|
+
writable: true;
|
|
104
|
+
pda: {
|
|
105
|
+
seeds: [
|
|
106
|
+
{
|
|
107
|
+
kind: "const";
|
|
108
|
+
value: [100, 101, 112, 111, 115, 105, 116];
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
kind: "account";
|
|
112
|
+
path: "depositor";
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
kind: "arg";
|
|
116
|
+
path: "username";
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: "systemProgram";
|
|
123
|
+
address: "11111111111111111111111111111111";
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
args: [
|
|
127
|
+
{
|
|
128
|
+
name: "username";
|
|
129
|
+
type: "string";
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "amount";
|
|
133
|
+
type: "u64";
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: "refundDeposit";
|
|
139
|
+
discriminator: [19, 19, 78, 50, 187, 10, 162, 229];
|
|
140
|
+
accounts: [
|
|
141
|
+
{
|
|
142
|
+
name: "depositor";
|
|
143
|
+
writable: true;
|
|
144
|
+
signer: true;
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "vault";
|
|
148
|
+
writable: true;
|
|
149
|
+
pda: {
|
|
150
|
+
seeds: [
|
|
151
|
+
{
|
|
152
|
+
kind: "const";
|
|
153
|
+
value: [118, 97, 117, 108, 116];
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: "deposit";
|
|
160
|
+
writable: true;
|
|
161
|
+
pda: {
|
|
162
|
+
seeds: [
|
|
163
|
+
{
|
|
164
|
+
kind: "const";
|
|
165
|
+
value: [100, 101, 112, 111, 115, 105, 116];
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
kind: "account";
|
|
169
|
+
path: "depositor";
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
kind: "account";
|
|
173
|
+
path: "deposit.username";
|
|
174
|
+
account: "deposit";
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
args: [
|
|
181
|
+
{
|
|
182
|
+
name: "amount";
|
|
183
|
+
type: "u64";
|
|
184
|
+
}
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
];
|
|
188
|
+
accounts: [
|
|
189
|
+
{
|
|
190
|
+
name: "deposit";
|
|
191
|
+
discriminator: [148, 146, 121, 66, 207, 173, 21, 227];
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "telegramSession";
|
|
195
|
+
discriminator: [166, 166, 101, 241, 97, 253, 72, 138];
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
name: "vault";
|
|
199
|
+
discriminator: [211, 8, 232, 43, 2, 152, 117, 119];
|
|
200
|
+
}
|
|
201
|
+
];
|
|
202
|
+
errors: [
|
|
203
|
+
{
|
|
204
|
+
code: 6000;
|
|
205
|
+
name: "overflow";
|
|
206
|
+
msg: "overflow";
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
code: 6001;
|
|
210
|
+
name: "insufficientVault";
|
|
211
|
+
msg: "Insufficient Vault";
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
code: 6002;
|
|
215
|
+
name: "insufficientDeposit";
|
|
216
|
+
msg: "Insufficient Deposit";
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
code: 6003;
|
|
220
|
+
name: "notVerified";
|
|
221
|
+
msg: "Not Verified";
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
code: 6004;
|
|
225
|
+
name: "expiredSignature";
|
|
226
|
+
msg: "Expired Signature";
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
code: 6005;
|
|
230
|
+
name: "replay";
|
|
231
|
+
msg: "replay";
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
code: 6006;
|
|
235
|
+
name: "invalidEd25519";
|
|
236
|
+
msg: "Invalid Ed25519";
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
code: 6007;
|
|
240
|
+
name: "invalidUsername";
|
|
241
|
+
msg: "Invalid Username";
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
code: 6008;
|
|
245
|
+
name: "invalidRecipient";
|
|
246
|
+
msg: "Invalid Recipient";
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
code: 6009;
|
|
250
|
+
name: "invalidDepositor";
|
|
251
|
+
msg: "Invalid Depositor";
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
types: [
|
|
255
|
+
{
|
|
256
|
+
name: "deposit";
|
|
257
|
+
docs: ["A deposit account for a user and token mint."];
|
|
258
|
+
type: {
|
|
259
|
+
kind: "struct";
|
|
260
|
+
fields: [
|
|
261
|
+
{
|
|
262
|
+
name: "user";
|
|
263
|
+
type: "pubkey";
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "username";
|
|
267
|
+
type: "string";
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
name: "amount";
|
|
271
|
+
type: "u64";
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "lastNonce";
|
|
275
|
+
type: "u64";
|
|
276
|
+
}
|
|
277
|
+
];
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
name: "telegramSession";
|
|
282
|
+
type: {
|
|
283
|
+
kind: "struct";
|
|
284
|
+
fields: [
|
|
285
|
+
{
|
|
286
|
+
name: "userWallet";
|
|
287
|
+
type: "pubkey";
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: "username";
|
|
291
|
+
type: "string";
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
name: "validationBytes";
|
|
295
|
+
type: "bytes";
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
name: "verified";
|
|
299
|
+
type: "bool";
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: "authAt";
|
|
303
|
+
type: "u64";
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
name: "verifiedAt";
|
|
307
|
+
type: {
|
|
308
|
+
option: "u64";
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
};
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
name: "vault";
|
|
316
|
+
docs: ["A vault storing deposited SOL."];
|
|
317
|
+
type: {
|
|
318
|
+
kind: "struct";
|
|
319
|
+
fields: [
|
|
320
|
+
{
|
|
321
|
+
name: "bump";
|
|
322
|
+
type: "u8";
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
name: "totalDeposited";
|
|
326
|
+
type: "u64";
|
|
327
|
+
}
|
|
328
|
+
];
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
];
|
|
332
|
+
};
|
|
333
|
+
/**
|
|
334
|
+
* Bundled IDL constant for the Telegram Transfer program
|
|
335
|
+
*/
|
|
336
|
+
export declare const IDL: TelegramTransfer;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Derive the deposit PDA for a user and username
|
|
4
|
+
*
|
|
5
|
+
* @param depositor - The depositor's public key
|
|
6
|
+
* @param username - The Telegram username
|
|
7
|
+
* @param programId - Optional program ID (defaults to PROGRAM_ID)
|
|
8
|
+
* @returns [PDA address, bump seed]
|
|
9
|
+
*/
|
|
10
|
+
export declare function findDepositPda(depositor: PublicKey, username: string, programId?: PublicKey): [PublicKey, number];
|
|
11
|
+
/**
|
|
12
|
+
* Derive the vault PDA
|
|
13
|
+
*
|
|
14
|
+
* @param programId - Optional program ID (defaults to PROGRAM_ID)
|
|
15
|
+
* @returns [PDA address, bump seed]
|
|
16
|
+
*/
|
|
17
|
+
export declare function findVaultPda(programId?: PublicKey): [PublicKey, number];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PublicKey, Transaction, VersionedTransaction, Keypair, Commitment } from "@solana/web3.js";
|
|
2
|
+
import type { AnchorProvider } from "@coral-xyz/anchor";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal wallet interface matching @solana/wallet-adapter-base
|
|
5
|
+
* Compatible with browser wallet adapters (Phantom, Solflare, etc.)
|
|
6
|
+
*/
|
|
7
|
+
export interface WalletLike {
|
|
8
|
+
publicKey: PublicKey;
|
|
9
|
+
signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
|
|
10
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Union type supporting multiple wallet types:
|
|
14
|
+
* - WalletLike: Browser wallet adapters (Phantom, Solflare, etc.)
|
|
15
|
+
* - Keypair: Server-side scripts and testing
|
|
16
|
+
* - AnchorProvider: Existing Anchor projects
|
|
17
|
+
*/
|
|
18
|
+
export type WalletSigner = WalletLike | Keypair | AnchorProvider;
|
|
19
|
+
/**
|
|
20
|
+
* Parameters for depositing SOL for a Telegram username
|
|
21
|
+
*/
|
|
22
|
+
export interface DepositParams {
|
|
23
|
+
/** Telegram username (without @, 5-32 characters) */
|
|
24
|
+
username: string;
|
|
25
|
+
/** Amount in lamports to deposit */
|
|
26
|
+
amountLamports: number | bigint;
|
|
27
|
+
/** Transaction commitment level (default: 'confirmed') */
|
|
28
|
+
commitment?: Commitment;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Result of a successful deposit transaction
|
|
32
|
+
*/
|
|
33
|
+
export interface DepositResult {
|
|
34
|
+
/** Transaction signature */
|
|
35
|
+
signature: string;
|
|
36
|
+
/** Updated deposit account data */
|
|
37
|
+
deposit: DepositData;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Deposit account data structure
|
|
41
|
+
*/
|
|
42
|
+
export interface DepositData {
|
|
43
|
+
/** Wallet address of the depositor */
|
|
44
|
+
user: PublicKey;
|
|
45
|
+
/** Telegram username */
|
|
46
|
+
username: string;
|
|
47
|
+
/** Total deposited amount in lamports */
|
|
48
|
+
amount: number;
|
|
49
|
+
/** Last nonce used (for replay protection) */
|
|
50
|
+
lastNonce: number;
|
|
51
|
+
/** PDA address of the deposit account */
|
|
52
|
+
address: PublicKey;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if signer is a raw Keypair
|
|
56
|
+
*/
|
|
57
|
+
export declare function isKeypair(signer: WalletSigner): signer is Keypair;
|
|
58
|
+
/**
|
|
59
|
+
* Check if signer is an AnchorProvider
|
|
60
|
+
*/
|
|
61
|
+
export declare function isAnchorProvider(signer: WalletSigner): signer is AnchorProvider;
|
|
62
|
+
/**
|
|
63
|
+
* Check if signer is a WalletLike (wallet adapter)
|
|
64
|
+
*/
|
|
65
|
+
export declare function isWalletLike(signer: WalletSigner): signer is WalletLike;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PublicKey, Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { type WalletSigner, type WalletLike } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Internal wallet adapter that normalizes different wallet types
|
|
5
|
+
* to a common interface compatible with AnchorProvider
|
|
6
|
+
*/
|
|
7
|
+
export declare class InternalWalletAdapter implements WalletLike {
|
|
8
|
+
private readonly signer;
|
|
9
|
+
readonly publicKey: PublicKey;
|
|
10
|
+
private constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Create an adapter from any supported wallet type
|
|
13
|
+
*/
|
|
14
|
+
static from(signer: WalletSigner): InternalWalletAdapter;
|
|
15
|
+
/**
|
|
16
|
+
* Extract public key from any supported wallet type
|
|
17
|
+
*/
|
|
18
|
+
static getPublicKey(signer: WalletSigner): PublicKey;
|
|
19
|
+
/**
|
|
20
|
+
* Sign a single transaction
|
|
21
|
+
*/
|
|
22
|
+
signTransaction<T extends Transaction | VersionedTransaction>(tx: T): Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Sign multiple transactions
|
|
25
|
+
*/
|
|
26
|
+
signAllTransactions<T extends Transaction | VersionedTransaction>(txs: T[]): Promise<T[]>;
|
|
27
|
+
/**
|
|
28
|
+
* Sign a transaction with a Keypair
|
|
29
|
+
*/
|
|
30
|
+
private signWithKeypair;
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loyal-labs/transactions",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SDK for Telegram-based Solana deposits",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"build": "bun run build:js && bun run build:types",
|
|
21
|
+
"build:js": "bun build ./index.ts --outdir ./dist --target node --format esm --external @coral-xyz/anchor --external @solana/web3.js --external bn.js",
|
|
22
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
23
|
+
"prepublishOnly": "bun run build",
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"test": "bun test"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"solana",
|
|
29
|
+
"telegram",
|
|
30
|
+
"anchor",
|
|
31
|
+
"web3",
|
|
32
|
+
"crypto",
|
|
33
|
+
"blockchain",
|
|
34
|
+
"deposit",
|
|
35
|
+
"transfer"
|
|
36
|
+
],
|
|
37
|
+
"author": "Loyal",
|
|
38
|
+
"license": "MIT",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "https://github.com/loyal/solana-telegram-transactions.git",
|
|
42
|
+
"directory": "sdk/transactions"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/loyal/solana-telegram-transactions/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/loyal/solana-telegram-transactions/tree/main/sdk/transactions#readme",
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@coral-xyz/anchor": "^0.32.0",
|
|
50
|
+
"@solana/web3.js": "^1.95.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@coral-xyz/anchor": "^0.32.1",
|
|
54
|
+
"@solana/web3.js": "^1.95.0",
|
|
55
|
+
"@types/bun": "latest",
|
|
56
|
+
"typescript": "^5"
|
|
57
|
+
}
|
|
58
|
+
}
|