@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
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ export default {
3
+ preset: 'ts-jest/presets/default-esm',
4
+ testEnvironment: 'node',
5
+ extensionsToTreatAsEsm: ['.ts'],
6
+ moduleNameMapper: {
7
+ '^(\\.{1,2}/.*)\\.js$': '$1',
8
+ },
9
+ verbose: true,
10
+ testTimeout: 1800000,
11
+ setupFiles: ['dotenv/config'],
12
+ };
package/package.json CHANGED
@@ -1,72 +1,67 @@
1
1
  {
2
- "name": "@tradeport/sui-trading-sdk",
3
- "license": "MIT",
4
- "version": "0.5.3",
5
- "type": "module",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "exports": {
12
- ".": {
13
- "types": "./dist/index.d.ts",
14
- "import": "./dist/index.js",
15
- "default": "./dist/index.js"
16
- }
17
- },
18
- "scripts": {
19
- "build": "tsup src/index.ts --sourcemap --format esm --dts",
20
- "prepublishOnly": "pnpm run build",
21
- "release": "pnpm run build && changeset publish",
22
- "lint": "tsc && eslint --fix src/* --ignore-path .gitignore --ext .js,.ts",
23
- "format": "prettier --write \"**/*.+(js|ts|json)\"",
24
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
25
- "prepare": "husky install",
26
- "pre-commit": "lint-staged"
27
- },
28
- "devDependencies": {
29
- "@babel/core": "^7.23.3",
30
- "@babel/preset-env": "^7.23.3",
31
- "@changesets/cli": "^2.26.2",
32
- "@types/jest": "^29.5.10",
33
- "@types/ms": "^2.1.0",
34
- "@types/node": "^20.10.0",
35
- "@typescript-eslint/eslint-plugin": "^6.13.1",
36
- "@typescript-eslint/parser": "^6.13.1",
37
- "babel-jest": "^29.7.0",
38
- "dotenv": "^16.3.1",
39
- "eslint": "^8.54.0",
40
- "eslint-config-prettier": "^9.0.0",
41
- "eslint-config-xo": "^0.43.1",
42
- "eslint-config-xo-typescript": "^1.0.1",
43
- "husky": "^8.0.0",
44
- "jest": "^29.7.0",
45
- "lint-staged": "^16.2.7",
46
- "prettier": "^3.1.0",
47
- "ts-jest": "^29.1.1",
48
- "tsup": "^8.0.1",
49
- "typescript": "^5.3.2"
50
- },
51
- "dependencies": {
52
- "@mysten/kiosk": "^1.3.1",
53
- "@mysten/sui": "^2.20.0",
54
- "@types/analytics-node": "^3.1.14",
55
- "analytics-node": "^6.2.0",
56
- "bignumber.js": "^9.3.1",
57
- "graphql": "^16.12.0",
58
- "graphql-request": "^6.1.0",
59
- "ms": "^2.1.3"
60
- },
61
- "publishConfig": {
62
- "access": "public",
63
- "registry": "https://registry.npmjs.org/"
64
- },
65
- "lint-staged": {
66
- "*.ts": [
67
- "eslint --fix",
68
- "bash -c 'tsc --noEmit'",
69
- "prettier --write"
70
- ]
71
- }
72
- }
2
+ "name": "@tradeport/sui-trading-sdk",
3
+ "license": "MIT",
4
+ "version": "0.5.4",
5
+ "type": "module",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "devDependencies": {
16
+ "@babel/core": "^7.23.3",
17
+ "@babel/preset-env": "^7.23.3",
18
+ "@changesets/cli": "^2.26.2",
19
+ "@types/jest": "^29.5.10",
20
+ "@types/ms": "^2.1.0",
21
+ "@types/node": "^20.10.0",
22
+ "@typescript-eslint/eslint-plugin": "^6.13.1",
23
+ "@typescript-eslint/parser": "^6.13.1",
24
+ "babel-jest": "^29.7.0",
25
+ "dotenv": "^16.3.1",
26
+ "eslint": "^8.54.0",
27
+ "eslint-config-prettier": "^9.0.0",
28
+ "eslint-config-xo": "^0.43.1",
29
+ "eslint-config-xo-typescript": "^1.0.1",
30
+ "husky": "^8.0.0",
31
+ "jest": "^29.7.0",
32
+ "lint-staged": "^16.2.7",
33
+ "prettier": "^3.1.0",
34
+ "ts-jest": "^29.1.1",
35
+ "tsup": "^8.0.1",
36
+ "typescript": "^5.3.2"
37
+ },
38
+ "dependencies": {
39
+ "@mysten/kiosk": "^1.3.1",
40
+ "@mysten/sui": "^2.20.0",
41
+ "@types/analytics-node": "^3.1.14",
42
+ "analytics-node": "^6.2.0",
43
+ "bignumber.js": "^9.3.1",
44
+ "graphql": "^16.12.0",
45
+ "graphql-request": "^6.1.0",
46
+ "ms": "^2.1.3"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "registry": "https://registry.npmjs.org/"
51
+ },
52
+ "lint-staged": {
53
+ "*.ts": [
54
+ "eslint --fix",
55
+ "bash -c 'tsc --noEmit'",
56
+ "prettier --write"
57
+ ]
58
+ },
59
+ "scripts": {
60
+ "build": "tsup src/index.ts --sourcemap --format esm --dts",
61
+ "release": "pnpm run build && changeset publish",
62
+ "lint": "tsc && eslint --fix src/* --ignore-path .gitignore --ext .js,.ts",
63
+ "format": "prettier --write \"**/*.+(js|ts|json)\"",
64
+ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
65
+ "pre-commit": "lint-staged"
66
+ }
67
+ }
@@ -0,0 +1,442 @@
1
+ import { type Transaction } from '@mysten/sui/transactions';
2
+ import { GraphQLClient } from 'graphql-request';
3
+ import createKioskClient from './apiClients/createKioskClient';
4
+ import createSuiClient from './apiClients/createSuiClient';
5
+ import { getGraphqlClient, setGraphqlClient } from './apiClients/graphqlClient';
6
+ import { gqlChainRequest } from './graphql/gqlChainRequest';
7
+ import { fetchCollectionBidsById } from './graphql/queries/fetchCollectionBidById';
8
+ import { fetchCollectionBidsAtSamePrice } from './graphql/queries/fetchCollectionBidsAtSamePrice';
9
+ import {
10
+ acceptCollectionBid,
11
+ type AcceptCollectionBid,
12
+ } from './methods/acceptCollectionBid/acceptCollectionBid';
13
+ import { acceptNftBids, type AcceptNftBids } from './methods/acceptNftBids/acceptNftBids';
14
+ import { applyFtStrategy, type ApplyFtStrategy } from './methods/applyFtStrategy/applyFtStrategy';
15
+ import {
16
+ type ApplyNftStrategy,
17
+ applyTradeportNftStrategy,
18
+ } from './methods/applyNftStrategy/applyNftStrategy';
19
+ import { buyListings, type BuyListings } from './methods/buyListings/buyListings';
20
+ import { cancelMultiBid, type CancelMultiBid } from './methods/cancelMultiBid/cancelMultiBid';
21
+ import {
22
+ cancelNftTransfers,
23
+ type CancelNftTransfers,
24
+ } from './methods/cancelNftTransfers/cancelNftTransfers';
25
+ import { claimNfts, type ClaimNfts } from './methods/claimNfts/claimNfts';
26
+ import { createMultiBid, type CreateMultiBid } from './methods/createMultiBid/createMultiBid';
27
+ import { listNfts, type ListNfts } from './methods/listNfts/listNfts';
28
+ import {
29
+ migrateNftsFromUnsharedToSharedKiosks,
30
+ type MigrateNftsFromUnsharedToSharedKiosks,
31
+ } from './methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks';
32
+ import {
33
+ type PlaceCollectionBid,
34
+ placeCollectionBids,
35
+ } from './methods/placeCollectionBids/placeCollectionBids';
36
+ import { placeNftBids, type PlaceNftBids } from './methods/placeNftBids/placeNftBids';
37
+ import {
38
+ removeCollectionBids,
39
+ type RemoveCollectionBids,
40
+ } from './methods/removeCollectionBids/removeCollectionBids';
41
+ import { removeNftBids, type RemoveNftBids } from './methods/removeNftBids/removeNftBids';
42
+ import {
43
+ type SponsorNftListing,
44
+ sponsorNftListing,
45
+ } from './methods/sponsorNftListing/sponsorNftListing';
46
+ import { transferNfts, type TransferNfts } from './methods/transferNfts/transferNfts';
47
+ import { unlistListings, type UnlistListings } from './methods/unlistListings/unlistListings';
48
+ import { updateMultiBid, type UpdateMultiBid } from './methods/updateMultiBid/updateMultiBid';
49
+ import {
50
+ withdrawProfitsFromKiosks,
51
+ type WithdrawProfitsFromKiosks,
52
+ } from './methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks';
53
+ import { addLeadingZerosAfter0x } from './utils/addLeadingZerosAfter0x';
54
+
55
+ const DEFAULT_SUI_GRPC_URL = 'https://fullnode.mainnet.sui.io:443';
56
+ const DEFAULT_SUI_GRAPHQL_URL = 'https://graphql.mainnet.sui.io/';
57
+
58
+ type ApiConfig = {
59
+ apiUser: string;
60
+ apiKey: string;
61
+ apiUrl?: string;
62
+ tradeportRouterUrl?: string;
63
+ apiVercelId?: string;
64
+ suiNodeUrl?: string;
65
+ suiGraphqlUrl?: string;
66
+ graphQLClient?: GraphQLClient;
67
+ };
68
+ export interface RequestContext {
69
+ apiUser: string;
70
+ apiKey: string;
71
+ tradeportRouterUrl?: string;
72
+ suiClient: ReturnType<typeof createSuiClient>;
73
+ kioskClient: ReturnType<typeof createKioskClient>;
74
+ }
75
+
76
+ class SuiTradingClient {
77
+ private readonly apiUser: string;
78
+ private readonly apiKey: string;
79
+ private readonly tradeportRouterUrl?: string;
80
+ private readonly suiClient: ReturnType<typeof createSuiClient>;
81
+ private readonly kioskClient: ReturnType<typeof createKioskClient>;
82
+ private readonly allowedApiUsersForUnsharedKiosksMigration = ['tradeport.xyz', 'mercato.xyz'];
83
+
84
+ constructor({
85
+ apiUser,
86
+ apiKey,
87
+ apiVercelId,
88
+ apiUrl,
89
+ tradeportRouterUrl,
90
+ suiNodeUrl,
91
+ suiGraphqlUrl,
92
+ graphQLClient,
93
+ }: ApiConfig) {
94
+ this.apiUser = apiUser;
95
+ this.apiKey = apiKey;
96
+ this.tradeportRouterUrl = tradeportRouterUrl;
97
+ this.suiClient = createSuiClient(suiNodeUrl ?? DEFAULT_SUI_GRPC_URL);
98
+ this.kioskClient = createKioskClient(suiGraphqlUrl ?? DEFAULT_SUI_GRAPHQL_URL);
99
+
100
+ if (graphQLClient) {
101
+ setGraphqlClient(graphQLClient);
102
+ } else {
103
+ setGraphqlClient(new GraphQLClient(apiUrl ?? 'https://graphql.tradeport.gg'));
104
+ }
105
+
106
+ getGraphqlClient().setHeaders({
107
+ 'x-api-user': apiUser,
108
+ 'x-api-key': apiKey,
109
+ ...(apiVercelId && { 'x-vercel-id': apiVercelId }),
110
+ });
111
+
112
+ // trackMethodCall({ apiUser, apiKey, event: 'INITIALIZE_CLIENT' });
113
+ }
114
+
115
+ public async buyListings(args: BuyListings): Promise<Transaction> {
116
+ const context: RequestContext = {
117
+ apiUser: this.apiUser,
118
+ apiKey: this.apiKey,
119
+ tradeportRouterUrl: this.tradeportRouterUrl,
120
+ suiClient: this.suiClient,
121
+ kioskClient: this.kioskClient,
122
+ };
123
+ return buyListings(args, context);
124
+ }
125
+
126
+ public async listNfts({ nfts, walletAddress, tx }: ListNfts) {
127
+ const context: RequestContext = {
128
+ apiUser: this.apiUser,
129
+ apiKey: this.apiKey,
130
+ tradeportRouterUrl: this.tradeportRouterUrl,
131
+ suiClient: this.suiClient,
132
+ kioskClient: this.kioskClient,
133
+ };
134
+
135
+ return listNfts({ nfts, walletAddress, tx }, context);
136
+ }
137
+
138
+ public async unlistListings({ listingIds, walletAddress }: UnlistListings) {
139
+ const context: RequestContext = {
140
+ apiUser: this.apiUser,
141
+ apiKey: this.apiKey,
142
+ tradeportRouterUrl: this.tradeportRouterUrl,
143
+ suiClient: this.suiClient,
144
+ kioskClient: this.kioskClient,
145
+ };
146
+
147
+ return unlistListings({ listingIds, walletAddress }, context);
148
+ }
149
+
150
+ public async placeNftBids(data: PlaceNftBids) {
151
+ const context: RequestContext = {
152
+ apiUser: this.apiUser,
153
+ apiKey: this.apiKey,
154
+ tradeportRouterUrl: this.tradeportRouterUrl,
155
+ suiClient: this.suiClient,
156
+ kioskClient: this.kioskClient,
157
+ };
158
+
159
+ return placeNftBids(data, context);
160
+ }
161
+
162
+ public async removeNftBids({ bidIds, tx }: RemoveNftBids) {
163
+ const context: RequestContext = {
164
+ apiUser: this.apiUser,
165
+ tradeportRouterUrl: this.tradeportRouterUrl,
166
+ apiKey: this.apiKey,
167
+ suiClient: this.suiClient,
168
+ kioskClient: this.kioskClient,
169
+ };
170
+
171
+ return removeNftBids({ bidIds, tx }, context);
172
+ }
173
+
174
+ public async acceptNftBids({ bidIds, walletAddress }: AcceptNftBids) {
175
+ const context: RequestContext = {
176
+ apiUser: this.apiUser,
177
+ apiKey: this.apiKey,
178
+ tradeportRouterUrl: this.tradeportRouterUrl,
179
+ suiClient: this.suiClient,
180
+ kioskClient: this.kioskClient,
181
+ };
182
+
183
+ return acceptNftBids({ bidIds, walletAddress }, context);
184
+ }
185
+
186
+ public async placeCollectionBid({
187
+ collectionId,
188
+ bidAmountInMist,
189
+ numOfBids,
190
+ walletAddress,
191
+ multiBidId,
192
+ multiBidChainId,
193
+ expireAt,
194
+ tx,
195
+ }: PlaceCollectionBid): Promise<Transaction> {
196
+ const context: RequestContext = {
197
+ apiUser: this.apiUser,
198
+ apiKey: this.apiKey,
199
+ tradeportRouterUrl: this.tradeportRouterUrl,
200
+ suiClient: this.suiClient,
201
+ kioskClient: this.kioskClient,
202
+ };
203
+
204
+ return placeCollectionBids(
205
+ {
206
+ collections: [
207
+ {
208
+ id: collectionId,
209
+ bidAmountInMist,
210
+ numOfBids,
211
+ expireAt,
212
+ },
213
+ ],
214
+ walletAddress,
215
+ multiBidId,
216
+ multiBidChainId,
217
+ tx,
218
+ },
219
+ context,
220
+ );
221
+ }
222
+
223
+ public async acceptCollectionBid({ bidId, nftId, walletAddress }: AcceptCollectionBid) {
224
+ const context: RequestContext = {
225
+ apiUser: this.apiUser,
226
+ apiKey: this.apiKey,
227
+ tradeportRouterUrl: this.tradeportRouterUrl,
228
+ suiClient: this.suiClient,
229
+ kioskClient: this.kioskClient,
230
+ };
231
+
232
+ const collectionBidRes = await gqlChainRequest({
233
+ chain: 'sui',
234
+ query: fetchCollectionBidsById,
235
+ variables: { bidIds: [bidId] },
236
+ });
237
+ const bid = collectionBidRes?.bids?.[0];
238
+
239
+ if (!bid) {
240
+ throw new Error('No bid found');
241
+ }
242
+
243
+ if (addLeadingZerosAfter0x(bid?.bidder) === addLeadingZerosAfter0x(walletAddress)) {
244
+ throw new Error('Wallet cannot accept its own bid');
245
+ }
246
+
247
+ if (bid?.status !== 'active') {
248
+ throw new Error('Bid not active');
249
+ }
250
+
251
+ if (bid?.type !== 'collection') {
252
+ throw new Error('Bid is not a collection bid. Use acceptNftBid() instead.');
253
+ }
254
+
255
+ const allBidsWithSameHighestPriceRes = await gqlChainRequest({
256
+ chain: 'sui',
257
+ query: fetchCollectionBidsAtSamePrice,
258
+ variables: {
259
+ collectionId: bid?.collection_id,
260
+ price: bid?.price,
261
+ },
262
+ });
263
+ const allBidsWithSameHighestPrice = allBidsWithSameHighestPriceRes?.bids;
264
+
265
+ // loop through all highest bids at same price until one succeeds
266
+ for (let i = 0; i < (allBidsWithSameHighestPrice?.length ?? 0); i++) {
267
+ const tx = await acceptCollectionBid(
268
+ {
269
+ bid: allBidsWithSameHighestPrice?.[i],
270
+ nftId,
271
+ walletAddress,
272
+ },
273
+ context,
274
+ );
275
+
276
+ tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
277
+ let result = await this.suiClient.simulateTransaction({
278
+ transaction: tx,
279
+ include: { effects: true },
280
+ });
281
+
282
+ if (result.$kind === 'Transaction') {
283
+ return tx;
284
+ }
285
+
286
+ if (i === allBidsWithSameHighestPrice.length - 1) {
287
+ // next loop through all the same bids and try with splitting royalty from user gas coins in case royalty has changed and the amount in escrow is not ennough
288
+ for (let j = 0; j < allBidsWithSameHighestPrice?.length; j++) {
289
+ const tx = await acceptCollectionBid(
290
+ {
291
+ bid: allBidsWithSameHighestPrice?.[j],
292
+ nftId,
293
+ walletAddress,
294
+ shouldSplitRoyaltyFromUserGasCoins: true,
295
+ },
296
+ context,
297
+ );
298
+
299
+ tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
300
+ result = await this.suiClient.simulateTransaction({
301
+ transaction: tx,
302
+ include: { effects: true },
303
+ });
304
+
305
+ if (result?.$kind === 'Transaction') {
306
+ return tx;
307
+ }
308
+ }
309
+
310
+ throw new Error(
311
+ `Failed to validate accept bid transaction: ${
312
+ result?.FailedTransaction?.status?.error
313
+ ? JSON.stringify(result.FailedTransaction.status.error)
314
+ : 'Unknown error'
315
+ }`,
316
+ );
317
+ }
318
+ }
319
+ }
320
+
321
+ public async removeCollectionBids({ bidIds, tx }: RemoveCollectionBids) {
322
+ const context: RequestContext = {
323
+ apiUser: this.apiUser,
324
+ apiKey: this.apiKey,
325
+ tradeportRouterUrl: this.tradeportRouterUrl,
326
+ suiClient: this.suiClient,
327
+ kioskClient: this.kioskClient,
328
+ };
329
+
330
+ return removeCollectionBids({ bidIds, tx }, context);
331
+ }
332
+
333
+ public async transferNfts({ nftIds, recipientAddress, walletAddress }: TransferNfts) {
334
+ const context: RequestContext = {
335
+ apiUser: this.apiUser,
336
+ apiKey: this.apiKey,
337
+ tradeportRouterUrl: this.tradeportRouterUrl,
338
+ suiClient: this.suiClient,
339
+ kioskClient: this.kioskClient,
340
+ };
341
+
342
+ return transferNfts({ nftIds, recipientAddress, walletAddress }, context);
343
+ }
344
+
345
+ public async cancelNftTransfers({ nftIds, walletAddress }: CancelNftTransfers) {
346
+ const context: RequestContext = {
347
+ apiUser: this.apiUser,
348
+ apiKey: this.apiKey,
349
+ tradeportRouterUrl: this.tradeportRouterUrl,
350
+ suiClient: this.suiClient,
351
+ kioskClient: this.kioskClient,
352
+ };
353
+
354
+ try {
355
+ return await cancelNftTransfers({ nftIds, walletAddress }, context);
356
+ } catch (err) {
357
+ throw new Error(
358
+ 'Cannot cancel NFT transfer unless the NFT was transferred using kiosk_transfers::transfer_with_purchase_capability',
359
+ );
360
+ }
361
+ }
362
+
363
+ public async claimNfts({ nftIds, walletAddress }: ClaimNfts) {
364
+ const context: RequestContext = {
365
+ apiUser: this.apiUser,
366
+ apiKey: this.apiKey,
367
+ tradeportRouterUrl: this.tradeportRouterUrl,
368
+ suiClient: this.suiClient,
369
+ kioskClient: this.kioskClient,
370
+ };
371
+
372
+ try {
373
+ const tx = await claimNfts({ nftIds, walletAddress }, context, true);
374
+
375
+ tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
376
+ const rawTransaction = await tx.build({ client: this.suiClient });
377
+ await this.suiClient.simulateTransaction({
378
+ transaction: rawTransaction,
379
+ });
380
+ return tx;
381
+ } catch (err) {
382
+ return claimNfts({ nftIds, walletAddress }, context);
383
+ }
384
+ }
385
+
386
+ public async withdrawProfitsFromKiosks(args: WithdrawProfitsFromKiosks) {
387
+ const context: RequestContext = {
388
+ apiUser: this.apiUser,
389
+ apiKey: this.apiKey,
390
+ tradeportRouterUrl: this.tradeportRouterUrl,
391
+ suiClient: this.suiClient,
392
+ kioskClient: this.kioskClient,
393
+ };
394
+
395
+ return withdrawProfitsFromKiosks(args, context);
396
+ }
397
+
398
+ public async migrateNftsFromUnsharedToSharedKiosks(args: MigrateNftsFromUnsharedToSharedKiosks) {
399
+ if (!this.allowedApiUsersForUnsharedKiosksMigration.includes(this.apiUser)) {
400
+ throw new Error('This method is not available for your API user.');
401
+ }
402
+
403
+ const context: RequestContext = {
404
+ apiUser: this.apiUser,
405
+ apiKey: this.apiKey,
406
+ tradeportRouterUrl: this.tradeportRouterUrl,
407
+ suiClient: this.suiClient,
408
+ kioskClient: this.kioskClient,
409
+ };
410
+
411
+ return migrateNftsFromUnsharedToSharedKiosks(args, context);
412
+ }
413
+
414
+ public async createMultiBid(args: CreateMultiBid) {
415
+ return createMultiBid(args);
416
+ }
417
+
418
+ public async cancelMultiBid(args: CancelMultiBid) {
419
+ return cancelMultiBid(args);
420
+ }
421
+
422
+ public async updateMultiBid(args: UpdateMultiBid) {
423
+ return updateMultiBid(args, {
424
+ suiClient: this.suiClient,
425
+ tradeportRouterUrl: this.tradeportRouterUrl,
426
+ });
427
+ }
428
+
429
+ public async sponsorNftListing(args: SponsorNftListing) {
430
+ return sponsorNftListing(args);
431
+ }
432
+
433
+ public async applyFtStrategy(args: ApplyFtStrategy) {
434
+ return applyFtStrategy(args);
435
+ }
436
+
437
+ public async applyTradeportNftStrategy(args: ApplyNftStrategy) {
438
+ return applyTradeportNftStrategy(args);
439
+ }
440
+ }
441
+
442
+ export default SuiTradingClient;
@@ -0,0 +1,10 @@
1
+ import { KioskClient } from '@mysten/kiosk';
2
+ import { SuiGraphQLClient } from '@mysten/sui/graphql';
3
+
4
+ const createKioskClient = (graphqlUrl: string) =>
5
+ new KioskClient({
6
+ client: new SuiGraphQLClient({ url: graphqlUrl, network: 'mainnet' }),
7
+ network: 'mainnet',
8
+ });
9
+
10
+ export default createKioskClient;
@@ -0,0 +1,5 @@
1
+ import { SuiGrpcClient } from '@mysten/sui/grpc';
2
+
3
+ const createSuiClient = (baseUrl: string) => new SuiGrpcClient({ network: 'mainnet', baseUrl });
4
+
5
+ export default createSuiClient;
@@ -0,0 +1,17 @@
1
+ import type { GraphQLClient } from 'graphql-request';
2
+
3
+ let graphqlClient: GraphQLClient;
4
+
5
+ export const getGraphqlClient = () => {
6
+ if (!graphqlClient) {
7
+ throw new Error(
8
+ 'GraphQL client not initialized. Please provide apiUrl to SuiTradingClient constructor.',
9
+ );
10
+ }
11
+
12
+ return graphqlClient;
13
+ };
14
+
15
+ export function setGraphqlClient(client: GraphQLClient) {
16
+ graphqlClient = client;
17
+ }
@@ -0,0 +1,10 @@
1
+ import { BigNumber } from 'bignumber.js';
2
+
3
+ BigNumber.set({
4
+ POW_PRECISION: 64,
5
+ });
6
+
7
+ export const ZERO = new BigNumber(0);
8
+ export const ONE = new BigNumber(1);
9
+
10
+ export default BigNumber;