@vleap/warps-adapter-fastset 0.1.0-alpha.8 → 0.1.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.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -5
- package/dist/index.d.mts +0 -303
- package/dist/index.js +0 -853
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,853 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
Address: () => Address,
|
|
24
|
-
Amount: () => Amount,
|
|
25
|
-
Bytes32: () => Bytes32,
|
|
26
|
-
ClaimType: () => ClaimType,
|
|
27
|
-
FastsetClient: () => FastsetClient,
|
|
28
|
-
Nonce: () => Nonce,
|
|
29
|
-
PublicKey: () => PublicKey,
|
|
30
|
-
Transaction: () => Transaction,
|
|
31
|
-
Transfer: () => Transfer,
|
|
32
|
-
UserData: () => UserData,
|
|
33
|
-
WarpFastsetConstants: () => WarpFastsetConstants,
|
|
34
|
-
WarpFastsetExecutor: () => WarpFastsetExecutor,
|
|
35
|
-
WarpFastsetExplorer: () => WarpFastsetExplorer,
|
|
36
|
-
WarpFastsetResults: () => WarpFastsetResults,
|
|
37
|
-
WarpFastsetSerializer: () => WarpFastsetSerializer,
|
|
38
|
-
decimalToHex: () => decimalToHex,
|
|
39
|
-
fromBase64: () => fromBase64,
|
|
40
|
-
getFastsetAdapter: () => getFastsetAdapter,
|
|
41
|
-
hexToDecimal: () => hexToDecimal2,
|
|
42
|
-
isValidFastsetAddress: () => isValidFastsetAddress,
|
|
43
|
-
normalizeAmount: () => normalizeAmount,
|
|
44
|
-
toBase64String: () => toBase64String,
|
|
45
|
-
toHexString: () => toHexString,
|
|
46
|
-
validateAmount: () => validateAmount,
|
|
47
|
-
validatePrivateKey: () => validatePrivateKey,
|
|
48
|
-
validatePublicKey: () => validatePublicKey
|
|
49
|
-
});
|
|
50
|
-
module.exports = __toCommonJS(index_exports);
|
|
51
|
-
|
|
52
|
-
// src/constants.ts
|
|
53
|
-
var WarpFastsetConstants = {
|
|
54
|
-
Pi: {
|
|
55
|
-
Identifier: "PI",
|
|
56
|
-
DisplayName: "Pi",
|
|
57
|
-
Decimals: 18
|
|
58
|
-
},
|
|
59
|
-
GasLimit: {
|
|
60
|
-
Default: 21e3,
|
|
61
|
-
ContractCall: 1e5,
|
|
62
|
-
ContractDeploy: 5e5,
|
|
63
|
-
Transfer: 21e3,
|
|
64
|
-
Approve: 46e3,
|
|
65
|
-
Swap: 2e5
|
|
66
|
-
},
|
|
67
|
-
GasPrice: {
|
|
68
|
-
Default: "20000000000",
|
|
69
|
-
// 20 gwei
|
|
70
|
-
Low: "10000000000",
|
|
71
|
-
// 10 gwei
|
|
72
|
-
Medium: "20000000000",
|
|
73
|
-
// 20 gwei
|
|
74
|
-
High: "50000000000"
|
|
75
|
-
// 50 gwei
|
|
76
|
-
},
|
|
77
|
-
Validation: {
|
|
78
|
-
AddressLength: 42,
|
|
79
|
-
HexPrefix: "0x",
|
|
80
|
-
MinGasLimit: 21e3,
|
|
81
|
-
MaxGasLimit: 3e7
|
|
82
|
-
},
|
|
83
|
-
Timeouts: {
|
|
84
|
-
DefaultRpcTimeout: 3e4,
|
|
85
|
-
// 30 seconds
|
|
86
|
-
GasEstimationTimeout: 1e4,
|
|
87
|
-
// 10 seconds
|
|
88
|
-
QueryTimeout: 15e3
|
|
89
|
-
// 15 seconds
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
// src/WarpFastsetDataLoader.ts
|
|
94
|
-
var WarpFastsetDataLoader = class {
|
|
95
|
-
constructor(config, chain) {
|
|
96
|
-
this.config = config;
|
|
97
|
-
this.chain = chain;
|
|
98
|
-
}
|
|
99
|
-
async getAccount(address) {
|
|
100
|
-
return {
|
|
101
|
-
address,
|
|
102
|
-
balance: BigInt(0)
|
|
103
|
-
// TODO: Implement actual balance fetching from Fastset API
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
async getAccountAssets(address) {
|
|
107
|
-
return [];
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// src/WarpFastsetExecutor.ts
|
|
112
|
-
var import_warps2 = require("@vleap/warps");
|
|
113
|
-
|
|
114
|
-
// src/config.ts
|
|
115
|
-
var FASTSET_CHAIN_CONFIGS = {
|
|
116
|
-
fastset: {
|
|
117
|
-
mainnet: {
|
|
118
|
-
apiUrl: "http://157.90.201.117:8765",
|
|
119
|
-
proxyUrl: "http://136.243.61.168:44444",
|
|
120
|
-
explorerUrl: "https://explorer.fastset.com",
|
|
121
|
-
chainId: "1",
|
|
122
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
123
|
-
nativeToken: "PI",
|
|
124
|
-
blockTime: 12e3
|
|
125
|
-
},
|
|
126
|
-
testnet: {
|
|
127
|
-
apiUrl: "http://157.90.201.117:8765",
|
|
128
|
-
proxyUrl: "http://136.243.61.168:44444",
|
|
129
|
-
explorerUrl: "https://testnet-explorer.fastset.com",
|
|
130
|
-
chainId: "11155111",
|
|
131
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
132
|
-
nativeToken: "PI",
|
|
133
|
-
blockTime: 12e3
|
|
134
|
-
},
|
|
135
|
-
devnet: {
|
|
136
|
-
apiUrl: "http://157.90.201.117:8765",
|
|
137
|
-
proxyUrl: "http://136.243.61.168:44444",
|
|
138
|
-
explorerUrl: "http://localhost:4000",
|
|
139
|
-
chainId: "1337",
|
|
140
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
141
|
-
nativeToken: "PI",
|
|
142
|
-
blockTime: 12e3
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
var DEFAULT_CHAIN = "fastset";
|
|
147
|
-
var getFastsetChainConfig = (chain = DEFAULT_CHAIN, env) => {
|
|
148
|
-
const chainConfigs = FASTSET_CHAIN_CONFIGS[chain];
|
|
149
|
-
if (!chainConfigs) {
|
|
150
|
-
throw new Error(`Unsupported Fastset chain: ${chain}`);
|
|
151
|
-
}
|
|
152
|
-
const config = chainConfigs[env];
|
|
153
|
-
if (!config) {
|
|
154
|
-
throw new Error(`Unsupported environment ${env} for chain ${chain}`);
|
|
155
|
-
}
|
|
156
|
-
return config;
|
|
157
|
-
};
|
|
158
|
-
var getFastsetApiUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
159
|
-
return getFastsetChainConfig(chain, env).apiUrl;
|
|
160
|
-
};
|
|
161
|
-
var getFastsetProxyUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
162
|
-
return getFastsetChainConfig(chain, env).proxyUrl;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// src/sdk/FastsetClient.ts
|
|
166
|
-
var import_ed25519 = require("@noble/ed25519");
|
|
167
|
-
|
|
168
|
-
// src/sdk/types.ts
|
|
169
|
-
var import_bcs = require("@mysten/bcs");
|
|
170
|
-
BigInt.prototype.toJSON = function() {
|
|
171
|
-
return Number(this);
|
|
172
|
-
};
|
|
173
|
-
var Bytes32 = import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8());
|
|
174
|
-
var PublicKey = Bytes32;
|
|
175
|
-
var Address = import_bcs.bcs.enum("Address", {
|
|
176
|
-
External: PublicKey,
|
|
177
|
-
FastSet: PublicKey
|
|
178
|
-
});
|
|
179
|
-
var Amount = import_bcs.bcs.u256().transform({
|
|
180
|
-
input: (val) => hexToDecimal(val.toString()),
|
|
181
|
-
output: (value) => value
|
|
182
|
-
});
|
|
183
|
-
var UserData = import_bcs.bcs.option(Bytes32);
|
|
184
|
-
var Nonce = import_bcs.bcs.u64();
|
|
185
|
-
var Transfer = import_bcs.bcs.struct("Transfer", {
|
|
186
|
-
recipient: Address,
|
|
187
|
-
amount: Amount,
|
|
188
|
-
user_data: UserData
|
|
189
|
-
});
|
|
190
|
-
var ClaimType = import_bcs.bcs.enum("ClaimType", {
|
|
191
|
-
Transfer
|
|
192
|
-
});
|
|
193
|
-
var Transaction = import_bcs.bcs.struct("Transaction", {
|
|
194
|
-
sender: PublicKey,
|
|
195
|
-
nonce: Nonce,
|
|
196
|
-
timestamp_nanos: import_bcs.bcs.u128(),
|
|
197
|
-
claim: ClaimType
|
|
198
|
-
});
|
|
199
|
-
function hexToDecimal(hex) {
|
|
200
|
-
return BigInt(`0x${hex}`).toString();
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/sdk/FastsetClient.ts
|
|
204
|
-
var FastsetClient = class {
|
|
205
|
-
constructor(config) {
|
|
206
|
-
this.config = config;
|
|
207
|
-
}
|
|
208
|
-
async getAccountInfo(address) {
|
|
209
|
-
try {
|
|
210
|
-
const response = await this.requestValidator("set_getAccountInfo", {
|
|
211
|
-
address: Array.from(address)
|
|
212
|
-
});
|
|
213
|
-
if (response.error) {
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
return response.result;
|
|
217
|
-
} catch (error) {
|
|
218
|
-
return null;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
async getNextNonce(senderAddress) {
|
|
222
|
-
const accountInfo = await this.getAccountInfo(senderAddress);
|
|
223
|
-
return accountInfo?.next_nonce ?? 0;
|
|
224
|
-
}
|
|
225
|
-
async fundFromFaucet(request) {
|
|
226
|
-
const response = await this.requestProxy("faucetDrip", {
|
|
227
|
-
recipient: Array.from(request.recipient),
|
|
228
|
-
amount: request.amount
|
|
229
|
-
});
|
|
230
|
-
if (response.error) {
|
|
231
|
-
throw new Error(`Faucet request failed: ${response.error.message}`);
|
|
232
|
-
}
|
|
233
|
-
return response.result;
|
|
234
|
-
}
|
|
235
|
-
async submitTransaction(request) {
|
|
236
|
-
const response = await this.requestValidator("set_submitTransaction", {
|
|
237
|
-
transaction: this.serializeTransaction(request.transaction),
|
|
238
|
-
signature: Array.from(request.signature)
|
|
239
|
-
});
|
|
240
|
-
if (response.error) {
|
|
241
|
-
throw new Error(`Transaction submission failed: ${response.error.message}`);
|
|
242
|
-
}
|
|
243
|
-
const result = response.result;
|
|
244
|
-
return {
|
|
245
|
-
transaction_hash: new Uint8Array(result.transaction_hash),
|
|
246
|
-
validator: new Uint8Array(result.validator),
|
|
247
|
-
signature: new Uint8Array(result.signature)
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
async submitCertificate(request) {
|
|
251
|
-
const response = await this.requestValidator("set_submitTransactionCertificate", {
|
|
252
|
-
transaction: this.serializeTransaction(request.transaction),
|
|
253
|
-
signature: Array.from(request.signature),
|
|
254
|
-
validator_signatures: request.validator_signatures.map(([validator, signature]) => [Array.from(validator), Array.from(signature)])
|
|
255
|
-
});
|
|
256
|
-
if (response.error) {
|
|
257
|
-
throw new Error(`Certificate submission failed: ${response.error.message}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
async executeTransfer(senderPrivateKey, recipient, amount, userData) {
|
|
261
|
-
const senderPublicKey = await (0, import_ed25519.getPublicKey)(senderPrivateKey);
|
|
262
|
-
const nonce = await this.getNextNonce(senderPublicKey);
|
|
263
|
-
const transaction = {
|
|
264
|
-
sender: senderPublicKey,
|
|
265
|
-
nonce,
|
|
266
|
-
timestamp_nanos: BigInt(Date.now()) * 1000000n,
|
|
267
|
-
claim: {
|
|
268
|
-
Transfer: {
|
|
269
|
-
recipient: { FastSet: recipient },
|
|
270
|
-
amount,
|
|
271
|
-
user_data: userData ?? null
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
const signature = await this.signTransaction(transaction, senderPrivateKey);
|
|
276
|
-
const submitResponse = await this.submitTransaction({
|
|
277
|
-
transaction,
|
|
278
|
-
signature
|
|
279
|
-
});
|
|
280
|
-
await this.submitCertificate({
|
|
281
|
-
transaction,
|
|
282
|
-
signature,
|
|
283
|
-
validator_signatures: [[submitResponse.validator, submitResponse.signature]]
|
|
284
|
-
});
|
|
285
|
-
return submitResponse.transaction_hash;
|
|
286
|
-
}
|
|
287
|
-
async signTransaction(transaction, privateKey) {
|
|
288
|
-
const msg = Transaction.serialize(transaction);
|
|
289
|
-
const msgBytes = msg.toBytes();
|
|
290
|
-
const prefix = new TextEncoder().encode("Transaction::");
|
|
291
|
-
const dataToSign = new Uint8Array(prefix.length + msgBytes.length);
|
|
292
|
-
dataToSign.set(prefix, 0);
|
|
293
|
-
dataToSign.set(msgBytes, prefix.length);
|
|
294
|
-
return (0, import_ed25519.sign)(dataToSign, privateKey);
|
|
295
|
-
}
|
|
296
|
-
serializeTransaction(transaction) {
|
|
297
|
-
return JSON.stringify(transaction, this.jsonReplacer);
|
|
298
|
-
}
|
|
299
|
-
async requestValidator(method, params) {
|
|
300
|
-
return this.request(this.config.validatorUrl, method, params);
|
|
301
|
-
}
|
|
302
|
-
async requestProxy(method, params) {
|
|
303
|
-
return this.request(this.config.proxyUrl, method, params);
|
|
304
|
-
}
|
|
305
|
-
async request(url, method, params) {
|
|
306
|
-
const request = {
|
|
307
|
-
jsonrpc: "2.0",
|
|
308
|
-
id: 1,
|
|
309
|
-
method,
|
|
310
|
-
params
|
|
311
|
-
};
|
|
312
|
-
const response = await fetch(url, {
|
|
313
|
-
method: "POST",
|
|
314
|
-
headers: { "Content-Type": "application/json" },
|
|
315
|
-
body: JSON.stringify(request, this.jsonReplacer)
|
|
316
|
-
});
|
|
317
|
-
if (!response.ok) {
|
|
318
|
-
throw new Error(`HTTP request failed: ${response.statusText}`);
|
|
319
|
-
}
|
|
320
|
-
return response.json();
|
|
321
|
-
}
|
|
322
|
-
jsonReplacer(key, value) {
|
|
323
|
-
if (value instanceof Uint8Array) {
|
|
324
|
-
return Array.from(value);
|
|
325
|
-
}
|
|
326
|
-
return value;
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// src/sdk/utils.ts
|
|
331
|
-
var import_bcs2 = require("@mysten/bcs");
|
|
332
|
-
function isValidFastsetAddress(address) {
|
|
333
|
-
if (typeof address !== "string" || address.length === 0) {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
if (address.startsWith("fs") || address.startsWith("pi")) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
try {
|
|
340
|
-
const decoded = fromBase64(address);
|
|
341
|
-
return decoded.length === 32;
|
|
342
|
-
} catch {
|
|
343
|
-
return false;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function fromBase64(base64) {
|
|
347
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
348
|
-
}
|
|
349
|
-
function toBase64String(bytes) {
|
|
350
|
-
return (0, import_bcs2.toB64)(bytes);
|
|
351
|
-
}
|
|
352
|
-
function toHexString(bytes) {
|
|
353
|
-
return (0, import_bcs2.toHEX)(bytes);
|
|
354
|
-
}
|
|
355
|
-
function hexToDecimal2(hex) {
|
|
356
|
-
return BigInt(`0x${hex}`).toString();
|
|
357
|
-
}
|
|
358
|
-
function decimalToHex(decimal) {
|
|
359
|
-
return BigInt(decimal).toString(16);
|
|
360
|
-
}
|
|
361
|
-
function validateAmount(amount) {
|
|
362
|
-
try {
|
|
363
|
-
const bigInt = BigInt(amount);
|
|
364
|
-
return bigInt >= 0;
|
|
365
|
-
} catch {
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
function normalizeAmount(amount) {
|
|
370
|
-
try {
|
|
371
|
-
const bigInt = BigInt(amount);
|
|
372
|
-
return bigInt.toString(16);
|
|
373
|
-
} catch {
|
|
374
|
-
throw new Error(`Invalid amount format: ${amount}`);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
function validatePrivateKey(privateKey) {
|
|
378
|
-
try {
|
|
379
|
-
const key = typeof privateKey === "string" ? fromBase64(privateKey) : privateKey;
|
|
380
|
-
return key.length === 32;
|
|
381
|
-
} catch {
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
function validatePublicKey(publicKey) {
|
|
386
|
-
try {
|
|
387
|
-
const key = typeof publicKey === "string" ? fromBase64(publicKey) : publicKey;
|
|
388
|
-
return key.length === 32;
|
|
389
|
-
} catch {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// src/WarpFastsetSerializer.ts
|
|
395
|
-
var import_warps = require("@vleap/warps");
|
|
396
|
-
var WarpFastsetSerializer = class {
|
|
397
|
-
constructor() {
|
|
398
|
-
this.coreSerializer = new import_warps.WarpSerializer();
|
|
399
|
-
}
|
|
400
|
-
typedToString(value) {
|
|
401
|
-
if (typeof value === "string") {
|
|
402
|
-
return `string:${value}`;
|
|
403
|
-
}
|
|
404
|
-
if (typeof value === "number") {
|
|
405
|
-
return `number:${value}`;
|
|
406
|
-
}
|
|
407
|
-
if (typeof value === "boolean") {
|
|
408
|
-
return `boolean:${value}`;
|
|
409
|
-
}
|
|
410
|
-
if (typeof value === "bigint") {
|
|
411
|
-
return `bigint:${value.toString()}`;
|
|
412
|
-
}
|
|
413
|
-
if (Array.isArray(value)) {
|
|
414
|
-
const items = value.map((item) => this.typedToString(item)).join(",");
|
|
415
|
-
return `array:${items}`;
|
|
416
|
-
}
|
|
417
|
-
if (value === null) {
|
|
418
|
-
return "null:null";
|
|
419
|
-
}
|
|
420
|
-
if (value === void 0) {
|
|
421
|
-
return "undefined:undefined";
|
|
422
|
-
}
|
|
423
|
-
return `string:${String(value)}`;
|
|
424
|
-
}
|
|
425
|
-
typedToNative(value) {
|
|
426
|
-
if (typeof value === "string") {
|
|
427
|
-
return ["string", value];
|
|
428
|
-
}
|
|
429
|
-
if (typeof value === "number") {
|
|
430
|
-
return ["number", value];
|
|
431
|
-
}
|
|
432
|
-
if (typeof value === "boolean") {
|
|
433
|
-
return ["boolean", value];
|
|
434
|
-
}
|
|
435
|
-
if (typeof value === "bigint") {
|
|
436
|
-
return ["bigint", value];
|
|
437
|
-
}
|
|
438
|
-
return ["string", String(value)];
|
|
439
|
-
}
|
|
440
|
-
nativeToTyped(type, value) {
|
|
441
|
-
switch (type) {
|
|
442
|
-
case "string":
|
|
443
|
-
return String(value);
|
|
444
|
-
case "number":
|
|
445
|
-
return Number(value);
|
|
446
|
-
case "boolean":
|
|
447
|
-
return Boolean(value);
|
|
448
|
-
case "bigint":
|
|
449
|
-
return BigInt(value);
|
|
450
|
-
default:
|
|
451
|
-
return String(value);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
nativeToType(type) {
|
|
455
|
-
switch (type) {
|
|
456
|
-
case "string":
|
|
457
|
-
return "string";
|
|
458
|
-
case "number":
|
|
459
|
-
return "number";
|
|
460
|
-
case "boolean":
|
|
461
|
-
return "boolean";
|
|
462
|
-
case "bigint":
|
|
463
|
-
return "bigint";
|
|
464
|
-
default:
|
|
465
|
-
return "string";
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
stringToTyped(value) {
|
|
469
|
-
const colonIndex = value.indexOf(":");
|
|
470
|
-
if (colonIndex === -1) {
|
|
471
|
-
return value;
|
|
472
|
-
}
|
|
473
|
-
const type = value.substring(0, colonIndex);
|
|
474
|
-
const stringValue = value.substring(colonIndex + 1);
|
|
475
|
-
switch (type) {
|
|
476
|
-
case "string":
|
|
477
|
-
return stringValue;
|
|
478
|
-
case "number":
|
|
479
|
-
return Number(stringValue);
|
|
480
|
-
case "boolean":
|
|
481
|
-
return stringValue === "true";
|
|
482
|
-
case "bigint":
|
|
483
|
-
return BigInt(stringValue);
|
|
484
|
-
case "array":
|
|
485
|
-
return stringValue.split(",").map((item) => this.stringToTyped(item));
|
|
486
|
-
case "null":
|
|
487
|
-
return null;
|
|
488
|
-
case "undefined":
|
|
489
|
-
return void 0;
|
|
490
|
-
default:
|
|
491
|
-
return stringValue;
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
|
|
496
|
-
// src/WarpFastsetExecutor.ts
|
|
497
|
-
var WarpFastsetExecutor = class {
|
|
498
|
-
constructor(config) {
|
|
499
|
-
this.config = config;
|
|
500
|
-
this.serializer = new WarpFastsetSerializer();
|
|
501
|
-
this.fastsetClient = new FastsetClient({
|
|
502
|
-
validatorUrl: getFastsetApiUrl(this.config.env, "fastset"),
|
|
503
|
-
proxyUrl: getFastsetProxyUrl(this.config.env, "fastset")
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
|
-
async createTransaction(executable) {
|
|
507
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
508
|
-
switch (action.type) {
|
|
509
|
-
case "transfer":
|
|
510
|
-
return this.createTransferTransaction(executable);
|
|
511
|
-
case "contract":
|
|
512
|
-
return this.createContractCallTransaction(executable);
|
|
513
|
-
case "query":
|
|
514
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
515
|
-
case "collect":
|
|
516
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
517
|
-
default:
|
|
518
|
-
throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
async createTransferTransaction(executable) {
|
|
522
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
523
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
524
|
-
if (!isValidFastsetAddress(executable.destination)) {
|
|
525
|
-
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
526
|
-
}
|
|
527
|
-
if (executable.value < 0) {
|
|
528
|
-
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
529
|
-
}
|
|
530
|
-
const recipientAddress = fromBase64(executable.destination);
|
|
531
|
-
const amount = normalizeAmount(executable.value.toString());
|
|
532
|
-
const userData = executable.data ? fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
|
|
533
|
-
return {
|
|
534
|
-
type: "fastset-transfer",
|
|
535
|
-
recipient: recipientAddress,
|
|
536
|
-
amount,
|
|
537
|
-
userData,
|
|
538
|
-
chain: executable.chain
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
async createContractCallTransaction(executable) {
|
|
542
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
543
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
544
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
545
|
-
if (!action || !("func" in action) || !action.func) {
|
|
546
|
-
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
547
|
-
}
|
|
548
|
-
if (!isValidFastsetAddress(executable.destination)) {
|
|
549
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
550
|
-
}
|
|
551
|
-
if (executable.value < 0) {
|
|
552
|
-
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
553
|
-
}
|
|
554
|
-
try {
|
|
555
|
-
const contractAddress = fromBase64(executable.destination);
|
|
556
|
-
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
557
|
-
return {
|
|
558
|
-
type: "fastset-contract-call",
|
|
559
|
-
contract: contractAddress,
|
|
560
|
-
function: action.func,
|
|
561
|
-
data: encodedData,
|
|
562
|
-
value: executable.value,
|
|
563
|
-
chain: executable.chain
|
|
564
|
-
};
|
|
565
|
-
} catch (error) {
|
|
566
|
-
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
async executeQuery(executable) {
|
|
570
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
571
|
-
if (action.type !== "query") {
|
|
572
|
-
throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
573
|
-
}
|
|
574
|
-
if (!action.func) {
|
|
575
|
-
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
576
|
-
}
|
|
577
|
-
if (!isValidFastsetAddress(executable.destination)) {
|
|
578
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
579
|
-
}
|
|
580
|
-
try {
|
|
581
|
-
const contractAddress = fromBase64(executable.destination);
|
|
582
|
-
const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
|
|
583
|
-
return {
|
|
584
|
-
success: true,
|
|
585
|
-
result,
|
|
586
|
-
chain: executable.chain
|
|
587
|
-
};
|
|
588
|
-
} catch (error) {
|
|
589
|
-
return {
|
|
590
|
-
success: false,
|
|
591
|
-
error: error instanceof Error ? error.message : String(error),
|
|
592
|
-
chain: executable.chain
|
|
593
|
-
};
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
async preprocessInput(chain, input, type, value) {
|
|
597
|
-
const typedValue = this.serializer.stringToTyped(value);
|
|
598
|
-
switch (type) {
|
|
599
|
-
case "address":
|
|
600
|
-
if (!isValidFastsetAddress(typedValue)) {
|
|
601
|
-
throw new Error(`Invalid Fastset address format: ${typedValue}`);
|
|
602
|
-
}
|
|
603
|
-
return typedValue;
|
|
604
|
-
case "hex":
|
|
605
|
-
const hexValue = typedValue.startsWith("0x") ? typedValue.slice(2) : typedValue;
|
|
606
|
-
if (!/^[0-9a-fA-F]+$/.test(hexValue)) {
|
|
607
|
-
throw new Error(`Invalid hex format: ${typedValue}`);
|
|
608
|
-
}
|
|
609
|
-
return typedValue;
|
|
610
|
-
case "number":
|
|
611
|
-
const numValue = Number(typedValue);
|
|
612
|
-
if (isNaN(numValue)) {
|
|
613
|
-
throw new Error(`Invalid number format: ${typedValue}`);
|
|
614
|
-
}
|
|
615
|
-
return numValue.toString();
|
|
616
|
-
case "biguint":
|
|
617
|
-
const bigIntValue = BigInt(typedValue);
|
|
618
|
-
if (bigIntValue < 0) {
|
|
619
|
-
throw new Error(`Negative value not allowed`);
|
|
620
|
-
}
|
|
621
|
-
return bigIntValue.toString();
|
|
622
|
-
default:
|
|
623
|
-
return String(typedValue);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
encodeFunctionData(functionName, args) {
|
|
627
|
-
return JSON.stringify({
|
|
628
|
-
function: functionName,
|
|
629
|
-
arguments: args
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
async executeFastsetQuery(contractAddress, functionName, args) {
|
|
633
|
-
const response = await fetch(`${getFastsetApiUrl(this.config.env, "fastset")}/query`, {
|
|
634
|
-
method: "POST",
|
|
635
|
-
headers: {
|
|
636
|
-
"Content-Type": "application/json"
|
|
637
|
-
},
|
|
638
|
-
body: JSON.stringify({
|
|
639
|
-
contract: Array.from(contractAddress),
|
|
640
|
-
function: functionName,
|
|
641
|
-
arguments: args
|
|
642
|
-
})
|
|
643
|
-
});
|
|
644
|
-
if (!response.ok) {
|
|
645
|
-
throw new Error(`Fastset query failed: ${response.statusText}`);
|
|
646
|
-
}
|
|
647
|
-
return response.json();
|
|
648
|
-
}
|
|
649
|
-
async signMessage(message, privateKey) {
|
|
650
|
-
throw new Error("Not implemented");
|
|
651
|
-
}
|
|
652
|
-
async executeTransfer(executable) {
|
|
653
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
654
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
655
|
-
const transaction = await this.createTransferTransaction(executable);
|
|
656
|
-
return {
|
|
657
|
-
success: true,
|
|
658
|
-
transaction,
|
|
659
|
-
chain: executable.chain.name,
|
|
660
|
-
message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
|
|
661
|
-
};
|
|
662
|
-
}
|
|
663
|
-
async executeTransferWithKey(executable, privateKey) {
|
|
664
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
665
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
666
|
-
const transaction = await this.createTransferTransaction(executable);
|
|
667
|
-
const privateKeyBytes = fromBase64(privateKey);
|
|
668
|
-
const transactionHash = await this.fastsetClient.executeTransfer(
|
|
669
|
-
privateKeyBytes,
|
|
670
|
-
transaction.recipient,
|
|
671
|
-
transaction.amount,
|
|
672
|
-
transaction.userData
|
|
673
|
-
);
|
|
674
|
-
return {
|
|
675
|
-
success: true,
|
|
676
|
-
transactionHash: Array.from(transactionHash),
|
|
677
|
-
chain: executable.chain.name
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
// src/WarpFastsetExplorer.ts
|
|
683
|
-
var WarpFastsetExplorer = class {
|
|
684
|
-
constructor(chainInfo) {
|
|
685
|
-
this.chainInfo = chainInfo;
|
|
686
|
-
}
|
|
687
|
-
getAccountUrl(address) {
|
|
688
|
-
const baseUrl = this.getDefaultExplorerUrl();
|
|
689
|
-
return `${baseUrl}/address/${address}`;
|
|
690
|
-
}
|
|
691
|
-
getTransactionUrl(hash) {
|
|
692
|
-
const baseUrl = this.getDefaultExplorerUrl();
|
|
693
|
-
return `${baseUrl}/tx/${hash}`;
|
|
694
|
-
}
|
|
695
|
-
getBlockUrl(blockNumber) {
|
|
696
|
-
const baseUrl = this.getDefaultExplorerUrl();
|
|
697
|
-
return `${baseUrl}/block/${blockNumber}`;
|
|
698
|
-
}
|
|
699
|
-
getContractUrl(address) {
|
|
700
|
-
const baseUrl = this.getDefaultExplorerUrl();
|
|
701
|
-
return `${baseUrl}/contract/${address}`;
|
|
702
|
-
}
|
|
703
|
-
getAssetUrl(identifier) {
|
|
704
|
-
const baseUrl = this.getDefaultExplorerUrl();
|
|
705
|
-
return `${baseUrl}/token/${identifier}`;
|
|
706
|
-
}
|
|
707
|
-
getDefaultExplorerUrl() {
|
|
708
|
-
return `https://explorer.fastset.xyz`;
|
|
709
|
-
}
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// src/WarpFastsetResults.ts
|
|
713
|
-
var import_warps3 = require("@vleap/warps");
|
|
714
|
-
var WarpFastsetResults = class {
|
|
715
|
-
constructor(config) {
|
|
716
|
-
this.config = config;
|
|
717
|
-
this.serializer = new WarpFastsetSerializer();
|
|
718
|
-
}
|
|
719
|
-
async getTransactionExecutionResults(warp, tx) {
|
|
720
|
-
const success = this.isTransactionSuccessful(tx);
|
|
721
|
-
const gasUsed = this.extractGasUsed(tx);
|
|
722
|
-
const gasPrice = this.extractGasPrice(tx);
|
|
723
|
-
const blockNumber = this.extractBlockNumber(tx);
|
|
724
|
-
const transactionHash = this.extractTransactionHash(tx);
|
|
725
|
-
const logs = this.extractLogs(tx);
|
|
726
|
-
return {
|
|
727
|
-
success,
|
|
728
|
-
warp,
|
|
729
|
-
action: 0,
|
|
730
|
-
user: this.config.user?.wallets?.fastset || null,
|
|
731
|
-
txHash: transactionHash,
|
|
732
|
-
next: null,
|
|
733
|
-
values: [transactionHash, blockNumber, gasUsed, gasPrice, ...logs.length > 0 ? logs : []],
|
|
734
|
-
results: {},
|
|
735
|
-
messages: {}
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
|
-
async extractQueryResults(warp, typedValues, actionIndex, inputs) {
|
|
739
|
-
const values = typedValues.map((t) => this.serializer.typedToString(t));
|
|
740
|
-
const valuesRaw = typedValues.map((t) => this.serializer.typedToNative(t)[1]);
|
|
741
|
-
let results = {};
|
|
742
|
-
if (!warp.results) return { values, results };
|
|
743
|
-
const getNestedValue = (path) => {
|
|
744
|
-
const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
|
|
745
|
-
if (indices.length === 0) return void 0;
|
|
746
|
-
let value = valuesRaw[indices[0]];
|
|
747
|
-
for (let i = 1; i < indices.length; i++) {
|
|
748
|
-
if (value === void 0 || value === null) return void 0;
|
|
749
|
-
value = value[indices[i]];
|
|
750
|
-
}
|
|
751
|
-
return value;
|
|
752
|
-
};
|
|
753
|
-
for (const [key, path] of Object.entries(warp.results)) {
|
|
754
|
-
if (path.startsWith(import_warps3.WarpConstants.Transform.Prefix)) continue;
|
|
755
|
-
const currentActionIndex = (0, import_warps3.parseResultsOutIndex)(path);
|
|
756
|
-
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
757
|
-
results[key] = null;
|
|
758
|
-
continue;
|
|
759
|
-
}
|
|
760
|
-
if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
|
|
761
|
-
results[key] = getNestedValue(path) || null;
|
|
762
|
-
} else {
|
|
763
|
-
results[key] = path;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
return { values, results: await (0, import_warps3.evaluateResultsCommon)(warp, results, actionIndex, inputs) };
|
|
767
|
-
}
|
|
768
|
-
isTransactionSuccessful(tx) {
|
|
769
|
-
return tx.status === "success" || tx.status === 1 || tx.success === true;
|
|
770
|
-
}
|
|
771
|
-
extractGasUsed(tx) {
|
|
772
|
-
return tx.gasUsed?.toString() || tx.gas_used?.toString() || "0";
|
|
773
|
-
}
|
|
774
|
-
extractGasPrice(tx) {
|
|
775
|
-
return tx.gasPrice?.toString() || tx.gas_price?.toString() || "0";
|
|
776
|
-
}
|
|
777
|
-
extractBlockNumber(tx) {
|
|
778
|
-
return tx.blockNumber?.toString() || tx.block_number?.toString() || "0";
|
|
779
|
-
}
|
|
780
|
-
extractTransactionHash(tx) {
|
|
781
|
-
return tx.hash || tx.transactionHash || tx.transaction_hash || "";
|
|
782
|
-
}
|
|
783
|
-
extractLogs(tx) {
|
|
784
|
-
const logs = tx.logs || tx.events || [];
|
|
785
|
-
return logs.map((log) => ({
|
|
786
|
-
address: log.address || log.contract,
|
|
787
|
-
topics: log.topics || log.topics || [],
|
|
788
|
-
data: log.data || log.payload || "",
|
|
789
|
-
blockNumber: log.blockNumber?.toString() || log.block_number?.toString() || "0",
|
|
790
|
-
transactionHash: log.transactionHash || log.transaction_hash || "",
|
|
791
|
-
index: log.index?.toString() || "0"
|
|
792
|
-
}));
|
|
793
|
-
}
|
|
794
|
-
};
|
|
795
|
-
|
|
796
|
-
// src/main.ts
|
|
797
|
-
var ChainName = "fastset";
|
|
798
|
-
var getFastsetAdapter = (config, fallback) => {
|
|
799
|
-
if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
|
|
800
|
-
const chainInfo = {
|
|
801
|
-
name: ChainName,
|
|
802
|
-
displayName: "FastSet",
|
|
803
|
-
chainId: "1",
|
|
804
|
-
blockTime: 100,
|
|
805
|
-
addressHrp: "set",
|
|
806
|
-
apiUrl: "TODO",
|
|
807
|
-
nativeToken: "SET"
|
|
808
|
-
};
|
|
809
|
-
return {
|
|
810
|
-
chain: ChainName,
|
|
811
|
-
chainInfo,
|
|
812
|
-
prefix: "fastset",
|
|
813
|
-
builder: () => fallback.builder(),
|
|
814
|
-
executor: new WarpFastsetExecutor(config),
|
|
815
|
-
results: new WarpFastsetResults(config),
|
|
816
|
-
serializer: new WarpFastsetSerializer(),
|
|
817
|
-
registry: fallback.registry,
|
|
818
|
-
explorer: new WarpFastsetExplorer(chainInfo),
|
|
819
|
-
abiBuilder: () => fallback.abiBuilder(),
|
|
820
|
-
brandBuilder: () => fallback.brandBuilder(),
|
|
821
|
-
dataLoader: new WarpFastsetDataLoader(config, chainInfo)
|
|
822
|
-
};
|
|
823
|
-
};
|
|
824
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
825
|
-
0 && (module.exports = {
|
|
826
|
-
Address,
|
|
827
|
-
Amount,
|
|
828
|
-
Bytes32,
|
|
829
|
-
ClaimType,
|
|
830
|
-
FastsetClient,
|
|
831
|
-
Nonce,
|
|
832
|
-
PublicKey,
|
|
833
|
-
Transaction,
|
|
834
|
-
Transfer,
|
|
835
|
-
UserData,
|
|
836
|
-
WarpFastsetConstants,
|
|
837
|
-
WarpFastsetExecutor,
|
|
838
|
-
WarpFastsetExplorer,
|
|
839
|
-
WarpFastsetResults,
|
|
840
|
-
WarpFastsetSerializer,
|
|
841
|
-
decimalToHex,
|
|
842
|
-
fromBase64,
|
|
843
|
-
getFastsetAdapter,
|
|
844
|
-
hexToDecimal,
|
|
845
|
-
isValidFastsetAddress,
|
|
846
|
-
normalizeAmount,
|
|
847
|
-
toBase64String,
|
|
848
|
-
toHexString,
|
|
849
|
-
validateAmount,
|
|
850
|
-
validatePrivateKey,
|
|
851
|
-
validatePublicKey
|
|
852
|
-
});
|
|
853
|
-
//# sourceMappingURL=index.js.map
|