@vleap/warps-adapter-solana 0.1.0-beta.1 → 0.1.0-beta.3
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 +69 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// src/chains/solana.ts
|
|
2
|
+
import { WarpChainName as WarpChainName2 } from "@vleap/warps";
|
|
3
|
+
|
|
1
4
|
// src/WarpSolanaDataLoader.ts
|
|
2
5
|
import {
|
|
3
6
|
CacheTtl,
|
|
@@ -64,7 +67,8 @@ var SolanaExplorerNames = {
|
|
|
64
67
|
var SolanaExplorerUrls = ExplorerUrls;
|
|
65
68
|
|
|
66
69
|
// src/tokens/solana.ts
|
|
67
|
-
|
|
70
|
+
import { WarpChainName } from "@vleap/warps";
|
|
71
|
+
var SolanaChain = WarpChainName.Solana;
|
|
68
72
|
var SolanaTokens = [
|
|
69
73
|
{
|
|
70
74
|
chain: SolanaChain,
|
|
@@ -325,6 +329,8 @@ var WarpSolanaDataLoader = class {
|
|
|
325
329
|
};
|
|
326
330
|
|
|
327
331
|
// src/WarpSolanaExecutor.ts
|
|
332
|
+
import { createAssociatedTokenAccountInstruction, createTransferInstruction, getAssociatedTokenAddress } from "@solana/spl-token";
|
|
333
|
+
import { ComputeBudgetProgram, Connection as Connection3, PublicKey as PublicKey3, SystemProgram, Transaction, TransactionInstruction } from "@solana/web3.js";
|
|
328
334
|
import {
|
|
329
335
|
applyOutputToMessages,
|
|
330
336
|
extractResolvedInputValues as extractResolvedInputValues2,
|
|
@@ -333,8 +339,6 @@ import {
|
|
|
333
339
|
getWarpActionByIndex,
|
|
334
340
|
getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig2
|
|
335
341
|
} from "@vleap/warps";
|
|
336
|
-
import { Connection as Connection3, PublicKey as PublicKey3, SystemProgram, Transaction, TransactionInstruction, ComputeBudgetProgram } from "@solana/web3.js";
|
|
337
|
-
import { createTransferInstruction, getAssociatedTokenAddress, createAssociatedTokenAccountInstruction } from "@solana/spl-token";
|
|
338
342
|
|
|
339
343
|
// src/WarpSolanaOutput.ts
|
|
340
344
|
import {
|
|
@@ -833,14 +837,14 @@ var WarpSolanaExecutor = class {
|
|
|
833
837
|
try {
|
|
834
838
|
const data = Buffer.alloc(8);
|
|
835
839
|
if (instructionDef.discriminator && Buffer.isBuffer(instructionDef.discriminator)) {
|
|
836
|
-
instructionDef.discriminator.
|
|
840
|
+
data.set(instructionDef.discriminator.subarray(0, Math.min(8, instructionDef.discriminator.length)), 0);
|
|
837
841
|
} else {
|
|
838
|
-
const hash = Buffer.from(funcName).
|
|
839
|
-
|
|
842
|
+
const hash = Buffer.from(funcName).subarray(0, 8);
|
|
843
|
+
data.set(hash, 0);
|
|
840
844
|
}
|
|
841
845
|
if (args.length > 0 && instructionDef.args) {
|
|
842
846
|
const encodedArgs = this.encodeArgs(args, instructionDef.args);
|
|
843
|
-
return Buffer.
|
|
847
|
+
return Buffer.from([...data, ...encodedArgs]);
|
|
844
848
|
}
|
|
845
849
|
return data;
|
|
846
850
|
} catch {
|
|
@@ -848,9 +852,9 @@ var WarpSolanaExecutor = class {
|
|
|
848
852
|
}
|
|
849
853
|
}
|
|
850
854
|
encodeBasicInstructionData(args, funcName) {
|
|
851
|
-
const funcHash = Buffer.from(funcName).
|
|
855
|
+
const funcHash = Buffer.from(funcName).subarray(0, 8);
|
|
852
856
|
const data = Buffer.alloc(8);
|
|
853
|
-
|
|
857
|
+
data.set(funcHash, 0);
|
|
854
858
|
if (args.length > 0) {
|
|
855
859
|
const encodedArgs = args.map((arg) => {
|
|
856
860
|
if (typeof arg === "string") {
|
|
@@ -867,7 +871,7 @@ var WarpSolanaExecutor = class {
|
|
|
867
871
|
}
|
|
868
872
|
return Buffer.from(String(arg), "utf8");
|
|
869
873
|
});
|
|
870
|
-
return Buffer.
|
|
874
|
+
return Buffer.from([...data, ...encodedArgs]);
|
|
871
875
|
}
|
|
872
876
|
return data;
|
|
873
877
|
}
|
|
@@ -881,7 +885,7 @@ var WarpSolanaExecutor = class {
|
|
|
881
885
|
const size = def.type === "u128" ? 16 : 8;
|
|
882
886
|
const buf = Buffer.alloc(size);
|
|
883
887
|
if (size === 16) {
|
|
884
|
-
buf.writeBigUInt64LE(num &
|
|
888
|
+
buf.writeBigUInt64LE(num & 0xffffffffffffffffn, 0);
|
|
885
889
|
buf.writeBigUInt64LE(num >> 64n, 8);
|
|
886
890
|
} else {
|
|
887
891
|
buf.writeBigUInt64LE(num, 0);
|
|
@@ -900,7 +904,7 @@ var WarpSolanaExecutor = class {
|
|
|
900
904
|
buffers.push(Buffer.from(String(arg), "utf8"));
|
|
901
905
|
}
|
|
902
906
|
}
|
|
903
|
-
return Buffer.
|
|
907
|
+
return Buffer.from(buffers.flatMap((buf) => Array.from(buf)));
|
|
904
908
|
}
|
|
905
909
|
buildInstructionAccounts(action, executable, fromPubkey, programId) {
|
|
906
910
|
const accounts = [
|
|
@@ -971,23 +975,9 @@ var WarpSolanaExecutor = class {
|
|
|
971
975
|
}
|
|
972
976
|
const destinationAccountInfo = await this.connection.getAccountInfo(destinationTokenAccount);
|
|
973
977
|
if (!destinationAccountInfo) {
|
|
974
|
-
transaction.add(
|
|
975
|
-
createAssociatedTokenAccountInstruction(
|
|
976
|
-
fromPubkey,
|
|
977
|
-
destinationTokenAccount,
|
|
978
|
-
destinationPubkey,
|
|
979
|
-
mintAddress
|
|
980
|
-
)
|
|
981
|
-
);
|
|
978
|
+
transaction.add(createAssociatedTokenAccountInstruction(fromPubkey, destinationTokenAccount, destinationPubkey, mintAddress));
|
|
982
979
|
}
|
|
983
|
-
transaction.add(
|
|
984
|
-
createTransferInstruction(
|
|
985
|
-
sourceTokenAccount,
|
|
986
|
-
destinationTokenAccount,
|
|
987
|
-
fromPubkey,
|
|
988
|
-
Number(transfer.amount)
|
|
989
|
-
)
|
|
990
|
-
);
|
|
980
|
+
transaction.add(createTransferInstruction(sourceTokenAccount, destinationTokenAccount, fromPubkey, Number(transfer.amount)));
|
|
991
981
|
return this.setTransactionDefaults(transaction, fromPubkey);
|
|
992
982
|
}
|
|
993
983
|
async executeQuery(executable) {
|
|
@@ -1044,9 +1034,7 @@ var WarpSolanaExecutor = class {
|
|
|
1044
1034
|
executable.resolvedInputs
|
|
1045
1035
|
);
|
|
1046
1036
|
const next = getNextInfo(this.config, [], executable.warp, executable.action, output);
|
|
1047
|
-
const destinationInput = executable.resolvedInputs.find(
|
|
1048
|
-
(i) => i.input.position === "receiver" || i.input.position === "destination"
|
|
1049
|
-
);
|
|
1037
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
1050
1038
|
const destination = destinationInput?.value || executable.destination;
|
|
1051
1039
|
const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
|
|
1052
1040
|
return {
|
|
@@ -1065,9 +1053,7 @@ var WarpSolanaExecutor = class {
|
|
|
1065
1053
|
};
|
|
1066
1054
|
} catch (error) {
|
|
1067
1055
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1068
|
-
const destinationInput = executable.resolvedInputs.find(
|
|
1069
|
-
(i) => i.input.position === "receiver" || i.input.position === "destination"
|
|
1070
|
-
);
|
|
1056
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
1071
1057
|
const destination = destinationInput?.value || executable.destination;
|
|
1072
1058
|
const resolvedInputs = extractResolvedInputValues2(executable.resolvedInputs);
|
|
1073
1059
|
return {
|
|
@@ -1103,12 +1089,8 @@ var WarpSolanaExecutor = class {
|
|
|
1103
1089
|
transaction.feePayer = fromPubkey;
|
|
1104
1090
|
}
|
|
1105
1091
|
const instructions = transaction.instructions;
|
|
1106
|
-
const hasTransfer = instructions.some(
|
|
1107
|
-
|
|
1108
|
-
);
|
|
1109
|
-
const hasTokenTransfer = instructions.some(
|
|
1110
|
-
(ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram
|
|
1111
|
-
);
|
|
1092
|
+
const hasTransfer = instructions.some((ix) => ix.programId.equals(SystemProgram.programId) && ix.data.length === 4);
|
|
1093
|
+
const hasTokenTransfer = instructions.some((ix) => ix.programId.toBase58() === WarpSolanaConstants.Programs.TokenProgram);
|
|
1112
1094
|
let computeUnits = WarpSolanaConstants.ComputeUnitLimit.Default;
|
|
1113
1095
|
if (hasTransfer && !hasTokenTransfer) {
|
|
1114
1096
|
computeUnits = WarpSolanaConstants.ComputeUnitLimit.Transfer;
|
|
@@ -1463,16 +1445,16 @@ var createSolanaAdapter = (chainName, chainInfos) => {
|
|
|
1463
1445
|
|
|
1464
1446
|
// src/chains/solana.ts
|
|
1465
1447
|
var NativeTokenSol = {
|
|
1466
|
-
chain:
|
|
1448
|
+
chain: WarpChainName2.Solana,
|
|
1467
1449
|
identifier: "SOL",
|
|
1468
1450
|
symbol: "SOL",
|
|
1469
1451
|
name: "Solana",
|
|
1470
1452
|
decimals: 9,
|
|
1471
1453
|
logoUrl: "https://vleap.ai/images/tokens/sol.svg"
|
|
1472
1454
|
};
|
|
1473
|
-
var getSolanaAdapter = createSolanaAdapter(
|
|
1455
|
+
var getSolanaAdapter = createSolanaAdapter(WarpChainName2.Solana, {
|
|
1474
1456
|
mainnet: {
|
|
1475
|
-
name:
|
|
1457
|
+
name: WarpChainName2.Solana,
|
|
1476
1458
|
displayName: "Solana Mainnet",
|
|
1477
1459
|
chainId: "101",
|
|
1478
1460
|
blockTime: 400,
|
|
@@ -1482,7 +1464,7 @@ var getSolanaAdapter = createSolanaAdapter("solana", {
|
|
|
1482
1464
|
nativeToken: NativeTokenSol
|
|
1483
1465
|
},
|
|
1484
1466
|
testnet: {
|
|
1485
|
-
name:
|
|
1467
|
+
name: WarpChainName2.Solana,
|
|
1486
1468
|
displayName: "Solana Testnet",
|
|
1487
1469
|
chainId: "103",
|
|
1488
1470
|
blockTime: 400,
|
|
@@ -1492,7 +1474,7 @@ var getSolanaAdapter = createSolanaAdapter("solana", {
|
|
|
1492
1474
|
nativeToken: NativeTokenSol
|
|
1493
1475
|
},
|
|
1494
1476
|
devnet: {
|
|
1495
|
-
name:
|
|
1477
|
+
name: WarpChainName2.Solana,
|
|
1496
1478
|
displayName: "Solana Devnet",
|
|
1497
1479
|
chainId: "103",
|
|
1498
1480
|
blockTime: 400,
|