@silvana-one/abi 1.1.2 → 1.1.4
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/node/index.cjs +1 -1
- package/dist/node/token/info.d.ts +2 -2
- package/dist/node/token/info.js +2 -348
- package/dist/node/token/info.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tsconfig.web.tsbuildinfo +1 -1
- package/dist/web/token/info.d.ts +2 -2
- package/dist/web/token/info.js +2 -348
- package/dist/web/token/info.js.map +1 -1
- package/package.json +10 -10
- package/src/token/info.ts +6 -386
package/src/token/info.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import { Mina, PublicKey,
|
|
1
|
+
import { Mina, PublicKey, TokenId, Field } from "o1js";
|
|
2
2
|
import { fetchMinaAccount } from "../fetch.js";
|
|
3
3
|
import {
|
|
4
|
-
TokenState,
|
|
5
|
-
TokenInfoRequestParams,
|
|
6
4
|
BalanceRequestParams,
|
|
7
5
|
BalanceResponse,
|
|
6
|
+
CanonicalBlockchain,
|
|
8
7
|
} from "@silvana-one/api";
|
|
9
8
|
import { checkAddress } from "../info/address.js";
|
|
10
|
-
import {
|
|
11
|
-
FungibleToken,
|
|
12
|
-
AdvancedFungibleToken,
|
|
13
|
-
FungibleTokenAdmin,
|
|
14
|
-
FungibleTokenAdvancedAdmin,
|
|
15
|
-
FungibleTokenBidContract,
|
|
16
|
-
FungibleTokenOfferContract,
|
|
17
|
-
FungibleTokenClaimContract,
|
|
18
|
-
} from "@silvana-one/token";
|
|
9
|
+
import { FungibleToken } from "@silvana-one/token";
|
|
19
10
|
import { ContractInfo } from "@silvana-one/api";
|
|
20
11
|
import { tokenVerificationKeys } from "../vk/vk.js";
|
|
21
12
|
|
|
@@ -24,10 +15,11 @@ export async function getContractInfo(params: {
|
|
|
24
15
|
tokenId?: string | Field;
|
|
25
16
|
parentTokenId?: Field;
|
|
26
17
|
decimals?: number;
|
|
27
|
-
chain:
|
|
18
|
+
chain: CanonicalBlockchain;
|
|
28
19
|
}): Promise<ContractInfo[]> {
|
|
29
20
|
const { address, chain, parentTokenId, decimals } = params;
|
|
30
|
-
const vk =
|
|
21
|
+
const vk =
|
|
22
|
+
tokenVerificationKeys[chain === "mina:mainnet" ? "mainnet" : "devnet"].vk;
|
|
31
23
|
const info: ContractInfo[] = [];
|
|
32
24
|
if (typeof address === "string" && !checkAddress(address)) {
|
|
33
25
|
throw new Error("Invalid address");
|
|
@@ -229,375 +221,3 @@ export async function tokenBalance(
|
|
|
229
221
|
};
|
|
230
222
|
}
|
|
231
223
|
}
|
|
232
|
-
|
|
233
|
-
// export async function offerInfo(
|
|
234
|
-
// params: OfferInfoRequest,
|
|
235
|
-
// apiKeyAddress: string
|
|
236
|
-
// ): Promise<ApiResponse<OfferInfo>> {
|
|
237
|
-
// const { tokenAddress, offerAddress } = params;
|
|
238
|
-
|
|
239
|
-
// try {
|
|
240
|
-
// await initBlockchain();
|
|
241
|
-
|
|
242
|
-
// if (!offerAddress || !checkAddress(offerAddress)) {
|
|
243
|
-
// return {
|
|
244
|
-
// status: 400,
|
|
245
|
-
// json: { error: "Invalid offer address" },
|
|
246
|
-
// };
|
|
247
|
-
// }
|
|
248
|
-
|
|
249
|
-
// if (!tokenAddress || !checkAddress(tokenAddress)) {
|
|
250
|
-
// return {
|
|
251
|
-
// status: 400,
|
|
252
|
-
// json: { error: "Invalid token address" },
|
|
253
|
-
// };
|
|
254
|
-
// }
|
|
255
|
-
|
|
256
|
-
// const tokenContractPublicKey = PublicKey.fromBase58(tokenAddress);
|
|
257
|
-
// const offerPublicKey = PublicKey.fromBase58(offerAddress);
|
|
258
|
-
// const tokenId = TokenId.derive(tokenContractPublicKey);
|
|
259
|
-
|
|
260
|
-
// await fetchMinaAccount({
|
|
261
|
-
// publicKey: offerPublicKey,
|
|
262
|
-
// tokenId,
|
|
263
|
-
// force: false,
|
|
264
|
-
// });
|
|
265
|
-
// if (!Mina.hasAccount(offerPublicKey, tokenId)) {
|
|
266
|
-
// return {
|
|
267
|
-
// status: 400,
|
|
268
|
-
// json: { error: "Offer account not found" },
|
|
269
|
-
// };
|
|
270
|
-
// }
|
|
271
|
-
// const offer = new FungibleTokenOfferContract(offerPublicKey, tokenId);
|
|
272
|
-
// const price = Number(offer.price.get().toBigInt());
|
|
273
|
-
// const amount = Number(
|
|
274
|
-
// Mina.getAccount(offerPublicKey, tokenId).balance.toBigInt()
|
|
275
|
-
// );
|
|
276
|
-
// const ownerAddress = offer.seller.get().toBase58();
|
|
277
|
-
// const offerInfo = await getOffer({ tokenAddress, offerAddress });
|
|
278
|
-
// if (
|
|
279
|
-
// offerInfo === null ||
|
|
280
|
-
// amount !== Number(offerInfo?.amount) ||
|
|
281
|
-
// price !== Number(offerInfo?.price) ||
|
|
282
|
-
// ownerAddress !== offerInfo?.ownerAddress
|
|
283
|
-
// ) {
|
|
284
|
-
// writeOffer({
|
|
285
|
-
// tokenAddress,
|
|
286
|
-
// offerAddress,
|
|
287
|
-
// amount,
|
|
288
|
-
// price,
|
|
289
|
-
// ownerAddress,
|
|
290
|
-
// });
|
|
291
|
-
// }
|
|
292
|
-
|
|
293
|
-
// return {
|
|
294
|
-
// status: 200,
|
|
295
|
-
// json: {
|
|
296
|
-
// tokenAddress,
|
|
297
|
-
// offerAddress,
|
|
298
|
-
// ownerAddress,
|
|
299
|
-
// amount,
|
|
300
|
-
// price,
|
|
301
|
-
// },
|
|
302
|
-
// };
|
|
303
|
-
// } catch (error) {
|
|
304
|
-
// console.error("Cannot fetch offer info", params, error);
|
|
305
|
-
// return {
|
|
306
|
-
// status: 500,
|
|
307
|
-
// json: { error: "Failed to get offer info" },
|
|
308
|
-
// };
|
|
309
|
-
// }
|
|
310
|
-
// }
|
|
311
|
-
|
|
312
|
-
// export async function bidInfo(
|
|
313
|
-
// params: BidInfoRequest,
|
|
314
|
-
// apiKeyAddress: string
|
|
315
|
-
// ): Promise<ApiResponse<BidInfo>> {
|
|
316
|
-
// const { tokenAddress, bidAddress } = params;
|
|
317
|
-
|
|
318
|
-
// try {
|
|
319
|
-
// await initBlockchain();
|
|
320
|
-
|
|
321
|
-
// if (!bidAddress || !checkAddress(bidAddress)) {
|
|
322
|
-
// return {
|
|
323
|
-
// status: 400,
|
|
324
|
-
// json: { error: "Invalid bid address" },
|
|
325
|
-
// };
|
|
326
|
-
// }
|
|
327
|
-
|
|
328
|
-
// if (!tokenAddress || !checkAddress(tokenAddress)) {
|
|
329
|
-
// return {
|
|
330
|
-
// status: 400,
|
|
331
|
-
// json: { error: "Invalid token address" },
|
|
332
|
-
// };
|
|
333
|
-
// }
|
|
334
|
-
|
|
335
|
-
// const tokenContractPublicKey = PublicKey.fromBase58(tokenAddress);
|
|
336
|
-
// const bidPublicKey = PublicKey.fromBase58(bidAddress);
|
|
337
|
-
// const tokenId = TokenId.derive(tokenContractPublicKey);
|
|
338
|
-
|
|
339
|
-
// await fetchMinaAccount({
|
|
340
|
-
// publicKey: bidPublicKey,
|
|
341
|
-
// force: false,
|
|
342
|
-
// });
|
|
343
|
-
// if (!Mina.hasAccount(bidPublicKey)) {
|
|
344
|
-
// return {
|
|
345
|
-
// status: 400,
|
|
346
|
-
// json: { error: "Bid account not found" },
|
|
347
|
-
// };
|
|
348
|
-
// }
|
|
349
|
-
// const bid = new FungibleTokenBidContract(bidPublicKey);
|
|
350
|
-
// const price = Number(bid.price.get().toBigInt());
|
|
351
|
-
// const amount = Number(Mina.getAccount(bidPublicKey).balance.toBigInt());
|
|
352
|
-
// const ownerAddress = bid.buyer.get().toBase58();
|
|
353
|
-
// const bidInfo = await getBid({ tokenAddress, bidAddress });
|
|
354
|
-
// if (
|
|
355
|
-
// bidInfo === null ||
|
|
356
|
-
// amount !== Number(bidInfo?.amount) ||
|
|
357
|
-
// price !== Number(bidInfo?.price) ||
|
|
358
|
-
// ownerAddress !== bidInfo?.ownerAddress
|
|
359
|
-
// ) {
|
|
360
|
-
// writeBid({
|
|
361
|
-
// tokenAddress,
|
|
362
|
-
// bidAddress,
|
|
363
|
-
// amount,
|
|
364
|
-
// price,
|
|
365
|
-
// ownerAddress,
|
|
366
|
-
// });
|
|
367
|
-
// }
|
|
368
|
-
|
|
369
|
-
// return {
|
|
370
|
-
// status: 200,
|
|
371
|
-
// json: {
|
|
372
|
-
// tokenAddress,
|
|
373
|
-
// bidAddress,
|
|
374
|
-
// ownerAddress,
|
|
375
|
-
// amount,
|
|
376
|
-
// price,
|
|
377
|
-
// },
|
|
378
|
-
// };
|
|
379
|
-
// } catch (error) {
|
|
380
|
-
// console.error("Cannot fetch bid info", params, error);
|
|
381
|
-
// return {
|
|
382
|
-
// status: 500,
|
|
383
|
-
// json: { error: "Failed to get bid info" },
|
|
384
|
-
// };
|
|
385
|
-
// }
|
|
386
|
-
// }
|
|
387
|
-
|
|
388
|
-
// class FungibleTokenState extends Struct({
|
|
389
|
-
// decimals: UInt8,
|
|
390
|
-
// admin: PublicKey,
|
|
391
|
-
// paused: Bool,
|
|
392
|
-
// }) {}
|
|
393
|
-
|
|
394
|
-
// const FungibleTokenStateSize = FungibleTokenState.sizeInFields();
|
|
395
|
-
|
|
396
|
-
// class FungibleTokenAdminState extends Struct({
|
|
397
|
-
// adminPublicKey: PublicKey,
|
|
398
|
-
// }) {}
|
|
399
|
-
|
|
400
|
-
// const FungibleTokenAdminStateSize = FungibleTokenAdminState.sizeInFields();
|
|
401
|
-
|
|
402
|
-
// export async function getTokenState(props: {
|
|
403
|
-
// params: TokenInfoRequestParams;
|
|
404
|
-
// name: ApiName;
|
|
405
|
-
// apiKeyAddress: string;
|
|
406
|
-
// }): Promise<ApiResponse<TokenState>> {
|
|
407
|
-
// const { params, name, apiKeyAddress } = props;
|
|
408
|
-
// const { tokenAddress } = params;
|
|
409
|
-
// try {
|
|
410
|
-
// await initBlockchain();
|
|
411
|
-
// if (!checkAddress(tokenAddress)) {
|
|
412
|
-
// return {
|
|
413
|
-
// status: 400,
|
|
414
|
-
// json: { error: "Invalid token address" },
|
|
415
|
-
// };
|
|
416
|
-
// }
|
|
417
|
-
// const tokenContractPublicKey = PublicKey.fromBase58(tokenAddress);
|
|
418
|
-
|
|
419
|
-
// await fetchMinaAccount({ publicKey: tokenContractPublicKey, force: false });
|
|
420
|
-
// if (!Mina.hasAccount(tokenContractPublicKey)) {
|
|
421
|
-
// return {
|
|
422
|
-
// status: 400,
|
|
423
|
-
// json: { error: "Token contract account not found" },
|
|
424
|
-
// };
|
|
425
|
-
// }
|
|
426
|
-
// const tokenId = TokenId.derive(tokenContractPublicKey);
|
|
427
|
-
// await fetchMinaAccount({
|
|
428
|
-
// publicKey: tokenContractPublicKey,
|
|
429
|
-
// tokenId,
|
|
430
|
-
// force: false,
|
|
431
|
-
// });
|
|
432
|
-
// if (!Mina.hasAccount(tokenContractPublicKey, tokenId)) {
|
|
433
|
-
// console.error(
|
|
434
|
-
// "getTokenState: Token contract totalSupply account not found",
|
|
435
|
-
// {
|
|
436
|
-
// tokenAddress,
|
|
437
|
-
// }
|
|
438
|
-
// );
|
|
439
|
-
// return {
|
|
440
|
-
// status: 400,
|
|
441
|
-
// json: { error: "Token contract totalSupply account not found" },
|
|
442
|
-
// };
|
|
443
|
-
// }
|
|
444
|
-
// const account = Mina.getAccount(tokenContractPublicKey);
|
|
445
|
-
// if (account.zkapp?.appState === undefined) {
|
|
446
|
-
// console.error("getTokenState: Token contract state not found", {
|
|
447
|
-
// tokenAddress,
|
|
448
|
-
// });
|
|
449
|
-
// return {
|
|
450
|
-
// status: 400,
|
|
451
|
-
// json: { error: "Token contract state not found" },
|
|
452
|
-
// };
|
|
453
|
-
// }
|
|
454
|
-
// const state = FungibleTokenState.fromFields(
|
|
455
|
-
// account.zkapp?.appState.slice(0, FungibleTokenStateSize)
|
|
456
|
-
// );
|
|
457
|
-
// const adminContractPublicKey = state.admin;
|
|
458
|
-
// const decimals = state.decimals.toNumber();
|
|
459
|
-
// const isPaused = state.paused.toBoolean();
|
|
460
|
-
// const totalSupply =
|
|
461
|
-
// Number(Mina.getBalance(tokenContractPublicKey, tokenId).toBigInt()) /
|
|
462
|
-
// 1_000_000_000;
|
|
463
|
-
// const tokenSymbol = account.tokenSymbol;
|
|
464
|
-
// const uri = account.zkapp?.zkappUri;
|
|
465
|
-
|
|
466
|
-
// if (uri === undefined) {
|
|
467
|
-
// console.error("getTokenState: Token uri not found", {
|
|
468
|
-
// tokenAddress,
|
|
469
|
-
// });
|
|
470
|
-
// return {
|
|
471
|
-
// status: 400,
|
|
472
|
-
// json: { error: "Token uri not found" },
|
|
473
|
-
// };
|
|
474
|
-
// }
|
|
475
|
-
// const verificationKeyHash = account.zkapp?.verificationKey?.hash.toJSON();
|
|
476
|
-
// if (verificationKeyHash === undefined) {
|
|
477
|
-
// console.error("getTokenState: Token verification key hash not found", {
|
|
478
|
-
// tokenAddress,
|
|
479
|
-
// });
|
|
480
|
-
// return {
|
|
481
|
-
// status: 400,
|
|
482
|
-
// json: { error: "Token verification key hash not found" },
|
|
483
|
-
// };
|
|
484
|
-
// }
|
|
485
|
-
// const versionData = account.zkapp?.zkappVersion;
|
|
486
|
-
// if (versionData === undefined) {
|
|
487
|
-
// console.error("getTokenState: Token contract version not found", {
|
|
488
|
-
// tokenAddress,
|
|
489
|
-
// });
|
|
490
|
-
// return {
|
|
491
|
-
// status: 400,
|
|
492
|
-
// json: { error: "Token contract version not found" },
|
|
493
|
-
// };
|
|
494
|
-
// }
|
|
495
|
-
// const version = Number(versionData.toBigint());
|
|
496
|
-
|
|
497
|
-
// await fetchMinaAccount({ publicKey: adminContractPublicKey, force: false });
|
|
498
|
-
// if (!Mina.hasAccount(adminContractPublicKey)) {
|
|
499
|
-
// console.error("getTokenState: Admin contract account not found", {
|
|
500
|
-
// tokenAddress,
|
|
501
|
-
// });
|
|
502
|
-
// return {
|
|
503
|
-
// status: 400,
|
|
504
|
-
// json: { error: "Admin contract account not found" },
|
|
505
|
-
// };
|
|
506
|
-
// }
|
|
507
|
-
|
|
508
|
-
// const adminContract = Mina.getAccount(adminContractPublicKey);
|
|
509
|
-
// const adminTokenSymbol = adminContract.tokenSymbol;
|
|
510
|
-
// const adminUri = adminContract.zkapp?.zkappUri;
|
|
511
|
-
|
|
512
|
-
// const adminVerificationKeyHash =
|
|
513
|
-
// adminContract.zkapp?.verificationKey?.hash.toJSON();
|
|
514
|
-
// if (adminVerificationKeyHash === undefined) {
|
|
515
|
-
// console.error(
|
|
516
|
-
// "getTokenState: Admin contract verification key hash not found",
|
|
517
|
-
// {
|
|
518
|
-
// adminContractPublicKey: adminContractPublicKey.toBase58(),
|
|
519
|
-
// }
|
|
520
|
-
// );
|
|
521
|
-
// return {
|
|
522
|
-
// status: 400,
|
|
523
|
-
// json: { error: "Admin contract verification key hash not found" },
|
|
524
|
-
// };
|
|
525
|
-
// }
|
|
526
|
-
// const adminVersionData = adminContract.zkapp?.zkappVersion;
|
|
527
|
-
// if (adminVersionData === undefined) {
|
|
528
|
-
// console.error("getTokenState: Admin contract version not found", {
|
|
529
|
-
// adminContractPublicKey: adminContractPublicKey.toBase58(),
|
|
530
|
-
// });
|
|
531
|
-
// return {
|
|
532
|
-
// status: 400,
|
|
533
|
-
// json: { error: "Admin contract version not found" },
|
|
534
|
-
// };
|
|
535
|
-
// }
|
|
536
|
-
// const adminVersion = Number(adminVersionData.toBigint());
|
|
537
|
-
// const adminAddress0 = adminContract.zkapp?.appState[0];
|
|
538
|
-
// const adminAddress1 = adminContract.zkapp?.appState[1];
|
|
539
|
-
// if (adminAddress0 === undefined || adminAddress1 === undefined) {
|
|
540
|
-
// console.error("Cannot fetch admin address from admin contract");
|
|
541
|
-
// return {
|
|
542
|
-
// status: 400,
|
|
543
|
-
// json: { error: "Cannot fetch admin address from admin contract" },
|
|
544
|
-
// };
|
|
545
|
-
// }
|
|
546
|
-
// const adminAddress = PublicKey.fromFields([adminAddress0, adminAddress1]);
|
|
547
|
-
// let adminTokenBalance = 0;
|
|
548
|
-
// try {
|
|
549
|
-
// await fetchMinaAccount({
|
|
550
|
-
// publicKey: adminAddress,
|
|
551
|
-
// tokenId,
|
|
552
|
-
// force: false,
|
|
553
|
-
// });
|
|
554
|
-
// adminTokenBalance = Number(
|
|
555
|
-
// Mina.getBalance(adminAddress, tokenId).toBigInt()
|
|
556
|
-
// );
|
|
557
|
-
// } catch (error) {}
|
|
558
|
-
|
|
559
|
-
// const tokenState: TokenState = {
|
|
560
|
-
// tokenAddress: tokenContractPublicKey.toBase58(),
|
|
561
|
-
// tokenId: TokenId.toBase58(tokenId),
|
|
562
|
-
// adminContractAddress: adminContractPublicKey.toBase58(),
|
|
563
|
-
// adminAddress: adminAddress.toBase58(),
|
|
564
|
-
// adminTokenBalance,
|
|
565
|
-
// totalSupply,
|
|
566
|
-
// isPaused,
|
|
567
|
-
// decimals,
|
|
568
|
-
// tokenSymbol,
|
|
569
|
-
// verificationKeyHash,
|
|
570
|
-
// uri,
|
|
571
|
-
// version,
|
|
572
|
-
// adminTokenSymbol,
|
|
573
|
-
// adminUri: adminUri ?? "",
|
|
574
|
-
// adminVerificationKeyHash,
|
|
575
|
-
// adminVersion,
|
|
576
|
-
// };
|
|
577
|
-
|
|
578
|
-
// const updated = await updateTokenInfo({
|
|
579
|
-
// tokenAddress,
|
|
580
|
-
// tokenState,
|
|
581
|
-
// });
|
|
582
|
-
// if (updated) {
|
|
583
|
-
// console.log("getTokenState: Updated token info", {
|
|
584
|
-
// tokenAddress,
|
|
585
|
-
// symbol: tokenState.tokenSymbol,
|
|
586
|
-
// });
|
|
587
|
-
// }
|
|
588
|
-
// return {
|
|
589
|
-
// status: 200,
|
|
590
|
-
// json: tokenState,
|
|
591
|
-
// };
|
|
592
|
-
// } catch (error: any) {
|
|
593
|
-
// console.error("getTokenState catch", error);
|
|
594
|
-
// return {
|
|
595
|
-
// status: 503,
|
|
596
|
-
// json: {
|
|
597
|
-
// error:
|
|
598
|
-
// "getTokenState error:" +
|
|
599
|
-
// (error?.message ?? (error ? String(error) : "unknown error")),
|
|
600
|
-
// },
|
|
601
|
-
// };
|
|
602
|
-
// }
|
|
603
|
-
// }
|