@tradeport/sui-trading-sdk 0.4.66 → 0.5.1
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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +330 -329
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -5
- package/dist/index.mjs.map +1 -1
- package/jest.config.js +6 -2
- package/package.json +66 -65
- package/src/SuiTradingClient.ts +24 -14
- package/src/apiClients/createKioskClient.ts +5 -6
- package/src/apiClients/createSuiClient.ts +2 -2
- package/src/helpers/getTransferPolicyRuleNamesFromSuiObject.ts +9 -21
- package/src/helpers/isNonKioskListing.ts +2 -2
- package/src/helpers/kiosk/getKioskCollectionRoyaltyFeeAmount.ts +10 -10
- package/src/helpers/kiosk/getKioskIdFromKioskTx.ts +15 -7
- package/src/helpers/kiosk/getKioskPlaceBidCoin.ts +2 -2
- package/src/helpers/kiosk/getRulePackageId.ts +2 -2
- package/src/helpers/kiosk/getTransferPoliciesToResolve.ts +2 -2
- package/src/helpers/kiosk/kioskListingBcs.ts +19 -0
- package/src/helpers/kiosk/kioskTxWrapper.ts +3 -3
- package/src/helpers/kiosk/lockNftInsideKioskIfNotLocked.ts +9 -9
- package/src/helpers/kiosk/preProcessSharedBulkBuyingData.ts +33 -21
- package/src/helpers/kiosk/resolveRoyaltyRule.ts +2 -2
- package/src/helpers/kiosk/resolveTransferPolicies.ts +2 -2
- package/src/helpers/kiosk/takeAndBorrowNftFromKiosk.ts +2 -2
- package/src/helpers/kiosk/takeLockedNftFromKiosk.ts +5 -9
- package/src/helpers/originByte/getOBBidderKiosk.ts +4 -7
- package/src/helpers/rpc/getAcountBalance.ts +3 -3
- package/src/helpers/rpc/getObjectType.ts +8 -4
- package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +2 -2
- package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +3 -3
- package/src/methods/acceptNftBids/acceptNftBids.ts +2 -2
- package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +4 -4
- package/src/methods/buyListings/addBuyListingTxs.ts +16 -18
- package/src/methods/buyListings/buyListings.ts +2 -2
- package/src/methods/cancelNftTransfers/addCancelNftTransfersTx.ts +1 -1
- package/src/methods/claimNfts/addClaimNftsTxs.ts +8 -8
- package/src/methods/claimNfts/claimNfts.ts +3 -3
- package/src/methods/listNfts/addListTxs.ts +2 -2
- package/src/methods/listNfts/addRelistTxs.ts +4 -4
- package/src/methods/listNfts/listNfts.ts +2 -2
- package/src/methods/placeCollectionBids/placeCollectionBids.ts +2 -2
- package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +5 -10
- package/src/methods/placeNftBids/placeNftBids.ts +2 -2
- package/src/methods/relistNft/relistNft.ts +2 -2
- package/src/methods/removeCollectionBids/removeCollectionBids.ts +2 -2
- package/src/methods/removeNftBids/removeNftBids.ts +2 -2
- package/src/methods/transferNfts/addTransferNftTx.ts +16 -7
- package/src/methods/transferNfts/transferNfts.ts +2 -2
- package/src/methods/unlistListings/addUnlistListingTxs.ts +6 -10
- package/src/methods/unlistListings/unlistListings.ts +2 -2
- package/src/methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks.ts +2 -2
- package/src/tests/SuiWallet.ts +19 -15
- package/tsconfig.json +2 -1
- package/.claude/settings.local.json +0 -5
package/jest.config.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
-
|
|
3
|
-
preset: 'ts-jest',
|
|
2
|
+
export default {
|
|
3
|
+
preset: 'ts-jest/presets/default-esm',
|
|
4
4
|
testEnvironment: 'node',
|
|
5
|
+
extensionsToTreatAsEsm: ['.ts'],
|
|
6
|
+
moduleNameMapper: {
|
|
7
|
+
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
8
|
+
},
|
|
5
9
|
verbose: true,
|
|
6
10
|
testTimeout: 1800000,
|
|
7
11
|
setupFiles: ['dotenv/config'],
|
package/package.json
CHANGED
|
@@ -1,66 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
2
|
+
"name": "@tradeport/sui-trading-sdk",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "0.5.1",
|
|
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
|
+
}
|
package/src/SuiTradingClient.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getFullnodeUrl } from '@mysten/sui/client';
|
|
2
1
|
import { type Transaction } from '@mysten/sui/transactions';
|
|
3
2
|
import { GraphQLClient } from 'graphql-request';
|
|
4
3
|
import createKioskClient from './apiClients/createKioskClient';
|
|
@@ -53,6 +52,9 @@ import {
|
|
|
53
52
|
} from './methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks';
|
|
54
53
|
import { addLeadingZerosAfter0x } from './utils/addLeadingZerosAfter0x';
|
|
55
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
|
+
|
|
56
58
|
type ApiConfig = {
|
|
57
59
|
apiUser: string;
|
|
58
60
|
apiKey: string;
|
|
@@ -60,6 +62,7 @@ type ApiConfig = {
|
|
|
60
62
|
tradeportRouterUrl?: string;
|
|
61
63
|
apiVercelId?: string;
|
|
62
64
|
suiNodeUrl?: string;
|
|
65
|
+
suiGraphqlUrl?: string;
|
|
63
66
|
graphQLClient?: GraphQLClient;
|
|
64
67
|
};
|
|
65
68
|
export interface RequestContext {
|
|
@@ -85,13 +88,14 @@ class SuiTradingClient {
|
|
|
85
88
|
apiUrl,
|
|
86
89
|
tradeportRouterUrl,
|
|
87
90
|
suiNodeUrl,
|
|
91
|
+
suiGraphqlUrl,
|
|
88
92
|
graphQLClient,
|
|
89
93
|
}: ApiConfig) {
|
|
90
94
|
this.apiUser = apiUser;
|
|
91
95
|
this.apiKey = apiKey;
|
|
92
96
|
this.tradeportRouterUrl = tradeportRouterUrl;
|
|
93
|
-
this.suiClient = createSuiClient(suiNodeUrl ??
|
|
94
|
-
this.kioskClient = createKioskClient(
|
|
97
|
+
this.suiClient = createSuiClient(suiNodeUrl ?? DEFAULT_SUI_GRPC_URL);
|
|
98
|
+
this.kioskClient = createKioskClient(suiGraphqlUrl ?? DEFAULT_SUI_GRAPHQL_URL);
|
|
95
99
|
|
|
96
100
|
if (graphQLClient) {
|
|
97
101
|
setGraphqlClient(graphQLClient);
|
|
@@ -269,12 +273,13 @@ class SuiTradingClient {
|
|
|
269
273
|
context,
|
|
270
274
|
);
|
|
271
275
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
276
|
+
tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
|
|
277
|
+
let result = await this.suiClient.simulateTransaction({
|
|
278
|
+
transaction: tx,
|
|
279
|
+
include: { effects: true },
|
|
275
280
|
});
|
|
276
281
|
|
|
277
|
-
if (result
|
|
282
|
+
if (result.$kind === 'Transaction') {
|
|
278
283
|
return tx;
|
|
279
284
|
}
|
|
280
285
|
|
|
@@ -291,18 +296,23 @@ class SuiTradingClient {
|
|
|
291
296
|
context,
|
|
292
297
|
);
|
|
293
298
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
299
|
+
tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
|
|
300
|
+
result = await this.suiClient.simulateTransaction({
|
|
301
|
+
transaction: tx,
|
|
302
|
+
include: { effects: true },
|
|
297
303
|
});
|
|
298
304
|
|
|
299
|
-
if (result
|
|
305
|
+
if (result?.$kind === 'Transaction') {
|
|
300
306
|
return tx;
|
|
301
307
|
}
|
|
302
308
|
}
|
|
303
309
|
|
|
304
310
|
throw new Error(
|
|
305
|
-
`Failed to validate accept bid transaction: ${
|
|
311
|
+
`Failed to validate accept bid transaction: ${
|
|
312
|
+
result?.FailedTransaction?.status?.error
|
|
313
|
+
? JSON.stringify(result.FailedTransaction.status.error)
|
|
314
|
+
: 'Unknown error'
|
|
315
|
+
}`,
|
|
306
316
|
);
|
|
307
317
|
}
|
|
308
318
|
}
|
|
@@ -364,8 +374,8 @@ class SuiTradingClient {
|
|
|
364
374
|
|
|
365
375
|
tx.setSenderIfNotSet(addLeadingZerosAfter0x(walletAddress));
|
|
366
376
|
const rawTransaction = await tx.build({ client: this.suiClient });
|
|
367
|
-
await this.suiClient.
|
|
368
|
-
|
|
377
|
+
await this.suiClient.simulateTransaction({
|
|
378
|
+
transaction: rawTransaction,
|
|
369
379
|
});
|
|
370
380
|
return tx;
|
|
371
381
|
} catch (err) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { KioskClient
|
|
2
|
-
import {
|
|
1
|
+
import { KioskClient } from '@mysten/kiosk';
|
|
2
|
+
import { SuiGraphQLClient } from '@mysten/sui/graphql';
|
|
3
3
|
|
|
4
|
-
const createKioskClient = (
|
|
4
|
+
const createKioskClient = (graphqlUrl: string) =>
|
|
5
5
|
new KioskClient({
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
network: Network.MAINNET,
|
|
6
|
+
client: new SuiGraphQLClient({ url: graphqlUrl, network: 'mainnet' }),
|
|
7
|
+
network: 'mainnet',
|
|
9
8
|
});
|
|
10
9
|
|
|
11
10
|
export default createKioskClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
2
2
|
|
|
3
|
-
const createSuiClient = (
|
|
3
|
+
const createSuiClient = (baseUrl: string) => new SuiGrpcClient({ network: 'mainnet', baseUrl });
|
|
4
4
|
|
|
5
5
|
export default createSuiClient;
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
2
2
|
import { normalizeStructTag, normalizeSuiObjectId } from '@mysten/sui/utils';
|
|
3
3
|
|
|
4
4
|
export const getTransferPolicyRuleNamesFromSuiObject = async ({
|
|
5
5
|
suiClient,
|
|
6
6
|
transferPolicyId,
|
|
7
7
|
}: {
|
|
8
|
-
suiClient:
|
|
8
|
+
suiClient: SuiGrpcClient;
|
|
9
9
|
transferPolicyId: string;
|
|
10
10
|
}) => {
|
|
11
|
-
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
showContent: true,
|
|
15
|
-
},
|
|
11
|
+
const { object } = await suiClient.getObject({
|
|
12
|
+
objectId: normalizeSuiObjectId(transferPolicyId),
|
|
13
|
+
include: { json: true },
|
|
16
14
|
});
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const content = data.content as unknown as {
|
|
23
|
-
fields: {
|
|
24
|
-
rules: {
|
|
25
|
-
fields: {
|
|
26
|
-
contents: Array<{ fields: { name: string } }>;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
16
|
+
const content = object.json as unknown as {
|
|
17
|
+
rules: {
|
|
18
|
+
contents: string[];
|
|
29
19
|
};
|
|
30
20
|
};
|
|
31
|
-
const ruleNames = content.
|
|
32
|
-
normalizeStructTag(rule.fields.name),
|
|
33
|
-
);
|
|
21
|
+
const ruleNames = content.rules.contents.map((rule) => normalizeStructTag(rule));
|
|
34
22
|
|
|
35
23
|
return ruleNames;
|
|
36
24
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
2
2
|
import { NON_KIOSK_LISTING_NONCE_TYPE } from '../constants';
|
|
3
3
|
import { getObjectType } from './rpc/getObjectType';
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ export const isNonKioskListing = async ({
|
|
|
6
6
|
suiClient,
|
|
7
7
|
listingNonce,
|
|
8
8
|
}: {
|
|
9
|
-
suiClient:
|
|
9
|
+
suiClient: SuiGrpcClient;
|
|
10
10
|
listingNonce: string;
|
|
11
11
|
}): Promise<boolean> => {
|
|
12
12
|
const listingType = await getObjectType({ suiClient, objectId: listingNonce });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import {
|
|
4
4
|
Transaction,
|
|
5
5
|
type TransactionArgument,
|
|
@@ -9,7 +9,7 @@ import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
|
9
9
|
|
|
10
10
|
interface Args {
|
|
11
11
|
tx: Transaction;
|
|
12
|
-
suiClient:
|
|
12
|
+
suiClient: SuiGrpcClient;
|
|
13
13
|
walletAddress: string;
|
|
14
14
|
royaltyRulePackageId: string;
|
|
15
15
|
royaltyRuleModule: string;
|
|
@@ -45,17 +45,17 @@ export async function getKioskCollectionRoyaltyFeeAmount({
|
|
|
45
45
|
typeArguments: [nftType],
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
feeTx.setSender(addLeadingZerosAfter0x(walletAddress));
|
|
49
|
+
const res = await suiClient.simulateTransaction({
|
|
50
|
+
transaction: feeTx,
|
|
51
|
+
include: { commandResults: true },
|
|
52
|
+
checksEnabled: false,
|
|
51
53
|
});
|
|
52
54
|
|
|
53
55
|
let feeAmount: TransactionArgument | bigint | undefined;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
feeAmount = BigInt(bcs.U64.parse(new Uint8Array(returnedAmount)));
|
|
58
|
-
}
|
|
56
|
+
const returnedAmount = res?.commandResults?.[0]?.returnValues?.[0]?.bcs;
|
|
57
|
+
if (returnedAmount) {
|
|
58
|
+
feeAmount = BigInt(bcs.U64.parse(returnedAmount));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
// We were not able to calculate the amount outside of the transaction, so fall back to resolving it within the PTB
|
|
@@ -8,14 +8,22 @@ export const getKioskIdFromKioskTx = ({
|
|
|
8
8
|
kioskTx: KioskTransaction;
|
|
9
9
|
tx: Transaction;
|
|
10
10
|
}): string => {
|
|
11
|
+
const kioskArg = kioskTx.kiosk as any;
|
|
12
|
+
|
|
13
|
+
if (!kioskArg || !('Input' in kioskArg)) {
|
|
14
|
+
throw new Error('Invalid kiosk transaction structure');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const input = (tx as any).getData().inputs[kioskArg.Input];
|
|
11
18
|
const kioskId =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
input?.UnresolvedObject?.objectId ??
|
|
20
|
+
input?.Object?.ImmOrOwnedObject?.objectId ??
|
|
21
|
+
input?.Object?.SharedObject?.objectId ??
|
|
22
|
+
input?.Object?.Receiving?.objectId;
|
|
23
|
+
|
|
24
|
+
if (!kioskId) {
|
|
25
|
+
throw new Error('Invalid kiosk transaction structure');
|
|
26
|
+
}
|
|
19
27
|
|
|
20
28
|
return kioskId;
|
|
21
29
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
2
2
|
import { type Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
import { splitCoins } from '../splitCoins';
|
|
4
4
|
import { getKioskCollectionRoyaltyFeeAmount } from './getKioskCollectionRoyaltyFeeAmount';
|
|
@@ -15,7 +15,7 @@ export async function getKioskPlaceBidCoin({
|
|
|
15
15
|
transferPolicyId,
|
|
16
16
|
}: {
|
|
17
17
|
tx: Transaction;
|
|
18
|
-
suiClient:
|
|
18
|
+
suiClient: SuiGrpcClient;
|
|
19
19
|
bidder: string;
|
|
20
20
|
nftType: string;
|
|
21
21
|
bidAmount: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNormalizedRuleType, type KioskClient } from '@mysten/kiosk';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import { addHexPrefix } from '../../utils/addHexPrefix';
|
|
4
4
|
import { normalizedNftType } from '../../utils/normalizeNftType';
|
|
5
5
|
import { getTransferPolicyRuleNamesFromSuiObject } from '../getTransferPolicyRuleNamesFromSuiObject';
|
|
@@ -16,7 +16,7 @@ export const getRulePackageId = async ({
|
|
|
16
16
|
suiClient,
|
|
17
17
|
}: {
|
|
18
18
|
transferPolicies: any[];
|
|
19
|
-
suiClient:
|
|
19
|
+
suiClient: SuiGrpcClient;
|
|
20
20
|
nftType: string;
|
|
21
21
|
ruleType: RuleType;
|
|
22
22
|
kioskClient: KioskClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getNormalizedRuleType, type KioskClient } from '@mysten/kiosk';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import { normalizedNftType } from '../../utils/normalizeNftType';
|
|
4
4
|
import { getTransferPolicyRuleNamesFromSuiObject } from '../getTransferPolicyRuleNamesFromSuiObject';
|
|
5
5
|
import {
|
|
@@ -23,7 +23,7 @@ export type Policy = {
|
|
|
23
23
|
|
|
24
24
|
type Props = {
|
|
25
25
|
transferPolicies: any[];
|
|
26
|
-
suiClient:
|
|
26
|
+
suiClient: SuiGrpcClient;
|
|
27
27
|
kioskClient: KioskClient;
|
|
28
28
|
nftType: string;
|
|
29
29
|
customTransferPolicies?: any;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
+
|
|
3
|
+
const PurchaseCap = bcs.struct('PurchaseCap', {
|
|
4
|
+
id: bcs.Address,
|
|
5
|
+
kiosk_id: bcs.Address,
|
|
6
|
+
item_id: bcs.Address,
|
|
7
|
+
min_price: bcs.u64(),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const KioskListing = bcs.struct('KioskListing', {
|
|
11
|
+
id: bcs.Address,
|
|
12
|
+
seller: bcs.Address,
|
|
13
|
+
kiosk_id: bcs.Address,
|
|
14
|
+
nft_id: bcs.Address,
|
|
15
|
+
cap: PurchaseCap,
|
|
16
|
+
price: bcs.u64(),
|
|
17
|
+
commission: bcs.u64(),
|
|
18
|
+
beneficiary: bcs.Address,
|
|
19
|
+
});
|
|
@@ -105,7 +105,7 @@ export const kioskTxWrapper = async ({
|
|
|
105
105
|
})
|
|
106
106
|
).personalCap.id;
|
|
107
107
|
kioskTx = new KioskTransaction({
|
|
108
|
-
|
|
108
|
+
transaction: tx,
|
|
109
109
|
kioskClient,
|
|
110
110
|
cap: {
|
|
111
111
|
isPersonal: true,
|
|
@@ -124,7 +124,7 @@ export const kioskTxWrapper = async ({
|
|
|
124
124
|
})
|
|
125
125
|
).ownerCap?.id;
|
|
126
126
|
kioskTx = new KioskTransaction({
|
|
127
|
-
|
|
127
|
+
transaction: tx,
|
|
128
128
|
kioskClient,
|
|
129
129
|
cap: {
|
|
130
130
|
isPersonal: false,
|
|
@@ -136,7 +136,7 @@ export const kioskTxWrapper = async ({
|
|
|
136
136
|
});
|
|
137
137
|
} else {
|
|
138
138
|
// creating new personal kiosk
|
|
139
|
-
kioskTx = new KioskTransaction({
|
|
139
|
+
kioskTx = new KioskTransaction({ transaction: tx, kioskClient });
|
|
140
140
|
kioskTx.createPersonal(true);
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -29,11 +29,11 @@ export const lockNftInsideKioskIfNotLocked = async ({
|
|
|
29
29
|
let takeFromKiosk = true;
|
|
30
30
|
|
|
31
31
|
if (!nftInKiosk) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
})
|
|
36
|
-
if (
|
|
32
|
+
const { object } = await (kioskClient.client as any).getObject({
|
|
33
|
+
objectId: nftTokenId,
|
|
34
|
+
include: {},
|
|
35
|
+
});
|
|
36
|
+
if (object?.owner?.$kind === 'AddressOwner') {
|
|
37
37
|
// NFT is owned by account
|
|
38
38
|
takeFromKiosk = false;
|
|
39
39
|
} else {
|
|
@@ -50,11 +50,11 @@ export const lockNftInsideKioskIfNotLocked = async ({
|
|
|
50
50
|
itemType: nftType,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
takenNftId =
|
|
53
|
+
takenNftId = (takenNft as any).value ?? takenNft;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
kioskTx.lock({
|
|
57
|
-
|
|
57
|
+
item: takenNftId ?? nftTokenId,
|
|
58
58
|
itemType: nftType,
|
|
59
59
|
policy: transferPolicyId,
|
|
60
60
|
});
|
|
@@ -75,7 +75,7 @@ function lockNftInsideKioskIfKioskCreatedInThisTx({
|
|
|
75
75
|
transferPolicyId: string;
|
|
76
76
|
}) {
|
|
77
77
|
if (Array.isArray(kioskTx.kiosk.NestedResult)) {
|
|
78
|
-
const transaction = tx.
|
|
78
|
+
const transaction = (tx as any).getData().commands[kioskTx.kiosk.NestedResult[0]] as {
|
|
79
79
|
target: string;
|
|
80
80
|
};
|
|
81
81
|
if (
|
|
@@ -86,7 +86,7 @@ function lockNftInsideKioskIfKioskCreatedInThisTx({
|
|
|
86
86
|
) {
|
|
87
87
|
// just created in this transaction block kiosk
|
|
88
88
|
kioskTx.lock({
|
|
89
|
-
|
|
89
|
+
item: nftTokenId,
|
|
90
90
|
itemType: nftType,
|
|
91
91
|
policy: transferPolicyId,
|
|
92
92
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { KioskClient } from '@mysten/kiosk';
|
|
2
2
|
import { bcs } from '@mysten/sui/bcs';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
4
4
|
import { Transaction } from '@mysten/sui/transactions';
|
|
5
5
|
import { TRADEPORT_KIOSK_LISTING_STORE } from '../../constants';
|
|
6
6
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
@@ -8,6 +8,7 @@ import { getNftType } from '../getNftType';
|
|
|
8
8
|
import { getSharedObjects } from '../getSharedObjects';
|
|
9
9
|
import { isOriginByteCollection } from '../originByte/isOriginByteCollection';
|
|
10
10
|
import { getTransferPoliciesToResolve } from './getTransferPoliciesToResolve';
|
|
11
|
+
import { KioskListing } from './kioskListingBcs';
|
|
11
12
|
|
|
12
13
|
export type SharedBulkBuyingDataByNftType = Record<
|
|
13
14
|
string,
|
|
@@ -26,7 +27,7 @@ export const preProcessSharedBulkBuyingData = async ({
|
|
|
26
27
|
walletAddress,
|
|
27
28
|
}: {
|
|
28
29
|
listings: any[];
|
|
29
|
-
suiClient:
|
|
30
|
+
suiClient: SuiGrpcClient;
|
|
30
31
|
kioskClient: KioskClient;
|
|
31
32
|
walletAddress: string;
|
|
32
33
|
}) => {
|
|
@@ -103,18 +104,25 @@ export const preProcessSharedBulkBuyingData = async ({
|
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
feeTx.setSender(addLeadingZerosAfter0x(walletAddress));
|
|
108
|
+
const res = await suiClient.simulateTransaction({
|
|
109
|
+
transaction: feeTx,
|
|
110
|
+
include: { commandResults: true },
|
|
111
|
+
checksEnabled: false,
|
|
109
112
|
});
|
|
110
113
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
const
|
|
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));
|
|
115
123
|
|
|
116
124
|
if (!feeAmount && feeAmount !== 0n) {
|
|
117
|
-
// We were not able to calculate the fee amount outside of the transaction via
|
|
125
|
+
// We were not able to calculate the fee amount outside of the transaction via simulation, so skip pre processing
|
|
118
126
|
continue;
|
|
119
127
|
}
|
|
120
128
|
|
|
@@ -130,19 +138,23 @@ export const preProcessSharedBulkBuyingData = async ({
|
|
|
130
138
|
for (let i = 0; i < tradeportLegacyKioskListings.length; i += batchSize) {
|
|
131
139
|
const batch = tradeportLegacyKioskListings.slice(i, i + batchSize);
|
|
132
140
|
const batchPromises = batch.map(async (listing: any) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 {
|
|
139
156
|
throw new Error(`Not found kiosk listing object of token ${listing.nft.token_id}`);
|
|
140
157
|
}
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
listingId: listing.id,
|
|
144
|
-
commission: Number((response.data.content as any).fields.commission),
|
|
145
|
-
};
|
|
146
158
|
});
|
|
147
159
|
|
|
148
160
|
const batchResults = await Promise.all(batchPromises);
|