@loyal-labs/transactions 0.1.0 → 0.1.2

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 CHANGED
@@ -34,6 +34,15 @@ const result = await client.deposit({
34
34
 
35
35
  console.log("Transaction:", result.signature);
36
36
  console.log("Deposited:", result.deposit.amount, "lamports");
37
+
38
+ // Refund some of the deposit
39
+ const refundResult = await client.refund({
40
+ username: "alice",
41
+ amountLamports: solToLamports(0.05), // 0.05 SOL
42
+ });
43
+
44
+ console.log("Refunded:", refundResult.signature);
45
+ console.log("Remaining:", refundResult.deposit.amount, "lamports");
37
46
  ```
38
47
 
39
48
  ## Usage
@@ -146,6 +155,35 @@ interface DepositResult {
146
155
  }
147
156
  ```
148
157
 
158
+ ##### `refund(params): Promise<RefundResult>`
159
+
160
+ Refund SOL from a deposit back to the depositor's wallet.
161
+
162
+ ```typescript
163
+ interface RefundParams {
164
+ username: string; // Telegram username (5-32 chars, without @)
165
+ amountLamports: number | bigint; // Amount in lamports to refund
166
+ commitment?: Commitment; // Optional, defaults to 'confirmed'
167
+ }
168
+
169
+ interface RefundResult {
170
+ signature: string; // Transaction signature
171
+ deposit: DepositData; // Updated deposit account data
172
+ }
173
+ ```
174
+
175
+ Example:
176
+
177
+ ```typescript
178
+ const result = await client.refund({
179
+ username: "alice",
180
+ amountLamports: solToLamports(0.05),
181
+ });
182
+
183
+ console.log("Refunded:", result.signature);
184
+ console.log("Remaining balance:", result.deposit.amount);
185
+ ```
186
+
149
187
  ##### `getDeposit(depositor, username): Promise<DepositData | null>`
150
188
 
151
189
  Fetch deposit data for a specific depositor and username.
@@ -275,7 +313,9 @@ try {
275
313
 
276
314
  Common errors:
277
315
  - `"Username must be between 5 and 32 characters"` - Invalid username length
278
- - `"Amount must be greater than 0"` - Invalid deposit amount
316
+ - `"Amount must be greater than 0"` - Invalid amount
317
+ - `"No deposit found for this username"` - Deposit doesn't exist (refund only)
318
+ - `"Insufficient deposit"` - Refund amount exceeds deposit balance
279
319
  - `"Failed to fetch deposit account after transaction"` - Network/confirmation issue
280
320
 
281
321
  ## Development
package/dist/index.d.ts CHANGED
@@ -40,7 +40,7 @@
40
40
  * const client = LoyalTransactionsClient.fromProvider(provider);
41
41
  */
42
42
  export { LoyalTransactionsClient } from "./src/LoyalTransactionsClient";
43
- export type { WalletSigner, WalletLike, DepositParams, DepositResult, DepositData, } from "./src/types";
43
+ export type { WalletSigner, WalletLike, DepositParams, DepositResult, RefundParams, RefundResult, DepositData, } from "./src/types";
44
44
  export { isKeypair, isAnchorProvider, isWalletLike } from "./src/types";
45
45
  export { PROGRAM_ID, DEPOSIT_SEED, VAULT_SEED, LAMPORTS_PER_SOL, solToLamports, lamportsToSol, } from "./src/constants";
46
46
  export { findDepositPda, findVaultPda } from "./src/pda";
package/dist/index.js CHANGED
@@ -473,6 +473,41 @@ class LoyalTransactionsClient {
473
473
  deposit
474
474
  };
475
475
  }
476
+ async refund(params) {
477
+ const { username, amountLamports, commitment = "confirmed" } = params;
478
+ if (!username || username.length < 5 || username.length > 32) {
479
+ throw new Error("Username must be between 5 and 32 characters");
480
+ }
481
+ if (amountLamports <= 0) {
482
+ throw new Error("Amount must be greater than 0");
483
+ }
484
+ const depositor = this.wallet.publicKey;
485
+ const currentDeposit = await this.getDeposit(depositor, username);
486
+ if (!currentDeposit) {
487
+ throw new Error("No deposit found for this username");
488
+ }
489
+ if (currentDeposit.amount < amountLamports) {
490
+ throw new Error("Insufficient deposit");
491
+ }
492
+ const [depositPda] = findDepositPda(depositor, username);
493
+ const [vaultPda] = findVaultPda();
494
+ const amountBN = new BN(amountLamports.toString());
495
+ const signature = await this.program.methods.refundDeposit(amountBN).accountsPartial({
496
+ depositor,
497
+ vault: vaultPda,
498
+ deposit: depositPda
499
+ }).rpc({ commitment });
500
+ console.log("Transaction:", signature);
501
+ const deposit = await this.getDeposit(depositor, username);
502
+ console.log("Deposit:", deposit);
503
+ if (!deposit) {
504
+ throw new Error("Failed to fetch deposit account after transaction");
505
+ }
506
+ return {
507
+ signature,
508
+ deposit
509
+ };
510
+ }
476
511
  async getDeposit(depositor, username) {
477
512
  const [depositPda] = findDepositPda(depositor, username);
478
513
  try {
@@ -1,7 +1,7 @@
1
1
  import { Connection, PublicKey, Keypair } from "@solana/web3.js";
2
2
  import { AnchorProvider, Program } from "@coral-xyz/anchor";
3
3
  import { type TelegramTransfer } from "./idl";
4
- import type { WalletSigner, WalletLike, DepositParams, DepositResult, DepositData } from "./types";
4
+ import type { WalletSigner, WalletLike, DepositParams, DepositResult, RefundParams, RefundResult, DepositData } from "./types";
5
5
  /**
6
6
  * LoyalTransactionsClient - SDK for interacting with the Telegram Transfer program
7
7
  *
@@ -82,6 +82,25 @@ export declare class LoyalTransactionsClient {
82
82
  * console.log('Deposit amount:', result.deposit.amount);
83
83
  */
84
84
  deposit(params: DepositParams): Promise<DepositResult>;
85
+ /**
86
+ * Refund SOL from a deposit
87
+ *
88
+ * Withdraws the specified amount from the deposit back to the depositor's wallet.
89
+ * Only the original depositor can refund their deposit.
90
+ *
91
+ * @param params - Refund parameters
92
+ * @returns Transaction signature and updated deposit data
93
+ *
94
+ * @example
95
+ * const result = await client.refund({
96
+ * username: 'alice',
97
+ * amountLamports: 50_000_000, // 0.05 SOL
98
+ * });
99
+ *
100
+ * console.log('Signature:', result.signature);
101
+ * console.log('Remaining deposit:', result.deposit.amount);
102
+ */
103
+ refund(params: RefundParams): Promise<RefundResult>;
85
104
  /**
86
105
  * Get deposit data for a specific depositor and username
87
106
  *
@@ -36,6 +36,26 @@ export interface DepositResult {
36
36
  /** Updated deposit account data */
37
37
  deposit: DepositData;
38
38
  }
39
+ /**
40
+ * Parameters for refunding SOL from a deposit
41
+ */
42
+ export interface RefundParams {
43
+ /** Telegram username (without @, 5-32 characters) */
44
+ username: string;
45
+ /** Amount in lamports to refund */
46
+ amountLamports: number | bigint;
47
+ /** Transaction commitment level (default: 'confirmed') */
48
+ commitment?: Commitment;
49
+ }
50
+ /**
51
+ * Result of a successful refund transaction
52
+ */
53
+ export interface RefundResult {
54
+ /** Transaction signature */
55
+ signature: string;
56
+ /** Updated deposit account data */
57
+ deposit: DepositData;
58
+ }
39
59
  /**
40
60
  * Deposit account data structure
41
61
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loyal-labs/transactions",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "SDK for Telegram-based Solana deposits",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,13 +38,13 @@
38
38
  "license": "MIT",
39
39
  "repository": {
40
40
  "type": "git",
41
- "url": "https://github.com/loyal/solana-telegram-transactions.git",
41
+ "url": "https://github.com/loyal/loyal-app.git",
42
42
  "directory": "sdk/transactions"
43
43
  },
44
44
  "bugs": {
45
- "url": "https://github.com/loyal/solana-telegram-transactions/issues"
45
+ "url": "https://github.com/loyal/loyal-app/issues"
46
46
  },
47
- "homepage": "https://github.com/loyal/solana-telegram-transactions/tree/main/sdk/transactions#readme",
47
+ "homepage": "https://github.com/loyal/loyal-app/tree/main/sdk/transactions#readme",
48
48
  "peerDependencies": {
49
49
  "@coral-xyz/anchor": "^0.32.0",
50
50
  "@solana/web3.js": "^1.95.0"