@vleap/warps-adapter-fastset 0.1.0-alpha.20 → 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 +76 -97
- package/dist/index.d.ts +76 -97
- package/dist/index.js +380 -513
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +379 -501
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
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
|
+
};
|
|
8
11
|
var __export = (target, all) => {
|
|
9
12
|
for (var name in all)
|
|
10
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,178 +30,193 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
30
|
));
|
|
28
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
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
|
+
|
|
30
195
|
// src/index.ts
|
|
31
196
|
var index_exports = {};
|
|
32
197
|
__export(index_exports, {
|
|
33
198
|
FastsetClient: () => FastsetClient,
|
|
34
199
|
NativeTokenSet: () => NativeTokenSet,
|
|
35
|
-
|
|
36
|
-
|
|
200
|
+
Transaction: () => Transaction,
|
|
201
|
+
Wallet: () => Wallet,
|
|
37
202
|
WarpFastsetExecutor: () => WarpFastsetExecutor,
|
|
38
|
-
|
|
39
|
-
WarpFastsetResults: () => WarpFastsetResults,
|
|
40
|
-
WarpFastsetSerializer: () => WarpFastsetSerializer,
|
|
203
|
+
WarpFastsetWallet: () => WarpFastsetWallet,
|
|
41
204
|
getFastsetAdapter: () => getFastsetAdapter
|
|
42
205
|
});
|
|
43
206
|
module.exports = __toCommonJS(index_exports);
|
|
44
207
|
|
|
45
|
-
// src/constants.ts
|
|
46
|
-
var WarpFastsetConstants = {
|
|
47
|
-
// Placeholder for future FastSet-specific constants
|
|
48
|
-
};
|
|
49
|
-
|
|
50
208
|
// src/main.ts
|
|
51
|
-
var
|
|
209
|
+
var import_warps6 = require("@vleap/warps");
|
|
52
210
|
|
|
53
211
|
// src/WarpFastsetDataLoader.ts
|
|
54
212
|
var bech323 = __toESM(require("bech32"), 1);
|
|
55
213
|
|
|
56
|
-
// src/
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
External: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
63
|
-
FastSet: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
|
|
64
|
-
}),
|
|
65
|
-
nonce: import_bcs.bcs.u64(),
|
|
66
|
-
timestamp_nanos: import_bcs.bcs.u128(),
|
|
67
|
-
claim: import_bcs.bcs.enum("ClaimType", {
|
|
68
|
-
Transfer: import_bcs.bcs.struct("Transfer", {
|
|
69
|
-
recipient: import_bcs.bcs.enum("Address", {
|
|
70
|
-
External: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
71
|
-
FastSet: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
|
|
72
|
-
}),
|
|
73
|
-
amount: import_bcs.bcs.string(),
|
|
74
|
-
user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
|
|
75
|
-
}),
|
|
76
|
-
TokenTransfer: import_bcs.bcs.struct("TokenTransfer", {
|
|
77
|
-
token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
78
|
-
amount: import_bcs.bcs.string(),
|
|
79
|
-
user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
|
|
80
|
-
}),
|
|
81
|
-
TokenCreation: import_bcs.bcs.struct("TokenCreation", {
|
|
82
|
-
token_name: import_bcs.bcs.string(),
|
|
83
|
-
decimals: import_bcs.bcs.u8(),
|
|
84
|
-
initial_amount: import_bcs.bcs.string(),
|
|
85
|
-
mints: import_bcs.bcs.vector(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
|
|
86
|
-
user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
|
|
87
|
-
}),
|
|
88
|
-
TokenManagement: import_bcs.bcs.struct("TokenManagement", {
|
|
89
|
-
token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
90
|
-
update_id: import_bcs.bcs.u64(),
|
|
91
|
-
new_admin: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
|
|
92
|
-
mints: import_bcs.bcs.vector(
|
|
93
|
-
import_bcs.bcs.tuple([
|
|
94
|
-
import_bcs.bcs.enum("AddressChange", {
|
|
95
|
-
Add: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
96
|
-
Remove: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
|
|
97
|
-
}),
|
|
98
|
-
import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())
|
|
99
|
-
])
|
|
100
|
-
),
|
|
101
|
-
user_data: import_bcs.bcs.option(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()))
|
|
102
|
-
}),
|
|
103
|
-
Mint: import_bcs.bcs.struct("Mint", {
|
|
104
|
-
token_id: import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()),
|
|
105
|
-
amount: import_bcs.bcs.string()
|
|
106
|
-
}),
|
|
107
|
-
ExternalClaim: import_bcs.bcs.struct("ExternalClaim", {
|
|
108
|
-
claim: import_bcs.bcs.struct("ExternalClaimBody", {
|
|
109
|
-
verifier_committee: import_bcs.bcs.vector(import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8())),
|
|
110
|
-
verifier_quorum: import_bcs.bcs.u64(),
|
|
111
|
-
claim_data: import_bcs.bcs.vector(import_bcs.bcs.u8())
|
|
112
|
-
}),
|
|
113
|
-
signatures: import_bcs.bcs.vector(import_bcs.bcs.tuple([import_bcs.bcs.fixedArray(32, import_bcs.bcs.u8()), import_bcs.bcs.fixedArray(64, import_bcs.bcs.u8())]))
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
var FastsetClient = class {
|
|
118
|
-
constructor(config, chain) {
|
|
119
|
-
if (config && "proxyUrl" in config) {
|
|
120
|
-
this.apiUrl = config.proxyUrl;
|
|
121
|
-
} else if (config && chain) {
|
|
122
|
-
this.apiUrl = chain.defaultApiUrl;
|
|
123
|
-
} else {
|
|
124
|
-
this.apiUrl = "https://rpc.fastset.xyz";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async makeRequest(method, params = {}) {
|
|
128
|
-
const response = await fetch(this.apiUrl, {
|
|
129
|
-
method: "POST",
|
|
130
|
-
headers: {
|
|
131
|
-
"Content-Type": "application/json"
|
|
132
|
-
},
|
|
133
|
-
body: JSON.stringify({
|
|
134
|
-
jsonrpc: "2.0",
|
|
135
|
-
method,
|
|
136
|
-
params,
|
|
137
|
-
id: Date.now()
|
|
138
|
-
})
|
|
139
|
-
});
|
|
140
|
-
if (!response.ok) {
|
|
141
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
142
|
-
}
|
|
143
|
-
const jsonResponse = await response.json();
|
|
144
|
-
if (jsonResponse.error) {
|
|
145
|
-
throw new Error(`JSON-RPC error ${jsonResponse.error.code}: ${jsonResponse.error.message}`);
|
|
146
|
-
}
|
|
147
|
-
return jsonResponse.result;
|
|
148
|
-
}
|
|
149
|
-
async getAccountInfo(address, token_balance_filter, certificate_by_nonce) {
|
|
150
|
-
return this.makeRequest("set_getAccountInfo", {
|
|
151
|
-
address,
|
|
152
|
-
token_balance_filter,
|
|
153
|
-
certificate_by_nonce
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
async getTokenInfo(token_ids) {
|
|
157
|
-
return this.makeRequest("set_getTokenInfo", {
|
|
158
|
-
token_ids
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
async getTransfers(page) {
|
|
162
|
-
return this.makeRequest("set_getTransfers", { page });
|
|
163
|
-
}
|
|
164
|
-
async getClaims(confirmed, page) {
|
|
165
|
-
return this.makeRequest("set_getClaims", { confirmed, page });
|
|
166
|
-
}
|
|
167
|
-
async getClaimsByAddress(address, page) {
|
|
168
|
-
return this.makeRequest("set_getClaimsByAddress", {
|
|
169
|
-
address,
|
|
170
|
-
page
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
async getNextNonce(address) {
|
|
174
|
-
if (typeof address === "string") {
|
|
175
|
-
const addressBytes = this.addressToBytes(address);
|
|
176
|
-
const accountInfo2 = await this.getAccountInfo(addressBytes);
|
|
177
|
-
return accountInfo2.next_nonce;
|
|
178
|
-
}
|
|
179
|
-
const accountInfo = await this.getAccountInfo(address);
|
|
180
|
-
return accountInfo.next_nonce;
|
|
181
|
-
}
|
|
182
|
-
async submitTransaction(transaction, signature) {
|
|
183
|
-
const signatureArray = Array.isArray(signature) ? signature : Array.from(signature);
|
|
184
|
-
return this.makeRequest("set_submitTransaction", {
|
|
185
|
-
transaction,
|
|
186
|
-
signature: signatureArray
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
addressToBytes(address) {
|
|
190
|
-
try {
|
|
191
|
-
const decoded = bech32.bech32m.decode(address);
|
|
192
|
-
return Array.from(bech32.bech32m.fromWords(decoded.words));
|
|
193
|
-
} catch {
|
|
194
|
-
try {
|
|
195
|
-
const decoded = bech32.bech32.decode(address);
|
|
196
|
-
return Array.from(bech32.bech32.fromWords(decoded.words));
|
|
197
|
-
} catch {
|
|
198
|
-
throw new Error(`Invalid FastSet address: ${address}`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
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 });
|
|
202
220
|
};
|
|
203
221
|
|
|
204
222
|
// src/WarpFastsetDataLoader.ts
|
|
@@ -206,36 +224,23 @@ var WarpFastsetDataLoader = class {
|
|
|
206
224
|
constructor(config, chain) {
|
|
207
225
|
this.config = config;
|
|
208
226
|
this.chain = chain;
|
|
209
|
-
this.client =
|
|
210
|
-
}
|
|
211
|
-
addressToBytes(address) {
|
|
212
|
-
try {
|
|
213
|
-
const decoded = bech323.bech32m.decode(address);
|
|
214
|
-
return Array.from(bech323.bech32m.fromWords(decoded.words));
|
|
215
|
-
} catch {
|
|
216
|
-
try {
|
|
217
|
-
const decoded = bech323.bech32.decode(address);
|
|
218
|
-
return Array.from(bech323.bech32.fromWords(decoded.words));
|
|
219
|
-
} catch {
|
|
220
|
-
throw new Error(`Invalid FastSet address: ${address}`);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
227
|
+
this.client = getConfiguredFastsetClient(config, chain);
|
|
223
228
|
}
|
|
224
229
|
async getAccount(address) {
|
|
225
230
|
const addressBytes = this.addressToBytes(address);
|
|
226
231
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
227
|
-
return { chain: this.chain.name, address, balance: BigInt(accountInfo.balance) };
|
|
232
|
+
return { chain: this.chain.name, address, balance: BigInt(parseInt(accountInfo.balance, 16)) };
|
|
228
233
|
}
|
|
229
234
|
async getAccountAssets(address) {
|
|
230
235
|
const addressBytes = this.addressToBytes(address);
|
|
231
236
|
const accountInfo = await this.client.getAccountInfo(addressBytes);
|
|
232
237
|
const assets = [];
|
|
233
|
-
const balance = BigInt(accountInfo.balance);
|
|
238
|
+
const balance = BigInt(parseInt(accountInfo.balance, 16));
|
|
234
239
|
if (balance > 0n) {
|
|
235
240
|
assets.push({ ...this.chain.nativeToken, amount: balance });
|
|
236
241
|
}
|
|
237
242
|
for (const [tokenId, tokenBalance] of accountInfo.token_balance) {
|
|
238
|
-
const amount = BigInt(tokenBalance);
|
|
243
|
+
const amount = BigInt(parseInt(tokenBalance, 16));
|
|
239
244
|
if (amount > 0n) {
|
|
240
245
|
const tokenInfo = await this.client.getTokenInfo([tokenId]);
|
|
241
246
|
const metadata = tokenInfo.requested_token_metadata[0]?.[1];
|
|
@@ -253,12 +258,13 @@ var WarpFastsetDataLoader = class {
|
|
|
253
258
|
return assets;
|
|
254
259
|
}
|
|
255
260
|
async getAsset(identifier) {
|
|
261
|
+
if (identifier === this.chain.nativeToken.identifier) {
|
|
262
|
+
return this.chain.nativeToken;
|
|
263
|
+
}
|
|
256
264
|
const tokenId = Buffer.from(identifier, "hex");
|
|
257
265
|
const tokenInfo = await this.client.getTokenInfo([Array.from(tokenId)]);
|
|
258
266
|
const metadata = tokenInfo.requested_token_metadata[0]?.[1];
|
|
259
|
-
if (!metadata)
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
267
|
+
if (!metadata) return null;
|
|
262
268
|
return {
|
|
263
269
|
chain: this.chain.name,
|
|
264
270
|
identifier,
|
|
@@ -275,129 +281,147 @@ var WarpFastsetDataLoader = class {
|
|
|
275
281
|
async getAccountActions(address, options) {
|
|
276
282
|
return [];
|
|
277
283
|
}
|
|
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
|
+
}
|
|
296
|
+
}
|
|
278
297
|
};
|
|
279
298
|
|
|
280
299
|
// src/WarpFastsetExecutor.ts
|
|
281
|
-
var ed25519 = __toESM(require("@noble/ed25519"), 1);
|
|
282
300
|
var import_warps2 = require("@vleap/warps");
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
this.
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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" });
|
|
307
|
+
}
|
|
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})`);
|
|
315
|
+
}
|
|
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);
|
|
326
|
+
}
|
|
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");
|
|
304
332
|
return {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
|
310
339
|
};
|
|
311
340
|
}
|
|
312
|
-
|
|
313
|
-
|
|
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}`);
|
|
344
|
+
try {
|
|
345
|
+
const result = await this.executeFastsetQuery(this.fromBase64(executable.destination), action.func, executable.args);
|
|
346
|
+
return { success: true, result, chain: executable.chain };
|
|
347
|
+
} catch (error) {
|
|
348
|
+
return { success: false, error: error instanceof Error ? error.message : String(error), chain: executable.chain };
|
|
349
|
+
}
|
|
314
350
|
}
|
|
315
|
-
|
|
316
|
-
|
|
351
|
+
async executeTransfer(executable) {
|
|
352
|
+
const transaction = await this.createTransferTransaction(executable);
|
|
353
|
+
return { success: true, transaction, chain: executable.chain.name };
|
|
317
354
|
}
|
|
318
|
-
|
|
319
|
-
|
|
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 };
|
|
320
368
|
}
|
|
321
|
-
|
|
322
|
-
|
|
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));
|
|
323
372
|
}
|
|
324
|
-
|
|
325
|
-
|
|
373
|
+
serializeTransaction(tx) {
|
|
374
|
+
const serialized = JSON.stringify(tx, (k, v) => v instanceof Uint8Array ? Array.from(v) : v);
|
|
375
|
+
return new TextEncoder().encode(serialized);
|
|
326
376
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
+
})
|
|
330
387
|
});
|
|
388
|
+
if (!response.ok) throw new Error(`Query failed: ${response.statusText}`);
|
|
389
|
+
return response.json();
|
|
390
|
+
}
|
|
391
|
+
fromBase64(base64) {
|
|
392
|
+
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
331
393
|
}
|
|
332
394
|
};
|
|
333
395
|
|
|
334
|
-
// src/
|
|
335
|
-
var
|
|
336
|
-
constructor(
|
|
337
|
-
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
340
|
-
this.publicKeyHex = Buffer.from(this.publicKey).toString("hex");
|
|
341
|
-
}
|
|
342
|
-
toBech32() {
|
|
343
|
-
const words = bech325.bech32m.toWords(this.publicKey);
|
|
344
|
-
return bech325.bech32m.encode("set", words);
|
|
345
|
-
}
|
|
346
|
-
getWalletInfo() {
|
|
347
|
-
return {
|
|
348
|
-
publicKeyHex: this.publicKeyHex,
|
|
349
|
-
address: this.toBech32()
|
|
350
|
-
};
|
|
351
|
-
}
|
|
352
|
-
createTransferClaim(recipientAddress, amount, assetType) {
|
|
353
|
-
const recipientBytes = _Wallet.decodeBech32Address(recipientAddress);
|
|
354
|
-
const assetTypeBytes = new TextEncoder().encode(assetType);
|
|
355
|
-
const userData = new Uint8Array(32);
|
|
356
|
-
userData.set(assetTypeBytes.slice(0, 32));
|
|
357
|
-
return {
|
|
358
|
-
Transfer: {
|
|
359
|
-
recipient: { FastSet: recipientBytes },
|
|
360
|
-
amount: amount.toString(),
|
|
361
|
-
user_data: userData
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
createTransaction(nonce, recipient, claim) {
|
|
366
|
-
return new Transaction(this.publicKey, recipient, nonce, claim);
|
|
367
|
-
}
|
|
368
|
-
static decodeBech32Address(address) {
|
|
369
|
-
try {
|
|
370
|
-
const decoded = bech325.bech32m.decode(address);
|
|
371
|
-
return new Uint8Array(bech325.bech32m.fromWords(decoded.words));
|
|
372
|
-
} catch (error) {
|
|
373
|
-
const decoded = bech325.bech32.decode(address);
|
|
374
|
-
return new Uint8Array(bech325.bech32.fromWords(decoded.words));
|
|
375
|
-
}
|
|
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";
|
|
376
402
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
return bech325.bech32m.encode("set", words);
|
|
403
|
+
getAccountUrl(address) {
|
|
404
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
380
405
|
}
|
|
381
|
-
|
|
382
|
-
return
|
|
406
|
+
getTransactionUrl(hash) {
|
|
407
|
+
return `${this.explorerUrl}/transaction/${hash}`;
|
|
383
408
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const privateKeyHex = Buffer.from(privateKey).toString("hex");
|
|
387
|
-
return new _Wallet(privateKeyHex);
|
|
409
|
+
getAssetUrl(identifier) {
|
|
410
|
+
return `${this.explorerUrl}/asset/${identifier}`;
|
|
388
411
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const privateKeyHex = (await fs.readFile(filePath, "utf8")).trim();
|
|
392
|
-
return new _Wallet(privateKeyHex);
|
|
412
|
+
getContractUrl(address) {
|
|
413
|
+
return `${this.explorerUrl}/account/${address}`;
|
|
393
414
|
}
|
|
394
415
|
};
|
|
395
416
|
|
|
417
|
+
// src/WarpFastsetResults.ts
|
|
418
|
+
var import_warps4 = require("@vleap/warps");
|
|
419
|
+
|
|
396
420
|
// src/WarpFastsetSerializer.ts
|
|
397
|
-
var
|
|
421
|
+
var import_warps3 = require("@vleap/warps");
|
|
398
422
|
var WarpFastsetSerializer = class {
|
|
399
423
|
constructor() {
|
|
400
|
-
this.coreSerializer = new
|
|
424
|
+
this.coreSerializer = new import_warps3.WarpSerializer();
|
|
401
425
|
}
|
|
402
426
|
typedToString(value) {
|
|
403
427
|
if (typeof value === "string") {
|
|
@@ -503,228 +527,7 @@ var WarpFastsetSerializer = class {
|
|
|
503
527
|
}
|
|
504
528
|
};
|
|
505
529
|
|
|
506
|
-
// src/WarpFastsetExecutor.ts
|
|
507
|
-
var WarpFastsetExecutor = class {
|
|
508
|
-
constructor(config, chain) {
|
|
509
|
-
this.config = config;
|
|
510
|
-
this.chain = chain;
|
|
511
|
-
this.serializer = new WarpFastsetSerializer();
|
|
512
|
-
const proxyUrl = (0, import_warps2.getProviderUrl)(this.config, chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
513
|
-
this.fastsetClient = new FastsetClient({
|
|
514
|
-
proxyUrl
|
|
515
|
-
});
|
|
516
|
-
}
|
|
517
|
-
async createTransaction(executable) {
|
|
518
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
519
|
-
switch (action.type) {
|
|
520
|
-
case "transfer":
|
|
521
|
-
return this.createTransferTransaction(executable);
|
|
522
|
-
case "contract":
|
|
523
|
-
return this.createContractCallTransaction(executable);
|
|
524
|
-
case "query":
|
|
525
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeQuery instead");
|
|
526
|
-
case "collect":
|
|
527
|
-
throw new Error("WarpFastsetExecutor: Invalid action type for createTransaction; Use executeCollect instead");
|
|
528
|
-
default:
|
|
529
|
-
throw new Error(`WarpFastsetExecutor: Invalid action type (${action.type})`);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
async createTransferTransaction(executable) {
|
|
533
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
534
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createTransfer - user address not set");
|
|
535
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
536
|
-
throw new Error(`WarpFastsetExecutor: Invalid destination address: ${executable.destination}`);
|
|
537
|
-
}
|
|
538
|
-
if (executable.value < 0) {
|
|
539
|
-
throw new Error(`WarpFastsetExecutor: Transfer value cannot be negative: ${executable.value}`);
|
|
540
|
-
}
|
|
541
|
-
const recipientAddress = this.fromBase64(executable.destination);
|
|
542
|
-
const amount = this.normalizeAmount(executable.value.toString());
|
|
543
|
-
const userData = executable.data ? this.fromBase64(this.serializer.stringToTyped(executable.data)) : void 0;
|
|
544
|
-
return {
|
|
545
|
-
type: "fastset-transfer",
|
|
546
|
-
recipient: recipientAddress,
|
|
547
|
-
amount,
|
|
548
|
-
userData,
|
|
549
|
-
chain: executable.chain
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
async createContractCallTransaction(executable) {
|
|
553
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
554
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: createContractCall - user address not set");
|
|
555
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
556
|
-
if (!action || !("func" in action) || !action.func) {
|
|
557
|
-
throw new Error("WarpFastsetExecutor: Contract action must have a function name");
|
|
558
|
-
}
|
|
559
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
560
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address: ${executable.destination}`);
|
|
561
|
-
}
|
|
562
|
-
if (executable.value < 0) {
|
|
563
|
-
throw new Error(`WarpFastsetExecutor: Contract call value cannot be negative: ${executable.value}`);
|
|
564
|
-
}
|
|
565
|
-
try {
|
|
566
|
-
const contractAddress = this.fromBase64(executable.destination);
|
|
567
|
-
const encodedData = this.encodeFunctionData(action.func, executable.args);
|
|
568
|
-
return {
|
|
569
|
-
type: "fastset-contract-call",
|
|
570
|
-
contract: contractAddress,
|
|
571
|
-
function: action.func,
|
|
572
|
-
data: encodedData,
|
|
573
|
-
value: executable.value,
|
|
574
|
-
chain: executable.chain
|
|
575
|
-
};
|
|
576
|
-
} catch (error) {
|
|
577
|
-
throw new Error(`WarpFastsetExecutor: Failed to encode function data for ${action.func}: ${error}`);
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
async executeQuery(executable) {
|
|
581
|
-
const action = (0, import_warps2.getWarpActionByIndex)(executable.warp, executable.action);
|
|
582
|
-
if (action.type !== "query") {
|
|
583
|
-
throw new Error(`WarpFastsetExecutor: Invalid action type for executeQuery: ${action.type}`);
|
|
584
|
-
}
|
|
585
|
-
if (!action.func) {
|
|
586
|
-
throw new Error("WarpFastsetExecutor: Query action must have a function name");
|
|
587
|
-
}
|
|
588
|
-
if (!this.isValidFastsetAddress(executable.destination)) {
|
|
589
|
-
throw new Error(`WarpFastsetExecutor: Invalid contract address for query: ${executable.destination}`);
|
|
590
|
-
}
|
|
591
|
-
try {
|
|
592
|
-
const contractAddress = this.fromBase64(executable.destination);
|
|
593
|
-
const result = await this.executeFastsetQuery(contractAddress, action.func, executable.args);
|
|
594
|
-
return {
|
|
595
|
-
success: true,
|
|
596
|
-
result,
|
|
597
|
-
chain: executable.chain
|
|
598
|
-
};
|
|
599
|
-
} catch (error) {
|
|
600
|
-
return {
|
|
601
|
-
success: false,
|
|
602
|
-
error: error instanceof Error ? error.message : String(error),
|
|
603
|
-
chain: executable.chain
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
async signMessage(message, privateKey) {
|
|
608
|
-
throw new Error("Not implemented");
|
|
609
|
-
}
|
|
610
|
-
async signTransaction(transaction, privateKey) {
|
|
611
|
-
const transactionJson = JSON.stringify(transaction, (key, value) => {
|
|
612
|
-
if (value instanceof Uint8Array) {
|
|
613
|
-
return Array.from(value);
|
|
614
|
-
}
|
|
615
|
-
return value;
|
|
616
|
-
});
|
|
617
|
-
const prefix = "Transaction::";
|
|
618
|
-
const dataToSign = new TextEncoder().encode(prefix + transactionJson);
|
|
619
|
-
return await ed25519.sign(dataToSign, privateKey);
|
|
620
|
-
}
|
|
621
|
-
async executeTransfer(executable) {
|
|
622
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
623
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
624
|
-
const transaction = await this.createTransferTransaction(executable);
|
|
625
|
-
return {
|
|
626
|
-
success: true,
|
|
627
|
-
transaction,
|
|
628
|
-
chain: executable.chain.name,
|
|
629
|
-
message: "Transaction created successfully. Use executeTransferWithKey to execute with private key."
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
async executeTransferWithKey(executable, privateKey) {
|
|
633
|
-
const userWallet = this.config.user?.wallets?.[executable.chain.name];
|
|
634
|
-
if (!userWallet) throw new Error("WarpFastsetExecutor: executeTransfer - user wallet not set");
|
|
635
|
-
const transaction = await this.createTransferTransaction(executable);
|
|
636
|
-
const privateKeyBytes = this.fromBase64(privateKey);
|
|
637
|
-
const transactionData = {
|
|
638
|
-
sender: Array.from(privateKeyBytes.slice(0, 32)),
|
|
639
|
-
// First 32 bytes as public key
|
|
640
|
-
recipient: { FastSet: transaction.recipient },
|
|
641
|
-
nonce: await this.fastsetClient.getNextNonce(Wallet.encodeBech32Address(privateKeyBytes.slice(0, 32))),
|
|
642
|
-
timestamp_nanos: (BigInt(Date.now()) * 1000000n).toString(),
|
|
643
|
-
claim: {
|
|
644
|
-
Transfer: {
|
|
645
|
-
recipient: { FastSet: transaction.recipient },
|
|
646
|
-
amount: transaction.amount,
|
|
647
|
-
user_data: transaction.userData ? Array.from(transaction.userData) : null
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
const signature = await this.signTransaction(transactionData, privateKeyBytes);
|
|
652
|
-
const transactionHash = await this.fastsetClient.submitTransaction(transactionData, signature);
|
|
653
|
-
return {
|
|
654
|
-
success: true,
|
|
655
|
-
transactionHash: Array.from(transactionHash),
|
|
656
|
-
chain: executable.chain.name
|
|
657
|
-
};
|
|
658
|
-
}
|
|
659
|
-
encodeFunctionData(functionName, args) {
|
|
660
|
-
return JSON.stringify({
|
|
661
|
-
function: functionName,
|
|
662
|
-
arguments: args
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
async executeFastsetQuery(contractAddress, functionName, args) {
|
|
666
|
-
const validatorUrl = (0, import_warps2.getProviderUrl)(this.config, this.chain.name, this.config.env, this.chain.defaultApiUrl);
|
|
667
|
-
const response = await fetch(`${validatorUrl}/query`, {
|
|
668
|
-
method: "POST",
|
|
669
|
-
headers: {
|
|
670
|
-
"Content-Type": "application/json"
|
|
671
|
-
},
|
|
672
|
-
body: JSON.stringify({
|
|
673
|
-
contract: Array.from(contractAddress),
|
|
674
|
-
function: functionName,
|
|
675
|
-
arguments: args
|
|
676
|
-
})
|
|
677
|
-
});
|
|
678
|
-
if (!response.ok) {
|
|
679
|
-
throw new Error(`Fastset query failed: ${response.statusText}`);
|
|
680
|
-
}
|
|
681
|
-
return response.json();
|
|
682
|
-
}
|
|
683
|
-
isValidFastsetAddress(address) {
|
|
684
|
-
if (typeof address !== "string" || address.length === 0) {
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
if (address.startsWith("fs") || address.startsWith("pi")) {
|
|
688
|
-
return true;
|
|
689
|
-
}
|
|
690
|
-
try {
|
|
691
|
-
const decoded = this.fromBase64(address);
|
|
692
|
-
return decoded.length === 32;
|
|
693
|
-
} catch {
|
|
694
|
-
return false;
|
|
695
|
-
}
|
|
696
|
-
}
|
|
697
|
-
fromBase64(base64) {
|
|
698
|
-
return Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
|
|
699
|
-
}
|
|
700
|
-
normalizeAmount(amount) {
|
|
701
|
-
return amount.startsWith("0x") ? amount.slice(2) : amount;
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
|
|
705
|
-
// src/WarpFastsetExplorer.ts
|
|
706
|
-
var WarpFastsetExplorer = class {
|
|
707
|
-
constructor(_chainInfo, _config) {
|
|
708
|
-
this._chainInfo = _chainInfo;
|
|
709
|
-
this._config = _config;
|
|
710
|
-
this.explorerUrl = "https://explorer.fastset.xyz";
|
|
711
|
-
}
|
|
712
|
-
getAccountUrl(address) {
|
|
713
|
-
return `${this.explorerUrl}/account/${address}`;
|
|
714
|
-
}
|
|
715
|
-
getTransactionUrl(hash) {
|
|
716
|
-
return `${this.explorerUrl}/transaction/${hash}`;
|
|
717
|
-
}
|
|
718
|
-
getAssetUrl(identifier) {
|
|
719
|
-
return `${this.explorerUrl}/asset/${identifier}`;
|
|
720
|
-
}
|
|
721
|
-
getContractUrl(address) {
|
|
722
|
-
return `${this.explorerUrl}/account/${address}`;
|
|
723
|
-
}
|
|
724
|
-
};
|
|
725
|
-
|
|
726
530
|
// src/WarpFastsetResults.ts
|
|
727
|
-
var import_warps3 = require("@vleap/warps");
|
|
728
531
|
var WarpFastsetResults = class {
|
|
729
532
|
constructor(config, chain) {
|
|
730
533
|
this.config = config;
|
|
@@ -740,7 +543,7 @@ var WarpFastsetResults = class {
|
|
|
740
543
|
success,
|
|
741
544
|
warp,
|
|
742
545
|
action: 0,
|
|
743
|
-
user: this.config
|
|
546
|
+
user: (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name),
|
|
744
547
|
txHash: transactionHash,
|
|
745
548
|
tx,
|
|
746
549
|
next: null,
|
|
@@ -771,8 +574,8 @@ var WarpFastsetResults = class {
|
|
|
771
574
|
return value;
|
|
772
575
|
};
|
|
773
576
|
for (const [key, path] of Object.entries(warp.results)) {
|
|
774
|
-
if (path.startsWith(
|
|
775
|
-
const currentActionIndex = (0,
|
|
577
|
+
if (path.startsWith(import_warps4.WarpConstants.Transform.Prefix)) continue;
|
|
578
|
+
const currentActionIndex = (0, import_warps4.parseResultsOutIndex)(path);
|
|
776
579
|
if (currentActionIndex !== null && currentActionIndex !== actionIndex) {
|
|
777
580
|
results[key] = null;
|
|
778
581
|
continue;
|
|
@@ -784,7 +587,7 @@ var WarpFastsetResults = class {
|
|
|
784
587
|
results[key] = path;
|
|
785
588
|
}
|
|
786
589
|
}
|
|
787
|
-
return { values, results: await (0,
|
|
590
|
+
return { values, results: await (0, import_warps4.evaluateResultsCommon)(warp, results, actionIndex, inputs, this.config.transform?.runner) };
|
|
788
591
|
}
|
|
789
592
|
isTransactionSuccessful(tx) {
|
|
790
593
|
if (!tx) return false;
|
|
@@ -809,9 +612,71 @@ var WarpFastsetResults = class {
|
|
|
809
612
|
}
|
|
810
613
|
};
|
|
811
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);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
|
|
812
677
|
// src/main.ts
|
|
813
678
|
var NativeTokenSet = {
|
|
814
|
-
chain:
|
|
679
|
+
chain: import_warps6.WarpChainName.Fastset,
|
|
815
680
|
identifier: "SET",
|
|
816
681
|
name: "SET",
|
|
817
682
|
symbol: "SET",
|
|
@@ -835,49 +700,51 @@ function createFastsetAdapter(chainName, chainPrefix, chainInfos) {
|
|
|
835
700
|
explorer: new WarpFastsetExplorer(chainInfo, config),
|
|
836
701
|
abiBuilder: () => fallback.abiBuilder(),
|
|
837
702
|
brandBuilder: () => fallback.brandBuilder(),
|
|
838
|
-
dataLoader: new WarpFastsetDataLoader(config, chainInfo)
|
|
703
|
+
dataLoader: new WarpFastsetDataLoader(config, chainInfo),
|
|
704
|
+
wallet: new WarpFastsetWallet(config, chainInfo)
|
|
839
705
|
};
|
|
840
706
|
};
|
|
841
707
|
}
|
|
842
|
-
var getFastsetAdapter = createFastsetAdapter(
|
|
708
|
+
var getFastsetAdapter = createFastsetAdapter(import_warps6.WarpChainName.Fastset, "fastset", {
|
|
843
709
|
mainnet: {
|
|
844
|
-
name:
|
|
710
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
845
711
|
displayName: "FastSet",
|
|
846
712
|
chainId: "1",
|
|
847
713
|
blockTime: 1e3,
|
|
848
714
|
addressHrp: "set",
|
|
849
|
-
defaultApiUrl: "https://
|
|
715
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
850
716
|
nativeToken: NativeTokenSet
|
|
851
717
|
},
|
|
852
718
|
testnet: {
|
|
853
|
-
name:
|
|
719
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
854
720
|
displayName: "FastSet Testnet",
|
|
855
721
|
chainId: "testnet",
|
|
856
722
|
blockTime: 1e3,
|
|
857
723
|
addressHrp: "set",
|
|
858
|
-
defaultApiUrl: "https://
|
|
724
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
859
725
|
nativeToken: NativeTokenSet
|
|
860
726
|
},
|
|
861
727
|
devnet: {
|
|
862
|
-
name:
|
|
728
|
+
name: import_warps6.WarpChainName.Fastset,
|
|
863
729
|
displayName: "FastSet Devnet",
|
|
864
730
|
chainId: "devnet",
|
|
865
731
|
blockTime: 1e3,
|
|
866
732
|
addressHrp: "set",
|
|
867
|
-
defaultApiUrl: "https://
|
|
733
|
+
defaultApiUrl: "https://proxy.fastset.xyz",
|
|
868
734
|
nativeToken: NativeTokenSet
|
|
869
735
|
}
|
|
870
736
|
});
|
|
737
|
+
|
|
738
|
+
// src/index.ts
|
|
739
|
+
init_sdk();
|
|
871
740
|
// Annotate the CommonJS export names for ESM import in node:
|
|
872
741
|
0 && (module.exports = {
|
|
873
742
|
FastsetClient,
|
|
874
743
|
NativeTokenSet,
|
|
875
|
-
|
|
876
|
-
|
|
744
|
+
Transaction,
|
|
745
|
+
Wallet,
|
|
877
746
|
WarpFastsetExecutor,
|
|
878
|
-
|
|
879
|
-
WarpFastsetResults,
|
|
880
|
-
WarpFastsetSerializer,
|
|
747
|
+
WarpFastsetWallet,
|
|
881
748
|
getFastsetAdapter
|
|
882
749
|
});
|
|
883
750
|
//# sourceMappingURL=index.js.map
|