@tradeport/sui-trading-sdk 0.5.5 → 0.5.6

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.
Files changed (153) hide show
  1. package/dist/index.d.ts +194 -0
  2. package/dist/index.js +7420 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +71 -66
  5. package/.babel.config.js +0 -3
  6. package/.claude/settings.json +0 -5
  7. package/.claude/settings.local.json +0 -5
  8. package/.env.demo +0 -5
  9. package/.eslintrc.json +0 -46
  10. package/.prettierignore +0 -4
  11. package/.prettierrc.json +0 -7
  12. package/.vscode/launch.json +0 -23
  13. package/CHANGELOG.md +0 -746
  14. package/jest.config.js +0 -12
  15. package/src/SuiTradingClient.ts +0 -442
  16. package/src/apiClients/createKioskClient.ts +0 -10
  17. package/src/apiClients/createSuiClient.ts +0 -5
  18. package/src/apiClients/graphqlClient.ts +0 -17
  19. package/src/bigNumberConfig.ts +0 -10
  20. package/src/constants.ts +0 -1052
  21. package/src/graphql/createChainGQLQuery.ts +0 -27
  22. package/src/graphql/gqlChainRequest.ts +0 -21
  23. package/src/graphql/queries/fetchAccountKiosks.ts +0 -12
  24. package/src/graphql/queries/fetchActiveLockStateByNftId.ts +0 -15
  25. package/src/graphql/queries/fetchBidsById.ts +0 -36
  26. package/src/graphql/queries/fetchCollectionBidById.ts +0 -21
  27. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +0 -29
  28. package/src/graphql/queries/fetchCollectionChainState.ts +0 -17
  29. package/src/graphql/queries/fetchCollectionFloorListingForMarket.ts +0 -28
  30. package/src/graphql/queries/fetchCollectionFloorListings.ts +0 -15
  31. package/src/graphql/queries/fetchCollectionsById.ts +0 -39
  32. package/src/graphql/queries/fetchCommissionByListingId.ts +0 -13
  33. package/src/graphql/queries/fetchCryptoToUsdRate.ts +0 -13
  34. package/src/graphql/queries/fetchKiosksByOwner.ts +0 -14
  35. package/src/graphql/queries/fetchListingsById.ts +0 -29
  36. package/src/graphql/queries/fetchListingsByNftId.ts +0 -23
  37. package/src/graphql/queries/fetchLockById.ts +0 -23
  38. package/src/graphql/queries/fetchMultibidById.ts +0 -34
  39. package/src/graphql/queries/fetchNftCollectionChainState.ts +0 -12
  40. package/src/graphql/queries/fetchNftsById.ts +0 -75
  41. package/src/graphql/queries/fetchNftsByKioskId.ts +0 -45
  42. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +0 -10
  43. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +0 -10
  44. package/src/graphql/queries/fetchSharedObjectsByType.ts +0 -12
  45. package/src/graphql/queries/fetchTransferPoliciesByType.ts +0 -12
  46. package/src/graphql/queries/fetchWalletKiosks.ts +0 -14
  47. package/src/graphql/queries/getCommissionByListingId.ts +0 -15
  48. package/src/helpers/addOneDollarFee.ts +0 -17
  49. package/src/helpers/addThirdPartyTxFee.ts +0 -17
  50. package/src/helpers/calculatePremium.ts +0 -9
  51. package/src/helpers/calculateRoyaltyFee.ts +0 -28
  52. package/src/helpers/destroyZeroCoin.ts +0 -14
  53. package/src/helpers/getActiveLockStateByNftId.ts +0 -15
  54. package/src/helpers/getCollectionChainState.ts +0 -31
  55. package/src/helpers/getCollectionFloorPrice.ts +0 -12
  56. package/src/helpers/getLockById.ts +0 -29
  57. package/src/helpers/getMarketFeePrice.ts +0 -82
  58. package/src/helpers/getNftType.ts +0 -38
  59. package/src/helpers/getRoyaltyRuleModule.ts +0 -7
  60. package/src/helpers/getSharedObjects.ts +0 -119
  61. package/src/helpers/getSuiToUsdRate.ts +0 -14
  62. package/src/helpers/getTradeportBiddingContractBidAmount.ts +0 -31
  63. package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +0 -24
  64. package/src/helpers/hasPersonalKioskRule.ts +0 -7
  65. package/src/helpers/hasRoyaltyRule.ts +0 -7
  66. package/src/helpers/hasTransferPolicyRules.ts +0 -6
  67. package/src/helpers/isExpiredListing.ts +0 -9
  68. package/src/helpers/isNonKioskListing.ts +0 -14
  69. package/src/helpers/isSIngleBid.ts +0 -13
  70. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +0 -31
  71. package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +0 -71
  72. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +0 -29
  73. package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +0 -59
  74. package/src/helpers/kiosk/getNativeKioskTransferPolicies.ts +0 -29
  75. package/src/helpers/kiosk/getNativeKioskTransferPoliciesByNftType.ts +0 -21
  76. package/src/helpers/kiosk/getRulePackageId.ts +0 -59
  77. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +0 -154
  78. package/src/helpers/kiosk/isBluemoveKioskBid.ts +0 -1
  79. package/src/helpers/kiosk/isTradePortKioskBid.ts +0 -4
  80. package/src/helpers/kiosk/kioskListingBcs.ts +0 -19
  81. package/src/helpers/kiosk/kioskTxWrapper.ts +0 -152
  82. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +0 -100
  83. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +0 -171
  84. package/src/helpers/kiosk/resolveCustomTransferPolicyRules.ts +0 -75
  85. package/src/helpers/kiosk/resolveFloorPriceRule.ts +0 -21
  86. package/src/helpers/kiosk/resolveKioskLockRule.ts +0 -47
  87. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +0 -23
  88. package/src/helpers/kiosk/resolveRoyaltyRule.ts +0 -57
  89. package/src/helpers/kiosk/resolveTableAllowlistRule.ts +0 -34
  90. package/src/helpers/kiosk/resolveTransferPolicies.ts +0 -158
  91. package/src/helpers/kiosk/sharedKioskState.type.ts +0 -11
  92. package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +0 -50
  93. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +0 -73
  94. package/src/helpers/kiosk/upgradeKioskRulesPackageId.ts +0 -17
  95. package/src/helpers/originByte/confirmOBTranfer.ts +0 -33
  96. package/src/helpers/originByte/createOBKiosk.ts +0 -14
  97. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +0 -16
  98. package/src/helpers/originByte/getOBBidderKiosk.ts +0 -12
  99. package/src/helpers/originByte/getOBKiosk.ts +0 -24
  100. package/src/helpers/originByte/getOrCreateOBKiosk.ts +0 -42
  101. package/src/helpers/originByte/isOBKiosk.ts +0 -13
  102. package/src/helpers/originByte/isOriginByteBid.ts +0 -30
  103. package/src/helpers/originByte/isOriginByteCollection.ts +0 -11
  104. package/src/helpers/originByte/shareOriginByteKiosk.ts +0 -14
  105. package/src/helpers/rpc/getAcountBalance.ts +0 -18
  106. package/src/helpers/rpc/getObjectType.ts +0 -25
  107. package/src/helpers/splitCoins.ts +0 -12
  108. package/src/helpers/track.ts +0 -20
  109. package/src/helpers/validateMinFloorPrice.ts +0 -22
  110. package/src/index.ts +0 -2
  111. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +0 -189
  112. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +0 -398
  113. package/src/methods/acceptNftBids/acceptNftBids.ts +0 -174
  114. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +0 -438
  115. package/src/methods/applyFtStrategy/applyFtStrategy.ts +0 -55
  116. package/src/methods/applyNftStrategy/applyNftStrategy.ts +0 -90
  117. package/src/methods/buyListings/addBuyListingTxs.ts +0 -806
  118. package/src/methods/buyListings/buyListings.ts +0 -230
  119. package/src/methods/cancelMultiBid/cancelMultiBid.ts +0 -51
  120. package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +0 -20
  121. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +0 -118
  122. package/src/methods/claimNfts/addClaimNftsTxs.ts +0 -247
  123. package/src/methods/claimNfts/claimNfts.ts +0 -270
  124. package/src/methods/createMultiBid/createMultiBid.ts +0 -36
  125. package/src/methods/listNfts/addListTxs.ts +0 -210
  126. package/src/methods/listNfts/addRelistTxs.ts +0 -87
  127. package/src/methods/listNfts/listNfts.ts +0 -152
  128. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +0 -226
  129. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +0 -149
  130. package/src/methods/placeCollectionBids/placeCollectionBids.ts +0 -153
  131. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +0 -154
  132. package/src/methods/placeNftBids/placeNftBids.ts +0 -111
  133. package/src/methods/relistNft/relistNft.ts +0 -153
  134. package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +0 -132
  135. package/src/methods/removeCollectionBids/removeCollectionBids.ts +0 -117
  136. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +0 -122
  137. package/src/methods/removeNftBids/removeNftBids.ts +0 -116
  138. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +0 -40
  139. package/src/methods/sponsorNftListing/sponsorNftListing.ts +0 -60
  140. package/src/methods/transferNfts/addTransferNftTx.ts +0 -220
  141. package/src/methods/transferNfts/transferNfts.ts +0 -216
  142. package/src/methods/unlistListings/addUnlistListingTxs.ts +0 -399
  143. package/src/methods/unlistListings/unlistListings.ts +0 -158
  144. package/src/methods/updateMultiBid/updateMultiBid.ts +0 -66
  145. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +0 -100
  146. package/src/tests/SuiWallet.ts +0 -83
  147. package/src/utils/addHexPrefix.ts +0 -7
  148. package/src/utils/addLeadingZerosAfter0x.ts +0 -9
  149. package/src/utils/normalizeNftType.ts +0 -7
  150. package/src/utils/printTxBlockTxs.ts +0 -11
  151. package/src/utils/pureValues.ts +0 -13
  152. package/src/utils/toUint8Array.ts +0 -12
  153. package/tsconfig.json +0 -16
