@tradeport/sui-trading-sdk 0.5.3 → 0.5.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.
Files changed (153) hide show
  1. package/.babel.config.js +3 -0
  2. package/.claude/settings.json +5 -0
  3. package/.claude/settings.local.json +5 -0
  4. package/.env.demo +5 -0
  5. package/.eslintrc.json +46 -0
  6. package/.prettierignore +4 -0
  7. package/.prettierrc.json +7 -0
  8. package/.vscode/launch.json +23 -0
  9. package/CHANGELOG.md +746 -0
  10. package/jest.config.js +12 -0
  11. package/package.json +66 -71
  12. package/src/SuiTradingClient.ts +442 -0
  13. package/src/apiClients/createKioskClient.ts +10 -0
  14. package/src/apiClients/createSuiClient.ts +5 -0
  15. package/src/apiClients/graphqlClient.ts +17 -0
  16. package/src/bigNumberConfig.ts +10 -0
  17. package/src/constants.ts +1052 -0
  18. package/src/graphql/createChainGQLQuery.ts +27 -0
  19. package/src/graphql/gqlChainRequest.ts +21 -0
  20. package/src/graphql/queries/fetchAccountKiosks.ts +12 -0
  21. package/src/graphql/queries/fetchActiveLockStateByNftId.ts +15 -0
  22. package/src/graphql/queries/fetchBidsById.ts +36 -0
  23. package/src/graphql/queries/fetchCollectionBidById.ts +21 -0
  24. package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +29 -0
  25. package/src/graphql/queries/fetchCollectionChainState.ts +17 -0
  26. package/src/graphql/queries/fetchCollectionFloorListingForMarket.ts +28 -0
  27. package/src/graphql/queries/fetchCollectionFloorListings.ts +15 -0
  28. package/src/graphql/queries/fetchCollectionsById.ts +39 -0
  29. package/src/graphql/queries/fetchCommissionByListingId.ts +13 -0
  30. package/src/graphql/queries/fetchCryptoToUsdRate.ts +13 -0
  31. package/src/graphql/queries/fetchKiosksByOwner.ts +14 -0
  32. package/src/graphql/queries/fetchListingsById.ts +29 -0
  33. package/src/graphql/queries/fetchListingsByNftId.ts +23 -0
  34. package/src/graphql/queries/fetchLockById.ts +23 -0
  35. package/src/graphql/queries/fetchMultibidById.ts +34 -0
  36. package/src/graphql/queries/fetchNftCollectionChainState.ts +12 -0
  37. package/src/graphql/queries/fetchNftsById.ts +75 -0
  38. package/src/graphql/queries/fetchNftsByKioskId.ts +45 -0
  39. package/src/graphql/queries/fetchOwnerCapByKiosk.ts +10 -0
  40. package/src/graphql/queries/fetchPersonalCapByKiosk.ts +10 -0
  41. package/src/graphql/queries/fetchSharedObjectsByType.ts +12 -0
  42. package/src/graphql/queries/fetchTransferPoliciesByType.ts +12 -0
  43. package/src/graphql/queries/fetchWalletKiosks.ts +14 -0
  44. package/src/graphql/queries/getCommissionByListingId.ts +15 -0
  45. package/src/helpers/addOneDollarFee.ts +17 -0
  46. package/src/helpers/addThirdPartyTxFee.ts +17 -0
  47. package/src/helpers/calculatePremium.ts +9 -0
  48. package/src/helpers/calculateRoyaltyFee.ts +28 -0
  49. package/src/helpers/destroyZeroCoin.ts +14 -0
  50. package/src/helpers/getActiveLockStateByNftId.ts +15 -0
  51. package/src/helpers/getCollectionChainState.ts +31 -0
  52. package/src/helpers/getCollectionFloorPrice.ts +12 -0
  53. package/src/helpers/getLockById.ts +29 -0
  54. package/src/helpers/getMarketFeePrice.ts +82 -0
  55. package/src/helpers/getNftType.ts +38 -0
  56. package/src/helpers/getRoyaltyRuleModule.ts +7 -0
  57. package/src/helpers/getSharedObjects.ts +119 -0
  58. package/src/helpers/getSuiToUsdRate.ts +14 -0
  59. package/src/helpers/getTradeportBiddingContractBidAmount.ts +31 -0
  60. package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +24 -0
  61. package/src/helpers/hasPersonalKioskRule.ts +7 -0
  62. package/src/helpers/hasRoyaltyRule.ts +7 -0
  63. package/src/helpers/hasTransferPolicyRules.ts +6 -0
  64. package/src/helpers/isExpiredListing.ts +9 -0
  65. package/src/helpers/isNonKioskListing.ts +14 -0
  66. package/src/helpers/isSIngleBid.ts +13 -0
  67. package/src/helpers/kiosk/assertNftInSharedKiosk.ts +31 -0
  68. package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +71 -0
  69. package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +29 -0
  70. package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +59 -0
  71. package/src/helpers/kiosk/getNativeKioskTransferPolicies.ts +29 -0
  72. package/src/helpers/kiosk/getNativeKioskTransferPoliciesByNftType.ts +21 -0
  73. package/src/helpers/kiosk/getRulePackageId.ts +59 -0
  74. package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +154 -0
  75. package/src/helpers/kiosk/isBluemoveKioskBid.ts +1 -0
  76. package/src/helpers/kiosk/isTradePortKioskBid.ts +4 -0
  77. package/src/helpers/kiosk/kioskListingBcs.ts +19 -0
  78. package/src/helpers/kiosk/kioskTxWrapper.ts +152 -0
  79. package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +100 -0
  80. package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +171 -0
  81. package/src/helpers/kiosk/resolveCustomTransferPolicyRules.ts +75 -0
  82. package/src/helpers/kiosk/resolveFloorPriceRule.ts +21 -0
  83. package/src/helpers/kiosk/resolveKioskLockRule.ts +47 -0
  84. package/src/helpers/kiosk/resolvePersonalKioskRule.ts +23 -0
  85. package/src/helpers/kiosk/resolveRoyaltyRule.ts +57 -0
  86. package/src/helpers/kiosk/resolveTableAllowlistRule.ts +34 -0
  87. package/src/helpers/kiosk/resolveTransferPolicies.ts +158 -0
  88. package/src/helpers/kiosk/sharedKioskState.type.ts +11 -0
  89. package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +50 -0
  90. package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +73 -0
  91. package/src/helpers/kiosk/upgradeKioskRulesPackageId.ts +17 -0
  92. package/src/helpers/originByte/confirmOBTranfer.ts +33 -0
  93. package/src/helpers/originByte/createOBKiosk.ts +14 -0
  94. package/src/helpers/originByte/depositNftIntoOBKiosk.ts +16 -0
  95. package/src/helpers/originByte/getOBBidderKiosk.ts +12 -0
  96. package/src/helpers/originByte/getOBKiosk.ts +24 -0
  97. package/src/helpers/originByte/getOrCreateOBKiosk.ts +42 -0
  98. package/src/helpers/originByte/isOBKiosk.ts +13 -0
  99. package/src/helpers/originByte/isOriginByteBid.ts +30 -0
  100. package/src/helpers/originByte/isOriginByteCollection.ts +11 -0
  101. package/src/helpers/originByte/shareOriginByteKiosk.ts +14 -0
  102. package/src/helpers/rpc/getAcountBalance.ts +18 -0
  103. package/src/helpers/rpc/getObjectType.ts +25 -0
  104. package/src/helpers/splitCoins.ts +12 -0
  105. package/src/helpers/track.ts +20 -0
  106. package/src/helpers/validateMinFloorPrice.ts +22 -0
  107. package/src/index.ts +2 -0
  108. package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +189 -0
  109. package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +398 -0
  110. package/src/methods/acceptNftBids/acceptNftBids.ts +174 -0
  111. package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +438 -0
  112. package/src/methods/applyFtStrategy/applyFtStrategy.ts +55 -0
  113. package/src/methods/applyNftStrategy/applyNftStrategy.ts +90 -0
  114. package/src/methods/buyListings/addBuyListingTxs.ts +806 -0
  115. package/src/methods/buyListings/buyListings.ts +230 -0
  116. package/src/methods/cancelMultiBid/cancelMultiBid.ts +51 -0
  117. package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +20 -0
  118. package/src/methods/cancelNftTransfers/cancelNftTransfers.ts +118 -0
  119. package/src/methods/claimNfts/addClaimNftsTxs.ts +247 -0
  120. package/src/methods/claimNfts/claimNfts.ts +270 -0
  121. package/src/methods/createMultiBid/createMultiBid.ts +36 -0
  122. package/src/methods/listNfts/addListTxs.ts +210 -0
  123. package/src/methods/listNfts/addRelistTxs.ts +87 -0
  124. package/src/methods/listNfts/listNfts.ts +152 -0
  125. package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +226 -0
  126. package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +149 -0
  127. package/src/methods/placeCollectionBids/placeCollectionBids.ts +153 -0
  128. package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +154 -0
  129. package/src/methods/placeNftBids/placeNftBids.ts +111 -0
  130. package/src/methods/relistNft/relistNft.ts +153 -0
  131. package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +132 -0
  132. package/src/methods/removeCollectionBids/removeCollectionBids.ts +117 -0
  133. package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +122 -0
  134. package/src/methods/removeNftBids/removeNftBids.ts +116 -0
  135. package/src/methods/sponsorNftListing/addSponsorNftListingTx.ts +40 -0
  136. package/src/methods/sponsorNftListing/sponsorNftListing.ts +60 -0
  137. package/src/methods/transferNfts/addTransferNftTx.ts +220 -0
  138. package/src/methods/transferNfts/transferNfts.ts +216 -0
  139. package/src/methods/unlistListings/addUnlistListingTxs.ts +399 -0
  140. package/src/methods/unlistListings/unlistListings.ts +158 -0
  141. package/src/methods/updateMultiBid/updateMultiBid.ts +66 -0
  142. package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +100 -0
  143. package/src/tests/SuiWallet.ts +83 -0
  144. package/src/utils/addHexPrefix.ts +7 -0
  145. package/src/utils/addLeadingZerosAfter0x.ts +9 -0
  146. package/src/utils/normalizeNftType.ts +7 -0
  147. package/src/utils/printTxBlockTxs.ts +11 -0
  148. package/src/utils/pureValues.ts +13 -0
  149. package/src/utils/toUint8Array.ts +12 -0
  150. package/tsconfig.json +16 -0
  151. package/dist/index.d.ts +0 -194
  152. package/dist/index.js +0 -7419
  153. package/dist/index.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ type ChainQuery = {
4
+ chain: string;
5
+ query: string;
6
+ };
7
+
8
+ export function createChainGQLQuery({ chain, query }: ChainQuery) {
9
+ const regex = /query\s+(\w+)\s*\(([\s\S]*?)\)\s*((?:@\w+(?:\([^)]*\))?\s*)*){([\s\S]*)}/;
10
+ const matches = regex.exec(query);
11
+
12
+ if (!matches || matches.length !== 5) {
13
+ throw new Error('Invalid query string format');
14
+ }
15
+
16
+ const [, queryName, argsString, directivesString, bodyString] = matches;
17
+
18
+ if (!argsString || !bodyString) return '';
19
+
20
+ const args = argsString.trim().length ? `(${argsString.trim()})` : '';
21
+ const directives = directivesString.trim();
22
+ const directivesPart = directives.length ? ` ${directives}` : '';
23
+ const body = bodyString.trim();
24
+ const wrappedBody = `${chain} {\n${body}\n}`;
25
+
26
+ return gql`query ${queryName}${args}${directivesPart} {\n${wrappedBody}\n}`;
27
+ }
@@ -0,0 +1,21 @@
1
+ import { getGraphqlClient } from '../apiClients/graphqlClient';
2
+ import { createChainGQLQuery } from './createChainGQLQuery';
3
+
4
+ type Args = {
5
+ chain: string;
6
+ query: string;
7
+ variables?: any;
8
+ };
9
+
10
+ export const gqlChainRequest = async ({ chain, query, variables }: Args) => {
11
+ if (!chain || !query) {
12
+ throw new Error('Missing required arguments');
13
+ }
14
+
15
+ const response = await getGraphqlClient().request<any>(
16
+ createChainGQLQuery({ chain, query }),
17
+ variables,
18
+ );
19
+
20
+ return response?.[chain];
21
+ };
@@ -0,0 +1,12 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchAccountKiosks = gql`
4
+ query fetchAccountKiosks($accountAddress: String!) {
5
+ kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
6
+ id
7
+ is_origin_byte
8
+ owner_address
9
+ profits
10
+ }
11
+ }
12
+ `;
@@ -0,0 +1,15 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchActiveLockStateByNftId = gql`
4
+ query fetchActiveLockStateByNftId($nftId: uuid!) {
5
+ locks(
6
+ where: {
7
+ state: { _nin: ["exercised", "canceled", "confirmed"] }
8
+ nft_meta_id: { _eq: $nftId }
9
+ }
10
+ ) {
11
+ id
12
+ state
13
+ }
14
+ }
15
+ `;
@@ -0,0 +1,36 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchBidsById = gql`
4
+ query fetchBidsById($bidIds: [uuid!]) {
5
+ bids(where: { id: { _in: $bidIds } }) {
6
+ nonce
7
+ price
8
+ status
9
+ type
10
+ receiver
11
+ bidder
12
+ multi_bid_id
13
+ nft {
14
+ token_id
15
+ properties
16
+ chain_state
17
+ collection_id
18
+ owner
19
+ contract {
20
+ properties
21
+ }
22
+ listings(where: { listed: { _eq: true } }) {
23
+ price
24
+ market_name
25
+ }
26
+ }
27
+ market_contract {
28
+ name
29
+ }
30
+ collection {
31
+ id
32
+ chain_state
33
+ }
34
+ }
35
+ }
36
+ `;
@@ -0,0 +1,21 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionBidsById = gql`
4
+ query fetchCollectionBidsById($bidIds: [uuid!]) {
5
+ bids(where: { id: { _in: $bidIds } }) {
6
+ nonce
7
+ price
8
+ bidder
9
+ status
10
+ type
11
+ collection_id
12
+ multi_bid_id
13
+ contract {
14
+ properties
15
+ }
16
+ market_contract {
17
+ name
18
+ }
19
+ }
20
+ }
21
+ `;
@@ -0,0 +1,29 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionBidsAtSamePrice = gql`
4
+ query fetchCollectionBidsAtSamePrice($collectionId: uuid!, $price: numeric) {
5
+ bids(
6
+ where: {
7
+ collection_id: { _eq: $collectionId }
8
+ price: { _eq: $price }
9
+ status: { _eq: "active" }
10
+ type: { _eq: "collection" }
11
+ }
12
+ order_by: { price: desc }
13
+ ) {
14
+ nonce
15
+ price
16
+ bidder
17
+ status
18
+ type
19
+ collection_id
20
+ multi_bid_id
21
+ contract {
22
+ properties
23
+ }
24
+ market_contract {
25
+ name
26
+ }
27
+ }
28
+ }
29
+ `;
@@ -0,0 +1,17 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionChainState = gql`
4
+ query fetchCollectionChainState($collectionId: uuid!) @cached(ttl: 10) {
5
+ collections(where: { id: { _eq: $collectionId } }) {
6
+ chain_state
7
+ }
8
+ }
9
+ `;
10
+
11
+ export const fetchCollectionChainStateByFtType = gql`
12
+ query fetchCollectionChainStateByFtType($ftType: String!) @cached(ttl: 10) {
13
+ collections_by_ft_type(args: { coin_type: $ftType }, limit: 1) {
14
+ chain_state
15
+ }
16
+ }
17
+ `;
@@ -0,0 +1,28 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionFloorListingsForMarket = gql`
4
+ query fetchCollectionFloorListingsForMarket(
5
+ $collectionId: uuid!
6
+ $marketAddress: String!
7
+ $totalPrice: numeric
8
+ ) {
9
+ listings(
10
+ where: {
11
+ collection_id: { _eq: $collectionId }
12
+ listed: { _eq: true }
13
+ market_name: { _eq: "tradeport" }
14
+ seller: { _neq: $marketAddress }
15
+ nonce: { _like: "1::0x%" }
16
+ price: { _lte: $totalPrice }
17
+ }
18
+ order_by: [{ price: asc_nulls_last }, { block_height: asc }, { tx_index: asc }]
19
+ ) {
20
+ id
21
+ price
22
+ nft {
23
+ token_id
24
+ delegated_owner
25
+ }
26
+ }
27
+ }
28
+ `;
@@ -0,0 +1,15 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionFloorListings = gql`
4
+ query fetchCollectionFloorListings($collectionId: uuid!) {
5
+ listings(
6
+ where: { collection_id: { _eq: $collectionId }, listed: { _eq: true }, nft: {} }
7
+ order_by: { price: asc_nulls_last, market_name: desc_nulls_last }
8
+ limit: 3
9
+ ) {
10
+ id
11
+ price
12
+ market_name
13
+ }
14
+ }
15
+ `;
@@ -0,0 +1,39 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCollectionsById = gql`
4
+ query fetchCollectionsById($collectionIds: [uuid!]) {
5
+ collections(where: { id: { _in: $collectionIds } }) {
6
+ id
7
+ contract {
8
+ properties
9
+ }
10
+ }
11
+ }
12
+ `;
13
+
14
+ export const fetchCollectionsByIdWithOneNft = gql`
15
+ query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
16
+ collections(where: { id: { _in: $collectionIds } }) {
17
+ id
18
+ chain_state
19
+ contract {
20
+ properties
21
+ }
22
+ nfts(limit: 1) {
23
+ id
24
+ properties
25
+ contract {
26
+ properties
27
+ }
28
+ }
29
+ }
30
+ }
31
+ `;
32
+
33
+ export const fetchCollectionsBySlug = gql`
34
+ query fetchCollectionsBySlug($slug: String!) {
35
+ collections(where: { slug: { _eq: $slug } }) {
36
+ id
37
+ }
38
+ }
39
+ `;
@@ -0,0 +1,13 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCommissionByNftContractId = gql`
4
+ query fetchCommissionByNftContractId($nftContractId: uuid!) {
5
+ commissions(where: { contract_id: { _eq: $nftContractId } }) {
6
+ is_custodial
7
+ key
8
+ market_fee
9
+ market_name
10
+ royalty
11
+ }
12
+ }
13
+ `;
@@ -0,0 +1,13 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchCryptoToUsdRate = gql`
4
+ query fetchCryptoToUsdRate($crypto: String!) {
5
+ crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
6
+ crypto
7
+ fiat
8
+ id
9
+ rate
10
+ timestamp
11
+ }
12
+ }
13
+ `;
@@ -0,0 +1,14 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchKiosksByOwner = gql`
4
+ query fetchKiosksByOwner($ownerAddress: String!) {
5
+ kiosks: kiosks_by_owner_address(owner_address: $ownerAddress) {
6
+ id
7
+ is_origin_byte
8
+ is_personal
9
+ owner_address
10
+ profits
11
+ is_shared
12
+ }
13
+ }
14
+ `;
@@ -0,0 +1,29 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchListingsById = gql`
4
+ query fetchListingsById($listingIds: [uuid!]) {
5
+ listings(where: { id: { _in: $listingIds } }) {
6
+ id
7
+ seller
8
+ listed
9
+ market_name
10
+ price
11
+ nonce
12
+ nft {
13
+ id
14
+ token_id
15
+ collection_id
16
+ contract_id
17
+ properties
18
+ chain_state
19
+ contract {
20
+ properties
21
+ }
22
+ }
23
+ collection {
24
+ id
25
+ chain_state
26
+ }
27
+ }
28
+ }
29
+ `;
@@ -0,0 +1,23 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchListingsByNftId = gql`
4
+ query fetchListingsByNftId($nftIds: [uuid!]) {
5
+ listings(where: { nft_id: { _in: $nftIds }, listed: { _eq: true } }) {
6
+ listed
7
+ market_name
8
+ price
9
+ nonce
10
+ nft {
11
+ id
12
+ token_id
13
+ collection_id
14
+ contract_id
15
+ properties
16
+ chain_state
17
+ contract {
18
+ properties
19
+ }
20
+ }
21
+ }
22
+ }
23
+ `;
@@ -0,0 +1,23 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchLockById = gql`
4
+ query fetchLockById($lockId: uuid!) {
5
+ locks(where: { id: { _eq: $lockId } }) {
6
+ id
7
+ type
8
+ state
9
+ collection_id
10
+ lock_id
11
+ nft_type
12
+ maker_price
13
+ maker
14
+ chain_state
15
+ collection_id
16
+ expire_in
17
+ nft {
18
+ id
19
+ token_id
20
+ }
21
+ }
22
+ }
23
+ `;
@@ -0,0 +1,34 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchMultibidChainIdById = gql`
4
+ query fetchMultibidById($multiBidId: uuid!) {
5
+ multi_bids(where: { id: { _eq: $multiBidId } }) {
6
+ chain_id
7
+ cancelled_at
8
+ }
9
+ }
10
+ `;
11
+
12
+ export const fetchMultibidChainIdAndSingleBidsById = gql`
13
+ query fetchMultibidChainIdAndSingleBidsById($multiBidId: uuid!) {
14
+ multi_bids(where: { id: { _eq: $multiBidId } }) {
15
+ chain_id
16
+ cancelled_at
17
+ bids(where: { status: { _in: ["active", "inactive", "expired"] } }) {
18
+ nonce
19
+ }
20
+ }
21
+ }
22
+ `;
23
+
24
+ export const fetchMultibidChainIdAndExpiredSingleBidsById = gql`
25
+ query fetchMultibidChainIdAndExpiredSingleBidsById($multiBidId: uuid!, $expiredBidLimit: Int!) {
26
+ multi_bids(where: { id: { _eq: $multiBidId } }) {
27
+ chain_id
28
+ cancelled_at
29
+ bids(where: { status: { _eq: "expired" } }, limit: $expiredBidLimit) {
30
+ nonce
31
+ }
32
+ }
33
+ }
34
+ `;
@@ -0,0 +1,12 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchNftCollectionChainState = gql`
4
+ query fetchNftCollectionChainState($nftTokenId: String!) {
5
+ nfts(where: { token_id: { _eq: $nftTokenId } }) {
6
+ collection {
7
+ id
8
+ chain_state
9
+ }
10
+ }
11
+ }
12
+ `;
@@ -0,0 +1,75 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchNftById = gql`
4
+ query fetchNftById($nftId: uuid!) {
5
+ nfts(where: { id: { _eq: $nftId } }) {
6
+ id
7
+ token_id
8
+ collection_id
9
+ properties
10
+ chain_state
11
+ listed
12
+ owner
13
+ contract {
14
+ properties
15
+ }
16
+ listings(where: { listed: { _eq: true } }) {
17
+ price
18
+ nonce
19
+ market_name
20
+ }
21
+ collection {
22
+ id
23
+ chain_state
24
+ }
25
+ }
26
+ }
27
+ `;
28
+
29
+ export const fetchNftsById = gql`
30
+ query fetchNftsById($nftIds: [uuid!]) {
31
+ nfts(where: { id: { _in: $nftIds } }) {
32
+ id
33
+ token_id
34
+ collection_id
35
+ properties
36
+ chain_state
37
+ listed
38
+ owner
39
+ contract {
40
+ properties
41
+ }
42
+ collection {
43
+ id
44
+ chain_state
45
+ }
46
+ }
47
+ }
48
+ `;
49
+
50
+ export const fetchNftsWithListingsById = gql`
51
+ query fetchNftsWithListingsById($nftIds: [uuid!]) {
52
+ nfts(where: { id: { _in: $nftIds } }) {
53
+ id
54
+ token_id
55
+ collection_id
56
+ properties
57
+ chain_state
58
+ listed
59
+ contract {
60
+ properties
61
+ }
62
+ listings {
63
+ listed
64
+ market_name
65
+ price
66
+ nonce
67
+ seller
68
+ }
69
+ collection {
70
+ id
71
+ chain_state
72
+ }
73
+ }
74
+ }
75
+ `;
@@ -0,0 +1,45 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchNftsByKioskId = gql`
4
+ query fetchNftsByKioskId($jsonFilter: jsonb) {
5
+ nfts(where: { chain_state: { _contains: $jsonFilter } }) {
6
+ id
7
+ name
8
+ token_id
9
+ properties
10
+ chain_state
11
+ collection_id
12
+ claimable_reason
13
+ owner
14
+ contract {
15
+ properties
16
+ }
17
+ collection {
18
+ id
19
+ chain_state
20
+ }
21
+ }
22
+ }
23
+ `;
24
+
25
+ export const fetchBulkNftsByKioskId = gql`
26
+ query fetchNftsByKioskId($where: nfts_bool_exp) {
27
+ nfts(where: $where) {
28
+ id
29
+ name
30
+ token_id
31
+ properties
32
+ chain_state
33
+ collection_id
34
+ claimable_reason
35
+ owner
36
+ contract {
37
+ properties
38
+ }
39
+ collection {
40
+ id
41
+ chain_state
42
+ }
43
+ }
44
+ }
45
+ `;
@@ -0,0 +1,10 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchOwnerCapByKiosk = gql`
4
+ query fetchOwnerCapByKiosk($kioskId: String!) {
5
+ ownerCap: kiosk_owner_cap_by_kiosk(kiosk_id: $kioskId) {
6
+ id
7
+ kiosk_id
8
+ }
9
+ }
10
+ `;
@@ -0,0 +1,10 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchPersonalCapByKiosk = gql`
4
+ query fetchPersonalCapByKiosk($kioskId: String!) {
5
+ personalCap: personal_kiosk_cap_by_kiosk(kiosk_id: $kioskId) {
6
+ id
7
+ kiosk_id
8
+ }
9
+ }
10
+ `;
@@ -0,0 +1,12 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchSharedObjectsByType = gql`
4
+ query fetchSharedObjectsByType($type: String!) {
5
+ sharedObjects: shared_objects_by_type(type: $type) {
6
+ id
7
+ module
8
+ pkg
9
+ type
10
+ }
11
+ }
12
+ `;
@@ -0,0 +1,12 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchTransferPoliciesByType = gql`
4
+ query fetchTransferPoliciesByType($type: String!) {
5
+ transfer_policies_by_type(type: $type) {
6
+ id
7
+ is_origin_byte
8
+ rules
9
+ type
10
+ }
11
+ }
12
+ `;
@@ -0,0 +1,14 @@
1
+ import { gql } from 'graphql-request';
2
+
3
+ export const fetchWalletKiosks = gql`
4
+ query fetchWalletKiosks($wallet: String!) {
5
+ kiosks: kiosks_by_owner_address(owner_address: $wallet) {
6
+ id
7
+ is_origin_byte
8
+ is_personal
9
+ owner_address
10
+ profits
11
+ is_shared
12
+ }
13
+ }
14
+ `;
@@ -0,0 +1,15 @@
1
+ import { gqlChainRequest } from '../gqlChainRequest';
2
+ import { fetchCommissionByNftContractId } from './fetchCommissionByListingId';
3
+
4
+ export const getCommissionByNftContractId = async (nftContractId: string) => {
5
+ try {
6
+ const res = await gqlChainRequest({
7
+ chain: 'sui',
8
+ query: fetchCommissionByNftContractId,
9
+ variables: { nftContractId },
10
+ });
11
+ return res?.commissions?.[0];
12
+ } catch (err) {
13
+ throw new Error(`Failed to fetch commission for listing ${nftContractId}`);
14
+ }
15
+ };
@@ -0,0 +1,17 @@
1
+ import { type Transaction } from '@mysten/sui/transactions';
2
+ import { TRADEPORT_BENEFICIARY_ADDRESS } from '../constants';
3
+ import { addLeadingZerosAfter0x } from '../utils/addLeadingZerosAfter0x';
4
+ import { getSuiToUsdRate } from './getSuiToUsdRate';
5
+
6
+ export const addOneDollarFee = async (tx: Transaction) => {
7
+ const rate = await getSuiToUsdRate();
8
+
9
+ const companyFee = BigInt(Math.ceil(1_000_000_000 / rate));
10
+
11
+ const [microTxFee] = tx.splitCoins(tx.gas, [tx.pure.u64(Number(companyFee))]);
12
+
13
+ tx.transferObjects(
14
+ [tx.object(microTxFee)],
15
+ tx.pure.address(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS)),
16
+ );
17
+ };
@@ -0,0 +1,17 @@
1
+ import { type Transaction } from '@mysten/sui/transactions';
2
+ import {
3
+ TRADEPORT_BENEFICIARY_ADDRESS,
4
+ TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT,
5
+ } from '../constants';
6
+ import { addLeadingZerosAfter0x } from '../utils/addLeadingZerosAfter0x';
7
+
8
+ export const addThirdPartyTxFee = async (tx: Transaction, price: number) => {
9
+ const [microTxFee] = tx.splitCoins(tx.gas, [
10
+ tx.pure.u64(price * TRADEPORT_THIRD_PARTY_FEE_DECIMAL_PERCENT),
11
+ ]);
12
+
13
+ tx.transferObjects(
14
+ [tx.object(microTxFee)],
15
+ tx.pure.address(addLeadingZerosAfter0x(TRADEPORT_BENEFICIARY_ADDRESS)),
16
+ );
17
+ };