@tradeport/sui-trading-sdk 0.3.4 → 0.3.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tradeport/sui-trading-sdk",
3
3
  "license": "MIT",
4
- "version": "0.3.4",
4
+ "version": "0.3.6",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -11,11 +11,11 @@ import { addTradeportKioskTransferTx } from '../transferNfts/addTransferNftTx';
11
11
 
12
12
  export type MigrateNftsFromUnsharedToSharedKiosks = {
13
13
  walletAddress: string;
14
- max: number;
14
+ max?: number;
15
15
  };
16
16
 
17
17
  export async function migrateNftsFromUnsharedToSharedKiosks(
18
- { walletAddress, max }: MigrateNftsFromUnsharedToSharedKiosks,
18
+ { walletAddress, max = 5 }: MigrateNftsFromUnsharedToSharedKiosks,
19
19
  context: RequestContext,
20
20
  ): Promise<Transaction> {
21
21
  const tx = new Transaction();
@@ -28,15 +28,14 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
28
28
 
29
29
  const unsharedOBKiosks = res?.kiosks
30
30
  ?.filter((k: any) => !k.is_shared && k.is_origin_byte)
31
- ?.map((k: any) => k.id)
32
- ?.slice(0, 5);
31
+ ?.map((k: any) => k.id);
33
32
 
34
33
  let currentMigrationCount = 0;
35
34
 
36
35
  const sharedOBKiosk = res?.kiosks?.filter((k: any) => k.is_shared && k.is_origin_byte)?.[0]?.id;
37
36
 
38
37
  for (const unsharedOBKiosk of unsharedOBKiosks) {
39
- if (currentMigrationCount >= (max ?? 5)) {
38
+ if (currentMigrationCount >= max) {
40
39
  continue;
41
40
  }
42
41
 
@@ -99,11 +98,10 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
99
98
 
100
99
  const unsharedNativeKiosks = res?.kiosks
101
100
  ?.filter((k: any) => !k.is_shared && !k.is_origin_byte)
102
- ?.map((k: any) => k.id)
103
- ?.slice(0, 5);
101
+ ?.map((k: any) => k.id);
104
102
 
105
103
  for (const unsharedNativeKiosk of unsharedNativeKiosks) {
106
- if (currentMigrationCount >= 5) {
104
+ if (currentMigrationCount >= max) {
107
105
  continue;
108
106
  }
109
107
 
@@ -169,11 +169,40 @@ export function canBeTransferedDirectly(collectionChainState?: CollectionChainSt
169
169
  export function getTransferPolicyForDirectTransfer(
170
170
  collectionChainState?: CollectionChainState,
171
171
  ): TransferPolicy | undefined {
172
- return collectionChainState?.transfer_policies?.find(
172
+ if (!collectionChainState?.transfer_policies?.length) {
173
+ return undefined;
174
+ }
175
+
176
+ const usablePolicies = collectionChainState.transfer_policies.filter(
173
177
  (policy) =>
174
178
  !policy.is_origin_byte &&
175
179
  policy.rules?.filter(
176
180
  (rule) => rule.type !== 'kiosk_lock_rule' && rule.type !== 'royalty_rule',
177
181
  ).length === 0,
178
182
  );
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];
179
208
  }