@vleap/warps-adapter-evm 0.2.0-alpha.8 → 0.2.0-alpha.9
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.mts +2 -19
- package/dist/index.d.ts +2 -19
- package/dist/index.js +22 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +22 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChain, AdapterFactory, WarpClientConfig, Adapter, WarpChainEnv,
|
|
1
|
+
import { WarpChain, AdapterFactory, WarpClientConfig, Adapter, WarpChainEnv, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpChainInfo, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
|
|
4
4
|
declare const ChainNameArbitrum: WarpChain;
|
|
@@ -82,23 +82,6 @@ declare const EvmExplorers: {
|
|
|
82
82
|
};
|
|
83
83
|
declare const ExplorerUrls: Record<ExplorerName, string>;
|
|
84
84
|
|
|
85
|
-
declare class WarpEvmBuilder implements CombinedWarpBuilder {
|
|
86
|
-
private readonly config;
|
|
87
|
-
private warp;
|
|
88
|
-
private actions;
|
|
89
|
-
constructor(config: WarpClientConfig);
|
|
90
|
-
createFromRaw(encoded: string): Promise<Warp>;
|
|
91
|
-
setTitle(title: string): BaseWarpBuilder;
|
|
92
|
-
setDescription(description: string): BaseWarpBuilder;
|
|
93
|
-
setPreview(preview: string): BaseWarpBuilder;
|
|
94
|
-
setActions(actions: any[]): BaseWarpBuilder;
|
|
95
|
-
addAction(action: any): BaseWarpBuilder;
|
|
96
|
-
build(): Promise<Warp>;
|
|
97
|
-
createInscriptionTransaction(warp: Warp): ethers.TransactionRequest;
|
|
98
|
-
createFromTransaction(tx: ethers.TransactionResponse, validate?: boolean): Promise<Warp>;
|
|
99
|
-
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
85
|
declare class WarpEvmExecutor implements AdapterWarpExecutor {
|
|
103
86
|
private readonly config;
|
|
104
87
|
private readonly serializer;
|
|
@@ -154,4 +137,4 @@ declare class WarpEvmSerializer implements AdapterWarpSerializer {
|
|
|
154
137
|
private parseNativeValue;
|
|
155
138
|
}
|
|
156
139
|
|
|
157
|
-
export { ArbitrumExplorers, BaseExplorers, ChainNameArbitrum, ChainNameBase, ChainNameEthereum, EVM_CHAIN_CONFIGS, EthereumExplorers, type EvmChainConfig, EvmExplorers, type ExplorerName, ExplorerUrls,
|
|
140
|
+
export { ArbitrumExplorers, BaseExplorers, ChainNameArbitrum, ChainNameBase, ChainNameEthereum, EVM_CHAIN_CONFIGS, EthereumExplorers, type EvmChainConfig, EvmExplorers, type ExplorerName, ExplorerUrls, WarpEvmConstants, WarpEvmExecutor, WarpEvmExplorer, WarpEvmResults, WarpEvmSerializer, getAllEvmAdapters, getAllEvmChainNames, getArbitrumAdapter, getBaseAdapter, getEthereumAdapter, getEvmApiUrl, getEvmChainConfig, getEvmExplorerUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WarpChain, AdapterFactory, WarpClientConfig, Adapter, WarpChainEnv,
|
|
1
|
+
import { WarpChain, AdapterFactory, WarpClientConfig, Adapter, WarpChainEnv, AdapterWarpExecutor, WarpExecutable, WarpExecution, WarpChainInfo, WarpActionInputType, AdapterWarpExplorer, AdapterWarpResults, Warp, ResolvedInput, WarpExecutionResults, AdapterWarpSerializer, WarpSerializer, WarpNativeValue, BaseWarpActionInputType, WarpAdapterGenericType } from '@vleap/warps';
|
|
2
2
|
import { ethers } from 'ethers';
|
|
3
3
|
|
|
4
4
|
declare const ChainNameArbitrum: WarpChain;
|
|
@@ -82,23 +82,6 @@ declare const EvmExplorers: {
|
|
|
82
82
|
};
|
|
83
83
|
declare const ExplorerUrls: Record<ExplorerName, string>;
|
|
84
84
|
|
|
85
|
-
declare class WarpEvmBuilder implements CombinedWarpBuilder {
|
|
86
|
-
private readonly config;
|
|
87
|
-
private warp;
|
|
88
|
-
private actions;
|
|
89
|
-
constructor(config: WarpClientConfig);
|
|
90
|
-
createFromRaw(encoded: string): Promise<Warp>;
|
|
91
|
-
setTitle(title: string): BaseWarpBuilder;
|
|
92
|
-
setDescription(description: string): BaseWarpBuilder;
|
|
93
|
-
setPreview(preview: string): BaseWarpBuilder;
|
|
94
|
-
setActions(actions: any[]): BaseWarpBuilder;
|
|
95
|
-
addAction(action: any): BaseWarpBuilder;
|
|
96
|
-
build(): Promise<Warp>;
|
|
97
|
-
createInscriptionTransaction(warp: Warp): ethers.TransactionRequest;
|
|
98
|
-
createFromTransaction(tx: ethers.TransactionResponse, validate?: boolean): Promise<Warp>;
|
|
99
|
-
createFromTransactionHash(hash: string, cache?: WarpCacheConfig): Promise<Warp | null>;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
85
|
declare class WarpEvmExecutor implements AdapterWarpExecutor {
|
|
103
86
|
private readonly config;
|
|
104
87
|
private readonly serializer;
|
|
@@ -154,4 +137,4 @@ declare class WarpEvmSerializer implements AdapterWarpSerializer {
|
|
|
154
137
|
private parseNativeValue;
|
|
155
138
|
}
|
|
156
139
|
|
|
157
|
-
export { ArbitrumExplorers, BaseExplorers, ChainNameArbitrum, ChainNameBase, ChainNameEthereum, EVM_CHAIN_CONFIGS, EthereumExplorers, type EvmChainConfig, EvmExplorers, type ExplorerName, ExplorerUrls,
|
|
140
|
+
export { ArbitrumExplorers, BaseExplorers, ChainNameArbitrum, ChainNameBase, ChainNameEthereum, EVM_CHAIN_CONFIGS, EthereumExplorers, type EvmChainConfig, EvmExplorers, type ExplorerName, ExplorerUrls, WarpEvmConstants, WarpEvmExecutor, WarpEvmExplorer, WarpEvmResults, WarpEvmSerializer, getAllEvmAdapters, getAllEvmChainNames, getArbitrumAdapter, getBaseAdapter, getEthereumAdapter, getEvmApiUrl, getEvmChainConfig, getEvmExplorerUrl };
|
package/dist/index.js
CHANGED
|
@@ -29,7 +29,6 @@ __export(index_exports, {
|
|
|
29
29
|
EthereumExplorers: () => EthereumExplorers,
|
|
30
30
|
EvmExplorers: () => EvmExplorers,
|
|
31
31
|
ExplorerUrls: () => ExplorerUrls,
|
|
32
|
-
WarpEvmBuilder: () => WarpEvmBuilder,
|
|
33
32
|
WarpEvmConstants: () => WarpEvmConstants,
|
|
34
33
|
WarpEvmExecutor: () => WarpEvmExecutor,
|
|
35
34
|
WarpEvmExplorer: () => WarpEvmExplorer,
|
|
@@ -46,7 +45,7 @@ __export(index_exports, {
|
|
|
46
45
|
});
|
|
47
46
|
module.exports = __toCommonJS(index_exports);
|
|
48
47
|
|
|
49
|
-
// src/
|
|
48
|
+
// src/WarpEvmDataLoader.ts
|
|
50
49
|
var import_ethers = require("ethers");
|
|
51
50
|
|
|
52
51
|
// src/config.ts
|
|
@@ -149,103 +148,7 @@ var getEvmExplorerUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
|
149
148
|
return getEvmChainConfig(chain, env).explorerUrl;
|
|
150
149
|
};
|
|
151
150
|
|
|
152
|
-
// src/WarpEvmBuilder.ts
|
|
153
|
-
var WarpEvmBuilder = class {
|
|
154
|
-
constructor(config) {
|
|
155
|
-
this.config = config;
|
|
156
|
-
this.warp = {};
|
|
157
|
-
this.actions = [];
|
|
158
|
-
}
|
|
159
|
-
async createFromRaw(encoded) {
|
|
160
|
-
try {
|
|
161
|
-
const decoded = JSON.parse(encoded);
|
|
162
|
-
return decoded;
|
|
163
|
-
} catch (error) {
|
|
164
|
-
throw new Error(`Failed to decode warp from raw data: ${error}`);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
setTitle(title) {
|
|
168
|
-
this.warp.title = title;
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
setDescription(description) {
|
|
172
|
-
this.warp.description = description;
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
setPreview(preview) {
|
|
176
|
-
this.warp.preview = preview;
|
|
177
|
-
return this;
|
|
178
|
-
}
|
|
179
|
-
setActions(actions) {
|
|
180
|
-
this.actions = actions;
|
|
181
|
-
return this;
|
|
182
|
-
}
|
|
183
|
-
addAction(action) {
|
|
184
|
-
this.actions.push(action);
|
|
185
|
-
return this;
|
|
186
|
-
}
|
|
187
|
-
async build() {
|
|
188
|
-
if (!this.warp.title) {
|
|
189
|
-
throw new Error("Warp title is required");
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
protocol: "warp",
|
|
193
|
-
name: this.warp.name || "evm-warp",
|
|
194
|
-
title: this.warp.title,
|
|
195
|
-
description: this.warp.description || null,
|
|
196
|
-
preview: this.warp.preview || null,
|
|
197
|
-
actions: this.actions,
|
|
198
|
-
meta: {
|
|
199
|
-
chain: "evm",
|
|
200
|
-
hash: import_ethers.ethers.keccak256(import_ethers.ethers.toUtf8Bytes(this.warp.title)),
|
|
201
|
-
creator: this.config.user?.wallets?.evm || "",
|
|
202
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
createInscriptionTransaction(warp) {
|
|
207
|
-
const warpData = JSON.stringify(warp);
|
|
208
|
-
const data = import_ethers.ethers.toUtf8Bytes(warpData);
|
|
209
|
-
return {
|
|
210
|
-
data: import_ethers.ethers.hexlify(data)
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
async createFromTransaction(tx, validate) {
|
|
214
|
-
if (!tx.data || tx.data === "0x") {
|
|
215
|
-
throw new Error("Transaction has no data");
|
|
216
|
-
}
|
|
217
|
-
try {
|
|
218
|
-
const data = import_ethers.ethers.toUtf8String(tx.data);
|
|
219
|
-
const warp = JSON.parse(data);
|
|
220
|
-
if (validate) {
|
|
221
|
-
if (!warp.protocol || warp.protocol !== "warp") {
|
|
222
|
-
throw new Error("Invalid warp protocol");
|
|
223
|
-
}
|
|
224
|
-
if (!warp.title) {
|
|
225
|
-
throw new Error("Warp title is required");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return warp;
|
|
229
|
-
} catch (error) {
|
|
230
|
-
throw new Error(`Failed to create warp from transaction: ${error}`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
async createFromTransactionHash(hash, cache) {
|
|
234
|
-
try {
|
|
235
|
-
const provider = new import_ethers.ethers.JsonRpcProvider(getEvmApiUrl(this.config.env));
|
|
236
|
-
const tx = await provider.getTransaction(hash);
|
|
237
|
-
if (!tx) {
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
return await this.createFromTransaction(tx);
|
|
241
|
-
} catch (error) {
|
|
242
|
-
return null;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
|
|
247
151
|
// src/WarpEvmDataLoader.ts
|
|
248
|
-
var import_ethers2 = require("ethers");
|
|
249
152
|
var ERC20_ABI = [
|
|
250
153
|
"function balanceOf(address owner) view returns (uint256)",
|
|
251
154
|
"function decimals() view returns (uint8)",
|
|
@@ -325,7 +228,7 @@ var WarpEvmDataLoader = class {
|
|
|
325
228
|
constructor(config, chain) {
|
|
326
229
|
this.config = config;
|
|
327
230
|
this.chain = chain;
|
|
328
|
-
this.provider = new
|
|
231
|
+
this.provider = new import_ethers.ethers.JsonRpcProvider(getEvmApiUrl(this.config.env, this.chain.name));
|
|
329
232
|
this.chainConfig = getEvmChainConfig(this.chain.name, this.config.env);
|
|
330
233
|
}
|
|
331
234
|
async getAccount(address) {
|
|
@@ -398,7 +301,7 @@ var WarpEvmDataLoader = class {
|
|
|
398
301
|
}
|
|
399
302
|
async getTokenBalance(address, tokenAddress) {
|
|
400
303
|
try {
|
|
401
|
-
const contract = new
|
|
304
|
+
const contract = new import_ethers.ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
|
|
402
305
|
const balance = await contract.balanceOf(address);
|
|
403
306
|
return balance;
|
|
404
307
|
} catch (error) {
|
|
@@ -407,7 +310,7 @@ var WarpEvmDataLoader = class {
|
|
|
407
310
|
}
|
|
408
311
|
async getTokenMetadata(tokenAddress) {
|
|
409
312
|
try {
|
|
410
|
-
const contract = new
|
|
313
|
+
const contract = new import_ethers.ethers.Contract(tokenAddress, ERC20_ABI, this.provider);
|
|
411
314
|
const [name, symbol, decimals] = await Promise.all([contract.name(), contract.symbol(), contract.decimals()]);
|
|
412
315
|
return {
|
|
413
316
|
name: name || "Unknown Token",
|
|
@@ -426,10 +329,10 @@ var WarpEvmDataLoader = class {
|
|
|
426
329
|
fromBlock,
|
|
427
330
|
toBlock: currentBlock,
|
|
428
331
|
topics: [
|
|
429
|
-
|
|
332
|
+
import_ethers.ethers.id("Transfer(address,address,uint256)"),
|
|
430
333
|
null,
|
|
431
334
|
// from address (any)
|
|
432
|
-
|
|
335
|
+
import_ethers.ethers.zeroPadValue(address, 32)
|
|
433
336
|
// to address (our target)
|
|
434
337
|
]
|
|
435
338
|
};
|
|
@@ -479,7 +382,7 @@ var WarpEvmDataLoader = class {
|
|
|
479
382
|
|
|
480
383
|
// src/WarpEvmExecutor.ts
|
|
481
384
|
var import_warps3 = require("@vleap/warps");
|
|
482
|
-
var
|
|
385
|
+
var import_ethers3 = require("ethers");
|
|
483
386
|
|
|
484
387
|
// src/constants.ts
|
|
485
388
|
var WarpEvmConstants = {
|
|
@@ -559,7 +462,7 @@ var import_warps2 = require("@vleap/warps");
|
|
|
559
462
|
|
|
560
463
|
// src/WarpEvmSerializer.ts
|
|
561
464
|
var import_warps = require("@vleap/warps");
|
|
562
|
-
var
|
|
465
|
+
var import_ethers2 = require("ethers");
|
|
563
466
|
var SplitParamsRegex = new RegExp(`${import_warps.WarpConstants.ArgParamsSeparator}(.*)`);
|
|
564
467
|
var WarpEvmSerializer = class {
|
|
565
468
|
constructor() {
|
|
@@ -567,10 +470,10 @@ var WarpEvmSerializer = class {
|
|
|
567
470
|
}
|
|
568
471
|
typedToString(value) {
|
|
569
472
|
if (typeof value === "string") {
|
|
570
|
-
if (
|
|
473
|
+
if (import_ethers2.ethers.isAddress(value)) {
|
|
571
474
|
return `address:${value}`;
|
|
572
475
|
}
|
|
573
|
-
if (
|
|
476
|
+
if (import_ethers2.ethers.isHexString(value) && !import_ethers2.ethers.isAddress(value)) {
|
|
574
477
|
return `hex:${value}`;
|
|
575
478
|
}
|
|
576
479
|
return `string:${value}`;
|
|
@@ -778,7 +681,7 @@ var WarpEvmExecutor = class {
|
|
|
778
681
|
constructor(config) {
|
|
779
682
|
this.config = config;
|
|
780
683
|
this.serializer = new WarpEvmSerializer();
|
|
781
|
-
this.provider = new
|
|
684
|
+
this.provider = new import_ethers3.ethers.JsonRpcProvider(getEvmApiUrl(config.env));
|
|
782
685
|
this.results = new WarpEvmResults(config);
|
|
783
686
|
}
|
|
784
687
|
async createTransaction(executable) {
|
|
@@ -799,7 +702,7 @@ var WarpEvmExecutor = class {
|
|
|
799
702
|
async createTransferTransaction(executable) {
|
|
800
703
|
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
801
704
|
if (!userWallet) throw new Error("WarpEvmExecutor: createTransfer - user address not set");
|
|
802
|
-
if (!
|
|
705
|
+
if (!import_ethers3.ethers.isAddress(executable.destination)) {
|
|
803
706
|
throw new Error(`WarpEvmExecutor: Invalid destination address: ${executable.destination}`);
|
|
804
707
|
}
|
|
805
708
|
if (executable.value < 0) {
|
|
@@ -819,14 +722,14 @@ var WarpEvmExecutor = class {
|
|
|
819
722
|
if (!action || !("func" in action) || !action.func) {
|
|
820
723
|
throw new Error("WarpEvmExecutor: Contract action must have a function name");
|
|
821
724
|
}
|
|
822
|
-
if (!
|
|
725
|
+
if (!import_ethers3.ethers.isAddress(executable.destination)) {
|
|
823
726
|
throw new Error(`WarpEvmExecutor: Invalid contract address: ${executable.destination}`);
|
|
824
727
|
}
|
|
825
728
|
if (executable.value < 0) {
|
|
826
729
|
throw new Error(`WarpEvmExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
827
730
|
}
|
|
828
731
|
try {
|
|
829
|
-
const iface = new
|
|
732
|
+
const iface = new import_ethers3.ethers.Interface([`function ${action.func}`]);
|
|
830
733
|
const encodedData = iface.encodeFunctionData(action.func, executable.args);
|
|
831
734
|
const tx = {
|
|
832
735
|
to: executable.destination,
|
|
@@ -846,11 +749,11 @@ var WarpEvmExecutor = class {
|
|
|
846
749
|
if (!action.func) {
|
|
847
750
|
throw new Error("WarpEvmExecutor: Query action must have a function name");
|
|
848
751
|
}
|
|
849
|
-
if (!
|
|
752
|
+
if (!import_ethers3.ethers.isAddress(executable.destination)) {
|
|
850
753
|
throw new Error(`WarpEvmExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
851
754
|
}
|
|
852
755
|
try {
|
|
853
|
-
const iface = new
|
|
756
|
+
const iface = new import_ethers3.ethers.Interface([`function ${action.func}`]);
|
|
854
757
|
const encodedData = iface.encodeFunctionData(action.func, executable.args);
|
|
855
758
|
const result = await this.provider.call({
|
|
856
759
|
to: executable.destination,
|
|
@@ -894,12 +797,12 @@ var WarpEvmExecutor = class {
|
|
|
894
797
|
const typedValue = this.serializer.stringToTyped(value);
|
|
895
798
|
switch (type) {
|
|
896
799
|
case "address":
|
|
897
|
-
if (!
|
|
800
|
+
if (!import_ethers3.ethers.isAddress(typedValue)) {
|
|
898
801
|
throw new Error(`Invalid address format: ${typedValue}`);
|
|
899
802
|
}
|
|
900
|
-
return
|
|
803
|
+
return import_ethers3.ethers.getAddress(typedValue);
|
|
901
804
|
case "hex":
|
|
902
|
-
if (!
|
|
805
|
+
if (!import_ethers3.ethers.isHexString(typedValue)) {
|
|
903
806
|
throw new Error(`Invalid hex format: ${typedValue}`);
|
|
904
807
|
}
|
|
905
808
|
return typedValue;
|
|
@@ -947,7 +850,7 @@ var WarpEvmExecutor = class {
|
|
|
947
850
|
return {
|
|
948
851
|
...tx,
|
|
949
852
|
gasLimit: gasEstimate,
|
|
950
|
-
gasPrice:
|
|
853
|
+
gasPrice: import_ethers3.ethers.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
|
|
951
854
|
};
|
|
952
855
|
}
|
|
953
856
|
} catch (error) {
|
|
@@ -960,7 +863,7 @@ var WarpEvmExecutor = class {
|
|
|
960
863
|
return {
|
|
961
864
|
...tx,
|
|
962
865
|
gasLimit: defaultGasLimit,
|
|
963
|
-
gasPrice:
|
|
866
|
+
gasPrice: import_ethers3.ethers.parseUnits(WarpEvmConstants.GasPrice.Default, "wei")
|
|
964
867
|
};
|
|
965
868
|
}
|
|
966
869
|
}
|
|
@@ -1063,7 +966,7 @@ var createEvmAdapter = (chainName, chainPrefix, chainInfos) => {
|
|
|
1063
966
|
chain: chainName,
|
|
1064
967
|
chainInfo: chainInfos[config.env],
|
|
1065
968
|
prefix: chainPrefix,
|
|
1066
|
-
builder: () =>
|
|
969
|
+
builder: () => fallback.builder(),
|
|
1067
970
|
executor: new WarpEvmExecutor(config),
|
|
1068
971
|
results: new WarpEvmResults(config),
|
|
1069
972
|
serializer: new WarpEvmSerializer(),
|
|
@@ -1190,7 +1093,6 @@ var getAllEvmChainNames = () => [ChainNameArbitrum, ChainNameBase, ChainNameEthe
|
|
|
1190
1093
|
EthereumExplorers,
|
|
1191
1094
|
EvmExplorers,
|
|
1192
1095
|
ExplorerUrls,
|
|
1193
|
-
WarpEvmBuilder,
|
|
1194
1096
|
WarpEvmConstants,
|
|
1195
1097
|
WarpEvmExecutor,
|
|
1196
1098
|
WarpEvmExplorer,
|