@meshconnect/web-link-sdk 3.2.7 → 3.2.9
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/package.json +1 -1
- package/utils/connectors/solana/transaction.js +81 -53
- package/utils/version.d.ts +1 -1
- package/utils/version.js +1 -1
package/package.json
CHANGED
@@ -64,6 +64,22 @@ export function getAssociatedTokenAddress(mint_1, owner_1) {
|
|
64
64
|
});
|
65
65
|
});
|
66
66
|
}
|
67
|
+
function createTokenAccountInstruction(payer, associatedToken, owner, mint, programId) {
|
68
|
+
if (programId === void 0) { programId = TOKEN_PROGRAM_ID; }
|
69
|
+
var keys = [
|
70
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
71
|
+
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
72
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
73
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
74
|
+
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
|
75
|
+
{ pubkey: programId, isSigner: false, isWritable: false }
|
76
|
+
];
|
77
|
+
return new TransactionInstruction({
|
78
|
+
keys: keys,
|
79
|
+
programId: ASSOCIATED_TOKEN_PROGRAM_ID,
|
80
|
+
data: Buffer.alloc(0)
|
81
|
+
});
|
82
|
+
}
|
67
83
|
export function createTransferCheckedInstruction(fromTokenAccount, toTokenAccount, owner, amount, decimals, tokenMint) {
|
68
84
|
if (decimals === void 0) { decimals = 9; }
|
69
85
|
var data = Buffer.alloc(10);
|
@@ -99,42 +115,68 @@ export function createSPLTransferInstruction(_a) {
|
|
99
115
|
}
|
100
116
|
export function createTransferTransaction(config) {
|
101
117
|
return __awaiter(this, void 0, void 0, function () {
|
102
|
-
var fromPubkey, toPubkey,
|
103
|
-
|
104
|
-
|
118
|
+
var fromPubkey, toPubkey, instructions, connection, token2022Accounts, tokenProgram, tokenMintPubkey, fromTokenAccount, toTokenAccount, messageV0;
|
119
|
+
var _a;
|
120
|
+
return __generator(this, function (_b) {
|
121
|
+
switch (_b.label) {
|
105
122
|
case 0:
|
106
123
|
fromPubkey = new PublicKey(config.fromAddress);
|
107
124
|
toPubkey = new PublicKey(config.toAddress);
|
125
|
+
instructions = [];
|
108
126
|
if (!!config.tokenMint) return [3 /*break*/, 1];
|
109
|
-
|
127
|
+
instructions.push(SystemProgram.transfer({
|
110
128
|
fromPubkey: fromPubkey,
|
111
129
|
toPubkey: toPubkey,
|
112
130
|
lamports: Number(config.amount)
|
113
|
-
});
|
114
|
-
return [3 /*break*/,
|
131
|
+
}));
|
132
|
+
return [3 /*break*/, 6];
|
115
133
|
case 1:
|
134
|
+
connection = void 0;
|
135
|
+
// special use case for PYUSD on solana devnet. TODO: make it generic
|
136
|
+
if (config.tokenMint === 'CXk2AMBfi3TwaEL2468s6zP8xq9NxTXjp9gjMgzeUynM') {
|
137
|
+
connection = new Connection('https://api.devnet.solana.com', 'confirmed');
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
|
141
|
+
}
|
142
|
+
return [4 /*yield*/, connection.getTokenAccountsByOwner(fromPubkey, { programId: TOKEN_2022_PROGRAM_ID })];
|
143
|
+
case 2:
|
144
|
+
token2022Accounts = _b.sent();
|
145
|
+
tokenProgram = (token2022Accounts === null || token2022Accounts === void 0 ? void 0 : token2022Accounts.value.length)
|
146
|
+
? TOKEN_2022_PROGRAM_ID
|
147
|
+
: TOKEN_PROGRAM_ID;
|
148
|
+
config.tokenProgram = tokenProgram.toBase58();
|
116
149
|
tokenMintPubkey = new PublicKey(config.tokenMint);
|
117
150
|
return [4 /*yield*/, getAssociatedTokenAddress(tokenMintPubkey, fromPubkey, config.tokenProgram)];
|
118
|
-
case 2:
|
119
|
-
fromTokenAccount = _a.sent();
|
120
|
-
return [4 /*yield*/, getAssociatedTokenAddress(tokenMintPubkey, toPubkey, config.tokenProgram)];
|
121
151
|
case 3:
|
122
|
-
|
123
|
-
|
124
|
-
config.tokenProgram === TOKEN_2022_PROGRAM_ID.toBase58()
|
125
|
-
? createTransferCheckedInstruction(fromTokenAccount, toTokenAccount, fromPubkey, BigInt(config.amount), config.tokenDecimals, tokenMintPubkey)
|
126
|
-
: createSPLTransferInstruction({
|
127
|
-
fromTokenAccount: fromTokenAccount,
|
128
|
-
toTokenAccount: toTokenAccount,
|
129
|
-
owner: fromPubkey,
|
130
|
-
amount: BigInt(config.amount)
|
131
|
-
});
|
132
|
-
_a.label = 4;
|
152
|
+
fromTokenAccount = _b.sent();
|
153
|
+
return [4 /*yield*/, getAssociatedTokenAddress(tokenMintPubkey, toPubkey, config.tokenProgram)];
|
133
154
|
case 4:
|
155
|
+
toTokenAccount = _b.sent();
|
156
|
+
return [4 /*yield*/, connection.getTokenAccountsByOwner(toPubkey, {
|
157
|
+
programId: tokenProgram
|
158
|
+
})];
|
159
|
+
case 5:
|
160
|
+
if (!((_a = (_b.sent())) === null || _a === void 0 ? void 0 : _a.value.length)) {
|
161
|
+
instructions.push(createTokenAccountInstruction(fromPubkey, toTokenAccount, toPubkey, tokenMintPubkey, tokenProgram));
|
162
|
+
}
|
163
|
+
if (config.tokenProgram === TOKEN_2022_PROGRAM_ID.toBase58()) {
|
164
|
+
instructions.push(createTransferCheckedInstruction(fromTokenAccount, toTokenAccount, fromPubkey, BigInt(config.amount), config.tokenDecimals, tokenMintPubkey));
|
165
|
+
}
|
166
|
+
else {
|
167
|
+
instructions.push(createSPLTransferInstruction({
|
168
|
+
fromTokenAccount: fromTokenAccount,
|
169
|
+
toTokenAccount: toTokenAccount,
|
170
|
+
owner: fromPubkey,
|
171
|
+
amount: BigInt(config.amount)
|
172
|
+
}));
|
173
|
+
}
|
174
|
+
_b.label = 6;
|
175
|
+
case 6:
|
134
176
|
messageV0 = new TransactionMessage({
|
135
177
|
payerKey: fromPubkey,
|
136
178
|
recentBlockhash: config.blockhash,
|
137
|
-
instructions:
|
179
|
+
instructions: instructions
|
138
180
|
}).compileToV0Message();
|
139
181
|
return [2 /*return*/, new VersionedTransaction(messageV0)];
|
140
182
|
}
|
@@ -178,55 +220,41 @@ export function handleManualSignAndSend(transaction, provider) {
|
|
178
220
|
});
|
179
221
|
}
|
180
222
|
export var sendSOLTransaction = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
181
|
-
var provider,
|
223
|
+
var provider, transaction, isManualWallet, signature, error_2, error_3;
|
182
224
|
return __generator(this, function (_a) {
|
183
225
|
switch (_a.label) {
|
184
226
|
case 0:
|
185
|
-
_a.trys.push([0,
|
227
|
+
_a.trys.push([0, 8, , 9]);
|
186
228
|
provider = getSolanaProvider(config.walletName);
|
187
|
-
|
188
|
-
if (!config.tokenMint) return [3 /*break*/, 2];
|
189
|
-
connection = void 0;
|
190
|
-
// special use case for PYUSD on solana devnet. TODO: make it generic
|
191
|
-
if (config.tokenMint === 'CXk2AMBfi3TwaEL2468s6zP8xq9NxTXjp9gjMgzeUynM') {
|
192
|
-
connection = new Connection('https://api.devnet.solana.com', 'confirmed');
|
193
|
-
}
|
194
|
-
else {
|
195
|
-
connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
|
196
|
-
}
|
197
|
-
return [4 /*yield*/, connection.getTokenAccountsByOwner(walletPublicKey, { programId: TOKEN_2022_PROGRAM_ID })];
|
229
|
+
return [4 /*yield*/, createTransferTransaction(config)];
|
198
230
|
case 1:
|
199
|
-
token2022Accounts = _a.sent();
|
200
|
-
config.tokenProgram = (token2022Accounts === null || token2022Accounts === void 0 ? void 0 : token2022Accounts.value.length)
|
201
|
-
? TOKEN_2022_PROGRAM_ID.toBase58()
|
202
|
-
: TOKEN_PROGRAM_ID.toBase58();
|
203
|
-
_a.label = 2;
|
204
|
-
case 2: return [4 /*yield*/, createTransferTransaction(config)];
|
205
|
-
case 3:
|
206
231
|
transaction = _a.sent();
|
207
232
|
isManualWallet = provider.isTrust ||
|
208
233
|
provider.isTrustWallet ||
|
209
234
|
config.walletName.toLowerCase().includes('trust');
|
210
|
-
if (!isManualWallet) return [3 /*break*/,
|
235
|
+
if (!isManualWallet) return [3 /*break*/, 3];
|
211
236
|
return [4 /*yield*/, handleManualSignAndSend(transaction, provider)];
|
212
|
-
case
|
237
|
+
case 2: return [2 /*return*/, _a.sent()];
|
238
|
+
case 3:
|
239
|
+
if (!provider.signAndSendTransaction) return [3 /*break*/, 7];
|
240
|
+
_a.label = 4;
|
241
|
+
case 4:
|
242
|
+
_a.trys.push([4, 6, , 7]);
|
243
|
+
return [4 /*yield*/, provider.signAndSendTransaction(transaction)
|
244
|
+
// @TODO: validate that signature was a successful tx
|
245
|
+
];
|
213
246
|
case 5:
|
214
|
-
if (!provider.signAndSendTransaction) return [3 /*break*/, 9];
|
215
|
-
_a.label = 6;
|
216
|
-
case 6:
|
217
|
-
_a.trys.push([6, 8, , 9]);
|
218
|
-
return [4 /*yield*/, provider.signAndSendTransaction(transaction)];
|
219
|
-
case 7:
|
220
247
|
signature = (_a.sent()).signature;
|
248
|
+
// @TODO: validate that signature was a successful tx
|
221
249
|
return [2 /*return*/, signature];
|
222
|
-
case
|
250
|
+
case 6:
|
223
251
|
error_2 = _a.sent();
|
224
252
|
if (isUserRejection(error_2)) {
|
225
253
|
throw new Error('Transaction was rejected by user');
|
226
254
|
}
|
227
255
|
return [2 /*return*/, handleManualSignAndSend(transaction, provider)];
|
228
|
-
case
|
229
|
-
case
|
256
|
+
case 7: return [2 /*return*/, handleManualSignAndSend(transaction, provider)];
|
257
|
+
case 8:
|
230
258
|
error_3 = _a.sent();
|
231
259
|
if (isUserRejection(error_3)) {
|
232
260
|
throw new Error('Transaction was rejected by user');
|
@@ -234,7 +262,7 @@ export var sendSOLTransaction = function (config) { return __awaiter(void 0, voi
|
|
234
262
|
throw error_3 instanceof Error
|
235
263
|
? error_3
|
236
264
|
: new Error("Failed to send SOL transaction with ".concat(config.walletName, " wallet"));
|
237
|
-
case
|
265
|
+
case 9: return [2 /*return*/];
|
238
266
|
}
|
239
267
|
});
|
240
268
|
}); };
|
package/utils/version.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const sdkVersion = "3.2.
|
1
|
+
export declare const sdkVersion = "3.2.9";
|
package/utils/version.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export var sdkVersion = '3.2.
|
1
|
+
export var sdkVersion = '3.2.9';
|