@vleap/warps-adapter-evm 0.2.0-alpha.34 → 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 +10 -6
- package/dist/index.d.ts +10 -6
- package/dist/index.js +109 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -64
- 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,21 +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) {
|
|
716
719
|
if (!tx) {
|
|
717
|
-
return
|
|
718
|
-
success: false,
|
|
719
|
-
warp,
|
|
720
|
-
action: 0,
|
|
721
|
-
user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
|
|
722
|
-
txHash: "",
|
|
723
|
-
tx: null,
|
|
724
|
-
next: null,
|
|
725
|
-
values: { string: [], native: [] },
|
|
726
|
-
results: {},
|
|
727
|
-
messages: {}
|
|
728
|
-
};
|
|
720
|
+
return this.createFailedExecution(warp, actionIndex);
|
|
729
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) {
|
|
730
763
|
const success = tx.status === 1;
|
|
731
764
|
const gasUsed = tx.gasUsed?.toString() || "0";
|
|
732
765
|
const gasPrice = tx.gasPrice?.toString() || "0";
|
|
@@ -741,11 +774,11 @@ var WarpEvmResults = class {
|
|
|
741
774
|
index: log.index?.toString() || "0"
|
|
742
775
|
}));
|
|
743
776
|
const rawValues = [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []];
|
|
744
|
-
const stringValues = rawValues.map(
|
|
777
|
+
const stringValues = rawValues.map(String);
|
|
745
778
|
return {
|
|
746
779
|
success,
|
|
747
780
|
warp,
|
|
748
|
-
action:
|
|
781
|
+
action: actionIndex,
|
|
749
782
|
user: getWarpWalletAddressFromConfig(this.config, this.chain.name),
|
|
750
783
|
txHash: transactionHash,
|
|
751
784
|
tx,
|
|
@@ -856,15 +889,17 @@ var WarpEvmExecutor = class {
|
|
|
856
889
|
const userWallet = getWarpWalletAddressFromConfig2(this.config, executable.chain.name);
|
|
857
890
|
if (!userWallet) throw new Error("WarpEvmExecutor: createContractCall - user address not set");
|
|
858
891
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
859
|
-
if (!action || !("func" in action) || !action.func)
|
|
860
|
-
|
|
861
|
-
}
|
|
862
|
-
if (!ethers4.isAddress(executable.destination)) {
|
|
863
|
-
throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
|
|
864
|
-
}
|
|
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}`);
|
|
865
894
|
try {
|
|
866
|
-
|
|
867
|
-
|
|
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);
|
|
868
903
|
const tx = {
|
|
869
904
|
to: executable.destination,
|
|
870
905
|
value: executable.value,
|
|
@@ -876,19 +911,13 @@ var WarpEvmExecutor = class {
|
|
|
876
911
|
}
|
|
877
912
|
}
|
|
878
913
|
async createTokenTransferTransaction(executable, userWallet) {
|
|
879
|
-
if (executable.transfers.length === 0)
|
|
880
|
-
|
|
881
|
-
}
|
|
882
|
-
if (!this.chain.nativeToken?.identifier) {
|
|
883
|
-
throw new Error("WarpEvmExecutor: No native token defined for this chain");
|
|
884
|
-
}
|
|
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");
|
|
885
916
|
const nativeTokenTransfers = executable.transfers.filter((transfer) => transfer.identifier === this.chain.nativeToken.identifier);
|
|
886
917
|
const erc20Transfers = executable.transfers.filter((transfer) => transfer.identifier !== this.chain.nativeToken.identifier);
|
|
887
918
|
if (nativeTokenTransfers.length === 1 && erc20Transfers.length === 0) {
|
|
888
919
|
const transfer = nativeTokenTransfers[0];
|
|
889
|
-
if (transfer.amount <= 0n)
|
|
890
|
-
throw new Error("WarpEvmExecutor: Native token transfer amount must be positive");
|
|
891
|
-
}
|
|
920
|
+
if (transfer.amount <= 0n) throw new Error("WarpEvmExecutor: Native token transfer amount must be positive");
|
|
892
921
|
const tx = {
|
|
893
922
|
to: executable.destination,
|
|
894
923
|
value: transfer.amount,
|
|
@@ -899,9 +928,7 @@ var WarpEvmExecutor = class {
|
|
|
899
928
|
if (nativeTokenTransfers.length === 0 && erc20Transfers.length === 1) {
|
|
900
929
|
return this.createSingleTokenTransfer(executable, erc20Transfers[0], userWallet);
|
|
901
930
|
}
|
|
902
|
-
if (executable.transfers.length > 1)
|
|
903
|
-
throw new Error("WarpEvmExecutor: Multiple token transfers not yet supported");
|
|
904
|
-
}
|
|
931
|
+
if (executable.transfers.length > 1) throw new Error("WarpEvmExecutor: Multiple token transfers not yet supported");
|
|
905
932
|
throw new Error("WarpEvmExecutor: Invalid transfer configuration");
|
|
906
933
|
}
|
|
907
934
|
async createSingleTokenTransfer(executable, transfer, userWallet) {
|
|
@@ -912,27 +939,25 @@ var WarpEvmExecutor = class {
|
|
|
912
939
|
const encodedData = transferInterface.encodeFunctionData("transfer", [executable.destination, transfer.amount]);
|
|
913
940
|
const tx = {
|
|
914
941
|
to: transfer.identifier,
|
|
915
|
-
// Token contract address
|
|
916
942
|
value: 0n,
|
|
917
|
-
// No native token value for ERC-20 transfers
|
|
918
943
|
data: encodedData
|
|
919
944
|
};
|
|
920
945
|
return this.estimateGasAndSetDefaults(tx, userWallet);
|
|
921
946
|
}
|
|
922
947
|
async executeQuery(executable) {
|
|
923
948
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
924
|
-
if (action.type !== "query") {
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
if (!action.func) {
|
|
928
|
-
throw new Error("WarpEvmExecutor: Query action must have a function name");
|
|
929
|
-
}
|
|
930
|
-
if (!ethers4.isAddress(executable.destination)) {
|
|
931
|
-
throw new Error(`WarpEvmExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
932
|
-
}
|
|
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}`);
|
|
933
952
|
try {
|
|
934
|
-
|
|
935
|
-
|
|
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);
|
|
936
961
|
const result = await this.provider.call({
|
|
937
962
|
to: executable.destination,
|
|
938
963
|
data: encodedData
|
|
@@ -979,12 +1004,8 @@ var WarpEvmExecutor = class {
|
|
|
979
1004
|
...tx,
|
|
980
1005
|
from
|
|
981
1006
|
});
|
|
982
|
-
if (gasEstimate < BigInt(WarpEvmConstants.Validation.MinGasLimit)) {
|
|
983
|
-
|
|
984
|
-
}
|
|
985
|
-
if (gasEstimate > BigInt(WarpEvmConstants.Validation.MaxGasLimit)) {
|
|
986
|
-
throw new Error(`Gas estimate too high: ${gasEstimate}`);
|
|
987
|
-
}
|
|
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}`);
|
|
988
1009
|
const feeData = await this.provider.getFeeData();
|
|
989
1010
|
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
|
990
1011
|
return {
|
|
@@ -1028,15 +1049,6 @@ var WarpEvmExecutor = class {
|
|
|
1028
1049
|
};
|
|
1029
1050
|
}
|
|
1030
1051
|
}
|
|
1031
|
-
async signMessage(message, privateKey) {
|
|
1032
|
-
try {
|
|
1033
|
-
const wallet = new ethers4.Wallet(privateKey);
|
|
1034
|
-
const signature = await wallet.signMessage(message);
|
|
1035
|
-
return signature;
|
|
1036
|
-
} catch (error) {
|
|
1037
|
-
throw new Error(`Failed to sign message: ${error}`);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
1052
|
async verifyMessage(message, signature) {
|
|
1041
1053
|
try {
|
|
1042
1054
|
const recoveredAddress = ethers4.verifyMessage(message, signature);
|
|
@@ -1196,6 +1208,36 @@ var WarpEvmWallet = class {
|
|
|
1196
1208
|
const signedTx = await wallet.signTransaction(txRequest);
|
|
1197
1209
|
return { ...tx, signature: signedTx };
|
|
1198
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
|
+
}
|
|
1199
1241
|
async signMessage(message) {
|
|
1200
1242
|
const wallet = this.getWallet();
|
|
1201
1243
|
const signature = await wallet.signMessage(message);
|
|
@@ -1210,6 +1252,9 @@ var WarpEvmWallet = class {
|
|
|
1210
1252
|
const txResponse = await connectedWallet.sendTransaction(tx);
|
|
1211
1253
|
return txResponse.hash;
|
|
1212
1254
|
}
|
|
1255
|
+
async sendTransactions(txs) {
|
|
1256
|
+
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1257
|
+
}
|
|
1213
1258
|
create(mnemonic) {
|
|
1214
1259
|
const wallet = ethers5.Wallet.fromPhrase(mnemonic);
|
|
1215
1260
|
return { address: wallet.address, privateKey: wallet.privateKey, mnemonic };
|