@tradeport/sui-trading-sdk 0.0.1 → 0.0.2
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.js +87 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -55
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/helpers/hasRoyaltyRule.ts +4 -9
- package/src/helpers/hasTransferPolicyRules.ts +3 -18
- package/src/helpers/kiosk/getKioskTransferPolicies.ts +16 -0
- package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +29 -17
package/dist/index.mjs
CHANGED
|
@@ -291,27 +291,50 @@ var getSharedObjects = async (nftType) => {
|
|
|
291
291
|
};
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
-
// src/
|
|
295
|
-
import {
|
|
296
|
-
var
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
294
|
+
// src/graphql/queries/fetchTransferPoliciesByType.ts
|
|
295
|
+
import { gql as gql6 } from "graphql-request";
|
|
296
|
+
var fetchTransferPoliciesByType = gql6`
|
|
297
|
+
query fetchTransferPoliciesByType($type: String!) {
|
|
298
|
+
transfer_policies_by_type(type: $type) {
|
|
299
|
+
id
|
|
300
|
+
is_origin_byte
|
|
301
|
+
rules
|
|
302
|
+
type
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
`;
|
|
302
306
|
|
|
303
|
-
// src/helpers/
|
|
304
|
-
var
|
|
307
|
+
// src/helpers/kiosk/getKioskTransferPolicies.ts
|
|
308
|
+
var getKioskTransferPolicies = async (nftType) => {
|
|
305
309
|
const nftTypeSplit = nftType?.split("::");
|
|
306
310
|
if (nftTypeSplit?.[0])
|
|
307
311
|
nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
|
|
308
|
-
const res = await
|
|
309
|
-
|
|
312
|
+
const res = await gqlChainRequest({
|
|
313
|
+
chain: "sui",
|
|
314
|
+
query: fetchTransferPoliciesByType,
|
|
315
|
+
variables: { type: nftTypeSplit?.join("::") }
|
|
316
|
+
});
|
|
317
|
+
return res?.transfer_policies_by_type?.filter((policy) => !policy?.is_origin_byte);
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/helpers/hasTransferPolicyRules.ts
|
|
321
|
+
var hasTransferPolicyRules = async (nftType) => {
|
|
322
|
+
const transferPolicies = await getKioskTransferPolicies(nftType);
|
|
323
|
+
return transferPolicies?.some((policy) => policy?.rules?.length > 0);
|
|
310
324
|
};
|
|
311
325
|
|
|
312
326
|
// src/helpers/kiosk/getRulePackageId.ts
|
|
313
327
|
import { getNormalizedRuleType } from "@mysten/kiosk";
|
|
314
328
|
|
|
329
|
+
// src/apiClients/kioskClient.ts
|
|
330
|
+
import { KioskClient, Network } from "@mysten/kiosk";
|
|
331
|
+
var kioskClient = new KioskClient({
|
|
332
|
+
// @ts-ignore
|
|
333
|
+
client: suiClient_default,
|
|
334
|
+
network: Network.MAINNET
|
|
335
|
+
});
|
|
336
|
+
var kioskClient_default = kioskClient;
|
|
337
|
+
|
|
315
338
|
// src/utils/addHexPrefix.ts
|
|
316
339
|
function addHexPrefix(input) {
|
|
317
340
|
if (input.startsWith("0x")) {
|
|
@@ -346,8 +369,8 @@ var isTradePortKioskBid = (bidType) => bidType === TRADEPORT_KIOSK_BID_NONCE_TYP
|
|
|
346
369
|
import { KioskTransaction } from "@mysten/kiosk";
|
|
347
370
|
|
|
348
371
|
// src/graphql/queries/fetchKiosksByOwner.ts
|
|
349
|
-
import { gql as
|
|
350
|
-
var fetchKiosksByOwner =
|
|
372
|
+
import { gql as gql7 } from "graphql-request";
|
|
373
|
+
var fetchKiosksByOwner = gql7`
|
|
351
374
|
query fetchKiosksByOwner($ownerAddress: String!) {
|
|
352
375
|
kiosks: kiosks_by_owner_address(owner_address: $ownerAddress) {
|
|
353
376
|
id
|
|
@@ -360,8 +383,8 @@ var fetchKiosksByOwner = gql6`
|
|
|
360
383
|
`;
|
|
361
384
|
|
|
362
385
|
// src/graphql/queries/fetchOwnerCapByKiosk.ts
|
|
363
|
-
import { gql as
|
|
364
|
-
var fetchOwnerCapByKiosk =
|
|
386
|
+
import { gql as gql8 } from "graphql-request";
|
|
387
|
+
var fetchOwnerCapByKiosk = gql8`
|
|
365
388
|
query fetchOwnerCapByKiosk($kioskId: String!) {
|
|
366
389
|
ownerCap: kiosk_owner_cap_by_kiosk(kiosk_id: $kioskId) {
|
|
367
390
|
id
|
|
@@ -371,8 +394,8 @@ var fetchOwnerCapByKiosk = gql7`
|
|
|
371
394
|
`;
|
|
372
395
|
|
|
373
396
|
// src/graphql/queries/fetchPersonalCapByKiosk.ts
|
|
374
|
-
import { gql as
|
|
375
|
-
var fetchPersonalCapByKiosk =
|
|
397
|
+
import { gql as gql9 } from "graphql-request";
|
|
398
|
+
var fetchPersonalCapByKiosk = gql9`
|
|
376
399
|
query fetchPersonalCapByKiosk($kioskId: String!) {
|
|
377
400
|
personalCap: personal_kiosk_cap_by_kiosk(kiosk_id: $kioskId) {
|
|
378
401
|
id
|
|
@@ -489,8 +512,8 @@ var createOBKiosk = async ({ txBlock, createMethod = "new" }) => {
|
|
|
489
512
|
};
|
|
490
513
|
|
|
491
514
|
// src/helpers/originByte/getOBKiosk.ts
|
|
492
|
-
import { gql as
|
|
493
|
-
var fetchAccountKiosks =
|
|
515
|
+
import { gql as gql10 } from "graphql-request";
|
|
516
|
+
var fetchAccountKiosks = gql10`
|
|
494
517
|
query fetchAccountKiosks($accountAddress: String!) {
|
|
495
518
|
kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
|
|
496
519
|
id
|
|
@@ -1518,8 +1541,8 @@ var acceptCollectionBid = async ({
|
|
|
1518
1541
|
import { TransactionBlock as TransactionBlock2 } from "@mysten/sui.js/transactions";
|
|
1519
1542
|
|
|
1520
1543
|
// src/graphql/queries/fetchBidsById.ts
|
|
1521
|
-
import { gql as
|
|
1522
|
-
var fetchBidsById =
|
|
1544
|
+
import { gql as gql11 } from "graphql-request";
|
|
1545
|
+
var fetchBidsById = gql11`
|
|
1523
1546
|
query fetchBidsById($bidIds: [uuid!]) {
|
|
1524
1547
|
bids(where: { id: { _in: $bidIds } }) {
|
|
1525
1548
|
nonce
|
|
@@ -1607,8 +1630,8 @@ var acceptNftBids = async ({ bidIds }) => {
|
|
|
1607
1630
|
import { TransactionBlock as TransactionBlock3 } from "@mysten/sui.js/transactions";
|
|
1608
1631
|
|
|
1609
1632
|
// src/graphql/queries/fetchListingsById.ts
|
|
1610
|
-
import { gql as
|
|
1611
|
-
var fetchListingsById =
|
|
1633
|
+
import { gql as gql12 } from "graphql-request";
|
|
1634
|
+
var fetchListingsById = gql12`
|
|
1612
1635
|
query fetchListingsById($listingIds: [uuid!]) {
|
|
1613
1636
|
listings(where: { id: { _in: $listingIds } }) {
|
|
1614
1637
|
seller
|
|
@@ -1643,8 +1666,8 @@ var addThirdPartyTxFee = async (txBlock, price) => {
|
|
|
1643
1666
|
};
|
|
1644
1667
|
|
|
1645
1668
|
// src/graphql/queries/fetchCommissionByListingId.ts
|
|
1646
|
-
import { gql as
|
|
1647
|
-
var fetchCommissionByNftContractId =
|
|
1669
|
+
import { gql as gql13 } from "graphql-request";
|
|
1670
|
+
var fetchCommissionByNftContractId = gql13`
|
|
1648
1671
|
query fetchCommissionByNftContractId($nftContractId: uuid!) {
|
|
1649
1672
|
commissions(where: { contract_id: { _eq: $nftContractId } }) {
|
|
1650
1673
|
is_custodial
|
|
@@ -2673,8 +2696,8 @@ var listNfts = async ({ nfts, walletAddress }) => {
|
|
|
2673
2696
|
import { TransactionBlock as TransactionBlock6 } from "@mysten/sui.js/transactions";
|
|
2674
2697
|
|
|
2675
2698
|
// src/graphql/queries/fetchCollectionsById.ts
|
|
2676
|
-
import { gql as
|
|
2677
|
-
var fetchCollectionsById =
|
|
2699
|
+
import { gql as gql14 } from "graphql-request";
|
|
2700
|
+
var fetchCollectionsById = gql14`
|
|
2678
2701
|
query fetchCollectionsById($collectionIds: [uuid!]) {
|
|
2679
2702
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
2680
2703
|
id
|
|
@@ -2684,7 +2707,7 @@ var fetchCollectionsById = gql13`
|
|
|
2684
2707
|
}
|
|
2685
2708
|
}
|
|
2686
2709
|
`;
|
|
2687
|
-
var fetchCollectionsByIdWithOneNft =
|
|
2710
|
+
var fetchCollectionsByIdWithOneNft = gql14`
|
|
2688
2711
|
query fetchCollectionsByIdWithOneNft($collectionIds: [uuid!]) {
|
|
2689
2712
|
collections(where: { id: { _in: $collectionIds } }) {
|
|
2690
2713
|
id
|
|
@@ -2719,12 +2742,9 @@ var getTradeportBiddingContractBidAmount = ({ bidAmount, collectionId }) => {
|
|
|
2719
2742
|
|
|
2720
2743
|
// src/helpers/hasRoyaltyRule.ts
|
|
2721
2744
|
var hasRoyaltyRule = async (nftType) => {
|
|
2722
|
-
const
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
const res = await kioskClient_default.getTransferPolicies({ type: nftTypeSplit?.join("::") });
|
|
2726
|
-
return res?.some(
|
|
2727
|
-
(policy) => policy?.rules?.filter((rule) => rule?.includes("royalty_rule"))?.length > 0
|
|
2745
|
+
const transferPolicies = await getKioskTransferPolicies(nftType);
|
|
2746
|
+
return transferPolicies?.some(
|
|
2747
|
+
(policy) => policy?.rules?.filter((rule) => rule?.type?.includes("royalty_rule"))?.length > 0
|
|
2728
2748
|
);
|
|
2729
2749
|
};
|
|
2730
2750
|
|
|
@@ -2757,36 +2777,48 @@ function addTradePortKioskCollectionBidTx({
|
|
|
2757
2777
|
nftType,
|
|
2758
2778
|
bidAmount,
|
|
2759
2779
|
sharedObjects,
|
|
2760
|
-
bidder,
|
|
2761
2780
|
royaltyRulePackageId,
|
|
2762
2781
|
royaltyRuleModule
|
|
2763
2782
|
}) {
|
|
2764
2783
|
const { transferPolicy } = sharedObjects;
|
|
2765
|
-
const marketFeePrice = getMarketFeePrice({
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2784
|
+
const marketFeePrice = getMarketFeePrice({
|
|
2785
|
+
price: bidAmount,
|
|
2786
|
+
collectionId
|
|
2787
|
+
});
|
|
2788
|
+
let coin;
|
|
2789
|
+
if (royaltyRulePackageId && royaltyRuleModule) {
|
|
2790
|
+
const fee = txBlock.moveCall({
|
|
2791
|
+
target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
|
|
2792
|
+
arguments: [txBlock.object(transferPolicy), txBlock.pure(bidAmount)],
|
|
2793
|
+
typeArguments: [nftType]
|
|
2794
|
+
});
|
|
2795
|
+
const [coin1, coin2] = splitCoins({
|
|
2796
|
+
txBlock,
|
|
2797
|
+
amounts: [txBlock.pure(bidAmount + marketFeePrice), txBlock.object(fee)]
|
|
2798
|
+
});
|
|
2799
|
+
coin = coin1;
|
|
2800
|
+
if (!coin1 || !coin2)
|
|
2801
|
+
throw new Error("Coin could not be split");
|
|
2802
|
+
txBlock.mergeCoins(txBlock.object(coin1), [txBlock.object(coin2)]);
|
|
2803
|
+
} else {
|
|
2804
|
+
const [coin1] = splitCoins({
|
|
2805
|
+
txBlock,
|
|
2806
|
+
amounts: [txBlock.pure(bidAmount + marketFeePrice)]
|
|
2807
|
+
});
|
|
2808
|
+
coin = coin1;
|
|
2809
|
+
}
|
|
2778
2810
|
txBlock.moveCall({
|
|
2779
2811
|
target: "0x33a9e4a3089d911c2a2bf16157a1d6a4a8cbd9a2106a98ecbaefe6ed370d7a25::kiosk_biddings::collection_bid",
|
|
2780
2812
|
arguments: [
|
|
2781
2813
|
txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
|
|
2782
2814
|
txBlock.pure(bidAmount),
|
|
2783
|
-
txBlock.object(
|
|
2815
|
+
txBlock.object(coin),
|
|
2784
2816
|
txBlock.pure(marketFeePrice),
|
|
2785
2817
|
txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS)
|
|
2786
2818
|
],
|
|
2787
2819
|
typeArguments: [nftType]
|
|
2788
2820
|
});
|
|
2789
|
-
destroyZeroCoin({ txBlock, coin
|
|
2821
|
+
destroyZeroCoin({ txBlock, coin });
|
|
2790
2822
|
}
|
|
2791
2823
|
async function addOriginByteCollectionBidTx({
|
|
2792
2824
|
txBlock,
|
|
@@ -3289,8 +3321,8 @@ var removeNftBids = async ({ bidIds }) => {
|
|
|
3289
3321
|
import { TransactionBlock as TransactionBlock10 } from "@mysten/sui.js/transactions";
|
|
3290
3322
|
|
|
3291
3323
|
// src/graphql/queries/fetchCryptoToUsdRate.ts
|
|
3292
|
-
import { gql as
|
|
3293
|
-
var fetchCryptoToUsdRate =
|
|
3324
|
+
import { gql as gql15 } from "graphql-request";
|
|
3325
|
+
var fetchCryptoToUsdRate = gql15`
|
|
3294
3326
|
query fetchCryptoToUsdRate($crypto: String!) {
|
|
3295
3327
|
crypto_rates(where: { crypto: { _eq: $crypto }, fiat: { _eq: "USD" } }) {
|
|
3296
3328
|
crypto
|
|
@@ -3328,8 +3360,8 @@ var addOneDollarFee = async (txBlock) => {
|
|
|
3328
3360
|
};
|
|
3329
3361
|
|
|
3330
3362
|
// src/graphql/queries/fetchAccountKiosks.ts
|
|
3331
|
-
import { gql as
|
|
3332
|
-
var fetchAccountKiosks2 =
|
|
3363
|
+
import { gql as gql16 } from "graphql-request";
|
|
3364
|
+
var fetchAccountKiosks2 = gql16`
|
|
3333
3365
|
query fetchAccountKiosks($accountAddress: String!) {
|
|
3334
3366
|
kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
|
|
3335
3367
|
id
|