@joai/warps-adapter-solana 1.0.1 → 1.0.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/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +155 -83
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -7
package/dist/index.d.cts
CHANGED
|
@@ -211,6 +211,9 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
211
211
|
private initializeCache;
|
|
212
212
|
private createProviderForOperation;
|
|
213
213
|
private resolveTransaction;
|
|
214
|
+
private asVersionedTransaction;
|
|
215
|
+
private asVersionedTransactionOrThrow;
|
|
216
|
+
private toSerializedTransactionBytes;
|
|
214
217
|
private shouldSkipPreflight;
|
|
215
218
|
private sendWithRetry;
|
|
216
219
|
private sendRawTransaction;
|
package/dist/index.d.ts
CHANGED
|
@@ -211,6 +211,9 @@ declare class WarpSolanaWallet implements AdapterWarpWallet {
|
|
|
211
211
|
private initializeCache;
|
|
212
212
|
private createProviderForOperation;
|
|
213
213
|
private resolveTransaction;
|
|
214
|
+
private asVersionedTransaction;
|
|
215
|
+
private asVersionedTransactionOrThrow;
|
|
216
|
+
private toSerializedTransactionBytes;
|
|
214
217
|
private shouldSkipPreflight;
|
|
215
218
|
private sendWithRetry;
|
|
216
219
|
private sendRawTransaction;
|
package/dist/index.js
CHANGED
|
@@ -57,8 +57,7 @@ var import_warps13 = require("@joai/warps");
|
|
|
57
57
|
|
|
58
58
|
// src/WarpSolanaDataLoader.ts
|
|
59
59
|
var import_warps5 = require("@joai/warps");
|
|
60
|
-
var
|
|
61
|
-
var import_spl_token = require("@solana/spl-token");
|
|
60
|
+
var import_web32 = require("@solana/web3.js");
|
|
62
61
|
|
|
63
62
|
// src/constants.ts
|
|
64
63
|
var WarpSolanaConstants = {
|
|
@@ -120,6 +119,58 @@ var X402SolanaNetworkIdentifiers = {
|
|
|
120
119
|
};
|
|
121
120
|
var SupportedX402SolanaNetworks = [X402SolanaNetworkIdentifiers.Mainnet, X402SolanaNetworkIdentifiers.Devnet];
|
|
122
121
|
|
|
122
|
+
// src/tokenProgram.ts
|
|
123
|
+
var import_web3 = require("@solana/web3.js");
|
|
124
|
+
var MINT_SIZE = 82;
|
|
125
|
+
var TOKEN_TRANSFER_INSTRUCTION = 3;
|
|
126
|
+
var TOKEN_PROGRAM_ID = new import_web3.PublicKey(WarpSolanaConstants.Programs.TokenProgram);
|
|
127
|
+
var ASSOCIATED_TOKEN_PROGRAM_ID = new import_web3.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
|
|
128
|
+
var getAssociatedTokenAddress = async (mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve, programId, associatedTokenProgramId);
|
|
129
|
+
var getAssociatedTokenAddressSync = (mint, owner, allowOwnerOffCurve = false, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => {
|
|
130
|
+
if (!allowOwnerOffCurve && !import_web3.PublicKey.isOnCurve(owner.toBuffer())) {
|
|
131
|
+
throw new Error("Owner cannot be a PDA");
|
|
132
|
+
}
|
|
133
|
+
const [address] = import_web3.PublicKey.findProgramAddressSync([owner.toBuffer(), programId.toBuffer(), mint.toBuffer()], associatedTokenProgramId);
|
|
134
|
+
return address;
|
|
135
|
+
};
|
|
136
|
+
var createAssociatedTokenAccountInstruction = (payer, associatedToken, owner, mint, programId = TOKEN_PROGRAM_ID, associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) => new import_web3.TransactionInstruction({
|
|
137
|
+
keys: [
|
|
138
|
+
{ pubkey: payer, isSigner: true, isWritable: true },
|
|
139
|
+
{ pubkey: associatedToken, isSigner: false, isWritable: true },
|
|
140
|
+
{ pubkey: owner, isSigner: false, isWritable: false },
|
|
141
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
142
|
+
{ pubkey: import_web3.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
143
|
+
{ pubkey: programId, isSigner: false, isWritable: false }
|
|
144
|
+
],
|
|
145
|
+
programId: associatedTokenProgramId,
|
|
146
|
+
data: Buffer.alloc(0)
|
|
147
|
+
});
|
|
148
|
+
var createTransferInstruction = (source, destination, owner, amount, programId = TOKEN_PROGRAM_ID) => {
|
|
149
|
+
const data = Buffer.alloc(9);
|
|
150
|
+
data.writeUInt8(TOKEN_TRANSFER_INSTRUCTION, 0);
|
|
151
|
+
data.writeBigUInt64LE(BigInt(amount), 1);
|
|
152
|
+
return new import_web3.TransactionInstruction({
|
|
153
|
+
keys: [
|
|
154
|
+
{ pubkey: source, isSigner: false, isWritable: true },
|
|
155
|
+
{ pubkey: destination, isSigner: false, isWritable: true },
|
|
156
|
+
{ pubkey: owner, isSigner: true, isWritable: false }
|
|
157
|
+
],
|
|
158
|
+
programId,
|
|
159
|
+
data
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
var getMint = async (connection, address, commitment, programId = TOKEN_PROGRAM_ID) => {
|
|
163
|
+
const info = await connection.getAccountInfo(address, commitment);
|
|
164
|
+
if (!info) throw new Error("Token mint account not found");
|
|
165
|
+
if (!info.owner.equals(programId)) throw new Error("Token mint account owner mismatch");
|
|
166
|
+
if (info.data.length < MINT_SIZE) throw new Error("Token mint account has invalid size");
|
|
167
|
+
return {
|
|
168
|
+
address,
|
|
169
|
+
decimals: info.data.readUInt8(44),
|
|
170
|
+
isInitialized: info.data.readUInt8(45) !== 0
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
123
174
|
// src/tokens.ts
|
|
124
175
|
var import_warps4 = require("@joai/warps");
|
|
125
176
|
|
|
@@ -323,12 +374,12 @@ var WarpSolanaDataLoader = class {
|
|
|
323
374
|
this.config = config;
|
|
324
375
|
this.chain = chain;
|
|
325
376
|
const providerConfig = (0, import_warps5.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
326
|
-
this.connection = new
|
|
377
|
+
this.connection = new import_web32.Connection(providerConfig.url, "confirmed");
|
|
327
378
|
this.cache = new import_warps5.WarpCache(config.env, config.cache);
|
|
328
379
|
}
|
|
329
380
|
async getAccount(address) {
|
|
330
381
|
try {
|
|
331
|
-
const publicKey = new
|
|
382
|
+
const publicKey = new import_web32.PublicKey(address);
|
|
332
383
|
const balance = await this.connection.getBalance(publicKey);
|
|
333
384
|
return {
|
|
334
385
|
chain: this.chain.name,
|
|
@@ -426,9 +477,9 @@ var WarpSolanaDataLoader = class {
|
|
|
426
477
|
}
|
|
427
478
|
async getTokenBalances(address) {
|
|
428
479
|
try {
|
|
429
|
-
const publicKey = new
|
|
480
|
+
const publicKey = new import_web32.PublicKey(address);
|
|
430
481
|
const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(publicKey, {
|
|
431
|
-
programId: new
|
|
482
|
+
programId: new import_web32.PublicKey(WarpSolanaConstants.Programs.TokenProgram)
|
|
432
483
|
});
|
|
433
484
|
const env = this.config.env === "mainnet" ? "mainnet" : this.config.env === "devnet" ? "devnet" : "testnet";
|
|
434
485
|
const knownTokens = getKnownTokensForChain(this.chain.name, env);
|
|
@@ -470,8 +521,8 @@ var WarpSolanaDataLoader = class {
|
|
|
470
521
|
}
|
|
471
522
|
async getTokenMetadata(tokenAddress) {
|
|
472
523
|
try {
|
|
473
|
-
const mintPublicKey = new
|
|
474
|
-
const mintInfo = await
|
|
524
|
+
const mintPublicKey = new import_web32.PublicKey(tokenAddress);
|
|
525
|
+
const mintInfo = await getMint(this.connection, mintPublicKey);
|
|
475
526
|
return {
|
|
476
527
|
name: "Unknown Token",
|
|
477
528
|
symbol: "UNKNOWN",
|
|
@@ -620,17 +671,16 @@ var WarpSolanaDataLoader = class {
|
|
|
620
671
|
};
|
|
621
672
|
|
|
622
673
|
// src/WarpSolanaExecutor.ts
|
|
623
|
-
var
|
|
624
|
-
var import_web34 = require("@solana/web3.js");
|
|
674
|
+
var import_web35 = require("@solana/web3.js");
|
|
625
675
|
var import_warps8 = require("@joai/warps");
|
|
626
676
|
|
|
627
677
|
// src/WarpSolanaOutput.ts
|
|
628
678
|
var import_warps7 = require("@joai/warps");
|
|
629
|
-
var
|
|
679
|
+
var import_web34 = require("@solana/web3.js");
|
|
630
680
|
|
|
631
681
|
// src/WarpSolanaSerializer.ts
|
|
632
682
|
var import_warps6 = require("@joai/warps");
|
|
633
|
-
var
|
|
683
|
+
var import_web33 = require("@solana/web3.js");
|
|
634
684
|
var import_bs58 = __toESM(require("bs58"), 1);
|
|
635
685
|
var WarpSolanaSerializer = class {
|
|
636
686
|
constructor() {
|
|
@@ -643,7 +693,7 @@ var WarpSolanaSerializer = class {
|
|
|
643
693
|
if (typeof value === "string") {
|
|
644
694
|
if (value.length >= 32 && value.length <= 44) {
|
|
645
695
|
try {
|
|
646
|
-
const pubkey = new
|
|
696
|
+
const pubkey = new import_web33.PublicKey(value);
|
|
647
697
|
if (pubkey.toBase58() === value && /^[1-9A-HJ-NP-Za-km-z]+$/.test(value)) {
|
|
648
698
|
return `address:${value}`;
|
|
649
699
|
}
|
|
@@ -670,7 +720,7 @@ var WarpSolanaSerializer = class {
|
|
|
670
720
|
if (typeof value === "boolean") {
|
|
671
721
|
return `boolean:${value}`;
|
|
672
722
|
}
|
|
673
|
-
if (value instanceof
|
|
723
|
+
if (value instanceof import_web33.PublicKey) {
|
|
674
724
|
return `address:${value.toBase58()}`;
|
|
675
725
|
}
|
|
676
726
|
if (value instanceof Uint8Array) {
|
|
@@ -820,7 +870,7 @@ var WarpSolanaOutput = class {
|
|
|
820
870
|
this.chain = chain;
|
|
821
871
|
this.serializer = new WarpSolanaSerializer();
|
|
822
872
|
const providerConfig = (0, import_warps7.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
823
|
-
this.connection = new
|
|
873
|
+
this.connection = new import_web34.Connection(providerConfig.url, "confirmed");
|
|
824
874
|
this.cache = new import_warps7.WarpCache(config.env, config.cache);
|
|
825
875
|
}
|
|
826
876
|
async getActionExecution(warp, actionIndex, tx) {
|
|
@@ -996,7 +1046,7 @@ var WarpSolanaExecutor = class {
|
|
|
996
1046
|
this.chain = chain;
|
|
997
1047
|
this.serializer = new WarpSolanaSerializer();
|
|
998
1048
|
const providerConfig = (0, import_warps8.getProviderConfig)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
999
|
-
this.connection = new
|
|
1049
|
+
this.connection = new import_web35.Connection(providerConfig.url, "confirmed");
|
|
1000
1050
|
this.output = new WarpSolanaOutput(config, this.chain);
|
|
1001
1051
|
}
|
|
1002
1052
|
async createTransaction(executable) {
|
|
@@ -1025,14 +1075,14 @@ var WarpSolanaExecutor = class {
|
|
|
1025
1075
|
}
|
|
1026
1076
|
const instructions = [];
|
|
1027
1077
|
if (executable.value > 0n) {
|
|
1028
|
-
instructions.push(
|
|
1078
|
+
instructions.push(import_web35.SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(executable.value) }));
|
|
1029
1079
|
}
|
|
1030
1080
|
if (executable.data) {
|
|
1031
1081
|
const data = this.serializer.stringToTyped(executable.data);
|
|
1032
1082
|
if (data && typeof data === "string") {
|
|
1033
1083
|
const dataBuffer = Buffer.from(data, "base64");
|
|
1034
1084
|
instructions.push(
|
|
1035
|
-
new
|
|
1085
|
+
new import_web35.TransactionInstruction({
|
|
1036
1086
|
keys: [
|
|
1037
1087
|
{ pubkey: fromPubkey, isSigner: true, isWritable: true },
|
|
1038
1088
|
{ pubkey: destinationPubkey, isSigner: false, isWritable: true }
|
|
@@ -1061,9 +1111,9 @@ var WarpSolanaExecutor = class {
|
|
|
1061
1111
|
const abiAccounts = parsedAbi?.instructions?.[action.func]?.accounts ?? null;
|
|
1062
1112
|
const accounts = await this.buildInstructionAccounts(action, executable, fromPubkey, programId, abiAccounts);
|
|
1063
1113
|
await this.ensureATAs(abiAccounts, accounts, fromPubkey, instructions);
|
|
1064
|
-
instructions.push(new
|
|
1114
|
+
instructions.push(new import_web35.TransactionInstruction({ keys: accounts, programId, data: instructionData }));
|
|
1065
1115
|
if (executable.value > 0n) {
|
|
1066
|
-
instructions.push(
|
|
1116
|
+
instructions.push(import_web35.SystemProgram.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
|
|
1067
1117
|
}
|
|
1068
1118
|
return this.setTransactionDefaults(instructions, fromPubkey);
|
|
1069
1119
|
}
|
|
@@ -1086,14 +1136,14 @@ var WarpSolanaExecutor = class {
|
|
|
1086
1136
|
if (match) {
|
|
1087
1137
|
const mintAddress = match[1];
|
|
1088
1138
|
try {
|
|
1089
|
-
const mintPubkey = new
|
|
1090
|
-
const expectedAta = await
|
|
1139
|
+
const mintPubkey = new import_web35.PublicKey(mintAddress);
|
|
1140
|
+
const expectedAta = await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
1091
1141
|
const ataKey = expectedAta.toBase58();
|
|
1092
1142
|
if (!createdATAs.has(ataKey)) {
|
|
1093
1143
|
createdATAs.add(ataKey);
|
|
1094
1144
|
const ataInfo = await this.connection.getAccountInfo(expectedAta);
|
|
1095
1145
|
if (!ataInfo) {
|
|
1096
|
-
instructions.push(
|
|
1146
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, expectedAta, fromPubkey, mintPubkey));
|
|
1097
1147
|
}
|
|
1098
1148
|
}
|
|
1099
1149
|
} catch {
|
|
@@ -1107,15 +1157,15 @@ var WarpSolanaExecutor = class {
|
|
|
1107
1157
|
const mintAddress = match[1];
|
|
1108
1158
|
const receiverAddress = match[2];
|
|
1109
1159
|
try {
|
|
1110
|
-
const mintPubkey = new
|
|
1111
|
-
const receiverPubkey = new
|
|
1112
|
-
const expectedAta = await
|
|
1160
|
+
const mintPubkey = new import_web35.PublicKey(mintAddress);
|
|
1161
|
+
const receiverPubkey = new import_web35.PublicKey(receiverAddress);
|
|
1162
|
+
const expectedAta = await getAssociatedTokenAddress(mintPubkey, receiverPubkey);
|
|
1113
1163
|
const ataKey = expectedAta.toBase58();
|
|
1114
1164
|
if (!createdATAs.has(ataKey)) {
|
|
1115
1165
|
createdATAs.add(ataKey);
|
|
1116
1166
|
const ataInfo = await this.connection.getAccountInfo(expectedAta);
|
|
1117
1167
|
if (!ataInfo) {
|
|
1118
|
-
instructions.push(
|
|
1168
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, expectedAta, receiverPubkey, mintPubkey));
|
|
1119
1169
|
}
|
|
1120
1170
|
}
|
|
1121
1171
|
} catch {
|
|
@@ -1192,7 +1242,7 @@ var WarpSolanaExecutor = class {
|
|
|
1192
1242
|
buffers.push(Buffer.from(String(arg), "utf8"));
|
|
1193
1243
|
} else if (def.type === "publicKey" || def.type === "pubkey") {
|
|
1194
1244
|
try {
|
|
1195
|
-
const pubkey = new
|
|
1245
|
+
const pubkey = new import_web35.PublicKey(arg);
|
|
1196
1246
|
buffers.push(Buffer.from(pubkey.toBuffer()));
|
|
1197
1247
|
} catch {
|
|
1198
1248
|
buffers.push(Buffer.from(String(arg), "utf8"));
|
|
@@ -1273,7 +1323,7 @@ var WarpSolanaExecutor = class {
|
|
|
1273
1323
|
if (accountInput.input.as?.startsWith("USER_ATA:") || accountInput.input.as?.startsWith("RECEIVER_ATA:")) {
|
|
1274
1324
|
return await this.resolveAccountPubkey(`{{${accountInput.input.as}}}`, fromPubkey);
|
|
1275
1325
|
}
|
|
1276
|
-
return new
|
|
1326
|
+
return new import_web35.PublicKey(address);
|
|
1277
1327
|
}
|
|
1278
1328
|
interpolateAccountAddress(address, resolvedInputs) {
|
|
1279
1329
|
if (!address.includes("{{")) return address;
|
|
@@ -1330,8 +1380,8 @@ var WarpSolanaExecutor = class {
|
|
|
1330
1380
|
if (nativeTokenTransfers.length === 1 && splTokenTransfers.length === 0) {
|
|
1331
1381
|
const transfer = nativeTokenTransfers[0];
|
|
1332
1382
|
if (transfer.amount <= 0n) throw new Error("WarpSolanaExecutor: Native token transfer amount must be positive");
|
|
1333
|
-
const fromPubkey = new
|
|
1334
|
-
return this.setTransactionDefaults([
|
|
1383
|
+
const fromPubkey = new import_web35.PublicKey(userWallet);
|
|
1384
|
+
return this.setTransactionDefaults([import_web35.SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(transfer.amount) })], fromPubkey);
|
|
1335
1385
|
}
|
|
1336
1386
|
if (nativeTokenTransfers.length === 0 && splTokenTransfers.length === 1) {
|
|
1337
1387
|
return this.createSingleTokenTransfer(executable, splTokenTransfers[0], userWallet, destinationPubkey);
|
|
@@ -1340,18 +1390,18 @@ var WarpSolanaExecutor = class {
|
|
|
1340
1390
|
throw new Error("WarpSolanaExecutor: Invalid transfer configuration");
|
|
1341
1391
|
}
|
|
1342
1392
|
async createSingleTokenTransfer(executable, transfer, userWallet, destinationPubkey) {
|
|
1343
|
-
const mintAddress = new
|
|
1344
|
-
const fromPubkey = new
|
|
1345
|
-
const sourceTokenAccount = await
|
|
1346
|
-
const destinationTokenAccount = await
|
|
1393
|
+
const mintAddress = new import_web35.PublicKey(transfer.identifier);
|
|
1394
|
+
const fromPubkey = new import_web35.PublicKey(userWallet);
|
|
1395
|
+
const sourceTokenAccount = await getAssociatedTokenAddress(mintAddress, fromPubkey);
|
|
1396
|
+
const destinationTokenAccount = await getAssociatedTokenAddress(mintAddress, destinationPubkey);
|
|
1347
1397
|
if (!await this.connection.getAccountInfo(sourceTokenAccount)) {
|
|
1348
1398
|
throw new Error("WarpSolanaExecutor: Source token account does not exist");
|
|
1349
1399
|
}
|
|
1350
1400
|
const instructions = [];
|
|
1351
1401
|
if (!await this.connection.getAccountInfo(destinationTokenAccount)) {
|
|
1352
|
-
instructions.push(
|
|
1402
|
+
instructions.push(createAssociatedTokenAccountInstruction(fromPubkey, destinationTokenAccount, destinationPubkey, mintAddress));
|
|
1353
1403
|
}
|
|
1354
|
-
instructions.push(
|
|
1404
|
+
instructions.push(createTransferInstruction(sourceTokenAccount, destinationTokenAccount, fromPubkey, Number(transfer.amount)));
|
|
1355
1405
|
return this.setTransactionDefaults(instructions, fromPubkey);
|
|
1356
1406
|
}
|
|
1357
1407
|
async executeQuery(executable) {
|
|
@@ -1359,7 +1409,7 @@ var WarpSolanaExecutor = class {
|
|
|
1359
1409
|
if (action.type !== "query") throw new Error(`WarpSolanaExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
1360
1410
|
if (!action.func) throw new Error("WarpSolanaExecutor: Query action must have a function name");
|
|
1361
1411
|
if (!executable.destination) throw new Error("WarpSolanaExecutor: Query address is required");
|
|
1362
|
-
const queryAddress = new
|
|
1412
|
+
const queryAddress = new import_web35.PublicKey(executable.destination);
|
|
1363
1413
|
const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
1364
1414
|
let decodedResult = [];
|
|
1365
1415
|
let isSuccess = true;
|
|
@@ -1418,16 +1468,16 @@ var WarpSolanaExecutor = class {
|
|
|
1418
1468
|
async setTransactionDefaults(instructions, fromPubkey) {
|
|
1419
1469
|
const { blockhash } = await this.connection.getLatestBlockhash("confirmed");
|
|
1420
1470
|
const allInstructions = this.addComputeBudgetInstructions(instructions);
|
|
1421
|
-
const messageV0 =
|
|
1471
|
+
const messageV0 = import_web35.MessageV0.compile({
|
|
1422
1472
|
payerKey: fromPubkey,
|
|
1423
1473
|
instructions: allInstructions,
|
|
1424
1474
|
recentBlockhash: blockhash
|
|
1425
1475
|
});
|
|
1426
|
-
return new
|
|
1476
|
+
return new import_web35.VersionedTransaction(messageV0);
|
|
1427
1477
|
}
|
|
1428
1478
|
toPublicKey(address, errorMsg) {
|
|
1429
1479
|
try {
|
|
1430
|
-
return new
|
|
1480
|
+
return new import_web35.PublicKey(address);
|
|
1431
1481
|
} catch {
|
|
1432
1482
|
throw new Error(`WarpSolanaExecutor: ${errorMsg}`);
|
|
1433
1483
|
}
|
|
@@ -1476,8 +1526,8 @@ var WarpSolanaExecutor = class {
|
|
|
1476
1526
|
if (!mintAddress || mintAddress.includes("{{")) {
|
|
1477
1527
|
throw new Error(`Invalid USER_ATA placeholder: ${address}. Mint address must be resolved first.`);
|
|
1478
1528
|
}
|
|
1479
|
-
const mintPubkey = new
|
|
1480
|
-
return await
|
|
1529
|
+
const mintPubkey = new import_web35.PublicKey(mintAddress);
|
|
1530
|
+
return await getAssociatedTokenAddress(mintPubkey, fromPubkey);
|
|
1481
1531
|
}
|
|
1482
1532
|
if (address.startsWith("{{RECEIVER_ATA:") && address.endsWith("}}")) {
|
|
1483
1533
|
const content = address.slice(15, -2);
|
|
@@ -1490,12 +1540,12 @@ var WarpSolanaExecutor = class {
|
|
|
1490
1540
|
}
|
|
1491
1541
|
if (mintAddress.includes(":")) mintAddress = mintAddress.split(":")[1];
|
|
1492
1542
|
if (receiverAddress.includes(":")) receiverAddress = receiverAddress.split(":")[1];
|
|
1493
|
-
const mintPubkey = new
|
|
1494
|
-
const receiverPubkey = new
|
|
1495
|
-
return await
|
|
1543
|
+
const mintPubkey = new import_web35.PublicKey(mintAddress);
|
|
1544
|
+
const receiverPubkey = new import_web35.PublicKey(receiverAddress);
|
|
1545
|
+
return await getAssociatedTokenAddress(mintPubkey, receiverPubkey);
|
|
1496
1546
|
}
|
|
1497
1547
|
}
|
|
1498
|
-
return new
|
|
1548
|
+
return new import_web35.PublicKey(address);
|
|
1499
1549
|
}
|
|
1500
1550
|
determineAccountFlags(accountDef, pubkey, fromPubkey) {
|
|
1501
1551
|
const accountMeta = typeof accountDef === "object" ? accountDef : {};
|
|
@@ -1509,8 +1559,8 @@ var WarpSolanaExecutor = class {
|
|
|
1509
1559
|
addComputeBudgetInstructions(instructions) {
|
|
1510
1560
|
const hasTokenTransfer = instructions.some((ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram);
|
|
1511
1561
|
const computeUnits = hasTokenTransfer ? WarpSolanaConstants.ComputeUnitLimit.TokenTransfer : WarpSolanaConstants.ComputeUnitLimit.Default;
|
|
1512
|
-
const computeUnitLimitIx =
|
|
1513
|
-
const computeUnitPriceIx =
|
|
1562
|
+
const computeUnitLimitIx = import_web35.ComputeBudgetProgram.setComputeUnitLimit({ units: computeUnits });
|
|
1563
|
+
const computeUnitPriceIx = import_web35.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: WarpSolanaConstants.PriorityFee.Default });
|
|
1514
1564
|
return [computeUnitLimitIx, computeUnitPriceIx, ...instructions];
|
|
1515
1565
|
}
|
|
1516
1566
|
};
|
|
@@ -1663,13 +1713,13 @@ var WarpSolanaExplorer = class {
|
|
|
1663
1713
|
// src/WarpSolanaWallet.ts
|
|
1664
1714
|
var import_warps12 = require("@joai/warps");
|
|
1665
1715
|
var import_kit = require("@solana/kit");
|
|
1666
|
-
var
|
|
1716
|
+
var import_web38 = require("@solana/web3.js");
|
|
1667
1717
|
var import_client = require("@x402/svm/exact/client");
|
|
1668
1718
|
|
|
1669
1719
|
// src/providers/MnemonicWalletProvider.ts
|
|
1670
1720
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
1671
1721
|
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
1672
|
-
var
|
|
1722
|
+
var import_web36 = require("@solana/web3.js");
|
|
1673
1723
|
var import_warps9 = require("@joai/warps");
|
|
1674
1724
|
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1675
1725
|
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
@@ -1698,22 +1748,22 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1698
1748
|
}
|
|
1699
1749
|
async signTransaction(tx) {
|
|
1700
1750
|
const keypair = this.getKeypair();
|
|
1701
|
-
if (tx instanceof
|
|
1751
|
+
if (tx instanceof import_web36.VersionedTransaction) {
|
|
1702
1752
|
tx.sign([keypair]);
|
|
1703
1753
|
return tx;
|
|
1704
1754
|
}
|
|
1705
|
-
if (tx instanceof
|
|
1755
|
+
if (tx instanceof import_web36.Transaction) {
|
|
1706
1756
|
tx.sign(keypair);
|
|
1707
1757
|
return tx;
|
|
1708
1758
|
}
|
|
1709
1759
|
if (tx.transaction) {
|
|
1710
|
-
if (tx.transaction instanceof
|
|
1760
|
+
if (tx.transaction instanceof import_web36.Transaction) {
|
|
1711
1761
|
tx.transaction.sign(keypair);
|
|
1712
1762
|
return { ...tx, transaction: tx.transaction.serialize() };
|
|
1713
1763
|
}
|
|
1714
1764
|
if (typeof tx.transaction === "object") {
|
|
1715
1765
|
try {
|
|
1716
|
-
const transaction =
|
|
1766
|
+
const transaction = import_web36.Transaction.from(tx.transaction);
|
|
1717
1767
|
transaction.sign(keypair);
|
|
1718
1768
|
return { ...tx, transaction: transaction.serialize(), signature: transaction.signature };
|
|
1719
1769
|
} catch {
|
|
@@ -1745,7 +1795,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1745
1795
|
async importFromMnemonic(mnemonic) {
|
|
1746
1796
|
const trimmedMnemonic = (0, import_warps9.normalizeAndValidateMnemonic)(mnemonic);
|
|
1747
1797
|
const seed = bip39.mnemonicToSeedSync(trimmedMnemonic);
|
|
1748
|
-
const keypair =
|
|
1798
|
+
const keypair = import_web36.Keypair.fromSeed(seed.slice(0, 32));
|
|
1749
1799
|
const walletDetails = {
|
|
1750
1800
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1751
1801
|
address: keypair.publicKey.toBase58(),
|
|
@@ -1756,7 +1806,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1756
1806
|
return walletDetails;
|
|
1757
1807
|
}
|
|
1758
1808
|
async importFromPrivateKey(privateKey) {
|
|
1759
|
-
const keypair =
|
|
1809
|
+
const keypair = import_web36.Keypair.fromSecretKey(import_bs582.default.decode(privateKey));
|
|
1760
1810
|
const walletDetails = {
|
|
1761
1811
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1762
1812
|
address: keypair.publicKey.toBase58(),
|
|
@@ -1782,7 +1832,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1782
1832
|
const mnemonic = (0, import_warps9.normalizeMnemonic)(mnemonicRaw);
|
|
1783
1833
|
(0, import_warps9.validateMnemonicLength)(mnemonic);
|
|
1784
1834
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1785
|
-
const keypair =
|
|
1835
|
+
const keypair = import_web36.Keypair.fromSeed(seed.slice(0, 32));
|
|
1786
1836
|
return {
|
|
1787
1837
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1788
1838
|
address: keypair.publicKey.toBase58(),
|
|
@@ -1795,7 +1845,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
1795
1845
|
const mnemonic = (0, import_warps9.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1796
1846
|
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
1797
1847
|
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1798
|
-
this.keypair =
|
|
1848
|
+
this.keypair = import_web36.Keypair.fromSeed(seed.slice(0, 32));
|
|
1799
1849
|
return this.keypair;
|
|
1800
1850
|
}
|
|
1801
1851
|
};
|
|
@@ -1803,7 +1853,7 @@ _MnemonicWalletProvider.PROVIDER_NAME = "mnemonic";
|
|
|
1803
1853
|
var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
1804
1854
|
|
|
1805
1855
|
// src/providers/PrivateKeyWalletProvider.ts
|
|
1806
|
-
var
|
|
1856
|
+
var import_web37 = require("@solana/web3.js");
|
|
1807
1857
|
var import_warps10 = require("@joai/warps");
|
|
1808
1858
|
var import_bs583 = __toESM(require("bs58"), 1);
|
|
1809
1859
|
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
@@ -1832,22 +1882,22 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1832
1882
|
}
|
|
1833
1883
|
async signTransaction(tx) {
|
|
1834
1884
|
const keypair = this.getKeypair();
|
|
1835
|
-
if (tx instanceof
|
|
1885
|
+
if (tx instanceof import_web37.VersionedTransaction) {
|
|
1836
1886
|
tx.sign([keypair]);
|
|
1837
1887
|
return tx;
|
|
1838
1888
|
}
|
|
1839
|
-
if (tx instanceof
|
|
1889
|
+
if (tx instanceof import_web37.Transaction) {
|
|
1840
1890
|
tx.sign(keypair);
|
|
1841
1891
|
return tx;
|
|
1842
1892
|
}
|
|
1843
1893
|
if (tx.transaction) {
|
|
1844
|
-
if (tx.transaction instanceof
|
|
1894
|
+
if (tx.transaction instanceof import_web37.Transaction) {
|
|
1845
1895
|
tx.transaction.sign(keypair);
|
|
1846
1896
|
return { ...tx, transaction: tx.transaction.serialize() };
|
|
1847
1897
|
}
|
|
1848
1898
|
if (typeof tx.transaction === "object") {
|
|
1849
1899
|
try {
|
|
1850
|
-
const transaction =
|
|
1900
|
+
const transaction = import_web37.Transaction.from(tx.transaction);
|
|
1851
1901
|
transaction.sign(keypair);
|
|
1852
1902
|
return { ...tx, transaction: transaction.serialize(), signature: transaction.signature };
|
|
1853
1903
|
} catch {
|
|
@@ -1880,7 +1930,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1880
1930
|
throw new Error("PrivateKeyWalletProvider does not support importing from mnemonics. Use MnemonicWalletProvider instead.");
|
|
1881
1931
|
}
|
|
1882
1932
|
async importFromPrivateKey(privateKey) {
|
|
1883
|
-
const keypair =
|
|
1933
|
+
const keypair = import_web37.Keypair.fromSecretKey(import_bs583.default.decode(privateKey));
|
|
1884
1934
|
const walletDetails = {
|
|
1885
1935
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1886
1936
|
address: keypair.publicKey.toBase58(),
|
|
@@ -1902,7 +1952,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1902
1952
|
};
|
|
1903
1953
|
}
|
|
1904
1954
|
async generate() {
|
|
1905
|
-
const keypair =
|
|
1955
|
+
const keypair = import_web37.Keypair.generate();
|
|
1906
1956
|
return {
|
|
1907
1957
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1908
1958
|
address: keypair.publicKey.toBase58(),
|
|
@@ -1917,10 +1967,10 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
1917
1967
|
try {
|
|
1918
1968
|
const secretKey = import_bs583.default.decode(privateKey);
|
|
1919
1969
|
if (secretKey.length === 64) {
|
|
1920
|
-
this.keypair =
|
|
1970
|
+
this.keypair = import_web37.Keypair.fromSecretKey(secretKey);
|
|
1921
1971
|
return this.keypair;
|
|
1922
1972
|
} else if (secretKey.length === 32) {
|
|
1923
|
-
this.keypair =
|
|
1973
|
+
this.keypair = import_web37.Keypair.fromSeed(secretKey);
|
|
1924
1974
|
return this.keypair;
|
|
1925
1975
|
} else {
|
|
1926
1976
|
throw new Error(`Invalid private key length: expected 32 or 64 bytes, got ${secretKey.length}`);
|
|
@@ -1983,7 +2033,7 @@ var WarpSolanaWallet = class {
|
|
|
1983
2033
|
this.cachedAddress = null;
|
|
1984
2034
|
this.cachedPublicKey = null;
|
|
1985
2035
|
const providerConfig = (0, import_warps12.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1986
|
-
this.connection = new
|
|
2036
|
+
this.connection = new import_web38.Connection(providerConfig.url, "confirmed");
|
|
1987
2037
|
this.walletProvider = this.createProvider();
|
|
1988
2038
|
this.initializeCache();
|
|
1989
2039
|
}
|
|
@@ -2084,29 +2134,51 @@ var WarpSolanaWallet = class {
|
|
|
2084
2134
|
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${provider}`);
|
|
2085
2135
|
}
|
|
2086
2136
|
resolveTransaction(tx) {
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
return tx;
|
|
2137
|
+
const directVersionedTransaction = this.asVersionedTransaction(tx);
|
|
2138
|
+
if (directVersionedTransaction) return directVersionedTransaction;
|
|
2139
|
+
if (tx instanceof import_web38.Transaction) {
|
|
2140
|
+
throw new Error("Legacy Transaction format is not supported. All transactions must use VersionedTransaction (v0).");
|
|
2092
2141
|
}
|
|
2093
|
-
|
|
2142
|
+
const nestedTransaction = tx.transaction;
|
|
2143
|
+
const nestedVersionedTransaction = this.asVersionedTransaction(nestedTransaction);
|
|
2144
|
+
if (nestedVersionedTransaction) return nestedVersionedTransaction;
|
|
2145
|
+
if (nestedTransaction instanceof import_web38.Transaction) {
|
|
2094
2146
|
throw new Error("Legacy Transaction format is not supported. All transactions must use VersionedTransaction (v0).");
|
|
2095
2147
|
}
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2148
|
+
const serializedTransaction = this.toSerializedTransactionBytes(nestedTransaction);
|
|
2149
|
+
if (serializedTransaction) {
|
|
2150
|
+
try {
|
|
2151
|
+
return this.asVersionedTransactionOrThrow(import_web38.VersionedTransaction.deserialize(serializedTransaction));
|
|
2152
|
+
} catch {
|
|
2153
|
+
throw new Error("Invalid serialized transaction format. Expected a VersionedTransaction payload.");
|
|
2099
2154
|
}
|
|
2100
|
-
return tx.transaction;
|
|
2101
|
-
}
|
|
2102
|
-
if (tx.transaction instanceof import_web37.Transaction) {
|
|
2103
|
-
throw new Error("Legacy Transaction format is not supported. All transactions must use VersionedTransaction (v0).");
|
|
2104
2155
|
}
|
|
2105
|
-
if (!
|
|
2156
|
+
if (!nestedTransaction) {
|
|
2106
2157
|
throw new Error("Transaction must be signed before sending");
|
|
2107
2158
|
}
|
|
2108
2159
|
throw new Error("Invalid transaction format - only VersionedTransaction is supported");
|
|
2109
2160
|
}
|
|
2161
|
+
asVersionedTransaction(tx) {
|
|
2162
|
+
if (!(tx instanceof import_web38.VersionedTransaction)) return null;
|
|
2163
|
+
return this.asVersionedTransactionOrThrow(tx);
|
|
2164
|
+
}
|
|
2165
|
+
asVersionedTransactionOrThrow(tx) {
|
|
2166
|
+
if (tx.version === void 0 || tx.version === "legacy") {
|
|
2167
|
+
throw new Error("Transaction must be a VersionedTransaction (v0), not legacy");
|
|
2168
|
+
}
|
|
2169
|
+
return tx;
|
|
2170
|
+
}
|
|
2171
|
+
toSerializedTransactionBytes(value) {
|
|
2172
|
+
if (value instanceof Uint8Array) return value;
|
|
2173
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(value)) return new Uint8Array(value);
|
|
2174
|
+
if (Array.isArray(value) && value.every((byte) => Number.isInteger(byte) && byte >= 0 && byte <= 255)) {
|
|
2175
|
+
return Uint8Array.from(value);
|
|
2176
|
+
}
|
|
2177
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
2178
|
+
return Uint8Array.from(Buffer.from(value.trim(), "base64"));
|
|
2179
|
+
}
|
|
2180
|
+
return null;
|
|
2181
|
+
}
|
|
2110
2182
|
async shouldSkipPreflight(transaction) {
|
|
2111
2183
|
if (!transaction.signatures || transaction.signatures.length === 0 || !transaction.signatures.some((sig) => sig.some((b) => b !== 0))) {
|
|
2112
2184
|
return false;
|