@tradeport/sui-trading-sdk 0.5.2 → 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 (153) hide show
  1. package/dist/index.d.ts +194 -0
  2. package/dist/index.js +7419 -0
  3. package/dist/index.js.map +1 -0
  4. package/package.json +5 -1
  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 -803
  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,122 +0,0 @@
1
- import { normalizeSuiObjectId } from '@mysten/sui/utils';
2
- import {
3
- BLUEMOVE_OFFER_DATA_OBJECT,
4
- TOCEN_MARKETPLACE_OBJECT,
5
- TRADEPORT_BIDDING_STORE,
6
- TRADEPORT_KIOSK_BIDDING_STORE,
7
- TRADEPORT_MULTI_BID_PACKAGE,
8
- TRADEPORT_MULTI_BID_STORE,
9
- } from '../../constants';
10
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
11
- import { fetchMultibidChainIdById } from '../../graphql/queries/fetchMultibidById';
12
- import { isSingleBid } from '../../helpers/isSIngleBid';
13
- import { isTradePortKioskBid } from '../../helpers/kiosk/isTradePortKioskBid';
14
- import { isOriginByteBid } from '../../helpers/originByte/isOriginByteBid';
15
- import { getObjectType } from '../../helpers/rpc/getObjectType';
16
- import { type RemoveNftBidTx } from './removeNftBids';
17
- import { type Transaction } from '@mysten/sui/transactions';
18
-
19
- export function addTradeportRemoveNftBidTx({ tx, bidNonce, nftType }: RemoveNftBidTx) {
20
- tx.moveCall({
21
- target:
22
- '0xb42dbb7413b79394e1a0175af6ae22b69a5c7cc5df259cd78072b6818217c027::biddings::cancel_bid',
23
- arguments: [tx.object(TRADEPORT_BIDDING_STORE), tx.pure.address(bidNonce)],
24
- typeArguments: [nftType],
25
- });
26
- }
27
-
28
- export function addTradeportKioskRemoveNftBidTx({ tx, bidNonce, nftType }: RemoveNftBidTx) {
29
- tx.moveCall({
30
- target:
31
- '0x475e98e9c436ec118909f3b9e241d86bcbbc2cf9fba05e99a934823fefb375b7::kiosk_biddings::cancel_bid',
32
- arguments: [tx.object(TRADEPORT_KIOSK_BIDDING_STORE), tx.pure.address(bidNonce)],
33
- typeArguments: [nftType],
34
- });
35
- }
36
-
37
- export function addOriginByteRemoveNftBidTx({ tx, bidNonce }: RemoveNftBidTx) {
38
- tx.moveCall({
39
- target:
40
- '0x8534e4cdfd28709c94330a9783c3d5fe6f5daba0bffb69102ce303c5b38aed5a::bidding::close_bid',
41
- arguments: [tx.object(bidNonce)],
42
- typeArguments: ['0x2::sui::SUI'],
43
- });
44
- }
45
-
46
- export function addBluemoveRemoveNftBidTx({ tx, bidNonce, nftTokenId, nftType }: RemoveNftBidTx) {
47
- tx.moveCall({
48
- target:
49
- '0xd5dd28cc24009752905689b2ba2bf90bfc8de4549b9123f93519bb8ba9bf9981::offer_item::cancel_offer_nft',
50
- arguments: [
51
- tx.object(BLUEMOVE_OFFER_DATA_OBJECT),
52
- tx.pure.address(nftTokenId),
53
- tx.pure.u64(bidNonce),
54
- ],
55
- typeArguments: [nftType],
56
- });
57
- }
58
-
59
- export function addTocenRemoveNftBidTx({ tx, nftTokenId, bidAmount }: RemoveNftBidTx) {
60
- tx.moveCall({
61
- target:
62
- '0x3605d91c559e80cf8fdeabae9abaccb0bc38f96eac0b32bf47e95a9159a5277f::tocen_marketplace::cancel_offer',
63
- arguments: [
64
- tx.object(TOCEN_MARKETPLACE_OBJECT),
65
- tx.pure.address(nftTokenId),
66
- tx.pure.u64(bidAmount),
67
- ],
68
- typeArguments: [],
69
- });
70
- }
71
-
72
- export async function addSingleBidRemoveNftBidTx({ tx, bidNonce, multiBidId }: RemoveNftBidTx) {
73
- const multiBidChainId = multiBidId
74
- ? (
75
- await gqlChainRequest({
76
- chain: 'sui',
77
- query: fetchMultibidChainIdById,
78
- variables: { multiBidId },
79
- })
80
- )?.multi_bids?.[0]?.chain_id
81
- : undefined;
82
- addCancelSingleBidForMultibidChainId(tx, bidNonce, multiBidChainId);
83
- }
84
-
85
- export function addCancelSingleBidForMultibidChainId(
86
- tx: Transaction,
87
- bidNonce: string,
88
- multiBidChainId?: string,
89
- ) {
90
- tx.moveCall({
91
- target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::cancel_bid`,
92
- arguments: [
93
- tx.object(TRADEPORT_MULTI_BID_STORE),
94
- tx.pure.id(normalizeSuiObjectId(bidNonce)),
95
- tx.pure.option('id', multiBidChainId),
96
- ],
97
- });
98
- }
99
-
100
- export async function addTradePortRemoveNftBidTxHandler(txData: RemoveNftBidTx) {
101
- const bidType = await getObjectType({
102
- suiClient: txData?.suiClient,
103
- objectId: normalizeSuiObjectId(txData?.bidNonce),
104
- });
105
-
106
- if (isSingleBid(bidType)) {
107
- await addSingleBidRemoveNftBidTx(txData);
108
- return;
109
- }
110
-
111
- if (isOriginByteBid(bidType)) {
112
- addOriginByteRemoveNftBidTx(txData);
113
- return;
114
- }
115
-
116
- if (isTradePortKioskBid(bidType)) {
117
- addTradeportKioskRemoveNftBidTx(txData);
118
- return;
119
- }
120
-
121
- addTradeportRemoveNftBidTx(txData);
122
- }
@@ -1,116 +0,0 @@
1
- import type { SuiGrpcClient } from '@mysten/sui/grpc';
2
- import { Transaction } from '@mysten/sui/transactions';
3
- import { type RequestContext } from '../../SuiTradingClient';
4
- import {
5
- DELOREAN_TOKEN_IDS_TO_DISABLE,
6
- DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
7
- } from '../../constants';
8
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
9
- import { fetchBidsById } from '../../graphql/queries/fetchBidsById';
10
- import { getNftType } from '../../helpers/getNftType';
11
- import {
12
- addBluemoveRemoveNftBidTx,
13
- addOriginByteRemoveNftBidTx,
14
- addTocenRemoveNftBidTx,
15
- addTradePortRemoveNftBidTxHandler,
16
- } from './addRemoveNftBidTxs';
17
-
18
- export type RemoveNftBidTx = {
19
- tx: Transaction;
20
- suiClient: SuiGrpcClient;
21
- sharedObjects?: any;
22
- bidNonce: string;
23
- nftType: string;
24
- nftTokenId: string;
25
- bidAmount: number;
26
- sellerKiosk: string;
27
- bidMarketName: string;
28
- multiBidId?: string;
29
- };
30
-
31
- export type RemoveNftBid = {
32
- bidId: string;
33
- };
34
-
35
- export type RemoveNftBids = {
36
- bidIds: string[];
37
- tx?: Transaction | string;
38
- };
39
-
40
- export const removeNftBids = async (
41
- { bidIds, tx: existingTx }: RemoveNftBids,
42
- context: RequestContext,
43
- ): Promise<Transaction> => {
44
- const res = await gqlChainRequest({
45
- chain: 'sui',
46
- query: fetchBidsById,
47
- variables: { bidIds },
48
- });
49
-
50
- if (res?.bids?.length === 0) {
51
- throw new Error('No bids found');
52
- }
53
-
54
- const bidsForTracking = [];
55
- const tx = existingTx ? Transaction.from(existingTx) : new Transaction();
56
-
57
- for (const bid of res.bids) {
58
- if (DELOREAN_TOKEN_IDS_TO_DISABLE?.includes(bid?.nft?.token_id)) {
59
- throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
60
- }
61
-
62
- const nftType = getNftType({
63
- collectionId: bid?.collection?.id,
64
- collectionChainState: bid?.collection?.chain_state,
65
- nft: bid?.nft,
66
- });
67
-
68
- const txData: RemoveNftBidTx = {
69
- tx,
70
- suiClient: context.suiClient,
71
- bidNonce: bid?.nonce,
72
- nftType,
73
- nftTokenId: bid?.nft?.token_id,
74
- bidAmount: bid?.price,
75
- sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
76
- bidMarketName: bid?.market_contract?.name,
77
- multiBidId: bid?.multi_bid_id,
78
- };
79
-
80
- switch (txData.bidMarketName) {
81
- case 'tradeport':
82
- await addTradePortRemoveNftBidTxHandler(txData);
83
- break;
84
- case 'clutchy':
85
- addOriginByteRemoveNftBidTx(txData);
86
- break;
87
- case 'bluemove':
88
- addBluemoveRemoveNftBidTx(txData);
89
- break;
90
- case 'tocen':
91
- addTocenRemoveNftBidTx(txData);
92
- break;
93
- default:
94
- throw new Error('Marketplace not supported');
95
- }
96
-
97
- bidsForTracking.push({
98
- nftType,
99
- collectionId: bid?.nft?.collection_id,
100
- bidAmount: bid?.price,
101
- bidMarketName: bid?.market_contract?.name,
102
- bidder: bid?.bidder,
103
- });
104
- }
105
-
106
- // if (process.env.ENABLE_SEGMENT_TRACKING === 'true' && bidsForTracking.length > 0) {
107
- // trackMethodCall({
108
- // apiUser: context.apiUser,
109
- // apiKey: context.apiKey,
110
- // event: 'REMOVE_NFT_BIDS',
111
- // items: bidsForTracking,
112
- // });
113
- // }
114
-
115
- return Transaction.from(tx);
116
- };
@@ -1,40 +0,0 @@
1
- import { coinWithBalance, type Transaction } from '@mysten/sui/transactions';
2
- import BigNumber from '../../bigNumberConfig';
3
- import {
4
- TRADEPORT_LISTINGS_PACKAGE,
5
- TRADEPORT_LISTINGS_STORE,
6
- USDC_COIN_TYPE,
7
- } from '../../constants';
8
- import { type SponsorNftListingOptions } from './sponsorNftListing';
9
-
10
- export const addSponsorListingTx = async ({
11
- tx,
12
- nftTokenId,
13
- nftType,
14
- sponsorOptions,
15
- }: {
16
- tx: Transaction;
17
- nftTokenId: string;
18
- nftType: string;
19
- sponsorOptions: SponsorNftListingOptions;
20
- }) => {
21
- const totalFee = new BigNumber(sponsorOptions?.usdcFeeAmountPerPeriod)
22
- ?.times(sponsorOptions?.numOfPeriods)
23
- .toString();
24
-
25
- const sponsorCoin = sponsorOptions.coinToSplit
26
- ? tx.splitCoins(sponsorOptions.coinToSplit, [tx.pure.u64(totalFee)])[0]
27
- : coinWithBalance({ type: USDC_COIN_TYPE, balance: BigInt(totalFee) });
28
-
29
- tx.moveCall({
30
- target: `${TRADEPORT_LISTINGS_PACKAGE}::tradeport_listings::add_sponsored_listing`,
31
- arguments: [
32
- tx.object(TRADEPORT_LISTINGS_STORE),
33
- tx.object.clock(),
34
- tx.pure.id(nftTokenId),
35
- tx.pure.u64(sponsorOptions?.numOfPeriods),
36
- tx.object(sponsorCoin),
37
- ],
38
- typeArguments: [nftType],
39
- });
40
- };
@@ -1,60 +0,0 @@
1
- import { Transaction } from '@mysten/sui/transactions';
2
- import { gqlChainRequest } from '../../graphql/gqlChainRequest';
3
- import { fetchNftCollectionChainState } from '../../graphql/queries/fetchNftCollectionChainState';
4
- import { getNftType } from '../../helpers/getNftType';
5
- import { isOriginByteCollection } from '../../helpers/originByte/isOriginByteCollection';
6
- import { addSponsorListingTx } from './addSponsorNftListingTx';
7
-
8
- export type SponsorNftListingOptions = {
9
- shouldSponsor?: boolean;
10
- numOfPeriods?: number;
11
- usdcFeeAmountPerPeriod?: number;
12
- coinToSplit?: any;
13
- };
14
-
15
- export type SponsorNftListing = {
16
- tx?: Transaction;
17
- nftTokenId: string;
18
- options: SponsorNftListingOptions;
19
- };
20
-
21
- export const sponsorNftListing = async ({
22
- tx: existingTx,
23
- nftTokenId,
24
- options,
25
- }: SponsorNftListing): Promise<Transaction> => {
26
- const res = await gqlChainRequest({
27
- chain: 'sui',
28
- query: fetchNftCollectionChainState,
29
- variables: { nftTokenId },
30
- });
31
-
32
- if (res?.nfts?.length === 0) {
33
- throw new Error(`No nft found with token id ${nftTokenId}`);
34
- }
35
-
36
- const nft = res?.nfts?.[0];
37
-
38
- const nftType = getNftType({
39
- collectionId: nft?.collection?.id,
40
- collectionChainState: nft?.collection?.chain_state,
41
- nft,
42
- });
43
-
44
- const transferPolicies = nft?.collection?.chain_state?.transfer_policies;
45
-
46
- if (isOriginByteCollection(transferPolicies)) {
47
- throw new Error(`You cannot sponsor an Origin Byte NFT. Nft Token Id: ${nftTokenId}`);
48
- }
49
-
50
- const tx = existingTx ?? new Transaction();
51
-
52
- await addSponsorListingTx({
53
- tx,
54
- nftTokenId,
55
- nftType,
56
- sponsorOptions: options,
57
- });
58
-
59
- return tx;
60
- };
@@ -1,220 +0,0 @@
1
- import { type KioskClient } from '@mysten/kiosk';
2
- import { type SuiGrpcClient } from '@mysten/sui/grpc';
3
- import { type Transaction } from '@mysten/sui/transactions';
4
- import {
5
- MYSTEN_TRANSFER_POLICY_RULES_PACKAGE_ID,
6
- MYSTEN_TRANSFER_POLICY_RULES_PACKAGE_ID_V2,
7
- TRADEPORT_KIOSK_TRANSFERS_STORE,
8
- } from '../../constants';
9
- import { destroyZeroCoin } from '../../helpers/destroyZeroCoin';
10
- import { getNftType } from '../../helpers/getNftType';
11
- import { getTransferPolicyRuleNamesFromSuiObject } from '../../helpers/getTransferPolicyRuleNamesFromSuiObject';
12
- import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
13
- import { getNativeKioskTransferPolicies } from '../../helpers/kiosk/getNativeKioskTransferPolicies';
14
- import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
15
- import { type SharedKioskState } from '../../helpers/kiosk/sharedKioskState.type';
16
- import { getOBKiosk } from '../../helpers/originByte/getOBKiosk';
17
- import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
18
- import { type TransferNftTx } from './transferNfts';
19
-
20
- type CollectionChainState = {
21
- transfer_policies: TransferPolicy[];
22
- };
23
- type TransferPolicy = {
24
- id: string;
25
- rules: Array<{ type: string; min_amount?: string }>;
26
- is_origin_byte: boolean;
27
- is_disabled: boolean;
28
- };
29
-
30
- export async function addOriginByteTransferNftTx({
31
- tx,
32
- nftTokenId,
33
- nftType,
34
- recipientAddress,
35
- senderKiosk,
36
- senderAddress,
37
- sharedKioskState,
38
- }: TransferNftTx) {
39
- await assertNftInSharedKiosk({
40
- kioskId: senderKiosk,
41
- walletAddress: senderAddress,
42
- sharedKioskState,
43
- });
44
-
45
- const recipientOBKiosk = await getOBKiosk({ wallet: recipientAddress, sharedKioskState });
46
-
47
- if (recipientOBKiosk) {
48
- tx.moveCall({
49
- target:
50
- '0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::p2p_transfer',
51
- arguments: [tx.object(senderKiosk), tx.object(recipientOBKiosk), tx.pure.address(nftTokenId)],
52
- typeArguments: [nftType],
53
- });
54
- } else {
55
- tx.moveCall({
56
- target:
57
- '0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::p2p_transfer_and_create_target_kiosk',
58
- arguments: [
59
- tx.object(senderKiosk),
60
- tx.pure.address(addLeadingZerosAfter0x(recipientAddress)),
61
- tx.pure.address(nftTokenId),
62
- ],
63
- typeArguments: [nftType],
64
- });
65
- }
66
- }
67
-
68
- export async function addTradeportKioskTransferTx({
69
- tx,
70
- kioskTx,
71
- nftTokenId,
72
- nftType,
73
- recipientAddress,
74
- transferPolicy,
75
- transferPolicies,
76
- }: TransferNftTx) {
77
- const existingTransferPolicy =
78
- transferPolicy ?? getNativeKioskTransferPolicies(transferPolicies)?.at(0);
79
- const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
80
- (rule: any) => rule.type === 'floor_price_rule',
81
- );
82
- if (hasFloorPriceRule) {
83
- throw new Error('Cannot transfer NFT with a minimum floor price rule');
84
- }
85
-
86
- tx.moveCall({
87
- target:
88
- '0x49642273ca7db3d942f9fd810c93467974c40e73ea7f03e8e7a632f1222aca73::kiosk_transfers::transfer_with_purchase_capability',
89
- arguments: [
90
- tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
91
- tx.object(kioskTx.kiosk),
92
- tx.object(kioskTx.kioskCap),
93
- tx.pure.address(nftTokenId),
94
- tx.pure.address(addLeadingZerosAfter0x(recipientAddress)),
95
- ],
96
- typeArguments: [nftType],
97
- });
98
- }
99
-
100
- export async function addTradeportKioskDirectTransferTx(
101
- txData: {
102
- tx: Transaction;
103
- recipientAddress: string;
104
- kioskClient: KioskClient;
105
- senderAddress: string;
106
- sharedKioskState?: SharedKioskState;
107
- },
108
- nfts: any[],
109
- suiClient: SuiGrpcClient,
110
- ) {
111
- const { tx, recipientAddress, kioskClient, sharedKioskState, senderAddress } = txData;
112
- if (nfts.length === 0) {
113
- return;
114
- }
115
-
116
- const transferPolicies = new Map<string, TransferPolicy>(
117
- await Promise.all(
118
- nfts.map(
119
- async (nft): Promise<[string, TransferPolicy]> => [
120
- nft.id as string,
121
- await getTransferPolicyForDirectTransfer(suiClient, nft.collection.chain_state),
122
- ],
123
- ),
124
- ),
125
- );
126
- const royaltyAmounts = [...transferPolicies.values()].map((transferPolicy) =>
127
- BigInt(transferPolicy?.rules.find((rule) => rule.type === 'royalty_rule')?.min_amount ?? 0n),
128
- );
129
-
130
- const totalRoyaltyAmount = royaltyAmounts.reduce((sum: bigint, amount) => sum + amount, 0n);
131
- // When no royalty is due, avoid touching the gas coin: sponsored transactions
132
- // (e.g. Enoki) reject any PTB that uses GasCoin as an argument.
133
- const [royaltyCoin] =
134
- totalRoyaltyAmount === 0n
135
- ? tx.moveCall({
136
- target: '0x2::coin::zero',
137
- arguments: [],
138
- typeArguments: ['0x2::sui::SUI'],
139
- })
140
- : tx.splitCoins(tx.gas, [tx.pure.u64(totalRoyaltyAmount)]);
141
- for (const nft of nfts) {
142
- const nftType = getNftType({
143
- collectionId: nft?.collection?.id,
144
- collectionChainState: nft?.collection?.chain_state,
145
- nft,
146
- });
147
-
148
- await kioskTxWrapper({
149
- tx,
150
- kioskClient,
151
- kioskOwner: senderAddress,
152
- kiosk: nft?.chain_state?.kiosk_id,
153
- sharedKioskState,
154
- shouldUseSharedKioskTx: false,
155
- async runCommands(kioskTx) {
156
- tx.moveCall({
157
- target:
158
- '0x4acc0efedd243eb61ab8f8a3e9c24b09a1838c43d16029e8c8985004dfd67239::kiosk_transfers::direct_transfer_to_receiver',
159
- arguments: [
160
- tx.object(kioskTx.getKiosk() as any),
161
- tx.object(kioskTx.getKioskCap() as any),
162
- tx.pure.address(recipientAddress),
163
- tx.pure.id(nft.token_id),
164
- tx.object(transferPolicies.get(nft.id).id),
165
- royaltyCoin,
166
- ],
167
- typeArguments: [nftType],
168
- });
169
- },
170
- });
171
- }
172
-
173
- destroyZeroCoin({ tx, coin: royaltyCoin });
174
- }
175
-
176
- export async function canBeTransferedDirectly(
177
- suiClient: SuiGrpcClient,
178
- collectionChainState?: CollectionChainState,
179
- ) {
180
- return (
181
- (await getTransferPolicyForDirectTransfer(suiClient, collectionChainState, true)) !== undefined
182
- );
183
- }
184
-
185
- export async function getTransferPolicyForDirectTransfer(
186
- suiClient: SuiGrpcClient,
187
- collectionChainState?: CollectionChainState,
188
- validateRules = false,
189
- ): Promise<TransferPolicy | undefined> {
190
- const candidatePolicy = collectionChainState?.transfer_policies?.find(
191
- (policy) =>
192
- !policy.is_origin_byte &&
193
- !policy.is_disabled &&
194
- policy.rules.length > 0 &&
195
- policy.rules?.filter(
196
- (rule) =>
197
- rule.type !== 'kiosk_lock_rule' &&
198
- rule.type !== 'royalty_rule' &&
199
- rule.type !== 'personal_kiosk_rule',
200
- ).length === 0,
201
- );
202
-
203
- if (validateRules && candidatePolicy) {
204
- const ruleNames = await getTransferPolicyRuleNamesFromSuiObject({
205
- suiClient,
206
- transferPolicyId: candidatePolicy.id,
207
- });
208
- if (
209
- !ruleNames.every(
210
- (name) =>
211
- name.startsWith(MYSTEN_TRANSFER_POLICY_RULES_PACKAGE_ID) ||
212
- name.startsWith(MYSTEN_TRANSFER_POLICY_RULES_PACKAGE_ID_V2),
213
- )
214
- ) {
215
- return undefined;
216
- }
217
- }
218
-
219
- return candidatePolicy;
220
- }