@tradeport/sui-trading-sdk 0.5.1 → 0.5.3

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 (154) hide show
  1. package/dist/index.js +19 -1
  2. package/dist/index.js.map +1 -1
  3. package/package.json +71 -66
  4. package/.babel.config.js +0 -3
  5. package/.claude/settings.json +0 -5
  6. package/.env.demo +0 -5
  7. package/.eslintrc.json +0 -46
  8. package/.prettierignore +0 -4
  9. package/.prettierrc.json +0 -7
  10. package/.vscode/launch.json +0 -23
  11. package/CHANGELOG.md +0 -746
  12. package/dist/index.d.mts +0 -193
  13. package/dist/index.mjs +0 -7386
  14. package/dist/index.mjs.map +0 -1
  15. package/jest.config.js +0 -12
  16. package/src/SuiTradingClient.ts +0 -442
  17. package/src/apiClients/createKioskClient.ts +0 -10
  18. package/src/apiClients/createSuiClient.ts +0 -5
  19. package/src/apiClients/graphqlClient.ts +0 -17
  20. package/src/bigNumberConfig.ts +0 -10
  21. package/src/constants.ts +0 -1052
  22. package/src/graphql/createChainGQLQuery.ts +0 -27
  23. package/src/graphql/gqlChainRequest.ts +0 -21
  24. package/src/graphql/queries/fetchAccountKiosks.ts +0 -12
  25. package/src/graphql/queries/fetchActiveLockStateByNftId.ts +0 -15
  26. package/src/graphql/queries/fetchBidsById.ts +0 -36
  27. package/src/graphql/queries/fetchCollectionBidById.ts +0 -21
  28. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +0 -29
  29. package/src/graphql/queries/fetchCollectionChainState.ts +0 -17
  30. package/src/graphql/queries/fetchCollectionFloorListingForMarket.ts +0 -28
  31. package/src/graphql/queries/fetchCollectionFloorListings.ts +0 -15
  32. package/src/graphql/queries/fetchCollectionsById.ts +0 -39
  33. package/src/graphql/queries/fetchCommissionByListingId.ts +0 -13
  34. package/src/graphql/queries/fetchCryptoToUsdRate.ts +0 -13
  35. package/src/graphql/queries/fetchKiosksByOwner.ts +0 -14
  36. package/src/graphql/queries/fetchListingsById.ts +0 -29
  37. package/src/graphql/queries/fetchListingsByNftId.ts +0 -23
  38. package/src/graphql/queries/fetchLockById.ts +0 -23
  39. package/src/graphql/queries/fetchMultibidById.ts +0 -34
  40. package/src/graphql/queries/fetchNftCollectionChainState.ts +0 -12
  41. package/src/graphql/queries/fetchNftsById.ts +0 -75
  42. package/src/graphql/queries/fetchNftsByKioskId.ts +0 -45
  43. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +0 -10
  44. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +0 -10
  45. package/src/graphql/queries/fetchSharedObjectsByType.ts +0 -12
  46. package/src/graphql/queries/fetchTransferPoliciesByType.ts +0 -12
  47. package/src/graphql/queries/fetchWalletKiosks.ts +0 -14
  48. package/src/graphql/queries/getCommissionByListingId.ts +0 -15
  49. package/src/helpers/addOneDollarFee.ts +0 -17
  50. package/src/helpers/addThirdPartyTxFee.ts +0 -17
  51. package/src/helpers/calculatePremium.ts +0 -9
  52. package/src/helpers/calculateRoyaltyFee.ts +0 -28
  53. package/src/helpers/destroyZeroCoin.ts +0 -14
  54. package/src/helpers/getActiveLockStateByNftId.ts +0 -15
  55. package/src/helpers/getCollectionChainState.ts +0 -31
  56. package/src/helpers/getCollectionFloorPrice.ts +0 -12
  57. package/src/helpers/getLockById.ts +0 -29
  58. package/src/helpers/getMarketFeePrice.ts +0 -82
  59. package/src/helpers/getNftType.ts +0 -38
  60. package/src/helpers/getRoyaltyRuleModule.ts +0 -7
  61. package/src/helpers/getSharedObjects.ts +0 -119
  62. package/src/helpers/getSuiToUsdRate.ts +0 -14
  63. package/src/helpers/getTradeportBiddingContractBidAmount.ts +0 -31
  64. package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +0 -24
  65. package/src/helpers/hasPersonalKioskRule.ts +0 -7
  66. package/src/helpers/hasRoyaltyRule.ts +0 -7
  67. package/src/helpers/hasTransferPolicyRules.ts +0 -6
  68. package/src/helpers/isExpiredListing.ts +0 -9
  69. package/src/helpers/isNonKioskListing.ts +0 -14
  70. package/src/helpers/isSIngleBid.ts +0 -13
  71. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +0 -31
  72. package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +0 -71
  73. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +0 -29
  74. package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +0 -59
  75. package/src/helpers/kiosk/getNativeKioskTransferPolicies.ts +0 -29
  76. package/src/helpers/kiosk/getNativeKioskTransferPoliciesByNftType.ts +0 -21
  77. package/src/helpers/kiosk/getRulePackageId.ts +0 -59
  78. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +0 -154
  79. package/src/helpers/kiosk/isBluemoveKioskBid.ts +0 -1
  80. package/src/helpers/kiosk/isTradePortKioskBid.ts +0 -4
  81. package/src/helpers/kiosk/kioskListingBcs.ts +0 -19
  82. package/src/helpers/kiosk/kioskTxWrapper.ts +0 -152
  83. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +0 -100
  84. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +0 -171
  85. package/src/helpers/kiosk/resolveCustomTransferPolicyRules.ts +0 -75
  86. package/src/helpers/kiosk/resolveFloorPriceRule.ts +0 -21
  87. package/src/helpers/kiosk/resolveKioskLockRule.ts +0 -47
  88. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +0 -23
  89. package/src/helpers/kiosk/resolveRoyaltyRule.ts +0 -57
  90. package/src/helpers/kiosk/resolveTableAllowlistRule.ts +0 -34
  91. package/src/helpers/kiosk/resolveTransferPolicies.ts +0 -158
  92. package/src/helpers/kiosk/sharedKioskState.type.ts +0 -11
  93. package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +0 -50
  94. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +0 -73
  95. package/src/helpers/kiosk/upgradeKioskRulesPackageId.ts +0 -17
  96. package/src/helpers/originByte/confirmOBTranfer.ts +0 -33
  97. package/src/helpers/originByte/createOBKiosk.ts +0 -14
  98. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +0 -16
  99. package/src/helpers/originByte/getOBBidderKiosk.ts +0 -12
  100. package/src/helpers/originByte/getOBKiosk.ts +0 -24
  101. package/src/helpers/originByte/getOrCreateOBKiosk.ts +0 -42
  102. package/src/helpers/originByte/isOBKiosk.ts +0 -13
  103. package/src/helpers/originByte/isOriginByteBid.ts +0 -6
  104. package/src/helpers/originByte/isOriginByteCollection.ts +0 -11
  105. package/src/helpers/originByte/shareOriginByteKiosk.ts +0 -14
  106. package/src/helpers/rpc/getAcountBalance.ts +0 -18
  107. package/src/helpers/rpc/getObjectType.ts +0 -25
  108. package/src/helpers/splitCoins.ts +0 -12
  109. package/src/helpers/track.ts +0 -20
  110. package/src/helpers/validateMinFloorPrice.ts +0 -22
  111. package/src/index.ts +0 -2
  112. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +0 -189
  113. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +0 -398
  114. package/src/methods/acceptNftBids/acceptNftBids.ts +0 -174
  115. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +0 -438
  116. package/src/methods/applyFtStrategy/applyFtStrategy.ts +0 -55
  117. package/src/methods/applyNftStrategy/applyNftStrategy.ts +0 -90
  118. package/src/methods/buyListings/addBuyListingTxs.ts +0 -803
  119. package/src/methods/buyListings/buyListings.ts +0 -230
  120. package/src/methods/cancelMultiBid/cancelMultiBid.ts +0 -51
  121. package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +0 -20
  122. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +0 -118
  123. package/src/methods/claimNfts/addClaimNftsTxs.ts +0 -247
  124. package/src/methods/claimNfts/claimNfts.ts +0 -270
  125. package/src/methods/createMultiBid/createMultiBid.ts +0 -36
  126. package/src/methods/listNfts/addListTxs.ts +0 -210
  127. package/src/methods/listNfts/addRelistTxs.ts +0 -87
  128. package/src/methods/listNfts/listNfts.ts +0 -152
  129. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +0 -226
  130. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +0 -149
  131. package/src/methods/placeCollectionBids/placeCollectionBids.ts +0 -153
  132. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +0 -154
  133. package/src/methods/placeNftBids/placeNftBids.ts +0 -111
  134. package/src/methods/relistNft/relistNft.ts +0 -153
  135. package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +0 -132
  136. package/src/methods/removeCollectionBids/removeCollectionBids.ts +0 -117
  137. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +0 -122
  138. package/src/methods/removeNftBids/removeNftBids.ts +0 -116
  139. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +0 -40
  140. package/src/methods/sponsorNftListing/sponsorNftListing.ts +0 -60
  141. package/src/methods/transferNfts/addTransferNftTx.ts +0 -220
  142. package/src/methods/transferNfts/transferNfts.ts +0 -216
  143. package/src/methods/unlistListings/addUnlistListingTxs.ts +0 -399
  144. package/src/methods/unlistListings/unlistListings.ts +0 -158
  145. package/src/methods/updateMultiBid/updateMultiBid.ts +0 -66
  146. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +0 -100
  147. package/src/tests/SuiWallet.ts +0 -83
  148. package/src/utils/addHexPrefix.ts +0 -7
  149. package/src/utils/addLeadingZerosAfter0x.ts +0 -9
  150. package/src/utils/normalizeNftType.ts +0 -7
  151. package/src/utils/printTxBlockTxs.ts +0 -11
  152. package/src/utils/pureValues.ts +0 -13
  153. package/src/utils/toUint8Array.ts +0 -12
  154. package/tsconfig.json +0 -16
