@@ -39,7 +39,7 @@ module ob_kiosk::ob_kiosk {
3939 use sui::dynamic_field::{Self as df};
4040 use sui::kiosk::{Self , Kiosk , KioskOwnerCap , uid, uid_mut as ext};
4141 use sui::object::{Self , ID , UID , uid_to_address};
42- use sui::coin;
42+ use sui::coin::{ Self , Coin } ;
4343 use sui::table::{Self , Table };
4444 use sui::transfer::{transfer, public_share_object, public_transfer};
4545 use sui::tx_context::{Self , TxContext , sender};
@@ -864,6 +864,140 @@ module ob_kiosk::ob_kiosk {
864864 });
865865 }
866866
867+ /// Deposit an NFT and lock it within the `Kiosk`
868+ ///
869+ /// Once an NFT is locked it can only be listed either with `list` or
870+ /// `list_with_purchase_cap`.
871+ ///
872+ /// Useful for interacting with non-OB collections.
873+ ///
874+ /// #### Panics
875+ ///
876+ /// Panics if transaction sender is not owner or `Kiosk` is not
877+ /// permissionless.
878+ public fun lock <T : key + store >(
879+ self: &mut Kiosk ,
880+ policy: &sui::transfer_policy ::TransferPolicy <T >,
881+ nft: T ,
882+ ctx: &mut TxContext ,
883+ ) {
884+ assert_version_and_upgrade (ext (self));
885+ assert_can_deposit <T >(self, ctx);
886+
887+ let cap = pop_cap (self);
888+ kiosk::lock (self, &cap, policy, nft);
889+ set_cap (self, cap);
890+ }
891+
892+ /// List the NFT directly on the `Kiosk`
893+ ///
894+ /// #### Panics
895+ ///
896+ /// - Transaction sender is not owner or `Kiosk` is not permissionless
897+ /// - NFT with type and `ID` does not exist on the `Kiosk`
898+ /// - NFT is listed exclusively
899+ public fun list <T : key + store >(
900+ self: &mut Kiosk ,
901+ nft_id: ID ,
902+ price: u64 ,
903+ ctx: &mut TxContext ,
904+ ) {
905+ assert_version_and_upgrade (ext (self));
906+ assert_permission (self, ctx);
907+
908+ let cap = pop_cap (self);
909+ kiosk::list <T >(self, &cap, nft_id, price);
910+ set_cap (self, cap);
911+ }
912+
913+ /// List the NFT directly on the `Kiosk`
914+ ///
915+ /// #### Panics
916+ ///
917+ /// - Transaction sender is not owner or `Kiosk` is not permissionless
918+ /// - NFT with type and `ID` does not exist on the `Kiosk`
919+ /// - NFT is listed exclusively
920+ public fun list_with_purchase_cap <T : key + store >(
921+ self: &mut Kiosk ,
922+ nft_id: ID ,
923+ min_price: u64 ,
924+ ctx: &mut TxContext ,
925+ ): sui::kiosk ::PurchaseCap <T > {
926+ assert_version_and_upgrade (ext (self));
927+ assert_permission (self, ctx);
928+
929+ let cap = pop_cap (self);
930+ let purchase_cap = kiosk::list_with_purchase_cap <T >(
931+ self, &cap, nft_id, min_price, ctx,
932+ );
933+ set_cap (self, cap);
934+
935+ purchase_cap
936+ }
937+
938+ /// Delist the NFT from the `Kiosk`
939+ ///
940+ /// #### Panics
941+ ///
942+ /// - Transaction sender is not owner or `Kiosk` is not permissionless
943+ /// - NFT with type and `ID` does not exist on the `Kiosk`
944+ /// - NFT is listed exclusively
945+ /// - NFT is not listed
946+ public fun delist <T : key + store >(
947+ self: &mut Kiosk ,
948+ nft_id: ID ,
949+ ctx: &mut TxContext ,
950+ ) {
951+ assert_version_and_upgrade (ext (self));
952+ assert_permission (self, ctx);
953+
954+ let cap = pop_cap (self);
955+ kiosk::delist <T >(self, &cap, nft_id);
956+ set_cap (self, cap);
957+ }
958+
959+ /// Withdraw funds from the `Kiosk`
960+ ///
961+ /// This is only applicable when NFTs were sold using
962+ /// `sui::kiosk::purchase` or `sui::kiosk::purchase_with_cap`.
963+ ///
964+ /// #### Panics
965+ ///
966+ /// Panics if transaction sender is not owner or `Kiosk` is not
967+ /// permissionless.
968+ public fun withdraw (
969+ self: &mut Kiosk ,
970+ amount: Option <u64 >,
971+ ctx: &mut TxContext ,
972+ ): Coin <sui::sui ::SUI > {
973+ assert_version_and_upgrade (ext (self));
974+ assert_permission (self, ctx);
975+
976+ let cap = pop_cap (self);
977+ let coin = kiosk::withdraw (self, &cap, amount, ctx);
978+ set_cap (self, cap);
979+
980+ coin
981+ }
982+
983+ /// Withdraw funds from the `Kiosk` and transfer
984+ ///
985+ /// This is only applicable when NFTs were sold using
986+ /// `sui::kiosk::purchase` or `sui::kiosk::purchase_with_cap`.
987+ ///
988+ /// #### Panics
989+ ///
990+ /// Panics if transaction sender is not owner or `Kiosk` is not
991+ /// permissionless.
992+ public fun withdraw_and_transfer (
993+ self: &mut Kiosk ,
994+ amount: Option <u64 >,
995+ ctx: &mut TxContext ,
996+ ) {
997+ let coin = withdraw (self, amount, ctx);
998+ public_transfer (coin, tx_context::sender (ctx));
999+ }
1000+
8671001 // === Private Functions ===
8681002
8691003 /// Initializes a transfer transaction
@@ -1164,6 +1298,8 @@ module ob_kiosk::ob_kiosk {
11641298 df::exists_ (uid (self), NftRefsDfKey {})
11651299 }
11661300
1301+ /// Returns whether the current transaction sender can deposit into `Kiosk`
1302+ ///
11671303 /// Either sender is owner or permissionless deposits of `T` enabled.
11681304 public fun can_deposit <T >(self: &mut Kiosk , ctx: &mut TxContext ): bool {
11691305 sender (ctx) == kiosk::owner (self) || can_deposit_permissionlessly <T >(self)
@@ -1189,7 +1325,6 @@ module ob_kiosk::ob_kiosk {
11891325 /// Panics if `Kiosk` is not OriginByte `Kiosk`
11901326 //
11911327 // TODO: Replace with immutable API
1192- // TODO: Consider removing test_only
11931328 public fun nft_refs (self: &Kiosk ): &Table <ID , NftRef > {
11941329 is_ob_kiosk_imut (self);
11951330 df::borrow (uid (self), NftRefsDfKey {})
@@ -1221,6 +1356,11 @@ module ob_kiosk::ob_kiosk {
12211356 assert ! (is_permissionless (self), EKioskNotPermissionless );
12221357 }
12231358
1359+ /// Asserts that the transaction sender may deposit into `Kiosk`
1360+ ///
1361+ /// #### Panics
1362+ ///
1363+ /// Panics if sender is not owner or `Kiosk` is not permissionless.
12241364 public fun assert_can_deposit <T >(self: &mut Kiosk , ctx: &mut TxContext ) {
12251365 assert ! (can_deposit <T >(self, ctx), ECannotDeposit );
12261366 }
0 commit comments