@tradeport/sui-trading-sdk 0.0.0
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/.babel.config.js +3 -0
- package/.env.demo +4 -0
- package/.eslintrc.json +46 -0
- package/.prettierignore +4 -0
- package/.prettierrc.json +7 -0
- package/README.md +1 -0
- package/dist/index.d.mts +90 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +3760 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3733 -0
- package/dist/index.mjs.map +1 -0
- package/jest.config.js +7 -0
- package/package.json +45 -0
- package/src/SuiTradingClient.ts +158 -0
- package/src/apiClients/graphqlClient.ts +5 -0
- package/src/apiClients/kioskClient.ts +10 -0
- package/src/apiClients/suiClient.ts +5 -0
- package/src/constants.ts +74 -0
- package/src/graphql/createChainGQLQuery.ts +25 -0
- package/src/graphql/gqlChainRequest.ts +20 -0
- package/src/graphql/queries/fetchAccountKiosks.ts +12 -0
- package/src/graphql/queries/fetchBidsById.ts +28 -0
- package/src/graphql/queries/fetchCollectionBidById.ts +20 -0
- package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +28 -0
- package/src/graphql/queries/fetchCollectionsById.ts +30 -0
- package/src/graphql/queries/fetchCommissionByListingId.ts +13 -0
- package/src/graphql/queries/fetchCryptoToUsdRate.ts +13 -0
- package/src/graphql/queries/fetchKiosksByOwner.ts +13 -0
- package/src/graphql/queries/fetchListingsById.ts +24 -0
- package/src/graphql/queries/fetchListingsByNftId.ts +23 -0
- package/src/graphql/queries/fetchNftsById.ts +61 -0
- package/src/graphql/queries/fetchOwnerCapByKiosk.ts +10 -0
- package/src/graphql/queries/fetchPersonalCapByKiosk.ts +10 -0
- package/src/graphql/queries/fetchSharedObjectsByType.ts +12 -0
- package/src/graphql/queries/fetchTransferPoliciesByType.ts +12 -0
- package/src/graphql/queries/getCommissionByListingId.ts +15 -0
- package/src/helpers/addOneDollarFee.ts +17 -0
- package/src/helpers/addThirdPartyTxFee.ts +17 -0
- package/src/helpers/destroyZeroCoin.ts +14 -0
- package/src/helpers/getMarketFeePrice.ts +78 -0
- package/src/helpers/getNftTypeFromNft.ts +8 -0
- package/src/helpers/getSharedObjects.ts +113 -0
- package/src/helpers/getSuiToUsdRate.ts +17 -0
- package/src/helpers/getTradeportBiddingContractParsedBidAmount.ts +32 -0
- package/src/helpers/hasRoyaltyRule.ts +14 -0
- package/src/helpers/hasTransferPolicyRules.ts +21 -0
- package/src/helpers/isNonKioskListing.ts +7 -0
- package/src/helpers/kiosk/getRulePackageId.ts +26 -0
- package/src/helpers/kiosk/isBluemoveKioskBid.ts +1 -0
- package/src/helpers/kiosk/isTradePortKioskBid.ts +4 -0
- package/src/helpers/kiosk/kioskTxWrapper.ts +102 -0
- package/src/helpers/kiosk/resolveFloorPriceRule.ts +25 -0
- package/src/helpers/kiosk/resolveKioskLockRule.ts +49 -0
- package/src/helpers/kiosk/resolvePersonalKioskRule.ts +26 -0
- package/src/helpers/kiosk/resolveRoyaltyRule.ts +41 -0
- package/src/helpers/kiosk/resolveTransferPolicies.ts +150 -0
- package/src/helpers/originByte/confirmOBTranfer.ts +33 -0
- package/src/helpers/originByte/createOBKiosk.ts +14 -0
- package/src/helpers/originByte/depositNftIntoOBKiosk.ts +14 -0
- package/src/helpers/originByte/getOBBidderKiosk.ts +9 -0
- package/src/helpers/originByte/getOBKiosk.ts +24 -0
- package/src/helpers/originByte/getOrCreateOBKiosk.ts +37 -0
- package/src/helpers/originByte/isOBKiosk.ts +13 -0
- package/src/helpers/originByte/isOriginByteBid.ts +6 -0
- package/src/helpers/originByte/isOriginByteTx.ts +2 -0
- package/src/helpers/originByte/shareOriginByteKiosk.ts +14 -0
- package/src/helpers/rpc/getAcountBalance.ts +17 -0
- package/src/helpers/rpc/getObjectType.ts +10 -0
- package/src/helpers/splitCoins.ts +12 -0
- package/src/index.ts +3 -0
- package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +119 -0
- package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +359 -0
- package/src/methods/acceptNftBids/acceptNftBids.ts +100 -0
- package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +214 -0
- package/src/methods/buyListings/addBuyListingTxs.ts +503 -0
- package/src/methods/buyListings/buyListings.ts +143 -0
- package/src/methods/claimNfts/addClaimNftsTxs.ts +104 -0
- package/src/methods/claimNfts/claimNfts.ts +139 -0
- package/src/methods/listNfts/addListTxs.ts +186 -0
- package/src/methods/listNfts/addRelistTxs.ts +79 -0
- package/src/methods/listNfts/listNfts.ts +80 -0
- package/src/methods/placeCollectionBids/addPlaceCollectionBidTxs.ts +146 -0
- package/src/methods/placeCollectionBids/placeCollectionBids.ts +120 -0
- package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +146 -0
- package/src/methods/placeNftBids/placeNftBids.ts +69 -0
- package/src/methods/relistNft/relistNft.ts +104 -0
- package/src/methods/removeCollectionBid/addRemoveCollectionBidTxs.ts +119 -0
- package/src/methods/removeCollectionBid/removeCollectionBid.ts +97 -0
- package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +84 -0
- package/src/methods/removeNftBids/removeNftBids.ts +80 -0
- package/src/methods/transferNfts/addTransferNftTx.ts +78 -0
- package/src/methods/transferNfts/transferNfts.ts +107 -0
- package/src/methods/unlistListings/addUnlistListingTxs.ts +258 -0
- package/src/methods/unlistListings/unlistListings.ts +108 -0
- package/src/methods/withdrawKioskProfits/withdrawKioskProfits.ts +25 -0
- package/src/tests/SuiWallet.ts +49 -0
- package/src/utils/addHexPrefix.ts +7 -0
- package/src/utils/addLeadingZerosAfter0x.ts +2 -0
- package/src/utils/parseSUI.ts +1 -0
- package/src/utils/printTxBlockTxs.ts +5 -0
- package/src/utils/toUint8Array.ts +12 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { getNormalizedRuleType, type ObjectArgument } from '@mysten/kiosk';
|
|
2
|
+
import { type TransactionBlock, type TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
3
|
+
import kioskClient from '../../apiClients/kioskClient';
|
|
4
|
+
import { resolveFloorPriceRule } from './resolveFloorPriceRule';
|
|
5
|
+
import { resolveKioskLockRule } from './resolveKioskLockRule';
|
|
6
|
+
import { resolvePersonalKioskRule } from './resolvePersonalKioskRule';
|
|
7
|
+
import { resolveRoyaltyRule } from './resolveRoyaltyRule';
|
|
8
|
+
|
|
9
|
+
export type Policy = {
|
|
10
|
+
data: any;
|
|
11
|
+
transferRequest: TransactionObjectArgument;
|
|
12
|
+
isCustom: boolean;
|
|
13
|
+
type?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type Props = {
|
|
17
|
+
txBlock: TransactionBlock;
|
|
18
|
+
kioskTx: any;
|
|
19
|
+
nftType: string;
|
|
20
|
+
kioskToLockRuleProve?: ObjectArgument;
|
|
21
|
+
kioskItem?: ObjectArgument;
|
|
22
|
+
transferRequest: TransactionObjectArgument;
|
|
23
|
+
customTransferPolicies?: any;
|
|
24
|
+
price?: string;
|
|
25
|
+
priceObjectArgument?: ObjectArgument;
|
|
26
|
+
shouldSkipKioskLocking?: boolean;
|
|
27
|
+
shouldSkipResolvingRoyaltyRule?: boolean;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const resolveTransferPolicies = async ({
|
|
31
|
+
txBlock,
|
|
32
|
+
kioskTx,
|
|
33
|
+
nftType,
|
|
34
|
+
kioskToLockRuleProve,
|
|
35
|
+
kioskItem,
|
|
36
|
+
transferRequest,
|
|
37
|
+
customTransferPolicies,
|
|
38
|
+
price,
|
|
39
|
+
priceObjectArgument,
|
|
40
|
+
shouldSkipKioskLocking,
|
|
41
|
+
shouldSkipResolvingRoyaltyRule,
|
|
42
|
+
}: Props) => {
|
|
43
|
+
const transferPolicies = await kioskClient.getTransferPolicies({
|
|
44
|
+
type: nftType,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
let policies: Policy[] =
|
|
48
|
+
transferPolicies.length > 0
|
|
49
|
+
? [
|
|
50
|
+
{
|
|
51
|
+
data: transferPolicies[0],
|
|
52
|
+
transferRequest,
|
|
53
|
+
isCustom: false,
|
|
54
|
+
},
|
|
55
|
+
]
|
|
56
|
+
: [];
|
|
57
|
+
|
|
58
|
+
if (customTransferPolicies) {
|
|
59
|
+
for (const customTransferPolicy of customTransferPolicies) {
|
|
60
|
+
const customPolicy = await kioskClient.getTransferPolicies({
|
|
61
|
+
type: customTransferPolicy?.type,
|
|
62
|
+
});
|
|
63
|
+
policies = [
|
|
64
|
+
...policies,
|
|
65
|
+
{
|
|
66
|
+
data: customPolicy[0],
|
|
67
|
+
transferRequest: customTransferPolicy?.transferRequest,
|
|
68
|
+
isCustom: true,
|
|
69
|
+
type: customTransferPolicy?.type,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let canTransferOutsideKiosk = true;
|
|
76
|
+
|
|
77
|
+
for (const policy of policies) {
|
|
78
|
+
for (const rule of policy.data.rules) {
|
|
79
|
+
const ruleDefinition = kioskClient.rules.find(
|
|
80
|
+
(x) => getNormalizedRuleType(x.rule) === getNormalizedRuleType(rule),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
let rulePackageId = ruleDefinition?.packageId;
|
|
84
|
+
if (!rulePackageId) {
|
|
85
|
+
rulePackageId = rule?.split('::')?.[0];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
switch (rule?.split('::')?.[1]) {
|
|
89
|
+
case 'royalty_rule':
|
|
90
|
+
case 'kiosk_royalty_rule':
|
|
91
|
+
if (shouldSkipResolvingRoyaltyRule) break;
|
|
92
|
+
resolveRoyaltyRule({
|
|
93
|
+
txBlock,
|
|
94
|
+
packageId: rulePackageId,
|
|
95
|
+
moduleName: rule?.split('::')?.[1],
|
|
96
|
+
policyId: policy.data.id,
|
|
97
|
+
transferRequest: policy.transferRequest,
|
|
98
|
+
nftType: policy.isCustom && policy.type ? policy.type : nftType,
|
|
99
|
+
price,
|
|
100
|
+
priceObjectArgument,
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
case 'kiosk_lock_rule':
|
|
104
|
+
canTransferOutsideKiosk = false;
|
|
105
|
+
resolveKioskLockRule({
|
|
106
|
+
txBlock,
|
|
107
|
+
packageId: rulePackageId,
|
|
108
|
+
policyId: policy.data.id,
|
|
109
|
+
transferRequest: policy.transferRequest,
|
|
110
|
+
nftType: policy.isCustom && policy.type ? policy.type : nftType,
|
|
111
|
+
kiosk: kioskToLockRuleProve ? kioskToLockRuleProve : kioskTx.kiosk,
|
|
112
|
+
kioskCap: kioskTx.kioskCap,
|
|
113
|
+
kioskItem,
|
|
114
|
+
shouldSkipLocking: shouldSkipKioskLocking,
|
|
115
|
+
});
|
|
116
|
+
break;
|
|
117
|
+
case 'personal_kiosk_rule':
|
|
118
|
+
resolvePersonalKioskRule({
|
|
119
|
+
txBlock,
|
|
120
|
+
packageId: rulePackageId,
|
|
121
|
+
nftType: policy.isCustom && policy.type ? policy.type : nftType,
|
|
122
|
+
kiosk: kioskTx.kiosk,
|
|
123
|
+
transferRequest: policy.transferRequest,
|
|
124
|
+
});
|
|
125
|
+
break;
|
|
126
|
+
case 'floor_price_rule':
|
|
127
|
+
resolveFloorPriceRule({
|
|
128
|
+
txBlock,
|
|
129
|
+
packageId: rulePackageId,
|
|
130
|
+
nftType: policy.isCustom && policy.type ? policy.type : nftType,
|
|
131
|
+
policyId: policy.data.id,
|
|
132
|
+
transferRequest: policy.transferRequest,
|
|
133
|
+
});
|
|
134
|
+
break;
|
|
135
|
+
default:
|
|
136
|
+
throw new Error(`No resolver for the following rule: ${rule}.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
txBlock.moveCall({
|
|
141
|
+
target: '0x2::transfer_policy::confirm_request',
|
|
142
|
+
arguments: [txBlock.object(policy.data.id), policy.transferRequest],
|
|
143
|
+
typeArguments: [policy.isCustom && policy.type ? policy.type : nftType],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (canTransferOutsideKiosk && kioskItem) {
|
|
148
|
+
kioskTx.place({ itemType: nftType, item: kioskItem });
|
|
149
|
+
}
|
|
150
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
|
|
3
|
+
type Args = {
|
|
4
|
+
txBlock: TransactionBlock;
|
|
5
|
+
sharedObjects: any;
|
|
6
|
+
transferRequest: any;
|
|
7
|
+
nftType: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const confirmOBTranfer = ({ txBlock, sharedObjects, transferRequest, nftType }: Args) => {
|
|
11
|
+
txBlock.moveCall({
|
|
12
|
+
target:
|
|
13
|
+
'0x6f42ec2355fcda5ebeee2399d901ae9f71cb214e640a45a0007f1f1cdf9f7b5e::transfer_allowlist::confirm_transfer',
|
|
14
|
+
arguments: [txBlock.object(sharedObjects?.allowList), txBlock.object(transferRequest)],
|
|
15
|
+
typeArguments: [nftType],
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (sharedObjects?.royaltyStrategy) {
|
|
19
|
+
txBlock.moveCall({
|
|
20
|
+
target:
|
|
21
|
+
'0x6f42ec2355fcda5ebeee2399d901ae9f71cb214e640a45a0007f1f1cdf9f7b5e::royalty_strategy_bps::confirm_transfer',
|
|
22
|
+
arguments: [txBlock.object(sharedObjects?.royaltyStrategy), txBlock.object(transferRequest)],
|
|
23
|
+
typeArguments: [nftType, '0x2::sui::SUI'],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
txBlock.moveCall({
|
|
28
|
+
target:
|
|
29
|
+
'0xadf32ebafc587cc86e1e56e59f7b17c7e8cbeb3315193be63c6f73157d4e88b9::transfer_request::confirm',
|
|
30
|
+
arguments: [txBlock.object(transferRequest), txBlock.object(sharedObjects?.transferPolicy)],
|
|
31
|
+
typeArguments: [nftType, '0x2::sui::SUI'],
|
|
32
|
+
});
|
|
33
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Args = {
|
|
2
|
+
txBlock: any;
|
|
3
|
+
createMethod?: string;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const createOBKiosk = async ({ txBlock, createMethod = 'new' }: Args) => {
|
|
7
|
+
const [kiosk] = txBlock.moveCall({
|
|
8
|
+
target: `0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::${createMethod}`,
|
|
9
|
+
arguments: [],
|
|
10
|
+
typeArguments: [],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return [kiosk];
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Args = {
|
|
2
|
+
txBlock: any;
|
|
3
|
+
kiosk: string;
|
|
4
|
+
nftTokenId: string;
|
|
5
|
+
nftType: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const depositItemIntoOBKiosk = ({ txBlock, kiosk, nftTokenId, nftType }: Args) => {
|
|
9
|
+
txBlock.moveCall({
|
|
10
|
+
target: '0x2678c98fe23173eebea384509464eb81b1f3035a57419cb46d025000c337451a::ob_kiosk::deposit',
|
|
11
|
+
arguments: [txBlock.object(kiosk), txBlock.pure(nftTokenId)],
|
|
12
|
+
typeArguments: [nftType],
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import suiClient from '../../apiClients/suiClient';
|
|
2
|
+
|
|
3
|
+
export const getOBBidderKiosk = async (bidNonce: string) => {
|
|
4
|
+
const bidObject = (await suiClient.call('sui_getObject', [
|
|
5
|
+
bidNonce,
|
|
6
|
+
{ showContent: true },
|
|
7
|
+
])) as any;
|
|
8
|
+
return bidObject.data?.content?.fields?.kiosk;
|
|
9
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { gql } from 'graphql-request';
|
|
2
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
3
|
+
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
4
|
+
|
|
5
|
+
const fetchAccountKiosks = gql`
|
|
6
|
+
query fetchAccountKiosks($accountAddress: String!) {
|
|
7
|
+
kiosks: kiosks_by_owner_address(owner_address: $accountAddress) {
|
|
8
|
+
id
|
|
9
|
+
is_origin_byte
|
|
10
|
+
owner_address
|
|
11
|
+
profits
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
export const getOBKiosk = async (accountAddress: string): Promise<any> => {
|
|
17
|
+
const res = await gqlChainRequest({
|
|
18
|
+
chain: 'sui',
|
|
19
|
+
query: fetchAccountKiosks,
|
|
20
|
+
variables: { accountAddress: addLeadingZerosAfter0x(accountAddress) },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return res?.kiosks?.filter((kiosk: any) => kiosk?.is_origin_byte)?.[0]?.id;
|
|
24
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createOBKiosk } from './createOBKiosk';
|
|
2
|
+
import { getOBKiosk } from './getOBKiosk';
|
|
3
|
+
|
|
4
|
+
type Args = {
|
|
5
|
+
txBlock: any;
|
|
6
|
+
address: string;
|
|
7
|
+
kioskToUseIfExists?: string;
|
|
8
|
+
createMethod?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const getOrCreateOBKiosk = async ({
|
|
12
|
+
txBlock,
|
|
13
|
+
address,
|
|
14
|
+
kioskToUseIfExists,
|
|
15
|
+
createMethod,
|
|
16
|
+
}: Args) => {
|
|
17
|
+
if (kioskToUseIfExists) {
|
|
18
|
+
return {
|
|
19
|
+
kiosk: kioskToUseIfExists,
|
|
20
|
+
isNewKiosk: false,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const existingKiosk = await getOBKiosk(address);
|
|
25
|
+
if (existingKiosk) {
|
|
26
|
+
return {
|
|
27
|
+
kiosk: existingKiosk,
|
|
28
|
+
isNewKiosk: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const [newKiosk] = await createOBKiosk({ txBlock, createMethod });
|
|
33
|
+
return {
|
|
34
|
+
kiosk: newKiosk,
|
|
35
|
+
isNewKiosk: true,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
2
|
+
import { fetchAccountKiosks } from '../../graphql/queries/fetchAccountKiosks';
|
|
3
|
+
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
4
|
+
|
|
5
|
+
export const isOBKiosk = async (accountAddress: string, kiosk: any): Promise<boolean> => {
|
|
6
|
+
const res = await gqlChainRequest({
|
|
7
|
+
chain: 'sui',
|
|
8
|
+
query: fetchAccountKiosks,
|
|
9
|
+
variables: { accountAddress: addLeadingZerosAfter0x(accountAddress) },
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
return res?.kiosks?.filter((k: any) => k?.id === kiosk)?.[0]?.is_origin_byte;
|
|
13
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
|
|
3
|
+
type Args = {
|
|
4
|
+
txBlock: TransactionBlock;
|
|
5
|
+
kiosk: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const shareOriginByteKiosk = async ({ txBlock, kiosk }: Args) => {
|
|
9
|
+
txBlock.moveCall({
|
|
10
|
+
target: '0x2::transfer::public_share_object',
|
|
11
|
+
arguments: [txBlock.object(kiosk)],
|
|
12
|
+
typeArguments: ['0x2::kiosk::Kiosk'],
|
|
13
|
+
});
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import suiClient from '../../apiClients/suiClient';
|
|
2
|
+
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
3
|
+
|
|
4
|
+
type Args = {
|
|
5
|
+
owner: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const getAccountBalance = async ({ owner }: Args): Promise<string> => {
|
|
9
|
+
try {
|
|
10
|
+
const res = await suiClient.getBalance({
|
|
11
|
+
owner: addLeadingZerosAfter0x(owner),
|
|
12
|
+
});
|
|
13
|
+
return res?.totalBalance;
|
|
14
|
+
} catch (err) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import suiClient from '../../apiClients/suiClient';
|
|
2
|
+
|
|
3
|
+
export const getObjectType = async (objectId: string): Promise<string> => {
|
|
4
|
+
try {
|
|
5
|
+
const res = await suiClient.getObject({ id: objectId, options: { showType: true } });
|
|
6
|
+
return res?.data?.type;
|
|
7
|
+
} catch (err) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
|
|
3
|
+
type Args = {
|
|
4
|
+
txBlock: TransactionBlock;
|
|
5
|
+
amounts: any;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const splitCoins = ({ txBlock, amounts }: Args) => {
|
|
9
|
+
const res = txBlock.splitCoins(txBlock.gas, amounts);
|
|
10
|
+
|
|
11
|
+
return res;
|
|
12
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
3
|
+
import { fetchNftById } from '../../graphql/queries/fetchNftsById';
|
|
4
|
+
import { getNftTypeFromNft } from '../../helpers/getNftTypeFromNft';
|
|
5
|
+
import { getSharedObjects } from '../../helpers/getSharedObjects';
|
|
6
|
+
import {
|
|
7
|
+
addBluemoveAcceptCollectionBidTxHandler,
|
|
8
|
+
addOriginByteAcceptCollectionBidTx,
|
|
9
|
+
addTocenAcceptCollectionBidTxHandler,
|
|
10
|
+
addTradePortAcceptCollectionBidTxHandler,
|
|
11
|
+
} from './addAcceptCollectionBIdTxs';
|
|
12
|
+
|
|
13
|
+
export type AcceptCollectionBidTx = {
|
|
14
|
+
txBlock: TransactionBlock;
|
|
15
|
+
sharedObjects: any;
|
|
16
|
+
kioskTx?: any;
|
|
17
|
+
bidNonce: string;
|
|
18
|
+
nftType: string;
|
|
19
|
+
nftTokenId: string;
|
|
20
|
+
listingPrice: number;
|
|
21
|
+
listingNonce: string;
|
|
22
|
+
itemOwner: string;
|
|
23
|
+
bidAmount: number;
|
|
24
|
+
bidder: string;
|
|
25
|
+
seller: string;
|
|
26
|
+
sellerKiosk: string;
|
|
27
|
+
collectionId: string;
|
|
28
|
+
isListedOnBluemove: boolean;
|
|
29
|
+
bidMarketName: string;
|
|
30
|
+
itemTakenOutOfNativeKiosk?: any;
|
|
31
|
+
royaltyRulePackageId?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type AcceptCollectionBid = {
|
|
35
|
+
bidId: string;
|
|
36
|
+
nftId: string;
|
|
37
|
+
walletAddress: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type InternalAcceptCollectionBid = {
|
|
41
|
+
bid: any;
|
|
42
|
+
nftId: string;
|
|
43
|
+
walletAddress: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const ERROR_UNLIST_FIRST =
|
|
47
|
+
'Item must be unlisted first before you can accept a collection bid with it';
|
|
48
|
+
|
|
49
|
+
export const acceptCollectionBid = async ({
|
|
50
|
+
bid,
|
|
51
|
+
nftId,
|
|
52
|
+
walletAddress,
|
|
53
|
+
}: InternalAcceptCollectionBid): Promise<TransactionBlock> => {
|
|
54
|
+
const nftRes = await gqlChainRequest({
|
|
55
|
+
chain: 'sui',
|
|
56
|
+
query: fetchNftById,
|
|
57
|
+
variables: { nftId },
|
|
58
|
+
});
|
|
59
|
+
const nft = nftRes?.nfts?.[0];
|
|
60
|
+
|
|
61
|
+
if (!nft) {
|
|
62
|
+
throw new Error('No nft found');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const txBlock = new TransactionBlock();
|
|
66
|
+
|
|
67
|
+
const sharedObjects = await getSharedObjects(
|
|
68
|
+
nft?.properties?.nft_type || nft?.contract?.properties?.nft_type,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const txData: AcceptCollectionBidTx = {
|
|
72
|
+
txBlock,
|
|
73
|
+
sharedObjects,
|
|
74
|
+
bidNonce: bid?.nonce,
|
|
75
|
+
nftType: getNftTypeFromNft(nft),
|
|
76
|
+
nftTokenId: nft?.token_id,
|
|
77
|
+
itemOwner: nft?.owner,
|
|
78
|
+
listingPrice: nft?.listings?.[0]?.price,
|
|
79
|
+
listingNonce: nft?.listings?.[0]?.nonce,
|
|
80
|
+
bidAmount: bid?.price,
|
|
81
|
+
bidder: bid?.bidder,
|
|
82
|
+
seller: walletAddress,
|
|
83
|
+
sellerKiosk: nft?.chain_state?.kiosk_id,
|
|
84
|
+
collectionId: nft?.collection_id,
|
|
85
|
+
isListedOnBluemove: nft?.listings?.[0]?.market_name === 'bluemove',
|
|
86
|
+
bidMarketName: bid?.market_contract?.name,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
switch (txData.bidMarketName) {
|
|
90
|
+
case 'tradeport':
|
|
91
|
+
if (txData?.listingPrice && txData?.listingPrice > 0) {
|
|
92
|
+
throw new Error(ERROR_UNLIST_FIRST);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
await addTradePortAcceptCollectionBidTxHandler(txData);
|
|
96
|
+
break;
|
|
97
|
+
case 'clutchy':
|
|
98
|
+
await addOriginByteAcceptCollectionBidTx(txData);
|
|
99
|
+
break;
|
|
100
|
+
case 'bluemove':
|
|
101
|
+
if (txData?.listingPrice && txData?.listingPrice > 0 && !txData?.isListedOnBluemove) {
|
|
102
|
+
throw new Error(ERROR_UNLIST_FIRST);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
await addBluemoveAcceptCollectionBidTxHandler(txData);
|
|
106
|
+
break;
|
|
107
|
+
case 'tocen':
|
|
108
|
+
if (txData?.listingPrice && txData?.listingPrice > 0) {
|
|
109
|
+
throw new Error(ERROR_UNLIST_FIRST);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addTocenAcceptCollectionBidTxHandler(txData);
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
throw new Error('Marketplace not supported');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return new TransactionBlock(txBlock);
|
|
119
|
+
};
|