@vleap/warps-adapter-evm 0.2.0-alpha.33 → 0.2.0-alpha.35
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 +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +133 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +138 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -381,7 +381,10 @@ var WarpEvmDataLoader = class {
|
|
|
381
381
|
try {
|
|
382
382
|
const tx = await this.provider.getTransaction(identifier);
|
|
383
383
|
if (!tx) return null;
|
|
384
|
-
|
|
384
|
+
let receipt = await this.provider.getTransactionReceipt(identifier);
|
|
385
|
+
if (awaitCompleted && !receipt) {
|
|
386
|
+
receipt = await tx.wait();
|
|
387
|
+
}
|
|
385
388
|
const block = await this.provider.getBlock(tx.blockNumber || "latest");
|
|
386
389
|
return {
|
|
387
390
|
chain: this.chain.name,
|
|
@@ -712,7 +715,51 @@ var WarpEvmResults = class {
|
|
|
712
715
|
const network = new ethers3.Network(this.chain.name, parseInt(this.chain.chainId));
|
|
713
716
|
this.provider = new ethers3.JsonRpcProvider(apiUrl, network);
|
|
714
717
|
}
|
|
715
|
-
async
|
|
718
|
+
async getActionExecution(warp, actionIndex, tx) {
|
|
719
|
+
if (!tx) {
|
|
720
|
+
return this.createFailedExecution(warp, actionIndex);
|
|
721
|
+
}
|
|
722
|
+
if ("status" in tx && typeof tx.status === "string") {
|
|
723
|
+
return this.handleWarpChainAction(warp, actionIndex, tx);
|
|
724
|
+
}
|
|
725
|
+
return this.handleTransactionReceipt(warp, actionIndex, tx);
|
|
726
|
+
}
|
|
727
|
+
createFailedExecution(warp, actionIndex) {
|
|
728
|
+
return {
|
|
729
|
+
success: false,
|
|
730
|
+
warp,
|
|
731
|
+
action: actionIndex,
|
|
732
|
+
user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
|
|
733
|
+
txHash: "",
|
|
734
|
+
tx: null,
|
|
735
|
+
next: null,
|
|
736
|
+
values: { string: [], native: [] },
|
|
737
|
+
results: {},
|
|
738
|
+
messages: {}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
handleWarpChainAction(warp, actionIndex, tx) {
|
|
742
|
+
const success = tx.status === "success";
|
|
743
|
+
const transactionHash = tx.id || tx.tx?.hash || "";
|
|
744
|
+
const gasUsed = tx.tx?.gasLimit || "0";
|
|
745
|
+
const gasPrice = tx.tx?.gasPrice || "0";
|
|
746
|
+
const blockNumber = tx.tx?.blockNumber || "0";
|
|
747
|
+
const rawValues = [transactionHash, blockNumber, gasUsed, gasPrice];
|
|
748
|
+
const stringValues = rawValues.map(String);
|
|
749
|
+
return {
|
|
750
|
+
success,
|
|
751
|
+
warp,
|
|
752
|
+
action: actionIndex,
|
|
753
|
+
user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
|
|
754
|
+
txHash: transactionHash,
|
|
755
|
+
tx,
|
|
756
|
+
next: null,
|
|
757
|
+
values: { string: stringValues, native: rawValues },
|
|
758
|
+
results: {},
|
|
759
|
+
messages: {}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
handleTransactionReceipt(warp, actionIndex, tx) {
|
|
716
763
|
const success = tx.status === 1;
|
|
717
764
|
const gasUsed = tx.gasUsed?.toString() || "0";
|
|
718
765
|
const gasPrice = tx.gasPrice?.toString() || "0";
|
|
@@ -727,12 +774,12 @@ var WarpEvmResults = class {
|
|
|
727
774
|
index: log.index?.toString() || "0"
|
|
728
775
|
}));
|
|
729
776
|
const rawValues = [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []];
|
|
730
|
-
const stringValues = rawValues.map(
|
|
777
|
+
const stringValues = rawValues.map(String);
|
|
731
778
|
return {
|
|
732
779
|
success,
|
|
733
780
|
warp,
|
|
734
|
-
action:
|
|
735
|
-
user: getWarpWalletAddressFromConfig(this.config,
|
|
781
|
+
action: actionIndex,
|
|
782
|
+
user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
|
|
736
783
|
txHash: transactionHash,
|
|
737
784
|
tx,
|
|
738
785
|
next: null,
|
|
@@ -842,15 +889,17 @@ var WarpEvmExecutor = class {
|
|
|
842
889
|
const userWallet = getWarpWalletAddressFromConfig2(this.config, executable.chain.name);
|
|
843
890
|
if (!userWallet) throw new Error("WarpEvmExecutor: createContractCall - user address not set");
|
|
844
891
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
845
|
-
if (!action || !("func" in action) || !action.func)
|
|
846
|
-
|
|
847
|
-
}
|
|
848
|
-
if (!ethers4.isAddress(executable.destination)) {
|
|
849
|
-
throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
|
|
850
|
-
}
|
|
892
|
+
if (!action || !("func" in action) || !action.func) throw new Error("WarpEvmExecutor: Contract action must have a function name");
|
|
893
|
+
if (!ethers4.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
|
|
851
894
|
try {
|
|
852
|
-
|
|
853
|
-
|
|
895
|
+
let iface;
|
|
896
|
+
try {
|
|
897
|
+
iface = new ethers4.Interface(JSON.parse(action.abi));
|
|
898
|
+
} catch {
|
|
899
|
+
iface = new ethers4.Interface([action.abi]);
|
|
900
|
+
}
|
|
901
|
+
const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
902
|
+
const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
|
|
854
903
|
const tx = {
|
|
855
904
|
to: executable.destination,
|
|
856
905
|
value: executable.value,
|
|
@@ -862,19 +911,13 @@ var WarpEvmExecutor = class {
|
|
|
862
911
|
}
|
|
863
912
|
}
|
|
864
913
|
async createTokenTransferTransaction(executable, userWallet) {
|
|
865
|
-
if (executable.transfers.length === 0)
|
|
866
|
-
|
|
867
|
-
}
|
|
868
|
-
if (!this.chain.nativeToken?.identifier) {
|
|
869
|
-
throw new Error("WarpEvmExecutor: No native token defined for this chain");
|
|
870
|
-
}
|
|
914
|
+
if (executable.transfers.length === 0) throw new Error("WarpEvmExecutor: No transfers provided");
|
|
915
|
+
if (!this.chain.nativeToken?.identifier) throw new Error("WarpEvmExecutor: No native token defined for this chain");
|
|
871
916
|
const nativeTokenTransfers = executable.transfers.filter((transfer) => transfer.identifier === this.chain.nativeToken.identifier);
|
|
872
917
|
const erc20Transfers = executable.transfers.filter((transfer) => transfer.identifier !== this.chain.nativeToken.identifier);
|
|
873
918
|
if (nativeTokenTransfers.length === 1 && erc20Transfers.length === 0) {
|
|
874
919
|
const transfer = nativeTokenTransfers[0];
|
|
875
|
-
if (transfer.amount <= 0n)
|
|
876
|
-
throw new Error("WarpEvmExecutor: Native token transfer amount must be positive");
|
|
877
|
-
}
|
|
920
|
+
if (transfer.amount <= 0n) throw new Error("WarpEvmExecutor: Native token transfer amount must be positive");
|
|
878
921
|
const tx = {
|
|
879
922
|
to: executable.destination,
|
|
880
923
|
value: transfer.amount,
|
|
@@ -885,9 +928,7 @@ var WarpEvmExecutor = class {
|
|
|
885
928
|
if (nativeTokenTransfers.length === 0 && erc20Transfers.length === 1) {
|
|
886
929
|
return this.createSingleTokenTransfer(executable, erc20Transfers[0], userWallet);
|
|
887
930
|
}
|
|
888
|
-
if (executable.transfers.length > 1)
|
|
889
|
-
throw new Error("WarpEvmExecutor: Multiple token transfers not yet supported");
|
|
890
|
-
}
|
|
931
|
+
if (executable.transfers.length > 1) throw new Error("WarpEvmExecutor: Multiple token transfers not yet supported");
|
|
891
932
|
throw new Error("WarpEvmExecutor: Invalid transfer configuration");
|
|
892
933
|
}
|
|
893
934
|
async createSingleTokenTransfer(executable, transfer, userWallet) {
|
|
@@ -898,27 +939,25 @@ var WarpEvmExecutor = class {
|
|
|
898
939
|
const encodedData = transferInterface.encodeFunctionData("transfer", [executable.destination, transfer.amount]);
|
|
899
940
|
const tx = {
|
|
900
941
|
to: transfer.identifier,
|
|
901
|
-
// Token contract address
|
|
902
942
|
value: 0n,
|
|
903
|
-
// No native token value for ERC-20 transfers
|
|
904
943
|
data: encodedData
|
|
905
944
|
};
|
|
906
945
|
return this.estimateGasAndSetDefaults(tx, userWallet);
|
|
907
946
|
}
|
|
908
947
|
async executeQuery(executable) {
|
|
909
948
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
910
|
-
if (action.type !== "query") {
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
if (!action.func) {
|
|
914
|
-
throw new Error("WarpEvmExecutor: Query action must have a function name");
|
|
915
|
-
}
|
|
916
|
-
if (!ethers4.isAddress(executable.destination)) {
|
|
917
|
-
throw new Error(`WarpEvmExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
918
|
-
}
|
|
949
|
+
if (action.type !== "query") throw new Error(`WarpEvmExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
950
|
+
if (!action.func) throw new Error("WarpEvmExecutor: Query action must have a function name");
|
|
951
|
+
if (!ethers4.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid address for query: ${executable.destination}`);
|
|
919
952
|
try {
|
|
920
|
-
|
|
921
|
-
|
|
953
|
+
let iface;
|
|
954
|
+
try {
|
|
955
|
+
iface = new ethers4.Interface(JSON.parse(action.abi));
|
|
956
|
+
} catch {
|
|
957
|
+
iface = new ethers4.Interface([action.abi]);
|
|
958
|
+
}
|
|
959
|
+
const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
960
|
+
const encodedData = iface.encodeFunctionData(action.func, nativeArgs);
|
|
922
961
|
const result = await this.provider.call({
|
|
923
962
|
to: executable.destination,
|
|
924
963
|
data: encodedData
|
|
@@ -965,12 +1004,8 @@ var WarpEvmExecutor = class {
|
|
|
965
1004
|
...tx,
|
|
966
1005
|
from
|
|
967
1006
|
});
|
|
968
|
-
if (gasEstimate < BigInt(WarpEvmConstants.Validation.MinGasLimit)) {
|
|
969
|
-
|
|
970
|
-
}
|
|
971
|
-
if (gasEstimate > BigInt(WarpEvmConstants.Validation.MaxGasLimit)) {
|
|
972
|
-
throw new Error(`Gas estimate too high: ${gasEstimate}`);
|
|
973
|
-
}
|
|
1007
|
+
if (gasEstimate < BigInt(WarpEvmConstants.Validation.MinGasLimit)) throw new Error(`Gas estimate too low: ${gasEstimate}`);
|
|
1008
|
+
if (gasEstimate > BigInt(WarpEvmConstants.Validation.MaxGasLimit)) throw new Error(`Gas estimate too high: ${gasEstimate}`);
|
|
974
1009
|
const feeData = await this.provider.getFeeData();
|
|
975
1010
|
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
|
976
1011
|
return {
|
|
@@ -1014,15 +1049,6 @@ var WarpEvmExecutor = class {
|
|
|
1014
1049
|
};
|
|
1015
1050
|
}
|
|
1016
1051
|
}
|
|
1017
|
-
async signMessage(message, privateKey) {
|
|
1018
|
-
try {
|
|
1019
|
-
const wallet = new ethers4.Wallet(privateKey);
|
|
1020
|
-
const signature = await wallet.signMessage(message);
|
|
1021
|
-
return signature;
|
|
1022
|
-
} catch (error) {
|
|
1023
|
-
throw new Error(`Failed to sign message: ${error}`);
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
1052
|
async verifyMessage(message, signature) {
|
|
1027
1053
|
try {
|
|
1028
1054
|
const recoveredAddress = ethers4.verifyMessage(message, signature);
|
|
@@ -1153,22 +1179,22 @@ var WarpEvmExplorer = class {
|
|
|
1153
1179
|
};
|
|
1154
1180
|
|
|
1155
1181
|
// src/WarpEvmWallet.ts
|
|
1156
|
-
import {
|
|
1182
|
+
import {
|
|
1183
|
+
getProviderUrl as getProviderUrl4,
|
|
1184
|
+
getWarpWalletMnemonicFromConfig,
|
|
1185
|
+
getWarpWalletPrivateKeyFromConfig
|
|
1186
|
+
} from "@vleap/warps";
|
|
1157
1187
|
import { ethers as ethers5 } from "ethers";
|
|
1158
1188
|
var WarpEvmWallet = class {
|
|
1159
1189
|
constructor(config, chain) {
|
|
1160
1190
|
this.config = config;
|
|
1161
1191
|
this.chain = chain;
|
|
1162
|
-
|
|
1163
|
-
this.provider = new ethers5.JsonRpcProvider(
|
|
1192
|
+
const apiUrl = getProviderUrl4(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1193
|
+
this.provider = new ethers5.JsonRpcProvider(apiUrl);
|
|
1164
1194
|
}
|
|
1165
1195
|
async signTransaction(tx) {
|
|
1166
|
-
if (!tx || typeof tx !== "object")
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
1170
|
-
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
1171
|
-
const wallet = new ethers5.Wallet(privateKey);
|
|
1196
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1197
|
+
const wallet = this.getWallet();
|
|
1172
1198
|
const txRequest = {
|
|
1173
1199
|
to: tx.to,
|
|
1174
1200
|
data: tx.data,
|
|
@@ -1182,25 +1208,53 @@ var WarpEvmWallet = class {
|
|
|
1182
1208
|
const signedTx = await wallet.signTransaction(txRequest);
|
|
1183
1209
|
return { ...tx, signature: signedTx };
|
|
1184
1210
|
}
|
|
1211
|
+
async signTransactions(txs) {
|
|
1212
|
+
if (txs.length === 0) return [];
|
|
1213
|
+
if (txs.length > 1) {
|
|
1214
|
+
const wallet = this.getWallet();
|
|
1215
|
+
const address = wallet.address;
|
|
1216
|
+
const currentNonce = await this.provider.getTransactionCount(address, "pending");
|
|
1217
|
+
const signedTxs = [];
|
|
1218
|
+
for (let i = 0; i < txs.length; i++) {
|
|
1219
|
+
const tx = { ...txs[i] };
|
|
1220
|
+
tx.nonce = currentNonce + i;
|
|
1221
|
+
if (i > 0) {
|
|
1222
|
+
const priorityReduction = BigInt(i * 1e9);
|
|
1223
|
+
const minGasPrice = BigInt(1e9);
|
|
1224
|
+
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
|
1225
|
+
tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
|
|
1226
|
+
tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
|
|
1227
|
+
delete tx.gasPrice;
|
|
1228
|
+
} else if (tx.gasPrice) {
|
|
1229
|
+
tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
|
|
1230
|
+
delete tx.maxFeePerGas;
|
|
1231
|
+
delete tx.maxPriorityFeePerGas;
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const signedTx = await this.signTransaction(tx);
|
|
1235
|
+
signedTxs.push(signedTx);
|
|
1236
|
+
}
|
|
1237
|
+
return signedTxs;
|
|
1238
|
+
}
|
|
1239
|
+
return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
|
|
1240
|
+
}
|
|
1185
1241
|
async signMessage(message) {
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
return await wallet.signMessage(message);
|
|
1242
|
+
const wallet = this.getWallet();
|
|
1243
|
+
const signature = await wallet.signMessage(message);
|
|
1244
|
+
return signature;
|
|
1190
1245
|
}
|
|
1191
1246
|
async sendTransaction(tx) {
|
|
1192
|
-
if (!tx || typeof tx !== "object")
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
if (!
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
1199
|
-
if (!privateKey) throw new Error("Wallet not initialized - no private key provided");
|
|
1200
|
-
const wallet = new ethers5.Wallet(privateKey).connect(this.provider);
|
|
1201
|
-
const txResponse = await wallet.sendTransaction(tx);
|
|
1247
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1248
|
+
if (!tx.signature) throw new Error("Transaction must be signed before sending");
|
|
1249
|
+
const wallet = this.getWallet();
|
|
1250
|
+
if (!wallet) throw new Error("Wallet not initialized - no private key provided");
|
|
1251
|
+
const connectedWallet = wallet.connect(this.provider);
|
|
1252
|
+
const txResponse = await connectedWallet.sendTransaction(tx);
|
|
1202
1253
|
return txResponse.hash;
|
|
1203
1254
|
}
|
|
1255
|
+
async sendTransactions(txs) {
|
|
1256
|
+
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1257
|
+
}
|
|
1204
1258
|
create(mnemonic) {
|
|
1205
1259
|
const wallet = ethers5.Wallet.fromPhrase(mnemonic);
|
|
1206
1260
|
return { address: wallet.address, privateKey: wallet.privateKey, mnemonic };
|
|
@@ -1210,11 +1264,16 @@ var WarpEvmWallet = class {
|
|
|
1210
1264
|
return { address: wallet.address, privateKey: wallet.privateKey, mnemonic: wallet.mnemonic?.phrase || "" };
|
|
1211
1265
|
}
|
|
1212
1266
|
getAddress() {
|
|
1213
|
-
const
|
|
1214
|
-
if (!privateKey) return null;
|
|
1215
|
-
const wallet = new ethers5.Wallet(privateKey);
|
|
1267
|
+
const wallet = this.getWallet();
|
|
1216
1268
|
return wallet.address;
|
|
1217
1269
|
}
|
|
1270
|
+
getWallet() {
|
|
1271
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
1272
|
+
if (privateKey) return new ethers5.Wallet(privateKey);
|
|
1273
|
+
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
1274
|
+
if (mnemonic) return ethers5.Wallet.fromPhrase(mnemonic);
|
|
1275
|
+
throw new Error("No private key or mnemonic provided");
|
|
1276
|
+
}
|
|
1218
1277
|
};
|
|
1219
1278
|
|
|
1220
1279
|
// src/chains/common.ts
|