@tradeport/sui-trading-sdk 0.4.2 → 0.4.3
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/.env.demo +2 -1
- package/dist/index.js +81 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/graphql/queries/fetchNftsByKioskId.ts +22 -0
- package/src/helpers/destroyZeroCoin.ts +1 -1
- package/src/helpers/kiosk/kioskTxWrapper.ts +5 -6
- package/src/helpers/kiosk/resolveTransferPolicies.ts +1 -1
- package/src/methods/claimNfts/addClaimNftsTxs.ts +5 -3
- package/src/methods/claimNfts/claimNfts.ts +1 -0
- package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts +57 -18
- package/src/methods/transferNfts/addTransferNftTx.ts +4 -3
- package/src/methods/transferNfts/transferNfts.ts +1 -0
package/package.json
CHANGED
|
@@ -21,3 +21,25 @@ export const fetchNftsByKioskId = gql`
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
`;
|
|
24
|
+
|
|
25
|
+
export const fetchBulkNftsByKioskId = gql`
|
|
26
|
+
query fetchNftsByKioskId($where: nfts_bool_exp) {
|
|
27
|
+
nfts(where: $where) {
|
|
28
|
+
id
|
|
29
|
+
name
|
|
30
|
+
token_id
|
|
31
|
+
properties
|
|
32
|
+
chain_state
|
|
33
|
+
collection_id
|
|
34
|
+
claimable_reason
|
|
35
|
+
owner
|
|
36
|
+
contract {
|
|
37
|
+
properties
|
|
38
|
+
}
|
|
39
|
+
collection {
|
|
40
|
+
id
|
|
41
|
+
chain_state
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
@@ -114,10 +114,7 @@ export const kioskTxWrapper = async ({
|
|
|
114
114
|
version: '',
|
|
115
115
|
},
|
|
116
116
|
});
|
|
117
|
-
} else if (
|
|
118
|
-
kioskTx = new KioskTransaction({ transactionBlock: tx as any, kioskClient });
|
|
119
|
-
kioskTx.createPersonal(true);
|
|
120
|
-
} else {
|
|
117
|
+
} else if (kiosks.length > 0 && !shouldConvertToPersonalKiosk) {
|
|
121
118
|
const kioskCapId = (
|
|
122
119
|
await gqlChainRequest({
|
|
123
120
|
chain: 'sui',
|
|
@@ -137,9 +134,11 @@ export const kioskTxWrapper = async ({
|
|
|
137
134
|
version: '',
|
|
138
135
|
},
|
|
139
136
|
});
|
|
137
|
+
} else {
|
|
138
|
+
// creating new personal kiosk
|
|
139
|
+
kioskTx = new KioskTransaction({ transactionBlock: tx as any, kioskClient });
|
|
140
|
+
kioskTx.createPersonal(true);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
await runCommands(kioskTx);
|
|
143
|
-
|
|
144
|
-
kioskTx.finalize();
|
|
145
144
|
};
|
|
@@ -193,7 +193,7 @@ export const resolveTransferPolicies = async ({
|
|
|
193
193
|
packageId: rulePackageId,
|
|
194
194
|
nftType: policy.isCustom && policy.type ? policy.type : nftType,
|
|
195
195
|
policyId: policy.data.id,
|
|
196
|
-
transferRequest: policy.transferRequest,
|
|
196
|
+
transferRequest: policy.transferRequest as any,
|
|
197
197
|
});
|
|
198
198
|
break;
|
|
199
199
|
default:
|
|
@@ -165,8 +165,10 @@ export const addClaimTransferredNftWithPurchaseCapTx = async ({
|
|
|
165
165
|
nftTokenId,
|
|
166
166
|
nftType,
|
|
167
167
|
sellerKiosk,
|
|
168
|
+
preloadedTransferPolicyId,
|
|
168
169
|
}: ClaimTransferredNftTx) => {
|
|
169
|
-
const transferPolicyId =
|
|
170
|
+
const transferPolicyId =
|
|
171
|
+
preloadedTransferPolicyId ?? (await getKioskTransferPolicies(nftType))?.at(0)?.id;
|
|
170
172
|
|
|
171
173
|
const [transferRequest] = tx.moveCall({
|
|
172
174
|
target:
|
|
@@ -174,8 +176,8 @@ export const addClaimTransferredNftWithPurchaseCapTx = async ({
|
|
|
174
176
|
arguments: [
|
|
175
177
|
tx.object(TRADEPORT_KIOSK_TRANSFERS_STORE),
|
|
176
178
|
tx.object(sellerKiosk),
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
kioskTx.kiosk,
|
|
180
|
+
kioskTx.kioskCap,
|
|
179
181
|
tx.pure.address(nftTokenId),
|
|
180
182
|
tx.object(transferPolicyId),
|
|
181
183
|
],
|
package/src/methods/migrateNftsFromUnsharedToSharedKiosks/migrateNftsFromUnsharedToSharedKiosks.ts
CHANGED
|
@@ -2,8 +2,12 @@ import { Transaction } from '@mysten/sui/transactions';
|
|
|
2
2
|
import { type RequestContext } from '../../SuiTradingClient';
|
|
3
3
|
import { gqlChainRequest } from '../../graphql/gqlChainRequest';
|
|
4
4
|
import { fetchKiosksByOwner } from '../../graphql/queries/fetchKiosksByOwner';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
fetchBulkNftsByKioskId,
|
|
7
|
+
fetchNftsByKioskId,
|
|
8
|
+
} from '../../graphql/queries/fetchNftsByKioskId';
|
|
6
9
|
import { getNftType } from '../../helpers/getNftType';
|
|
10
|
+
import { getKioskTransferPolicies } from '../../helpers/kiosk/getKioskTransferPolicies';
|
|
7
11
|
import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
|
|
8
12
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
9
13
|
import { addClaimTransferredNftWithPurchaseCapTx } from '../claimNfts/addClaimNftsTxs';
|
|
@@ -15,7 +19,7 @@ export type MigrateNftsFromUnsharedToSharedKiosks = {
|
|
|
15
19
|
};
|
|
16
20
|
|
|
17
21
|
export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
18
|
-
{ walletAddress, max =
|
|
22
|
+
{ walletAddress, max = 50 }: MigrateNftsFromUnsharedToSharedKiosks,
|
|
19
23
|
context: RequestContext,
|
|
20
24
|
): Promise<Transaction> {
|
|
21
25
|
const tx = new Transaction();
|
|
@@ -57,11 +61,6 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
|
57
61
|
continue;
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
// if (nft?.collection_id === '67ded9ed-4dcc-4d15-9e6f-04dded46f419') {
|
|
61
|
-
// // Novagen, skip until we know what to do with them
|
|
62
|
-
// continue;
|
|
63
|
-
// }
|
|
64
|
-
|
|
65
64
|
const nftType = getNftType({
|
|
66
65
|
collectionId: nft?.collection?.id,
|
|
67
66
|
collectionChainState: nft?.collection?.chain_state,
|
|
@@ -100,24 +99,60 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
|
100
99
|
?.filter((k: any) => !k.is_shared && !k.is_origin_byte)
|
|
101
100
|
?.map((k: any) => k.id);
|
|
102
101
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
let globalKioskTx: any;
|
|
103
|
+
|
|
104
|
+
const allNfts = await gqlChainRequest({
|
|
105
|
+
chain: 'sui',
|
|
106
|
+
query: fetchBulkNftsByKioskId,
|
|
107
|
+
variables: {
|
|
108
|
+
where: {
|
|
109
|
+
_or: unsharedNativeKiosks.map((nk: any) => ({
|
|
110
|
+
chain_state: { _contains: { kiosk_id: nk } },
|
|
111
|
+
})),
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const formatted: any = {};
|
|
117
|
+
allNfts.nfts.forEach((e: any) => {
|
|
118
|
+
if (formatted[e.chain_state.kiosk_id]) {
|
|
119
|
+
formatted[e.chain_state.kiosk_id]?.push(e);
|
|
120
|
+
} else {
|
|
121
|
+
formatted[e.chain_state.kiosk_id] = [e];
|
|
106
122
|
}
|
|
123
|
+
});
|
|
107
124
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
125
|
+
const allNftTypes = allNfts.nfts.reduce((acc: any[], curr: any) => {
|
|
126
|
+
const type = getNftType({
|
|
127
|
+
collectionId: curr?.collection?.id,
|
|
128
|
+
collectionChainState: curr?.collection?.chain_state,
|
|
129
|
+
nft: curr,
|
|
112
130
|
});
|
|
131
|
+
if (!acc.includes(type)) acc.push(type);
|
|
132
|
+
return acc;
|
|
133
|
+
}, []);
|
|
113
134
|
|
|
114
|
-
|
|
135
|
+
const transferPolicies = await Promise.all(
|
|
136
|
+
allNftTypes.map((type: string) => getKioskTransferPolicies(type)),
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const mappedTrasferPolicies: Record<string, any> = {};
|
|
140
|
+
transferPolicies.forEach((tp: any) => {
|
|
141
|
+
mappedTrasferPolicies[tp.transfer_policies_by_type?.[0]?.type] = tp.transfer_policies_by_type;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
for (const unsharedNativeKiosk of unsharedNativeKiosks) {
|
|
145
|
+
if (currentMigrationCount >= max) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
115
148
|
|
|
149
|
+
const nfts = formatted[unsharedNativeKiosk] ?? [];
|
|
116
150
|
if (nfts?.length > 0) {
|
|
117
151
|
currentMigrationCount++;
|
|
118
152
|
}
|
|
119
153
|
|
|
120
154
|
for (const nft of nfts) {
|
|
155
|
+
let existingKioskTx;
|
|
121
156
|
if (nft?.claimable_reason === 'offer-transfer') {
|
|
122
157
|
// native kiosk kiosk_transfers transfer hold. Transfer needs to be cancelled first in order to be migrated
|
|
123
158
|
continue;
|
|
@@ -128,9 +163,7 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
|
128
163
|
collectionChainState: nft?.collection?.chain_state,
|
|
129
164
|
nft,
|
|
130
165
|
});
|
|
131
|
-
|
|
132
166
|
const nftTokenId = nft?.token_id;
|
|
133
|
-
|
|
134
167
|
await kioskTxWrapper({
|
|
135
168
|
tx,
|
|
136
169
|
kioskClient: context?.kioskClient,
|
|
@@ -147,18 +180,20 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
|
147
180
|
recipientAddress: walletAddress,
|
|
148
181
|
nftTokenId,
|
|
149
182
|
nftType,
|
|
183
|
+
transferPolicy: mappedTrasferPolicies[nftType]?.[0],
|
|
150
184
|
});
|
|
151
185
|
},
|
|
152
186
|
});
|
|
153
|
-
|
|
154
187
|
await kioskTxWrapper({
|
|
155
188
|
tx,
|
|
156
189
|
kioskClient: context.kioskClient,
|
|
157
190
|
kioskOwner: walletAddress,
|
|
158
191
|
kiosk: unsharedNativeKiosk,
|
|
159
192
|
kioskStrategy: 'exclude',
|
|
193
|
+
kioskTx: globalKioskTx,
|
|
160
194
|
shouldConvertToPersonalKiosk: true,
|
|
161
195
|
async runCommands(kioskTx) {
|
|
196
|
+
existingKioskTx = kioskTx;
|
|
162
197
|
await addClaimTransferredNftWithPurchaseCapTx({
|
|
163
198
|
tx,
|
|
164
199
|
kioskTx,
|
|
@@ -170,11 +205,15 @@ export async function migrateNftsFromUnsharedToSharedKiosks(
|
|
|
170
205
|
nftType,
|
|
171
206
|
sellerKiosk: unsharedNativeKiosk,
|
|
172
207
|
seller: nft?.owner,
|
|
208
|
+
preloadedTransferPolicyId: mappedTrasferPolicies[nftType]?.[0]?.id,
|
|
173
209
|
});
|
|
174
210
|
},
|
|
175
211
|
});
|
|
212
|
+
|
|
213
|
+
globalKioskTx = existingKioskTx;
|
|
176
214
|
}
|
|
177
215
|
}
|
|
178
216
|
|
|
217
|
+
globalKioskTx?.finalize();
|
|
179
218
|
return Transaction.from(tx);
|
|
180
219
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KioskClient } from '@mysten/kiosk';
|
|
1
2
|
import { type Transaction } from '@mysten/sui/dist/cjs/transactions';
|
|
2
3
|
import { TRADEPORT_KIOSK_TRANSFERS_STORE } from '../../constants';
|
|
3
4
|
import { destroyZeroCoin } from '../../helpers/destroyZeroCoin';
|
|
@@ -8,7 +9,6 @@ import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
|
|
|
8
9
|
import { getOBKiosk } from '../../helpers/originByte/getOBKiosk';
|
|
9
10
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
10
11
|
import { type TransferNftTx } from './transferNfts';
|
|
11
|
-
import { type KioskClient } from '@mysten/kiosk';
|
|
12
12
|
|
|
13
13
|
type CollectionChainState = {
|
|
14
14
|
transfer_policies: TransferPolicy[];
|
|
@@ -61,9 +61,10 @@ export async function addTradeportKioskTransferTx({
|
|
|
61
61
|
nftTokenId,
|
|
62
62
|
nftType,
|
|
63
63
|
recipientAddress,
|
|
64
|
+
transferPolicy,
|
|
64
65
|
}: TransferNftTx) {
|
|
65
|
-
const
|
|
66
|
-
const hasFloorPriceRule =
|
|
66
|
+
const existingTransferPolicy = transferPolicy ?? (await getKioskTransferPolicies(nftType))?.at(0);
|
|
67
|
+
const hasFloorPriceRule = existingTransferPolicy?.rules?.some(
|
|
67
68
|
(rule: any) => rule.type === 'floor_price_rule',
|
|
68
69
|
);
|
|
69
70
|
if (hasFloorPriceRule) {
|