@vleap/warps-adapter-solana 0.1.0-beta.2 → 0.1.0-beta.4
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.js +51 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -101,10 +101,10 @@ var SolanaExplorerMap = {
|
|
|
101
101
|
var ExplorerUrls = {
|
|
102
102
|
["solscan" /* Solscan */]: "https://solscan.io",
|
|
103
103
|
["solscan_mainnet" /* SolscanMainnet */]: "https://solscan.io",
|
|
104
|
-
["solscan_devnet" /* SolscanDevnet */]: "https://solscan.io
|
|
104
|
+
["solscan_devnet" /* SolscanDevnet */]: "https://solscan.io",
|
|
105
105
|
["solana_explorer" /* SolanaExplorer */]: "https://explorer.solana.com",
|
|
106
106
|
["solana_explorer_mainnet" /* SolanaExplorerMainnet */]: "https://explorer.solana.com",
|
|
107
|
-
["solana_explorer_devnet" /* SolanaExplorerDevnet */]: "https://explorer.solana.com
|
|
107
|
+
["solana_explorer_devnet" /* SolanaExplorerDevnet */]: "https://explorer.solana.com"
|
|
108
108
|
};
|
|
109
109
|
var SolanaExplorerNames = {
|
|
110
110
|
mainnet: ["solscan_mainnet" /* SolscanMainnet */, "solana_explorer_mainnet" /* SolanaExplorerMainnet */],
|
|
@@ -376,9 +376,9 @@ var WarpSolanaDataLoader = class {
|
|
|
376
376
|
};
|
|
377
377
|
|
|
378
378
|
// src/WarpSolanaExecutor.ts
|
|
379
|
-
var import_warps5 = require("@vleap/warps");
|
|
380
|
-
var import_web34 = require("@solana/web3.js");
|
|
381
379
|
var import_spl_token2 = require("@solana/spl-token");
|
|
380
|
+
var import_web34 = require("@solana/web3.js");
|
|
381
|
+
var import_warps5 = require("@vleap/warps");
|
|
382
382
|
|
|
383
383
|
// src/WarpSolanaOutput.ts
|
|
384
384
|
var import_warps4 = require("@vleap/warps");
|
|
@@ -769,12 +769,12 @@ var WarpSolanaExecutor = class {
|
|
|
769
769
|
async createTransferTransaction(executable) {
|
|
770
770
|
const userWallet = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
771
771
|
if (!userWallet) throw new Error("WarpSolanaExecutor: createTransfer - user address not set");
|
|
772
|
+
if (!executable.destination) throw new Error("WarpSolanaExecutor: Destination address is required");
|
|
772
773
|
let destinationPubkey;
|
|
773
774
|
try {
|
|
774
|
-
if (!executable.destination) throw new Error("WarpSolanaExecutor: Destination address is required");
|
|
775
775
|
destinationPubkey = new import_web34.PublicKey(executable.destination);
|
|
776
|
-
} catch {
|
|
777
|
-
throw new Error(
|
|
776
|
+
} catch (error) {
|
|
777
|
+
throw new Error("WarpSolanaExecutor: Invalid destination address");
|
|
778
778
|
}
|
|
779
779
|
if (executable.transfers && executable.transfers.length > 0) {
|
|
780
780
|
return this.createTokenTransferTransaction(executable, userWallet, destinationPubkey);
|
|
@@ -782,13 +782,7 @@ var WarpSolanaExecutor = class {
|
|
|
782
782
|
const fromPubkey = new import_web34.PublicKey(userWallet);
|
|
783
783
|
const transaction = new import_web34.Transaction();
|
|
784
784
|
if (executable.value > 0n) {
|
|
785
|
-
transaction.add(
|
|
786
|
-
import_web34.SystemProgram.transfer({
|
|
787
|
-
fromPubkey,
|
|
788
|
-
toPubkey: destinationPubkey,
|
|
789
|
-
lamports: Number(executable.value)
|
|
790
|
-
})
|
|
791
|
-
);
|
|
785
|
+
transaction.add(import_web34.SystemProgram.transfer({ fromPubkey, toPubkey: destinationPubkey, lamports: Number(executable.value) }));
|
|
792
786
|
}
|
|
793
787
|
if (executable.data) {
|
|
794
788
|
const data = this.serializer.stringToTyped(executable.data);
|
|
@@ -812,13 +806,8 @@ var WarpSolanaExecutor = class {
|
|
|
812
806
|
if (!userWallet) throw new Error("WarpSolanaExecutor: createContractCall - user address not set");
|
|
813
807
|
const action = (0, import_warps5.getWarpActionByIndex)(executable.warp, executable.action);
|
|
814
808
|
if (!action || !("func" in action) || !action.func) throw new Error("WarpSolanaExecutor: Contract action must have a function name");
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (!executable.destination) throw new Error("WarpSolanaExecutor: Contract address is required");
|
|
818
|
-
programId = new import_web34.PublicKey(executable.destination);
|
|
819
|
-
} catch {
|
|
820
|
-
throw new Error(`WarpSolanaExecutor: Invalid contract address: ${executable.destination}`);
|
|
821
|
-
}
|
|
809
|
+
if (!executable.destination) throw new Error("WarpSolanaExecutor: Contract address is required");
|
|
810
|
+
const programId = new import_web34.PublicKey(executable.destination);
|
|
822
811
|
const fromPubkey = new import_web34.PublicKey(userWallet);
|
|
823
812
|
const transaction = new import_web34.Transaction();
|
|
824
813
|
try {
|
|
@@ -847,13 +836,7 @@ var WarpSolanaExecutor = class {
|
|
|
847
836
|
});
|
|
848
837
|
transaction.add(instruction);
|
|
849
838
|
if (executable.value > 0n) {
|
|
850
|
-
transaction.add(
|
|
851
|
-
import_web34.SystemProgram.transfer({
|
|
852
|
-
fromPubkey,
|
|
853
|
-
toPubkey: programId,
|
|
854
|
-
lamports: Number(executable.value)
|
|
855
|
-
})
|
|
856
|
-
);
|
|
839
|
+
transaction.add(import_web34.SystemProgram.transfer({ fromPubkey, toPubkey: programId, lamports: Number(executable.value) }));
|
|
857
840
|
}
|
|
858
841
|
return this.setTransactionDefaults(transaction, fromPubkey);
|
|
859
842
|
} catch (error) {
|
|
@@ -865,10 +848,10 @@ var WarpSolanaExecutor = class {
|
|
|
865
848
|
try {
|
|
866
849
|
const data = Buffer.alloc(8);
|
|
867
850
|
if (instructionDef.discriminator && Buffer.isBuffer(instructionDef.discriminator)) {
|
|
868
|
-
instructionDef.discriminator.
|
|
851
|
+
data.set(instructionDef.discriminator.subarray(0, Math.min(8, instructionDef.discriminator.length)), 0);
|
|
869
852
|
} else {
|
|
870
|
-
const hash = Buffer.from(funcName).
|
|
871
|
-
|
|
853
|
+
const hash = Buffer.from(funcName).subarray(0, 8);
|
|
854
|
+
data.set(hash, 0);
|
|
872
855
|
}
|
|
873
856
|
if (args.length > 0 && instructionDef.args) {
|
|
874
857
|
const encodedArgs = this.encodeArgs(args, instructionDef.args);
|
|
@@ -880,9 +863,9 @@ var WarpSolanaExecutor = class {
|
|
|
880
863
|
}
|
|
881
864
|
}
|
|
882
865
|
encodeBasicInstructionData(args, funcName) {
|
|
883
|
-
const funcHash = Buffer.from(funcName).
|
|
866
|
+
const funcHash = Buffer.from(funcName).subarray(0, 8);
|
|
884
867
|
const data = Buffer.alloc(8);
|
|
885
|
-
|
|
868
|
+
data.set(funcHash, 0);
|
|
886
869
|
if (args.length > 0) {
|
|
887
870
|
const encodedArgs = args.map((arg) => {
|
|
888
871
|
if (typeof arg === "string") {
|
|
@@ -913,7 +896,7 @@ var WarpSolanaExecutor = class {
|
|
|
913
896
|
const size = def.type === "u128" ? 16 : 8;
|
|
914
897
|
const buf = Buffer.alloc(size);
|
|
915
898
|
if (size === 16) {
|
|
916
|
-
buf.writeBigUInt64LE(num &
|
|
899
|
+
buf.writeBigUInt64LE(num & 0xffffffffffffffffn, 0);
|
|
917
900
|
buf.writeBigUInt64LE(num >> 64n, 8);
|
|
918
901
|
} else {
|
|
919
902
|
buf.writeBigUInt64LE(num, 0);
|
|
@@ -1003,23 +986,9 @@ var WarpSolanaExecutor = class {
|
|
|
1003
986
|
}
|
|
1004
987
|
const destinationAccountInfo = await this.connection.getAccountInfo(destinationTokenAccount);
|
|
1005
988
|
if (!destinationAccountInfo) {
|
|
1006
|
-
transaction.add(
|
|
1007
|
-
(0, import_spl_token2.createAssociatedTokenAccountInstruction)(
|
|
1008
|
-
fromPubkey,
|
|
1009
|
-
destinationTokenAccount,
|
|
1010
|
-
destinationPubkey,
|
|
1011
|
-
mintAddress
|
|
1012
|
-
)
|
|
1013
|
-
);
|
|
989
|
+
transaction.add((0, import_spl_token2.createAssociatedTokenAccountInstruction)(fromPubkey, destinationTokenAccount, destinationPubkey, mintAddress));
|
|
1014
990
|
}
|
|
1015
|
-
transaction.add(
|
|
1016
|
-
(0, import_spl_token2.createTransferInstruction)(
|
|
1017
|
-
sourceTokenAccount,
|
|
1018
|
-
destinationTokenAccount,
|
|
1019
|
-
fromPubkey,
|
|
1020
|
-
Number(transfer.amount)
|
|
1021
|
-
)
|
|
1022
|
-
);
|
|
991
|
+
transaction.add((0, import_spl_token2.createTransferInstruction)(sourceTokenAccount, destinationTokenAccount, fromPubkey, Number(transfer.amount)));
|
|
1023
992
|
return this.setTransactionDefaults(transaction, fromPubkey);
|
|
1024
993
|
}
|
|
1025
994
|
async executeQuery(executable) {
|
|
@@ -1076,9 +1045,7 @@ var WarpSolanaExecutor = class {
|
|
|
1076
1045
|
executable.resolvedInputs
|
|
1077
1046
|
);
|
|
1078
1047
|
const next = (0, import_warps5.getNextInfo)(this.config, [], executable.warp, executable.action, output);
|
|
1079
|
-
const destinationInput = executable.resolvedInputs.find(
|
|
1080
|
-
(i) => i.input.position === "receiver" || i.input.position === "destination"
|
|
1081
|
-
);
|
|
1048
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
1082
1049
|
const destination = destinationInput?.value || executable.destination;
|
|
1083
1050
|
const resolvedInputs = (0, import_warps5.extractResolvedInputValues)(executable.resolvedInputs);
|
|
1084
1051
|
return {
|
|
@@ -1097,9 +1064,7 @@ var WarpSolanaExecutor = class {
|
|
|
1097
1064
|
};
|
|
1098
1065
|
} catch (error) {
|
|
1099
1066
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1100
|
-
const destinationInput = executable.resolvedInputs.find(
|
|
1101
|
-
(i) => i.input.position === "receiver" || i.input.position === "destination"
|
|
1102
|
-
);
|
|
1067
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
1103
1068
|
const destination = destinationInput?.value || executable.destination;
|
|
1104
1069
|
const resolvedInputs = (0, import_warps5.extractResolvedInputValues)(executable.resolvedInputs);
|
|
1105
1070
|
return {
|
|
@@ -1135,12 +1100,8 @@ var WarpSolanaExecutor = class {
|
|
|
1135
1100
|
transaction.feePayer = fromPubkey;
|
|
1136
1101
|
}
|
|
1137
1102
|
const instructions = transaction.instructions;
|
|
1138
|
-
const hasTransfer = instructions.some(
|
|
1139
|
-
|
|
1140
|
-
);
|
|
1141
|
-
const hasTokenTransfer = instructions.some(
|
|
1142
|
-
(ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram
|
|
1143
|
-
);
|
|
1103
|
+
const hasTransfer = instructions.some((ix) => ix.programId.equals(import_web34.SystemProgram.programId) && ix.data.length === 4);
|
|
1104
|
+
const hasTokenTransfer = instructions.some((ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram);
|
|
1144
1105
|
let computeUnits = WarpSolanaConstants.ComputeUnitLimit.Default;
|
|
1145
1106
|
if (hasTransfer && !hasTokenTransfer) {
|
|
1146
1107
|
computeUnits = WarpSolanaConstants.ComputeUnitLimit.Transfer;
|
|
@@ -1149,16 +1110,13 @@ var WarpSolanaExecutor = class {
|
|
|
1149
1110
|
} else {
|
|
1150
1111
|
computeUnits = WarpSolanaConstants.ComputeUnitLimit.ContractCall;
|
|
1151
1112
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
microLamports: WarpSolanaConstants.PriorityFee.Default
|
|
1160
|
-
})
|
|
1161
|
-
);
|
|
1113
|
+
const computeUnitLimitIx = import_web34.ComputeBudgetProgram.setComputeUnitLimit({
|
|
1114
|
+
units: computeUnits
|
|
1115
|
+
});
|
|
1116
|
+
const computeUnitPriceIx = import_web34.ComputeBudgetProgram.setComputeUnitPrice({
|
|
1117
|
+
microLamports: WarpSolanaConstants.PriorityFee.Default
|
|
1118
|
+
});
|
|
1119
|
+
transaction.instructions = [computeUnitLimitIx, computeUnitPriceIx, ...transaction.instructions];
|
|
1162
1120
|
return transaction;
|
|
1163
1121
|
} catch (error) {
|
|
1164
1122
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1200,26 +1158,46 @@ var WarpSolanaExplorer = class {
|
|
|
1200
1158
|
}
|
|
1201
1159
|
getAccountUrl(address, explorer) {
|
|
1202
1160
|
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
1161
|
+
if (baseUrl.includes("?")) {
|
|
1162
|
+
const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
|
|
1163
|
+
return `${baseUrl}/account/${address}${cluster2}`;
|
|
1164
|
+
}
|
|
1203
1165
|
const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
|
|
1204
1166
|
return `${baseUrl}/account/${address}${cluster}`;
|
|
1205
1167
|
}
|
|
1206
1168
|
getTransactionUrl(hash, explorer) {
|
|
1207
1169
|
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
1170
|
+
if (baseUrl.includes("?")) {
|
|
1171
|
+
const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
|
|
1172
|
+
return `${baseUrl}/tx/${hash}${cluster2}`;
|
|
1173
|
+
}
|
|
1208
1174
|
const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
|
|
1209
1175
|
return `${baseUrl}/tx/${hash}${cluster}`;
|
|
1210
1176
|
}
|
|
1211
1177
|
getBlockUrl(blockNumber, explorer) {
|
|
1212
1178
|
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
1179
|
+
if (baseUrl.includes("?")) {
|
|
1180
|
+
const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
|
|
1181
|
+
return `${baseUrl}/block/${blockNumber}${cluster2}`;
|
|
1182
|
+
}
|
|
1213
1183
|
const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
|
|
1214
1184
|
return `${baseUrl}/block/${blockNumber}${cluster}`;
|
|
1215
1185
|
}
|
|
1216
1186
|
getAssetUrl(identifier, explorer) {
|
|
1217
1187
|
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
1188
|
+
if (baseUrl.includes("?")) {
|
|
1189
|
+
const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
|
|
1190
|
+
return `${baseUrl}/token/${identifier}${cluster2}`;
|
|
1191
|
+
}
|
|
1218
1192
|
const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
|
|
1219
1193
|
return `${baseUrl}/token/${identifier}${cluster}`;
|
|
1220
1194
|
}
|
|
1221
1195
|
getContractUrl(address, explorer) {
|
|
1222
1196
|
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
1197
|
+
if (baseUrl.includes("?")) {
|
|
1198
|
+
const cluster2 = this.config.env === "mainnet" ? "" : `&cluster=${this.config.env}`;
|
|
1199
|
+
return `${baseUrl}/account/${address}${cluster2}`;
|
|
1200
|
+
}
|
|
1223
1201
|
const cluster = this.config.env === "mainnet" ? "" : `?cluster=${this.config.env}`;
|
|
1224
1202
|
return `${baseUrl}/account/${address}${cluster}`;
|
|
1225
1203
|
}
|
|
@@ -1296,7 +1274,7 @@ var WarpSolanaExplorer = class {
|
|
|
1296
1274
|
var import_warps6 = require("@vleap/warps");
|
|
1297
1275
|
var import_web35 = require("@solana/web3.js");
|
|
1298
1276
|
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
1299
|
-
var import_english = require("@scure/bip39/wordlists/english");
|
|
1277
|
+
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
1300
1278
|
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1301
1279
|
var WarpSolanaWallet = class {
|
|
1302
1280
|
constructor(config, chain) {
|