@tradeport/sui-trading-sdk 0.2.2 → 0.3.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 +6 -0
- package/dist/index.js +92 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/methods/transferNfts/addTransferNftTx.ts +108 -0
- package/src/methods/transferNfts/transferNfts.ts +28 -11
package/package.json
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
import { type Transaction } from '@mysten/sui/dist/cjs/transactions';
|
|
1
2
|
import { TRADEPORT_KIOSK_TRANSFERS_STORE } from '../../constants';
|
|
3
|
+
import { destroyZeroCoin } from '../../helpers/destroyZeroCoin';
|
|
4
|
+
import { getNftType } from '../../helpers/getNftType';
|
|
2
5
|
import { assertNftInSharedKiosk } from '../../helpers/kiosk/assertNftInSharedKiosk';
|
|
3
6
|
import { getKioskTransferPolicies } from '../../helpers/kiosk/getKioskTransferPolicies';
|
|
7
|
+
import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
|
|
4
8
|
import { getOBKiosk } from '../../helpers/originByte/getOBKiosk';
|
|
5
9
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
6
10
|
import { type TransferNftTx } from './transferNfts';
|
|
11
|
+
import { type KioskClient } from '@mysten/kiosk';
|
|
12
|
+
|
|
13
|
+
type CollectionChainState = {
|
|
14
|
+
transfer_policies: TransferPolicy[];
|
|
15
|
+
};
|
|
16
|
+
type TransferPolicy = {
|
|
17
|
+
id: string;
|
|
18
|
+
rules: Array<{ type: string; min_amount?: string }>;
|
|
19
|
+
is_origin_byte: boolean;
|
|
20
|
+
};
|
|
7
21
|
|
|
8
22
|
export async function addOriginByteTransferNftTx({
|
|
9
23
|
tx,
|
|
@@ -69,3 +83,97 @@ export async function addTradeportKioskTransferTx({
|
|
|
69
83
|
typeArguments: [nftType],
|
|
70
84
|
});
|
|
71
85
|
}
|
|
86
|
+
|
|
87
|
+
export async function addTradeportKioskDirectTransferTx(
|
|
88
|
+
txData: {
|
|
89
|
+
tx: Transaction;
|
|
90
|
+
recipientAddress: string;
|
|
91
|
+
kioskClient: KioskClient;
|
|
92
|
+
senderAddress: string;
|
|
93
|
+
},
|
|
94
|
+
nfts: any[],
|
|
95
|
+
) {
|
|
96
|
+
const { tx, recipientAddress, kioskClient, senderAddress } = txData;
|
|
97
|
+
if (nfts.length === 0) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const [receiverKiosk, receiverKioskCap] = tx.moveCall({
|
|
102
|
+
target: '0x2::kiosk::new',
|
|
103
|
+
arguments: [],
|
|
104
|
+
});
|
|
105
|
+
const recipientAddressWithPrefix = addLeadingZerosAfter0x(recipientAddress);
|
|
106
|
+
tx.moveCall({
|
|
107
|
+
target: '0x2::kiosk::set_owner_custom',
|
|
108
|
+
arguments: [
|
|
109
|
+
tx.object(receiverKiosk),
|
|
110
|
+
tx.object(receiverKioskCap),
|
|
111
|
+
tx.pure.address(recipientAddressWithPrefix),
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
const totalRoyaltyAmount = nfts.reduce(
|
|
115
|
+
(sum: bigint, nft) =>
|
|
116
|
+
sum +
|
|
117
|
+
BigInt(
|
|
118
|
+
getTransferPolicyForDirectTransfer(nft.collection.chain_state)?.rules?.find(
|
|
119
|
+
(rule) => rule.type === 'royalty_rule',
|
|
120
|
+
)?.min_amount ?? 0n,
|
|
121
|
+
),
|
|
122
|
+
0n,
|
|
123
|
+
);
|
|
124
|
+
const [royaltyCoin] = tx.splitCoins(tx.gas, [tx.pure.u64(totalRoyaltyAmount)]);
|
|
125
|
+
for (const nft of nfts) {
|
|
126
|
+
const nftType = getNftType({
|
|
127
|
+
collectionId: nft?.collection?.id,
|
|
128
|
+
collectionChainState: nft?.collection?.chain_state,
|
|
129
|
+
nft,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
await kioskTxWrapper({
|
|
133
|
+
tx,
|
|
134
|
+
kioskClient,
|
|
135
|
+
kioskOwner: senderAddress,
|
|
136
|
+
kiosk: nft?.chain_state?.kiosk_id,
|
|
137
|
+
async runCommands(kioskTx) {
|
|
138
|
+
tx.moveCall({
|
|
139
|
+
target:
|
|
140
|
+
'0xd0ad5bf7ac7d372cdcfee5273d5e487dabad724040e089c626cba2a01127ccd6::kiosk_transfers::direct_transfer',
|
|
141
|
+
arguments: [
|
|
142
|
+
tx.object(kioskTx.getKiosk() as any),
|
|
143
|
+
tx.object(kioskTx.getKioskCap() as any),
|
|
144
|
+
tx.object(receiverKiosk),
|
|
145
|
+
tx.object(receiverKioskCap),
|
|
146
|
+
tx.pure.id(nft.token_id),
|
|
147
|
+
tx.object(getTransferPolicyForDirectTransfer(nft.collection.chain_state).id),
|
|
148
|
+
royaltyCoin,
|
|
149
|
+
],
|
|
150
|
+
typeArguments: [nftType],
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
tx.transferObjects([receiverKioskCap], tx.pure.address(recipientAddressWithPrefix));
|
|
157
|
+
tx.moveCall({
|
|
158
|
+
target: '0x2::transfer::public_share_object',
|
|
159
|
+
arguments: [receiverKiosk],
|
|
160
|
+
typeArguments: ['0x2::kiosk::Kiosk'],
|
|
161
|
+
});
|
|
162
|
+
destroyZeroCoin({ tx, coin: royaltyCoin });
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function canBeTransferedDirectly(collectionChainState?: CollectionChainState) {
|
|
166
|
+
return getTransferPolicyForDirectTransfer(collectionChainState) !== undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function getTransferPolicyForDirectTransfer(
|
|
170
|
+
collectionChainState?: CollectionChainState,
|
|
171
|
+
): TransferPolicy | undefined {
|
|
172
|
+
return collectionChainState?.transfer_policies?.find(
|
|
173
|
+
(policy) =>
|
|
174
|
+
!policy.is_origin_byte &&
|
|
175
|
+
policy.rules?.filter(
|
|
176
|
+
(rule) => rule.type !== 'kiosk_lock_rule' && rule.type !== 'royalty_rule',
|
|
177
|
+
).length === 0,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
@@ -13,7 +13,12 @@ import { kioskTxWrapper } from '../../helpers/kiosk/kioskTxWrapper';
|
|
|
13
13
|
import { isOBKiosk } from '../../helpers/originByte/isOBKiosk';
|
|
14
14
|
import { getAccountBalance } from '../../helpers/rpc/getAcountBalance';
|
|
15
15
|
import { addLeadingZerosAfter0x } from '../../utils/addLeadingZerosAfter0x';
|
|
16
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
addOriginByteTransferNftTx,
|
|
18
|
+
addTradeportKioskDirectTransferTx,
|
|
19
|
+
addTradeportKioskTransferTx,
|
|
20
|
+
canBeTransferedDirectly,
|
|
21
|
+
} from './addTransferNftTx';
|
|
17
22
|
|
|
18
23
|
export type TransferNftTx = {
|
|
19
24
|
tx: Transaction;
|
|
@@ -66,6 +71,7 @@ export const transferNfts = async (
|
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
const nftsForTracking = [];
|
|
74
|
+
const nftsToTransferDirectly = [];
|
|
69
75
|
const tx = new Transaction();
|
|
70
76
|
|
|
71
77
|
for (const nft of res.nfts) {
|
|
@@ -115,16 +121,22 @@ export const transferNfts = async (
|
|
|
115
121
|
}
|
|
116
122
|
|
|
117
123
|
// If NFT is inside native kiosk
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
|
|
125
|
+
// If NFT can be transfered directly by creating new kiosk for receiver
|
|
126
|
+
if (canBeTransferedDirectly(nft?.collection?.chain_state)) {
|
|
127
|
+
nftsToTransferDirectly.push(nft);
|
|
128
|
+
} else {
|
|
129
|
+
await kioskTxWrapper({
|
|
130
|
+
tx: txData?.tx,
|
|
131
|
+
kioskClient: txData?.kioskClient,
|
|
132
|
+
kioskOwner: txData?.senderAddress,
|
|
133
|
+
kiosk: txData?.senderKiosk,
|
|
134
|
+
shouldAssertNftInSharedKiosk: true,
|
|
135
|
+
async runCommands(kioskTx) {
|
|
136
|
+
await addTradeportKioskTransferTx({ ...txData, kioskTx });
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
128
140
|
|
|
129
141
|
nftsForTracking.push({
|
|
130
142
|
nftType,
|
|
@@ -133,6 +145,11 @@ export const transferNfts = async (
|
|
|
133
145
|
});
|
|
134
146
|
}
|
|
135
147
|
|
|
148
|
+
await addTradeportKioskDirectTransferTx(
|
|
149
|
+
{ tx, kioskClient: context.kioskClient, senderAddress: walletAddress, recipientAddress },
|
|
150
|
+
nftsToTransferDirectly,
|
|
151
|
+
);
|
|
152
|
+
|
|
136
153
|
// currently turned off $1 bulk transfer fee
|
|
137
154
|
// if (res?.nfts?.length > 1) {
|
|
138
155
|
// await addOneDollarFee(tx);
|