@@ -1,171 +0,0 @@
1
- import type { KioskClient } from '@mysten/kiosk';
2
- import { bcs } from '@mysten/sui/bcs';
3
- import type { SuiGrpcClient } from '@mysten/sui/grpc';
4
- import { Transaction } from '@mysten/sui/transactions';
5
- import { TRADEPORT_KIOSK_LISTING_STORE } from '../../constants';
6
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
7
- import { getNftType } from '../getNftType';
8
- import { getSharedObjects } from '../getSharedObjects';
9
- import { isOriginByteCollection } from '../originByte/isOriginByteCollection';
10
- import { getTransferPoliciesToResolve } from './getTransferPoliciesToResolve';
11
- import { KioskListing } from './kioskListingBcs';
12
-
13
- export type SharedBulkBuyingDataByNftType = Record<
14
- string,
15
- {
16
- sharedObjects?: any;
17
- transferPoliciesToResolve?: any[];
18
- royaltyFeeAmountsByListingId?: Record<string, bigint>;
19
- commissionFeeAmountsByListingId?: Record<string, number>;
20
- }
21
- >;
22
-
23
- export const preProcessSharedBulkBuyingData = async ({
24
- listings,
25
- suiClient,
26
- kioskClient,
27
- walletAddress,
28
- }: {
29
- listings: any[];
30
- suiClient: SuiGrpcClient;
31
- kioskClient: KioskClient;
32
- walletAddress: string;
33
- }) => {
34
- const sharedBulkBuyingDataByNftType: SharedBulkBuyingDataByNftType = {};
35
-
36
- const listingsByNftType = listings.reduce<Record<string, any[]>>(
37
- (acc: Record<string, any[]>, listing: any) => {
38
- const nftType = getNftType({
39
- collectionId: listing?.collection?.id,
40
- collectionChainState: listing?.collection?.chain_state,
41
- nft: listing?.nft,
42
- });
43
-
44
- acc[nftType] = [...(acc[nftType] || []), listing];
45
-
46
- return acc;
47
- },
48
- {},
49
- );
50
-
51
- for (const nftType of Object.keys(listingsByNftType)) {
52
- sharedBulkBuyingDataByNftType[nftType] = {
53
- sharedObjects: [],
54
- transferPoliciesToResolve: [],
55
- royaltyFeeAmountsByListingId: {},
56
- commissionFeeAmountsByListingId: {},
57
- };
58
-
59
- const transferPolicies =
60
- listingsByNftType[nftType]?.[0]?.collection?.chain_state?.transfer_policies;
61
-
62
- if (isOriginByteCollection(transferPolicies)) {
63
- sharedBulkBuyingDataByNftType[nftType].sharedObjects = await getSharedObjects(nftType);
64
- continue;
65
- }
66
-
67
- const tradeportLegacyKioskListings = listingsByNftType[nftType]?.filter(
68
- (listing: any) =>
69
- listing.market_name === 'tradeport' &&
70
- !listing.nonce?.startsWith('0::') &&
71
- !listing.nonce?.startsWith('1::') &&
72
- listing.price &&
73
- listing.listed &&
74
- !(listing?.nonce && isOriginByteCollection(transferPolicies)) &&
75
- listing.nft?.chain_state?.kiosk_id,
76
- );
77
-
78
- if (tradeportLegacyKioskListings.length === 0) {
79
- continue;
80
- }
81
-
82
- const transferPoliciesToResolve = await getTransferPoliciesToResolve({
83
- transferPolicies,
84
- suiClient,
85
- kioskClient,
86
- nftType,
87
- });
88
- sharedBulkBuyingDataByNftType[nftType].transferPoliciesToResolve = transferPoliciesToResolve;
89
-
90
- const transferPolicyToResolve = transferPoliciesToResolve.at(0);
91
-
92
- const royaltyRuleToResolve = transferPolicyToResolve.rules.find(
93
- (rule: any) => rule.moduleName === 'royalty_rule' || rule.moduleName === 'kiosk_royalty_rule',
94
- );
95
-
96
- if (royaltyRuleToResolve?.rulePackageId && royaltyRuleToResolve?.moduleName) {
97
- // for each tp kiosk listing, create fee_amount txs and dev inspect the tx block to get the royalty fee amounts and store them in shared data
98
- const feeTx = new Transaction();
99
- for (const listing of tradeportLegacyKioskListings) {
100
- feeTx.moveCall({
101
- target: `${royaltyRuleToResolve.rulePackageId}::${royaltyRuleToResolve.moduleName}::fee_amount`,
102
- arguments: [feeTx.object(transferPolicyToResolve?.id), feeTx.pure.u64(listing.price)],
103
- typeArguments: [nftType],
104
- });
105
- }
106
-
107
- feeTx.setSender(addLeadingZerosAfter0x(walletAddress));
108
- const res = await suiClient.simulateTransaction({
109
- transaction: feeTx,
110
- include: { commandResults: true },
111
- checksEnabled: false,
112
- });
113
-
114
- const commandResults = res.commandResults ?? [];
115
- for (let i = 0; i < commandResults.length; i++) {
116
- const result = commandResults[i];
117
- const returnedAmount = result?.returnValues?.[0]?.bcs;
118
- if (!returnedAmount) {
119
- continue;
120
- }
121
-
122
- const feeAmount = BigInt(bcs.U64.parse(returnedAmount));
123
-
124
- if (!feeAmount && feeAmount !== 0n) {
125
- // We were not able to calculate the fee amount outside of the transaction via simulation, so skip pre processing
126
- continue;
127
- }
128
-
129
- sharedBulkBuyingDataByNftType[nftType].royaltyFeeAmountsByListingId[
130
- tradeportLegacyKioskListings[i].id
131
- ] = feeAmount;
132
- }
133
- }
134
-
135
- // for each tp kiosk listing, pre-fetch commission fee amounts in batches and store them in shared data
136
- const batchSize = 10;
137
- const commissionResults: Array<{ listingId: string; commission: number }> = [];
138
- for (let i = 0; i < tradeportLegacyKioskListings.length; i += batchSize) {
139
- const batch = tradeportLegacyKioskListings.slice(i, i + batchSize);
140
- const batchPromises = batch.map(async (listing: any) => {
141
- try {
142
- const { object } = await suiClient.core.getDynamicObjectField({
143
- parentId: TRADEPORT_KIOSK_LISTING_STORE,
144
- name: {
145
- type: '0x2::object::ID',
146
- bcs: bcs.Address.serialize(listing.nft.token_id).toBytes(),
147
- },
148
- include: { content: true },
149
- });
150
-
151
- return {
152
- listingId: listing.id,
153
- commission: Number(KioskListing.parse(object.content).commission),
154
- };
155
- } catch {
156
- throw new Error(`Not found kiosk listing object of token ${listing.nft.token_id}`);
157
- }
158
- });
159
-
160
- const batchResults = await Promise.all(batchPromises);
161
- commissionResults.push(...batchResults);
162
- }
163
-
164
- for (const result of commissionResults) {
165
- sharedBulkBuyingDataByNftType[nftType].commissionFeeAmountsByListingId[result.listingId] =
166
- result.commission;
167
- }
168
- }
169
-
170
- return sharedBulkBuyingDataByNftType;
171
- };
@@ -1,75 +0,0 @@
1
- import {
2
- type Transaction,
3
- type TransactionArgument,
4
- type TransactionObjectInput,
5
- } from '@mysten/sui/transactions';
6
- import { CUSTOM_TRANSFER_RULES_BY_COLLECTION } from '../../constants';
7
- import { resolveTableAllowlistRule } from './resolveTableAllowlistRule';
8
-
9
- type ResolverArgs = {
10
- tx: Transaction;
11
- packageId: string;
12
- transferRequest: TransactionArgument;
13
- nftType: string;
14
- policyId: TransactionObjectInput;
15
- params: Record<string, string>;
16
- };
17
-
18
- type CustomRuleResolver = (args: ResolverArgs) => void;
19
-
20
- const customRuleResolvers: Record<string, CustomRuleResolver> = {
21
- table_allowlist_rule: resolveTableAllowlistRule,
22
- };
23
-
24
- export const customTransferPolicyRuleNames = Object.keys(customRuleResolvers);
25
-
26
- type RuleData = {
27
- rule: string;
28
- rulePackageId?: string;
29
- moduleName?: string;
30
- params?: Record<string, string>;
31
- };
32
-
33
- function findParamsFromConfig(moduleName: string, packageId: string): Record<string, string> {
34
- for (const configs of Object.values(CUSTOM_TRANSFER_RULES_BY_COLLECTION)) {
35
- const match = configs.find((c) => c.moduleName === moduleName && c.packageId === packageId);
36
- if (match) return match.params;
37
- }
38
-
39
- throw new Error(`No custom rule config found for ${moduleName} at package ${packageId}`);
40
- }
41
-
42
- export function resolveCustomTransferPolicyRules({
43
- tx,
44
- rules,
45
- transferRequest,
46
- nftType,
47
- policyId,
48
- }: {
49
- tx: Transaction;
50
- rules: RuleData[];
51
- transferRequest: TransactionArgument;
52
- nftType: string;
53
- policyId: TransactionObjectInput;
54
- }): boolean {
55
- let resolved = false;
56
- for (const rule of rules) {
57
- const moduleName = rule.moduleName ?? rule.rule?.split('::')?.[1];
58
- const resolver = moduleName ? customRuleResolvers[moduleName] : undefined;
59
- if (resolver) {
60
- const packageId = rule.rulePackageId ?? rule.rule?.split('::')?.[0];
61
- const params = rule.params ?? findParamsFromConfig(moduleName, packageId);
62
- resolver({
63
- tx,
64
- packageId,
65
- transferRequest,
66
- nftType,
67
- policyId,
68
- params,
69
- });
70
- resolved = true;
71
- }
72
- }
73
-
74
- return resolved;
75
- }
@@ -1,21 +0,0 @@
1
- import {
2
- type Transaction,
3
- type TransactionArgument,
4
- type TransactionObjectInput,
5
- } from '@mysten/sui/transactions';
6
-
7
- type Args = {
8
- tx: Transaction;
9
- packageId: string;
10
- transferRequest: TransactionArgument;
11
- nftType: string;
12
- policyId: TransactionObjectInput;
13
- };
14
-
15
- export function resolveFloorPriceRule({ tx, packageId, nftType, policyId, transferRequest }: Args) {
16
- tx.moveCall({
17
- target: `${packageId}::floor_price_rule::prove`,
18
- typeArguments: [nftType],
19
- arguments: [tx.object(policyId), transferRequest],
20
- });
21
- }
@@ -1,47 +0,0 @@
1
- import {
2
- type Transaction,
3
- type TransactionArgument,
4
- type TransactionObjectInput,
5
- } from '@mysten/sui/transactions';
6
-
7
- type Args = {
8
- tx: Transaction;
9
- policyId: TransactionObjectInput;
10
- packageId: string;
11
- transferRequest: TransactionArgument;
12
- nftType: string;
13
- kiosk: TransactionObjectInput;
14
- kioskCap: TransactionObjectInput;
15
- kioskItem?: TransactionObjectInput;
16
- shouldSkipLocking?: boolean;
17
- };
18
-
19
- export function resolveKioskLockRule({
20
- tx,
21
- packageId,
22
- policyId,
23
- transferRequest,
24
- nftType,
25
- kiosk,
26
- kioskCap,
27
- kioskItem,
28
- shouldSkipLocking,
29
- }: Args) {
30
- if (!kiosk || !kioskCap) throw new Error('Missing Owned Kiosk or Owned Kiosk Cap');
31
-
32
- if (!shouldSkipLocking) {
33
- if (!kioskItem) throw new Error('Missing Kiosk Item');
34
-
35
- tx.moveCall({
36
- target: '0x2::kiosk::lock',
37
- typeArguments: [nftType],
38
- arguments: [tx.object(kiosk), tx.object(kioskCap), tx.object(policyId), tx.object(kioskItem)],
39
- });
40
- }
41
-
42
- tx.moveCall({
43
- target: `${packageId}::kiosk_lock_rule::prove`,
44
- typeArguments: [nftType],
45
- arguments: [transferRequest, tx.object(kiosk)],
46
- });
47
- }
@@ -1,23 +0,0 @@
1
- import {
2
- type Transaction,
3
- type TransactionArgument,
4
- type TransactionObjectInput,
5
- } from '@mysten/sui/transactions';
6
-
7
- type Args = {
8
- tx: Transaction;
9
- packageId: string;
10
- transferRequest: TransactionArgument;
11
- nftType: string;
12
- kiosk: TransactionObjectInput;
13
- };
14
-
15
- export function resolvePersonalKioskRule({ tx, packageId, nftType, kiosk, transferRequest }: Args) {
16
- if (!kiosk) throw new Error('Missing owned Kiosk.');
17
-
18
- tx.moveCall({
19
- target: `${packageId}::personal_kiosk_rule::prove`,
20
- typeArguments: [nftType],
21
- arguments: [tx.object(kiosk), transferRequest],
22
- });
23
- }
@@ -1,57 +0,0 @@
1
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
2
- import {
3
- type Transaction,
4
- type TransactionArgument,
5
- type TransactionObjectInput,
6
- } from '@mysten/sui/transactions';
7
- import { getKioskCollectionRoyaltyFeeAmount } from './getKioskCollectionRoyaltyFeeAmount';
8
-
9
- type Args = {
10
- tx: Transaction;
11
- suiClient: SuiGrpcClient;
12
- walletAddress: string;
13
- policyId: TransactionObjectInput;
14
- moduleName: string;
15
- packageId: string;
16
- transferRequest: TransactionArgument;
17
- nftType: string;
18
- price: string;
19
- coinToSplit?: any;
20
- royaltyFeeAmount?: bigint;
21
- };
22
-
23
- export async function resolveRoyaltyRule({
24
- tx,
25
- suiClient,
26
- walletAddress,
27
- packageId,
28
- moduleName,
29
- policyId,
30
- transferRequest,
31
- nftType,
32
- price,
33
- coinToSplit,
34
- royaltyFeeAmount,
35
- }: Args) {
36
- let feeAmount: bigint | TransactionArgument | undefined = royaltyFeeAmount;
37
- if (!feeAmount) {
38
- feeAmount = await getKioskCollectionRoyaltyFeeAmount({
39
- tx,
40
- suiClient,
41
- walletAddress,
42
- royaltyRulePackageId: packageId,
43
- royaltyRuleModule: moduleName,
44
- transferPolicyId: policyId,
45
- price,
46
- nftType,
47
- });
48
- }
49
-
50
- const feeCoin = tx.splitCoins(coinToSplit ? coinToSplit : tx.gas, [feeAmount]);
51
-
52
- tx.moveCall({
53
- target: `${packageId}::${moduleName}::pay`,
54
- typeArguments: [nftType],
55
- arguments: [tx.object(policyId), transferRequest, feeCoin],
56
- });
57
- }
@@ -1,34 +0,0 @@
1
- import {
2
- type Transaction,
3
- type TransactionArgument,
4
- type TransactionObjectInput,
5
- } from '@mysten/sui/transactions';
6
-
7
- type Args = {
8
- tx: Transaction;
9
- packageId: string;
10
- transferRequest: TransactionArgument;
11
- nftType: string;
12
- policyId: TransactionObjectInput;
13
- params: Record<string, string>;
14
- };
15
-
16
- export function resolveTableAllowlistRule({
17
- tx,
18
- packageId,
19
- nftType,
20
- policyId,
21
- transferRequest,
22
- params,
23
- }: Args) {
24
- const { registryId } = params;
25
- if (!registryId) {
26
- throw new Error(`Missing registryId in params for table_allowlist_rule (package ${packageId})`);
27
- }
28
-
29
- tx.moveCall({
30
- target: `${packageId}::table_allowlist_rule::resolve`,
31
- typeArguments: [nftType],
32
- arguments: [tx.object(policyId), transferRequest, tx.object(registryId)],
33
- });
34
- }
@@ -1,158 +0,0 @@
1
- import { type KioskClient } from '@mysten/kiosk';
2
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
3
- import {
4
- type Transaction,
5
- type TransactionArgument,
6
- type TransactionObjectInput,
7
- } from '@mysten/sui/transactions';
8
- import { getTransferPoliciesToResolve } from './getTransferPoliciesToResolve';
9
- import { resolveFloorPriceRule } from './resolveFloorPriceRule';
10
- import { resolveKioskLockRule } from './resolveKioskLockRule';
11
- import { resolvePersonalKioskRule } from './resolvePersonalKioskRule';
12
- import { resolveRoyaltyRule } from './resolveRoyaltyRule';
13
- import { resolveCustomTransferPolicyRules } from './resolveCustomTransferPolicyRules';
14
-
15
- export type Policy = {
16
- data: any;
17
- transferRequest: TransactionArgument;
18
- isCustom: boolean;
19
- type?: string;
20
- };
21
-
22
- type Props = {
23
- tx: Transaction;
24
- transferPolicies: any[];
25
- suiClient: SuiGrpcClient;
26
- walletAddress: string;
27
- kioskClient: KioskClient;
28
- kioskTx: any;
29
- nftType: string;
30
- kioskToLockRuleProve?: TransactionObjectInput;
31
- kioskItem?: TransactionObjectInput;
32
- transferRequest: TransactionArgument;
33
- customTransferPolicies?: any;
34
- price: string;
35
- shouldSkipKioskLocking?: boolean;
36
- shouldSkipResolvingRoyaltyRule?: boolean;
37
- coinToSplit?: any;
38
- beforeResolveKioskTransferRequest?: (transferRequest: any) => void | Promise<void>;
39
- transferPoliciesToResolve?: any[];
40
- royaltyFeeAmount?: bigint;
41
- };
42
-
43
- export const resolveTransferPolicies = async ({
44
- tx,
45
- transferPolicies,
46
- suiClient,
47
- walletAddress,
48
- kioskClient,
49
- kioskTx,
50
- nftType,
51
- kioskToLockRuleProve,
52
- kioskItem,
53
- transferRequest,
54
- customTransferPolicies,
55
- price,
56
- shouldSkipKioskLocking,
57
- shouldSkipResolvingRoyaltyRule,
58
- coinToSplit,
59
- beforeResolveKioskTransferRequest,
60
- transferPoliciesToResolve,
61
- royaltyFeeAmount,
62
- }: Props) => {
63
- const policies =
64
- transferPoliciesToResolve ??
65
- (await getTransferPoliciesToResolve({
66
- transferPolicies,
67
- suiClient,
68
- kioskClient,
69
- nftType,
70
- customTransferPolicies,
71
- }));
72
-
73
- let hasLockRule = false;
74
- for (const policy of policies) {
75
- for (const rule of policy.rules) {
76
- switch (rule.moduleName) {
77
- case 'kiosk_lock_rule':
78
- hasLockRule = true;
79
- resolveKioskLockRule({
80
- tx,
81
- packageId: rule.rulePackageId,
82
- policyId: policy.id,
83
- transferRequest,
84
- nftType: policy.isCustom && policy.type ? policy.type : nftType,
85
- kiosk: kioskToLockRuleProve ? kioskToLockRuleProve : kioskTx.kiosk,
86
- kioskCap: kioskTx.kioskCap,
87
- kioskItem,
88
- shouldSkipLocking: shouldSkipKioskLocking,
89
- });
90
- break;
91
- case 'personal_kiosk_rule':
92
- resolvePersonalKioskRule({
93
- tx,
94
- packageId: rule.rulePackageId,
95
- nftType: policy.isCustom && policy.type ? policy.type : nftType,
96
- kiosk: kioskTx.kiosk,
97
- transferRequest,
98
- });
99
- break;
100
- case 'royalty_rule':
101
- case 'kiosk_royalty_rule':
102
- if (shouldSkipResolvingRoyaltyRule) break;
103
- await resolveRoyaltyRule({
104
- tx,
105
- suiClient,
106
- walletAddress,
107
- packageId: rule.rulePackageId,
108
- moduleName: rule.moduleName,
109
- policyId: policy.id,
110
- transferRequest,
111
- nftType: policy.isCustom && policy.type ? policy.type : nftType,
112
- price,
113
- coinToSplit,
114
- royaltyFeeAmount,
115
- });
116
- break;
117
- case 'floor_price_rule':
118
- resolveFloorPriceRule({
119
- tx,
120
- packageId: rule.rulePackageId,
121
- nftType: policy.isCustom && policy.type ? policy.type : nftType,
122
- policyId: policy.id,
123
- transferRequest,
124
- });
125
- break;
126
- default: {
127
- const nftTypeForRule = policy.isCustom && policy.type ? policy.type : nftType;
128
- const wasResolved = resolveCustomTransferPolicyRules({
129
- tx,
130
- rules: [rule],
131
- transferRequest,
132
- nftType: nftTypeForRule,
133
- policyId: policy.id,
134
- });
135
- if (!wasResolved) {
136
- throw new Error(`No resolver for the following rule: ${rule.rule}.`);
137
- }
138
-
139
- break;
140
- }
141
- }
142
- }
143
- }
144
-
145
- if (!hasLockRule && kioskItem) {
146
- kioskTx.place({ itemType: nftType, item: kioskItem });
147
- }
148
-
149
- await beforeResolveKioskTransferRequest?.(transferRequest);
150
-
151
- for (const policy of policies) {
152
- tx.moveCall({
153
- target: '0x2::transfer_policy::confirm_request',
154
- arguments: [tx.object(policy.id), transferRequest],
155
- typeArguments: [policy.isCustom && policy.type ? policy.type : nftType],
156
- });
157
- }
158
- };
@@ -1,11 +0,0 @@
1
- import type { KioskTransaction } from '@mysten/kiosk';
2
-
3
- export type SharedKioskState = {
4
- kioskTx: KioskTransaction | undefined;
5
- ownerKiosks?: Array<{
6
- id: string;
7
- is_personal: boolean;
8
- is_origin_byte: boolean;
9
- is_shared: boolean;
10
- }>;
11
- };
@@ -1,50 +0,0 @@
1
- import { type KioskClient, type KioskTransaction, type TransferPolicy } from '@mysten/kiosk';
2
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
3
- import { type Transaction } from '@mysten/sui/transactions';
4
- import { getKioskIdFromKioskTx } from './getKioskIdFromKioskTx';
5
- import { takeLockedNftFromKiosk } from './takeLockedNftFromKiosk';
6
-
7
- export const takeAndBorrowNftFromKiosk = async ({
8
- tx,
9
- transferPolicies,
10
- kioskTx,
11
- kioskClient,
12
- nftTokenId,
13
- nftType,
14
- suiClient,
15
- kioskOwner,
16
- }: {
17
- tx: Transaction;
18
- transferPolicies: TransferPolicy[];
19
- kioskTx: KioskTransaction;
20
- kioskClient: KioskClient;
21
- nftTokenId: string;
22
- nftType: string;
23
- suiClient: SuiGrpcClient;
24
- kioskOwner: string;
25
- }) => {
26
- const kioskId = getKioskIdFromKioskTx({ kioskTx, tx });
27
- const res = await kioskClient.getKiosk({ id: kioskId });
28
- const nftInKiosk = res.items.find((i) => i.objectId === nftTokenId);
29
-
30
- let borrowedNft = null;
31
- if (nftInKiosk?.isLocked) {
32
- borrowedNft = await takeLockedNftFromKiosk({
33
- tx,
34
- transferPolicies,
35
- kioskTx,
36
- nftTokenId,
37
- nftType,
38
- suiClient,
39
- kioskClient,
40
- kioskOwner,
41
- });
42
- } else {
43
- borrowedNft = kioskTx.take({
44
- itemId: nftTokenId,
45
- itemType: nftType,
46
- }) as any;
47
- }
48
-
49
- return borrowedNft;
50
- };