@joai/warps-adapter-solana 1.0.0 → 1.0.1
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 +1 -6
- package/dist/index.d.ts +1 -6
- package/dist/index.js +46 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -122
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -106,6 +106,7 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
106
106
|
createTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
107
107
|
createTransferTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
108
108
|
createContractCallTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
109
|
+
private parseAbi;
|
|
109
110
|
private ensureATAs;
|
|
110
111
|
private encodeInstructionData;
|
|
111
112
|
private encodeBasicInstructionData;
|
|
@@ -117,7 +118,6 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
117
118
|
private createTokenTransferTransaction;
|
|
118
119
|
private createSingleTokenTransfer;
|
|
119
120
|
executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
|
|
120
|
-
verifyMessage(message: string, signature: string): Promise<string>;
|
|
121
121
|
private setTransactionDefaults;
|
|
122
122
|
private toPublicKey;
|
|
123
123
|
private extractContractArgs;
|
|
@@ -126,11 +126,6 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
126
126
|
private resolveAccountPubkey;
|
|
127
127
|
private determineAccountFlags;
|
|
128
128
|
private addComputeBudgetInstructions;
|
|
129
|
-
private buildAccountMetaMap;
|
|
130
|
-
private sortAccounts;
|
|
131
|
-
private buildAccountIndexMap;
|
|
132
|
-
private compileInstructions;
|
|
133
|
-
private buildMessageV0;
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
declare class WarpSolanaExplorer implements AdapterWarpExplorer {
|
package/dist/index.d.ts
CHANGED
|
@@ -106,6 +106,7 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
106
106
|
createTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
107
107
|
createTransferTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
108
108
|
createContractCallTransaction(executable: WarpExecutable): Promise<VersionedTransaction>;
|
|
109
|
+
private parseAbi;
|
|
109
110
|
private ensureATAs;
|
|
110
111
|
private encodeInstructionData;
|
|
111
112
|
private encodeBasicInstructionData;
|
|
@@ -117,7 +118,6 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
117
118
|
private createTokenTransferTransaction;
|
|
118
119
|
private createSingleTokenTransfer;
|
|
119
120
|
executeQuery(executable: WarpExecutable): Promise<WarpActionExecutionResult>;
|
|
120
|
-
verifyMessage(message: string, signature: string): Promise<string>;
|
|
121
121
|
private setTransactionDefaults;
|
|
122
122
|
private toPublicKey;
|
|
123
123
|
private extractContractArgs;
|
|
@@ -126,11 +126,6 @@ declare class WarpSolanaExecutor implements AdapterWarpExecutor {
|
|
|
126
126
|
private resolveAccountPubkey;
|
|
127
127
|
private determineAccountFlags;
|
|
128
128
|
private addComputeBudgetInstructions;
|
|
129
|
-
private buildAccountMetaMap;
|
|
130
|
-
private sortAccounts;
|
|
131
|
-
private buildAccountIndexMap;
|
|
132
|
-
private compileInstructions;
|
|
133
|
-
private buildMessageV0;
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
declare class WarpSolanaExplorer implements AdapterWarpExplorer {
|
package/dist/index.js
CHANGED
|
@@ -947,7 +947,7 @@ var WarpSolanaOutput = class {
|
|
|
947
947
|
output[key] = path;
|
|
948
948
|
}
|
|
949
949
|
}
|
|
950
|
-
return { values, output: await (0, import_warps7.evaluateOutputCommon)(warp, output, actionIndex, inputs, this.serializer.coreSerializer, this.config) };
|
|
950
|
+
return { values, output: await (0, import_warps7.evaluateOutputCommon)(warp, output, nativeValues, actionIndex, inputs, this.serializer.coreSerializer, this.config) };
|
|
951
951
|
}
|
|
952
952
|
async getTransactionStatus(txHash) {
|
|
953
953
|
try {
|
|
@@ -1057,19 +1057,29 @@ var WarpSolanaExecutor = class {
|
|
|
1057
1057
|
const argsToUse = this.extractContractArgs(executable);
|
|
1058
1058
|
const nativeArgs = argsToUse.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
1059
1059
|
const instructionData = this.buildInstructionData(action, nativeArgs);
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1060
|
+
const parsedAbi = this.parseAbi(action);
|
|
1061
|
+
const abiAccounts = parsedAbi?.instructions?.[action.func]?.accounts ?? null;
|
|
1062
|
+
const accounts = await this.buildInstructionAccounts(action, executable, fromPubkey, programId, abiAccounts);
|
|
1063
|
+
await this.ensureATAs(abiAccounts, accounts, fromPubkey, instructions);
|
|
1062
1064
|
instructions.push(new import_web34.TransactionInstruction({ keys: accounts, programId, data: instructionData }));
|
|
1063
1065
|
if (executable.value > 0n) {
|
|
1064
1066
|
instructions.push(import_web34.SystemProgram.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
|
|
1065
1067
|
}
|
|
1066
1068
|
return this.setTransactionDefaults(instructions, fromPubkey);
|
|
1067
1069
|
}
|
|
1068
|
-
|
|
1069
|
-
if (!action.
|
|
1070
|
+
parseAbi(action) {
|
|
1071
|
+
if (!action.abi || typeof action.abi !== "string") return null;
|
|
1072
|
+
try {
|
|
1073
|
+
return JSON.parse(action.abi);
|
|
1074
|
+
} catch {
|
|
1075
|
+
return null;
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
async ensureATAs(abiAccounts, accounts, fromPubkey, instructions) {
|
|
1079
|
+
if (!abiAccounts || !Array.isArray(abiAccounts)) return;
|
|
1070
1080
|
const createdATAs = /* @__PURE__ */ new Set();
|
|
1071
|
-
for (let idx = 0; idx <
|
|
1072
|
-
const accountDef =
|
|
1081
|
+
for (let idx = 0; idx < abiAccounts.length; idx++) {
|
|
1082
|
+
const accountDef = abiAccounts[idx];
|
|
1073
1083
|
const accountStr = typeof accountDef === "string" ? accountDef : JSON.stringify(accountDef);
|
|
1074
1084
|
if (accountStr.includes("{{USER_ATA:")) {
|
|
1075
1085
|
const match = accountStr.match(/USER_ATA[:\s]*([^"}\s]+)/);
|
|
@@ -1193,7 +1203,7 @@ var WarpSolanaExecutor = class {
|
|
|
1193
1203
|
}
|
|
1194
1204
|
return Buffer.concat(buffers);
|
|
1195
1205
|
}
|
|
1196
|
-
async buildInstructionAccounts(action, executable, fromPubkey, programId) {
|
|
1206
|
+
async buildInstructionAccounts(action, executable, fromPubkey, programId, abiAccounts) {
|
|
1197
1207
|
const accounts = [];
|
|
1198
1208
|
const accountInputs = this.extractAccountInputs(action, executable);
|
|
1199
1209
|
if (accountInputs.length > 0) {
|
|
@@ -1207,13 +1217,11 @@ var WarpSolanaExecutor = class {
|
|
|
1207
1217
|
}
|
|
1208
1218
|
return accounts;
|
|
1209
1219
|
}
|
|
1210
|
-
if (!
|
|
1211
|
-
for (let idx = 0; idx <
|
|
1212
|
-
const accountDef =
|
|
1220
|
+
if (!abiAccounts || !Array.isArray(abiAccounts)) return accounts;
|
|
1221
|
+
for (let idx = 0; idx < abiAccounts.length; idx++) {
|
|
1222
|
+
const accountDef = abiAccounts[idx];
|
|
1213
1223
|
let address = this.extractAccountAddress(accountDef);
|
|
1214
|
-
if (address
|
|
1215
|
-
address = fromPubkey.toBase58();
|
|
1216
|
-
} else if (!address || address.length === 0) {
|
|
1224
|
+
if (!address || address.length === 0) {
|
|
1217
1225
|
throw new Error(`Invalid account definition at index ${idx}: ${JSON.stringify(accountDef)}`);
|
|
1218
1226
|
}
|
|
1219
1227
|
if (address === "{{USER_WALLET}}" || typeof address === "string" && address.includes("{{USER_WALLET}}")) {
|
|
@@ -1295,6 +1303,22 @@ var WarpSolanaExecutor = class {
|
|
|
1295
1303
|
}
|
|
1296
1304
|
}
|
|
1297
1305
|
}
|
|
1306
|
+
if (address.includes("{{USER_ATA:") || address.includes("{{RECEIVER_ATA:")) {
|
|
1307
|
+
for (const resolved of resolvedInputs) {
|
|
1308
|
+
if (!resolved.input?.as) continue;
|
|
1309
|
+
const key = resolved.input.as.toUpperCase();
|
|
1310
|
+
if (address.includes(key)) {
|
|
1311
|
+
let value = resolved.value;
|
|
1312
|
+
if (typeof value === "string" && value.includes(":")) {
|
|
1313
|
+
value = value.split(":")[1];
|
|
1314
|
+
}
|
|
1315
|
+
if (value) {
|
|
1316
|
+
address = address.replace(new RegExp(key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "g"), String(value));
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return address;
|
|
1321
|
+
}
|
|
1298
1322
|
return address;
|
|
1299
1323
|
}
|
|
1300
1324
|
async createTokenTransferTransaction(executable, userWallet, destinationPubkey) {
|
|
@@ -1391,28 +1415,15 @@ var WarpSolanaExecutor = class {
|
|
|
1391
1415
|
resolvedInputs
|
|
1392
1416
|
};
|
|
1393
1417
|
}
|
|
1394
|
-
async verifyMessage(message, signature) {
|
|
1395
|
-
try {
|
|
1396
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
1397
|
-
const signatureBytes = Buffer.from(signature, "base64");
|
|
1398
|
-
return "";
|
|
1399
|
-
} catch (error) {
|
|
1400
|
-
throw new Error(`Failed to verify message: ${error}`);
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
1418
|
async setTransactionDefaults(instructions, fromPubkey) {
|
|
1404
1419
|
const { blockhash } = await this.connection.getLatestBlockhash("confirmed");
|
|
1405
1420
|
const allInstructions = this.addComputeBudgetInstructions(instructions);
|
|
1406
|
-
const
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
if (versionedTx.version !== 0) {
|
|
1413
|
-
throw new Error(`Expected VersionedTransaction v0, got version: ${versionedTx.version}`);
|
|
1414
|
-
}
|
|
1415
|
-
return versionedTx;
|
|
1421
|
+
const messageV0 = import_web34.MessageV0.compile({
|
|
1422
|
+
payerKey: fromPubkey,
|
|
1423
|
+
instructions: allInstructions,
|
|
1424
|
+
recentBlockhash: blockhash
|
|
1425
|
+
});
|
|
1426
|
+
return new import_web34.VersionedTransaction(messageV0);
|
|
1416
1427
|
}
|
|
1417
1428
|
toPublicKey(address, errorMsg) {
|
|
1418
1429
|
try {
|
|
@@ -1452,20 +1463,8 @@ var WarpSolanaExecutor = class {
|
|
|
1452
1463
|
extractAccountAddress(accountDef) {
|
|
1453
1464
|
if (typeof accountDef === "string") return accountDef;
|
|
1454
1465
|
if (!accountDef || typeof accountDef !== "object") return void 0;
|
|
1455
|
-
const
|
|
1456
|
-
if (
|
|
1457
|
-
if (str.includes("RECEIVER_ADDRESS") || str.includes("{{RECEIVER_ADDRESS}}")) return "{{RECEIVER_ADDRESS}}";
|
|
1458
|
-
if (str.includes("USER_ATA")) {
|
|
1459
|
-
const match = str.match(/USER_ATA[:\s]*([^"}\s]+)/);
|
|
1460
|
-
if (match) return `{{USER_ATA:${match[1]}}}`;
|
|
1461
|
-
}
|
|
1462
|
-
const addrValue = accountDef.address || accountDef.pubkey || accountDef.value;
|
|
1463
|
-
if (typeof addrValue === "string") return addrValue;
|
|
1464
|
-
if (addrValue?.toBase58) return addrValue.toBase58();
|
|
1465
|
-
if (addrValue?.identifier) return addrValue.identifier;
|
|
1466
|
-
if (addrValue?.value) return addrValue.value;
|
|
1467
|
-
const keys = Object.keys(accountDef);
|
|
1468
|
-
if (keys.length === 1 && typeof accountDef[keys[0]] === "string") return accountDef[keys[0]];
|
|
1466
|
+
const address = accountDef.address || accountDef.pubkey;
|
|
1467
|
+
if (typeof address === "string") return address;
|
|
1469
1468
|
return void 0;
|
|
1470
1469
|
}
|
|
1471
1470
|
async resolveAccountPubkey(address, fromPubkey) {
|
|
@@ -1514,81 +1513,6 @@ var WarpSolanaExecutor = class {
|
|
|
1514
1513
|
const computeUnitPriceIx = import_web34.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: WarpSolanaConstants.PriorityFee.Default });
|
|
1515
1514
|
return [computeUnitLimitIx, computeUnitPriceIx, ...instructions];
|
|
1516
1515
|
}
|
|
1517
|
-
buildAccountMetaMap(instructions, fromPubkey) {
|
|
1518
|
-
const accountMetaMap = /* @__PURE__ */ new Map();
|
|
1519
|
-
if (fromPubkey) {
|
|
1520
|
-
accountMetaMap.set(fromPubkey.toBase58(), { pubkey: fromPubkey, isSigner: true, isWritable: true });
|
|
1521
|
-
}
|
|
1522
|
-
for (const ix of instructions) {
|
|
1523
|
-
const programIdStr = ix.programId.toBase58();
|
|
1524
|
-
if (!accountMetaMap.has(programIdStr)) {
|
|
1525
|
-
accountMetaMap.set(programIdStr, { pubkey: ix.programId, isSigner: false, isWritable: false });
|
|
1526
|
-
}
|
|
1527
|
-
for (const key of ix.keys) {
|
|
1528
|
-
const keyStr = key.pubkey.toBase58();
|
|
1529
|
-
const existing = accountMetaMap.get(keyStr);
|
|
1530
|
-
if (existing) {
|
|
1531
|
-
accountMetaMap.set(keyStr, {
|
|
1532
|
-
pubkey: key.pubkey,
|
|
1533
|
-
isSigner: existing.isSigner || key.isSigner,
|
|
1534
|
-
isWritable: existing.isWritable || key.isWritable
|
|
1535
|
-
});
|
|
1536
|
-
} else {
|
|
1537
|
-
accountMetaMap.set(keyStr, {
|
|
1538
|
-
pubkey: key.pubkey,
|
|
1539
|
-
isSigner: key.isSigner,
|
|
1540
|
-
isWritable: key.isWritable
|
|
1541
|
-
});
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
return accountMetaMap;
|
|
1546
|
-
}
|
|
1547
|
-
sortAccounts(accountMetaMap) {
|
|
1548
|
-
const signedAccounts = [];
|
|
1549
|
-
const unsignedAccounts = [];
|
|
1550
|
-
for (const meta of accountMetaMap.values()) {
|
|
1551
|
-
;
|
|
1552
|
-
(meta.isSigner ? signedAccounts : unsignedAccounts).push(meta.pubkey);
|
|
1553
|
-
}
|
|
1554
|
-
const sortByWritable = (a, b) => (accountMetaMap.get(a.toBase58()).isWritable ? 0 : 1) - (accountMetaMap.get(b.toBase58()).isWritable ? 0 : 1);
|
|
1555
|
-
signedAccounts.sort(sortByWritable);
|
|
1556
|
-
unsignedAccounts.sort(sortByWritable);
|
|
1557
|
-
return { signedAccounts, unsignedAccounts };
|
|
1558
|
-
}
|
|
1559
|
-
buildAccountIndexMap(signedAccounts, unsignedAccounts) {
|
|
1560
|
-
const staticAccountKeys = [...signedAccounts, ...unsignedAccounts];
|
|
1561
|
-
const accountIndexMap = /* @__PURE__ */ new Map();
|
|
1562
|
-
staticAccountKeys.forEach((key, index) => {
|
|
1563
|
-
accountIndexMap.set(key.toBase58(), index);
|
|
1564
|
-
});
|
|
1565
|
-
return { staticAccountKeys, accountIndexMap };
|
|
1566
|
-
}
|
|
1567
|
-
compileInstructions(instructions, accountIndexMap) {
|
|
1568
|
-
return instructions.map((ix) => {
|
|
1569
|
-
const programIdIndex = accountIndexMap.get(ix.programId.toBase58());
|
|
1570
|
-
const accountKeyIndexes = ix.keys.map((key) => accountIndexMap.get(key.pubkey.toBase58()));
|
|
1571
|
-
return {
|
|
1572
|
-
programIdIndex,
|
|
1573
|
-
accountKeyIndexes,
|
|
1574
|
-
data: Uint8Array.from(ix.data)
|
|
1575
|
-
};
|
|
1576
|
-
});
|
|
1577
|
-
}
|
|
1578
|
-
buildMessageV0(blockhash, signedAccounts, unsignedAccounts, accountMetaMap, staticAccountKeys, compiledInstructions) {
|
|
1579
|
-
const getWritable = (key) => accountMetaMap.get(key.toBase58()).isWritable;
|
|
1580
|
-
return new import_web34.MessageV0({
|
|
1581
|
-
header: {
|
|
1582
|
-
numRequiredSignatures: signedAccounts.length,
|
|
1583
|
-
numReadonlySignedAccounts: signedAccounts.filter((k) => !getWritable(k)).length,
|
|
1584
|
-
numReadonlyUnsignedAccounts: unsignedAccounts.filter((k) => !getWritable(k)).length
|
|
1585
|
-
},
|
|
1586
|
-
staticAccountKeys,
|
|
1587
|
-
recentBlockhash: blockhash,
|
|
1588
|
-
compiledInstructions,
|
|
1589
|
-
addressTableLookups: []
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
1516
|
};
|
|
1593
1517
|
|
|
1594
1518
|
// src/WarpSolanaExplorer.ts
|