@vleap/warps-adapter-near 0.1.0-beta.10
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 +152 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +1339 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1312 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +45 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1339 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ExplorerUrls: () => ExplorerUrls,
|
|
34
|
+
KnownTokens: () => KnownTokens,
|
|
35
|
+
NativeTokenNear: () => NativeTokenNear,
|
|
36
|
+
NearAdapter: () => NearAdapter,
|
|
37
|
+
NearExplorerMap: () => NearExplorerMap,
|
|
38
|
+
NearExplorerNames: () => NearExplorerNames,
|
|
39
|
+
NearExplorerUrls: () => NearExplorerUrls,
|
|
40
|
+
NearExplorers: () => NearExplorers,
|
|
41
|
+
NearTokens: () => NearTokens,
|
|
42
|
+
WarpNearConstants: () => WarpNearConstants,
|
|
43
|
+
WarpNearDataLoader: () => WarpNearDataLoader,
|
|
44
|
+
WarpNearExecutor: () => WarpNearExecutor,
|
|
45
|
+
WarpNearExplorer: () => WarpNearExplorer,
|
|
46
|
+
WarpNearOutput: () => WarpNearOutput,
|
|
47
|
+
WarpNearSerializer: () => WarpNearSerializer,
|
|
48
|
+
WarpNearWallet: () => WarpNearWallet,
|
|
49
|
+
findKnownTokenById: () => findKnownTokenById,
|
|
50
|
+
getKnownTokensForChain: () => getKnownTokensForChain
|
|
51
|
+
});
|
|
52
|
+
module.exports = __toCommonJS(index_exports);
|
|
53
|
+
|
|
54
|
+
// src/WarpNearDataLoader.ts
|
|
55
|
+
var import_warps = require("@vleap/warps");
|
|
56
|
+
var import_near_api_js = require("near-api-js");
|
|
57
|
+
|
|
58
|
+
// src/constants.ts
|
|
59
|
+
var WarpNearConstants = {
|
|
60
|
+
NativeToken: {
|
|
61
|
+
Identifier: "NEAR",
|
|
62
|
+
Decimals: 24
|
|
63
|
+
},
|
|
64
|
+
Gas: {
|
|
65
|
+
Default: "300000000000000",
|
|
66
|
+
Transfer: "100000000000000",
|
|
67
|
+
FunctionCall: "300000000000000"
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
var NearExplorers = /* @__PURE__ */ ((NearExplorers2) => {
|
|
71
|
+
NearExplorers2["NearExplorer"] = "near_explorer";
|
|
72
|
+
NearExplorers2["NearBlocks"] = "near_blocks";
|
|
73
|
+
NearExplorers2["NearScan"] = "nearscan";
|
|
74
|
+
return NearExplorers2;
|
|
75
|
+
})(NearExplorers || {});
|
|
76
|
+
var NearExplorerMap = {
|
|
77
|
+
near: {
|
|
78
|
+
mainnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */],
|
|
79
|
+
testnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */],
|
|
80
|
+
devnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */]
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
var ExplorerUrls = {
|
|
84
|
+
["near_explorer" /* NearExplorer */]: "https://explorer.near.org",
|
|
85
|
+
["near_blocks" /* NearBlocks */]: "https://nearblocks.io",
|
|
86
|
+
["nearscan" /* NearScan */]: "https://nearscan.io"
|
|
87
|
+
};
|
|
88
|
+
var NearExplorerNames = {
|
|
89
|
+
mainnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */],
|
|
90
|
+
testnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */],
|
|
91
|
+
devnet: ["near_explorer" /* NearExplorer */, "near_blocks" /* NearBlocks */, "nearscan" /* NearScan */]
|
|
92
|
+
};
|
|
93
|
+
var NearExplorerUrls = ExplorerUrls;
|
|
94
|
+
|
|
95
|
+
// src/tokens.ts
|
|
96
|
+
var NearTokens = [];
|
|
97
|
+
var KnownTokens = {
|
|
98
|
+
near: {
|
|
99
|
+
mainnet: NearTokens,
|
|
100
|
+
testnet: NearTokens,
|
|
101
|
+
devnet: NearTokens
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var findKnownTokenById = (chain, env, id) => {
|
|
105
|
+
const chainTokens = KnownTokens[chain]?.[env] || [];
|
|
106
|
+
return chainTokens.find((token) => token.identifier === id) || null;
|
|
107
|
+
};
|
|
108
|
+
var getKnownTokensForChain = (chainName, env = "mainnet") => {
|
|
109
|
+
return KnownTokens[chainName]?.[env] || [];
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/WarpNearDataLoader.ts
|
|
113
|
+
var WarpNearDataLoader = class {
|
|
114
|
+
constructor(config, chain) {
|
|
115
|
+
this.config = config;
|
|
116
|
+
this.chain = chain;
|
|
117
|
+
this.cache = new import_warps.WarpCache(config.cache?.type);
|
|
118
|
+
const providerConfig = (0, import_warps.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
119
|
+
this.nearConfig = {
|
|
120
|
+
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
121
|
+
nodeUrl: providerConfig.url,
|
|
122
|
+
keyStore: new import_near_api_js.keyStores.InMemoryKeyStore()
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async getAccount(address) {
|
|
126
|
+
try {
|
|
127
|
+
const near = await (0, import_near_api_js.connect)(this.nearConfig);
|
|
128
|
+
const account = await near.account(address);
|
|
129
|
+
const balance = await account.getAccountBalance();
|
|
130
|
+
const balanceBigInt = BigInt(balance.total);
|
|
131
|
+
return {
|
|
132
|
+
chain: this.chain.name,
|
|
133
|
+
address,
|
|
134
|
+
balance: balanceBigInt
|
|
135
|
+
};
|
|
136
|
+
} catch (error) {
|
|
137
|
+
throw new Error(`Failed to get account: ${error}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async getAccountAssets(address) {
|
|
141
|
+
try {
|
|
142
|
+
const account = await this.getAccount(address);
|
|
143
|
+
const assets = account.balance > 0n ? [{ ...this.chain.nativeToken, amount: account.balance }] : [];
|
|
144
|
+
const env = this.config.env === "mainnet" ? "mainnet" : this.config.env === "devnet" ? "devnet" : "testnet";
|
|
145
|
+
const knownTokens = getKnownTokensForChain(this.chain.name, env);
|
|
146
|
+
for (const token of knownTokens) {
|
|
147
|
+
try {
|
|
148
|
+
const near = await (0, import_near_api_js.connect)(this.nearConfig);
|
|
149
|
+
const accountObj = await near.account(address);
|
|
150
|
+
const balance = await accountObj.viewFunction({
|
|
151
|
+
contractId: token.identifier,
|
|
152
|
+
methodName: "ft_balance_of",
|
|
153
|
+
args: { account_id: address }
|
|
154
|
+
});
|
|
155
|
+
if (balance && BigInt(balance) > 0n) {
|
|
156
|
+
assets.push({
|
|
157
|
+
...token,
|
|
158
|
+
amount: BigInt(balance)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return assets;
|
|
165
|
+
} catch (error) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async getAsset(identifier) {
|
|
170
|
+
try {
|
|
171
|
+
if (identifier === this.chain.nativeToken.identifier || identifier === WarpNearConstants.NativeToken.Identifier) {
|
|
172
|
+
return this.chain.nativeToken;
|
|
173
|
+
}
|
|
174
|
+
const cacheKey = import_warps.WarpCacheKey.Asset(this.config.env, this.chain.name, identifier);
|
|
175
|
+
const cachedAsset = this.cache.get(cacheKey);
|
|
176
|
+
if (cachedAsset) {
|
|
177
|
+
return cachedAsset;
|
|
178
|
+
}
|
|
179
|
+
const env = this.config.env === "mainnet" ? "mainnet" : this.config.env === "devnet" ? "devnet" : "testnet";
|
|
180
|
+
const knownToken = findKnownTokenById(this.chain.name, env, identifier);
|
|
181
|
+
if (knownToken) {
|
|
182
|
+
return {
|
|
183
|
+
chain: this.chain.name,
|
|
184
|
+
identifier,
|
|
185
|
+
name: knownToken.name,
|
|
186
|
+
symbol: knownToken.symbol,
|
|
187
|
+
amount: 0n,
|
|
188
|
+
decimals: knownToken.decimals,
|
|
189
|
+
logoUrl: knownToken.logoUrl
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
const near = await (0, import_near_api_js.connect)(this.nearConfig);
|
|
194
|
+
const account = await near.account(identifier);
|
|
195
|
+
const metadata = await account.viewFunction({
|
|
196
|
+
contractId: identifier,
|
|
197
|
+
methodName: "ft_metadata",
|
|
198
|
+
args: {}
|
|
199
|
+
});
|
|
200
|
+
const asset = {
|
|
201
|
+
chain: this.chain.name,
|
|
202
|
+
identifier,
|
|
203
|
+
name: metadata.name || "Unknown Token",
|
|
204
|
+
symbol: metadata.symbol || "UNKNOWN",
|
|
205
|
+
amount: 0n,
|
|
206
|
+
decimals: metadata.decimals || WarpNearConstants.NativeToken.Decimals,
|
|
207
|
+
logoUrl: metadata.icon || ""
|
|
208
|
+
};
|
|
209
|
+
this.cache.set(cacheKey, asset, import_warps.CacheTtl.OneHour);
|
|
210
|
+
return asset;
|
|
211
|
+
} catch {
|
|
212
|
+
const asset = {
|
|
213
|
+
chain: this.chain.name,
|
|
214
|
+
identifier,
|
|
215
|
+
name: "Unknown Token",
|
|
216
|
+
symbol: "UNKNOWN",
|
|
217
|
+
amount: 0n,
|
|
218
|
+
decimals: WarpNearConstants.NativeToken.Decimals,
|
|
219
|
+
logoUrl: ""
|
|
220
|
+
};
|
|
221
|
+
return asset;
|
|
222
|
+
}
|
|
223
|
+
} catch (error) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async getAction(identifier, awaitCompleted = false) {
|
|
228
|
+
try {
|
|
229
|
+
const near = await (0, import_near_api_js.connect)(this.nearConfig);
|
|
230
|
+
const txStatus = await near.connection.provider.txStatus(identifier, this.nearConfig.networkId);
|
|
231
|
+
if (!txStatus) return null;
|
|
232
|
+
const statusObj = txStatus.status;
|
|
233
|
+
const isSuccess = statusObj && ("SuccessValue" in statusObj || "SuccessReceiptId" in statusObj);
|
|
234
|
+
const status = isSuccess ? "success" : "failed";
|
|
235
|
+
const transaction = txStatus.transaction;
|
|
236
|
+
const receipt = txStatus.receipts?.[0];
|
|
237
|
+
const sender = transaction.signer_id;
|
|
238
|
+
const receiver = transaction.receiver_id;
|
|
239
|
+
const value = transaction.actions?.[0]?.Transfer?.deposit ? BigInt(transaction.actions[0].Transfer.deposit) : 0n;
|
|
240
|
+
return {
|
|
241
|
+
chain: this.chain.name,
|
|
242
|
+
id: identifier,
|
|
243
|
+
receiver,
|
|
244
|
+
sender,
|
|
245
|
+
value,
|
|
246
|
+
function: transaction.actions?.[0]?.FunctionCall?.method_name || "transfer",
|
|
247
|
+
status,
|
|
248
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
249
|
+
error: status === "failed" ? JSON.stringify(txStatus.status) : null,
|
|
250
|
+
tx: txStatus
|
|
251
|
+
};
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
async getAccountActions(address, options) {
|
|
257
|
+
return [];
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// src/WarpNearExecutor.ts
|
|
262
|
+
var import_warps4 = require("@vleap/warps");
|
|
263
|
+
var import_near_api_js3 = require("near-api-js");
|
|
264
|
+
|
|
265
|
+
// src/WarpNearOutput.ts
|
|
266
|
+
var import_warps3 = require("@vleap/warps");
|
|
267
|
+
var import_near_api_js2 = require("near-api-js");
|
|
268
|
+
|
|
269
|
+
// src/WarpNearSerializer.ts
|
|
270
|
+
var import_warps2 = require("@vleap/warps");
|
|
271
|
+
var WarpNearSerializer = class {
|
|
272
|
+
constructor() {
|
|
273
|
+
this.coreSerializer = new import_warps2.WarpSerializer();
|
|
274
|
+
}
|
|
275
|
+
typedToString(value) {
|
|
276
|
+
if (typeof value === "string") {
|
|
277
|
+
if (value.endsWith(".near") || value.length > 2 && value.length < 65 && /^[a-z0-9._-]+$/.test(value) && !value.includes(" ")) {
|
|
278
|
+
return `address:${value}`;
|
|
279
|
+
}
|
|
280
|
+
if (value.startsWith("0x") || /^[0-9a-fA-F]+$/.test(value)) {
|
|
281
|
+
return `hex:${value}`;
|
|
282
|
+
}
|
|
283
|
+
return `string:${value}`;
|
|
284
|
+
}
|
|
285
|
+
if (typeof value === "number") {
|
|
286
|
+
if (Number.isInteger(value)) {
|
|
287
|
+
if (value >= 0 && value <= 255) return `uint8:${value}`;
|
|
288
|
+
if (value >= 0 && value <= 65535) return `uint16:${value}`;
|
|
289
|
+
if (value >= 0 && value <= 4294967295) return `uint32:${value}`;
|
|
290
|
+
return `uint64:${value}`;
|
|
291
|
+
}
|
|
292
|
+
return `string:${value}`;
|
|
293
|
+
}
|
|
294
|
+
if (typeof value === "bigint") {
|
|
295
|
+
return `biguint:${value.toString()}`;
|
|
296
|
+
}
|
|
297
|
+
if (typeof value === "boolean") {
|
|
298
|
+
return `boolean:${value}`;
|
|
299
|
+
}
|
|
300
|
+
if (value instanceof Uint8Array) {
|
|
301
|
+
return `hex:${Buffer.from(value).toString("hex")}`;
|
|
302
|
+
}
|
|
303
|
+
if (typeof value === "object" && value !== null && "identifier" in value && "amount" in value) {
|
|
304
|
+
const asset = value;
|
|
305
|
+
if (asset.decimals !== void 0) {
|
|
306
|
+
return `asset:${asset.identifier}${import_warps2.WarpConstants.ArgCompositeSeparator}${asset.amount.toString()}${import_warps2.WarpConstants.ArgCompositeSeparator}${asset.decimals}`;
|
|
307
|
+
}
|
|
308
|
+
return `asset:${asset.identifier}${import_warps2.WarpConstants.ArgCompositeSeparator}${asset.amount.toString()}`;
|
|
309
|
+
}
|
|
310
|
+
if (Array.isArray(value)) {
|
|
311
|
+
if (value.length === 0) return `list:string:`;
|
|
312
|
+
const types = value.map((item) => this.typedToString(item).split(import_warps2.WarpConstants.ArgParamsSeparator)[0]);
|
|
313
|
+
const type = types[0];
|
|
314
|
+
const values = value.map((item) => this.typedToString(item).split(import_warps2.WarpConstants.ArgParamsSeparator)[1]);
|
|
315
|
+
return `list:${type}:${values.join(",")}`;
|
|
316
|
+
}
|
|
317
|
+
if (value === null || value === void 0) {
|
|
318
|
+
return `string:null`;
|
|
319
|
+
}
|
|
320
|
+
return `string:${String(value)}`;
|
|
321
|
+
}
|
|
322
|
+
typedToNative(value) {
|
|
323
|
+
const stringValue = this.typedToString(value);
|
|
324
|
+
const [type, ...valueParts] = stringValue.split(import_warps2.WarpConstants.ArgParamsSeparator);
|
|
325
|
+
const nativeValue = valueParts.join(import_warps2.WarpConstants.ArgParamsSeparator);
|
|
326
|
+
return [type, this.parseNativeValue(type, nativeValue)];
|
|
327
|
+
}
|
|
328
|
+
nativeToTyped(type, value) {
|
|
329
|
+
switch (type) {
|
|
330
|
+
case "string":
|
|
331
|
+
return String(value);
|
|
332
|
+
case "uint8":
|
|
333
|
+
case "uint16":
|
|
334
|
+
case "uint32":
|
|
335
|
+
case "uint64":
|
|
336
|
+
return BigInt(value);
|
|
337
|
+
case "biguint":
|
|
338
|
+
return BigInt(value);
|
|
339
|
+
case "boolean":
|
|
340
|
+
return Boolean(value);
|
|
341
|
+
case "address":
|
|
342
|
+
return String(value);
|
|
343
|
+
case "hex":
|
|
344
|
+
return String(value);
|
|
345
|
+
case "asset":
|
|
346
|
+
if (typeof value === "object" && value !== null && "identifier" in value && "amount" in value) {
|
|
347
|
+
return value;
|
|
348
|
+
}
|
|
349
|
+
return value;
|
|
350
|
+
default:
|
|
351
|
+
if (type.startsWith("list:")) {
|
|
352
|
+
const [, itemType, itemsStr] = type.split(":");
|
|
353
|
+
if (!itemsStr) return [];
|
|
354
|
+
const items = itemsStr.split(",");
|
|
355
|
+
return items.map((item) => this.nativeToTyped(itemType, item));
|
|
356
|
+
}
|
|
357
|
+
return String(value);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
nativeToType(type) {
|
|
361
|
+
switch (type) {
|
|
362
|
+
case "string":
|
|
363
|
+
return "string";
|
|
364
|
+
case "uint8":
|
|
365
|
+
case "uint16":
|
|
366
|
+
case "uint32":
|
|
367
|
+
case "uint64":
|
|
368
|
+
case "biguint":
|
|
369
|
+
return "bigint";
|
|
370
|
+
case "boolean":
|
|
371
|
+
return "boolean";
|
|
372
|
+
case "address":
|
|
373
|
+
return "string";
|
|
374
|
+
case "hex":
|
|
375
|
+
return "string";
|
|
376
|
+
default:
|
|
377
|
+
return "string";
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
stringToTyped(value) {
|
|
381
|
+
const parts = value.split(import_warps2.WarpConstants.ArgParamsSeparator, 2);
|
|
382
|
+
if (parts.length < 2) {
|
|
383
|
+
return value;
|
|
384
|
+
}
|
|
385
|
+
const [type, stringValue] = parts;
|
|
386
|
+
switch (type) {
|
|
387
|
+
case "string":
|
|
388
|
+
return stringValue;
|
|
389
|
+
case "uint8":
|
|
390
|
+
case "uint16":
|
|
391
|
+
case "uint32":
|
|
392
|
+
case "uint64":
|
|
393
|
+
return BigInt(stringValue);
|
|
394
|
+
case "biguint":
|
|
395
|
+
return BigInt(stringValue);
|
|
396
|
+
case "boolean":
|
|
397
|
+
return stringValue === "true";
|
|
398
|
+
case "address":
|
|
399
|
+
return stringValue;
|
|
400
|
+
case "hex":
|
|
401
|
+
return stringValue;
|
|
402
|
+
case "asset":
|
|
403
|
+
const assetParts = stringValue.split(import_warps2.WarpConstants.ArgCompositeSeparator);
|
|
404
|
+
const identifier = assetParts[0] || "";
|
|
405
|
+
const amount = assetParts[1] ? BigInt(assetParts[1]) : 0n;
|
|
406
|
+
const decimals = assetParts[2] ? parseInt(assetParts[2], 10) : void 0;
|
|
407
|
+
return { identifier, amount, decimals };
|
|
408
|
+
default:
|
|
409
|
+
if (type.startsWith("list:")) {
|
|
410
|
+
const [, itemType, itemsStr] = type.split(":");
|
|
411
|
+
if (!itemsStr) return [];
|
|
412
|
+
const items = itemsStr.split(",");
|
|
413
|
+
return items.map((item) => this.stringToTyped(`${itemType}:${item}`));
|
|
414
|
+
}
|
|
415
|
+
return stringValue;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
parseNativeValue(type, value) {
|
|
419
|
+
switch (type) {
|
|
420
|
+
case "string":
|
|
421
|
+
return value;
|
|
422
|
+
case "uint8":
|
|
423
|
+
case "uint16":
|
|
424
|
+
case "uint32":
|
|
425
|
+
case "uint64":
|
|
426
|
+
case "biguint":
|
|
427
|
+
return BigInt(value);
|
|
428
|
+
case "boolean":
|
|
429
|
+
return value === "true";
|
|
430
|
+
case "address":
|
|
431
|
+
return value;
|
|
432
|
+
case "hex":
|
|
433
|
+
return value;
|
|
434
|
+
default:
|
|
435
|
+
return value;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/WarpNearOutput.ts
|
|
441
|
+
var WarpNearOutput = class {
|
|
442
|
+
constructor(config, chain) {
|
|
443
|
+
this.config = config;
|
|
444
|
+
this.chain = chain;
|
|
445
|
+
this.serializer = new WarpNearSerializer();
|
|
446
|
+
const providerConfig = (0, import_warps3.getProviderConfig)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
447
|
+
this.nearConfig = {
|
|
448
|
+
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
449
|
+
nodeUrl: providerConfig.url,
|
|
450
|
+
keyStore: new import_near_api_js2.keyStores.InMemoryKeyStore()
|
|
451
|
+
};
|
|
452
|
+
this.cache = new import_warps3.WarpCache(config.cache?.type);
|
|
453
|
+
}
|
|
454
|
+
async getActionExecution(warp, actionIndex, tx) {
|
|
455
|
+
const inputs = this.cache.get(import_warps3.WarpCacheKey.WarpExecutable(this.config.env, warp.meta?.hash || "", actionIndex)) ?? [];
|
|
456
|
+
const resolvedInputs = (0, import_warps3.extractResolvedInputValues)(inputs);
|
|
457
|
+
if (!tx) {
|
|
458
|
+
return this.createFailedExecution(warp, actionIndex, resolvedInputs);
|
|
459
|
+
}
|
|
460
|
+
if ("status" in tx && typeof tx.status === "string") {
|
|
461
|
+
return this.handleWarpChainAction(warp, actionIndex, tx, resolvedInputs);
|
|
462
|
+
}
|
|
463
|
+
if (typeof tx === "string") {
|
|
464
|
+
return this.handleTransactionHash(warp, actionIndex, tx, resolvedInputs);
|
|
465
|
+
}
|
|
466
|
+
return this.createFailedExecution(warp, actionIndex, resolvedInputs);
|
|
467
|
+
}
|
|
468
|
+
createFailedExecution(warp, actionIndex, resolvedInputs = []) {
|
|
469
|
+
return {
|
|
470
|
+
status: "error",
|
|
471
|
+
warp,
|
|
472
|
+
action: actionIndex,
|
|
473
|
+
user: (0, import_warps3.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
474
|
+
txHash: "",
|
|
475
|
+
tx: null,
|
|
476
|
+
next: null,
|
|
477
|
+
values: { string: [], native: [], mapped: {} },
|
|
478
|
+
output: {},
|
|
479
|
+
messages: {},
|
|
480
|
+
destination: null,
|
|
481
|
+
resolvedInputs
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
handleWarpChainAction(warp, actionIndex, tx, resolvedInputs = []) {
|
|
485
|
+
const success = tx.status === "success";
|
|
486
|
+
const transactionHash = tx.id || tx.tx?.hash || "";
|
|
487
|
+
const rawValues = [transactionHash];
|
|
488
|
+
const stringValues = rawValues.map(String);
|
|
489
|
+
return {
|
|
490
|
+
status: success ? "success" : "error",
|
|
491
|
+
warp,
|
|
492
|
+
action: actionIndex,
|
|
493
|
+
user: (0, import_warps3.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
494
|
+
txHash: transactionHash,
|
|
495
|
+
tx,
|
|
496
|
+
next: null,
|
|
497
|
+
values: { string: stringValues, native: rawValues, mapped: {} },
|
|
498
|
+
output: {},
|
|
499
|
+
messages: {},
|
|
500
|
+
destination: null,
|
|
501
|
+
resolvedInputs
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
async handleTransactionHash(warp, actionIndex, hash, resolvedInputs = []) {
|
|
505
|
+
try {
|
|
506
|
+
const near = await (0, import_near_api_js2.connect)(this.nearConfig);
|
|
507
|
+
const txStatus = await near.connection.provider.txStatus(hash, this.nearConfig.networkId);
|
|
508
|
+
if (!txStatus) {
|
|
509
|
+
return this.createFailedExecution(warp, actionIndex, resolvedInputs);
|
|
510
|
+
}
|
|
511
|
+
const statusObj = txStatus.status;
|
|
512
|
+
const success = statusObj && ("SuccessValue" in statusObj || "SuccessReceiptId" in statusObj);
|
|
513
|
+
const transaction = txStatus.transaction;
|
|
514
|
+
const rawValues = [hash];
|
|
515
|
+
const stringValues = rawValues.map(String);
|
|
516
|
+
return {
|
|
517
|
+
status: success ? "success" : "error",
|
|
518
|
+
warp,
|
|
519
|
+
action: actionIndex,
|
|
520
|
+
user: (0, import_warps3.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
521
|
+
txHash: hash,
|
|
522
|
+
tx: {
|
|
523
|
+
hash,
|
|
524
|
+
transaction,
|
|
525
|
+
status: txStatus.status
|
|
526
|
+
},
|
|
527
|
+
next: null,
|
|
528
|
+
values: { string: stringValues, native: rawValues, mapped: {} },
|
|
529
|
+
output: {},
|
|
530
|
+
messages: {},
|
|
531
|
+
destination: null,
|
|
532
|
+
resolvedInputs
|
|
533
|
+
};
|
|
534
|
+
} catch (error) {
|
|
535
|
+
return this.createFailedExecution(warp, actionIndex, resolvedInputs);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
async extractQueryOutput(warp, typedValues, actionIndex, inputs) {
|
|
539
|
+
const stringValues = typedValues.map((t) => this.serializer.typedToString(t));
|
|
540
|
+
const nativeValues = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
|
|
541
|
+
const values = { string: stringValues, native: nativeValues, mapped: {} };
|
|
542
|
+
let output = {};
|
|
543
|
+
if (!warp.output) return { values, output };
|
|
544
|
+
const getNestedValue = (path) => {
|
|
545
|
+
const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
|
|
546
|
+
if (indices.length === 0) return void 0;
|
|
547
|
+
let value = nativeValues[indices[0]];
|
|
548
|
+
for (let i = 1; i < indices.length; i++) {
|
|
549
|
+
if (value === void 0 || value === null) return void 0;
|
|
550
|
+
value = value[indices[i]];
|
|
551
|
+
}
|
|
552
|
+
return value;
|
|
553
|
+
};
|
|
554
|
+
for (const [key, path] of Object.entries(warp.output)) {
|
|
555
|
+
if (path.startsWith(import_warps3.WarpConstants.Transform.Prefix)) continue;
|
|
556
|
+
const currentActionIndex = (0, import_warps3.parseOutputOutIndex)(path);
|
|
557
|
+
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
558
|
+
output[key] = null;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
|
|
562
|
+
output[key] = getNestedValue(path) || null;
|
|
563
|
+
} else {
|
|
564
|
+
output[key] = path;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return { values, output: await (0, import_warps3.evaluateOutputCommon)(warp, output, actionIndex, inputs, this.serializer.coreSerializer, this.config) };
|
|
568
|
+
}
|
|
569
|
+
async getTransactionStatus(txHash) {
|
|
570
|
+
try {
|
|
571
|
+
const near = await (0, import_near_api_js2.connect)(this.nearConfig);
|
|
572
|
+
const txStatus = await near.connection.provider.txStatus(txHash, this.nearConfig.networkId);
|
|
573
|
+
if (!txStatus) {
|
|
574
|
+
return { status: "pending" };
|
|
575
|
+
}
|
|
576
|
+
const statusObj = txStatus.status;
|
|
577
|
+
const isSuccess = statusObj && ("SuccessValue" in statusObj || "SuccessReceiptId" in statusObj);
|
|
578
|
+
return {
|
|
579
|
+
status: isSuccess ? "confirmed" : "failed",
|
|
580
|
+
blockNumber: txStatus.transaction_outcome?.block_hash ? 0 : void 0,
|
|
581
|
+
gasUsed: BigInt(0)
|
|
582
|
+
};
|
|
583
|
+
} catch (error) {
|
|
584
|
+
throw new Error(`Failed to get transaction status: ${error}`);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
async getTransactionReceipt(txHash) {
|
|
588
|
+
try {
|
|
589
|
+
const near = await (0, import_near_api_js2.connect)(this.nearConfig);
|
|
590
|
+
const txStatus = await near.connection.provider.txStatus(txHash, this.nearConfig.networkId);
|
|
591
|
+
if (!txStatus) {
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
hash: txHash,
|
|
596
|
+
transaction: txStatus.transaction,
|
|
597
|
+
status: txStatus.status
|
|
598
|
+
};
|
|
599
|
+
} catch (error) {
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// src/WarpNearExecutor.ts
|
|
606
|
+
var WarpNearExecutor = class {
|
|
607
|
+
constructor(config, chain) {
|
|
608
|
+
this.config = config;
|
|
609
|
+
this.chain = chain;
|
|
610
|
+
this.serializer = new WarpNearSerializer();
|
|
611
|
+
const providerConfig = (0, import_warps4.getProviderConfig)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
612
|
+
this.nearConfig = {
|
|
613
|
+
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
614
|
+
nodeUrl: providerConfig.url,
|
|
615
|
+
keyStore: new import_near_api_js3.keyStores.InMemoryKeyStore()
|
|
616
|
+
};
|
|
617
|
+
this.output = new WarpNearOutput(config, this.chain);
|
|
618
|
+
}
|
|
619
|
+
async createTransaction(executable) {
|
|
620
|
+
const action = (0, import_warps4.getWarpActionByIndex)(executable.warp, executable.action);
|
|
621
|
+
let tx = null;
|
|
622
|
+
if (action.type === "transfer") {
|
|
623
|
+
tx = await this.createTransferTransaction(executable);
|
|
624
|
+
} else if (action.type === "contract") {
|
|
625
|
+
tx = await this.createContractCallTransaction(executable);
|
|
626
|
+
} else if (action.type === "query") {
|
|
627
|
+
throw new Error("WarpNearExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
628
|
+
} else if (action.type === "collect") {
|
|
629
|
+
throw new Error("WarpNearExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
630
|
+
}
|
|
631
|
+
if (!tx) throw new Error(`WarpNearExecutor: Invalid action type (${action.type})`);
|
|
632
|
+
return tx;
|
|
633
|
+
}
|
|
634
|
+
async createTransferTransaction(executable) {
|
|
635
|
+
const userWallet = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
636
|
+
if (!userWallet) throw new Error("WarpNearExecutor: createTransfer - user address not set");
|
|
637
|
+
if (!executable.destination) throw new Error("WarpNearExecutor: Destination address is required");
|
|
638
|
+
if (executable.transfers && executable.transfers.length > 0) {
|
|
639
|
+
return this.createTokenTransferTransaction(executable, userWallet);
|
|
640
|
+
}
|
|
641
|
+
const amount = executable.value > 0n ? executable.value : 0n;
|
|
642
|
+
const amountInYoctoNear = amount.toString();
|
|
643
|
+
return {
|
|
644
|
+
receiverId: executable.destination,
|
|
645
|
+
actions: [
|
|
646
|
+
{
|
|
647
|
+
type: "Transfer",
|
|
648
|
+
params: {
|
|
649
|
+
deposit: amountInYoctoNear
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
]
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
async createContractCallTransaction(executable) {
|
|
656
|
+
const userWallet = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
657
|
+
if (!userWallet) throw new Error("WarpNearExecutor: createContractCall - user address not set");
|
|
658
|
+
const action = (0, import_warps4.getWarpActionByIndex)(executable.warp, executable.action);
|
|
659
|
+
if (!action || !("func" in action) || !action.func) throw new Error("WarpNearExecutor: Contract action must have a function name");
|
|
660
|
+
if (!executable.destination) throw new Error("WarpNearExecutor: Contract address is required");
|
|
661
|
+
try {
|
|
662
|
+
const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
663
|
+
const args = nativeArgs.length > 0 ? nativeArgs : {};
|
|
664
|
+
const gas = WarpNearConstants.Gas.FunctionCall;
|
|
665
|
+
const deposit = executable.value > 0n ? executable.value.toString() : "0";
|
|
666
|
+
return {
|
|
667
|
+
receiverId: executable.destination,
|
|
668
|
+
actions: [
|
|
669
|
+
{
|
|
670
|
+
type: "FunctionCall",
|
|
671
|
+
params: {
|
|
672
|
+
methodName: action.func,
|
|
673
|
+
args,
|
|
674
|
+
gas,
|
|
675
|
+
deposit
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
]
|
|
679
|
+
};
|
|
680
|
+
} catch (error) {
|
|
681
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
682
|
+
throw new Error(`WarpNearExecutor: Failed to create contract call: ${errorMessage}`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
async createTokenTransferTransaction(executable, userWallet) {
|
|
686
|
+
if (executable.transfers.length === 0) throw new Error("WarpNearExecutor: No transfers provided");
|
|
687
|
+
if (!this.chain.nativeToken?.identifier) throw new Error("WarpNearExecutor: No native token defined for this chain");
|
|
688
|
+
const nativeTokenTransfers = executable.transfers.filter(
|
|
689
|
+
(transfer) => transfer.identifier === this.chain.nativeToken.identifier || transfer.identifier === WarpNearConstants.NativeToken.Identifier
|
|
690
|
+
);
|
|
691
|
+
const ftTokenTransfers = executable.transfers.filter(
|
|
692
|
+
(transfer) => transfer.identifier !== this.chain.nativeToken.identifier && transfer.identifier !== WarpNearConstants.NativeToken.Identifier
|
|
693
|
+
);
|
|
694
|
+
if (nativeTokenTransfers.length === 1 && ftTokenTransfers.length === 0) {
|
|
695
|
+
const transfer = nativeTokenTransfers[0];
|
|
696
|
+
if (transfer.amount <= 0n) throw new Error("WarpNearExecutor: Native token transfer amount must be positive");
|
|
697
|
+
return {
|
|
698
|
+
receiverId: executable.destination,
|
|
699
|
+
actions: [
|
|
700
|
+
{
|
|
701
|
+
type: "Transfer",
|
|
702
|
+
params: {
|
|
703
|
+
deposit: transfer.amount.toString()
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
]
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
if (nativeTokenTransfers.length === 0 && ftTokenTransfers.length === 1) {
|
|
710
|
+
return this.createSingleTokenTransfer(executable, ftTokenTransfers[0]);
|
|
711
|
+
}
|
|
712
|
+
if (executable.transfers.length > 1) throw new Error("WarpNearExecutor: Multiple token transfers not yet supported");
|
|
713
|
+
throw new Error("WarpNearExecutor: Invalid transfer configuration");
|
|
714
|
+
}
|
|
715
|
+
async createSingleTokenTransfer(executable, transfer) {
|
|
716
|
+
if (!executable.destination) throw new Error("WarpNearExecutor: Destination address is required");
|
|
717
|
+
const userWallet = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
718
|
+
if (!userWallet) throw new Error("WarpNearExecutor: User wallet not set");
|
|
719
|
+
const args = {
|
|
720
|
+
receiver_id: executable.destination,
|
|
721
|
+
amount: transfer.amount.toString()
|
|
722
|
+
};
|
|
723
|
+
return {
|
|
724
|
+
receiverId: transfer.identifier,
|
|
725
|
+
actions: [
|
|
726
|
+
{
|
|
727
|
+
type: "FunctionCall",
|
|
728
|
+
params: {
|
|
729
|
+
methodName: "ft_transfer",
|
|
730
|
+
args,
|
|
731
|
+
gas: WarpNearConstants.Gas.FunctionCall,
|
|
732
|
+
deposit: "1"
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
]
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
async executeQuery(executable) {
|
|
739
|
+
const action = (0, import_warps4.getWarpActionByIndex)(executable.warp, executable.action);
|
|
740
|
+
if (action.type !== "query") throw new Error(`WarpNearExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
741
|
+
if (!action.func) throw new Error("WarpNearExecutor: Query action must have a function name");
|
|
742
|
+
let queryAddress;
|
|
743
|
+
try {
|
|
744
|
+
if (!executable.destination) throw new Error("WarpNearExecutor: Query address is required");
|
|
745
|
+
queryAddress = executable.destination;
|
|
746
|
+
} catch {
|
|
747
|
+
throw new Error(`WarpNearExecutor: Invalid address for query: ${executable.destination}`);
|
|
748
|
+
}
|
|
749
|
+
try {
|
|
750
|
+
const nativeArgs = executable.args.map((arg) => this.serializer.coreSerializer.stringToNative(arg)[1]);
|
|
751
|
+
const args = nativeArgs.length > 0 ? nativeArgs : {};
|
|
752
|
+
const near = await (0, import_near_api_js3.connect)(this.nearConfig);
|
|
753
|
+
const account = await near.account(queryAddress);
|
|
754
|
+
const result = await account.viewFunction({
|
|
755
|
+
contractId: queryAddress,
|
|
756
|
+
methodName: action.func,
|
|
757
|
+
args
|
|
758
|
+
});
|
|
759
|
+
const { values, output } = await this.output.extractQueryOutput(
|
|
760
|
+
executable.warp,
|
|
761
|
+
Array.isArray(result) ? result : [result],
|
|
762
|
+
executable.action,
|
|
763
|
+
executable.resolvedInputs
|
|
764
|
+
);
|
|
765
|
+
const next = (0, import_warps4.getNextInfo)(this.config, [], executable.warp, executable.action, output);
|
|
766
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
767
|
+
const destination = destinationInput?.value || executable.destination;
|
|
768
|
+
const resolvedInputs = (0, import_warps4.extractResolvedInputValues)(executable.resolvedInputs);
|
|
769
|
+
return {
|
|
770
|
+
status: "success",
|
|
771
|
+
warp: executable.warp,
|
|
772
|
+
action: executable.action,
|
|
773
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, executable.chain.name),
|
|
774
|
+
txHash: null,
|
|
775
|
+
tx: null,
|
|
776
|
+
next,
|
|
777
|
+
values,
|
|
778
|
+
output: { ...output, _DATA: result },
|
|
779
|
+
messages: (0, import_warps4.applyOutputToMessages)(executable.warp, output, this.config),
|
|
780
|
+
destination,
|
|
781
|
+
resolvedInputs
|
|
782
|
+
};
|
|
783
|
+
} catch (error) {
|
|
784
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
785
|
+
const destinationInput = executable.resolvedInputs.find((i) => i.input.position === "receiver" || i.input.position === "destination");
|
|
786
|
+
const destination = destinationInput?.value || executable.destination;
|
|
787
|
+
const resolvedInputs = (0, import_warps4.extractResolvedInputValues)(executable.resolvedInputs);
|
|
788
|
+
return {
|
|
789
|
+
status: "error",
|
|
790
|
+
warp: executable.warp,
|
|
791
|
+
action: executable.action,
|
|
792
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, executable.chain.name),
|
|
793
|
+
txHash: null,
|
|
794
|
+
tx: null,
|
|
795
|
+
next: null,
|
|
796
|
+
values: { string: [], native: [], mapped: {} },
|
|
797
|
+
output: { _DATA: errorMessage, _ERROR: errorMessage },
|
|
798
|
+
messages: {},
|
|
799
|
+
destination,
|
|
800
|
+
resolvedInputs
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
|
|
806
|
+
// src/WarpNearExplorer.ts
|
|
807
|
+
var WarpNearExplorer = class {
|
|
808
|
+
constructor(chain, config) {
|
|
809
|
+
this.chain = chain;
|
|
810
|
+
this.config = config;
|
|
811
|
+
}
|
|
812
|
+
getExplorers() {
|
|
813
|
+
const explorers = NearExplorerNames[this.config.env];
|
|
814
|
+
if (!explorers) {
|
|
815
|
+
return ["near_explorer" /* NearExplorer */];
|
|
816
|
+
}
|
|
817
|
+
return explorers;
|
|
818
|
+
}
|
|
819
|
+
getPrimaryExplorer() {
|
|
820
|
+
const explorers = this.getExplorers();
|
|
821
|
+
return explorers[0];
|
|
822
|
+
}
|
|
823
|
+
getExplorerUrlByName(explorer) {
|
|
824
|
+
const userPreference = this.config.preferences?.explorers?.[this.chain.name];
|
|
825
|
+
if (userPreference && !explorer) {
|
|
826
|
+
const url2 = NearExplorerUrls[userPreference];
|
|
827
|
+
if (url2) return url2;
|
|
828
|
+
}
|
|
829
|
+
if (explorer) {
|
|
830
|
+
const url2 = NearExplorerUrls[explorer];
|
|
831
|
+
if (url2) return url2;
|
|
832
|
+
}
|
|
833
|
+
const primaryExplorer = this.getPrimaryExplorer();
|
|
834
|
+
const url = NearExplorerUrls[primaryExplorer];
|
|
835
|
+
return url || NearExplorerUrls[primaryExplorer];
|
|
836
|
+
}
|
|
837
|
+
getAccountUrl(address, explorer) {
|
|
838
|
+
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
839
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
840
|
+
return `${baseUrl}${network}/accounts/${address}`;
|
|
841
|
+
}
|
|
842
|
+
getTransactionUrl(hash, explorer) {
|
|
843
|
+
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
844
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
845
|
+
return `${baseUrl}${network}/transactions/${hash}`;
|
|
846
|
+
}
|
|
847
|
+
getBlockUrl(blockNumber, explorer) {
|
|
848
|
+
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
849
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
850
|
+
return `${baseUrl}${network}/blocks/${blockNumber}`;
|
|
851
|
+
}
|
|
852
|
+
getAssetUrl(identifier, explorer) {
|
|
853
|
+
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
854
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
855
|
+
return `${baseUrl}${network}/tokens/${identifier}`;
|
|
856
|
+
}
|
|
857
|
+
getContractUrl(address, explorer) {
|
|
858
|
+
const baseUrl = this.getExplorerUrlByName(explorer);
|
|
859
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
860
|
+
return `${baseUrl}${network}/accounts/${address}`;
|
|
861
|
+
}
|
|
862
|
+
getAllExplorers() {
|
|
863
|
+
return this.getExplorers();
|
|
864
|
+
}
|
|
865
|
+
getExplorerByName(name) {
|
|
866
|
+
const explorers = this.getExplorers();
|
|
867
|
+
return explorers.find((explorer) => explorer.toLowerCase() === name.toLowerCase());
|
|
868
|
+
}
|
|
869
|
+
getAccountUrls(address) {
|
|
870
|
+
const explorers = this.getAllExplorers();
|
|
871
|
+
const urls = {};
|
|
872
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
873
|
+
explorers.forEach((explorer) => {
|
|
874
|
+
const url = NearExplorerUrls[explorer];
|
|
875
|
+
if (url) {
|
|
876
|
+
urls[explorer] = `${url}${network}/accounts/${address}`;
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
return urls;
|
|
880
|
+
}
|
|
881
|
+
getTransactionUrls(hash) {
|
|
882
|
+
const explorers = this.getAllExplorers();
|
|
883
|
+
const urls = {};
|
|
884
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
885
|
+
explorers.forEach((explorer) => {
|
|
886
|
+
const url = NearExplorerUrls[explorer];
|
|
887
|
+
if (url) {
|
|
888
|
+
urls[explorer] = `${url}${network}/transactions/${hash}`;
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
return urls;
|
|
892
|
+
}
|
|
893
|
+
getAssetUrls(identifier) {
|
|
894
|
+
const explorers = this.getAllExplorers();
|
|
895
|
+
const urls = {};
|
|
896
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
897
|
+
explorers.forEach((explorer) => {
|
|
898
|
+
const url = NearExplorerUrls[explorer];
|
|
899
|
+
if (url) {
|
|
900
|
+
urls[explorer] = `${url}${network}/tokens/${identifier}`;
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
return urls;
|
|
904
|
+
}
|
|
905
|
+
getContractUrls(address) {
|
|
906
|
+
const explorers = this.getAllExplorers();
|
|
907
|
+
const urls = {};
|
|
908
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
909
|
+
explorers.forEach((explorer) => {
|
|
910
|
+
const url = NearExplorerUrls[explorer];
|
|
911
|
+
if (url) {
|
|
912
|
+
urls[explorer] = `${url}${network}/accounts/${address}`;
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
return urls;
|
|
916
|
+
}
|
|
917
|
+
getBlockUrls(blockNumber) {
|
|
918
|
+
const explorers = this.getAllExplorers();
|
|
919
|
+
const urls = {};
|
|
920
|
+
const network = this.config.env === "mainnet" ? "" : `/${this.config.env}`;
|
|
921
|
+
explorers.forEach((explorer) => {
|
|
922
|
+
const url = NearExplorerUrls[explorer];
|
|
923
|
+
if (url) {
|
|
924
|
+
urls[explorer] = `${url}${network}/blocks/${blockNumber}`;
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
return urls;
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
// src/WarpNearWallet.ts
|
|
932
|
+
var import_warps8 = require("@vleap/warps");
|
|
933
|
+
var import_near_api_js6 = require("near-api-js");
|
|
934
|
+
|
|
935
|
+
// src/providers/MnemonicWalletProvider.ts
|
|
936
|
+
var import_crypto = require("@near-js/crypto");
|
|
937
|
+
var bip39 = __toESM(require("@scure/bip39"), 1);
|
|
938
|
+
var import_english = require("@scure/bip39/wordlists/english.js");
|
|
939
|
+
var import_warps5 = require("@vleap/warps");
|
|
940
|
+
var import_bs58 = __toESM(require("bs58"), 1);
|
|
941
|
+
var import_near_api_js4 = require("near-api-js");
|
|
942
|
+
var _MnemonicWalletProvider = class _MnemonicWalletProvider {
|
|
943
|
+
constructor(config, chain) {
|
|
944
|
+
this.config = config;
|
|
945
|
+
this.chain = chain;
|
|
946
|
+
this.keypair = null;
|
|
947
|
+
}
|
|
948
|
+
async getAddress() {
|
|
949
|
+
const address = (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
950
|
+
if (address) return address;
|
|
951
|
+
try {
|
|
952
|
+
const keypair = this.getKeyPair();
|
|
953
|
+
const publicKey = keypair.getPublicKey();
|
|
954
|
+
return (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
955
|
+
} catch {
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
async getPublicKey() {
|
|
960
|
+
try {
|
|
961
|
+
const keypair = this.getKeyPair();
|
|
962
|
+
const publicKey = keypair.getPublicKey();
|
|
963
|
+
return publicKey.toString();
|
|
964
|
+
} catch {
|
|
965
|
+
return null;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
async signTransaction(tx) {
|
|
969
|
+
const keypair = this.getKeyPair();
|
|
970
|
+
return tx;
|
|
971
|
+
}
|
|
972
|
+
async signMessage(message) {
|
|
973
|
+
const keypair = this.getKeyPair();
|
|
974
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
975
|
+
const signature = keypair.sign(messageBytes);
|
|
976
|
+
return import_bs58.default.encode(signature.signature);
|
|
977
|
+
}
|
|
978
|
+
getKeyPairInstance() {
|
|
979
|
+
return this.getKeyPair();
|
|
980
|
+
}
|
|
981
|
+
create(mnemonic) {
|
|
982
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
983
|
+
const secretKey = seed.slice(0, 32);
|
|
984
|
+
const keyPair = import_near_api_js4.KeyPair.fromString(import_bs58.default.encode(secretKey));
|
|
985
|
+
const publicKey = keyPair.getPublicKey();
|
|
986
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
987
|
+
return {
|
|
988
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
989
|
+
address: accountId,
|
|
990
|
+
privateKey: null,
|
|
991
|
+
mnemonic
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
generate() {
|
|
995
|
+
const mnemonic = bip39.generateMnemonic(import_english.wordlist);
|
|
996
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
997
|
+
const secretKey = seed.slice(0, 32);
|
|
998
|
+
const keyPair = import_near_api_js4.KeyPair.fromString(import_bs58.default.encode(secretKey));
|
|
999
|
+
const publicKey = keyPair.getPublicKey();
|
|
1000
|
+
const accountId = (0, import_crypto.keyToImplicitAddress)(publicKey.toString());
|
|
1001
|
+
return {
|
|
1002
|
+
provider: _MnemonicWalletProvider.PROVIDER_NAME,
|
|
1003
|
+
address: accountId,
|
|
1004
|
+
privateKey: null,
|
|
1005
|
+
mnemonic
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
getKeyPair() {
|
|
1009
|
+
if (this.keypair) return this.keypair;
|
|
1010
|
+
const mnemonic = (0, import_warps5.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
|
|
1011
|
+
if (!mnemonic) throw new Error("No mnemonic provided");
|
|
1012
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
|
1013
|
+
const secretKey = seed.slice(0, 32);
|
|
1014
|
+
this.keypair = import_near_api_js4.KeyPair.fromString(import_bs58.default.encode(secretKey));
|
|
1015
|
+
return this.keypair;
|
|
1016
|
+
}
|
|
1017
|
+
};
|
|
1018
|
+
_MnemonicWalletProvider.PROVIDER_NAME = "mnemonic";
|
|
1019
|
+
var MnemonicWalletProvider = _MnemonicWalletProvider;
|
|
1020
|
+
|
|
1021
|
+
// src/providers/PrivateKeyWalletProvider.ts
|
|
1022
|
+
var import_crypto2 = require("@near-js/crypto");
|
|
1023
|
+
var bip392 = __toESM(require("@scure/bip39"), 1);
|
|
1024
|
+
var import_warps6 = require("@vleap/warps");
|
|
1025
|
+
var import_bs582 = __toESM(require("bs58"), 1);
|
|
1026
|
+
var import_near_api_js5 = require("near-api-js");
|
|
1027
|
+
var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
|
|
1028
|
+
constructor(config, chain) {
|
|
1029
|
+
this.config = config;
|
|
1030
|
+
this.chain = chain;
|
|
1031
|
+
this.keypair = null;
|
|
1032
|
+
}
|
|
1033
|
+
async getAddress() {
|
|
1034
|
+
const address = (0, import_warps6.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1035
|
+
if (address) return address;
|
|
1036
|
+
try {
|
|
1037
|
+
const keypair = this.getKeyPair();
|
|
1038
|
+
const publicKey = keypair.getPublicKey();
|
|
1039
|
+
return (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1040
|
+
} catch {
|
|
1041
|
+
return null;
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
async getPublicKey() {
|
|
1045
|
+
try {
|
|
1046
|
+
const keypair = this.getKeyPair();
|
|
1047
|
+
const publicKey = keypair.getPublicKey();
|
|
1048
|
+
return publicKey.toString();
|
|
1049
|
+
} catch {
|
|
1050
|
+
return null;
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
async signTransaction(tx) {
|
|
1054
|
+
const keypair = this.getKeyPair();
|
|
1055
|
+
return tx;
|
|
1056
|
+
}
|
|
1057
|
+
async signMessage(message) {
|
|
1058
|
+
const keypair = this.getKeyPair();
|
|
1059
|
+
const messageBytes = new TextEncoder().encode(message);
|
|
1060
|
+
const signature = keypair.sign(messageBytes);
|
|
1061
|
+
return import_bs582.default.encode(signature.signature);
|
|
1062
|
+
}
|
|
1063
|
+
getKeyPairInstance() {
|
|
1064
|
+
return this.getKeyPair();
|
|
1065
|
+
}
|
|
1066
|
+
create(mnemonic) {
|
|
1067
|
+
const seed = bip392.mnemonicToSeedSync(mnemonic);
|
|
1068
|
+
const secretKey = seed.slice(0, 32);
|
|
1069
|
+
const keyPair = import_near_api_js5.KeyPair.fromString(import_bs582.default.encode(secretKey));
|
|
1070
|
+
const publicKey = keyPair.getPublicKey();
|
|
1071
|
+
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1072
|
+
return {
|
|
1073
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1074
|
+
address: accountId,
|
|
1075
|
+
privateKey: keyPair.toString(),
|
|
1076
|
+
mnemonic: null
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
generate() {
|
|
1080
|
+
const keyPair = import_near_api_js5.KeyPair.fromRandom("ed25519");
|
|
1081
|
+
const publicKey = keyPair.getPublicKey();
|
|
1082
|
+
const accountId = (0, import_crypto2.keyToImplicitAddress)(publicKey.toString());
|
|
1083
|
+
return {
|
|
1084
|
+
provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
|
|
1085
|
+
address: accountId,
|
|
1086
|
+
privateKey: keyPair.toString(),
|
|
1087
|
+
mnemonic: null
|
|
1088
|
+
};
|
|
1089
|
+
}
|
|
1090
|
+
getKeyPair() {
|
|
1091
|
+
if (this.keypair) return this.keypair;
|
|
1092
|
+
const privateKey = (0, import_warps6.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
|
|
1093
|
+
if (!privateKey) throw new Error("No private key provided");
|
|
1094
|
+
try {
|
|
1095
|
+
return import_near_api_js5.KeyPair.fromString(privateKey);
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
if (error instanceof Error) {
|
|
1098
|
+
throw new Error(`Invalid private key format: ${error.message}`);
|
|
1099
|
+
}
|
|
1100
|
+
throw new Error("Invalid private key format");
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1104
|
+
_PrivateKeyWalletProvider.PROVIDER_NAME = "privateKey";
|
|
1105
|
+
var PrivateKeyWalletProvider = _PrivateKeyWalletProvider;
|
|
1106
|
+
|
|
1107
|
+
// src/providers/ReadOnlyWalletProvider.ts
|
|
1108
|
+
var import_warps7 = require("@vleap/warps");
|
|
1109
|
+
var ReadOnlyWalletProvider = class {
|
|
1110
|
+
constructor(config, chain) {
|
|
1111
|
+
this.config = config;
|
|
1112
|
+
this.chain = chain;
|
|
1113
|
+
}
|
|
1114
|
+
async getAddress() {
|
|
1115
|
+
return (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1116
|
+
}
|
|
1117
|
+
async getPublicKey() {
|
|
1118
|
+
return null;
|
|
1119
|
+
}
|
|
1120
|
+
async signTransaction(tx) {
|
|
1121
|
+
const address = await this.getAddress();
|
|
1122
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1123
|
+
}
|
|
1124
|
+
async signMessage(message) {
|
|
1125
|
+
const address = await this.getAddress();
|
|
1126
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1127
|
+
}
|
|
1128
|
+
create(mnemonic) {
|
|
1129
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1130
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1131
|
+
}
|
|
1132
|
+
generate() {
|
|
1133
|
+
const address = (0, import_warps7.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
1134
|
+
throw new Error(`Wallet can not be used for signing: ${address}`);
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
// src/WarpNearWallet.ts
|
|
1139
|
+
var WarpNearWallet = class {
|
|
1140
|
+
constructor(config, chain) {
|
|
1141
|
+
this.config = config;
|
|
1142
|
+
this.chain = chain;
|
|
1143
|
+
this.cachedAddress = null;
|
|
1144
|
+
this.cachedPublicKey = null;
|
|
1145
|
+
const providerConfig = (0, import_warps8.getProviderConfig)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
1146
|
+
this.nearConfig = {
|
|
1147
|
+
networkId: this.config.env === "mainnet" ? "mainnet" : this.config.env === "testnet" ? "testnet" : "testnet",
|
|
1148
|
+
nodeUrl: providerConfig.url,
|
|
1149
|
+
keyStore: new import_near_api_js6.keyStores.InMemoryKeyStore()
|
|
1150
|
+
};
|
|
1151
|
+
this.walletProvider = this.createProvider();
|
|
1152
|
+
this.initializeCache();
|
|
1153
|
+
}
|
|
1154
|
+
async signTransaction(tx) {
|
|
1155
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1156
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1157
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
1158
|
+
const accountId = this.getAddress();
|
|
1159
|
+
if (!accountId) throw new Error("No account ID available");
|
|
1160
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1161
|
+
const keyPair = this.walletProvider.getKeyPairInstance();
|
|
1162
|
+
await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
|
|
1163
|
+
const near = await (0, import_near_api_js6.connect)(this.nearConfig);
|
|
1164
|
+
const account = await near.account(accountId);
|
|
1165
|
+
if (tx.signature) {
|
|
1166
|
+
return tx;
|
|
1167
|
+
}
|
|
1168
|
+
const signedTx = await account.signAndSendTransaction({
|
|
1169
|
+
receiverId: tx.receiverId,
|
|
1170
|
+
actions: tx.actions
|
|
1171
|
+
});
|
|
1172
|
+
return {
|
|
1173
|
+
...tx,
|
|
1174
|
+
signature: signedTx.transaction.hash,
|
|
1175
|
+
transactionHash: signedTx.transaction.hash
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
throw new Error("Wallet provider does not support signing transactions");
|
|
1179
|
+
}
|
|
1180
|
+
async signTransactions(txs) {
|
|
1181
|
+
if (txs.length === 0) return [];
|
|
1182
|
+
const signedTxs = [];
|
|
1183
|
+
for (const tx of txs) {
|
|
1184
|
+
signedTxs.push(await this.signTransaction(tx));
|
|
1185
|
+
}
|
|
1186
|
+
return signedTxs;
|
|
1187
|
+
}
|
|
1188
|
+
async signMessage(message) {
|
|
1189
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1190
|
+
if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
|
|
1191
|
+
return await this.walletProvider.signMessage(message);
|
|
1192
|
+
}
|
|
1193
|
+
async sendTransaction(tx) {
|
|
1194
|
+
if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
|
|
1195
|
+
if (!this.walletProvider) throw new Error("No wallet provider available");
|
|
1196
|
+
const accountId = this.getAddress();
|
|
1197
|
+
if (!accountId) throw new Error("No account ID available");
|
|
1198
|
+
if (tx.transactionHash) {
|
|
1199
|
+
return tx.transactionHash;
|
|
1200
|
+
}
|
|
1201
|
+
if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
|
|
1202
|
+
const keyPair = this.walletProvider.getKeyPairInstance();
|
|
1203
|
+
await this.nearConfig.keyStore.setKey(this.nearConfig.networkId, accountId, keyPair);
|
|
1204
|
+
const near = await (0, import_near_api_js6.connect)(this.nearConfig);
|
|
1205
|
+
const account = await near.account(accountId);
|
|
1206
|
+
const result = await account.signAndSendTransaction({
|
|
1207
|
+
receiverId: tx.receiverId,
|
|
1208
|
+
actions: tx.actions
|
|
1209
|
+
});
|
|
1210
|
+
return result.transaction.hash;
|
|
1211
|
+
}
|
|
1212
|
+
throw new Error("Wallet provider does not support sending transactions");
|
|
1213
|
+
}
|
|
1214
|
+
async sendTransactions(txs) {
|
|
1215
|
+
return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
|
|
1216
|
+
}
|
|
1217
|
+
create(provider, mnemonic) {
|
|
1218
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1219
|
+
return walletProvider.create(mnemonic);
|
|
1220
|
+
}
|
|
1221
|
+
generate(provider) {
|
|
1222
|
+
const walletProvider = this.createProviderForOperation(provider);
|
|
1223
|
+
return walletProvider.generate();
|
|
1224
|
+
}
|
|
1225
|
+
getAddress() {
|
|
1226
|
+
return this.cachedAddress;
|
|
1227
|
+
}
|
|
1228
|
+
getPublicKey() {
|
|
1229
|
+
return this.cachedPublicKey;
|
|
1230
|
+
}
|
|
1231
|
+
createProvider() {
|
|
1232
|
+
const wallet = this.config.user?.wallets?.[this.chain.name];
|
|
1233
|
+
if (!wallet) return null;
|
|
1234
|
+
if (typeof wallet === "string") return new ReadOnlyWalletProvider(this.config, this.chain);
|
|
1235
|
+
return this.createProviderForOperation(wallet.provider);
|
|
1236
|
+
}
|
|
1237
|
+
initializeCache() {
|
|
1238
|
+
(0, import_warps8.initializeWalletCache)(this.walletProvider).then((cache) => {
|
|
1239
|
+
this.cachedAddress = cache.address;
|
|
1240
|
+
this.cachedPublicKey = cache.publicKey;
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
createProviderForOperation(provider) {
|
|
1244
|
+
const customWalletProviders = this.config.walletProviders?.[this.chain.name];
|
|
1245
|
+
const providerFactory = customWalletProviders?.[provider];
|
|
1246
|
+
if (providerFactory) {
|
|
1247
|
+
const walletProvider = providerFactory(this.config, this.chain);
|
|
1248
|
+
if (!walletProvider) throw new Error(`Custom wallet provider factory returned null for ${provider}`);
|
|
1249
|
+
return walletProvider;
|
|
1250
|
+
}
|
|
1251
|
+
if (provider === "privateKey") return new PrivateKeyWalletProvider(this.config, this.chain);
|
|
1252
|
+
if (provider === "mnemonic") return new MnemonicWalletProvider(this.config, this.chain);
|
|
1253
|
+
throw new Error(`Unsupported wallet provider for ${this.chain.name}: ${provider}`);
|
|
1254
|
+
}
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
// src/chains/common.ts
|
|
1258
|
+
var createNearAdapter = (chainName, chainInfos) => {
|
|
1259
|
+
return (config, fallback) => {
|
|
1260
|
+
if (!fallback) throw new Error(`${chainName} adapter requires a fallback adapter`);
|
|
1261
|
+
return {
|
|
1262
|
+
chainInfo: chainInfos[config.env],
|
|
1263
|
+
builder: () => fallback.builder(),
|
|
1264
|
+
executor: new WarpNearExecutor(config, chainInfos[config.env]),
|
|
1265
|
+
output: new WarpNearOutput(config, chainInfos[config.env]),
|
|
1266
|
+
serializer: new WarpNearSerializer(),
|
|
1267
|
+
registry: fallback.registry,
|
|
1268
|
+
explorer: new WarpNearExplorer(chainInfos[config.env], config),
|
|
1269
|
+
abiBuilder: () => fallback.abiBuilder(),
|
|
1270
|
+
brandBuilder: () => fallback.brandBuilder(),
|
|
1271
|
+
dataLoader: new WarpNearDataLoader(config, chainInfos[config.env]),
|
|
1272
|
+
wallet: new WarpNearWallet(config, chainInfos[config.env])
|
|
1273
|
+
};
|
|
1274
|
+
};
|
|
1275
|
+
};
|
|
1276
|
+
|
|
1277
|
+
// src/chains/near.ts
|
|
1278
|
+
var NativeTokenNear = {
|
|
1279
|
+
chain: "near",
|
|
1280
|
+
identifier: "NEAR",
|
|
1281
|
+
symbol: "NEAR",
|
|
1282
|
+
name: "NEAR",
|
|
1283
|
+
decimals: 24,
|
|
1284
|
+
logoUrl: "https://joai.ai/images/tokens/near-black.svg"
|
|
1285
|
+
};
|
|
1286
|
+
var NearAdapter = createNearAdapter("near", {
|
|
1287
|
+
mainnet: {
|
|
1288
|
+
name: "near",
|
|
1289
|
+
displayName: "NEAR Mainnet",
|
|
1290
|
+
chainId: "mainnet",
|
|
1291
|
+
blockTime: 1200,
|
|
1292
|
+
addressHrp: "",
|
|
1293
|
+
defaultApiUrl: "https://rpc.mainnet.near.org",
|
|
1294
|
+
logoUrl: "https://joai.ai/images/chains/near-black.svg",
|
|
1295
|
+
nativeToken: NativeTokenNear
|
|
1296
|
+
},
|
|
1297
|
+
testnet: {
|
|
1298
|
+
name: "near",
|
|
1299
|
+
displayName: "NEAR Testnet",
|
|
1300
|
+
chainId: "testnet",
|
|
1301
|
+
blockTime: 1200,
|
|
1302
|
+
addressHrp: "",
|
|
1303
|
+
defaultApiUrl: "https://rpc.testnet.near.org",
|
|
1304
|
+
logoUrl: "https://joai.ai/images/chains/near-black.svg",
|
|
1305
|
+
nativeToken: NativeTokenNear
|
|
1306
|
+
},
|
|
1307
|
+
devnet: {
|
|
1308
|
+
name: "near",
|
|
1309
|
+
displayName: "NEAR Devnet",
|
|
1310
|
+
chainId: "testnet",
|
|
1311
|
+
blockTime: 1200,
|
|
1312
|
+
addressHrp: "",
|
|
1313
|
+
defaultApiUrl: "https://rpc.testnet.near.org",
|
|
1314
|
+
logoUrl: "https://joai.ai/images/chains/near-black.svg",
|
|
1315
|
+
nativeToken: NativeTokenNear
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1319
|
+
0 && (module.exports = {
|
|
1320
|
+
ExplorerUrls,
|
|
1321
|
+
KnownTokens,
|
|
1322
|
+
NativeTokenNear,
|
|
1323
|
+
NearAdapter,
|
|
1324
|
+
NearExplorerMap,
|
|
1325
|
+
NearExplorerNames,
|
|
1326
|
+
NearExplorerUrls,
|
|
1327
|
+
NearExplorers,
|
|
1328
|
+
NearTokens,
|
|
1329
|
+
WarpNearConstants,
|
|
1330
|
+
WarpNearDataLoader,
|
|
1331
|
+
WarpNearExecutor,
|
|
1332
|
+
WarpNearExplorer,
|
|
1333
|
+
WarpNearOutput,
|
|
1334
|
+
WarpNearSerializer,
|
|
1335
|
+
WarpNearWallet,
|
|
1336
|
+
findKnownTokenById,
|
|
1337
|
+
getKnownTokensForChain
|
|
1338
|
+
});
|
|
1339
|
+
//# sourceMappingURL=index.js.map
|