@sudobility/contracts 1.13.0 → 1.13.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/dist/evm/src/evm/evm-mailer-client.js +3 -3
- package/dist/evm/src/evm/evm-mailer-client.js.map +1 -1
- package/dist/evm/src/evm/index.d.ts +3 -3
- package/dist/evm/src/evm/index.d.ts.map +1 -1
- package/dist/evm/src/evm/index.js +4 -4
- package/dist/evm/src/evm/index.js.map +1 -1
- package/dist/solana/solana/index.d.ts +2 -2
- package/dist/solana/solana/index.d.ts.map +1 -1
- package/dist/solana/solana/index.js +3 -3
- package/dist/solana/solana/index.js.map +1 -1
- package/dist/solana/solana/solana-mailer-client.d.ts +1 -1
- package/dist/solana/solana/solana-mailer-client.d.ts.map +1 -1
- package/dist/solana/solana/solana-mailer-client.js +1 -1
- package/dist/solana/solana/solana-mailer-client.js.map +1 -1
- package/dist/solana/solana/types.d.ts +1 -1
- package/dist/solana/solana/types.d.ts.map +1 -1
- package/dist/solana/solana/types.js +5 -5
- package/dist/solana/solana/types.js.map +1 -1
- package/dist/unified/src/evm/evm-mailer-client.js +7 -11
- package/dist/unified/src/evm/evm-mailer-client.js.map +1 -1
- package/dist/unified/src/evm/index.d.ts +3 -3
- package/dist/unified/src/evm/index.d.ts.map +1 -1
- package/dist/unified/src/evm/index.js +2 -7
- package/dist/unified/src/evm/index.js.map +1 -1
- package/dist/unified/src/react/context/MailerProvider.js +14 -55
- package/dist/unified/src/react/context/MailerProvider.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerMutations.js +76 -98
- package/dist/unified/src/react/hooks/useMailerMutations.js.map +1 -1
- package/dist/unified/src/react/hooks/useMailerQueries.js +52 -68
- package/dist/unified/src/react/hooks/useMailerQueries.js.map +1 -1
- package/dist/unified/src/react/index.js +5 -47
- package/dist/unified/src/react/index.js.map +1 -1
- package/dist/unified/src/solana/index.d.ts +2 -2
- package/dist/unified/src/solana/index.d.ts.map +1 -1
- package/dist/unified/src/solana/index.js +2 -20
- package/dist/unified/src/solana/index.js.map +1 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts +1 -1
- package/dist/unified/src/solana/solana-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/solana/solana-mailer-client.js +129 -133
- package/dist/unified/src/solana/solana-mailer-client.js.map +1 -1
- package/dist/unified/src/solana/types.d.ts +1 -1
- package/dist/unified/src/solana/types.d.ts.map +1 -1
- package/dist/unified/src/solana/types.js +6 -13
- package/dist/unified/src/solana/types.js.map +1 -1
- package/dist/unified/src/unified/index.d.ts +3 -3
- package/dist/unified/src/unified/index.d.ts.map +1 -1
- package/dist/unified/src/unified/index.js +2 -7
- package/dist/unified/src/unified/index.js.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.d.ts +3 -3
- package/dist/unified/src/unified/onchain-mailer-client.d.ts.map +1 -1
- package/dist/unified/src/unified/onchain-mailer-client.js +88 -125
- package/dist/unified/src/unified/onchain-mailer-client.js.map +1 -1
- package/dist/unified/src/unified/types.js +1 -2
- package/dist/unified/src/unified/wallet-detector.js +10 -14
- package/dist/unified/src/unified/wallet-detector.js.map +1 -1
- package/dist/unified/src/utils/chain-config.d.ts +1 -1
- package/dist/unified/src/utils/chain-config.d.ts.map +1 -1
- package/dist/unified/src/utils/chain-config.js +9 -13
- package/dist/unified/src/utils/chain-config.js.map +1 -1
- package/dist/unified/src/utils/currency.js +6 -11
- package/dist/unified/src/utils/currency.js.map +1 -1
- package/dist/unified/src/utils/index.d.ts +3 -3
- package/dist/unified/src/utils/index.d.ts.map +1 -1
- package/dist/unified/src/utils/index.js +3 -19
- package/dist/unified/src/utils/index.js.map +1 -1
- package/dist/unified/src/utils/validation.js +11 -17
- package/dist/unified/src/utils/validation.js.map +1 -1
- package/dist/unified/typechain-types/Mailer.js +1 -2
- package/dist/unified/typechain-types/MockUSDC.js +1 -2
- package/dist/unified/typechain-types/common.js +1 -2
- package/dist/unified/typechain-types/factories/Mailer__factory.js +4 -8
- package/dist/unified/typechain-types/factories/Mailer__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/MockUSDC__factory.js +4 -8
- package/dist/unified/typechain-types/factories/MockUSDC__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/index.js +3 -41
- package/dist/unified/typechain-types/factories/index.js.map +1 -1
- package/dist/unified/typechain-types/factories/interfaces/IERC20__factory.js +4 -8
- package/dist/unified/typechain-types/factories/interfaces/IERC20__factory.js.map +1 -1
- package/dist/unified/typechain-types/factories/interfaces/index.js +1 -5
- package/dist/unified/typechain-types/factories/interfaces/index.js.map +1 -1
- package/dist/unified/typechain-types/index.js +4 -43
- package/dist/unified/typechain-types/index.js.map +1 -1
- package/dist/unified/typechain-types/interfaces/IERC20.js +1 -2
- package/dist/unified/typechain-types/interfaces/index.js +1 -2
- package/package.json +12 -18
- package/dist/unified/package.json +0 -3
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts +0 -1062
- package/dist/unified-esm/src/evm/evm-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/evm-mailer-client.js +0 -920
- package/dist/unified-esm/src/evm/evm-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/evm/index.d.ts +0 -4
- package/dist/unified-esm/src/evm/index.d.ts.map +0 -1
- package/dist/unified-esm/src/evm/index.js +0 -5
- package/dist/unified-esm/src/evm/index.js.map +0 -1
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts +0 -108
- package/dist/unified-esm/src/react/context/MailerProvider.d.ts.map +0 -1
- package/dist/unified-esm/src/react/context/MailerProvider.js +0 -119
- package/dist/unified-esm/src/react/context/MailerProvider.js.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts +0 -334
- package/dist/unified-esm/src/react/hooks/useMailerMutations.d.ts.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js +0 -392
- package/dist/unified-esm/src/react/hooks/useMailerMutations.js.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts +0 -184
- package/dist/unified-esm/src/react/hooks/useMailerQueries.d.ts.map +0 -1
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js +0 -316
- package/dist/unified-esm/src/react/hooks/useMailerQueries.js.map +0 -1
- package/dist/unified-esm/src/react/index.d.ts +0 -39
- package/dist/unified-esm/src/react/index.d.ts.map +0 -1
- package/dist/unified-esm/src/react/index.js +0 -43
- package/dist/unified-esm/src/react/index.js.map +0 -1
- package/dist/unified-esm/src/solana/index.d.ts +0 -3
- package/dist/unified-esm/src/solana/index.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/index.js +0 -4
- package/dist/unified-esm/src/solana/index.js.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts +0 -209
- package/dist/unified-esm/src/solana/solana-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/solana-mailer-client.js +0 -1000
- package/dist/unified-esm/src/solana/solana-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/solana/types.d.ts +0 -29
- package/dist/unified-esm/src/solana/types.d.ts.map +0 -1
- package/dist/unified-esm/src/solana/types.js +0 -16
- package/dist/unified-esm/src/solana/types.js.map +0 -1
- package/dist/unified-esm/src/unified/index.d.ts +0 -4
- package/dist/unified-esm/src/unified/index.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/index.js +0 -4
- package/dist/unified-esm/src/unified/index.js.map +0 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts +0 -258
- package/dist/unified-esm/src/unified/onchain-mailer-client.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/onchain-mailer-client.js +0 -731
- package/dist/unified-esm/src/unified/onchain-mailer-client.js.map +0 -1
- package/dist/unified-esm/src/unified/types.d.ts +0 -54
- package/dist/unified-esm/src/unified/types.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/types.js +0 -2
- package/dist/unified-esm/src/unified/types.js.map +0 -1
- package/dist/unified-esm/src/unified/wallet-detector.d.ts +0 -28
- package/dist/unified-esm/src/unified/wallet-detector.d.ts.map +0 -1
- package/dist/unified-esm/src/unified/wallet-detector.js +0 -59
- package/dist/unified-esm/src/unified/wallet-detector.js.map +0 -1
- package/dist/unified-esm/src/utils/chain-config.d.ts +0 -75
- package/dist/unified-esm/src/utils/chain-config.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/chain-config.js +0 -199
- package/dist/unified-esm/src/utils/chain-config.js.map +0 -1
- package/dist/unified-esm/src/utils/currency.d.ts +0 -26
- package/dist/unified-esm/src/utils/currency.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/currency.js +0 -31
- package/dist/unified-esm/src/utils/currency.js.map +0 -1
- package/dist/unified-esm/src/utils/index.d.ts +0 -4
- package/dist/unified-esm/src/utils/index.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/index.js +0 -4
- package/dist/unified-esm/src/utils/index.js.map +0 -1
- package/dist/unified-esm/src/utils/validation.d.ts +0 -10
- package/dist/unified-esm/src/utils/validation.d.ts.map +0 -1
- package/dist/unified-esm/src/utils/validation.js +0 -96
- package/dist/unified-esm/src/utils/validation.js.map +0 -1
- package/dist/unified-esm/typechain-types/Mailer.d.ts +0 -698
- package/dist/unified-esm/typechain-types/Mailer.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/Mailer.js +0 -2
- package/dist/unified-esm/typechain-types/Mailer.js.map +0 -1
- package/dist/unified-esm/typechain-types/MockUSDC.d.ts +0 -118
- package/dist/unified-esm/typechain-types/MockUSDC.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/MockUSDC.js +0 -2
- package/dist/unified-esm/typechain-types/MockUSDC.js.map +0 -1
- package/dist/unified-esm/typechain-types/common.d.ts +0 -51
- package/dist/unified-esm/typechain-types/common.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/common.js +0 -2
- package/dist/unified-esm/typechain-types/common.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts +0 -875
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js +0 -1121
- package/dist/unified-esm/typechain-types/factories/Mailer__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.d.ts +0 -193
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.js +0 -259
- package/dist/unified-esm/typechain-types/factories/MockUSDC__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/index.d.ts +0 -4
- package/dist/unified-esm/typechain-types/factories/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/index.js +0 -7
- package/dist/unified-esm/typechain-types/factories/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.d.ts +0 -80
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.js +0 -112
- package/dist/unified-esm/typechain-types/factories/interfaces/IERC20__factory.js.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/index.d.ts +0 -2
- package/dist/unified-esm/typechain-types/factories/interfaces/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/factories/interfaces/index.js +0 -5
- package/dist/unified-esm/typechain-types/factories/interfaces/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/index.d.ts +0 -10
- package/dist/unified-esm/typechain-types/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/index.js +0 -5
- package/dist/unified-esm/typechain-types/index.js.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/IERC20.d.ts +0 -70
- package/dist/unified-esm/typechain-types/interfaces/IERC20.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/IERC20.js +0 -2
- package/dist/unified-esm/typechain-types/interfaces/IERC20.js.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/index.d.ts +0 -2
- package/dist/unified-esm/typechain-types/interfaces/index.d.ts.map +0 -1
- package/dist/unified-esm/typechain-types/interfaces/index.js +0 -2
- package/dist/unified-esm/typechain-types/interfaces/index.js.map +0 -1
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SolanaMailerClient = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
1
|
+
import { Connection, PublicKey, Transaction, TransactionInstruction, SystemProgram, ComputeBudgetProgram, } from '@solana/web3.js';
|
|
2
|
+
import { TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, createAssociatedTokenAccountInstruction, } from '@solana/spl-token';
|
|
6
3
|
/**
|
|
7
4
|
* Native Solana Program instruction types
|
|
8
5
|
*/
|
|
@@ -206,7 +203,7 @@ function encodeDistributeClaimableFunds(recipients) {
|
|
|
206
203
|
* All methods take wallet and chainInfo as parameters.
|
|
207
204
|
* No state is stored in the instance.
|
|
208
205
|
*/
|
|
209
|
-
class SolanaMailerClient {
|
|
206
|
+
export class SolanaMailerClient {
|
|
210
207
|
constructor() {
|
|
211
208
|
this.defaultComputeUnitMultiplier = 1.2; // 20% buffer by default
|
|
212
209
|
// Default compute unit limits for common operations
|
|
@@ -248,11 +245,11 @@ class SolanaMailerClient {
|
|
|
248
245
|
}
|
|
249
246
|
else {
|
|
250
247
|
// Default Solana endpoints
|
|
251
|
-
rpcUrl = chainInfo.
|
|
248
|
+
rpcUrl = chainInfo.isTestNet
|
|
252
249
|
? 'https://api.devnet.solana.com'
|
|
253
250
|
: 'https://api.mainnet-beta.solana.com';
|
|
254
251
|
}
|
|
255
|
-
return new
|
|
252
|
+
return new Connection(rpcUrl, 'confirmed');
|
|
256
253
|
}
|
|
257
254
|
/**
|
|
258
255
|
* Get program and state PDAs from chainInfo
|
|
@@ -261,8 +258,8 @@ class SolanaMailerClient {
|
|
|
261
258
|
if (!chainInfo.mailerAddress) {
|
|
262
259
|
throw new Error(`No mailer program deployed on ${chainInfo.name}`);
|
|
263
260
|
}
|
|
264
|
-
const programId = new
|
|
265
|
-
const [mailerPda, bump] =
|
|
261
|
+
const programId = new PublicKey(chainInfo.mailerAddress);
|
|
262
|
+
const [mailerPda, bump] = PublicKey.findProgramAddressSync([Buffer.from('mailer')], programId);
|
|
266
263
|
return {
|
|
267
264
|
programId,
|
|
268
265
|
mailerStatePda: mailerPda,
|
|
@@ -286,8 +283,8 @@ class SolanaMailerClient {
|
|
|
286
283
|
while (retryCount <= maxRetries) {
|
|
287
284
|
try {
|
|
288
285
|
// Set a high limit for simulation
|
|
289
|
-
const simTransaction = new
|
|
290
|
-
simTransaction.add(
|
|
286
|
+
const simTransaction = new Transaction().add(...transaction.instructions);
|
|
287
|
+
simTransaction.add(ComputeBudgetProgram.setComputeUnitLimit({
|
|
291
288
|
units: 1400000, // Max for simulation
|
|
292
289
|
}));
|
|
293
290
|
simTransaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
|
|
@@ -324,10 +321,10 @@ class SolanaMailerClient {
|
|
|
324
321
|
computeUnitLimit = defaultComputeUnits;
|
|
325
322
|
}
|
|
326
323
|
// Apply compute budget instructions
|
|
327
|
-
const optimizedTx = new
|
|
324
|
+
const optimizedTx = new Transaction();
|
|
328
325
|
// Add compute unit limit if specified
|
|
329
326
|
if (computeUnitLimit) {
|
|
330
|
-
optimizedTx.add(
|
|
327
|
+
optimizedTx.add(ComputeBudgetProgram.setComputeUnitLimit({
|
|
331
328
|
units: computeUnitLimit,
|
|
332
329
|
}));
|
|
333
330
|
}
|
|
@@ -335,7 +332,7 @@ class SolanaMailerClient {
|
|
|
335
332
|
const priorityFee = options?.computeUnitPrice ??
|
|
336
333
|
(options?.autoOptimize ? this.priorityFeeRecommendations.normal : undefined);
|
|
337
334
|
if (priorityFee) {
|
|
338
|
-
optimizedTx.add(
|
|
335
|
+
optimizedTx.add(ComputeBudgetProgram.setComputeUnitPrice({
|
|
339
336
|
microLamports: priorityFee,
|
|
340
337
|
}));
|
|
341
338
|
}
|
|
@@ -381,17 +378,17 @@ class SolanaMailerClient {
|
|
|
381
378
|
if (!chainInfo.usdcAddress) {
|
|
382
379
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
383
380
|
}
|
|
384
|
-
const usdcMint = new
|
|
385
|
-
const instruction = new
|
|
381
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
382
|
+
const instruction = new TransactionInstruction({
|
|
386
383
|
programId,
|
|
387
384
|
keys: [
|
|
388
385
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
389
386
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
390
|
-
{ pubkey:
|
|
387
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
391
388
|
],
|
|
392
389
|
data: encodeInitialize(usdcMint),
|
|
393
390
|
});
|
|
394
|
-
const transaction = new
|
|
391
|
+
const transaction = new Transaction().add(instruction);
|
|
395
392
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
396
393
|
}
|
|
397
394
|
/**
|
|
@@ -403,12 +400,12 @@ class SolanaMailerClient {
|
|
|
403
400
|
if (!chainInfo.usdcAddress) {
|
|
404
401
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
405
402
|
}
|
|
406
|
-
const usdcMint = new
|
|
407
|
-
const toPubkey = typeof to === 'string' ? new
|
|
403
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
404
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
408
405
|
// Get token accounts
|
|
409
|
-
const senderTokenAccount =
|
|
410
|
-
const mailerTokenAccount =
|
|
411
|
-
const [recipientInfo] =
|
|
406
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
407
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
408
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), toPubkey.toBuffer()], programId);
|
|
412
409
|
const keys = [
|
|
413
410
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
414
411
|
{ pubkey: toPubkey, isSigner: false, isWritable: false },
|
|
@@ -416,19 +413,19 @@ class SolanaMailerClient {
|
|
|
416
413
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
417
414
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
418
415
|
{ pubkey: recipientInfo, isSigner: false, isWritable: true },
|
|
419
|
-
{ pubkey:
|
|
420
|
-
{ pubkey:
|
|
416
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
417
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
421
418
|
];
|
|
422
|
-
const instruction = new
|
|
419
|
+
const instruction = new TransactionInstruction({
|
|
423
420
|
programId,
|
|
424
421
|
keys,
|
|
425
422
|
data: encodeSend(toPubkey, subject, body, revenueShareToReceiver),
|
|
426
423
|
});
|
|
427
|
-
const transaction = new
|
|
424
|
+
const transaction = new Transaction().add(instruction);
|
|
428
425
|
// Check if mailer token account exists, create if not
|
|
429
426
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
430
427
|
if (!accountInfo) {
|
|
431
|
-
transaction.add(
|
|
428
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
432
429
|
}
|
|
433
430
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
434
431
|
}
|
|
@@ -441,11 +438,11 @@ class SolanaMailerClient {
|
|
|
441
438
|
if (!chainInfo.usdcAddress) {
|
|
442
439
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
443
440
|
}
|
|
444
|
-
const usdcMint = new
|
|
445
|
-
const toPubkey = typeof to === 'string' ? new
|
|
446
|
-
const senderTokenAccount =
|
|
447
|
-
const mailerTokenAccount =
|
|
448
|
-
const [recipientInfo] =
|
|
441
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
442
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
443
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
444
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
445
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), toPubkey.toBuffer()], programId);
|
|
449
446
|
const keys = [
|
|
450
447
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
451
448
|
{ pubkey: toPubkey, isSigner: false, isWritable: false },
|
|
@@ -453,19 +450,19 @@ class SolanaMailerClient {
|
|
|
453
450
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
454
451
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
455
452
|
{ pubkey: recipientInfo, isSigner: false, isWritable: true },
|
|
456
|
-
{ pubkey:
|
|
457
|
-
{ pubkey:
|
|
453
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
454
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
458
455
|
];
|
|
459
|
-
const instruction = new
|
|
456
|
+
const instruction = new TransactionInstruction({
|
|
460
457
|
programId,
|
|
461
458
|
keys,
|
|
462
459
|
data: encodeSendPrepared(toPubkey, mailId, revenueShareToReceiver),
|
|
463
460
|
});
|
|
464
|
-
const transaction = new
|
|
461
|
+
const transaction = new Transaction().add(instruction);
|
|
465
462
|
// Check if mailer token account exists, create if not
|
|
466
463
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
467
464
|
if (!accountInfo) {
|
|
468
|
-
transaction.add(
|
|
465
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
469
466
|
}
|
|
470
467
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
471
468
|
}
|
|
@@ -478,11 +475,11 @@ class SolanaMailerClient {
|
|
|
478
475
|
if (!chainInfo.usdcAddress) {
|
|
479
476
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
480
477
|
}
|
|
481
|
-
const usdcMint = new
|
|
482
|
-
const toPubkey = typeof to === 'string' ? new
|
|
483
|
-
const senderTokenAccount =
|
|
484
|
-
const mailerTokenAccount =
|
|
485
|
-
const [recipientInfo] =
|
|
478
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
479
|
+
const toPubkey = typeof to === 'string' ? new PublicKey(to) : to;
|
|
480
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
481
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
482
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), toPubkey.toBuffer()], programId);
|
|
486
483
|
const keys = [
|
|
487
484
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
488
485
|
{ pubkey: toPubkey, isSigner: false, isWritable: false },
|
|
@@ -490,18 +487,18 @@ class SolanaMailerClient {
|
|
|
490
487
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
491
488
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
492
489
|
{ pubkey: recipientInfo, isSigner: false, isWritable: true },
|
|
493
|
-
{ pubkey:
|
|
494
|
-
{ pubkey:
|
|
490
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
491
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
495
492
|
];
|
|
496
|
-
const instruction = new
|
|
493
|
+
const instruction = new TransactionInstruction({
|
|
497
494
|
programId,
|
|
498
495
|
keys,
|
|
499
496
|
data: encodeSendThroughWebhook(toPubkey, subject, body, webhookId, revenueShareToReceiver),
|
|
500
497
|
});
|
|
501
|
-
const transaction = new
|
|
498
|
+
const transaction = new Transaction().add(instruction);
|
|
502
499
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
503
500
|
if (!accountInfo) {
|
|
504
|
-
transaction.add(
|
|
501
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
505
502
|
}
|
|
506
503
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
507
504
|
}
|
|
@@ -514,27 +511,27 @@ class SolanaMailerClient {
|
|
|
514
511
|
if (!chainInfo.usdcAddress) {
|
|
515
512
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
516
513
|
}
|
|
517
|
-
const usdcMint = new
|
|
518
|
-
const payerPubkey = typeof payer === 'string' ? new
|
|
519
|
-
const senderTokenAccount =
|
|
520
|
-
const mailerTokenAccount =
|
|
514
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
515
|
+
const payerPubkey = typeof payer === 'string' ? new PublicKey(payer) : payer;
|
|
516
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
517
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
521
518
|
const keys = [
|
|
522
519
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
523
520
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
524
521
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
525
522
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
526
|
-
{ pubkey:
|
|
527
|
-
{ pubkey:
|
|
523
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
524
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
528
525
|
];
|
|
529
|
-
const instruction = new
|
|
526
|
+
const instruction = new TransactionInstruction({
|
|
530
527
|
programId,
|
|
531
528
|
keys,
|
|
532
529
|
data: encodeSendToEmail(emailHash, subject, body, payerPubkey, revenueShareToReceiver),
|
|
533
530
|
});
|
|
534
|
-
const transaction = new
|
|
531
|
+
const transaction = new Transaction().add(instruction);
|
|
535
532
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
536
533
|
if (!accountInfo) {
|
|
537
|
-
transaction.add(
|
|
534
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
538
535
|
}
|
|
539
536
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
540
537
|
}
|
|
@@ -547,27 +544,27 @@ class SolanaMailerClient {
|
|
|
547
544
|
if (!chainInfo.usdcAddress) {
|
|
548
545
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
549
546
|
}
|
|
550
|
-
const usdcMint = new
|
|
551
|
-
const payerPubkey = typeof payer === 'string' ? new
|
|
552
|
-
const senderTokenAccount =
|
|
553
|
-
const mailerTokenAccount =
|
|
547
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
548
|
+
const payerPubkey = typeof payer === 'string' ? new PublicKey(payer) : payer;
|
|
549
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
550
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
554
551
|
const keys = [
|
|
555
552
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
556
553
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
557
554
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
558
555
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
559
|
-
{ pubkey:
|
|
560
|
-
{ pubkey:
|
|
556
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
557
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
561
558
|
];
|
|
562
|
-
const instruction = new
|
|
559
|
+
const instruction = new TransactionInstruction({
|
|
563
560
|
programId,
|
|
564
561
|
keys,
|
|
565
562
|
data: encodeSendPreparedToEmail(emailHash, mailId, payerPubkey, revenueShareToReceiver),
|
|
566
563
|
});
|
|
567
|
-
const transaction = new
|
|
564
|
+
const transaction = new Transaction().add(instruction);
|
|
568
565
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
569
566
|
if (!accountInfo) {
|
|
570
|
-
transaction.add(
|
|
567
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
571
568
|
}
|
|
572
569
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
573
570
|
}
|
|
@@ -580,24 +577,24 @@ class SolanaMailerClient {
|
|
|
580
577
|
if (!chainInfo.usdcAddress) {
|
|
581
578
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
582
579
|
}
|
|
583
|
-
const usdcMint = new
|
|
584
|
-
const recipientTokenAccount =
|
|
585
|
-
const mailerTokenAccount =
|
|
586
|
-
const [recipientInfo] =
|
|
580
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
581
|
+
const recipientTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
582
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
583
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
587
584
|
const keys = [
|
|
588
585
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
589
586
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
590
587
|
{ pubkey: recipientTokenAccount, isSigner: false, isWritable: true },
|
|
591
588
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
592
589
|
{ pubkey: recipientInfo, isSigner: false, isWritable: true },
|
|
593
|
-
{ pubkey:
|
|
590
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
594
591
|
];
|
|
595
|
-
const instruction = new
|
|
592
|
+
const instruction = new TransactionInstruction({
|
|
596
593
|
programId,
|
|
597
594
|
keys,
|
|
598
595
|
data: Buffer.from([InstructionType.ClaimRecipientShare]),
|
|
599
596
|
});
|
|
600
|
-
const transaction = new
|
|
597
|
+
const transaction = new Transaction().add(instruction);
|
|
601
598
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
602
599
|
}
|
|
603
600
|
/**
|
|
@@ -609,22 +606,22 @@ class SolanaMailerClient {
|
|
|
609
606
|
if (!chainInfo.usdcAddress) {
|
|
610
607
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
611
608
|
}
|
|
612
|
-
const usdcMint = new
|
|
613
|
-
const ownerTokenAccount =
|
|
614
|
-
const mailerTokenAccount =
|
|
609
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
610
|
+
const ownerTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
611
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
615
612
|
const keys = [
|
|
616
613
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
617
614
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
618
615
|
{ pubkey: ownerTokenAccount, isSigner: false, isWritable: true },
|
|
619
616
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
620
|
-
{ pubkey:
|
|
617
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
621
618
|
];
|
|
622
|
-
const instruction = new
|
|
619
|
+
const instruction = new TransactionInstruction({
|
|
623
620
|
programId,
|
|
624
621
|
keys,
|
|
625
622
|
data: Buffer.from([InstructionType.ClaimOwnerShare]),
|
|
626
623
|
});
|
|
627
|
-
const transaction = new
|
|
624
|
+
const transaction = new Transaction().add(instruction);
|
|
628
625
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
629
626
|
}
|
|
630
627
|
/**
|
|
@@ -633,19 +630,19 @@ class SolanaMailerClient {
|
|
|
633
630
|
async claimExpiredShares(connectedWallet, chainInfo, recipient, computeOptions) {
|
|
634
631
|
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
635
632
|
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
636
|
-
const recipientPubkey = typeof recipient === 'string' ? new
|
|
637
|
-
const [recipientInfo] =
|
|
633
|
+
const recipientPubkey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
|
|
634
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), recipientPubkey.toBuffer()], programId);
|
|
638
635
|
const keys = [
|
|
639
636
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
640
637
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
641
638
|
{ pubkey: recipientInfo, isSigner: false, isWritable: true },
|
|
642
639
|
];
|
|
643
|
-
const instruction = new
|
|
640
|
+
const instruction = new TransactionInstruction({
|
|
644
641
|
programId,
|
|
645
642
|
keys,
|
|
646
643
|
data: encodeClaimExpiredShares(recipientPubkey),
|
|
647
644
|
});
|
|
648
|
-
const transaction = new
|
|
645
|
+
const transaction = new Transaction().add(instruction);
|
|
649
646
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
650
647
|
}
|
|
651
648
|
/**
|
|
@@ -657,31 +654,31 @@ class SolanaMailerClient {
|
|
|
657
654
|
if (!chainInfo.usdcAddress) {
|
|
658
655
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
659
656
|
}
|
|
660
|
-
const usdcMint = new
|
|
657
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
661
658
|
const delegatePubkey = delegate
|
|
662
|
-
? (typeof delegate === 'string' ? new
|
|
659
|
+
? (typeof delegate === 'string' ? new PublicKey(delegate) : delegate)
|
|
663
660
|
: null;
|
|
664
|
-
const senderTokenAccount =
|
|
665
|
-
const mailerTokenAccount =
|
|
666
|
-
const [delegatorInfo] =
|
|
661
|
+
const senderTokenAccount = getAssociatedTokenAddressSync(usdcMint, connectedWallet.wallet.publicKey, false, TOKEN_PROGRAM_ID);
|
|
662
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
663
|
+
const [delegatorInfo] = PublicKey.findProgramAddressSync([Buffer.from('delegator_info'), connectedWallet.wallet.publicKey.toBuffer()], programId);
|
|
667
664
|
const keys = [
|
|
668
665
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
669
666
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
670
667
|
{ pubkey: senderTokenAccount, isSigner: false, isWritable: true },
|
|
671
668
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
672
669
|
{ pubkey: delegatorInfo, isSigner: false, isWritable: true },
|
|
673
|
-
{ pubkey:
|
|
674
|
-
{ pubkey:
|
|
670
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
671
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
675
672
|
];
|
|
676
|
-
const instruction = new
|
|
673
|
+
const instruction = new TransactionInstruction({
|
|
677
674
|
programId,
|
|
678
675
|
keys,
|
|
679
676
|
data: encodeDelegateTo(delegatePubkey),
|
|
680
677
|
});
|
|
681
|
-
const transaction = new
|
|
678
|
+
const transaction = new Transaction().add(instruction);
|
|
682
679
|
const accountInfo = await connection.getAccountInfo(mailerTokenAccount);
|
|
683
680
|
if (!accountInfo) {
|
|
684
|
-
transaction.add(
|
|
681
|
+
transaction.add(createAssociatedTokenAccountInstruction(connectedWallet.wallet.publicKey, mailerTokenAccount, mailerStatePda, usdcMint));
|
|
685
682
|
}
|
|
686
683
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
687
684
|
}
|
|
@@ -691,18 +688,18 @@ class SolanaMailerClient {
|
|
|
691
688
|
async rejectDelegation(connectedWallet, chainInfo, delegatingAddress, computeOptions) {
|
|
692
689
|
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
693
690
|
const { programId } = this.getProgramAddresses(chainInfo);
|
|
694
|
-
const delegatorPubkey = typeof delegatingAddress === 'string' ? new
|
|
695
|
-
const [delegatorInfo] =
|
|
691
|
+
const delegatorPubkey = typeof delegatingAddress === 'string' ? new PublicKey(delegatingAddress) : delegatingAddress;
|
|
692
|
+
const [delegatorInfo] = PublicKey.findProgramAddressSync([Buffer.from('delegator_info'), delegatorPubkey.toBuffer()], programId);
|
|
696
693
|
const keys = [
|
|
697
694
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
698
695
|
{ pubkey: delegatorInfo, isSigner: false, isWritable: true },
|
|
699
696
|
];
|
|
700
|
-
const instruction = new
|
|
697
|
+
const instruction = new TransactionInstruction({
|
|
701
698
|
programId,
|
|
702
699
|
keys,
|
|
703
700
|
data: encodeRejectDelegation(delegatorPubkey),
|
|
704
701
|
});
|
|
705
|
-
const transaction = new
|
|
702
|
+
const transaction = new Transaction().add(instruction);
|
|
706
703
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
707
704
|
}
|
|
708
705
|
/**
|
|
@@ -715,12 +712,12 @@ class SolanaMailerClient {
|
|
|
715
712
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
716
713
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
717
714
|
];
|
|
718
|
-
const instruction = new
|
|
715
|
+
const instruction = new TransactionInstruction({
|
|
719
716
|
programId,
|
|
720
717
|
keys,
|
|
721
718
|
data: encodeSetFees(BigInt(sendFee), BigInt(delegationFee)),
|
|
722
719
|
});
|
|
723
|
-
const transaction = new
|
|
720
|
+
const transaction = new Transaction().add(instruction);
|
|
724
721
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
725
722
|
}
|
|
726
723
|
/**
|
|
@@ -729,20 +726,20 @@ class SolanaMailerClient {
|
|
|
729
726
|
async setCustomFeePercentage(account, percentage, connectedWallet, chainInfo, computeOptions) {
|
|
730
727
|
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
731
728
|
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
732
|
-
const accountPubkey = typeof account === 'string' ? new
|
|
733
|
-
const [customFeeInfo] =
|
|
729
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
730
|
+
const [customFeeInfo] = PublicKey.findProgramAddressSync([Buffer.from('custom_fee'), accountPubkey.toBuffer()], programId);
|
|
734
731
|
const keys = [
|
|
735
732
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: true },
|
|
736
733
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: false },
|
|
737
734
|
{ pubkey: customFeeInfo, isSigner: false, isWritable: true },
|
|
738
|
-
{ pubkey:
|
|
735
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
|
739
736
|
];
|
|
740
|
-
const instruction = new
|
|
737
|
+
const instruction = new TransactionInstruction({
|
|
741
738
|
programId,
|
|
742
739
|
keys,
|
|
743
740
|
data: encodeSetCustomFeePercentage(accountPubkey, percentage),
|
|
744
741
|
});
|
|
745
|
-
const transaction = new
|
|
742
|
+
const transaction = new Transaction().add(instruction);
|
|
746
743
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
747
744
|
}
|
|
748
745
|
/**
|
|
@@ -751,19 +748,19 @@ class SolanaMailerClient {
|
|
|
751
748
|
async clearCustomFeePercentage(account, connectedWallet, chainInfo, computeOptions) {
|
|
752
749
|
const connection = await this.getOrCreateConnection(chainInfo, connectedWallet.connection);
|
|
753
750
|
const { programId, mailerStatePda } = this.getProgramAddresses(chainInfo);
|
|
754
|
-
const accountPubkey = typeof account === 'string' ? new
|
|
755
|
-
const [customFeeInfo] =
|
|
751
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
752
|
+
const [customFeeInfo] = PublicKey.findProgramAddressSync([Buffer.from('custom_fee'), accountPubkey.toBuffer()], programId);
|
|
756
753
|
const keys = [
|
|
757
754
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
758
755
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: false },
|
|
759
756
|
{ pubkey: customFeeInfo, isSigner: false, isWritable: true },
|
|
760
757
|
];
|
|
761
|
-
const instruction = new
|
|
758
|
+
const instruction = new TransactionInstruction({
|
|
762
759
|
programId,
|
|
763
760
|
keys,
|
|
764
761
|
data: encodeClearCustomFeePercentage(accountPubkey),
|
|
765
762
|
});
|
|
766
|
-
const transaction = new
|
|
763
|
+
const transaction = new Transaction().add(instruction);
|
|
767
764
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
768
765
|
}
|
|
769
766
|
/**
|
|
@@ -776,12 +773,12 @@ class SolanaMailerClient {
|
|
|
776
773
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
777
774
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
778
775
|
];
|
|
779
|
-
const instruction = new
|
|
776
|
+
const instruction = new TransactionInstruction({
|
|
780
777
|
programId,
|
|
781
778
|
keys,
|
|
782
779
|
data: Buffer.from([InstructionType.Pause]),
|
|
783
780
|
});
|
|
784
|
-
const transaction = new
|
|
781
|
+
const transaction = new Transaction().add(instruction);
|
|
785
782
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
786
783
|
}
|
|
787
784
|
/**
|
|
@@ -794,12 +791,12 @@ class SolanaMailerClient {
|
|
|
794
791
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
795
792
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
796
793
|
];
|
|
797
|
-
const instruction = new
|
|
794
|
+
const instruction = new TransactionInstruction({
|
|
798
795
|
programId,
|
|
799
796
|
keys,
|
|
800
797
|
data: Buffer.from([InstructionType.Unpause]),
|
|
801
798
|
});
|
|
802
|
-
const transaction = new
|
|
799
|
+
const transaction = new Transaction().add(instruction);
|
|
803
800
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
804
801
|
}
|
|
805
802
|
/**
|
|
@@ -812,12 +809,12 @@ class SolanaMailerClient {
|
|
|
812
809
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
813
810
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
814
811
|
];
|
|
815
|
-
const instruction = new
|
|
812
|
+
const instruction = new TransactionInstruction({
|
|
816
813
|
programId,
|
|
817
814
|
keys,
|
|
818
815
|
data: Buffer.from([InstructionType.EmergencyUnpause]),
|
|
819
816
|
});
|
|
820
|
-
const transaction = new
|
|
817
|
+
const transaction = new Transaction().add(instruction);
|
|
821
818
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
822
819
|
}
|
|
823
820
|
/**
|
|
@@ -829,29 +826,29 @@ class SolanaMailerClient {
|
|
|
829
826
|
if (!chainInfo.usdcAddress) {
|
|
830
827
|
throw new Error(`No USDC mint configured for ${chainInfo.name}`);
|
|
831
828
|
}
|
|
832
|
-
const usdcMint = new
|
|
833
|
-
const recipientPubkeys = recipients.map(r => typeof r === 'string' ? new
|
|
834
|
-
const mailerTokenAccount =
|
|
829
|
+
const usdcMint = new PublicKey(chainInfo.usdcAddress);
|
|
830
|
+
const recipientPubkeys = recipients.map(r => typeof r === 'string' ? new PublicKey(r) : r);
|
|
831
|
+
const mailerTokenAccount = getAssociatedTokenAddressSync(usdcMint, mailerStatePda, true, TOKEN_PROGRAM_ID);
|
|
835
832
|
// Build keys array
|
|
836
833
|
const keys = [
|
|
837
834
|
{ pubkey: connectedWallet.wallet.publicKey, isSigner: true, isWritable: false },
|
|
838
835
|
{ pubkey: mailerStatePda, isSigner: false, isWritable: true },
|
|
839
836
|
{ pubkey: mailerTokenAccount, isSigner: false, isWritable: true },
|
|
840
|
-
{ pubkey:
|
|
837
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },
|
|
841
838
|
];
|
|
842
839
|
// Add recipient info and token accounts
|
|
843
840
|
for (const recipient of recipientPubkeys) {
|
|
844
|
-
const [recipientInfo] =
|
|
845
|
-
const recipientTokenAccount =
|
|
841
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), recipient.toBuffer()], programId);
|
|
842
|
+
const recipientTokenAccount = getAssociatedTokenAddressSync(usdcMint, recipient, false, TOKEN_PROGRAM_ID);
|
|
846
843
|
keys.push({ pubkey: recipientInfo, isSigner: false, isWritable: true });
|
|
847
844
|
keys.push({ pubkey: recipientTokenAccount, isSigner: false, isWritable: true });
|
|
848
845
|
}
|
|
849
|
-
const instruction = new
|
|
846
|
+
const instruction = new TransactionInstruction({
|
|
850
847
|
programId,
|
|
851
848
|
keys,
|
|
852
849
|
data: encodeDistributeClaimableFunds(recipientPubkeys),
|
|
853
850
|
});
|
|
854
|
-
const transaction = new
|
|
851
|
+
const transaction = new Transaction().add(instruction);
|
|
855
852
|
return await this.sendTransaction(transaction, connectedWallet.wallet, connection, undefined, computeOptions);
|
|
856
853
|
}
|
|
857
854
|
// ============= Read Methods =============
|
|
@@ -894,8 +891,8 @@ class SolanaMailerClient {
|
|
|
894
891
|
async getRecipientClaimable(recipient, chainInfo, connection) {
|
|
895
892
|
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
896
893
|
const { programId } = this.getProgramAddresses(chainInfo);
|
|
897
|
-
const recipientPubkey = typeof recipient === 'string' ? new
|
|
898
|
-
const [recipientInfo] =
|
|
894
|
+
const recipientPubkey = typeof recipient === 'string' ? new PublicKey(recipient) : recipient;
|
|
895
|
+
const [recipientInfo] = PublicKey.findProgramAddressSync([Buffer.from('recipient_info'), recipientPubkey.toBuffer()], programId);
|
|
899
896
|
const accountInfo = await conn.getAccountInfo(recipientInfo);
|
|
900
897
|
if (!accountInfo || !accountInfo.data) {
|
|
901
898
|
return null;
|
|
@@ -911,7 +908,7 @@ class SolanaMailerClient {
|
|
|
911
908
|
amount: Number(amount),
|
|
912
909
|
timestamp: Number(expiresAt), // Using expiresAt as timestamp
|
|
913
910
|
expiresAt: Number(expiresAt),
|
|
914
|
-
recipient: recipient instanceof
|
|
911
|
+
recipient: recipient instanceof PublicKey ? recipient.toBase58() : recipient,
|
|
915
912
|
isExpired,
|
|
916
913
|
};
|
|
917
914
|
}
|
|
@@ -936,8 +933,8 @@ class SolanaMailerClient {
|
|
|
936
933
|
async getDelegation(address, chainInfo, connection) {
|
|
937
934
|
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
938
935
|
const { programId } = this.getProgramAddresses(chainInfo);
|
|
939
|
-
const addressPubkey = typeof address === 'string' ? new
|
|
940
|
-
const [delegatorInfo] =
|
|
936
|
+
const addressPubkey = typeof address === 'string' ? new PublicKey(address) : address;
|
|
937
|
+
const [delegatorInfo] = PublicKey.findProgramAddressSync([Buffer.from('delegator_info'), addressPubkey.toBuffer()], programId);
|
|
941
938
|
const accountInfo = await conn.getAccountInfo(delegatorInfo);
|
|
942
939
|
if (!accountInfo || !accountInfo.data) {
|
|
943
940
|
return null;
|
|
@@ -950,7 +947,7 @@ class SolanaMailerClient {
|
|
|
950
947
|
}
|
|
951
948
|
// Read delegate pubkey
|
|
952
949
|
const delegateBytes = data.slice(9, 41); // 32 bytes for pubkey
|
|
953
|
-
return new
|
|
950
|
+
return new PublicKey(delegateBytes);
|
|
954
951
|
}
|
|
955
952
|
/**
|
|
956
953
|
* Get custom fee percentage for an account
|
|
@@ -958,8 +955,8 @@ class SolanaMailerClient {
|
|
|
958
955
|
async getCustomFeePercentage(account, chainInfo, connection) {
|
|
959
956
|
const conn = await this.getOrCreateConnection(chainInfo, connection);
|
|
960
957
|
const { programId } = this.getProgramAddresses(chainInfo);
|
|
961
|
-
const accountPubkey = typeof account === 'string' ? new
|
|
962
|
-
const [customFeeInfo] =
|
|
958
|
+
const accountPubkey = typeof account === 'string' ? new PublicKey(account) : account;
|
|
959
|
+
const [customFeeInfo] = PublicKey.findProgramAddressSync([Buffer.from('custom_fee'), accountPubkey.toBuffer()], programId);
|
|
963
960
|
const accountInfo = await conn.getAccountInfo(customFeeInfo);
|
|
964
961
|
if (!accountInfo || !accountInfo.data) {
|
|
965
962
|
return 100; // Default to 100% if no custom fee set
|
|
@@ -997,8 +994,7 @@ class SolanaMailerClient {
|
|
|
997
994
|
// Parse the state data
|
|
998
995
|
const data = accountInfo.data;
|
|
999
996
|
const ownerBytes = data.slice(8, 40); // After discriminator(8)
|
|
1000
|
-
return new
|
|
997
|
+
return new PublicKey(ownerBytes);
|
|
1001
998
|
}
|
|
1002
999
|
}
|
|
1003
|
-
exports.SolanaMailerClient = SolanaMailerClient;
|
|
1004
1000
|
//# sourceMappingURL=solana-mailer-client.js.map
|