@tradeport/sui-trading-sdk 0.3.6 → 0.3.8
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +17 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/SuiTradingClient.ts +6 -2
- package/src/methods/acceptNftBids/acceptNftBids.ts +17 -9
- package/src/methods/transferNfts/addTransferNftTx.ts +2 -30
package/package.json
CHANGED
package/src/SuiTradingClient.ts
CHANGED
|
@@ -157,7 +157,7 @@ class SuiTradingClient {
|
|
|
157
157
|
return removeNftBids({ bidIds, tx }, context);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
public async acceptNftBids({ bidIds }: AcceptNftBids) {
|
|
160
|
+
public async acceptNftBids({ bidIds, walletAddress }: AcceptNftBids) {
|
|
161
161
|
const context: RequestContext = {
|
|
162
162
|
apiUser: this.apiUser,
|
|
163
163
|
apiKey: this.apiKey,
|
|
@@ -165,7 +165,7 @@ class SuiTradingClient {
|
|
|
165
165
|
kioskClient: this.kioskClient,
|
|
166
166
|
};
|
|
167
167
|
|
|
168
|
-
return acceptNftBids({ bidIds }, context);
|
|
168
|
+
return acceptNftBids({ bidIds, walletAddress }, context);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
public async placeCollectionBid({
|
|
@@ -215,6 +215,10 @@ class SuiTradingClient {
|
|
|
215
215
|
throw new Error('No bid found');
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
if (addLeadingZerosAfter0x(bid?.bidder) === addLeadingZerosAfter0x(walletAddress)) {
|
|
219
|
+
throw new Error('Wallet cannot accept its own bid');
|
|
220
|
+
}
|
|
221
|
+
|
|
218
222
|
if (bid?.status !== 'active') {
|
|
219
223
|
throw new Error('Bid not active');
|
|
220
224
|
}
|
|
@@ -2,19 +2,20 @@ import { type KioskClient, type KioskTransaction } from '@mysten/kiosk';
|
|
|
2
2
|
import { type SuiClient } from '@mysten/sui/client';
|
|
3
3
|
import { Transaction } from '@mysten/sui/transactions';
|
|
4
4
|
import { type RequestContext } from '../../SuiTradingClient';
|
|
5
|
+
import {
|
|
6
|
+
DELOREAN_TOKEN_IDS_TO_DISABLE,
|
|
7
|
+
DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
|
|
8
|
+
} from '../../constants';
|
|
5
9
|
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
6
10
|
import { fetchBidsById } from '../../graphql/queries/fetchBidsById';
|
|
7
11
|
import { getNftType } from '../../helpers/getNftType';
|
|
8
12
|
import { getSharedObjects } from '../../helpers/getSharedObjects';
|
|
13
|
+
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
9
14
|
import {
|
|
10
15
|
addBluemoveAcceptNftBidTx,
|
|
11
16
|
addOriginByteAcceptNftBidTx,
|
|
12
17
|
addTradePortAcceptNftBidTxHandler,
|
|
13
18
|
} from './addAcceptNftBidTxs';
|
|
14
|
-
import {
|
|
15
|
-
DELOREAN_TOKEN_IDS_TO_DISABLE,
|
|
16
|
-
DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE,
|
|
17
|
-
} from '../../constants';
|
|
18
19
|
|
|
19
20
|
export type AcceptNftBidTx = {
|
|
20
21
|
tx: Transaction;
|
|
@@ -38,12 +39,9 @@ export type AcceptNftBidTx = {
|
|
|
38
39
|
beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
|
-
export type AcceptNftBid = {
|
|
42
|
-
bidId: string;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
42
|
export type AcceptNftBids = {
|
|
46
43
|
bidIds: string[];
|
|
44
|
+
walletAddress: string;
|
|
47
45
|
tx?: Transaction;
|
|
48
46
|
kioskTx?: KioskTransaction;
|
|
49
47
|
beforeResolveKioskTransferRequest?: (coin: any, transferRequest: any) => void | Promise<void>;
|
|
@@ -52,7 +50,13 @@ export type AcceptNftBids = {
|
|
|
52
50
|
const ERROR_UNLIST_FIRST = 'Item must be unlisted first before you can accept a solo bid on it';
|
|
53
51
|
|
|
54
52
|
export const acceptNftBids = async (
|
|
55
|
-
{
|
|
53
|
+
{
|
|
54
|
+
bidIds,
|
|
55
|
+
walletAddress,
|
|
56
|
+
tx: existingTx,
|
|
57
|
+
kioskTx,
|
|
58
|
+
beforeResolveKioskTransferRequest,
|
|
59
|
+
}: AcceptNftBids,
|
|
56
60
|
context: RequestContext,
|
|
57
61
|
): Promise<Transaction> => {
|
|
58
62
|
const res = await gqlChainRequest({
|
|
@@ -73,6 +77,10 @@ export const acceptNftBids = async (
|
|
|
73
77
|
throw new Error(DELOREAN_TOKEN_IDS_TO_DISABLE_MESSAGE);
|
|
74
78
|
}
|
|
75
79
|
|
|
80
|
+
if (addLeadingZerosAfter0x(bid?.bidder) === addLeadingZerosAfter0x(walletAddress)) {
|
|
81
|
+
throw new Error('Wallet cannot accept its own bid');
|
|
82
|
+
}
|
|
83
|
+
|
|
76
84
|
if (bid?.status !== 'active') {
|
|
77
85
|
throw new Error('Bid not active');
|
|
78
86
|
}
|
|
@@ -169,40 +169,12 @@ export function canBeTransferedDirectly(collectionChainState?: CollectionChainSt
|
|
|
169
169
|
export function getTransferPolicyForDirectTransfer(
|
|
170
170
|
collectionChainState?: CollectionChainState,
|
|
171
171
|
): TransferPolicy | undefined {
|
|
172
|
-
|
|
173
|
-
return undefined;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const usablePolicies = collectionChainState.transfer_policies.filter(
|
|
172
|
+
return collectionChainState?.transfer_policies?.find(
|
|
177
173
|
(policy) =>
|
|
178
174
|
!policy.is_origin_byte &&
|
|
175
|
+
policy.rules.length > 0 &&
|
|
179
176
|
policy.rules?.filter(
|
|
180
177
|
(rule) => rule.type !== 'kiosk_lock_rule' && rule.type !== 'royalty_rule',
|
|
181
178
|
).length === 0,
|
|
182
179
|
);
|
|
183
|
-
|
|
184
|
-
const lockAndRoyaltyPolicy = usablePolicies.find(
|
|
185
|
-
(policy) =>
|
|
186
|
-
policy.rules?.some((rule) => rule.type === 'kiosk_lock_rule') &&
|
|
187
|
-
!policy.rules?.some((rule) => rule.type === 'royalty_rule'),
|
|
188
|
-
);
|
|
189
|
-
if (lockAndRoyaltyPolicy) {
|
|
190
|
-
return lockAndRoyaltyPolicy;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const royaltyPolicy = usablePolicies.find((policy) =>
|
|
194
|
-
policy.rules?.some((rule) => rule.type === 'royalty_rule'),
|
|
195
|
-
);
|
|
196
|
-
if (royaltyPolicy) {
|
|
197
|
-
return royaltyPolicy;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const lockPolicy = usablePolicies.find((policy) =>
|
|
201
|
-
policy.rules?.some((rule) => rule.type === 'kiosk_lock_rule'),
|
|
202
|
-
);
|
|
203
|
-
if (lockPolicy) {
|
|
204
|
-
return lockPolicy;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return usablePolicies[0];
|
|
208
180
|
}
|