@tradeport/sui-trading-sdk 0.3.8 → 0.4.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +38 -2
- package/dist/index.d.ts +38 -2
- package/dist/index.js +409 -350
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +409 -350
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SuiTradingClient.ts +23 -2
- package/src/constants.ts +11 -0
- package/src/graphql/queries/fetchBidsById.ts +1 -0
- package/src/graphql/queries/fetchCollectionBidById.ts +1 -0
- package/src/graphql/queries/fetchCollectionBidsAtSamePrice.ts +1 -0
- package/src/graphql/queries/fetchMultibidById.ts +10 -0
- package/src/helpers/isSIngleBid.ts +13 -0
- package/src/helpers/kiosk/getKioskTransferPolicies.ts +7 -0
- package/src/helpers/kiosk/kioskTxWrapper.ts +8 -5
- package/src/methods/acceptCollectionBid/acceptCollectionBid.ts +2 -0
- package/src/methods/acceptCollectionBid/addAcceptCollectionBIdTxs.ts +10 -1
- package/src/methods/acceptNftBids/acceptNftBids.ts +3 -0
- package/src/methods/acceptNftBids/addAcceptNftBidTxs.ts +94 -1
- package/src/methods/cancelMultiBid/cancelMultiBid.ts +35 -0
- package/src/methods/createMultiBid/createMultiBid.ts +35 -0
- package/src/methods/placeCollectionBids/placeCollectionBids.ts +26 -11
- package/src/methods/placeNftBids/addPlaceNftBidTxs.ts +100 -230
- package/src/methods/placeNftBids/placeNftBids.ts +21 -14
- package/src/methods/removeCollectionBids/addRemoveCollectionBidsTxs.ts +10 -1
- package/src/methods/removeNftBids/addRemoveNftBidTxs.ts +30 -0
- package/src/methods/removeNftBids/removeNftBids.ts +2 -0
- package/src/methods/updateMultiBid/updateMultiBid.ts +59 -0
- package/src/tests/SuiWallet.ts +1 -1
package/package.json
CHANGED
package/src/SuiTradingClient.ts
CHANGED
|
@@ -63,6 +63,9 @@ import {
|
|
|
63
63
|
type WithdrawProfitsFromKiosks,
|
|
64
64
|
} from './methods/withdrawProfitsFromKiosks/withdrawProfitsFromKiosks';
|
|
65
65
|
import { addLeadingZerosAfter0x } from './utils/addLeadingZerosAfter0x';
|
|
66
|
+
import { createMultiBid, type CreateMultiBid } from './methods/createMultiBid/createMultiBid';
|
|
67
|
+
import { cancelMultiBid, type CancelMultiBid } from './methods/cancelMultiBid/cancelMultiBid';
|
|
68
|
+
import { updateMultiBid, type UpdateMultiBid } from './methods/updateMultiBid/updateMultiBid';
|
|
66
69
|
|
|
67
70
|
type ApiConfig = {
|
|
68
71
|
apiUser: string;
|
|
@@ -135,7 +138,7 @@ class SuiTradingClient {
|
|
|
135
138
|
return unlistListings({ listingIds, walletAddress }, context);
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
public async placeNftBids(
|
|
141
|
+
public async placeNftBids(data: PlaceNftBids) {
|
|
139
142
|
const context: RequestContext = {
|
|
140
143
|
apiUser: this.apiUser,
|
|
141
144
|
apiKey: this.apiKey,
|
|
@@ -143,7 +146,7 @@ class SuiTradingClient {
|
|
|
143
146
|
kioskClient: this.kioskClient,
|
|
144
147
|
};
|
|
145
148
|
|
|
146
|
-
return placeNftBids(
|
|
149
|
+
return placeNftBids(data, context);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
public async removeNftBids({ bidIds, tx }: RemoveNftBids) {
|
|
@@ -173,6 +176,9 @@ class SuiTradingClient {
|
|
|
173
176
|
bidAmountInMist,
|
|
174
177
|
numOfBids,
|
|
175
178
|
walletAddress,
|
|
179
|
+
multiBidId,
|
|
180
|
+
multiBidChainId,
|
|
181
|
+
expireAt,
|
|
176
182
|
}: PlaceCollectionBid): Promise<Transaction> {
|
|
177
183
|
const context: RequestContext = {
|
|
178
184
|
apiUser: this.apiUser,
|
|
@@ -191,6 +197,9 @@ class SuiTradingClient {
|
|
|
191
197
|
},
|
|
192
198
|
],
|
|
193
199
|
walletAddress,
|
|
200
|
+
multiBidId,
|
|
201
|
+
multiBidChainId,
|
|
202
|
+
expireAt,
|
|
194
203
|
},
|
|
195
204
|
context,
|
|
196
205
|
);
|
|
@@ -461,6 +470,18 @@ class SuiTradingClient {
|
|
|
461
470
|
|
|
462
471
|
return migrateNftsFromUnsharedToSharedKiosks(args, context);
|
|
463
472
|
}
|
|
473
|
+
|
|
474
|
+
public async createMultiBid(args: CreateMultiBid) {
|
|
475
|
+
return createMultiBid(args);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
public async cancelMultiBid(args: CancelMultiBid) {
|
|
479
|
+
return cancelMultiBid(args);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
public async updateMultiBid(args: UpdateMultiBid) {
|
|
483
|
+
return updateMultiBid(args);
|
|
484
|
+
}
|
|
464
485
|
}
|
|
465
486
|
|
|
466
487
|
export default SuiTradingClient;
|
package/src/constants.ts
CHANGED
|
@@ -15,6 +15,9 @@ export const TRADEPORT_KIOSK_BID_NONCE_TYPE = '0xec175e537be9e48f75fa6929291de64
|
|
|
15
15
|
export const TRADEPORT_PRICE_LOCK_PACKAGE = '0x3cb532a2548290780a3d70ad6f4f06abc5bebb75ec6f8dd0197d4d2b2860c5d8';
|
|
16
16
|
export const TRADEPORT_PRICE_LOCK_STORE = '0x4b705de46a79b29276baf45009bc7d6f70cc0f1407f0c9e03cac5729c0c47946';
|
|
17
17
|
|
|
18
|
+
export const TRADEPORT_MULTI_BID_PACKAGE = '0xb32c899d9fb0d79a7e384bfbf2830a19ee26ccf51d6cadaaf1a14c4a2817886a'; // Upgrade Cap 0x7fdc0ebfd6265f7642e68269eb085fb551f02a9953d38f1872370d59613207c7
|
|
19
|
+
export const TRADEPORT_MULTI_BID_STORE = '0x2617658a6b03dcf6df2df4d256341bc4690d3a3d299c9552ca6ac9799ceb0ed7';
|
|
20
|
+
|
|
18
21
|
export const COLLECTION_IDS_WITH_ZERO_COMMISSION = [
|
|
19
22
|
'',
|
|
20
23
|
];
|
|
@@ -989,3 +992,11 @@ export const DELOREAN_TOKEN_IDS_TO_DISABLE = [
|
|
|
989
992
|
'0x8045e771ecd3c409c4245a003887b90964e31b63717252cfe4cd13d86ceaa2c3',
|
|
990
993
|
'0xbd494f677ec2361dda0fefe2ec9689f8d4c8ab585e5a39884290850e5a4e28df',
|
|
991
994
|
];
|
|
995
|
+
|
|
996
|
+
export const DYNAMIC_COLLECTION_IDS = [
|
|
997
|
+
'67aca668-31b0-4713-91cf-079d392b041a', // Kumo
|
|
998
|
+
'b5d64823-54b5-43ff-b58f-8b8abf08d27b', // Hunting Snake Legends
|
|
999
|
+
'5ea655c3-b8f9-4882-9090-3c59d1635d00', // Fever Maniac
|
|
1000
|
+
'f7ccba9d-04f8-49c4-8e1f-d264b122584d', // SuiFrens: Capys
|
|
1001
|
+
'a8c93237-922f-4d6c-825f-bdcbc4bf10fc', // Anima Genesis Avatars
|
|
1002
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TRADEPORT_MULTI_BID_PACKAGE } from '../constants';
|
|
2
|
+
|
|
3
|
+
export const isSingleBid = (bidType: string): boolean => {
|
|
4
|
+
if (!bidType) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (!bidType.startsWith('0x')) {
|
|
9
|
+
bidType = `0x${bidType}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return bidType === `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::SingleBid`;
|
|
13
|
+
};
|
|
@@ -46,6 +46,10 @@ export const kioskTxWrapper = async ({
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
if (!kioskOwner) {
|
|
50
|
+
throw new Error('No kiosk owner provided');
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
let kiosks =
|
|
50
54
|
kioskOwnerKiosks ??
|
|
51
55
|
(((
|
|
@@ -110,7 +114,10 @@ export const kioskTxWrapper = async ({
|
|
|
110
114
|
version: '',
|
|
111
115
|
},
|
|
112
116
|
});
|
|
113
|
-
} else if (kiosks.length
|
|
117
|
+
} else if (shouldConvertToPersonalKiosk || kiosks.length === 0) {
|
|
118
|
+
kioskTx = new KioskTransaction({ transactionBlock: tx as any, kioskClient });
|
|
119
|
+
kioskTx.createPersonal(true);
|
|
120
|
+
} else {
|
|
114
121
|
const kioskCapId = (
|
|
115
122
|
await gqlChainRequest({
|
|
116
123
|
chain: 'sui',
|
|
@@ -130,10 +137,6 @@ export const kioskTxWrapper = async ({
|
|
|
130
137
|
version: '',
|
|
131
138
|
},
|
|
132
139
|
});
|
|
133
|
-
} else {
|
|
134
|
-
// creating new personal kiosk
|
|
135
|
-
kioskTx = new KioskTransaction({ transactionBlock: tx as any, kioskClient });
|
|
136
|
-
kioskTx.createPersonal(true);
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
await runCommands(kioskTx);
|
|
@@ -40,6 +40,7 @@ export type AcceptCollectionBidTx = {
|
|
|
40
40
|
royaltyRulePackageId?: string;
|
|
41
41
|
royaltyRuleModule?: string;
|
|
42
42
|
shouldSplitRoyaltyFromUserGasCoins?: boolean;
|
|
43
|
+
multiBidId?: string;
|
|
43
44
|
beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
|
|
44
45
|
};
|
|
45
46
|
|
|
@@ -119,6 +120,7 @@ export const acceptCollectionBid = async (
|
|
|
119
120
|
collectionId: nft?.collection_id,
|
|
120
121
|
isListedOnBluemove: nft?.listings?.[0]?.market_name === 'bluemove',
|
|
121
122
|
bidMarketName: bid?.market_contract?.name,
|
|
123
|
+
multiBidId: bid.multi_bid_id,
|
|
122
124
|
shouldSplitRoyaltyFromUserGasCoins,
|
|
123
125
|
beforeResolveKioskTransferRequest,
|
|
124
126
|
};
|
|
@@ -25,9 +25,13 @@ import { isOriginByteBid } from '../../helpers/originByte/isOriginByteBid';
|
|
|
25
25
|
import { isOriginByteTx } from '../../helpers/originByte/isOriginByteTx';
|
|
26
26
|
import { shareOriginByteKiosk } from '../../helpers/originByte/shareOriginByteKiosk';
|
|
27
27
|
import { getObjectType } from '../../helpers/rpc/getObjectType';
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
addSingleBidAcceptNftBidTx,
|
|
30
|
+
addTradeportKioskAcceptNftBidTx,
|
|
31
|
+
} from '../acceptNftBids/addAcceptNftBidTxs';
|
|
29
32
|
import { addOriginByteUnlistTx } from '../unlistListings/addUnlistListingTxs';
|
|
30
33
|
import { type AcceptCollectionBidTx } from './acceptCollectionBid';
|
|
34
|
+
import { isSingleBid } from '../../helpers/isSIngleBid';
|
|
31
35
|
|
|
32
36
|
export function addTradeportAcceptCollectionBidTx({
|
|
33
37
|
tx,
|
|
@@ -228,6 +232,11 @@ export function addTocenAcceptCollectionBidTx({
|
|
|
228
232
|
export async function addTradePortAcceptCollectionBidTxHandler(txData: AcceptCollectionBidTx) {
|
|
229
233
|
const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
|
|
230
234
|
|
|
235
|
+
if (isSingleBid(bidType)) {
|
|
236
|
+
await addSingleBidAcceptNftBidTx(txData);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
|
|
231
240
|
if (isOriginByteBid(bidType)) {
|
|
232
241
|
if (isOriginByteTx(txData?.sharedObjects)) {
|
|
233
242
|
await addOriginByteAcceptCollectionBidTx(txData);
|
|
@@ -37,6 +37,7 @@ export type AcceptNftBidTx = {
|
|
|
37
37
|
royaltyRuleModule?: string;
|
|
38
38
|
shouldSplitRoyaltyFromUserGasCoins?: boolean;
|
|
39
39
|
beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
|
|
40
|
+
multiBidId?: string;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
export type AcceptNftBids = {
|
|
@@ -110,8 +111,10 @@ export const acceptNftBids = async (
|
|
|
110
111
|
itemOwner: bid?.nft?.owner,
|
|
111
112
|
bidAmount: bid?.price,
|
|
112
113
|
sellerKiosk: bid?.nft?.chain_state?.kiosk_id,
|
|
114
|
+
seller: bid?.nft?.owner,
|
|
113
115
|
isListedOnBluemove: bid?.nft?.listings?.[0]?.market_name === 'bluemove',
|
|
114
116
|
bidMarketName: bid?.market_contract?.name,
|
|
117
|
+
multiBidId: bid?.multi_bid_id,
|
|
115
118
|
beforeResolveKioskTransferRequest,
|
|
116
119
|
};
|
|
117
120
|
|
|
@@ -6,11 +6,16 @@ import {
|
|
|
6
6
|
BLUEMOVE_ROYALTY_COLLECTION_OBJECT,
|
|
7
7
|
TRADEPORT_BIDDING_STORE,
|
|
8
8
|
TRADEPORT_KIOSK_BIDDING_STORE,
|
|
9
|
+
TRADEPORT_MULTI_BID_PACKAGE,
|
|
10
|
+
TRADEPORT_MULTI_BID_STORE,
|
|
9
11
|
} from '../../constants';
|
|
10
12
|
import { getRoyaltyRuleModule } from '../../helpers/getRoyaltyRuleModule';
|
|
11
13
|
import { hasPersonalKioskRule } from '../../helpers/hasPersonalKioskRule';
|
|
12
14
|
import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
|
|
13
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
getKioskTransferPolicies,
|
|
17
|
+
knownTransferPolicyRules,
|
|
18
|
+
} from '../../helpers/kiosk/getKioskTransferPolicies';
|
|
14
19
|
import { getRulePackageId } from '../../helpers/kiosk/getRulePackageId';
|
|
15
20
|
import { isTradePortKioskBid } from '../../helpers/kiosk/isTradePortKioskBid';
|
|
16
21
|
import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
|
|
@@ -23,6 +28,10 @@ import { isOriginByteTx } from '../../helpers/originByte/isOriginByteTx';
|
|
|
23
28
|
import { getObjectType } from '../../helpers/rpc/getObjectType';
|
|
24
29
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
25
30
|
import { type AcceptNftBidTx } from './acceptNftBids';
|
|
31
|
+
import { isSingleBid } from '../../helpers/isSIngleBid';
|
|
32
|
+
import { normalizeStructTag, SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
33
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
34
|
+
import { fetchMultibidChainIdById } from '../../graphql/queries/fetchMultibidById';
|
|
26
35
|
|
|
27
36
|
export function addTradeportAcceptNftBidTx({
|
|
28
37
|
tx,
|
|
@@ -235,9 +244,93 @@ export function addBluemoveAcceptNftBidTx({
|
|
|
235
244
|
});
|
|
236
245
|
}
|
|
237
246
|
|
|
247
|
+
export async function addSingleBidAcceptNftBidTx(txData: AcceptNftBidTx) {
|
|
248
|
+
const { nftType, tx, bidNonce, multiBidId, kioskClient, nftTokenId } = txData;
|
|
249
|
+
const transferPolicies = await getKioskTransferPolicies(nftType);
|
|
250
|
+
const transferPolicy = transferPolicies?.find(
|
|
251
|
+
(policy: { rules: any[] }) => policy?.rules?.length > 0,
|
|
252
|
+
);
|
|
253
|
+
const { chain_id: multiBidChainId, cancelled_at } = multiBidId
|
|
254
|
+
? ((
|
|
255
|
+
await gqlChainRequest({
|
|
256
|
+
chain: 'sui',
|
|
257
|
+
query: fetchMultibidChainIdById,
|
|
258
|
+
variables: { multiBidId },
|
|
259
|
+
})
|
|
260
|
+
)?.multi_bids?.[0] ?? {})
|
|
261
|
+
: {};
|
|
262
|
+
|
|
263
|
+
if (multiBidChainId && cancelled_at) {
|
|
264
|
+
throw new Error(`MultiBid ${multiBidId} already cancelled`);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (transferPolicy) {
|
|
268
|
+
const transferPolicies = await kioskClient.getTransferPolicies({
|
|
269
|
+
type: normalizeStructTag(nftType),
|
|
270
|
+
});
|
|
271
|
+
const { rules: allRules } = transferPolicies.find((p) => p.id === transferPolicy.id);
|
|
272
|
+
const unsupportedRule = allRules.find(
|
|
273
|
+
(r) => !knownTransferPolicyRules.includes(r.split('::').at(1)),
|
|
274
|
+
);
|
|
275
|
+
if (unsupportedRule) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
`Found unsupported transfer policy rule ${unsupportedRule} for ${transferPolicy.id} of ${nftType}`,
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return kioskTxWrapper({
|
|
282
|
+
tx: txData?.tx,
|
|
283
|
+
kioskClient: txData?.kioskClient,
|
|
284
|
+
kioskTx: txData?.kioskTx,
|
|
285
|
+
kioskOwner: txData?.seller,
|
|
286
|
+
kiosk: txData?.sellerKiosk,
|
|
287
|
+
async runCommands(kioskTx) {
|
|
288
|
+
const [transferRequest] = tx.moveCall({
|
|
289
|
+
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::accept_bid_with_transfer_policy`,
|
|
290
|
+
typeArguments: [nftType],
|
|
291
|
+
arguments: [
|
|
292
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
293
|
+
tx.object(TRADEPORT_MULTI_BID_STORE),
|
|
294
|
+
tx.pure.id(bidNonce),
|
|
295
|
+
tx.pure.option('id', multiBidChainId),
|
|
296
|
+
tx.object(kioskTx.getKiosk() as any),
|
|
297
|
+
tx.object(kioskTx.getKioskCap() as any),
|
|
298
|
+
tx.pure.id(nftTokenId),
|
|
299
|
+
tx.object(transferPolicy.id),
|
|
300
|
+
],
|
|
301
|
+
});
|
|
302
|
+
// The contract resolves itself to the standard transfer policy rules
|
|
303
|
+
// Add here resolving custom transfer policy rules when they appear
|
|
304
|
+
tx.moveCall({
|
|
305
|
+
target: '0x2::transfer_policy::confirm_request',
|
|
306
|
+
arguments: [tx.object(transferPolicy.id), transferRequest],
|
|
307
|
+
typeArguments: [nftType],
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
tx.moveCall({
|
|
314
|
+
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::accept_bid_without_transfer_policy`,
|
|
315
|
+
typeArguments: [nftType],
|
|
316
|
+
arguments: [
|
|
317
|
+
tx.object(SUI_CLOCK_OBJECT_ID),
|
|
318
|
+
tx.object(TRADEPORT_MULTI_BID_STORE),
|
|
319
|
+
tx.pure.id(bidNonce),
|
|
320
|
+
tx.pure.option('id', multiBidChainId),
|
|
321
|
+
tx.object(nftTokenId),
|
|
322
|
+
],
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
238
326
|
export async function addTradePortAcceptNftBidTxHandler(txData: AcceptNftBidTx) {
|
|
239
327
|
const bidType = await getObjectType({ suiClient: txData?.suiClient, objectId: txData?.bidNonce });
|
|
240
328
|
|
|
329
|
+
if (isSingleBid(bidType)) {
|
|
330
|
+
await addSingleBidAcceptNftBidTx(txData);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
241
334
|
if (isOriginByteBid(bidType)) {
|
|
242
335
|
if (isOriginByteTx(txData?.sharedObjects)) {
|
|
243
336
|
await addOriginByteAcceptNftBidTx(txData);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { TRADEPORT_MULTI_BID_PACKAGE, TRADEPORT_MULTI_BID_STORE } from '../../constants';
|
|
3
|
+
import { fetchMultibidChainIdById } from '../../graphql/queries/fetchMultibidById';
|
|
4
|
+
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
5
|
+
|
|
6
|
+
export interface CancelMultiBid {
|
|
7
|
+
walletAddress: string;
|
|
8
|
+
multiBidId: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function cancelMultiBid({ multiBidId }: CancelMultiBid): Promise<Transaction> {
|
|
12
|
+
const { chain_id: multiBidChainId, cancelled_at } =
|
|
13
|
+
(
|
|
14
|
+
await gqlChainRequest({
|
|
15
|
+
chain: 'sui',
|
|
16
|
+
query: fetchMultibidChainIdById,
|
|
17
|
+
variables: { multiBidId },
|
|
18
|
+
})
|
|
19
|
+
)?.multi_bids?.[0] ?? {};
|
|
20
|
+
if (!multiBidChainId) {
|
|
21
|
+
throw new Error(`MultiBid ${multiBidId} not found`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (cancelled_at) {
|
|
25
|
+
throw new Error(`MultiBid ${multiBidId} already cancelled`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const tx = new Transaction();
|
|
29
|
+
tx.moveCall({
|
|
30
|
+
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::cancel_multi_bid`,
|
|
31
|
+
arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.id(multiBidChainId)],
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return tx;
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { TRADEPORT_MULTI_BID_PACKAGE, TRADEPORT_MULTI_BID_STORE } from '../../constants';
|
|
3
|
+
import { updateMultiBid } from '../updateMultiBid/updateMultiBid';
|
|
4
|
+
|
|
5
|
+
export interface CreateMultiBid {
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
amount?: bigint;
|
|
9
|
+
tx?: Transaction;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function createMultiBid({
|
|
13
|
+
walletAddress,
|
|
14
|
+
name,
|
|
15
|
+
amount,
|
|
16
|
+
tx: existingTx,
|
|
17
|
+
}: CreateMultiBid): Promise<{ multiBidChainId: any; tx: Transaction }> {
|
|
18
|
+
const tx = existingTx ?? new Transaction();
|
|
19
|
+
const multiBidChainId = tx.moveCall({
|
|
20
|
+
target: `${TRADEPORT_MULTI_BID_PACKAGE}::tradeport_biddings::create_multi_bid`,
|
|
21
|
+
arguments: [tx.object(TRADEPORT_MULTI_BID_STORE), tx.pure.option('string', name)],
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (amount > 0n) {
|
|
25
|
+
await updateMultiBid({
|
|
26
|
+
walletAddress,
|
|
27
|
+
multiBidChainId,
|
|
28
|
+
amount,
|
|
29
|
+
name,
|
|
30
|
+
tx,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return { multiBidChainId, tx };
|
|
35
|
+
}
|
|
@@ -10,11 +10,9 @@ import { getOrCreateOBKiosk } from '../../helpers/originByte/getOrCreateOBKiosk'
|
|
|
10
10
|
import { isOriginByteTx } from '../../helpers/originByte/isOriginByteTx';
|
|
11
11
|
import { shareOriginByteKiosk } from '../../helpers/originByte/shareOriginByteKiosk';
|
|
12
12
|
import { normalizedNftType } from '../../utils/normalizeNftType';
|
|
13
|
-
import {
|
|
14
|
-
addOriginByteCollectionBidTx,
|
|
15
|
-
addTradePortPlaceCollectionBidTxHandler,
|
|
16
|
-
} from './addPlaceCollectionBidTxs';
|
|
13
|
+
import { addOriginByteCollectionBidTx } from './addPlaceCollectionBidTxs';
|
|
17
14
|
import { type SuiClient } from '@mysten/sui/client';
|
|
15
|
+
import { addTradePortPlaceNftBidTxHandler } from '../placeNftBids/addPlaceNftBidTxs';
|
|
18
16
|
|
|
19
17
|
export type PlaceCollectionBidTx = {
|
|
20
18
|
tx: Transaction;
|
|
@@ -28,6 +26,9 @@ export type PlaceCollectionBidTx = {
|
|
|
28
26
|
bidderKiosk?: string;
|
|
29
27
|
royaltyRulePackageId?: string;
|
|
30
28
|
royaltyRuleModule?: string;
|
|
29
|
+
multiBidId?: string;
|
|
30
|
+
multiBidChainId?: any;
|
|
31
|
+
expireAt?: Date;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
export type PlaceCollectionBid = {
|
|
@@ -35,6 +36,10 @@ export type PlaceCollectionBid = {
|
|
|
35
36
|
bidAmountInMist: number;
|
|
36
37
|
numOfBids: number;
|
|
37
38
|
walletAddress: string;
|
|
39
|
+
multiBidId?: string;
|
|
40
|
+
multiBidChainId?: any;
|
|
41
|
+
expireAt?: Date;
|
|
42
|
+
tx?: Transaction;
|
|
38
43
|
};
|
|
39
44
|
|
|
40
45
|
export type PlaceCollectionBids = {
|
|
@@ -44,10 +49,21 @@ export type PlaceCollectionBids = {
|
|
|
44
49
|
numOfBids: number;
|
|
45
50
|
}>;
|
|
46
51
|
walletAddress: string;
|
|
52
|
+
multiBidId?: string;
|
|
53
|
+
multiBidChainId?: any;
|
|
54
|
+
expireAt?: Date;
|
|
55
|
+
tx?: Transaction;
|
|
47
56
|
};
|
|
48
57
|
|
|
49
58
|
export const placeCollectionBids = async (
|
|
50
|
-
{
|
|
59
|
+
{
|
|
60
|
+
collections,
|
|
61
|
+
walletAddress,
|
|
62
|
+
multiBidId,
|
|
63
|
+
multiBidChainId,
|
|
64
|
+
expireAt,
|
|
65
|
+
tx: existingTx,
|
|
66
|
+
}: PlaceCollectionBids,
|
|
51
67
|
context: RequestContext,
|
|
52
68
|
): Promise<Transaction> => {
|
|
53
69
|
const res = await gqlChainRequest({
|
|
@@ -60,12 +76,8 @@ export const placeCollectionBids = async (
|
|
|
60
76
|
throw new Error('No collection found');
|
|
61
77
|
}
|
|
62
78
|
|
|
63
|
-
if (res?.collections?.length === 0) {
|
|
64
|
-
throw new Error('No collection found');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
79
|
const collectionsForTracking = [];
|
|
68
|
-
const tx = new Transaction();
|
|
80
|
+
const tx = existingTx ?? new Transaction();
|
|
69
81
|
|
|
70
82
|
for (const collection of res.collections) {
|
|
71
83
|
const nftType = getNftType({
|
|
@@ -85,6 +97,9 @@ export const placeCollectionBids = async (
|
|
|
85
97
|
collectionId: collection?.id,
|
|
86
98
|
nftType,
|
|
87
99
|
bidAmount: collections?.find((c) => c.id === collection?.id)?.bidAmountInMist,
|
|
100
|
+
multiBidId,
|
|
101
|
+
multiBidChainId,
|
|
102
|
+
expireAt,
|
|
88
103
|
};
|
|
89
104
|
|
|
90
105
|
const numOfBids = collections?.find((c) => c.id === collection?.id)?.numOfBids;
|
|
@@ -107,7 +122,7 @@ export const placeCollectionBids = async (
|
|
|
107
122
|
}
|
|
108
123
|
} else {
|
|
109
124
|
for (let i = 0; i < numOfBids; i++) {
|
|
110
|
-
await
|
|
125
|
+
await addTradePortPlaceNftBidTxHandler({ ...txData, bidAmount: BigInt(txData.bidAmount) });
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
|