@vleap/warps-adapter-evm 0.2.0-beta.63 → 0.2.0-beta.65
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 +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +120 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +131 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -99,7 +99,11 @@ var UniswapService = _UniswapService;
|
|
|
99
99
|
|
|
100
100
|
// src/providers/PrivateKeyWalletProvider.ts
|
|
101
101
|
import { ethers } from "ethers";
|
|
102
|
-
import {
|
|
102
|
+
import {
|
|
103
|
+
getWarpWalletMnemonicFromConfig,
|
|
104
|
+
getWarpWalletPrivateKeyFromConfig,
|
|
105
|
+
setWarpWalletInConfig
|
|
106
|
+
} from "@vleap/warps";
|
|
103
107
|
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
104
108
|
constructor(config, chain) {
|
|
105
109
|
this.config = config;
|
|
@@ -145,16 +149,39 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
|
145
149
|
getWalletInstance() {
|
|
146
150
|
return this.getWallet();
|
|
147
151
|
}
|
|
148
|
-
|
|
152
|
+
async importFromMnemonic(mnemonic) {
|
|
149
153
|
const wallet = ethers.Wallet.fromPhrase(mnemonic);
|
|
150
|
-
|
|
154
|
+
const walletDetails = {
|
|
155
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
156
|
+
address: wallet.address,
|
|
157
|
+
privateKey: wallet.privateKey,
|
|
158
|
+
mnemonic
|
|
159
|
+
};
|
|
160
|
+
setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
|
|
161
|
+
return walletDetails;
|
|
162
|
+
}
|
|
163
|
+
async importFromPrivateKey(privateKey) {
|
|
164
|
+
const wallet = new ethers.Wallet(privateKey);
|
|
165
|
+
const walletDetails = {
|
|
151
166
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
152
167
|
address: wallet.address,
|
|
153
168
|
privateKey: wallet.privateKey,
|
|
154
169
|
mnemonic: null
|
|
155
170
|
};
|
|
171
|
+
setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
|
|
172
|
+
return walletDetails;
|
|
156
173
|
}
|
|
157
|
-
|
|
174
|
+
async export() {
|
|
175
|
+
const wallet = this.getWallet();
|
|
176
|
+
const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
|
|
177
|
+
return {
|
|
178
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
179
|
+
address: wallet.address,
|
|
180
|
+
privateKey: wallet.privateKey,
|
|
181
|
+
mnemonic: mnemonic || null
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async generate() {
|
|
158
185
|
const wallet = ethers.Wallet.createRandom();
|
|
159
186
|
return {
|
|
160
187
|
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
@@ -176,7 +203,11 @@ var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
|
176
203
|
|
|
177
204
|
// src/providers/MnemonicWalletProvider.ts
|
|
178
205
|
import { ethers as ethers2 } from "ethers";
|
|
179
|
-
import {
|
|
206
|
+
import {
|
|
207
|
+
getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
|
|
208
|
+
getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
|
|
209
|
+
setWarpWalletInConfig as setWarpWalletInConfig2
|
|
210
|
+
} from "@vleap/warps";
|
|
180
211
|
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
181
212
|
constructor(config, chain) {
|
|
182
213
|
this.config = config;
|
|
@@ -222,16 +253,40 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
222
253
|
getWalletInstance() {
|
|
223
254
|
return this.getWallet();
|
|
224
255
|
}
|
|
225
|
-
|
|
256
|
+
async importFromMnemonic(mnemonic) {
|
|
226
257
|
const wallet = ethers2.Wallet.fromPhrase(mnemonic);
|
|
227
|
-
|
|
258
|
+
const walletDetails = {
|
|
228
259
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
229
260
|
address: wallet.address,
|
|
230
|
-
privateKey:
|
|
261
|
+
privateKey: wallet.privateKey,
|
|
231
262
|
mnemonic
|
|
232
263
|
};
|
|
264
|
+
setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
|
|
265
|
+
return walletDetails;
|
|
266
|
+
}
|
|
267
|
+
async importFromPrivateKey(privateKey) {
|
|
268
|
+
const wallet = new ethers2.Wallet(privateKey);
|
|
269
|
+
const walletDetails = {
|
|
270
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
271
|
+
address: wallet.address,
|
|
272
|
+
privateKey: wallet.privateKey,
|
|
273
|
+
mnemonic: null
|
|
274
|
+
};
|
|
275
|
+
setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
|
|
276
|
+
return walletDetails;
|
|
277
|
+
}
|
|
278
|
+
async export() {
|
|
279
|
+
const wallet = this.getWallet();
|
|
280
|
+
const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
|
|
281
|
+
const privateKey = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
|
|
282
|
+
return {
|
|
283
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
284
|
+
address: wallet.address,
|
|
285
|
+
privateKey: privateKey || null,
|
|
286
|
+
mnemonic: mnemonic || null
|
|
287
|
+
};
|
|
233
288
|
}
|
|
234
|
-
generate() {
|
|
289
|
+
async generate() {
|
|
235
290
|
const wallet = ethers2.Wallet.createRandom();
|
|
236
291
|
return {
|
|
237
292
|
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
@@ -242,7 +297,7 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
|
242
297
|
}
|
|
243
298
|
getWallet() {
|
|
244
299
|
if (this.wallet) return this.wallet;
|
|
245
|
-
const mnemonic =
|
|
300
|
+
const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
|
|
246
301
|
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
247
302
|
this.wallet = ethers2.Wallet.fromPhrase(mnemonic);
|
|
248
303
|
return this.wallet;
|
|
@@ -272,11 +327,19 @@ var ReadOnlyWalletProvider = class {
|
|
|
272
327
|
const address = await this.getAddress();
|
|
273
328
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
274
329
|
}
|
|
275
|
-
|
|
330
|
+
async importFromMnemonic(mnemonic) {
|
|
276
331
|
const address = getWarpWalletAddressFromConfig(this.config, this.chain.name);
|
|
277
332
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
278
333
|
}
|
|
279
|
-
|
|
334
|
+
async importFromPrivateKey(privateKey) {
|
|
335
|
+
const address = getWarpWalletAddressFromConfig(this.config, this.chain.name);
|
|
336
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
337
|
+
}
|
|
338
|
+
async export() {
|
|
339
|
+
const address = getWarpWalletAddressFromConfig(this.config, this.chain.name);
|
|
340
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
341
|
+
}
|
|
342
|
+
async generate() {
|
|
280
343
|
const address = getWarpWalletAddressFromConfig(this.config, this.chain.name);
|
|
281
344
|
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
282
345
|
}
|
|
@@ -1597,37 +1660,43 @@ var WarpEvmWallet = class {
|
|
|
1597
1660
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1598
1661
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1599
1662
|
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
1663
|
+
if (tx.nonce === void 0) {
|
|
1664
|
+
const address = this.getAddress();
|
|
1665
|
+
if (address) {
|
|
1666
|
+
tx.nonce = await this.provider.getTransactionCount(address, "pending");
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1600
1669
|
return await this.walletProvider.signTransaction(tx);
|
|
1601
1670
|
}
|
|
1602
1671
|
async signTransactions(txs) {
|
|
1603
1672
|
if (txs.length === 0) return [];
|
|
1604
1673
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1674
|
+
const address = this.getAddress();
|
|
1675
|
+
if (!address) throw new Error("No wallet address available");
|
|
1676
|
+
if (txs.length > 1) {
|
|
1677
|
+
const currentNonce = await this.provider.getTransactionCount(address, "pending");
|
|
1678
|
+
const signedTxs2 = [];
|
|
1679
|
+
for (let i = 0; i < txs.length; i++) {
|
|
1680
|
+
const tx = { ...txs[i] };
|
|
1681
|
+
if (tx.nonce === void 0) {
|
|
1613
1682
|
tx.nonce = currentNonce + i;
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1683
|
+
}
|
|
1684
|
+
if (i > 0 && (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider)) {
|
|
1685
|
+
const priorityReduction = BigInt(i * 1e9);
|
|
1686
|
+
const minGasPrice = BigInt(1e9);
|
|
1687
|
+
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
|
1688
|
+
tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
|
|
1689
|
+
tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
|
|
1690
|
+
delete tx.gasPrice;
|
|
1691
|
+
} else if (tx.gasPrice) {
|
|
1692
|
+
tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
|
|
1693
|
+
delete tx.maxFeePerGas;
|
|
1694
|
+
delete tx.maxPriorityFeePerGas;
|
|
1626
1695
|
}
|
|
1627
|
-
signedTxs2.push(await this.signTransaction(tx));
|
|
1628
1696
|
}
|
|
1629
|
-
|
|
1697
|
+
signedTxs2.push(await this.signTransaction(tx));
|
|
1630
1698
|
}
|
|
1699
|
+
return signedTxs2;
|
|
1631
1700
|
}
|
|
1632
1701
|
const signedTxs = [];
|
|
1633
1702
|
for (const tx of txs) {
|
|
@@ -1644,6 +1713,10 @@ var WarpEvmWallet = class {
|
|
|
1644
1713
|
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1645
1714
|
if (!tx.signature) throw new Error("Transaction must be signed before sending");
|
|
1646
1715
|
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1716
|
+
if (typeof tx.signature === "string" && tx.signature.startsWith("0x")) {
|
|
1717
|
+
const txResponse = await this.provider.broadcastTransaction(tx.signature);
|
|
1718
|
+
return txResponse.hash;
|
|
1719
|
+
}
|
|
1647
1720
|
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1648
1721
|
const wallet = this.walletProvider.getWalletInstance();
|
|
1649
1722
|
const connectedWallet = wallet.connect(this.provider);
|
|
@@ -1655,13 +1728,21 @@ var WarpEvmWallet = class {
|
|
|
1655
1728
|
async sendTransactions(txs) {
|
|
1656
1729
|
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1657
1730
|
}
|
|
1658
|
-
|
|
1731
|
+
async importFromMnemonic(provider, mnemonic) {
|
|
1732
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1733
|
+
return await walletProvider.importFromMnemonic(mnemonic);
|
|
1734
|
+
}
|
|
1735
|
+
async importFromPrivateKey(provider, privateKey) {
|
|
1736
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1737
|
+
return await walletProvider.importFromPrivateKey(privateKey);
|
|
1738
|
+
}
|
|
1739
|
+
async export(provider) {
|
|
1659
1740
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1660
|
-
return walletProvider.
|
|
1741
|
+
return await walletProvider.export();
|
|
1661
1742
|
}
|
|
1662
|
-
generate(provider) {
|
|
1743
|
+
async generate(provider) {
|
|
1663
1744
|
const walletProvider = this.createProviderForOperation(provider);
|
|
1664
|
-
return walletProvider.generate();
|
|
1745
|
+
return await walletProvider.generate();
|
|
1665
1746
|
}
|
|
1666
1747
|
getAddress() {
|
|
1667
1748
|
return this.cachedAddress;
|
|
@@ -1858,7 +1939,10 @@ var EthereumAdapter = createEvmAdapter(WarpChainName10.Ethereum, {
|
|
|
1858
1939
|
blockTime: 12e3,
|
|
1859
1940
|
addressHrp: "0x",
|
|
1860
1941
|
defaultApiUrl: "https://ethereum-rpc.publicnode.com",
|
|
1861
|
-
logoUrl:
|
|
1942
|
+
logoUrl: {
|
|
1943
|
+
light: "https://joai.ai/images/chains/ethereum-white.svg",
|
|
1944
|
+
dark: "https://joai.ai/images/chains/ethereum-black.svg"
|
|
1945
|
+
},
|
|
1862
1946
|
nativeToken: NativeTokenEth
|
|
1863
1947
|
},
|
|
1864
1948
|
testnet: {
|
|
@@ -1868,7 +1952,10 @@ var EthereumAdapter = createEvmAdapter(WarpChainName10.Ethereum, {
|
|
|
1868
1952
|
blockTime: 12e3,
|
|
1869
1953
|
addressHrp: "0x",
|
|
1870
1954
|
defaultApiUrl: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
1871
|
-
logoUrl:
|
|
1955
|
+
logoUrl: {
|
|
1956
|
+
light: "https://joai.ai/images/chains/ethereum-white.svg",
|
|
1957
|
+
dark: "https://joai.ai/images/chains/ethereum-black.svg"
|
|
1958
|
+
},
|
|
1872
1959
|
nativeToken: NativeTokenEth
|
|
1873
1960
|
},
|
|
1874
1961
|
devnet: {
|
|
@@ -1878,7 +1965,10 @@ var EthereumAdapter = createEvmAdapter(WarpChainName10.Ethereum, {
|
|
|
1878
1965
|
blockTime: 12e3,
|
|
1879
1966
|
addressHrp: "0x",
|
|
1880
1967
|
defaultApiUrl: "https://ethereum-sepolia-rpc.publicnode.com",
|
|
1881
|
-
logoUrl:
|
|
1968
|
+
logoUrl: {
|
|
1969
|
+
light: "https://joai.ai/images/chains/ethereum-white.svg",
|
|
1970
|
+
dark: "https://joai.ai/images/chains/ethereum-black.svg"
|
|
1971
|
+
},
|
|
1882
1972
|
nativeToken: NativeTokenEth
|
|
1883
1973
|
}
|
|
1884
1974
|
});
|