@vleap/warps-adapter-fastset 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +124 -0
- package/dist/index.d.ts +108 -116
- package/dist/index.js +539 -437
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +534 -432
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -5
- package/dist/index.d.mts +0 -132
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,250 +20,408 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// src/sdk/ed25519-setup.ts
|
|
34
|
+
var ed, import_sha512;
|
|
35
|
+
var init_ed25519_setup = __esm({
|
|
36
|
+
"src/sdk/ed25519-setup.ts"() {
|
|
37
|
+
"use strict";
|
|
38
|
+
ed = __toESM(require("@noble/ed25519"), 1);
|
|
39
|
+
import_sha512 = require("@noble/hashes/sha512");
|
|
40
|
+
if (ed.etc) {
|
|
41
|
+
ed.etc.sha512Sync = (...m) => (0, import_sha512.sha512)(ed.etc.concatBytes(...m));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// src/sdk/FastsetClient.ts
|
|
47
|
+
var bech32, Transaction, FastsetClient, Wallet;
|
|
48
|
+
var init_FastsetClient = __esm({
|
|
49
|
+
"src/sdk/FastsetClient.ts"() {
|
|
50
|
+
"use strict";
|
|
51
|
+
bech32 = __toESM(require("bech32"), 1);
|
|
52
|
+
init_ed25519_setup();
|
|
53
|
+
BigInt.prototype.toJSON = function() {
|
|
54
|
+
return Number(this);
|
|
55
|
+
};
|
|
56
|
+
Transaction = class {
|
|
57
|
+
constructor(sender, recipient, nonce, claim, timestamp = BigInt(Date.now()) * 1000000n) {
|
|
58
|
+
this.sender = sender;
|
|
59
|
+
this.recipient = recipient;
|
|
60
|
+
this.nonce = nonce;
|
|
61
|
+
this.claim = claim;
|
|
62
|
+
this.timestamp = timestamp;
|
|
63
|
+
if (claim?.Transfer?.amount?.startsWith("0x")) {
|
|
64
|
+
claim = { ...claim, Transfer: { ...claim.Transfer, amount: claim.Transfer.amount.slice(2) } };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
toTransaction() {
|
|
68
|
+
return { sender: this.sender, recipient: this.recipient, nonce: this.nonce, timestamp_nanos: this.timestamp, claim: this.claim };
|
|
69
|
+
}
|
|
70
|
+
getRecipientAddress() {
|
|
71
|
+
return this.recipient;
|
|
72
|
+
}
|
|
73
|
+
getAmount() {
|
|
74
|
+
return this.claim?.Transfer?.amount || "";
|
|
75
|
+
}
|
|
76
|
+
getUserData() {
|
|
77
|
+
return this.claim?.Transfer?.user_data || null;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
FastsetClient = class {
|
|
81
|
+
constructor(config, chain) {
|
|
82
|
+
this.proxyUrl = config && "proxyUrl" in config ? config.proxyUrl : config && chain ? chain.defaultApiUrl : "https://proxy.fastset.xyz";
|
|
83
|
+
}
|
|
84
|
+
async makeRequest(method, params = {}) {
|
|
85
|
+
const response = await fetch(this.proxyUrl, {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: { "Content-Type": "application/json" },
|
|
88
|
+
body: JSON.stringify({ jsonrpc: "2.0", method, params, id: Date.now() }, (k, v) => v instanceof Uint8Array ? Array.from(v) : v)
|
|
89
|
+
});
|
|
90
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
91
|
+
const jsonResponse = await response.json();
|
|
92
|
+
if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
|
|
93
|
+
return jsonResponse.result;
|
|
94
|
+
}
|
|
95
|
+
async getAccountInfo(address) {
|
|
96
|
+
return this.makeRequest("set_proxy_getAccountInfo", { address });
|
|
97
|
+
}
|
|
98
|
+
async getNextNonce(address) {
|
|
99
|
+
const addressBytes = typeof address === "string" ? this.addressToBytes(address) : address;
|
|
100
|
+
const accountInfo = await this.getAccountInfo(addressBytes);
|
|
101
|
+
return accountInfo.next_nonce;
|
|
102
|
+
}
|
|
103
|
+
async submitTransaction(transaction, signature) {
|
|
104
|
+
const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
|
|
105
|
+
const submitTxReq = {
|
|
106
|
+
transaction: {
|
|
107
|
+
sender: transaction.sender instanceof Uint8Array ? transaction.sender : new Uint8Array(transaction.sender),
|
|
108
|
+
recipient: transaction.recipient,
|
|
109
|
+
nonce: transaction.nonce,
|
|
110
|
+
timestamp_nanos: transaction.timestamp_nanos,
|
|
111
|
+
claim: transaction.claim
|
|
112
|
+
},
|
|
113
|
+
signature: new Uint8Array(signatureArray)
|
|
114
|
+
};
|
|
115
|
+
const response = await fetch(this.proxyUrl, {
|
|
116
|
+
method: "POST",
|
|
117
|
+
headers: { "Content-Type": "application/json" },
|
|
118
|
+
body: JSON.stringify(
|
|
119
|
+
{ jsonrpc: "2.0", method: "set_proxy_submitTransaction", params: submitTxReq, id: 1 },
|
|
120
|
+
(k, v) => v instanceof Uint8Array ? Array.from(v) : v
|
|
121
|
+
)
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
|
|
124
|
+
const jsonResponse = await response.json();
|
|
125
|
+
if (jsonResponse.error) throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
|
|
126
|
+
return jsonResponse.result;
|
|
127
|
+
}
|
|
128
|
+
async faucetDrip(recipient, amount) {
|
|
129
|
+
const recipientArray = Array.isArray(recipient) ? recipient : Array.from(recipient);
|
|
130
|
+
return this.makeRequest("set_proxy_faucetDrip", { recipient: recipientArray, amount });
|
|
131
|
+
}
|
|
132
|
+
addressToBytes(address) {
|
|
133
|
+
try {
|
|
134
|
+
const decoded = bech32.bech32m.decode(address);
|
|
135
|
+
return Array.from(bech32.bech32m.fromWords(decoded.words));
|
|
136
|
+
} catch {
|
|
137
|
+
const decoded = bech32.bech32.decode(address);
|
|
138
|
+
return Array.from(bech32.bech32.fromWords(decoded.words));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Wallet utilities
|
|
142
|
+
generateNewWallet() {
|
|
143
|
+
const privateKey = ed.utils.randomPrivateKey();
|
|
144
|
+
return new Wallet(Buffer.from(privateKey).toString("hex"));
|
|
145
|
+
}
|
|
146
|
+
createWallet(privateKeyHex) {
|
|
147
|
+
return new Wallet(privateKeyHex);
|
|
148
|
+
}
|
|
149
|
+
static decodeBech32Address(address) {
|
|
150
|
+
try {
|
|
151
|
+
const decoded = bech32.bech32m.decode(address);
|
|
152
|
+
return new Uint8Array(bech32.bech32m.fromWords(decoded.words));
|
|
153
|
+
} catch {
|
|
154
|
+
const decoded = bech32.bech32.decode(address);
|
|
155
|
+
return new Uint8Array(bech32.bech32.fromWords(decoded.words));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
static encodeBech32Address(publicKey) {
|
|
159
|
+
const words = bech32.bech32m.toWords(publicKey);
|
|
160
|
+
return bech32.bech32m.encode("set", words);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
Wallet = class {
|
|
164
|
+
constructor(privateKeyHex) {
|
|
165
|
+
this.privateKey = new Uint8Array(Buffer.from(privateKeyHex.replace(/^0x/, ""), "hex"));
|
|
166
|
+
this.publicKey = ed.getPublicKey(this.privateKey);
|
|
167
|
+
}
|
|
168
|
+
toBech32() {
|
|
169
|
+
return bech32.bech32m.encode("set", bech32.bech32m.toWords(this.publicKey));
|
|
170
|
+
}
|
|
171
|
+
signTransactionRaw(data) {
|
|
172
|
+
return ed.sign(data, this.privateKey);
|
|
173
|
+
}
|
|
174
|
+
getPrivateKey() {
|
|
175
|
+
return this.privateKey;
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// src/sdk/index.ts
|
|
182
|
+
var sdk_exports = {};
|
|
183
|
+
__export(sdk_exports, {
|
|
184
|
+
FastsetClient: () => FastsetClient,
|
|
185
|
+
Transaction: () => Transaction,
|
|
186
|
+
Wallet: () => Wallet
|
|
187
|
+
});
|
|
188
|
+
var init_sdk = __esm({
|
|
189
|
+
"src/sdk/index.ts"() {
|
|
190
|
+
"use strict";
|
|
191
|
+
init_FastsetClient();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
20
195
|
// src/index.ts
|
|
21
196
|
var index_exports = {};
|
|
22
197
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
198
|
+
FastsetClient: () => FastsetClient,
|
|
199
|
+
NativeTokenSet: () => NativeTokenSet,
|
|
200
|
+
Transaction: () => Transaction,
|
|
201
|
+
Wallet: () => Wallet,
|
|
25
202
|
WarpFastsetExecutor: () => WarpFastsetExecutor,
|
|
26
|
-
|
|
27
|
-
WarpFastsetResults: () => WarpFastsetResults,
|
|
28
|
-
WarpFastsetSerializer: () => WarpFastsetSerializer,
|
|
203
|
+
WarpFastsetWallet: () => WarpFastsetWallet,
|
|
29
204
|
getFastsetAdapter: () => getFastsetAdapter
|
|
30
205
|
});
|
|
31
206
|
module.exports = __toCommonJS(index_exports);
|
|
32
207
|
|
|
33
|
-
// src/
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
ContractDeploy: 5e5,
|
|
46
|
-
Transfer: 21e3,
|
|
47
|
-
Approve: 46e3,
|
|
48
|
-
Swap: 2e5
|
|
49
|
-
},
|
|
50
|
-
GasPrice: {
|
|
51
|
-
Default: "20000000000",
|
|
52
|
-
// 20 gwei
|
|
53
|
-
Low: "10000000000",
|
|
54
|
-
// 10 gwei
|
|
55
|
-
Medium: "20000000000",
|
|
56
|
-
// 20 gwei
|
|
57
|
-
High: "50000000000"
|
|
58
|
-
// 50 gwei
|
|
59
|
-
},
|
|
60
|
-
Network: {
|
|
61
|
-
Mainnet: {
|
|
62
|
-
ChainId: "1",
|
|
63
|
-
Name: "Fastset Mainnet",
|
|
64
|
-
BlockTime: 12
|
|
65
|
-
},
|
|
66
|
-
Testnet: {
|
|
67
|
-
ChainId: "11155111",
|
|
68
|
-
Name: "Fastset Testnet",
|
|
69
|
-
BlockTime: 12
|
|
70
|
-
},
|
|
71
|
-
Devnet: {
|
|
72
|
-
ChainId: "1337",
|
|
73
|
-
Name: "Fastset Devnet",
|
|
74
|
-
BlockTime: 12
|
|
75
|
-
}
|
|
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
|
-
}
|
|
208
|
+
// src/main.ts
|
|
209
|
+
var import_warps6 = require("@vleap/warps");
|
|
210
|
+
|
|
211
|
+
// src/WarpFastsetDataLoader.ts
|
|
212
|
+
var bech323 = __toESM(require("bech32"), 1);
|
|
213
|
+
|
|
214
|
+
// src/helpers/general.ts
|
|
215
|
+
var import_warps = require("@vleap/warps");
|
|
216
|
+
init_sdk();
|
|
217
|
+
var getConfiguredFastsetClient = (config, chain) => {
|
|
218
|
+
const proxyUrl = (0, import_warps.getProviderUrl)(config, chain.name, config.env, chain.defaultApiUrl);
|
|
219
|
+
return new FastsetClient({ proxyUrl });
|
|
91
220
|
};
|
|
92
221
|
|
|
93
|
-
// src/
|
|
94
|
-
var
|
|
95
|
-
constructor(config) {
|
|
222
|
+
// src/WarpFastsetDataLoader.ts
|
|
223
|
+
var WarpFastsetDataLoader = class {
|
|
224
|
+
constructor(config, chain) {
|
|
96
225
|
this.config = config;
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
226
|
+
this.chain = chain;
|
|
227
|
+
this.client = getConfiguredFastsetClient(config, chain);
|
|
228
|
+
}
|
|
229
|
+
async getAccount(address) {
|
|
230
|
+
const addressBytes = this.addressToBytes(address);
|
|
231
|
+
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
232
|
+
return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
|
|
233
|
+
}
|
|
234
|
+
async getAccountAssets(address) {
|
|
235
|
+
const addressBytes = this.addressToBytes(address);
|
|
236
|
+
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
237
|
+
const assets = [];
|
|
238
|
+
const balance = BigInt(parseInt(accountInfo.balance, 16));
|
|
239
|
+
if (balance > 0n) {
|
|
240
|
+
assets.push({ ...this.chain.nativeToken, amount: balance });
|
|
241
|
+
}
|
|
242
|
+
for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
|
|
243
|
+
const amount = BigInt(parseInt(tokenBalance, 16));
|
|
244
|
+
if (amount > 0n) {
|
|
245
|
+
const tokenInfo = await this.client.getTokenInfo([tokenId]);
|
|
246
|
+
const metadata = tokenInfo.requested_token_metadata[0]?.[1];
|
|
247
|
+
assets.push({
|
|
248
|
+
chain: this.chain.name,
|
|
249
|
+
identifier: Buffer.from(tokenId).toString("hex"),
|
|
250
|
+
symbol: metadata?.token_name || "UNKNOWN",
|
|
251
|
+
name: metadata?.token_name || "Unknown Token",
|
|
252
|
+
decimals: metadata?.decimals || 6,
|
|
253
|
+
logoUrl: void 0,
|
|
254
|
+
amount
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return assets;
|
|
99
259
|
}
|
|
100
|
-
async
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
this.warp = parsed;
|
|
104
|
-
this.actions = parsed.actions || [];
|
|
105
|
-
return this.build();
|
|
106
|
-
} catch (error) {
|
|
107
|
-
throw new Error(`Failed to parse Fastset warp data: ${error}`);
|
|
260
|
+
async getAsset(identifier) {
|
|
261
|
+
if (identifier === this.chain.nativeToken.identifier) {
|
|
262
|
+
return this.chain.nativeToken;
|
|
108
263
|
}
|
|
264
|
+
const tokenId = Buffer.from(identifier, "hex");
|
|
265
|
+
const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
|
|
266
|
+
const metadata = tokenInfo.requested_token_metadata[0]?.[1];
|
|
267
|
+
if (!metadata) return null;
|
|
268
|
+
return {
|
|
269
|
+
chain: this.chain.name,
|
|
270
|
+
identifier,
|
|
271
|
+
symbol: metadata.token_name,
|
|
272
|
+
name: metadata.token_name,
|
|
273
|
+
decimals: metadata.decimals,
|
|
274
|
+
logoUrl: void 0,
|
|
275
|
+
amount: BigInt(metadata.total_supply)
|
|
276
|
+
};
|
|
109
277
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return this;
|
|
278
|
+
async getAction(identifier, awaitCompleted = false) {
|
|
279
|
+
return null;
|
|
113
280
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return this;
|
|
281
|
+
async getAccountActions(address, options) {
|
|
282
|
+
return [];
|
|
117
283
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
284
|
+
addressToBytes(address) {
|
|
285
|
+
try {
|
|
286
|
+
const decoded = bech323.bech32m.decode(address);
|
|
287
|
+
return Array.from(bech323.bech32m.fromWords(decoded.words));
|
|
288
|
+
} catch {
|
|
289
|
+
try {
|
|
290
|
+
const decoded = bech323.bech32.decode(address);
|
|
291
|
+
return Array.from(bech323.bech32.fromWords(decoded.words));
|
|
292
|
+
} catch {
|
|
293
|
+
throw new Error(`Invalid FastSet address: ${address}`);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
121
296
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/WarpFastsetExecutor.ts
|
|
300
|
+
var import_warps2 = require("@vleap/warps");
|
|
301
|
+
init_sdk();
|
|
302
|
+
var WarpFastsetExecutor = class {
|
|
303
|
+
constructor(config, chain) {
|
|
304
|
+
this.config = config;
|
|
305
|
+
this.chain = chain;
|
|
306
|
+
this.fastsetClient = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
|
|
125
307
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return this;
|
|
308
|
+
async createTransaction(executable) {
|
|
309
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
310
|
+
if (action.type === "transfer") return this.createTransferTransaction(executable);
|
|
311
|
+
if (action.type === "contract") return this.createContractCallTransaction(executable);
|
|
312
|
+
if (action.type === "query") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeQuery instead");
|
|
313
|
+
if (action.type === "collect") throw new Error("WarpFastsetExecutor: Invalid type for createTransaction; Use executeCollect instead");
|
|
314
|
+
throw new Error(`WarpFastsetExecutor: Invalid type (${action.type})`);
|
|
129
315
|
}
|
|
130
|
-
async
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
hash: this.generateHash(this.warp.title || ""),
|
|
141
|
-
creator: this.config.user?.wallets?.fastset || "",
|
|
142
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
143
|
-
}
|
|
144
|
-
};
|
|
316
|
+
async createTransferTransaction(executable) {
|
|
317
|
+
const userWallet = (0, import_warps2.getWarpWalletAddressFromConfig)(this.config, executable.chain.name);
|
|
318
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
|
|
319
|
+
const senderAddress = FastsetClient.decodeBech32Address(userWallet);
|
|
320
|
+
const recipientAddress = FastsetClient.decodeBech32Address(executable.destination);
|
|
321
|
+
const nonce = await this.fastsetClient.getNextNonce(userWallet);
|
|
322
|
+
const amount = executable.transfers?.[0]?.amount ? "0x" + executable.transfers[0].amount.toString(16) : executable.value.toString();
|
|
323
|
+
const userData = executable.data ? this.fromBase64(executable.data) : null;
|
|
324
|
+
const claim = { Transfer: { amount, user_data: userData } };
|
|
325
|
+
return new Transaction(senderAddress, { FastSet: recipientAddress }, nonce, claim);
|
|
145
326
|
}
|
|
146
|
-
|
|
327
|
+
async createContractCallTransaction(executable) {
|
|
328
|
+
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
329
|
+
if (!userWallet) throw new Error("WarpFastsetExecutor: User address not set");
|
|
330
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
331
|
+
if (!action || !("func" in action) || !action.func) throw new Error("Contract action must have function name");
|
|
147
332
|
return {
|
|
148
|
-
type: "fastset-
|
|
149
|
-
|
|
150
|
-
|
|
333
|
+
type: "fastset-contract-call",
|
|
334
|
+
contract: this.fromBase64(executable.destination),
|
|
335
|
+
function: action.func,
|
|
336
|
+
data: JSON.stringify({ function: action.func, arguments: executable.args }),
|
|
337
|
+
value: executable.value,
|
|
338
|
+
chain: executable.chain
|
|
151
339
|
};
|
|
152
340
|
}
|
|
153
|
-
async
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (!warpData) {
|
|
157
|
-
throw new Error("No warp data found in transaction");
|
|
158
|
-
}
|
|
159
|
-
const parsed = typeof warpData === "string" ? JSON.parse(warpData) : warpData;
|
|
160
|
-
if (validate) {
|
|
161
|
-
this.validateWarp(parsed);
|
|
162
|
-
}
|
|
163
|
-
return parsed;
|
|
164
|
-
} catch (error) {
|
|
165
|
-
throw new Error(`Failed to create warp from Fastset transaction: ${error}`);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
async createFromTransactionHash(hash, cache) {
|
|
341
|
+
async executeQuery(executable) {
|
|
342
|
+
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
343
|
+
if (action.type !== "query") throw new Error(`Invalid action type for executeQuery: ${action.type}`);
|
|
169
344
|
try {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
return this.createFromTransaction(tx);
|
|
345
|
+
const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
|
|
346
|
+
return { success: true, result, chain: executable.chain };
|
|
175
347
|
} catch (error) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
348
|
+
return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async executeTransfer(executable) {
|
|
352
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
353
|
+
return { success: true, transaction, chain: executable.chain.name };
|
|
354
|
+
}
|
|
355
|
+
async executeTransferWithKey(executable, privateKey) {
|
|
356
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
357
|
+
const privateKeyBytes = this.fromBase64(privateKey);
|
|
358
|
+
const transactionData = {
|
|
359
|
+
sender: privateKeyBytes.slice(0, 32),
|
|
360
|
+
recipient: transaction.getRecipientAddress(),
|
|
361
|
+
nonce: await this.fastsetClient.getNextNonce(FastsetClient.encodeBech32Address(privateKeyBytes.slice(0, 32))),
|
|
362
|
+
timestamp_nanos: BigInt(Date.now()) * 1000000n,
|
|
363
|
+
claim: { Transfer: { amount: transaction.getAmount(), user_data: transaction.getUserData() } }
|
|
364
|
+
};
|
|
365
|
+
const signature = await this.signTransaction(transactionData, privateKeyBytes);
|
|
366
|
+
const result = await this.fastsetClient.submitTransaction(transactionData, signature);
|
|
367
|
+
return { success: true, result, message: "Transaction submitted successfully", chain: executable.chain.name };
|
|
179
368
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const char = data.charCodeAt(i);
|
|
184
|
-
hash = (hash << 5) - hash + char;
|
|
185
|
-
hash = hash & hash;
|
|
186
|
-
}
|
|
187
|
-
return hash.toString(16);
|
|
369
|
+
async signTransaction(transaction, privateKey) {
|
|
370
|
+
const wallet = new (await Promise.resolve().then(() => (init_sdk(), sdk_exports))).Wallet(Buffer.from(privateKey).toString("hex"));
|
|
371
|
+
return wallet.signTransactionRaw(this.serializeTransaction(transaction));
|
|
188
372
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
if (!warp.actions || !Array.isArray(warp.actions)) {
|
|
194
|
-
throw new Error("Warp must have actions array");
|
|
195
|
-
}
|
|
373
|
+
serializeTransaction(tx) {
|
|
374
|
+
const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
|
|
375
|
+
return new TextEncoder().encode(serialized);
|
|
196
376
|
}
|
|
197
|
-
async
|
|
198
|
-
const response = await fetch(
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
377
|
+
async executeFastsetQuery(contractAddress, functionName, args) {
|
|
378
|
+
const response = await fetch("https://proxy.fastset.xyz", {
|
|
379
|
+
method: "POST",
|
|
380
|
+
headers: { "Content-Type": "application/json" },
|
|
381
|
+
body: JSON.stringify({
|
|
382
|
+
jsonrpc: "2.0",
|
|
383
|
+
method: "set_proxy_query",
|
|
384
|
+
params: { contract: Array.from(contractAddress), function: functionName, arguments: args },
|
|
385
|
+
id: 1
|
|
386
|
+
})
|
|
387
|
+
});
|
|
388
|
+
if (!response.ok) throw new Error(`Query failed: ${response.statusText}`);
|
|
202
389
|
return response.json();
|
|
203
390
|
}
|
|
204
|
-
|
|
205
|
-
return
|
|
391
|
+
fromBase64(base64) {
|
|
392
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
206
393
|
}
|
|
207
394
|
};
|
|
208
395
|
|
|
209
|
-
// src/
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
mainnet: {
|
|
216
|
-
apiUrl: "https://mainnet.fastset.com/api",
|
|
217
|
-
explorerUrl: "https://explorer.fastset.com",
|
|
218
|
-
chainId: "1",
|
|
219
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
220
|
-
nativeToken: "PI",
|
|
221
|
-
blockTime: 12
|
|
222
|
-
},
|
|
223
|
-
testnet: {
|
|
224
|
-
apiUrl: "https://testnet.fastset.com/api",
|
|
225
|
-
explorerUrl: "https://testnet-explorer.fastset.com",
|
|
226
|
-
chainId: "11155111",
|
|
227
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
228
|
-
nativeToken: "PI",
|
|
229
|
-
blockTime: 12
|
|
230
|
-
},
|
|
231
|
-
devnet: {
|
|
232
|
-
apiUrl: "http://localhost:8545",
|
|
233
|
-
explorerUrl: "http://localhost:4000",
|
|
234
|
-
chainId: "1337",
|
|
235
|
-
registryAddress: "0x0000000000000000000000000000000000000000",
|
|
236
|
-
nativeToken: "PI",
|
|
237
|
-
blockTime: 12
|
|
238
|
-
}
|
|
396
|
+
// src/WarpFastsetExplorer.ts
|
|
397
|
+
var WarpFastsetExplorer = class {
|
|
398
|
+
constructor(_chainInfo, _config) {
|
|
399
|
+
this._chainInfo = _chainInfo;
|
|
400
|
+
this._config = _config;
|
|
401
|
+
this.explorerUrl = "https://explorer.fastset.xyz";
|
|
239
402
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
throw new Error(`Unsupported Fastset chain: ${chain}`);
|
|
403
|
+
getAccountUrl(address) {
|
|
404
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
405
|
+
}
|
|
406
|
+
getTransactionUrl(hash) {
|
|
407
|
+
return `${this.explorerUrl}/transaction/${hash}`;
|
|
246
408
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
409
|
+
getAssetUrl(identifier) {
|
|
410
|
+
return `${this.explorerUrl}/asset/${identifier}`;
|
|
411
|
+
}
|
|
412
|
+
getContractUrl(address) {
|
|
413
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
250
414
|
}
|
|
251
|
-
return config;
|
|
252
|
-
};
|
|
253
|
-
var getFastsetApiUrl = (env, chain = DEFAULT_CHAIN) => {
|
|
254
|
-
return getFastsetChainConfig(chain, env).apiUrl;
|
|
255
415
|
};
|
|
256
416
|
|
|
417
|
+
// src/WarpFastsetResults.ts
|
|
418
|
+
var import_warps4 = require("@vleap/warps");
|
|
419
|
+
|
|
257
420
|
// src/WarpFastsetSerializer.ts
|
|
258
|
-
var
|
|
421
|
+
var import_warps3 = require("@vleap/warps");
|
|
259
422
|
var WarpFastsetSerializer = class {
|
|
260
423
|
constructor() {
|
|
261
|
-
this.coreSerializer = new
|
|
424
|
+
this.coreSerializer = new import_warps3.WarpSerializer();
|
|
262
425
|
}
|
|
263
426
|
typedToString(value) {
|
|
264
427
|
if (typeof value === "string") {
|
|
@@ -271,7 +434,7 @@ var WarpFastsetSerializer = class {
|
|
|
271
434
|
return `boolean:${value}`;
|
|
272
435
|
}
|
|
273
436
|
if (typeof value === "bigint") {
|
|
274
|
-
return `
|
|
437
|
+
return `biguint:${value.toString()}`;
|
|
275
438
|
}
|
|
276
439
|
if (Array.isArray(value)) {
|
|
277
440
|
const items = value.map((item) => this.typedToString(item)).join(",");
|
|
@@ -296,7 +459,7 @@ var WarpFastsetSerializer = class {
|
|
|
296
459
|
return ["boolean", value];
|
|
297
460
|
}
|
|
298
461
|
if (typeof value === "bigint") {
|
|
299
|
-
return ["
|
|
462
|
+
return ["biguint", value.toString()];
|
|
300
463
|
}
|
|
301
464
|
return ["string", String(value)];
|
|
302
465
|
}
|
|
@@ -308,8 +471,12 @@ var WarpFastsetSerializer = class {
|
|
|
308
471
|
return Number(value);
|
|
309
472
|
case "boolean":
|
|
310
473
|
return Boolean(value);
|
|
311
|
-
case "
|
|
474
|
+
case "biguint":
|
|
312
475
|
return BigInt(value);
|
|
476
|
+
case "address":
|
|
477
|
+
return String(value);
|
|
478
|
+
case "hex":
|
|
479
|
+
return String(value);
|
|
313
480
|
default:
|
|
314
481
|
return String(value);
|
|
315
482
|
}
|
|
@@ -322,8 +489,12 @@ var WarpFastsetSerializer = class {
|
|
|
322
489
|
return "number";
|
|
323
490
|
case "boolean":
|
|
324
491
|
return "boolean";
|
|
325
|
-
case "
|
|
326
|
-
return "
|
|
492
|
+
case "biguint":
|
|
493
|
+
return "biguint";
|
|
494
|
+
case "address":
|
|
495
|
+
return "address";
|
|
496
|
+
case "hex":
|
|
497
|
+
return "hex";
|
|
327
498
|
default:
|
|
328
499
|
return "string";
|
|
329
500
|
}
|
|
@@ -342,7 +513,7 @@ var WarpFastsetSerializer = class {
|
|
|
342
513
|
return Number(stringValue);
|
|
343
514
|
case "boolean":
|
|
344
515
|
return stringValue === "true";
|
|
345
|
-
case "
|
|
516
|
+
case "biguint":
|
|
346
517
|
return BigInt(stringValue);
|
|
347
518
|
case "array":
|
|
348
519
|
return stringValue.split(",").map((item) => this.stringToTyped(item));
|
|
@@ -356,207 +527,28 @@ var WarpFastsetSerializer = class {
|
|
|
356
527
|
}
|
|
357
528
|
};
|
|
358
529
|
|
|
359
|
-
// src/WarpFastsetExecutor.ts
|
|
360
|
-
var WarpFastsetExecutor = class {
|
|
361
|
-
constructor(config) {
|
|
362
|
-
this.config = config;
|
|
363
|
-
this.serializer = new WarpFastsetSerializer();
|
|
364
|
-
}
|
|
365
|
-
async createTransaction(executable) {
|
|
366
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
367
|
-
let tx = null;
|
|
368
|
-
if (action.type === "transfer") {
|
|
369
|
-
tx = await this.createTransferTransaction(executable);
|
|
370
|
-
} else if (action.type === "contract") {
|
|
371
|
-
tx = await this.createContractCallTransaction(executable);
|
|
372
|
-
} else if (action.type === "query") {
|
|
373
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
374
|
-
} else if (action.type === "collect") {
|
|
375
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
376
|
-
}
|
|
377
|
-
if (!tx) throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
378
|
-
return tx;
|
|
379
|
-
}
|
|
380
|
-
async createTransferTransaction(executable) {
|
|
381
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
382
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
383
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
384
|
-
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
385
|
-
}
|
|
386
|
-
if (executable.value < 0) {
|
|
387
|
-
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
388
|
-
}
|
|
389
|
-
return {
|
|
390
|
-
type: "fastset-transfer",
|
|
391
|
-
from: userWallet,
|
|
392
|
-
to: executable.destination,
|
|
393
|
-
value: executable.value,
|
|
394
|
-
data: executable.data ? this.serializer.stringToTyped(executable.data) : ""
|
|
395
|
-
// TODO: Add Fastset-specific transaction fields
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
async createContractCallTransaction(executable) {
|
|
399
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
400
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
401
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
402
|
-
if (!action || !("func" in action) || !action.func) {
|
|
403
|
-
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
404
|
-
}
|
|
405
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
406
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
407
|
-
}
|
|
408
|
-
if (executable.value < 0) {
|
|
409
|
-
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
410
|
-
}
|
|
411
|
-
try {
|
|
412
|
-
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
413
|
-
return {
|
|
414
|
-
type: "fastset-contract-call",
|
|
415
|
-
from: userWallet,
|
|
416
|
-
to: executable.destination,
|
|
417
|
-
value: executable.value,
|
|
418
|
-
data: encodedData,
|
|
419
|
-
function: action.func
|
|
420
|
-
// TODO: Add Fastset-specific transaction fields
|
|
421
|
-
};
|
|
422
|
-
} catch (error) {
|
|
423
|
-
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
async executeQuery(executable) {
|
|
427
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
428
|
-
if (action.type !== "query") {
|
|
429
|
-
throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
430
|
-
}
|
|
431
|
-
if (!action.func) {
|
|
432
|
-
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
433
|
-
}
|
|
434
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
435
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
436
|
-
}
|
|
437
|
-
try {
|
|
438
|
-
const result = await this.executeFastsetQuery(executable.destination, action.func, executable.args);
|
|
439
|
-
return {
|
|
440
|
-
success: true,
|
|
441
|
-
result
|
|
442
|
-
// TODO: Add Fastset-specific result fields
|
|
443
|
-
};
|
|
444
|
-
} catch (error) {
|
|
445
|
-
return {
|
|
446
|
-
success: false,
|
|
447
|
-
error: error instanceof Error ? error.message : String(error)
|
|
448
|
-
// TODO: Add Fastset-specific error fields
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
async preprocessInput(chain, input, type, value) {
|
|
453
|
-
const typedValue = this.serializer.stringToTyped(value);
|
|
454
|
-
switch (type) {
|
|
455
|
-
case "address":
|
|
456
|
-
if (!this.isValidFastsetAddress(typedValue)) {
|
|
457
|
-
throw new Error(`Invalid Fastset address format: ${typedValue}`);
|
|
458
|
-
}
|
|
459
|
-
return typedValue;
|
|
460
|
-
case "number":
|
|
461
|
-
const numValue = Number(typedValue);
|
|
462
|
-
if (isNaN(numValue)) {
|
|
463
|
-
throw new Error(`Invalid number format: ${typedValue}`);
|
|
464
|
-
}
|
|
465
|
-
return numValue.toString();
|
|
466
|
-
case "bigint":
|
|
467
|
-
const bigIntValue = BigInt(typedValue);
|
|
468
|
-
if (bigIntValue < 0) {
|
|
469
|
-
throw new Error(`Negative value not allowed for type ${type}: ${typedValue}`);
|
|
470
|
-
}
|
|
471
|
-
return bigIntValue.toString();
|
|
472
|
-
default:
|
|
473
|
-
return String(typedValue);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
isValidFastsetAddress(address) {
|
|
477
|
-
return typeof address === "string" && address.length > 0;
|
|
478
|
-
}
|
|
479
|
-
encodeFunctionData(functionName, args) {
|
|
480
|
-
return JSON.stringify({
|
|
481
|
-
function: functionName,
|
|
482
|
-
arguments: args
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
async executeFastsetQuery(contractAddress, functionName, args) {
|
|
486
|
-
const response = await fetch(`${getFastsetApiUrl(this.config.env, "fastset")}/query`, {
|
|
487
|
-
method: "POST",
|
|
488
|
-
headers: {
|
|
489
|
-
"Content-Type": "application/json"
|
|
490
|
-
},
|
|
491
|
-
body: JSON.stringify({
|
|
492
|
-
contract: contractAddress,
|
|
493
|
-
function: functionName,
|
|
494
|
-
arguments: args
|
|
495
|
-
})
|
|
496
|
-
});
|
|
497
|
-
if (!response.ok) {
|
|
498
|
-
throw new Error(`Fastset query failed: ${response.statusText}`);
|
|
499
|
-
}
|
|
500
|
-
return response.json();
|
|
501
|
-
}
|
|
502
|
-
async signMessage(message, privateKey) {
|
|
503
|
-
throw new Error("Not implemented");
|
|
504
|
-
}
|
|
505
|
-
};
|
|
506
|
-
|
|
507
|
-
// src/WarpFastsetExplorer.ts
|
|
508
|
-
var WarpFastsetExplorer = class {
|
|
509
|
-
constructor(chainInfo, chainName = "fastset") {
|
|
510
|
-
this.chainInfo = chainInfo;
|
|
511
|
-
this.chainName = chainName;
|
|
512
|
-
}
|
|
513
|
-
getAccountUrl(address) {
|
|
514
|
-
const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
|
|
515
|
-
return `${baseUrl}/address/${address}`;
|
|
516
|
-
}
|
|
517
|
-
getTransactionUrl(hash) {
|
|
518
|
-
const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
|
|
519
|
-
return `${baseUrl}/tx/${hash}`;
|
|
520
|
-
}
|
|
521
|
-
getBlockUrl(blockNumber) {
|
|
522
|
-
const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
|
|
523
|
-
return `${baseUrl}/block/${blockNumber}`;
|
|
524
|
-
}
|
|
525
|
-
getContractUrl(address) {
|
|
526
|
-
const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
|
|
527
|
-
return `${baseUrl}/contract/${address}`;
|
|
528
|
-
}
|
|
529
|
-
getTokenUrl(address) {
|
|
530
|
-
const baseUrl = this.chainInfo.explorerUrl || this.getDefaultExplorerUrl();
|
|
531
|
-
return `${baseUrl}/token/${address}`;
|
|
532
|
-
}
|
|
533
|
-
getDefaultExplorerUrl() {
|
|
534
|
-
return `https://explorer.fastset.xyz`;
|
|
535
|
-
}
|
|
536
|
-
};
|
|
537
|
-
|
|
538
530
|
// src/WarpFastsetResults.ts
|
|
539
|
-
var import_warps3 = require("@vleap/warps");
|
|
540
531
|
var WarpFastsetResults = class {
|
|
541
|
-
constructor(config) {
|
|
532
|
+
constructor(config, chain) {
|
|
542
533
|
this.config = config;
|
|
534
|
+
this.chain = chain;
|
|
543
535
|
this.serializer = new WarpFastsetSerializer();
|
|
544
536
|
}
|
|
545
537
|
async getTransactionExecutionResults(warp, tx) {
|
|
546
538
|
const success = this.isTransactionSuccessful(tx);
|
|
547
|
-
const gasUsed = this.extractGasUsed(tx);
|
|
548
|
-
const gasPrice = this.extractGasPrice(tx);
|
|
549
|
-
const blockNumber = this.extractBlockNumber(tx);
|
|
550
539
|
const transactionHash = this.extractTransactionHash(tx);
|
|
551
|
-
const
|
|
540
|
+
const blockNumber = this.extractBlockNumber(tx);
|
|
541
|
+
const timestamp = this.extractTimestamp(tx);
|
|
552
542
|
return {
|
|
553
543
|
success,
|
|
554
544
|
warp,
|
|
555
545
|
action: 0,
|
|
556
|
-
user: this.config.
|
|
546
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
557
547
|
txHash: transactionHash,
|
|
548
|
+
tx,
|
|
558
549
|
next: null,
|
|
559
|
-
values: [transactionHash, blockNumber,
|
|
550
|
+
values: [transactionHash, blockNumber, timestamp],
|
|
551
|
+
valuesRaw: [transactionHash, blockNumber, timestamp],
|
|
560
552
|
results: {},
|
|
561
553
|
messages: {}
|
|
562
554
|
};
|
|
@@ -567,6 +559,11 @@ var WarpFastsetResults = class {
|
|
|
567
559
|
let results = {};
|
|
568
560
|
if (!warp.results) return { values, results };
|
|
569
561
|
const getNestedValue = (path) => {
|
|
562
|
+
const match = path.match(/^out\[(\d+)\]$/);
|
|
563
|
+
if (match) {
|
|
564
|
+
const index = parseInt(match[1]) - 1;
|
|
565
|
+
return valuesRaw[index];
|
|
566
|
+
}
|
|
570
567
|
const indices = path.split(".").slice(1).map((i) => parseInt(i) - 1);
|
|
571
568
|
if (indices.length === 0) return void 0;
|
|
572
569
|
let value = valuesRaw[indices[0]];
|
|
@@ -577,72 +574,177 @@ var WarpFastsetResults = class {
|
|
|
577
574
|
return value;
|
|
578
575
|
};
|
|
579
576
|
for (const [key, path] of Object.entries(warp.results)) {
|
|
580
|
-
if (path.startsWith(
|
|
581
|
-
const currentActionIndex = (0,
|
|
577
|
+
if (path.startsWith(import_warps4.WarpConstants.Transform.Prefix)) continue;
|
|
578
|
+
const currentActionIndex = (0, import_warps4.parseResultsOutIndex)(path);
|
|
582
579
|
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
583
580
|
results[key] = null;
|
|
584
581
|
continue;
|
|
585
582
|
}
|
|
586
583
|
if (path.startsWith("out.") || path === "out" || path.startsWith("out[")) {
|
|
587
|
-
|
|
584
|
+
const value = getNestedValue(path);
|
|
585
|
+
results[key] = value || null;
|
|
588
586
|
} else {
|
|
589
587
|
results[key] = path;
|
|
590
588
|
}
|
|
591
589
|
}
|
|
592
|
-
return { values, results: await (0,
|
|
590
|
+
return { values, results: await (0, import_warps4.evaluateResultsCommon)(warp, results, actionIndex, inputs, this.config.transform?.runner) };
|
|
593
591
|
}
|
|
594
592
|
isTransactionSuccessful(tx) {
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
593
|
+
if (!tx) return false;
|
|
594
|
+
if (tx.success === false) return false;
|
|
595
|
+
if (tx.success === true) return true;
|
|
596
|
+
if (tx.status === "success") return true;
|
|
597
|
+
if (tx.status === 1) return true;
|
|
598
|
+
if (tx.result && tx.result.success === true) return true;
|
|
599
|
+
return false;
|
|
599
600
|
}
|
|
600
|
-
|
|
601
|
-
|
|
601
|
+
extractTransactionHash(tx) {
|
|
602
|
+
if (!tx) return "";
|
|
603
|
+
return tx.transaction_hash || tx.transactionHash || tx.hash || tx.result && tx.result.transaction_hash || "";
|
|
602
604
|
}
|
|
603
605
|
extractBlockNumber(tx) {
|
|
604
|
-
|
|
606
|
+
if (!tx) return "0";
|
|
607
|
+
return tx.block_number?.toString() || tx.blockNumber?.toString() || tx.result && tx.result.block_number?.toString() || "0";
|
|
605
608
|
}
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
609
|
+
extractTimestamp(tx) {
|
|
610
|
+
if (!tx) return "0";
|
|
611
|
+
return tx.timestamp?.toString() || tx.timestamp_nanos?.toString() || tx.result && tx.result.timestamp?.toString() || Date.now().toString();
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// src/WarpFastsetWallet.ts
|
|
616
|
+
var import_warps5 = require("@vleap/warps");
|
|
617
|
+
init_sdk();
|
|
618
|
+
init_ed25519_setup();
|
|
619
|
+
var WarpFastsetWallet = class {
|
|
620
|
+
constructor(config, chain) {
|
|
621
|
+
this.config = config;
|
|
622
|
+
this.chain = chain;
|
|
623
|
+
this.wallet = null;
|
|
624
|
+
this.initializeWallet();
|
|
625
|
+
}
|
|
626
|
+
initializeWallet() {
|
|
627
|
+
const walletConfig = this.config.user?.wallets?.[this.chain.name];
|
|
628
|
+
if (walletConfig && typeof walletConfig === "object" && "privateKey" in walletConfig && walletConfig.privateKey) {
|
|
629
|
+
this.wallet = new Wallet(walletConfig.privateKey);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
async signTransaction(tx) {
|
|
633
|
+
if (!this.wallet) throw new Error("Wallet not initialized");
|
|
634
|
+
const transaction = tx;
|
|
635
|
+
const serializedTx = this.serializeTransaction(transaction.toTransaction());
|
|
636
|
+
const signature = await ed.sign(serializedTx, this.wallet.getPrivateKey());
|
|
637
|
+
return Object.assign(transaction, { signature });
|
|
638
|
+
}
|
|
639
|
+
async signMessage(message) {
|
|
640
|
+
if (!this.wallet) throw new Error("Wallet not initialized");
|
|
641
|
+
const signature = await ed.sign(new TextEncoder().encode(message), this.wallet.getPrivateKey());
|
|
642
|
+
return Buffer.from(signature).toString("hex");
|
|
643
|
+
}
|
|
644
|
+
async sendTransaction(tx) {
|
|
645
|
+
if (!this.wallet) throw new Error("Wallet not initialized");
|
|
646
|
+
const transaction = tx;
|
|
647
|
+
const fastsetTx = transaction.toTransaction();
|
|
648
|
+
const transactionData = {
|
|
649
|
+
sender: fastsetTx.sender,
|
|
650
|
+
recipient: fastsetTx.recipient,
|
|
651
|
+
nonce: fastsetTx.nonce,
|
|
652
|
+
timestamp_nanos: fastsetTx.timestamp_nanos,
|
|
653
|
+
claim: fastsetTx.claim
|
|
654
|
+
};
|
|
655
|
+
const signature = tx.signature ? new Uint8Array(Buffer.from(tx.signature, "hex")) : await ed.sign(this.serializeTransaction(transactionData), this.wallet.getPrivateKey());
|
|
656
|
+
const client = new FastsetClient({ proxyUrl: "https://proxy.fastset.xyz" });
|
|
657
|
+
return await client.submitTransaction(transactionData, signature);
|
|
658
|
+
}
|
|
659
|
+
create(mnemonic) {
|
|
660
|
+
const wallet = new Wallet(mnemonic);
|
|
661
|
+
return { address: wallet.toBech32(), privateKey: Buffer.from(wallet.getPrivateKey()).toString("hex"), mnemonic };
|
|
662
|
+
}
|
|
663
|
+
generate() {
|
|
664
|
+
const privateKey = ed.utils.randomPrivateKey();
|
|
665
|
+
const wallet = new Wallet(Buffer.from(privateKey).toString("hex"));
|
|
666
|
+
return { address: wallet.toBech32(), privateKey: Buffer.from(privateKey).toString("hex"), mnemonic: null };
|
|
667
|
+
}
|
|
668
|
+
getAddress() {
|
|
669
|
+
return (0, import_warps5.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
|
|
670
|
+
}
|
|
671
|
+
serializeTransaction(tx) {
|
|
672
|
+
const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
|
|
673
|
+
return new TextEncoder().encode(serialized);
|
|
619
674
|
}
|
|
620
675
|
};
|
|
621
676
|
|
|
622
677
|
// src/main.ts
|
|
623
|
-
var
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
results: new WarpFastsetResults(config),
|
|
631
|
-
serializer: new WarpFastsetSerializer(),
|
|
632
|
-
registry: fallback.registry,
|
|
633
|
-
explorer: (chainInfo) => new WarpFastsetExplorer(chainInfo),
|
|
634
|
-
abiBuilder: () => fallback.abiBuilder(),
|
|
635
|
-
brandBuilder: () => fallback.brandBuilder()
|
|
636
|
-
};
|
|
678
|
+
var NativeTokenSet = {
|
|
679
|
+
chain: import_warps6.WarpChainName.Fastset,
|
|
680
|
+
identifier: "SET",
|
|
681
|
+
name: "SET",
|
|
682
|
+
symbol: "SET",
|
|
683
|
+
decimals: 6,
|
|
684
|
+
logoUrl: "https://vleap.ai/images/tokens/set.svg"
|
|
637
685
|
};
|
|
686
|
+
function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
|
|
687
|
+
return (config, fallback) => {
|
|
688
|
+
const chainInfo = chainInfos[config.env];
|
|
689
|
+
if (!chainInfo) throw new Error(`FastsetAdapter: chain info not found for chain ${chainName}`);
|
|
690
|
+
if (!fallback) throw new Error("Fastset adapter requires a fallback adapter");
|
|
691
|
+
return {
|
|
692
|
+
chain: chainName,
|
|
693
|
+
chainInfo,
|
|
694
|
+
prefix: chainPrefix,
|
|
695
|
+
builder: () => fallback.builder(),
|
|
696
|
+
executor: new WarpFastsetExecutor(config, chainInfo),
|
|
697
|
+
results: new WarpFastsetResults(config, chainInfo),
|
|
698
|
+
serializer: new WarpFastsetSerializer(),
|
|
699
|
+
registry: fallback.registry,
|
|
700
|
+
explorer: new WarpFastsetExplorer(chainInfo, config),
|
|
701
|
+
abiBuilder: () => fallback.abiBuilder(),
|
|
702
|
+
brandBuilder: () => fallback.brandBuilder(),
|
|
703
|
+
dataLoader: new WarpFastsetDataLoader(config, chainInfo),
|
|
704
|
+
wallet: new WarpFastsetWallet(config, chainInfo)
|
|
705
|
+
};
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset, "fastset", {
|
|
709
|
+
mainnet: {
|
|
710
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
711
|
+
displayName: "FastSet",
|
|
712
|
+
chainId: "1",
|
|
713
|
+
blockTime: 1e3,
|
|
714
|
+
addressHrp: "set",
|
|
715
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
716
|
+
nativeToken: NativeTokenSet
|
|
717
|
+
},
|
|
718
|
+
testnet: {
|
|
719
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
720
|
+
displayName: "FastSet Testnet",
|
|
721
|
+
chainId: "testnet",
|
|
722
|
+
blockTime: 1e3,
|
|
723
|
+
addressHrp: "set",
|
|
724
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
725
|
+
nativeToken: NativeTokenSet
|
|
726
|
+
},
|
|
727
|
+
devnet: {
|
|
728
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
729
|
+
displayName: "FastSet Devnet",
|
|
730
|
+
chainId: "devnet",
|
|
731
|
+
blockTime: 1e3,
|
|
732
|
+
addressHrp: "set",
|
|
733
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
734
|
+
nativeToken: NativeTokenSet
|
|
735
|
+
}
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
// src/index.ts
|
|
739
|
+
init_sdk();
|
|
638
740
|
// Annotate the CommonJS export names for ESM import in node:
|
|
639
741
|
0 && (module.exports = {
|
|
640
|
-
|
|
641
|
-
|
|
742
|
+
FastsetClient,
|
|
743
|
+
NativeTokenSet,
|
|
744
|
+
Transaction,
|
|
745
|
+
Wallet,
|
|
642
746
|
WarpFastsetExecutor,
|
|
643
|
-
|
|
644
|
-
WarpFastsetResults,
|
|
645
|
-
WarpFastsetSerializer,
|
|
747
|
+
WarpFastsetWallet,
|
|
646
748
|
getFastsetAdapter
|
|
647
749
|
});
|
|
648
750
|
//# sourceMappingURL=index.js.map
|