@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/package.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { addLeadingZerosAfter0x } from '../utils/addLeadingZerosAfter0x';
|
|
1
|
+
import { getKioskTransferPolicies } from './kiosk/getKioskTransferPolicies';
|
|
3
2
|
|
|
4
3
|
export const hasRoyaltyRule = async (nftType: string): Promise<boolean> => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const res = await kioskClient.getTransferPolicies({ type: nftTypeSplit?.join('::') });
|
|
9
|
-
|
|
10
|
-
return res?.some(
|
|
4
|
+
const transferPolicies = await getKioskTransferPolicies(nftType);
|
|
5
|
+
return transferPolicies?.some(
|
|
11
6
|
(policy: any) =>
|
|
12
|
-
policy?.rules?.filter((rule: any) => rule?.includes('royalty_rule'))?.length > 0,
|
|
7
|
+
policy?.rules?.filter((rule: any) => rule?.type?.includes('royalty_rule'))?.length > 0,
|
|
13
8
|
);
|
|
14
9
|
};
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { addLeadingZerosAfter0x } from '../utils/addLeadingZerosAfter0x';
|
|
1
|
+
import { getKioskTransferPolicies } from './kiosk/getKioskTransferPolicies';
|
|
3
2
|
|
|
4
3
|
export const hasTransferPolicyRules = async (nftType: string): Promise<boolean> => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// const res = await gqlChainRequest({
|
|
9
|
-
// chain: 'sui',
|
|
10
|
-
// query: fetchTransferPoliciesByType,
|
|
11
|
-
// variables: { type: nftTypeSplit?.join('::') },
|
|
12
|
-
// });
|
|
13
|
-
|
|
14
|
-
// return res?.transfer_policies_by_type
|
|
15
|
-
// ?.filter((policy: any) => !policy?.is_origin_byte)
|
|
16
|
-
// ?.some((policy: any) => policy?.rules?.length > 0);
|
|
17
|
-
|
|
18
|
-
const res = await kioskClient.getTransferPolicies({ type: nftTypeSplit?.join('::') });
|
|
19
|
-
|
|
20
|
-
return res?.some((policy: any) => policy?.rules?.length > 0);
|
|
4
|
+
const transferPolicies = await getKioskTransferPolicies(nftType);
|
|
5
|
+
return transferPolicies?.some((policy: any) => policy?.rules?.length > 0);
|
|
21
6
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
2
|
+
import { fetchTransferPoliciesByType } from '../../graphql/queries/fetchTransferPoliciesByType';
|
|
3
|
+
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
4
|
+
|
|
5
|
+
export const getKioskTransferPolicies = async (nftType: string) => {
|
|
6
|
+
const nftTypeSplit = nftType?.split('::');
|
|
7
|
+
if (nftTypeSplit?.[0]) nftTypeSplit[0] = addLeadingZerosAfter0x(nftTypeSplit[0]);
|
|
8
|
+
|
|
9
|
+
const res = await gqlChainRequest({
|
|
10
|
+
chain: 'sui',
|
|
11
|
+
query: fetchTransferPoliciesByType,
|
|
12
|
+
variables: { type: nftTypeSplit?.join('::') },
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
return res?.transfer_policies_by_type?.filter((policy: any) => !policy?.is_origin_byte);
|
|
16
|
+
};
|
|
@@ -44,28 +44,40 @@ export function addTradePortKioskCollectionBidTx({
|
|
|
44
44
|
nftType,
|
|
45
45
|
bidAmount,
|
|
46
46
|
sharedObjects,
|
|
47
|
-
bidder,
|
|
48
47
|
royaltyRulePackageId,
|
|
49
48
|
royaltyRuleModule,
|
|
50
49
|
}: PlaceCollectionBidTx) {
|
|
51
50
|
const { transferPolicy } = sharedObjects;
|
|
52
51
|
|
|
53
|
-
const marketFeePrice = getMarketFeePrice({
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
|
|
57
|
-
arguments: [txBlock.object(transferPolicy), txBlock.pure(bidAmount)],
|
|
58
|
-
typeArguments: [nftType],
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const [coin1, coin2] = splitCoins({
|
|
62
|
-
txBlock,
|
|
63
|
-
amounts: [txBlock.pure(bidAmount + marketFeePrice), txBlock.object(fee)],
|
|
52
|
+
const marketFeePrice = getMarketFeePrice({
|
|
53
|
+
price: bidAmount,
|
|
54
|
+
collectionId,
|
|
64
55
|
});
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
let coin;
|
|
58
|
+
if (royaltyRulePackageId && royaltyRuleModule) {
|
|
59
|
+
const fee = txBlock.moveCall({
|
|
60
|
+
target: `${royaltyRulePackageId}::${royaltyRuleModule}::fee_amount`,
|
|
61
|
+
arguments: [txBlock.object(transferPolicy), txBlock.pure(bidAmount)],
|
|
62
|
+
typeArguments: [nftType],
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const [coin1, coin2] = splitCoins({
|
|
66
|
+
txBlock,
|
|
67
|
+
amounts: [txBlock.pure(bidAmount + marketFeePrice), txBlock.object(fee)],
|
|
68
|
+
});
|
|
69
|
+
coin = coin1;
|
|
70
|
+
|
|
71
|
+
if (!coin1 || !coin2) throw new Error('Coin could not be split');
|
|
72
|
+
|
|
73
|
+
txBlock.mergeCoins(txBlock.object(coin1), [txBlock.object(coin2)]);
|
|
74
|
+
} else {
|
|
75
|
+
const [coin1] = splitCoins({
|
|
76
|
+
txBlock,
|
|
77
|
+
amounts: [txBlock.pure(bidAmount + marketFeePrice)],
|
|
78
|
+
});
|
|
79
|
+
coin = coin1;
|
|
80
|
+
}
|
|
69
81
|
|
|
70
82
|
txBlock.moveCall({
|
|
71
83
|
target:
|
|
@@ -73,14 +85,14 @@ export function addTradePortKioskCollectionBidTx({
|
|
|
73
85
|
arguments: [
|
|
74
86
|
txBlock.object(TRADEPORT_KIOSK_BIDDING_STORE),
|
|
75
87
|
txBlock.pure(bidAmount),
|
|
76
|
-
txBlock.object(
|
|
88
|
+
txBlock.object(coin),
|
|
77
89
|
txBlock.pure(marketFeePrice),
|
|
78
90
|
txBlock.pure(TRADEPORT_BENEFICIARY_ADDRESS),
|
|
79
91
|
],
|
|
80
92
|
typeArguments: [nftType],
|
|
81
93
|
});
|
|
82
94
|
|
|
83
|
-
destroyZeroCoin({ txBlock, coin
|
|
95
|
+
destroyZeroCoin({ txBlock, coin });
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
export async function addOriginByteCollectionBidTx({
|