@vleap/warps-adapter-evm 0.2.0-beta.55 → 0.2.0-beta.57

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.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,158 @@ 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
+ create(mnemonic) {
149
+ const wallet = ethers.Wallet.fromPhrase(mnemonic);
150
+ return {
151
+ provider: "privateKey",
152
+ address: wallet.address,
153
+ privateKey: wallet.privateKey,
154
+ mnemonic
155
+ };
156
+ }
157
+ generate() {
158
+ const wallet = ethers.Wallet.createRandom();
159
+ return {
160
+ provider: "privateKey",
161
+ address: wallet.address,
162
+ privateKey: wallet.privateKey,
163
+ mnemonic: wallet.mnemonic?.phrase || null
164
+ };
165
+ }
166
+ getWallet() {
167
+ if (this.wallet) return this.wallet;
168
+ const privateKey = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
169
+ if (!privateKey) throw new Error("No private key provided");
170
+ this.wallet = new ethers.Wallet(privateKey);
171
+ return this.wallet;
172
+ }
173
+ };
174
+
175
+ // src/providers/MnemonicWalletProvider.ts
176
+ import { ethers as ethers2 } from "ethers";
177
+ import { getWarpWalletMnemonicFromConfig } from "@vleap/warps";
178
+ var MnemonicWalletProvider = class {
179
+ constructor(config, chain, rpcProvider) {
180
+ this.config = config;
181
+ this.chain = chain;
182
+ this.rpcProvider = rpcProvider;
183
+ this.wallet = null;
184
+ }
185
+ async getAddress() {
186
+ try {
187
+ const wallet = this.getWallet();
188
+ return wallet.address;
189
+ } catch {
190
+ return null;
191
+ }
192
+ }
193
+ async getPublicKey() {
194
+ try {
195
+ const wallet = this.getWallet();
196
+ const publicKey = wallet.signingKey.publicKey;
197
+ return publicKey.startsWith("0x") ? publicKey.slice(2) : publicKey;
198
+ } catch {
199
+ return null;
200
+ }
201
+ }
202
+ async signTransaction(tx) {
203
+ const wallet = this.getWallet();
204
+ const txRequest = {
205
+ to: tx.to,
206
+ data: tx.data,
207
+ value: tx.value || 0,
208
+ gasLimit: tx.gasLimit,
209
+ maxFeePerGas: tx.maxFeePerGas,
210
+ maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
211
+ nonce: tx.nonce,
212
+ chainId: tx.chainId
213
+ };
214
+ const signedTx = await wallet.signTransaction(txRequest);
215
+ return { ...tx, signature: signedTx };
216
+ }
217
+ async signMessage(message) {
218
+ const wallet = this.getWallet();
219
+ return await wallet.signMessage(message);
220
+ }
221
+ getWalletInstance() {
222
+ return this.getWallet();
223
+ }
224
+ create(mnemonic) {
225
+ const wallet = ethers2.Wallet.fromPhrase(mnemonic);
226
+ return {
227
+ provider: "mnemonic",
228
+ address: wallet.address,
229
+ privateKey: wallet.privateKey,
230
+ mnemonic
231
+ };
232
+ }
233
+ generate() {
234
+ const wallet = ethers2.Wallet.createRandom();
235
+ return {
236
+ provider: "mnemonic",
237
+ address: wallet.address,
238
+ privateKey: wallet.privateKey,
239
+ mnemonic: wallet.mnemonic?.phrase || null
240
+ };
241
+ }
242
+ getWallet() {
243
+ if (this.wallet) return this.wallet;
244
+ const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
245
+ if (!mnemonic) throw new Error("No mnemonic provided");
246
+ this.wallet = ethers2.Wallet.fromPhrase(mnemonic);
247
+ return this.wallet;
248
+ }
249
+ };
250
+
99
251
  // src/tokens/arbitrum.ts
100
252
  import { WarpChainName } from "@vleap/warps";
101
253
  var ArbitrumChain = WarpChainName.Arbitrum;
