@mysten/kiosk 0.7.0 → 0.7.2
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 +17 -0
- package/dist/client/kiosk-transaction.d.ts +12 -37
- package/dist/index.js +23 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -21
- package/dist/index.mjs.map +1 -1
- package/dist/tx/kiosk.d.ts +6 -6
- package/dist/tx/personal-kiosk.d.ts +3 -3
- package/dist/tx/transfer-policy.d.ts +5 -5
- package/dist/types/index.d.ts +2 -2
- package/dist/types/transfer-policy.d.ts +3 -3
- package/dist/utils.d.ts +2 -2
- package/package.json +2 -2
- package/src/client/kiosk-transaction.ts +20 -13
- package/src/client/tp-transaction.ts +6 -6
- package/src/tx/kiosk.ts +21 -14
- package/src/tx/personal-kiosk.ts +3 -3
- package/src/tx/rules/attach.ts +3 -3
- package/src/tx/rules/resolve.ts +1 -1
- package/src/tx/transfer-policy.ts +11 -6
- package/src/types/index.ts +2 -2
- package/src/types/transfer-policy.ts +3 -3
- package/src/utils.ts +3 -3
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { TransactionArgument, TransactionBlock } from '@mysten/sui.js/transactions';
|
|
1
|
+
import { TransactionArgument, TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { ObjectArgument } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Call the `transfer_policy::new` function to create a new transfer policy.
|
|
5
5
|
* Returns `transferPolicyCap`
|
|
6
6
|
*/
|
|
7
|
-
export declare function createTransferPolicy(tx: TransactionBlock, itemType: string, publisher: ObjectArgument):
|
|
7
|
+
export declare function createTransferPolicy(tx: TransactionBlock, itemType: string, publisher: ObjectArgument): TransactionObjectArgument;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a transfer Policy and returns both the Policy and the Cap.
|
|
10
10
|
* Used if we want to use the policy before making it a shared object.
|
|
11
11
|
*/
|
|
12
|
-
export declare function createTransferPolicyWithoutSharing(tx: TransactionBlock, itemType: string, publisher: ObjectArgument): [
|
|
12
|
+
export declare function createTransferPolicyWithoutSharing(tx: TransactionBlock, itemType: string, publisher: ObjectArgument): [TransactionObjectArgument, TransactionObjectArgument];
|
|
13
13
|
/**
|
|
14
14
|
* Converts Transfer Policy to a shared object.
|
|
15
15
|
*/
|
|
16
|
-
export declare function shareTransferPolicy(tx: TransactionBlock, itemType: string, transferPolicy:
|
|
16
|
+
export declare function shareTransferPolicy(tx: TransactionBlock, itemType: string, transferPolicy: TransactionObjectArgument): void;
|
|
17
17
|
/**
|
|
18
18
|
* Call the `transfer_policy::withdraw` function to withdraw profits from a transfer policy.
|
|
19
19
|
*/
|
|
20
|
-
export declare function withdrawFromPolicy(tx: TransactionBlock, itemType: string, policy: ObjectArgument, policyCap: ObjectArgument, amount?: string | bigint | null):
|
|
20
|
+
export declare function withdrawFromPolicy(tx: TransactionBlock, itemType: string, policy: ObjectArgument, policyCap: ObjectArgument, amount?: string | bigint | null): TransactionObjectArgument;
|
|
21
21
|
/**
|
|
22
22
|
* Call the `transfer_policy::confirm_request` function to unblock the
|
|
23
23
|
* transaction.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { type SharedObjectRef } from '@mysten/sui.js/bcs';
|
|
2
2
|
import { type SuiClient, type SuiObjectRef } from '@mysten/sui.js/client';
|
|
3
|
-
import {
|
|
3
|
+
import { TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
4
4
|
import { BaseRulePackageIds } from '../constants';
|
|
5
5
|
export * from './kiosk';
|
|
6
6
|
export * from './transfer-policy';
|
|
7
7
|
/**
|
|
8
8
|
* A valid argument for any of the Kiosk functions.
|
|
9
9
|
*/
|
|
10
|
-
export type ObjectArgument = string |
|
|
10
|
+
export type ObjectArgument = string | TransactionObjectArgument | SharedObjectRef | SuiObjectRef;
|
|
11
11
|
/**
|
|
12
12
|
* A Network selector.
|
|
13
13
|
* Kiosk SDK supports mainnet & testnet.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ObjectOwner } from '@mysten/sui.js/client';
|
|
2
|
-
import {
|
|
2
|
+
import { TransactionObjectArgument, type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
3
3
|
import { ObjectArgument } from '.';
|
|
4
4
|
/** The Transfer Policy module. */
|
|
5
5
|
export declare const TRANSFER_POLICY_MODULE = "0x2::transfer_policy";
|
|
@@ -42,8 +42,8 @@ export type RuleResolvingParams = {
|
|
|
42
42
|
sellerKiosk: ObjectArgument;
|
|
43
43
|
kiosk: ObjectArgument;
|
|
44
44
|
kioskCap: ObjectArgument;
|
|
45
|
-
transferRequest:
|
|
46
|
-
purchasedItem:
|
|
45
|
+
transferRequest: TransactionObjectArgument;
|
|
46
|
+
purchasedItem: TransactionObjectArgument;
|
|
47
47
|
packageId: string;
|
|
48
48
|
extraArgs: Record<string, any>;
|
|
49
49
|
};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SharedObjectRef } from '@mysten/sui.js/bcs';
|
|
2
2
|
import { PaginationArguments, SuiClient, SuiObjectData, SuiObjectDataFilter, SuiObjectDataOptions, SuiObjectRef, SuiObjectResponse, type DynamicFieldInfo } from '@mysten/sui.js/client';
|
|
3
|
-
import {
|
|
3
|
+
import { TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
4
4
|
import { Kiosk, KioskData, KioskListing, TransferPolicyCap } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Convert any valid input into a TransactionArgument.
|
|
@@ -9,7 +9,7 @@ import { Kiosk, KioskData, KioskListing, TransferPolicyCap } from './types';
|
|
|
9
9
|
* @param arg The argument to convert.
|
|
10
10
|
* @returns The converted TransactionArgument.
|
|
11
11
|
*/
|
|
12
|
-
export declare function objArg(txb: TransactionBlock, arg: string | SharedObjectRef | SuiObjectRef |
|
|
12
|
+
export declare function objArg(txb: TransactionBlock, arg: string | SharedObjectRef | SuiObjectRef | TransactionObjectArgument): TransactionObjectArgument;
|
|
13
13
|
export declare function getKioskObject(client: SuiClient, id: string): Promise<Kiosk>;
|
|
14
14
|
export declare function extractKioskData(data: DynamicFieldInfo[], listings: KioskListing[], lockedItemIds: string[], kioskId: string): KioskData;
|
|
15
15
|
export declare function getTypeWithoutPackageAddress(type: string): string;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@mysten/kiosk",
|
|
3
3
|
"author": "Mysten Labs <build@mystenlabs.com>",
|
|
4
4
|
"description": "Sui Kiosk library",
|
|
5
|
-
"version": "0.7.
|
|
5
|
+
"version": "0.7.2",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@mysten/sui.js": "0.
|
|
27
|
+
"@mysten/sui.js": "0.43.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"cross-env": "^7.0.3",
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
TransactionObjectArgument,
|
|
6
|
+
type TransactionArgument,
|
|
7
|
+
type TransactionBlock,
|
|
8
|
+
} from '@mysten/sui.js/transactions';
|
|
5
9
|
|
|
6
10
|
import * as kioskTx from '../tx/kiosk';
|
|
7
11
|
import { convertToPersonalTx, transferPersonalCapTx } from '../tx/personal-kiosk';
|
|
@@ -39,8 +43,8 @@ export type KioskTransactionParams = {
|
|
|
39
43
|
export class KioskTransaction {
|
|
40
44
|
transactionBlock: TransactionBlock;
|
|
41
45
|
kioskClient: KioskClient;
|
|
42
|
-
kiosk?:
|
|
43
|
-
kioskCap?:
|
|
46
|
+
kiosk?: TransactionObjectArgument;
|
|
47
|
+
kioskCap?: TransactionObjectArgument;
|
|
44
48
|
// If we're pending `share` of a new kiosk, `finalize()` will share it.
|
|
45
49
|
#pendingShare?: boolean;
|
|
46
50
|
// If we're pending transferring of the cap, `finalize()` will either error or transfer the cap if it's a new personal.
|
|
@@ -48,7 +52,7 @@ export class KioskTransaction {
|
|
|
48
52
|
// The promise that the personalCap will be returned on `finalize()`.
|
|
49
53
|
#promise?: TransactionArgument | undefined;
|
|
50
54
|
// The personal kiosk argument.
|
|
51
|
-
#personalCap?:
|
|
55
|
+
#personalCap?: TransactionObjectArgument;
|
|
52
56
|
// A flag that checks whether kiosk TX is finalized.
|
|
53
57
|
#finalized: boolean = false;
|
|
54
58
|
|
|
@@ -114,7 +118,7 @@ export class KioskTransaction {
|
|
|
114
118
|
createAndShare(address: string) {
|
|
115
119
|
this.#validateFinalizedStatus();
|
|
116
120
|
const cap = kioskTx.createKioskAndShare(this.transactionBlock);
|
|
117
|
-
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure(address
|
|
121
|
+
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
/**
|
|
@@ -137,7 +141,7 @@ export class KioskTransaction {
|
|
|
137
141
|
this.share();
|
|
138
142
|
this.transactionBlock.transferObjects(
|
|
139
143
|
[this.kioskCap!],
|
|
140
|
-
this.transactionBlock.pure(address
|
|
144
|
+
this.transactionBlock.pure.address(address),
|
|
141
145
|
);
|
|
142
146
|
}
|
|
143
147
|
|
|
@@ -202,7 +206,7 @@ export class KioskTransaction {
|
|
|
202
206
|
this.kioskCap!,
|
|
203
207
|
amount,
|
|
204
208
|
);
|
|
205
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure(address
|
|
209
|
+
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
206
210
|
return this;
|
|
207
211
|
}
|
|
208
212
|
|
|
@@ -258,7 +262,7 @@ export class KioskTransaction {
|
|
|
258
262
|
* @param itemType The type `T` of the item
|
|
259
263
|
* @param itemId The ID of the item
|
|
260
264
|
*/
|
|
261
|
-
take({ itemType, itemId }: ItemId):
|
|
265
|
+
take({ itemType, itemId }: ItemId): TransactionObjectArgument {
|
|
262
266
|
this.#validateKioskIsSet();
|
|
263
267
|
return kioskTx.take(this.transactionBlock, itemType, this.kiosk!, this.kioskCap!, itemId);
|
|
264
268
|
}
|
|
@@ -273,7 +277,7 @@ export class KioskTransaction {
|
|
|
273
277
|
transfer({ itemType, itemId, address }: ItemId & { address: string }) {
|
|
274
278
|
this.#validateKioskIsSet();
|
|
275
279
|
const item = this.take({ itemType, itemId });
|
|
276
|
-
this.transactionBlock.transferObjects([item], this.transactionBlock.pure(address
|
|
280
|
+
this.transactionBlock.transferObjects([item], this.transactionBlock.pure.address(address));
|
|
277
281
|
return this;
|
|
278
282
|
}
|
|
279
283
|
|
|
@@ -304,10 +308,13 @@ export class KioskTransaction {
|
|
|
304
308
|
itemId,
|
|
305
309
|
price,
|
|
306
310
|
sellerKiosk,
|
|
307
|
-
}: ItemId & Price & { sellerKiosk: ObjectArgument }): [
|
|
311
|
+
}: ItemId & Price & { sellerKiosk: ObjectArgument }): [
|
|
312
|
+
TransactionObjectArgument,
|
|
313
|
+
TransactionObjectArgument,
|
|
314
|
+
] {
|
|
308
315
|
// Split the coin for the amount of the listing.
|
|
309
316
|
const coin = this.transactionBlock.splitCoins(this.transactionBlock.gas, [
|
|
310
|
-
this.transactionBlock.pure(price
|
|
317
|
+
this.transactionBlock.pure.u64(price),
|
|
311
318
|
]);
|
|
312
319
|
return kioskTx.purchase(this.transactionBlock, itemType, sellerKiosk, itemId, coin);
|
|
313
320
|
}
|
|
@@ -441,13 +448,13 @@ export class KioskTransaction {
|
|
|
441
448
|
}
|
|
442
449
|
|
|
443
450
|
// Some setters in case we want custom behavior.
|
|
444
|
-
setKioskCap(cap:
|
|
451
|
+
setKioskCap(cap: TransactionObjectArgument) {
|
|
445
452
|
this.#validateFinalizedStatus();
|
|
446
453
|
this.kioskCap = cap;
|
|
447
454
|
return this;
|
|
448
455
|
}
|
|
449
456
|
|
|
450
|
-
setKiosk(kiosk:
|
|
457
|
+
setKiosk(kiosk: TransactionObjectArgument) {
|
|
451
458
|
this.#validateFinalizedStatus();
|
|
452
459
|
this.kiosk = kiosk;
|
|
453
460
|
return this;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { TransactionObjectArgument, type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
attachFloorPriceRuleTx,
|
|
@@ -69,7 +69,7 @@ export class TransferPolicyTransaction {
|
|
|
69
69
|
if (policies.length > 0) throw new Error("There's already transfer policy for this Type.");
|
|
70
70
|
}
|
|
71
71
|
const cap = createTransferPolicy(this.transactionBlock, type, publisher);
|
|
72
|
-
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure(address
|
|
72
|
+
this.transactionBlock.transferObjects([cap], this.transactionBlock.pure.address(address));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -109,10 +109,10 @@ export class TransferPolicyTransaction {
|
|
|
109
109
|
if (!this.type || !this.policyCap || !this.policy)
|
|
110
110
|
throw new Error('This function can only be called after `transferPolicyManager.create`');
|
|
111
111
|
|
|
112
|
-
shareTransferPolicy(this.transactionBlock, this.type, this.policy as
|
|
112
|
+
shareTransferPolicy(this.transactionBlock, this.type, this.policy as TransactionObjectArgument);
|
|
113
113
|
this.transactionBlock.transferObjects(
|
|
114
|
-
[this.policyCap as
|
|
115
|
-
this.transactionBlock.pure(address
|
|
114
|
+
[this.policyCap as TransactionObjectArgument],
|
|
115
|
+
this.transactionBlock.pure.address(address),
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -141,7 +141,7 @@ export class TransferPolicyTransaction {
|
|
|
141
141
|
amount,
|
|
142
142
|
);
|
|
143
143
|
|
|
144
|
-
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure(address
|
|
144
|
+
this.transactionBlock.transferObjects([coin], this.transactionBlock.pure.address(address));
|
|
145
145
|
|
|
146
146
|
return this;
|
|
147
147
|
}
|
package/src/tx/kiosk.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { bcs } from '@mysten/sui.js/bcs';
|
|
5
|
+
import {
|
|
6
|
+
TransactionArgument,
|
|
7
|
+
TransactionBlock,
|
|
8
|
+
TransactionObjectArgument,
|
|
9
|
+
} from '@mysten/sui.js/transactions';
|
|
5
10
|
|
|
6
11
|
import { KIOSK_MODULE, KIOSK_TYPE, ObjectArgument } from '../types';
|
|
7
12
|
import { objArg } from '../utils';
|
|
@@ -9,7 +14,9 @@ import { objArg } from '../utils';
|
|
|
9
14
|
/**
|
|
10
15
|
* Create a new shared Kiosk and returns the [kiosk, kioskOwnerCap] tuple.
|
|
11
16
|
*/
|
|
12
|
-
export function createKiosk(
|
|
17
|
+
export function createKiosk(
|
|
18
|
+
tx: TransactionBlock,
|
|
19
|
+
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
13
20
|
const [kiosk, kioskOwnerCap] = tx.moveCall({
|
|
14
21
|
target: `${KIOSK_MODULE}::new`,
|
|
15
22
|
});
|
|
@@ -21,7 +28,7 @@ export function createKiosk(tx: TransactionBlock): [TransactionArgument, Transac
|
|
|
21
28
|
* Calls the `kiosk::new()` function and shares the kiosk.
|
|
22
29
|
* Returns the `kioskOwnerCap` object.
|
|
23
30
|
*/
|
|
24
|
-
export function createKioskAndShare(tx: TransactionBlock):
|
|
31
|
+
export function createKioskAndShare(tx: TransactionBlock): TransactionObjectArgument {
|
|
25
32
|
const [kiosk, kioskOwnerCap] = createKiosk(tx);
|
|
26
33
|
shareKiosk(tx, kiosk);
|
|
27
34
|
return kioskOwnerCap;
|
|
@@ -89,11 +96,11 @@ export function take(
|
|
|
89
96
|
kiosk: ObjectArgument,
|
|
90
97
|
kioskCap: ObjectArgument,
|
|
91
98
|
itemId: string,
|
|
92
|
-
):
|
|
99
|
+
): TransactionObjectArgument {
|
|
93
100
|
const [item] = tx.moveCall({
|
|
94
101
|
target: `${KIOSK_MODULE}::take`,
|
|
95
102
|
typeArguments: [itemType],
|
|
96
|
-
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId
|
|
103
|
+
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
|
|
97
104
|
});
|
|
98
105
|
|
|
99
106
|
return item;
|
|
@@ -117,8 +124,8 @@ export function list(
|
|
|
117
124
|
arguments: [
|
|
118
125
|
objArg(tx, kiosk),
|
|
119
126
|
objArg(tx, kioskCap),
|
|
120
|
-
tx.pure(itemId
|
|
121
|
-
tx.pure(price
|
|
127
|
+
tx.pure.address(itemId),
|
|
128
|
+
tx.pure.u64(price),
|
|
122
129
|
],
|
|
123
130
|
});
|
|
124
131
|
}
|
|
@@ -137,7 +144,7 @@ export function delist(
|
|
|
137
144
|
tx.moveCall({
|
|
138
145
|
target: `${KIOSK_MODULE}::delist`,
|
|
139
146
|
typeArguments: [itemType],
|
|
140
|
-
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId
|
|
147
|
+
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
|
|
141
148
|
});
|
|
142
149
|
}
|
|
143
150
|
|
|
@@ -156,7 +163,7 @@ export function placeAndList(
|
|
|
156
163
|
tx.moveCall({
|
|
157
164
|
target: `${KIOSK_MODULE}::place_and_list`,
|
|
158
165
|
typeArguments: [itemType],
|
|
159
|
-
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure(price
|
|
166
|
+
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), objArg(tx, item), tx.pure.u64(price)],
|
|
160
167
|
});
|
|
161
168
|
}
|
|
162
169
|
|
|
@@ -170,11 +177,11 @@ export function purchase(
|
|
|
170
177
|
kiosk: ObjectArgument,
|
|
171
178
|
itemId: string,
|
|
172
179
|
payment: ObjectArgument,
|
|
173
|
-
): [
|
|
180
|
+
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
174
181
|
const [item, transferRequest] = tx.moveCall({
|
|
175
182
|
target: `${KIOSK_MODULE}::purchase`,
|
|
176
183
|
typeArguments: [itemType],
|
|
177
|
-
arguments: [objArg(tx, kiosk), tx.pure(itemId
|
|
184
|
+
arguments: [objArg(tx, kiosk), tx.pure.address(itemId), objArg(tx, payment)],
|
|
178
185
|
});
|
|
179
186
|
|
|
180
187
|
return [item, transferRequest];
|
|
@@ -189,8 +196,8 @@ export function withdrawFromKiosk(
|
|
|
189
196
|
kiosk: ObjectArgument,
|
|
190
197
|
kioskCap: ObjectArgument,
|
|
191
198
|
amount?: string | bigint | number,
|
|
192
|
-
):
|
|
193
|
-
const amountArg =
|
|
199
|
+
): TransactionObjectArgument {
|
|
200
|
+
const amountArg = bcs.option(bcs.u64()).serialize(amount);
|
|
194
201
|
|
|
195
202
|
const [coin] = tx.moveCall({
|
|
196
203
|
target: `${KIOSK_MODULE}::withdraw`,
|
|
@@ -216,7 +223,7 @@ export function borrowValue(
|
|
|
216
223
|
const [item, promise] = tx.moveCall({
|
|
217
224
|
target: `${KIOSK_MODULE}::borrow_val`,
|
|
218
225
|
typeArguments: [itemType],
|
|
219
|
-
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure(itemId
|
|
226
|
+
arguments: [objArg(tx, kiosk), objArg(tx, kioskCap), tx.pure.address(itemId)],
|
|
220
227
|
});
|
|
221
228
|
|
|
222
229
|
return [item, promise];
|
package/src/tx/personal-kiosk.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
5
5
|
|
|
6
6
|
import { ObjectArgument } from '../types';
|
|
7
7
|
import { objArg } from '../utils';
|
|
@@ -11,7 +11,7 @@ export function convertToPersonalTx(
|
|
|
11
11
|
kiosk: ObjectArgument,
|
|
12
12
|
kioskOwnerCap: ObjectArgument,
|
|
13
13
|
packageId: string,
|
|
14
|
-
):
|
|
14
|
+
): TransactionObjectArgument {
|
|
15
15
|
const personalKioskCap = tx.moveCall({
|
|
16
16
|
target: `${packageId}::personal_kiosk::new`,
|
|
17
17
|
arguments: [objArg(tx, kiosk), objArg(tx, kioskOwnerCap)],
|
|
@@ -25,7 +25,7 @@ export function convertToPersonalTx(
|
|
|
25
25
|
*/
|
|
26
26
|
export function transferPersonalCapTx(
|
|
27
27
|
tx: TransactionBlock,
|
|
28
|
-
personalKioskCap:
|
|
28
|
+
personalKioskCap: TransactionObjectArgument,
|
|
29
29
|
packageId: string,
|
|
30
30
|
) {
|
|
31
31
|
tx.moveCall({
|
package/src/tx/rules/attach.ts
CHANGED
|
@@ -38,8 +38,8 @@ export function attachRoyaltyRuleTx(
|
|
|
38
38
|
arguments: [
|
|
39
39
|
objArg(tx, policy),
|
|
40
40
|
objArg(tx, policyCap),
|
|
41
|
-
tx.pure(percentageBps
|
|
42
|
-
tx.pure(minAmount
|
|
41
|
+
tx.pure.u16(Number(percentageBps)),
|
|
42
|
+
tx.pure.u64(minAmount),
|
|
43
43
|
],
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -69,6 +69,6 @@ export function attachFloorPriceRuleTx(
|
|
|
69
69
|
tx.moveCall({
|
|
70
70
|
target: `${packageId}::floor_price_rule::add`,
|
|
71
71
|
typeArguments: [type],
|
|
72
|
-
arguments: [objArg(tx, policy), objArg(tx, policyCap), tx.pure(minPrice
|
|
72
|
+
arguments: [objArg(tx, policy), objArg(tx, policyCap), tx.pure.u64(minPrice)],
|
|
73
73
|
});
|
|
74
74
|
}
|
package/src/tx/rules/resolve.ts
CHANGED
|
@@ -17,7 +17,7 @@ export function resolveRoyaltyRule(params: RuleResolvingParams) {
|
|
|
17
17
|
const [amount] = txb.moveCall({
|
|
18
18
|
target: `${packageId}::royalty_rule::fee_amount`,
|
|
19
19
|
typeArguments: [itemType],
|
|
20
|
-
arguments: [policyObj,
|
|
20
|
+
arguments: [policyObj, txb.pure.u64(price || '0')],
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
// splits the coin.
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { bcs } from '@mysten/sui.js/bcs';
|
|
5
|
+
import {
|
|
6
|
+
TransactionArgument,
|
|
7
|
+
TransactionBlock,
|
|
8
|
+
TransactionObjectArgument,
|
|
9
|
+
} from '@mysten/sui.js/transactions';
|
|
5
10
|
|
|
6
11
|
import { ObjectArgument, TRANSFER_POLICY_MODULE, TRANSFER_POLICY_TYPE } from '../types';
|
|
7
12
|
import { objArg } from '../utils';
|
|
@@ -14,7 +19,7 @@ export function createTransferPolicy(
|
|
|
14
19
|
tx: TransactionBlock,
|
|
15
20
|
itemType: string,
|
|
16
21
|
publisher: ObjectArgument,
|
|
17
|
-
):
|
|
22
|
+
): TransactionObjectArgument {
|
|
18
23
|
const [transferPolicy, transferPolicyCap] = createTransferPolicyWithoutSharing(
|
|
19
24
|
tx,
|
|
20
25
|
itemType,
|
|
@@ -34,7 +39,7 @@ export function createTransferPolicyWithoutSharing(
|
|
|
34
39
|
tx: TransactionBlock,
|
|
35
40
|
itemType: string,
|
|
36
41
|
publisher: ObjectArgument,
|
|
37
|
-
): [
|
|
42
|
+
): [TransactionObjectArgument, TransactionObjectArgument] {
|
|
38
43
|
const [transferPolicy, transferPolicyCap] = tx.moveCall({
|
|
39
44
|
target: `${TRANSFER_POLICY_MODULE}::new`,
|
|
40
45
|
typeArguments: [itemType],
|
|
@@ -49,7 +54,7 @@ export function createTransferPolicyWithoutSharing(
|
|
|
49
54
|
export function shareTransferPolicy(
|
|
50
55
|
tx: TransactionBlock,
|
|
51
56
|
itemType: string,
|
|
52
|
-
transferPolicy:
|
|
57
|
+
transferPolicy: TransactionObjectArgument,
|
|
53
58
|
) {
|
|
54
59
|
tx.moveCall({
|
|
55
60
|
target: `0x2::transfer::public_share_object`,
|
|
@@ -67,8 +72,8 @@ export function withdrawFromPolicy(
|
|
|
67
72
|
policy: ObjectArgument,
|
|
68
73
|
policyCap: ObjectArgument,
|
|
69
74
|
amount?: string | bigint | null,
|
|
70
|
-
):
|
|
71
|
-
const amountArg =
|
|
75
|
+
): TransactionObjectArgument {
|
|
76
|
+
const amountArg = bcs.option(bcs.u64()).serialize(amount);
|
|
72
77
|
|
|
73
78
|
const [profits] = tx.moveCall({
|
|
74
79
|
target: `${TRANSFER_POLICY_MODULE}::withdraw`,
|
package/src/types/index.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { type SharedObjectRef } from '@mysten/sui.js/bcs';
|
|
5
5
|
import { type SuiClient, type SuiObjectRef } from '@mysten/sui.js/client';
|
|
6
|
-
import {
|
|
6
|
+
import { TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
7
7
|
|
|
8
8
|
import { BaseRulePackageIds } from '../constants';
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ export * from './transfer-policy';
|
|
|
13
13
|
/**
|
|
14
14
|
* A valid argument for any of the Kiosk functions.
|
|
15
15
|
*/
|
|
16
|
-
export type ObjectArgument = string |
|
|
16
|
+
export type ObjectArgument = string | TransactionObjectArgument | SharedObjectRef | SuiObjectRef;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* A Network selector.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { type ObjectOwner } from '@mysten/sui.js/client';
|
|
5
|
-
import {
|
|
5
|
+
import { TransactionObjectArgument, type TransactionBlock } from '@mysten/sui.js/transactions';
|
|
6
6
|
|
|
7
7
|
import { ObjectArgument } from '.';
|
|
8
8
|
|
|
@@ -60,8 +60,8 @@ export type RuleResolvingParams = {
|
|
|
60
60
|
sellerKiosk: ObjectArgument;
|
|
61
61
|
kiosk: ObjectArgument;
|
|
62
62
|
kioskCap: ObjectArgument;
|
|
63
|
-
transferRequest:
|
|
64
|
-
purchasedItem:
|
|
63
|
+
transferRequest: TransactionObjectArgument;
|
|
64
|
+
purchasedItem: TransactionObjectArgument;
|
|
65
65
|
packageId: string;
|
|
66
66
|
extraArgs: Record<string, any>; // extraParams contains more possible {key, values} to pass for custom rules.
|
|
67
67
|
};
|
package/src/utils.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
SuiObjectResponse,
|
|
13
13
|
type DynamicFieldInfo,
|
|
14
14
|
} from '@mysten/sui.js/client';
|
|
15
|
-
import {
|
|
15
|
+
import { TransactionBlock, TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
16
16
|
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
|
|
17
17
|
|
|
18
18
|
import { bcs } from './bcs';
|
|
@@ -36,8 +36,8 @@ const DEFAULT_QUERY_LIMIT = 50;
|
|
|
36
36
|
*/
|
|
37
37
|
export function objArg(
|
|
38
38
|
txb: TransactionBlock,
|
|
39
|
-
arg: string | SharedObjectRef | SuiObjectRef |
|
|
40
|
-
):
|
|
39
|
+
arg: string | SharedObjectRef | SuiObjectRef | TransactionObjectArgument,
|
|
40
|
+
): TransactionObjectArgument {
|
|
41
41
|
if (typeof arg === 'string') {
|
|
42
42
|
return txb.object(arg);
|
|
43
43
|
}
|