@@ -1,158 +0,0 @@
1
- import type { KioskClient } from '@mysten/kiosk';
2
- import type { SuiGrpcClient } from '@mysten/sui/grpc';
3
- import { Transaction } from '@mysten/sui/transactions';
4
- import { type RequestContext } from '../../SuiTradingClient';
5
- import {
6
- DELOREAN_TOKEN_IDS_TO_DISABLE,
7
- DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
8
- } from '../../constants';
9
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
10
- import { fetchListingsById } from '../../graphql/queries/fetchListingsById';
11
- import { getNftType } from '../../helpers/getNftType';
12
- import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
13
- import {
14
- addBluemoveUnlistTxHandler,
15
- addClutchyUnlistTxHandler,
16
- addHyperspaceUnlistTxHandler,
17
- addKeepsakeUnlistTxHandler,
18
- addSomisUnlistTxHandler,
19
- addSouffl3UnlistTxHandler,
20
- addTocenUnlistTxHandler,
21
- addTradePortUnlistTxHandler,
22
- } from './addUnlistListingTxs';
23
- import { normalizeSuiAddress } from '@mysten/sui/utils';
24
-
25
- export type UnlistListingTx = {
26
- tx: Transaction;
27
- suiClient: SuiGrpcClient;
28
- kioskClient: KioskClient;
29
- sharedKioskState?: SharedKioskState;
30
- kioskTx?: any;
31
- seller: string;
32
- sharedObjects?: any;
33
- transferPolicies: any;
34
- collectionId: string;
35
- nftTokenId: string;
36
- nftType: string;
37
- listingNonce: string;
38
- price: number;
39
- sellerKiosk: string;
40
- isPartOfRelist?: boolean;
41
- };
42
-
43
- export type UnlistListing = {
44
- listingId: string;
45
- walletAddress: string;
46
- };
47
-
48
- export type UnlistListings = {
49
- listingIds: string[];
50
- walletAddress: string;
51
- };
52
-
53
- export const unlistListings = async (
54
- { listingIds, walletAddress }: UnlistListings,
55
- context: RequestContext,
56
- ): Promise<Transaction> => {
57
- const res = await gqlChainRequest({
58
- chain: 'sui',
59
- query: fetchListingsById,
60
- variables: { listingIds },
61
- });
62
-
63
- if (res?.listings?.length === 0) {
64
- throw new Error('No listings found');
65
- }
66
-
67
- const listingsForTracking = [];
68
- const tx = new Transaction();
69
-
70
- const sharedKioskState: SharedKioskState = {
71
- kioskTx: undefined,
72
- };
73
-
74
- for (const listing of res.listings) {
75
- if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(listing?.nft?.token_id)) {
76
- throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
77
- }
78
-
79
- // Allow the owner to unlist expired listing
80
- if (!listing?.listed && !listing?.nonce) {
81
- throw new Error(`Listing ${listing?.id} is not listed`);
82
- }
83
-
84
- const nftType = getNftType({
85
- collectionId: listing?.collection?.id,
86
- collectionChainState: listing?.collection?.chain_state,
87
- nft: listing?.nft,
88
- });
89
-
90
- const transferPolicies = listing?.collection?.chain_state?.transfer_policies;
91
-
92
- const txData: UnlistListingTx = {
93
- tx,
94
- suiClient: context.suiClient,
95
- kioskClient: context.kioskClient,
96
- sharedKioskState,
97
- transferPolicies,
98
- nftTokenId: listing.nft?.token_id,
99
- nftType,
100
- listingNonce: listing?.nonce,
101
- price: listing?.price,
102
- sellerKiosk: listing.nft?.chain_state?.kiosk_id,
103
- collectionId: listing?.nft?.collection_id,
104
- seller: walletAddress,
105
- };
106
-
107
- switch (listing?.market_name) {
108
- case 'tradeport':
109
- await addTradePortUnlistTxHandler(txData);
110
- break;
111
- case 'hyperspace':
112
- await addHyperspaceUnlistTxHandler(txData);
113
- break;
114
- case 'bluemove':
115
- await addBluemoveUnlistTxHandler(txData);
116
- break;
117
- case 'clutchy':
118
- await addClutchyUnlistTxHandler(txData);
119
- break;
120
- case 'souffl3':
121
- await addSouffl3UnlistTxHandler(txData);
122
- break;
123
- case 'somis':
124
- await addSomisUnlistTxHandler(txData);
125
- break;
126
- case 'keepsake':
127
- await addKeepsakeUnlistTxHandler(txData);
128
- break;
129
- case 'tocen':
130
- addTocenUnlistTxHandler(txData);
131
- break;
132
- default:
133
- throw new Error('Marketplace not supported');
134
- }
135
-
136
- listingsForTracking.push({
137
- walletAddress,
138
- nftType,
139
- collectionId: listing?.nft?.collection_id,
140
- price: listing?.price,
141
- seller: listing?.seller,
142
- marketName: listing?.market_name,
143
- });
144
- }
145
-
146
- sharedKioskState?.kioskTx?.finalize();
147
-
148
- // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && listingsForTracking.length > 0) {
149
- // trackMethodCall({
150
- // apiUser: context.apiUser,
151
- // apiKey: context.apiKey,
152
- // event: 'UNLIST_LISTINGS',
153
- // items: listingsForTracking,
154
- // });
155
- // }
156
-
157
- return Transaction.from(tx);
158
- };
@@ -1,66 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { TRADEPORT_MULTI_BID_PACKAGE, TRADEPORT_MULTI_BID_STORE } from '../../constants';
3
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
4
- import { fetchMultibidChainIdById } from '../../graphql/queries/fetchMultibidById';
5
- import { type RequestContext } from '../../SuiTradingClient';
6
-
7
- export interface UpdateMultiBid {
8
- walletAddress: string;
9
- multiBidId?: string;
10
- name?: string;
11
- amount?: bigint;
12
- amountToWithdraw?: bigint;
13
- tx?: Transaction;
14
- multiBidChainId?: any;
15
- coinToSplit?: any;
16
- }
17
-
18
- export async function updateMultiBid(
19
- {
20
- walletAddress,
21
- multiBidId,
22
- name,
23
- amount,
24
- amountToWithdraw,
25
- tx: existingTx,
26
- multiBidChainId,
27
- coinToSplit,
28
- }: UpdateMultiBid,
29
- context?: Pick<RequestContext, 'suiClient' | 'tradeportRouterUrl'>,
30
- ): Promise<Transaction> {
31
- const tx = existingTx ?? new Transaction();
32
-
33
- if (!multiBidChainId) {
34
- const { chain_id: chainId, cancelled_at } =
35
- (
36
- await gqlChainRequest({
37
- chain: 'sui',
38
- query: fetchMultibidChainIdById,
39
- variables: { multiBidId },
40
- })
41
- )?.multi_bids?.[0] ?? {};
42
- if (!chainId) {
43
- throw new Error(`MultiBid ${multiBidId} not found`);
44
- }
45
-
46
- if (cancelled_at) {
47
- throw new Error(`MultiBid ${multiBidId} already cancelled`);
48
- }
49
-
50
- multiBidChainId = chainId;
51
- }
52
-
53
- const [coin] = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [amount ?? 0n]);
54
- tx.moveCall({
55
- target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::update_multi_bid`,
56
- arguments: [
57
- tx.object(TRADEPORT_MULTI_BID_STORE),
58
- typeof multiBidChainId === 'string' ? tx.pure.id(multiBidChainId) : multiBidChainId,
59
- tx.pure.option('string', name),
60
- coin,
61
- tx.pure.option('u64', amountToWithdraw),
62
- ],
63
- });
64
-
65
- return tx;
66
- }
@@ -1,100 +0,0 @@
1
- import { KioskTransaction } from '@mysten/kiosk';
2
- import { Transaction } from '@mysten/sui/transactions';
3
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
4
- import { fetchOwnerCapByKiosk } from '../../graphql/queries/fetchOwnerCapByKiosk';
5
- import { fetchPersonalCapByKiosk } from '../../graphql/queries/fetchPersonalCapByKiosk';
6
- import { fetchWalletKiosks } from '../../graphql/queries/fetchWalletKiosks';
7
- import { type RequestContext } from '../../SuiTradingClient';
8
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
9
-
10
- export type WithdrawProfitsFromKiosks = {
11
- walletAddress: string;
12
- };
13
-
14
- export async function withdrawProfitsFromKiosks(
15
- { walletAddress }: WithdrawProfitsFromKiosks,
16
- context: RequestContext,
17
- ): Promise<Transaction> {
18
- const res = await gqlChainRequest({
19
- chain: 'sui',
20
- query: fetchWalletKiosks,
21
- variables: {
22
- wallet: addLeadingZerosAfter0x(walletAddress),
23
- },
24
- });
25
-
26
- const kiosks = res?.kiosks?.filter((kiosk: any) => !kiosk?.is_origin_byte);
27
-
28
- if (kiosks.length === 0) {
29
- throw new Error(`No kiosks found for ${walletAddress}`);
30
- }
31
-
32
- let kiosksWithProfit = kiosks.filter((kiosk: any) => kiosk.profits > 0);
33
-
34
- if (walletAddress === '0xcb0d10a55b0edd4d5b4748e484195a7a4b1dc10f0870d14fa850c66272796ece') {
35
- kiosksWithProfit = kiosksWithProfit.slice(0, 10);
36
- }
37
-
38
- if (kiosksWithProfit.length === 0) {
39
- throw new Error(`No kiosks with profit to withdraw found for ${walletAddress}`);
40
- }
41
-
42
- const tx = new Transaction();
43
-
44
- try {
45
- for (const kiosk of kiosksWithProfit) {
46
- let kioskTx: KioskTransaction;
47
-
48
- if (kiosk.is_personal) {
49
- const personalKioskCapId = (
50
- await gqlChainRequest({
51
- chain: 'sui',
52
- query: fetchPersonalCapByKiosk,
53
- variables: { kioskId: kiosk.id },
54
- })
55
- ).personalCap?.id;
56
-
57
- kioskTx = new KioskTransaction({
58
- transaction: tx,
59
- kioskClient: context.kioskClient,
60
- cap: {
61
- isPersonal: true,
62
- objectId: personalKioskCapId,
63
- kioskId: kiosk.id,
64
- digest: '',
65
- version: '',
66
- },
67
- });
68
- } else if (kiosks.length > 0) {
69
- const kioskCapId = (
70
- await gqlChainRequest({
71
- chain: 'sui',
72
- query: fetchOwnerCapByKiosk,
73
- variables: { kioskId: kiosk.id },
74
- })
75
- ).ownerCap?.id;
76
-
77
- kioskTx = new KioskTransaction({
78
- transaction: tx,
79
- kioskClient: context.kioskClient,
80
- cap: {
81
- isPersonal: false,
82
- objectId: kioskCapId,
83
- kioskId: kiosk.id,
84
- digest: '',
85
- version: '',
86
- },
87
- });
88
-
89
- kioskTx.convertToPersonal(true);
90
- }
91
-
92
- kioskTx.withdraw(addLeadingZerosAfter0x(walletAddress));
93
- kioskTx.finalize();
94
- }
95
- } catch (err) {
96
- console.log('err', err);
97
- }
98
-
99
- return Transaction.from(tx);
100
- }
@@ -1,83 +0,0 @@
1
- import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
2
- import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
3
- import { type Transaction } from '@mysten/sui/transactions';
4
- import createSuiClient from '../apiClients/createSuiClient';
5
- import { toUint8Array } from '../utils/toUint8Array';
6
-
7
- export class SuiWallet {
8
- readonly keypair = process.env.SUI_WALLET_SECRET_KEY.startsWith('suiprivkey')
9
- ? Ed25519Keypair.fromSecretKey(decodeSuiPrivateKey(process.env.SUI_WALLET_SECRET_KEY).secretKey)
10
- : Ed25519Keypair.fromSecretKey(toUint8Array(process.env.SUI_WALLET_SECRET_KEY));
11
-
12
- private readonly suiClient: ReturnType<typeof createSuiClient>;
13
- private balanceAmount = 0n;
14
-
15
- constructor() {
16
- this.suiClient = createSuiClient(process.env.SUI_RPC_URL);
17
- }
18
-
19
- async refreshBalance(): Promise<void> {
20
- this.balanceAmount = BigInt(
21
- (await this.suiClient.getBalance({ owner: this.keypair.toSuiAddress() })).balance.balance,
22
- );
23
- }
24
-
25
- get balance(): bigint {
26
- return this.balanceAmount;
27
- }
28
-
29
- get batchSize(): number {
30
- return 1;
31
- }
32
-
33
- async simulateCall(tx: Transaction, sender?: string): Promise<any> {
34
- tx.setSenderIfNotSet(sender ?? this.keypair.toSuiAddress());
35
- const result = await this.suiClient.simulateTransaction({
36
- transaction: tx,
37
- include: { effects: true },
38
- });
39
-
40
- if (result.$kind === 'FailedTransaction') {
41
- throw new Error(
42
- `Error on transaction simulation: ${JSON.stringify(result.FailedTransaction.status.error)}`,
43
- );
44
- }
45
-
46
- return result;
47
- }
48
-
49
- async executeTransaction(tx: Transaction): Promise<string> {
50
- tx.setSenderIfNotSet(this.keypair.toSuiAddress());
51
- const executed = await this.suiClient.signAndExecuteTransaction({
52
- transaction: tx,
53
- signer: this.keypair,
54
- });
55
- const digest = executed.Transaction?.digest ?? executed.FailedTransaction?.digest ?? '';
56
- console.log(digest);
57
- const response = await this.suiClient.waitForTransaction({
58
- digest,
59
- include: { effects: true },
60
- });
61
- if (response.$kind !== 'Transaction') {
62
- throw new Error(
63
- `Error on transaction execution: ${
64
- response.FailedTransaction?.status?.error
65
- ? JSON.stringify(response.FailedTransaction.status.error)
66
- : ''
67
- }`,
68
- );
69
- }
70
-
71
- return digest;
72
- }
73
- }
74
-
75
- export async function getSui(): Promise<SuiWallet> {
76
- const sui = new SuiWallet();
77
- await sui.refreshBalance();
78
- if (sui.balance < 100n) {
79
- console.warn(`⚠️ Sui balance is low (${sui.balance}). Please top up it.`);
80
- }
81
-
82
- return sui;
83
- }
@@ -1,7 +0,0 @@
1
- export function addHexPrefix(input: string): string {
2
- if (input.startsWith('0x')) {
3
- return input;
4
- }
5
-
6
- return '0x' + input;
7
- }
@@ -1,9 +0,0 @@
1
- export const addLeadingZerosAfter0x = (str: string): string =>
2
- `0x${str?.replace('0x', '').padStart(64, '0')}`;
3
-
4
- export const addLeadingZerosToPackage = (str: string, skip0x?: boolean) => {
5
- const address = str?.split('::')[0];
6
- const suffix = `::${str?.split('::').slice(1).join('::')}`;
7
-
8
- return `${skip0x ? '' : '0x'}${address?.replace('0x', '').padStart(64, '0')}${suffix}`;
9
- };
@@ -1,7 +0,0 @@
1
- import { addLeadingZerosAfter0x } from './addLeadingZerosAfter0x';
2
-
3
- export const normalizedNftType = (nftType: string): string => {
4
- const nftTypeSplit = nftType?.split('::');
5
- if (nftTypeSplit?.[0]) nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
6
- return nftTypeSplit?.join('::');
7
- };
@@ -1,11 +0,0 @@
1
- import { type Transaction } from '@mysten/sui/transactions';
2
-
3
- export const printTxBlockTxs = async (tx: Transaction) => {
4
- console.log(
5
- JSON.stringify(
6
- tx?.getData(),
7
- (key, value) => (typeof value === 'bigint' ? value.toString() : value),
8
- 2,
9
- ),
10
- );
11
- };
@@ -1,13 +0,0 @@
1
- import BigNumber from '../bigNumberConfig';
2
-
3
- export const toDecimalValue = (value: string | number | BigNumber, decimals: number): BigNumber => {
4
- if (!value || decimals === undefined) return new BigNumber(0);
5
-
6
- return new BigNumber(value).div(10 ** decimals);
7
- };
8
-
9
- export const toPureValue = (value: string | number | BigNumber, decimals: number): BigNumber => {
10
- if (!value || decimals === undefined) return new BigNumber(0);
11
-
12
- return new BigNumber(new BigNumber(value).multipliedBy(10 ** decimals).toFixed(0));
13
- };
@@ -1,12 +0,0 @@
1
- export function toUint8Array(hex: string): Uint8Array {
2
- if (hex?.startsWith('0x')) {
3
- hex = hex.slice(2); // Remove "0x" prefix
4
- }
5
-
6
- const bytes = [];
7
- for (let i = 0; i < hex.length; i += 2) {
8
- bytes.push(parseInt(hex.substr(i, 2), 16));
9
- }
10
-
11
- return Uint8Array.from(bytes);
12
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2020",
4
- "module": "esnext",
5
- "moduleResolution": "Bundler",
6
- "lib": ["es2020"],
7
- "allowJs": false,
8
- "skipLibCheck": true,
9
- "strict": true,
10
- "strictNullChecks": false,
11
- "forceConsistentCasingInFileNames": true,
12
- "noUncheckedIndexedAccess": true,
13
- "esModuleInterop": true,
14
- "noEmit": true
15
- }
16
- }