@vleap/warps-adapter-evm 0.2.0-beta.55 → 0.2.0-beta.56
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 +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +295 -171
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +215 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
WarpCache as WarpCache2,
|
|
9
9
|
WarpCacheKey
|
|
10
10
|
} from "@vleap/warps";
|
|
11
|
-
import { ethers } from "ethers";
|
|
11
|
+
import { ethers as ethers3 } from "ethers";
|
|
12
12
|
|
|
13
13
|
// src/providers/UniswapService.ts
|
|
14
14
|
import { CacheTtl } from "@vleap/warps";
|
|
@@ -96,6 +96,126 @@ var _UniswapService = class _UniswapService {
|
|
|
96
96
|
_UniswapService.UNISWAP_TOKEN_LIST_URL = "https://tokens.uniswap.org";
|
|
97
97
|
var UniswapService = _UniswapService;
|
|
98
98
|
|
|
99
|
+
// src/providers/PrivateKeyWalletProvider.ts
|
|
100
|
+
import { ethers } from "ethers";
|
|
101
|
+
import { getWarpWalletPrivateKeyFromConfig } from "@vleap/warps";
|
|
102
|
+
var PrivateKeyWalletProvider = class {
|
|
103
|
+
constructor(config, chain, rpcProvider) {
|
|
104
|
+
this.config = config;
|
|
105
|
+
this.chain = chain;
|
|
106
|
+
this.rpcProvider = rpcProvider;
|
|
107
|
+
this.wallet = null;
|
|
108
|
+
}
|
|
109
|
+
async getAddress() {
|
|
110
|
+
try {
|
|
111
|
+
const wallet = this.getWallet();
|
|
112
|
+
return wallet.address;
|
|
113
|
+
} catch {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async getPublicKey() {
|
|
118
|
+
try {
|
|
119
|
+
const wallet = this.getWallet();
|
|
120
|
+
const publicKey = wallet.signingKey.publicKey;
|
|
121
|
+
return publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async signTransaction(tx) {
|
|
127
|
+
const wallet = this.getWallet();
|
|
128
|
+
const txRequest = {
|
|
129
|
+
to: tx.to,
|
|
130
|
+
data: tx.data,
|
|
131
|
+
value: tx.value || 0,
|
|
132
|
+
gasLimit: tx.gasLimit,
|
|
133
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
134
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
135
|
+
nonce: tx.nonce,
|
|
136
|
+
chainId: tx.chainId
|
|
137
|
+
};
|
|
138
|
+
const signedTx = await wallet.signTransaction(txRequest);
|
|
139
|
+
return { ...tx, signature: signedTx };
|
|
140
|
+
}
|
|
141
|
+
async signMessage(message) {
|
|
142
|
+
const wallet = this.getWallet();
|
|
143
|
+
return await wallet.signMessage(message);
|
|
144
|
+
}
|
|
145
|
+
getWalletInstance() {
|
|
146
|
+
return this.getWallet();
|
|
147
|
+
}
|
|
148
|
+
getWallet() {
|
|
149
|
+
if (this.wallet) return this.wallet;
|
|
150
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
151
|
+
if (!privateKey) {
|
|
152
|
+
throw new Error("No private key provided");
|
|
153
|
+
}
|
|
154
|
+
this.wallet = new ethers.Wallet(privateKey);
|
|
155
|
+
return this.wallet;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
160
|
+
import { ethers as ethers2 } from "ethers";
|
|
161
|
+
import { getWarpWalletMnemonicFromConfig } from "@vleap/warps";
|
|
162
|
+
var MnemonicWalletProvider = class {
|
|
163
|
+
constructor(config, chain, rpcProvider) {
|
|
164
|
+
this.config = config;
|
|
165
|
+
this.chain = chain;
|
|
166
|
+
this.rpcProvider = rpcProvider;
|
|
167
|
+
this.wallet = null;
|
|
168
|
+
}
|
|
169
|
+
async getAddress() {
|
|
170
|
+
try {
|
|
171
|
+
const wallet = this.getWallet();
|
|
172
|
+
return wallet.address;
|
|
173
|
+
} catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async getPublicKey() {
|
|
178
|
+
try {
|
|
179
|
+
const wallet = this.getWallet();
|
|
180
|
+
const publicKey = wallet.signingKey.publicKey;
|
|
181
|
+
return publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async signTransaction(tx) {
|
|
187
|
+
const wallet = this.getWallet();
|
|
188
|
+
const txRequest = {
|
|
189
|
+
to: tx.to,
|
|
190
|
+
data: tx.data,
|
|
191
|
+
value: tx.value || 0,
|
|
192
|
+
gasLimit: tx.gasLimit,
|
|
193
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
194
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
195
|
+
nonce: tx.nonce,
|
|
196
|
+
chainId: tx.chainId
|
|
197
|
+
};
|
|
198
|
+
const signedTx = await wallet.signTransaction(txRequest);
|
|
199
|
+
return { ...tx, signature: signedTx };
|
|
200
|
+
}
|
|
201
|
+
async signMessage(message) {
|
|
202
|
+
const wallet = this.getWallet();
|
|
203
|
+
return await wallet.signMessage(message);
|
|
204
|
+
}
|
|
205
|
+
getWalletInstance() {
|
|
206
|
+
return this.getWallet();
|
|
207
|
+
}
|
|
208
|
+
getWallet() {
|
|
209
|
+
if (this.wallet) return this.wallet;
|
|
210
|
+
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
211
|
+
if (!mnemonic) {
|
|
212
|
+
throw new Error("No mnemonic provided");
|
|
213
|
+
}
|
|
214
|
+
this.wallet = ethers2.Wallet.fromPhrase(mnemonic);
|
|
215
|
+
return this.wallet;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
99
219
|
// src/tokens/arbitrum.ts
|
|
100
220
|
import { WarpChainName } from "@vleap/warps";
|
|
101
221
|
var ArbitrumChain = WarpChainName.Arbitrum;
|
|
@@ -387,8 +507,8 @@ var WarpEvmDataLoader = class {
|
|
|
387
507
|
this.config = config;
|
|
388
508
|
this.chain = chain;
|
|
389
509
|
const providerConfig = getProviderConfig(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
390
|
-
const network = new
|
|
391
|
-
this.provider = new
|
|
510
|
+
const network = new ethers3.Network(this.chain.name, parseInt(this.chain.chainId));
|
|
511
|
+
this.provider = new ethers3.JsonRpcProvider(providerConfig.url, network);
|
|
392
512
|
this.cache = new WarpCache2(config.cache?.type);
|
|
393
513
|
this.uniswapService = new UniswapService(this.cache, parseInt(this.chain.chainId));
|
|
394
514
|
}
|
|
@@ -513,7 +633,7 @@ var WarpEvmDataLoader = class {
|
|
|
513
633
|
}));
|
|
514
634
|
}
|
|
515
635
|
async getTokenBalance(address, tokenAddress) {
|
|
516
|
-
const contract = new
|
|
636
|
+
const contract = new ethers3.Contract(tokenAddress, ERC20_ABI, this.provider);
|
|
517
637
|
const balance = await contract.balanceOf(address);
|
|
518
638
|
return balance;
|
|
519
639
|
}
|
|
@@ -522,7 +642,7 @@ var WarpEvmDataLoader = class {
|
|
|
522
642
|
if (uniswapMetadata) {
|
|
523
643
|
return uniswapMetadata;
|
|
524
644
|
}
|
|
525
|
-
const contract = new
|
|
645
|
+
const contract = new ethers3.Contract(tokenAddress, ERC20_ABI, this.provider);
|
|
526
646
|
const [name, symbol, decimals] = await Promise.all([
|
|
527
647
|
contract.name().catch(() => "Unknown Token"),
|
|
528
648
|
contract.symbol().catch(() => "UNKNOWN"),
|
|
@@ -546,7 +666,7 @@ import {
|
|
|
546
666
|
getWarpActionByIndex,
|
|
547
667
|
getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig2
|
|
548
668
|
} from "@vleap/warps";
|
|
549
|
-
import { ethers as
|
|
669
|
+
import { ethers as ethers6 } from "ethers";
|
|
550
670
|
|
|
551
671
|
// src/constants.ts
|
|
552
672
|
var WarpEvmConstants = {
|
|
@@ -634,14 +754,14 @@ import {
|
|
|
634
754
|
WarpCache as WarpCache3,
|
|
635
755
|
WarpCacheKey as WarpCacheKey2
|
|
636
756
|
} from "@vleap/warps";
|
|
637
|
-
import { ethers as
|
|
757
|
+
import { ethers as ethers5 } from "ethers";
|
|
638
758
|
|
|
639
759
|
// src/WarpEvmSerializer.ts
|
|
640
760
|
import {
|
|
641
761
|
WarpConstants,
|
|
642
762
|
WarpSerializer
|
|
643
763
|
} from "@vleap/warps";
|
|
644
|
-
import { ethers as
|
|
764
|
+
import { ethers as ethers4 } from "ethers";
|
|
645
765
|
var SplitParamsRegex = new RegExp(`${WarpConstants.ArgParamsSeparator}(.*)`);
|
|
646
766
|
var WarpEvmSerializer = class {
|
|
647
767
|
constructor() {
|
|
@@ -649,10 +769,10 @@ var WarpEvmSerializer = class {
|
|
|
649
769
|
}
|
|
650
770
|
typedToString(value) {
|
|
651
771
|
if (typeof value === "string") {
|
|
652
|
-
if (
|
|
772
|
+
if (ethers4.isAddress(value)) {
|
|
653
773
|
return `address:${value}`;
|
|
654
774
|
}
|
|
655
|
-
if (
|
|
775
|
+
if (ethers4.isHexString(value) && !ethers4.isAddress(value)) {
|
|
656
776
|
return `hex:${value}`;
|
|
657
777
|
}
|
|
658
778
|
return `string:${value}`;
|
|
@@ -799,8 +919,8 @@ var WarpEvmOutput = class {
|
|
|
799
919
|
this.chain = chain;
|
|
800
920
|
this.serializer = new WarpEvmSerializer();
|
|
801
921
|
const providerConfig = getProviderConfig2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
802
|
-
const network = new
|
|
803
|
-
this.provider = new
|
|
922
|
+
const network = new ethers5.Network(this.chain.name, parseInt(this.chain.chainId));
|
|
923
|
+
this.provider = new ethers5.JsonRpcProvider(providerConfig.url, network);
|
|
804
924
|
this.cache = new WarpCache3(config.cache?.type);
|
|
805
925
|
}
|
|
806
926
|
async getActionExecution(warp, actionIndex, tx) {
|
|
@@ -946,8 +1066,8 @@ var WarpEvmExecutor = class {
|
|
|
946
1066
|
this.chain = chain;
|
|
947
1067
|
this.serializer = new WarpEvmSerializer();
|
|
948
1068
|
const providerConfig = getProviderConfig3(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
949
|
-
const network = new
|
|
950
|
-
this.provider = new
|
|
1069
|
+
const network = new ethers6.Network(this.chain.name, parseInt(this.chain.chainId));
|
|
1070
|
+
this.provider = new ethers6.JsonRpcProvider(providerConfig.url, network);
|
|
951
1071
|
this.output = new WarpEvmOutput(config, this.chain);
|
|
952
1072
|
}
|
|
953
1073
|
async createTransaction(executable) {
|
|
@@ -968,7 +1088,7 @@ var WarpEvmExecutor = class {
|
|
|
968
1088
|
async createTransferTransaction(executable) {
|
|
969
1089
|
const userWallet = getWarpWalletAddressFromConfig2(this.config, executable.chain.name);
|
|
970
1090
|
if (!userWallet) throw new Error("WarpEvmExecutor: createTransfer - user address not set");
|
|
971
|
-
if (!
|
|
1091
|
+
if (!ethers6.isAddress(executable.destination)) {
|
|
972
1092
|
throw new Error(`WarpEvmExecutor: Invalid destination address: ${executable.destination}`);
|
|
973
1093
|
}
|
|
974
1094
|
if (executable.transfers && executable.transfers.length > 0) {
|
|
@@ -986,13 +1106,13 @@ var WarpEvmExecutor = class {
|
|
|
986
1106
|
if (!userWallet) throw new Error("WarpEvmExecutor: createContractCall - user address not set");
|
|
987
1107
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
988
1108
|
if (!action || !("func" in action) || !action.func) throw new Error("WarpEvmExecutor: Contract action must have a function name");
|
|
989
|
-
if (!
|
|
1109
|
+
if (!ethers6.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
|
|
990
1110
|
try {
|
|
991
1111
|
let iface;
|
|
992
1112
|
try {
|
|
993
|
-
iface = new
|
|
1113
|
+
iface = new ethers6.Interface(JSON.parse(action.abi));
|
|
994
1114
|
} catch {
|
|
995
|
-
iface = new
|
|
1115
|
+
iface = new ethers6.Interface([action.abi]);
|
|
996
1116
|
}
|
|
997
1117
|
const funcFragment = iface.getFunction(action.func);
|
|
998
1118
|
if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
|
|
@@ -1034,10 +1154,10 @@ var WarpEvmExecutor = class {
|
|
|
1034
1154
|
throw new Error("WarpEvmExecutor: Invalid transfer configuration");
|
|
1035
1155
|
}
|
|
1036
1156
|
async createSingleTokenTransfer(executable, transfer, userWallet) {
|
|
1037
|
-
if (!
|
|
1157
|
+
if (!ethers6.isAddress(transfer.identifier)) {
|
|
1038
1158
|
throw new Error(`WarpEvmExecutor: Invalid token address: ${transfer.identifier}`);
|
|
1039
1159
|
}
|
|
1040
|
-
const transferInterface = new
|
|
1160
|
+
const transferInterface = new ethers6.Interface(["function transfer(address to, uint256 amount) returns (bool)"]);
|
|
1041
1161
|
const encodedData = transferInterface.encodeFunctionData("transfer", [executable.destination, transfer.amount]);
|
|
1042
1162
|
const tx = {
|
|
1043
1163
|
to: transfer.identifier,
|
|
@@ -1050,13 +1170,13 @@ var WarpEvmExecutor = class {
|
|
|
1050
1170
|
const action = getWarpActionByIndex(executable.warp, executable.action);
|
|
1051
1171
|
if (action.type !== "query") throw new Error(`WarpEvmExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
1052
1172
|
if (!action.func) throw new Error("WarpEvmExecutor: Query action must have a function name");
|
|
1053
|
-
if (!
|
|
1173
|
+
if (!ethers6.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid address for query: ${executable.destination}`);
|
|
1054
1174
|
try {
|
|
1055
1175
|
let iface;
|
|
1056
1176
|
try {
|
|
1057
|
-
iface = new
|
|
1177
|
+
iface = new ethers6.Interface(JSON.parse(action.abi));
|
|
1058
1178
|
} catch {
|
|
1059
|
-
iface = new
|
|
1179
|
+
iface = new ethers6.Interface([action.abi]);
|
|
1060
1180
|
}
|
|
1061
1181
|
const funcFragment = iface.getFunction(action.func);
|
|
1062
1182
|
if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
|
|
@@ -1141,7 +1261,7 @@ var WarpEvmExecutor = class {
|
|
|
1141
1261
|
...tx,
|
|
1142
1262
|
chainId: parseInt(this.chain.chainId),
|
|
1143
1263
|
gasLimit: gasEstimate,
|
|
1144
|
-
gasPrice:
|
|
1264
|
+
gasPrice: ethers6.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
|
|
1145
1265
|
};
|
|
1146
1266
|
}
|
|
1147
1267
|
} catch (error) {
|
|
@@ -1159,13 +1279,13 @@ var WarpEvmExecutor = class {
|
|
|
1159
1279
|
...tx,
|
|
1160
1280
|
chainId: parseInt(this.chain.chainId),
|
|
1161
1281
|
gasLimit: defaultGasLimit,
|
|
1162
|
-
gasPrice:
|
|
1282
|
+
gasPrice: ethers6.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
|
|
1163
1283
|
};
|
|
1164
1284
|
}
|
|
1165
1285
|
}
|
|
1166
1286
|
async verifyMessage(message, signature) {
|
|
1167
1287
|
try {
|
|
1168
|
-
const recoveredAddress =
|
|
1288
|
+
const recoveredAddress = ethers6.verifyMessage(message, signature);
|
|
1169
1289
|
return recoveredAddress;
|
|
1170
1290
|
} catch (error) {
|
|
1171
1291
|
throw new Error(`Failed to verify message: ${error}`);
|
|
@@ -1211,7 +1331,7 @@ var WarpEvmExecutor = class {
|
|
|
1211
1331
|
hexValue = "0x" + hexValue;
|
|
1212
1332
|
}
|
|
1213
1333
|
if (hexValue.length !== 66) {
|
|
1214
|
-
hexValue =
|
|
1334
|
+
hexValue = ethers6.zeroPadValue(hexValue, 32);
|
|
1215
1335
|
}
|
|
1216
1336
|
return hexValue;
|
|
1217
1337
|
}
|
|
@@ -1342,107 +1462,108 @@ var WarpEvmExplorer = class {
|
|
|
1342
1462
|
// src/WarpEvmWallet.ts
|
|
1343
1463
|
import {
|
|
1344
1464
|
getProviderConfig as getProviderConfig4,
|
|
1345
|
-
getWarpWalletMnemonicFromConfig,
|
|
1346
|
-
getWarpWalletPrivateKeyFromConfig
|
|
1465
|
+
getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
|
|
1466
|
+
getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
|
|
1467
|
+
initializeWalletCache
|
|
1347
1468
|
} from "@vleap/warps";
|
|
1348
|
-
import { ethers as
|
|
1469
|
+
import { ethers as ethers7 } from "ethers";
|
|
1349
1470
|
var WarpEvmWallet = class {
|
|
1350
|
-
constructor(config, chain) {
|
|
1471
|
+
constructor(config, chain, walletProvider) {
|
|
1351
1472
|
this.config = config;
|
|
1352
1473
|
this.chain = chain;
|
|
1474
|
+
this.cachedAddress = null;
|
|
1475
|
+
this.cachedPublicKey = null;
|
|
1353
1476
|
const providerConfig = getProviderConfig4(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1354
|
-
this.provider = new
|
|
1477
|
+
this.provider = new ethers7.JsonRpcProvider(providerConfig.url);
|
|
1478
|
+
this.walletProvider = walletProvider || this.createDefaultProvider();
|
|
1479
|
+
this.initializeCache();
|
|
1480
|
+
}
|
|
1481
|
+
createDefaultProvider() {
|
|
1482
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
|
|
1483
|
+
if (privateKey) {
|
|
1484
|
+
return new PrivateKeyWalletProvider(this.config, this.chain, this.provider);
|
|
1485
|
+
}
|
|
1486
|
+
const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
|
|
1487
|
+
if (mnemonic) {
|
|
1488
|
+
return new MnemonicWalletProvider(this.config, this.chain, this.provider);
|
|
1489
|
+
}
|
|
1490
|
+
return null;
|
|
1491
|
+
}
|
|
1492
|
+
initializeCache() {
|
|
1493
|
+
initializeWalletCache(this.walletProvider).then((cache) => {
|
|
1494
|
+
this.cachedAddress = cache.address;
|
|
1495
|
+
this.cachedPublicKey = cache.publicKey;
|
|
1496
|
+
});
|
|
1355
1497
|
}
|
|
1356
1498
|
async signTransaction(tx) {
|
|
1357
1499
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
to: tx.to,
|
|
1361
|
-
data: tx.data,
|
|
1362
|
-
value: tx.value || 0,
|
|
1363
|
-
gasLimit: tx.gasLimit,
|
|
1364
|
-
maxFeePerGas: tx.maxFeePerGas,
|
|
1365
|
-
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
1366
|
-
nonce: tx.nonce,
|
|
1367
|
-
chainId: tx.chainId
|
|
1368
|
-
};
|
|
1369
|
-
const signedTx = await wallet.signTransaction(txRequest);
|
|
1370
|
-
return { ...tx, signature: signedTx };
|
|
1500
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1501
|
+
return await this.walletProvider.signTransaction(tx);
|
|
1371
1502
|
}
|
|
1372
1503
|
async signTransactions(txs) {
|
|
1373
1504
|
if (txs.length === 0) return [];
|
|
1374
|
-
if (
|
|
1375
|
-
|
|
1505
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1506
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1507
|
+
const wallet = this.walletProvider.getWalletInstance();
|
|
1376
1508
|
const address = wallet.address;
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1509
|
+
if (txs.length > 1) {
|
|
1510
|
+
const currentNonce = await this.provider.getTransactionCount(address, "pending");
|
|
1511
|
+
const signedTxs = [];
|
|
1512
|
+
for (let i = 0; i < txs.length; i++) {
|
|
1513
|
+
const tx = { ...txs[i] };
|
|
1514
|
+
tx.nonce = currentNonce + i;
|
|
1515
|
+
if (i > 0) {
|
|
1516
|
+
const priorityReduction = BigInt(i * 1e9);
|
|
1517
|
+
const minGasPrice = BigInt(1e9);
|
|
1518
|
+
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
|
1519
|
+
tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
|
|
1520
|
+
tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
|
|
1521
|
+
delete tx.gasPrice;
|
|
1522
|
+
} else if (tx.gasPrice) {
|
|
1523
|
+
tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
|
|
1524
|
+
delete tx.maxFeePerGas;
|
|
1525
|
+
delete tx.maxPriorityFeePerGas;
|
|
1526
|
+
}
|
|
1393
1527
|
}
|
|
1528
|
+
signedTxs.push(await this.signTransaction(tx));
|
|
1394
1529
|
}
|
|
1395
|
-
|
|
1396
|
-
signedTxs.push(signedTx);
|
|
1530
|
+
return signedTxs;
|
|
1397
1531
|
}
|
|
1398
|
-
return signedTxs;
|
|
1399
1532
|
}
|
|
1400
1533
|
return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
|
|
1401
1534
|
}
|
|
1402
1535
|
async signMessage(message) {
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
return signature;
|
|
1536
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1537
|
+
return await this.walletProvider.signMessage(message);
|
|
1406
1538
|
}
|
|
1407
1539
|
async sendTransaction(tx) {
|
|
1408
1540
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1409
1541
|
if (!tx.signature) throw new Error("Transaction must be signed before sending");
|
|
1410
|
-
|
|
1411
|
-
if (
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1542
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1543
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1544
|
+
const wallet = this.walletProvider.getWalletInstance();
|
|
1545
|
+
const connectedWallet = wallet.connect(this.provider);
|
|
1546
|
+
const txResponse = await connectedWallet.sendTransaction(tx);
|
|
1547
|
+
return txResponse.hash;
|
|
1548
|
+
}
|
|
1549
|
+
throw new Error("Wallet provider does not support sending transactions");
|
|
1415
1550
|
}
|
|
1416
1551
|
async sendTransactions(txs) {
|
|
1417
1552
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1418
1553
|
}
|
|
1419
1554
|
create(mnemonic) {
|
|
1420
|
-
const wallet =
|
|
1555
|
+
const wallet = ethers7.Wallet.fromPhrase(mnemonic);
|
|
1421
1556
|
return { address: wallet.address, privateKey: wallet.privateKey, mnemonic };
|
|
1422
1557
|
}
|
|
1423
1558
|
generate() {
|
|
1424
|
-
const wallet =
|
|
1559
|
+
const wallet = ethers7.Wallet.createRandom();
|
|
1425
1560
|
return { address: wallet.address, privateKey: wallet.privateKey, mnemonic: wallet.mnemonic?.phrase || "" };
|
|
1426
1561
|
}
|
|
1427
1562
|
getAddress() {
|
|
1428
|
-
|
|
1429
|
-
return wallet.address;
|
|
1563
|
+
return this.cachedAddress;
|
|
1430
1564
|
}
|
|
1431
1565
|
getPublicKey() {
|
|
1432
|
-
|
|
1433
|
-
const wallet = this.getWallet();
|
|
1434
|
-
const publicKey = wallet.signingKey.publicKey;
|
|
1435
|
-
return publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
|
|
1436
|
-
} catch {
|
|
1437
|
-
return null;
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
getWallet() {
|
|
1441
|
-
const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
|
|
1442
|
-
if (privateKey) return new ethers5.Wallet(privateKey);
|
|
1443
|
-
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
1444
|
-
if (mnemonic) return ethers5.Wallet.fromPhrase(mnemonic);
|
|
1445
|
-
throw new Error("No private key or mnemonic provided");
|
|
1566
|
+
return this.cachedPublicKey;
|
|
1446
1567
|
}
|
|
1447
1568
|
};
|
|
1448
1569
|
|
|
@@ -1668,9 +1789,11 @@ export {
|
|
|
1668
1789
|
EvmExplorers,
|
|
1669
1790
|
ExplorerUrls,
|
|
1670
1791
|
KnownTokens,
|
|
1792
|
+
MnemonicWalletProvider,
|
|
1671
1793
|
NativeTokenArb,
|
|
1672
1794
|
NativeTokenBase,
|
|
1673
1795
|
NativeTokenEth,
|
|
1796
|
+
PrivateKeyWalletProvider,
|
|
1674
1797
|
UniswapService,
|
|
1675
1798
|
WarpEvmConstants,
|
|
1676
1799
|
WarpEvmDataLoader,
|