privacycash 1.2.2 → 1.2.3
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 +8 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.js +6 -6
- package/dist/withdraw.d.ts +3 -2
- package/dist/withdraw.js +5 -5
- package/dist/withdrawSPL.d.ts +3 -2
- package/dist/withdrawSPL.js +5 -5
- package/package.json +2 -2
- package/src/index.ts +10 -10
- package/src/withdraw.ts +9 -9
- package/src/withdrawSPL.ts +8 -8
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
This is the SDK for Privacy Cash. It has been audited by Zigtur (https://x.com/zigtur).
|
|
3
3
|
|
|
4
4
|
### Disclaimer
|
|
5
|
-
This SDK powers Privacy Cash's frontend, assuming the single wallet use case.
|
|
5
|
+
This SDK powers Privacy Cash's frontend, assuming the single wallet use case. It is NOT supposed to support hardware wallet.
|
|
6
|
+
|
|
7
|
+
If you use it or published npm library from this repo, please fully test and beware of the inherent software risks or potential bugs. Our team is not responsible for any losses.
|
|
6
8
|
|
|
7
9
|
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
8
10
|
|
|
@@ -18,6 +20,8 @@ depositSPL(), withdrawSPL(), getPrivateBalanceSpl()
|
|
|
18
20
|
For backend integration:
|
|
19
21
|
Check the example project under /example folder. The code should be fairly self-explanatory.
|
|
20
22
|
|
|
23
|
+
For SDK referral attribution, pass the database-assigned partner id when withdrawing, for example `privacyCash.withdraw({ lamports: 10000000, referralId: 'partner_id' })`. The same `referralId` option is available on `withdrawUSDC` and `withdrawSPL`. Invalid or inactive ids are rejected before the withdrawal is submitted. The old `referrer` wallet-address option does not enroll a withdrawal in this program. When a referral id is supplied, check `referralRecorded` in the result; a false value means the withdrawal succeeded but the referral entry needs reconciliation using `tx`.
|
|
24
|
+
|
|
21
25
|
For frontend integration:
|
|
22
26
|
Check the example project above, but also refer to: https://gist.github.com/SocialfiPanda/c63786b5dd156e59847e9a4afca31a77
|
|
23
27
|
|
|
@@ -31,6 +35,9 @@ Next.js project needs to update the postinstall build scripts:
|
|
|
31
35
|
|
|
32
36
|
Use node version 24 or above.
|
|
33
37
|
|
|
38
|
+
### Warnings
|
|
39
|
+
Privacy Cash SDK requires consistent signature generation, otherwise the deposited tokens might be lost forever since the encrypted UTXO can't be decrypted. For frontend, please make sure deriveEncryptionKeyFromSignature() generates the same result for the same params passed in, and for backend, please make sure deriveEncryptionKeyFromWallet() generates the same result. Most wallets returns the same result, but some non major wallets might generate different result.
|
|
40
|
+
|
|
34
41
|
### Tests
|
|
35
42
|
1. To run unit tests:
|
|
36
43
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -45,32 +45,34 @@ export declare class PrivacyCash {
|
|
|
45
45
|
*
|
|
46
46
|
* Lamports is the amount of SOL in lamports. e.g. if you want to withdraw 0.01 SOL (10000000 lamports), call withdraw({ lamports: 10000000 })
|
|
47
47
|
*/
|
|
48
|
-
withdraw({ lamports, recipientAddress,
|
|
48
|
+
withdraw({ lamports, recipientAddress, referralId }: {
|
|
49
49
|
lamports: number;
|
|
50
50
|
recipientAddress?: string;
|
|
51
|
-
|
|
51
|
+
referralId?: string;
|
|
52
52
|
}): Promise<{
|
|
53
53
|
isPartial: boolean;
|
|
54
54
|
tx: string;
|
|
55
55
|
recipient: string;
|
|
56
56
|
amount_in_lamports: number;
|
|
57
57
|
fee_in_lamports: number;
|
|
58
|
+
referralRecorded: boolean | undefined;
|
|
58
59
|
}>;
|
|
59
60
|
/**
|
|
60
61
|
* Withdraw USDC from the Privacy Cash.
|
|
61
62
|
*
|
|
62
63
|
* base_units is the amount of USDC in base unit. e.g. if you want to withdraw 1 USDC (1,000,000 base unit), call withdraw({ base_units: 1000000, recipientAddress: 'some_address' })
|
|
63
64
|
*/
|
|
64
|
-
withdrawUSDC({ base_units, recipientAddress,
|
|
65
|
+
withdrawUSDC({ base_units, recipientAddress, referralId }: {
|
|
65
66
|
base_units: number;
|
|
66
67
|
recipientAddress?: string;
|
|
67
|
-
|
|
68
|
+
referralId?: string;
|
|
68
69
|
}): Promise<{
|
|
69
70
|
isPartial: boolean;
|
|
70
71
|
tx: string;
|
|
71
72
|
recipient: string;
|
|
72
73
|
base_units: number;
|
|
73
74
|
fee_base_units: number;
|
|
75
|
+
referralRecorded: boolean | undefined;
|
|
74
76
|
}>;
|
|
75
77
|
/**
|
|
76
78
|
* Returns the amount of lamports current wallet has in Privacy Cash.
|
|
@@ -112,17 +114,18 @@ export declare class PrivacyCash {
|
|
|
112
114
|
/**
|
|
113
115
|
* Withdraw SPL from the Privacy Cash.
|
|
114
116
|
*/
|
|
115
|
-
withdrawSPL({ base_units, mintAddress, recipientAddress, amount,
|
|
117
|
+
withdrawSPL({ base_units, mintAddress, recipientAddress, amount, referralId }: {
|
|
116
118
|
base_units?: number;
|
|
117
119
|
amount?: number;
|
|
118
120
|
mintAddress: PublicKey | string;
|
|
119
121
|
recipientAddress?: string;
|
|
120
|
-
|
|
122
|
+
referralId?: string;
|
|
121
123
|
}): Promise<{
|
|
122
124
|
isPartial: boolean;
|
|
123
125
|
tx: string;
|
|
124
126
|
recipient: string;
|
|
125
127
|
base_units: number;
|
|
126
128
|
fee_base_units: number;
|
|
129
|
+
referralRecorded: boolean | undefined;
|
|
127
130
|
}>;
|
|
128
131
|
}
|
package/dist/index.js
CHANGED
|
@@ -123,7 +123,7 @@ export class PrivacyCash {
|
|
|
123
123
|
*
|
|
124
124
|
* Lamports is the amount of SOL in lamports. e.g. if you want to withdraw 0.01 SOL (10000000 lamports), call withdraw({ lamports: 10000000 })
|
|
125
125
|
*/
|
|
126
|
-
async withdraw({ lamports, recipientAddress,
|
|
126
|
+
async withdraw({ lamports, recipientAddress, referralId }) {
|
|
127
127
|
this.isRuning = true;
|
|
128
128
|
logger.info('start withdrawing');
|
|
129
129
|
let lightWasm = await WasmFactory.getInstance();
|
|
@@ -137,7 +137,7 @@ export class PrivacyCash {
|
|
|
137
137
|
recipient,
|
|
138
138
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
139
139
|
storage,
|
|
140
|
-
|
|
140
|
+
referralId
|
|
141
141
|
});
|
|
142
142
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${res.amount_in_lamports / LAMPORTS_PER_SOL} SOL, with ${res.fee_in_lamports / LAMPORTS_PER_SOL} SOL relayers fees`);
|
|
143
143
|
this.isRuning = false;
|
|
@@ -148,7 +148,7 @@ export class PrivacyCash {
|
|
|
148
148
|
*
|
|
149
149
|
* base_units is the amount of USDC in base unit. e.g. if you want to withdraw 1 USDC (1,000,000 base unit), call withdraw({ base_units: 1000000, recipientAddress: 'some_address' })
|
|
150
150
|
*/
|
|
151
|
-
async withdrawUSDC({ base_units, recipientAddress,
|
|
151
|
+
async withdrawUSDC({ base_units, recipientAddress, referralId }) {
|
|
152
152
|
this.isRuning = true;
|
|
153
153
|
logger.info('start withdrawing');
|
|
154
154
|
let lightWasm = await WasmFactory.getInstance();
|
|
@@ -163,7 +163,7 @@ export class PrivacyCash {
|
|
|
163
163
|
recipient,
|
|
164
164
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
165
165
|
storage,
|
|
166
|
-
|
|
166
|
+
referralId
|
|
167
167
|
});
|
|
168
168
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${base_units} USDC units`);
|
|
169
169
|
this.isRuning = false;
|
|
@@ -250,7 +250,7 @@ export class PrivacyCash {
|
|
|
250
250
|
/**
|
|
251
251
|
* Withdraw SPL from the Privacy Cash.
|
|
252
252
|
*/
|
|
253
|
-
async withdrawSPL({ base_units, mintAddress, recipientAddress, amount,
|
|
253
|
+
async withdrawSPL({ base_units, mintAddress, recipientAddress, amount, referralId }) {
|
|
254
254
|
this.isRuning = true;
|
|
255
255
|
logger.info('start withdrawing');
|
|
256
256
|
let lightWasm = await WasmFactory.getInstance();
|
|
@@ -266,7 +266,7 @@ export class PrivacyCash {
|
|
|
266
266
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
267
267
|
storage,
|
|
268
268
|
mintAddress,
|
|
269
|
-
|
|
269
|
+
referralId
|
|
270
270
|
});
|
|
271
271
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${base_units} USDC units`);
|
|
272
272
|
this.isRuning = false;
|
package/dist/withdraw.d.ts
CHANGED
|
@@ -10,13 +10,14 @@ type WithdrawParams = {
|
|
|
10
10
|
lightWasm: hasher.LightWasm;
|
|
11
11
|
recipient: PublicKey;
|
|
12
12
|
storage: Storage;
|
|
13
|
-
|
|
13
|
+
referralId?: string;
|
|
14
14
|
};
|
|
15
|
-
export declare function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath,
|
|
15
|
+
export declare function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath, referralId }: WithdrawParams): Promise<{
|
|
16
16
|
isPartial: boolean;
|
|
17
17
|
tx: string;
|
|
18
18
|
recipient: string;
|
|
19
19
|
amount_in_lamports: number;
|
|
20
20
|
fee_in_lamports: number;
|
|
21
|
+
referralRecorded: boolean | undefined;
|
|
21
22
|
}>;
|
|
22
23
|
export {};
|
package/dist/withdraw.js
CHANGED
|
@@ -28,14 +28,14 @@ async function submitWithdrawToIndexer(params) {
|
|
|
28
28
|
const result = await response.json();
|
|
29
29
|
logger.debug('Withdraw request submitted successfully!');
|
|
30
30
|
logger.debug('Response:', result);
|
|
31
|
-
return result
|
|
31
|
+
return result;
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
34
|
logger.debug('Failed to submit withdraw request to indexer:', typeof error, error);
|
|
35
35
|
throw error;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
export async function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath,
|
|
38
|
+
export async function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath, referralId }) {
|
|
39
39
|
let fee_in_lamports = Math.floor(amount_in_lamports * (await getConfig('withdraw_fee_rate')) + LAMPORTS_PER_SOL * (await getConfig('withdraw_rent_fee')));
|
|
40
40
|
amount_in_lamports = Math.floor(amount_in_lamports - fee_in_lamports);
|
|
41
41
|
let isPartial = false;
|
|
@@ -241,12 +241,12 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
241
241
|
encryptedOutput2: encryptedOutput2.toString('base64'),
|
|
242
242
|
fee: fee_in_lamports,
|
|
243
243
|
lookupTableAddress: ALT_ADDRESS.toString(),
|
|
244
|
-
|
|
244
|
+
referralId
|
|
245
245
|
};
|
|
246
246
|
logger.debug('Prepared withdraw parameters for indexer backend');
|
|
247
247
|
// Submit to indexer backend instead of directly to Solana
|
|
248
248
|
logger.info('submitting transaction to relayer...');
|
|
249
|
-
const signature = await submitWithdrawToIndexer(withdrawParams);
|
|
249
|
+
const { signature, referralRecorded } = await submitWithdrawToIndexer(withdrawParams);
|
|
250
250
|
// Wait a moment for the transaction to be confirmed
|
|
251
251
|
logger.info('waiting for transaction confirmation...');
|
|
252
252
|
let retryTimes = 0;
|
|
@@ -262,7 +262,7 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
262
262
|
let resJson = await res.json();
|
|
263
263
|
logger.debug('resJson:', resJson);
|
|
264
264
|
if (resJson.exists) {
|
|
265
|
-
return { isPartial, tx: signature, recipient: recipient.toString(), amount_in_lamports, fee_in_lamports };
|
|
265
|
+
return { isPartial, tx: signature, recipient: recipient.toString(), amount_in_lamports, fee_in_lamports, referralRecorded };
|
|
266
266
|
}
|
|
267
267
|
if (retryTimes >= 10) {
|
|
268
268
|
throw new Error('Refresh the page to see latest balance.');
|
package/dist/withdrawSPL.d.ts
CHANGED
|
@@ -12,13 +12,14 @@ type WithdrawParams = {
|
|
|
12
12
|
recipient: PublicKey;
|
|
13
13
|
mintAddress: PublicKey | string;
|
|
14
14
|
storage: Storage;
|
|
15
|
-
|
|
15
|
+
referralId?: string;
|
|
16
16
|
};
|
|
17
|
-
export declare function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress,
|
|
17
|
+
export declare function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress, referralId }: WithdrawParams): Promise<{
|
|
18
18
|
isPartial: boolean;
|
|
19
19
|
tx: string;
|
|
20
20
|
recipient: string;
|
|
21
21
|
base_units: number;
|
|
22
22
|
fee_base_units: number;
|
|
23
|
+
referralRecorded: boolean | undefined;
|
|
23
24
|
}>;
|
|
24
25
|
export {};
|
package/dist/withdrawSPL.js
CHANGED
|
@@ -29,14 +29,14 @@ async function submitWithdrawToIndexer(params) {
|
|
|
29
29
|
const result = await response.json();
|
|
30
30
|
logger.debug('Withdraw request submitted successfully!');
|
|
31
31
|
logger.debug('Response:', result);
|
|
32
|
-
return result
|
|
32
|
+
return result;
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
logger.debug('Failed to submit withdraw request to indexer:', typeof error, error);
|
|
36
36
|
throw error;
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress,
|
|
39
|
+
export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress, referralId }) {
|
|
40
40
|
if (typeof mintAddress == 'string') {
|
|
41
41
|
mintAddress = new PublicKey(mintAddress);
|
|
42
42
|
}
|
|
@@ -265,12 +265,12 @@ export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, co
|
|
|
265
265
|
recipientAta: recipient_ata.toString(),
|
|
266
266
|
mintAddress: token.pubkey.toString(),
|
|
267
267
|
feeRecipientTokenAccount: feeRecipientTokenAccount.toString(),
|
|
268
|
-
|
|
268
|
+
referralId
|
|
269
269
|
};
|
|
270
270
|
logger.debug('Prepared withdraw parameters for indexer backend');
|
|
271
271
|
// Submit to indexer backend instead of directly to Solana
|
|
272
272
|
logger.info('submitting transaction to relayer...');
|
|
273
|
-
const signature = await submitWithdrawToIndexer(withdrawParams);
|
|
273
|
+
const { signature, referralRecorded } = await submitWithdrawToIndexer(withdrawParams);
|
|
274
274
|
// Wait a moment for the transaction to be confirmed
|
|
275
275
|
logger.info('waiting for transaction confirmation...');
|
|
276
276
|
let retryTimes = 0;
|
|
@@ -286,7 +286,7 @@ export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, co
|
|
|
286
286
|
let resJson = await res.json();
|
|
287
287
|
logger.debug('resJson:', resJson);
|
|
288
288
|
if (resJson.exists) {
|
|
289
|
-
return { isPartial, tx: signature, recipient: recipient.toString(), base_units, fee_base_units };
|
|
289
|
+
return { isPartial, tx: signature, recipient: recipient.toString(), base_units, fee_base_units, referralRecorded };
|
|
290
290
|
}
|
|
291
291
|
if (retryTimes >= 10) {
|
|
292
292
|
throw new Error('Refresh the page to see latest balance.');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "privacycash",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": "https://github.com/Privacy-Cash/privacy-cash-sdk",
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
"typescript": "^5.9.2",
|
|
49
49
|
"vitest": "^3.2.4"
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -141,10 +141,10 @@ export class PrivacyCash {
|
|
|
141
141
|
*
|
|
142
142
|
* Lamports is the amount of SOL in lamports. e.g. if you want to withdraw 0.01 SOL (10000000 lamports), call withdraw({ lamports: 10000000 })
|
|
143
143
|
*/
|
|
144
|
-
async withdraw({ lamports, recipientAddress,
|
|
144
|
+
async withdraw({ lamports, recipientAddress, referralId }: {
|
|
145
145
|
lamports: number,
|
|
146
146
|
recipientAddress?: string,
|
|
147
|
-
|
|
147
|
+
referralId?: string
|
|
148
148
|
}) {
|
|
149
149
|
this.isRuning = true
|
|
150
150
|
logger.info('start withdrawing')
|
|
@@ -159,7 +159,7 @@ export class PrivacyCash {
|
|
|
159
159
|
recipient,
|
|
160
160
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
161
161
|
storage,
|
|
162
|
-
|
|
162
|
+
referralId
|
|
163
163
|
})
|
|
164
164
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${res.amount_in_lamports / LAMPORTS_PER_SOL} SOL, with ${res.fee_in_lamports / LAMPORTS_PER_SOL} SOL relayers fees`)
|
|
165
165
|
this.isRuning = false
|
|
@@ -171,10 +171,10 @@ export class PrivacyCash {
|
|
|
171
171
|
*
|
|
172
172
|
* base_units is the amount of USDC in base unit. e.g. if you want to withdraw 1 USDC (1,000,000 base unit), call withdraw({ base_units: 1000000, recipientAddress: 'some_address' })
|
|
173
173
|
*/
|
|
174
|
-
async withdrawUSDC({ base_units, recipientAddress,
|
|
174
|
+
async withdrawUSDC({ base_units, recipientAddress, referralId }: {
|
|
175
175
|
base_units: number,
|
|
176
176
|
recipientAddress?: string,
|
|
177
|
-
|
|
177
|
+
referralId?: string
|
|
178
178
|
}) {
|
|
179
179
|
this.isRuning = true
|
|
180
180
|
logger.info('start withdrawing')
|
|
@@ -190,7 +190,7 @@ export class PrivacyCash {
|
|
|
190
190
|
recipient,
|
|
191
191
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
192
192
|
storage,
|
|
193
|
-
|
|
193
|
+
referralId
|
|
194
194
|
})
|
|
195
195
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${base_units} USDC units`)
|
|
196
196
|
this.isRuning = false
|
|
@@ -288,12 +288,12 @@ export class PrivacyCash {
|
|
|
288
288
|
/**
|
|
289
289
|
* Withdraw SPL from the Privacy Cash.
|
|
290
290
|
*/
|
|
291
|
-
async withdrawSPL({ base_units, mintAddress, recipientAddress, amount,
|
|
291
|
+
async withdrawSPL({ base_units, mintAddress, recipientAddress, amount, referralId }: {
|
|
292
292
|
base_units?: number,
|
|
293
293
|
amount?: number,
|
|
294
294
|
mintAddress: PublicKey | string,
|
|
295
295
|
recipientAddress?: string,
|
|
296
|
-
|
|
296
|
+
referralId?: string
|
|
297
297
|
}) {
|
|
298
298
|
this.isRuning = true
|
|
299
299
|
logger.info('start withdrawing')
|
|
@@ -311,7 +311,7 @@ export class PrivacyCash {
|
|
|
311
311
|
keyBasePath: path.join(import.meta.dirname, '..', 'circuit2', 'transaction2'),
|
|
312
312
|
storage,
|
|
313
313
|
mintAddress,
|
|
314
|
-
|
|
314
|
+
referralId
|
|
315
315
|
})
|
|
316
316
|
logger.debug(`Withdraw successful. Recipient ${recipient} received ${base_units} USDC units`)
|
|
317
317
|
this.isRuning = false
|
|
@@ -353,4 +353,4 @@ function stdWrite(status: string, frame: string) {
|
|
|
353
353
|
let blue = "\x1b[34m";
|
|
354
354
|
let reset = "\x1b[0m";
|
|
355
355
|
process.stdout.write(`${frame}status: ${blue}${status}${reset}\r`);
|
|
356
|
-
}
|
|
356
|
+
}
|
package/src/withdraw.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { logger } from './utils/logger.js';
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
// Function to submit withdraw request to indexer backend
|
|
20
|
-
async function submitWithdrawToIndexer(params: any): Promise<string> {
|
|
20
|
+
async function submitWithdrawToIndexer(params: any): Promise<{ signature: string, referralRecorded?: boolean }> {
|
|
21
21
|
try {
|
|
22
22
|
|
|
23
23
|
const response = await fetch(`${RELAYER_API_URL}/withdraw`, {
|
|
@@ -33,11 +33,11 @@ async function submitWithdrawToIndexer(params: any): Promise<string> {
|
|
|
33
33
|
throw new Error(errorData.error)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const result = await response.json() as { signature: string, success: boolean };
|
|
36
|
+
const result = await response.json() as { signature: string, success: boolean, referralRecorded?: boolean };
|
|
37
37
|
logger.debug('Withdraw request submitted successfully!');
|
|
38
38
|
logger.debug('Response:', result);
|
|
39
39
|
|
|
40
|
-
return result
|
|
40
|
+
return result;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
logger.debug('Failed to submit withdraw request to indexer:', typeof error, error);
|
|
43
43
|
throw error;
|
|
@@ -53,10 +53,10 @@ type WithdrawParams = {
|
|
|
53
53
|
lightWasm: hasher.LightWasm,
|
|
54
54
|
recipient: PublicKey,
|
|
55
55
|
storage: Storage,
|
|
56
|
-
|
|
56
|
+
referralId?: string,
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export async function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath,
|
|
59
|
+
export async function withdraw({ recipient, lightWasm, storage, publicKey, connection, amount_in_lamports, encryptionService, keyBasePath, referralId }: WithdrawParams) {
|
|
60
60
|
let fee_in_lamports = Math.floor(amount_in_lamports * (await getConfig('withdraw_fee_rate')) + LAMPORTS_PER_SOL * (await getConfig('withdraw_rent_fee')))
|
|
61
61
|
amount_in_lamports = Math.floor(amount_in_lamports - fee_in_lamports)
|
|
62
62
|
let isPartial = false
|
|
@@ -297,7 +297,7 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
297
297
|
encryptedOutput2: encryptedOutput2.toString('base64'),
|
|
298
298
|
fee: fee_in_lamports,
|
|
299
299
|
lookupTableAddress: ALT_ADDRESS.toString(),
|
|
300
|
-
|
|
300
|
+
referralId
|
|
301
301
|
};
|
|
302
302
|
|
|
303
303
|
|
|
@@ -305,7 +305,7 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
305
305
|
|
|
306
306
|
// Submit to indexer backend instead of directly to Solana
|
|
307
307
|
logger.info('submitting transaction to relayer...')
|
|
308
|
-
const signature = await submitWithdrawToIndexer(withdrawParams);
|
|
308
|
+
const { signature, referralRecorded } = await submitWithdrawToIndexer(withdrawParams);
|
|
309
309
|
// Wait a moment for the transaction to be confirmed
|
|
310
310
|
logger.info('waiting for transaction confirmation...')
|
|
311
311
|
let retryTimes = 0
|
|
@@ -321,7 +321,7 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
321
321
|
let resJson = await res.json()
|
|
322
322
|
logger.debug('resJson:', resJson)
|
|
323
323
|
if (resJson.exists) {
|
|
324
|
-
return { isPartial, tx: signature, recipient: recipient.toString(), amount_in_lamports, fee_in_lamports }
|
|
324
|
+
return { isPartial, tx: signature, recipient: recipient.toString(), amount_in_lamports, fee_in_lamports, referralRecorded }
|
|
325
325
|
}
|
|
326
326
|
if (retryTimes >= 10) {
|
|
327
327
|
throw new Error('Refresh the page to see latest balance.')
|
|
@@ -329,4 +329,4 @@ export async function withdraw({ recipient, lightWasm, storage, publicKey, conne
|
|
|
329
329
|
retryTimes++
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
-
}
|
|
332
|
+
}
|
package/src/withdrawSPL.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { logger } from './utils/logger.js';
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
// Function to submit withdraw request to indexer backend
|
|
21
|
-
async function submitWithdrawToIndexer(params: any): Promise<string> {
|
|
21
|
+
async function submitWithdrawToIndexer(params: any): Promise<{ signature: string, referralRecorded?: boolean }> {
|
|
22
22
|
try {
|
|
23
23
|
const response = await fetch(`${RELAYER_API_URL}/withdraw/spl`, {
|
|
24
24
|
method: 'POST',
|
|
@@ -33,11 +33,11 @@ async function submitWithdrawToIndexer(params: any): Promise<string> {
|
|
|
33
33
|
throw new Error(errorData.error)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
const result = await response.json() as { signature: string, success: boolean };
|
|
36
|
+
const result = await response.json() as { signature: string, success: boolean, referralRecorded?: boolean };
|
|
37
37
|
logger.debug('Withdraw request submitted successfully!');
|
|
38
38
|
logger.debug('Response:', result);
|
|
39
39
|
|
|
40
|
-
return result
|
|
40
|
+
return result;
|
|
41
41
|
} catch (error) {
|
|
42
42
|
logger.debug('Failed to submit withdraw request to indexer:', typeof error, error);
|
|
43
43
|
throw error;
|
|
@@ -55,10 +55,10 @@ type WithdrawParams = {
|
|
|
55
55
|
recipient: PublicKey,
|
|
56
56
|
mintAddress: PublicKey | string,
|
|
57
57
|
storage: Storage,
|
|
58
|
-
|
|
58
|
+
referralId?: string,
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress,
|
|
61
|
+
export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, connection, base_units, amount, encryptionService, keyBasePath, mintAddress, referralId }: WithdrawParams) {
|
|
62
62
|
if (typeof mintAddress == 'string') {
|
|
63
63
|
mintAddress = new PublicKey(mintAddress)
|
|
64
64
|
}
|
|
@@ -350,14 +350,14 @@ export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, co
|
|
|
350
350
|
recipientAta: recipient_ata.toString(),
|
|
351
351
|
mintAddress: token.pubkey.toString(),
|
|
352
352
|
feeRecipientTokenAccount: feeRecipientTokenAccount.toString(),
|
|
353
|
-
|
|
353
|
+
referralId
|
|
354
354
|
};
|
|
355
355
|
|
|
356
356
|
logger.debug('Prepared withdraw parameters for indexer backend');
|
|
357
357
|
|
|
358
358
|
// Submit to indexer backend instead of directly to Solana
|
|
359
359
|
logger.info('submitting transaction to relayer...')
|
|
360
|
-
const signature = await submitWithdrawToIndexer(withdrawParams);
|
|
360
|
+
const { signature, referralRecorded } = await submitWithdrawToIndexer(withdrawParams);
|
|
361
361
|
// Wait a moment for the transaction to be confirmed
|
|
362
362
|
logger.info('waiting for transaction confirmation...')
|
|
363
363
|
let retryTimes = 0
|
|
@@ -373,7 +373,7 @@ export async function withdrawSPL({ recipient, lightWasm, storage, publicKey, co
|
|
|
373
373
|
let resJson = await res.json()
|
|
374
374
|
logger.debug('resJson:', resJson)
|
|
375
375
|
if (resJson.exists) {
|
|
376
|
-
return { isPartial, tx: signature, recipient: recipient.toString(), base_units, fee_base_units }
|
|
376
|
+
return { isPartial, tx: signature, recipient: recipient.toString(), base_units, fee_base_units, referralRecorded }
|
|
377
377
|
}
|
|
378
378
|
if (retryTimes >= 10) {
|
|
379
379
|
throw new Error('Refresh the page to see latest balance.')
|