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