@@ -387,8 +539,8 @@ var WarpEvmDataLoader = class {
387
539
  this.config = config;
388
540
  this.chain = chain;
389
541
  const providerConfig = getProviderConfig(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
390
- const network = new ethers.Network(this.chain.name, parseInt(this.chain.chainId));
391
- this.provider = new ethers.JsonRpcProvider(providerConfig.url, network);
542
+ const network = new ethers3.Network(this.chain.name, parseInt(this.chain.chainId));
543
+ this.provider = new ethers3.JsonRpcProvider(providerConfig.url, network);
392
544
  this.cache = new WarpCache2(config.cache?.type);
393
545
  this.uniswapService = new UniswapService(this.cache, parseInt(this.chain.chainId));
394
546
  }
@@ -513,7 +665,7 @@ var WarpEvmDataLoader = class {
513
665
  }));
514
666
  }
515
667
  async getTokenBalance(address, tokenAddress) {
516
- const contract = new ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
668
+ const contract = new ethers3.Contract(tokenAddress, ERC20_ABI, this.provider);
517
669
  const balance = await contract.balanceOf(address);
518
670
  return balance;
519
671
  }
@@ -522,7 +674,7 @@ var WarpEvmDataLoader = class {
522
674
  if (uniswapMetadata) {
523
675
  return uniswapMetadata;
524
676
  }
525
- const contract = new ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
677
+ const contract = new ethers3.Contract(tokenAddress, ERC20_ABI, this.provider);
526
678
  const [name, symbol, decimals] = await Promise.all([
527
679
  contract.name().catch(() => "Unknown Token"),
528
680
  contract.symbol().catch(() => "UNKNOWN"),
@@ -546,7 +698,7 @@ import {
546
698
  getWarpActionByIndex,
547
699
  getWarpWalletAddressFromConfig as getWarpWalletAddressFromConfig2
548
700
  } from "@vleap/warps";
549
- import { ethers as ethers4 } from "ethers";
701
+ import { ethers as ethers6 } from "ethers";
550
702
 
551
703
  // src/constants.ts
552
704
  var WarpEvmConstants = {
@@ -622,6 +774,55 @@ var ExplorerUrls = {
622
774
  ["blockscout_base" /* BlockscoutBase */]: "https://base.blockscout.com",
623
775
  ["blockscout_base_sepolia" /* BlockscoutBaseSepolia */]: "https://sepolia.blockscout.com"
624
776
  };
777
+ var EvmChainIds = {
778
+ Ethereum: {
779
+ Mainnet: 1,
780
+ Goerli: 5,
781
+ Sepolia: 11155111
782
+ },
783
+ Polygon: {
784
+ Mainnet: 137,
785
+ Mumbai: 80001
786
+ },
787
+ Arbitrum: {
788
+ Mainnet: 42161,
789
+ Sepolia: 421614
790
+ },
791
+ Base: {
792
+ Mainnet: 8453,
793
+ Sepolia: 84532
794
+ },
795
+ Optimism: {
796
+ Mainnet: 10,
797
+ Sepolia: 11155420
798
+ }
799
+ };
800
+ var EvmChainIdMap = {
801
+ "ethereum:mainnet": EvmChainIds.Ethereum.Mainnet,
802
+ "ethereum:goerli": EvmChainIds.Ethereum.Goerli,
803
+ "ethereum:sepolia": EvmChainIds.Ethereum.Sepolia,
804
+ "polygon:mainnet": EvmChainIds.Polygon.Mainnet,
805
+ "polygon:mumbai": EvmChainIds.Polygon.Mumbai,
806
+ "arbitrum:mainnet": EvmChainIds.Arbitrum.Mainnet,
807
+ "arbitrum:sepolia": EvmChainIds.Arbitrum.Sepolia,
808
+ "base:mainnet": EvmChainIds.Base.Mainnet,
809
+ "base:sepolia": EvmChainIds.Base.Sepolia,
810
+ "optimism:mainnet": EvmChainIds.Optimism.Mainnet,
811
+ "optimism:sepolia": EvmChainIds.Optimism.Sepolia
812
+ };
813
+ var SupportedEvmChainIds = [
814
+ EvmChainIds.Ethereum.Mainnet,
815
+ EvmChainIds.Ethereum.Goerli,
816
+ EvmChainIds.Ethereum.Sepolia,
817
+ EvmChainIds.Polygon.Mainnet,
818
+ EvmChainIds.Polygon.Mumbai,
819
+ EvmChainIds.Arbitrum.Mainnet,
820
+ EvmChainIds.Arbitrum.Sepolia,
821
+ EvmChainIds.Base.Mainnet,
822
+ EvmChainIds.Base.Sepolia,
823
+ EvmChainIds.Optimism.Mainnet,
824
+ EvmChainIds.Optimism.Sepolia
825
+ ];
625
826
 
626
827
  // src/WarpEvmOutput.ts
627
828
  import {
@@ -634,14 +835,14 @@ import {
634
835
  WarpCache as WarpCache3,
635
836
  WarpCacheKey as WarpCacheKey2
636
837
  } from "@vleap/warps";
637
- import { ethers as ethers3 } from "ethers";
838
+ import { ethers as ethers5 } from "ethers";
638
839
 
639
840
  // src/WarpEvmSerializer.ts
640
841
  import {
641
842
  WarpConstants,
642
843
  WarpSerializer
643
844
  } from "@vleap/warps";
644
- import { ethers as ethers2 } from "ethers";
845
+ import { ethers as ethers4 } from "ethers";
645
846
  var SplitParamsRegex = new RegExp(`${WarpConstants.ArgParamsSeparator}(.*)`);
646
847
  var WarpEvmSerializer = class {
647
848
  constructor() {
@@ -649,10 +850,10 @@ var WarpEvmSerializer = class {
649
850
  }
650
851
  typedToString(value) {
651
852
  if (typeof value === "string") {
652
- if (ethers2.isAddress(value)) {
853
+ if (ethers4.isAddress(value)) {
653
854
  return `address:${value}`;
654
855
  }
655
- if (ethers2.isHexString(value) && !ethers2.isAddress(value)) {
856
+ if (ethers4.isHexString(value) && !ethers4.isAddress(value)) {
656
857
  return `hex:${value}`;
657
858
  }
658
859
  return `string:${value}`;
@@ -799,8 +1000,8 @@ var WarpEvmOutput = class {
799
1000
  this.chain = chain;
800
1001
  this.serializer = new WarpEvmSerializer();
801
1002
  const providerConfig = getProviderConfig2(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
802
- const network = new ethers3.Network(this.chain.name, parseInt(this.chain.chainId));
803
- this.provider = new ethers3.JsonRpcProvider(providerConfig.url, network);
1003
+ const network = new ethers5.Network(this.chain.name, parseInt(this.chain.chainId));
1004
+ this.provider = new ethers5.JsonRpcProvider(providerConfig.url, network);
804
1005
  this.cache = new WarpCache3(config.cache?.type);
805
1006
  }
806
1007
  async getActionExecution(warp, actionIndex, tx) {
@@ -946,8 +1147,8 @@ var WarpEvmExecutor = class {
946
1147
  this.chain = chain;
947
1148
  this.serializer = new WarpEvmSerializer();
948
1149
  const providerConfig = getProviderConfig3(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
949
- const network = new ethers4.Network(this.chain.name, parseInt(this.chain.chainId));
950
- this.provider = new ethers4.JsonRpcProvider(providerConfig.url, network);
1150
+ const network = new ethers6.Network(this.chain.name, parseInt(this.chain.chainId));
1151
+ this.provider = new ethers6.JsonRpcProvider(providerConfig.url, network);
951
1152
  this.output = new WarpEvmOutput(config, this.chain);
952
1153
  }
953
1154
  async createTransaction(executable) {
@@ -968,7 +1169,7 @@ var WarpEvmExecutor = class {
968
1169
  async createTransferTransaction(executable) {
969
1170
  const userWallet = getWarpWalletAddressFromConfig2(this.config, executable.chain.name);
970
1171
  if (!userWallet) throw new Error("WarpEvmExecutor: createTransfer - user address not set");
971
- if (!ethers4.isAddress(executable.destination)) {
1172
+ if (!ethers6.isAddress(executable.destination)) {
972
1173
  throw new Error(`WarpEvmExecutor: Invalid destination address: ${executable.destination}`);
973
1174
  }
974
1175
  if (executable.transfers && executable.transfers.length > 0) {
@@ -986,13 +1187,13 @@ var WarpEvmExecutor = class {
986
1187
  if (!userWallet) throw new Error("WarpEvmExecutor: createContractCall - user address not set");
987
1188
  const action = getWarpActionByIndex(executable.warp, executable.action);
988
1189
  if (!action || !("func" in action) || !action.func) throw new Error("WarpEvmExecutor: Contract action must have a function name");
989
- if (!ethers4.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
1190
+ if (!ethers6.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
990
1191
  try {
991
1192
  let iface;
992
1193
  try {
993
- iface = new ethers4.Interface(JSON.parse(action.abi));
1194
+ iface = new ethers6.Interface(JSON.parse(action.abi));
994
1195
  } catch {
995
- iface = new ethers4.Interface([action.abi]);
1196
+ iface = new ethers6.Interface([action.abi]);
996
1197
  }
997
1198
  const funcFragment = iface.getFunction(action.func);
998
1199
  if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
@@ -1034,10 +1235,10 @@ var WarpEvmExecutor = class {
1034
1235
  throw new Error("WarpEvmExecutor: Invalid transfer configuration");
1035
1236
  }
1036
1237
  async createSingleTokenTransfer(executable, transfer, userWallet) {
1037
- if (!ethers4.isAddress(transfer.identifier)) {
1238
+ if (!ethers6.isAddress(transfer.identifier)) {
1038
1239
  throw new Error(`WarpEvmExecutor: Invalid token address: ${transfer.identifier}`);
1039
1240
  }
1040
- const transferInterface = new ethers4.Interface(["function transfer(address to, uint256 amount) returns (bool)"]);
1241
+ const transferInterface = new ethers6.Interface(["function transfer(address to, uint256 amount) returns (bool)"]);
1041
1242
  const encodedData = transferInterface.encodeFunctionData("transfer", [executable.destination, transfer.amount]);
1042
1243
  const tx = {
1043
1244
  to: transfer.identifier,
@@ -1050,13 +1251,13 @@ var WarpEvmExecutor = class {
1050
1251
  const action = getWarpActionByIndex(executable.warp, executable.action);
1051
1252
  if (action.type !== "query") throw new Error(`WarpEvmExecutor: Invalid action type for executeQuery: ${action.type}`);
1052
1253
  if (!action.func) throw new Error("WarpEvmExecutor: Query action must have a function name");
1053
- if (!ethers4.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid address for query: ${executable.destination}`);
1254
+ if (!ethers6.isAddress(executable.destination)) throw new Error(`WarpEvmExecutor: Invalid address for query: ${executable.destination}`);
1054
1255
  try {
1055
1256
  let iface;
1056
1257
  try {
1057
- iface = new ethers4.Interface(JSON.parse(action.abi));
1258
+ iface = new ethers6.Interface(JSON.parse(action.abi));
1058
1259
  } catch {
1059
- iface = new ethers4.Interface([action.abi]);
1260
+ iface = new ethers6.Interface([action.abi]);
1060
1261
  }
1061
1262
  const funcFragment = iface.getFunction(action.func);
1062
1263
  if (!funcFragment) throw new Error(`WarpEvmExecutor: Function ${action.func} not found in ABI`);
@@ -1141,7 +1342,7 @@ var WarpEvmExecutor = class {
1141
1342
  ...tx,
1142
1343
  chainId: parseInt(this.chain.chainId),
1143
1344
  gasLimit: gasEstimate,
1144
- gasPrice: ethers4.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
1345
+ gasPrice: ethers6.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
1145
1346
  };
1146
1347
  }
1147
1348
  } catch (error) {
@@ -1159,13 +1360,13 @@ var WarpEvmExecutor = class {
1159
1360
  ...tx,
1160
1361
  chainId: parseInt(this.chain.chainId),
1161
1362
  gasLimit: defaultGasLimit,
1162
- gasPrice: ethers4.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
1363
+ gasPrice: ethers6.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
1163
1364
  };
1164
1365
  }
1165
1366
  }
1166
1367
  async verifyMessage(message, signature) {
1167
1368
  try {
1168
- const recoveredAddress = ethers4.verifyMessage(message, signature);
1369
+ const recoveredAddress = ethers6.verifyMessage(message, signature);
1169
1370
  return recoveredAddress;
1170
1371
  } catch (error) {
1171
1372
  throw new Error(`Failed to verify message: ${error}`);
@@ -1211,7 +1412,7 @@ var WarpEvmExecutor = class {
1211
1412
  hexValue = "0x" + hexValue;
1212
1413
  }
1213
1414
  if (hexValue.length !== 66) {
1214
- hexValue = ethers4.zeroPadValue(hexValue, 32);
1415
+ hexValue = ethers6.zeroPadValue(hexValue, 32);
1215
1416
  }
1216
1417
  return hexValue;
1217
1418
  }
@@ -1342,107 +1543,124 @@ var WarpEvmExplorer = class {
1342
1543
  // src/WarpEvmWallet.ts
1343
1544
  import {
1344
1545
  getProviderConfig as getProviderConfig4,
1345
- getWarpWalletMnemonicFromConfig,
1346
- getWarpWalletPrivateKeyFromConfig
1546
+ initializeWalletCache
1347
1547
  } from "@vleap/warps";
1348
- import { ethers as ethers5 } from "ethers";
1548
+ import { registerExactEvmScheme } from "@x402/evm/exact/client";
1549
+ import { ethers as ethers7 } from "ethers";
1550
+ import { privateKeyToAccount } from "viem/accounts";
1349
1551
  var WarpEvmWallet = class {
1350
1552
  constructor(config, chain) {
1351
1553
  this.config = config;
1352
1554
  this.chain = chain;
1555
+ this.cachedAddress = null;
1556
+ this.cachedPublicKey = null;
1353
1557
  const providerConfig = getProviderConfig4(config, chain.name, config.env, chain.defaultApiUrl);
1354
- this.provider = new ethers5.JsonRpcProvider(providerConfig.url);
1558
+ this.provider = new ethers7.JsonRpcProvider(providerConfig.url);
1559
+ this.walletProvider = this.createProvider();
1560
+ this.initializeCache();
1561
+ }
1562
+ createProvider() {
1563
+ const wallet = this.config.user?.wallets?.[this.chain.name];
1564
+ if (!wallet) return null;
1565
+ if (typeof wallet === "string") throw new Error(`Wallet can not be used for signing: ${wallet}`);
1566
+ const customWalletProviders = this.config.walletProviders?.[this.chain.name];
1567
+ const providerFactory = customWalletProviders?.[wallet.provider];
1568
+ if (providerFactory) return providerFactory(this.config, this.chain);
1569
+ if (wallet.provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain, this.provider);
1570
+ if (wallet.provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain, this.provider);
1571
+ throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${wallet.provider}`);
1572
+ }
1573
+ initializeCache() {
1574
+ initializeWalletCache(this.walletProvider).then((cache) => {
1575
+ this.cachedAddress = cache.address;
1576
+ this.cachedPublicKey = cache.publicKey;
1577
+ });
1355
1578
  }
1356
1579
  async signTransaction(tx) {
1357
1580
  if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1358
- const wallet = this.getWallet();
1359
- const txRequest = {
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 };
1581
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1582
+ return await this.walletProvider.signTransaction(tx);
1371
1583
  }
1372
1584
  async signTransactions(txs) {
1373
1585
  if (txs.length === 0) return [];
1374
- if (txs.length > 1) {
1375
- const wallet = this.getWallet();
1586
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1587
+ if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1588
+ const wallet = this.walletProvider.getWalletInstance();
1376
1589
  const address = wallet.address;
1377
- const currentNonce = await this.provider.getTransactionCount(address, "pending");
1378
- const signedTxs = [];
1379
- for (let i = 0; i < txs.length; i++) {
1380
- const tx = { ...txs[i] };
1381
- tx.nonce = currentNonce + i;
1382
- if (i > 0) {
1383
- const priorityReduction = BigInt(i * 1e9);
1384
- const minGasPrice = BigInt(1e9);
1385
- if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
1386
- tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
1387
- tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
1388
- delete tx.gasPrice;
1389
- } else if (tx.gasPrice) {
1390
- tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
1391
- delete tx.maxFeePerGas;
1392
- delete tx.maxPriorityFeePerGas;
1590
+ if (txs.length > 1) {
1591
+ const currentNonce = await this.provider.getTransactionCount(address, "pending");
1592
+ const signedTxs = [];
1593
+ for (let i = 0; i < txs.length; i++) {
1594
+ const tx = { ...txs[i] };
1595
+ tx.nonce = currentNonce + i;
1596
+ if (i > 0) {
1597
+ const priorityReduction = BigInt(i * 1e9);
1598
+ const minGasPrice = BigInt(1e9);
1599
+ if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
1600
+ tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
1601
+ tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
1602
+ delete tx.gasPrice;
1603
+ } else if (tx.gasPrice) {
1604
+ tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
1605
+ delete tx.maxFeePerGas;
1606
+ delete tx.maxPriorityFeePerGas;
1607
+ }
1393
1608
  }
1609
+ signedTxs.push(await this.signTransaction(tx));
1394
1610
  }
1395
- const signedTx = await this.signTransaction(tx);
1396
- signedTxs.push(signedTx);
1611
+ return signedTxs;
1397
1612
  }
1398
- return signedTxs;
1399
1613
  }
1400
1614
  return Promise.all(txs.map(async (tx) => this.signTransaction(tx)));
1401
1615
  }
1402
1616
  async signMessage(message) {
1403
- const wallet = this.getWallet();
1404
- const signature = await wallet.signMessage(message);
1405
- return signature;
1617
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1618
+ return await this.walletProvider.signMessage(message);
1406
1619
  }
1407
1620
  async sendTransaction(tx) {
1408
1621
  if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1409
1622
  if (!tx.signature) throw new Error("Transaction must be signed before sending");
1410
- const wallet = this.getWallet();
1411
- if (!wallet) throw new Error("Wallet not initialized - no private key provided");
1412
- const connectedWallet = wallet.connect(this.provider);
1413
- const txResponse = await connectedWallet.sendTransaction(tx);
1414
- return txResponse.hash;
1623
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1624
+ if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1625
+ const wallet = this.walletProvider.getWalletInstance();
1626
+ const connectedWallet = wallet.connect(this.provider);
1627
+ const txResponse = await connectedWallet.sendTransaction(tx);
1628
+ return txResponse.hash;
1629
+ }
1630
+ throw new Error("Wallet provider does not support sending transactions");
1415
1631
  }
1416
1632
  async sendTransactions(txs) {
1417
1633
  return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
1418
1634
  }
1419
1635
  create(mnemonic) {
1420
- const wallet = ethers5.Wallet.fromPhrase(mnemonic);
1421
- return { address: wallet.address, privateKey: wallet.privateKey, mnemonic };
1636
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1637
+ return this.walletProvider.create(mnemonic);
1422
1638
  }
1423
1639
  generate() {
1424
- const wallet = ethers5.Wallet.createRandom();
1425
- return { address: wallet.address, privateKey: wallet.privateKey, mnemonic: wallet.mnemonic?.phrase || "" };
1640
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1641
+ return this.walletProvider.generate();
1426
1642
  }
1427
1643
  getAddress() {
1428
- const wallet = this.getWallet();
1429
- return wallet.address;
1644
+ return this.cachedAddress;
1430
1645
  }
1431
1646
  getPublicKey() {
1432
- try {
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;
1647
+ return this.cachedPublicKey;
1648
+ }
1649
+ async registerX402Handlers(client) {
1650
+ if (!this.walletProvider) throw new Error("No wallet provider available");
1651
+ const provider = this.walletProvider;
1652
+ const getInstance = provider.getWalletInstance;
1653
+ if (typeof getInstance !== "function") throw new Error("Wallet provider does not have getWalletInstance method");
1654
+ const wallet = getInstance();
1655
+ if (!wallet || !wallet.privateKey) throw new Error("Wallet instance does not have private key");
1656
+ const signer = privateKeyToAccount(wallet.privateKey);
1657
+ const handlers = {};
1658
+ for (const chainId of SupportedEvmChainIds) {
1659
+ handlers[`eip155:${chainId}`] = () => {
1660
+ registerExactEvmScheme(client, { signer });
1661
+ };
1438
1662
  }
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");
1663
+ return handlers;
1446
1664
  }
1447
1665
  };
1448
1666
 
@@ -1475,7 +1693,7 @@ var NativeTokenArb = {
1475
1693
  decimals: 18,
1476
1694
  logoUrl: "https://joai.ai/images/tokens/arb.svg"
1477
1695
  };
1478
- var getArbitrumAdapter = createEvmAdapter(WarpChainName7.Arbitrum, {
1696
+ var ArbitrumAdapter = createEvmAdapter(WarpChainName7.Arbitrum, {
1479
1697
  mainnet: {
1480
1698
  name: WarpChainName7.Arbitrum,
1481
1699
  displayName: "Arbitrum",
@@ -1518,7 +1736,7 @@ var NativeTokenBase = {
1518
1736
  decimals: 18,
1519
1737
  logoUrl: "https://joai.ai/images/tokens/eth.svg"
1520
1738
  };
1521
- var getBaseAdapter = createEvmAdapter(WarpChainName8.Base, {
1739
+ var BaseAdapter = createEvmAdapter(WarpChainName8.Base, {
1522
1740
  mainnet: {
1523
1741
  name: WarpChainName8.Base,
1524
1742
  displayName: "Base",
@@ -1552,21 +1770,27 @@ var getBaseAdapter = createEvmAdapter(WarpChainName8.Base, {
1552
1770
  });
1553
1771
 
1554
1772
  // src/chains/combined.ts
1555
- import { WarpChainName as WarpChainName11 } from "@vleap/warps";
1773
+ import { WarpChainName as WarpChainName9 } from "@vleap/warps";
1774
+ var getAllEvmChainNames = () => [
1775
+ WarpChainName9.Ethereum,
1776
+ WarpChainName9.Base,
1777
+ WarpChainName9.Arbitrum,
1778
+ WarpChainName9.Somnia
1779
+ ];
1556
1780
 
1557
1781
  // src/chains/ethereum.ts
1558
- import { WarpChainName as WarpChainName9 } from "@vleap/warps";
1782
+ import { WarpChainName as WarpChainName10 } from "@vleap/warps";
1559
1783
  var NativeTokenEth = {
1560
- chain: WarpChainName9.Ethereum,
1784
+ chain: WarpChainName10.Ethereum,
1561
1785
  identifier: "ETH",
1562
1786
  symbol: "ETH",
1563
1787
  name: "Ether",
1564
1788
  decimals: 18,
1565
1789
  logoUrl: "https://joai.ai/images/tokens/eth.svg"
1566
1790
  };
1567
- var getEthereumAdapter = createEvmAdapter(WarpChainName9.Ethereum, {
1791
+ var EthereumAdapter = createEvmAdapter(WarpChainName10.Ethereum, {
1568
1792
  mainnet: {
1569
- name: WarpChainName9.Ethereum,
1793
+ name: WarpChainName10.Ethereum,
1570
1794
  displayName: "Ethereum Mainnet",
1571
1795
  chainId: "1",
1572
1796
  blockTime: 12e3,
@@ -1576,7 +1800,7 @@ var getEthereumAdapter = createEvmAdapter(WarpChainName9.Ethereum, {
1576
1800
  nativeToken: NativeTokenEth
1577
1801
  },
1578
1802
  testnet: {
1579
- name: WarpChainName9.Ethereum,
1803
+ name: WarpChainName10.Ethereum,
1580
1804
  displayName: "Ethereum Sepolia",
1581
1805
  chainId: "11155111",
1582
1806
  blockTime: 12e3,
@@ -1586,7 +1810,7 @@ var getEthereumAdapter = createEvmAdapter(WarpChainName9.Ethereum, {
1586
1810
  nativeToken: NativeTokenEth
1587
1811
  },
1588
1812
  devnet: {
1589
- name: WarpChainName9.Ethereum,
1813
+ name: WarpChainName10.Ethereum,
1590
1814
  displayName: "Ethereum Sepolia",
1591
1815
  chainId: "11155111",
1592
1816
  blockTime: 12e3,
@@ -1597,10 +1821,13 @@ var getEthereumAdapter = createEvmAdapter(WarpChainName9.Ethereum, {
1597
1821
  }
1598
1822
  });
1599
1823
 
1824
+ // src/adapters.ts
1825
+ import { withAdapter } from "@vleap/warps";
1826
+
1600
1827
  // src/chains/somnia.ts
1601
- import { WarpChainName as WarpChainName10 } from "@vleap/warps";
1828
+ import { WarpChainName as WarpChainName11 } from "@vleap/warps";
1602
1829
  var NativeTokenSomi = {
1603
- chain: WarpChainName10.Somnia,
1830
+ chain: WarpChainName11.Somnia,
1604
1831
  identifier: "SOMI",
1605
1832
  symbol: "SOMI",
1606
1833
  name: "Somnia",
@@ -1608,16 +1835,16 @@ var NativeTokenSomi = {
1608
1835
  logoUrl: "https://assets.coingecko.com/coins/images/68061/standard/somniacg.png?1754641117"
1609
1836
  };
1610
1837
  var NativeTokenStt = {
1611
- chain: WarpChainName10.Somnia,
1838
+ chain: WarpChainName11.Somnia,
1612
1839
  identifier: "STT",
1613
1840
  symbol: "STT",
1614
1841
  name: "Somnia Testnet Token",
1615
1842
  decimals: 18,
1616
1843
  logoUrl: "https://assets.coingecko.com/coins/images/68061/standard/somniacg.png?1754641117"
1617
1844
  };
1618
- var getSomniaAdapter = createEvmAdapter(WarpChainName10.Somnia, {
1845
+ var SomniaAdapter = createEvmAdapter(WarpChainName11.Somnia, {
1619
1846
  mainnet: {
1620
- name: WarpChainName10.Somnia,
1847
+ name: WarpChainName11.Somnia,
1621
1848
  displayName: "Somnia Mainnet",
1622
1849
  chainId: "5031",
1623
1850
  blockTime: 100,
@@ -1627,7 +1854,7 @@ var getSomniaAdapter = createEvmAdapter(WarpChainName10.Somnia, {
1627
1854
  nativeToken: NativeTokenSomi
1628
1855
  },
1629
1856
  testnet: {
1630
- name: WarpChainName10.Somnia,
1857
+ name: WarpChainName11.Somnia,
1631
1858
  displayName: "Somnia Testnet",
1632
1859
  chainId: "50312",
1633
1860
  blockTime: 100,
@@ -1637,7 +1864,7 @@ var getSomniaAdapter = createEvmAdapter(WarpChainName10.Somnia, {
1637
1864
  nativeToken: NativeTokenStt
1638
1865
  },
1639
1866
  devnet: {
1640
- name: WarpChainName10.Somnia,
1867
+ name: WarpChainName11.Somnia,
1641
1868
  displayName: "Somnia Testnet",
1642
1869
  chainId: "50312",
1643
1870
  blockTime: 100,
@@ -1648,30 +1875,29 @@ var getSomniaAdapter = createEvmAdapter(WarpChainName10.Somnia, {
1648
1875
  }
1649
1876
  });
1650
1877
 
1651
- // src/chains/combined.ts
1652
- var getAllEvmAdapters = (config, fallback) => [
1653
- getEthereumAdapter(config, fallback),
1654
- getBaseAdapter(config, fallback),
1655
- getArbitrumAdapter(config, fallback),
1656
- getSomniaAdapter(config, fallback)
1657
- ];
1658
- var getAllEvmChainNames = () => [
1659
- WarpChainName11.Ethereum,
1660
- WarpChainName11.Base,
1661
- WarpChainName11.Arbitrum,
1662
- WarpChainName11.Somnia
1878
+ // src/adapters.ts
1879
+ var getAllEvmAdapters = (fallbackFactory) => [
1880
+ withAdapter(EthereumAdapter, fallbackFactory),
1881
+ withAdapter(BaseAdapter, fallbackFactory),
1882
+ withAdapter(ArbitrumAdapter, fallbackFactory),
1883
+ withAdapter(SomniaAdapter, fallbackFactory)
1663
1884
  ];
1664
1885
  export {
1886
+ ArbitrumAdapter,
1665
1887
  ArbitrumExplorers,
1888
+ BaseAdapter,
1666
1889
  BaseExplorers,
1890
+ EthereumAdapter,
1667
1891
  EthereumExplorers,
1892
+ EvmChainIdMap,
1893
+ EvmChainIds,
1668
1894
  EvmExplorers,
1669
1895
  ExplorerUrls,
1670
1896
  KnownTokens,
1671
1897
  NativeTokenArb,
1672
1898
  NativeTokenBase,
1673
1899
  NativeTokenEth,
1674
- UniswapService,
1900
+ SupportedEvmChainIds,
1675
1901
  WarpEvmConstants,
1676
1902
  WarpEvmDataLoader,
1677
1903
  WarpEvmExecutor,
@@ -1683,9 +1909,6 @@ export {
1683
1909
  findKnownTokenById,
1684
1910
  getAllEvmAdapters,
1685
1911
  getAllEvmChainNames,
1686
- getArbitrumAdapter,
1687
- getBaseAdapter,
1688
- getEthereumAdapter,
1689
1912
  getKnownTokensForChain
1690
1913
  };
1691
1914
  //# sourceMappingURL=index.mjs.map